添加购物车下单
parent
6b19b81c90
commit
24439c851b
|
|
@ -51,7 +51,7 @@ class DealerProductLvlRule extends Form implements LazyRenderable
|
|||
$_rule = DealerProductLvlRuleModel::find($rule['id']);
|
||||
$_rule['lvl'] = $rule['lvl'];
|
||||
$_rule['sale_price'] = $rule['sale_price'];
|
||||
$_rule['min_order_amount'] = $rule['min_order_amount'];
|
||||
// $_rule['min_order_amount'] = $rule['min_order_amount'];
|
||||
$lvlRules[] = $_rule;
|
||||
}
|
||||
}
|
||||
|
|
@ -88,7 +88,7 @@ class DealerProductLvlRule extends Form implements LazyRenderable
|
|||
6 => '一级经销商',
|
||||
]);
|
||||
$form->currency('sale_price', '等级进货单价')->symbol('¥');
|
||||
$form->currency('min_order_amount', '等级单次最低进货价')->symbol('¥');
|
||||
// $form->currency('min_order_amount', '等级单次最低进货价')->symbol('¥');
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -43,9 +43,15 @@ class Dealer extends Form
|
|||
$this->currency('withdraw_fee_rate', '提现费率')->symbol('%');
|
||||
$this->number('withdraw_days', '提现间隔');
|
||||
|
||||
$this->currency('upgrade_amount_'.DealerLvl::Contracted->value, '签约门槛')->symbol('¥');
|
||||
$this->currency('upgrade_amount_'.DealerLvl::Special->value, '特邀门槛')->symbol('¥');
|
||||
$this->currency('upgrade_amount_'.DealerLvl::Gold->value, '金牌门槛')->symbol('¥');
|
||||
$this->currency('upgrade_amount_'.DealerLvl::Gold->value, '金牌升级门槛')->symbol('¥');
|
||||
$this->currency('upgrade_amount_'.DealerLvl::Special->value, '特邀升级门槛')->symbol('¥');
|
||||
$this->currency('upgrade_amount_'.DealerLvl::Contracted->value, '签约升级门槛')->symbol('¥');
|
||||
|
||||
$this->currency('min_order_amount_'.DealerLvl::Gold->value, '金牌单次进货最低金额')->symbol('¥');
|
||||
$this->currency('min_order_amount_'.DealerLvl::Special->value, '特邀单次进货最低金额')->symbol('¥');
|
||||
$this->currency('min_order_amount_'.DealerLvl::Contracted->value, '签约单次进货最低金额')->symbol('¥');
|
||||
$this->currency('min_order_amount_'.DealerLvl::Secondary->value, '二级签约单次进货最低金额')->symbol('¥');
|
||||
$this->currency('min_order_amount_'.DealerLvl::Top->value, '一级签约单次进货最低金额')->symbol('¥');
|
||||
|
||||
$this->number('order_auto_allocate_times', '订单自动分配时间(分)')->min(1);
|
||||
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ class ProductLvlRuleResource extends JsonResource
|
|||
return [
|
||||
'lvl' => $this->lvl,
|
||||
'sale_price' => $this->sale_price,
|
||||
'min_order_amount' => $this->min_order_amount,
|
||||
'min_order_amount' => app_settings('dealer.min_order_amount_'.$this->lvl, 0),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ use App\Enums\DealerWalletAction;
|
|||
use App\Exceptions\BizException;
|
||||
use App\Models\DealerOrder;
|
||||
use App\Models\DealerOrderAllocateLog;
|
||||
use App\Models\DealerOrderProduct;
|
||||
use App\Models\DealerProduct;
|
||||
use App\Models\DealerUserProductLog;
|
||||
use App\Models\ShippingAddress;
|
||||
|
|
@ -55,13 +56,13 @@ class OrderService
|
|||
* @param integer $number
|
||||
* @return string
|
||||
*/
|
||||
public function totalAmount(User $user, DealerProduct $product, int $number = 0)
|
||||
public function totalAmount(User $user, DealerProduct $product, int $number = 0, ?int $allNumber = 0)
|
||||
{
|
||||
return bcmul($this->getSalePrice($user, $product, $number), $number, 2);
|
||||
return bcmul($this->getSalePrice($user, $product, $allNumber ?? $number), $number, 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建订单
|
||||
* 快捷创建订单(单个商品下单)
|
||||
*
|
||||
* @param User $user
|
||||
* @param DealerProduct $product
|
||||
|
|
@ -71,13 +72,13 @@ class OrderService
|
|||
*/
|
||||
public function quickCreateOrder(User $user, DealerProduct $product, int $number = 0, int $shippingAddressId)
|
||||
{
|
||||
//判断是否满足当前等级最低补货价
|
||||
$totalAmount = $this->totalAmount($user, $product, $number);
|
||||
foreach ($product->lvlRules as $rule) {
|
||||
if ($user->dealer && $rule->lvl == $user->dealer->lvl->value && $totalAmount < $rule->min_order_amount) {
|
||||
throw new BizException('当前单次补货价格不能低于'.$rule->min_order_amount.'元');
|
||||
}
|
||||
}
|
||||
// foreach ($product->lvlRules as $rule) {
|
||||
// $min_order_amount = app_settings('min_order_amount'.$rule->lvl);
|
||||
// if ($user->dealer && $rule->lvl == $user->dealer->lvl->value && $totalAmount < $min_order_amount) {
|
||||
// throw new BizException('当前单次补货价格不能低于'.$min_order_amount.'元');
|
||||
// }
|
||||
// }
|
||||
|
||||
$order = $this->createOrder($user, $totalAmount, $shippingAddressId);
|
||||
|
||||
|
|
@ -100,9 +101,58 @@ class OrderService
|
|||
return $order;
|
||||
}
|
||||
|
||||
/**
|
||||
* 购物车创建订单
|
||||
*
|
||||
* @param User $user
|
||||
* @param [type] $cartIds
|
||||
* @param integer $shippingAddressId
|
||||
* @return DealerOrder $order
|
||||
*/
|
||||
public function cartCreateOrder(User $user, $cartIds, int $shippingAddressId)
|
||||
{
|
||||
return null; //
|
||||
//获取购物车商品
|
||||
$shoppingCartItems = $user->dealerShoppingCartItems()->findMany($cartIds);
|
||||
if ($shoppingCartItems->count() !== count($cartIds)) {
|
||||
throw new BizException('购物车商品已丢失');
|
||||
}
|
||||
$shoppingCartItems->load('product');
|
||||
$totalQty = $shoppingCartItems->sum('quantity');
|
||||
$totalAmount = 0;
|
||||
$orderProducts = [];
|
||||
foreach ($shoppingCartItems as $item) {
|
||||
if (!$item->product->isOnline()) {
|
||||
throw new BizException('购物车商品已失效');
|
||||
}
|
||||
//计算订单价格
|
||||
$totalAmount += $this->totalAmount($user, $item->product, $item->quantity, $totalQty);
|
||||
//组装订单商品
|
||||
$orderProducts[] = [
|
||||
'product_id' => $item->product_id,
|
||||
'name'=> $item->name,
|
||||
'subtitle' => $item->product->subtitle,
|
||||
'cover' => $item->cover,
|
||||
'price' => $item->sell_price,
|
||||
'sale_price' => $this->getSalePrice($user, $item->product, $totalQty),
|
||||
'qty' => $item->quantity,
|
||||
];
|
||||
}
|
||||
|
||||
$order = $this->createOrder($user, $totalAmount, $shippingAddressId);
|
||||
|
||||
DealerOrderProduct::insert(array_map(function ($product) use ($order) {
|
||||
return array_merge($product, [
|
||||
'order_id'=>$order->id,
|
||||
'created_at'=> $order->created_at,
|
||||
'updated_at'=> $order->updated_at,
|
||||
]);
|
||||
}, $orderProducts));
|
||||
|
||||
if (!$order->consignor) {//如果订单分配给公司,则直接确认
|
||||
$this->confirmOrder($order);
|
||||
}
|
||||
|
||||
return $order;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -115,6 +165,11 @@ class OrderService
|
|||
*/
|
||||
protected function createOrder(User $user, $totalAmount, int $shippingAddressId)
|
||||
{
|
||||
//判断是否满足当前等级最低补货价
|
||||
$min_order_amount = app_settings('dealer.min_order_amount_'.$user->dealer?->lvl->value, 0);
|
||||
if ($user->dealer && $totalAmount < $min_order_amount) {
|
||||
throw new BizException('当前单次补货价格不能低于'.$min_order_amount.'元');
|
||||
}
|
||||
//找到发货人
|
||||
$consignor = $this->getConsignor($user, $totalAmount);
|
||||
|
||||
|
|
|
|||
|
|
@ -190,6 +190,18 @@ class AppSettingSeeder extends Seeder
|
|||
// 合约经销商升级金额
|
||||
'upgrade_amount_'.DealerLvl::Contracted->value => '26400',
|
||||
|
||||
//单次下单最低金额
|
||||
// 金牌经销商
|
||||
'min_order_amount_'.DealerLvl::Gold->value => '1260',
|
||||
// 特邀经销商
|
||||
'min_order_amount_'.DealerLvl::Special->value => '1720',
|
||||
// 签约约经销商
|
||||
'min_order_amount_'.DealerLvl::Contracted->value => '2640',
|
||||
// 二级签约约经销商
|
||||
'min_order_amount_'.DealerLvl::Secondary->value => '2640',
|
||||
// 一级签约约经销商
|
||||
'min_order_amount_'.DealerLvl::Top->value => '2640',
|
||||
|
||||
// 渠道补贴规则
|
||||
'channel_rules' => [
|
||||
// 签约 -> 签约 ->签约
|
||||
|
|
|
|||
Loading…
Reference in New Issue