mirror of
https://github.com/crmeb/CRMEB.git
synced 2026-10-29 22:10:49 +00:00
【程序目录】优化订单计算金额
This commit is contained in:
parent
e05104b0be
commit
4a5a993d22
@ -339,12 +339,12 @@ class StoreOrderCreateServices extends BaseServices
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单创建后的后置事件
|
||||
* @param UserAddressServices $addressServices
|
||||
* 订单数据创建之后的商品实际金额计算,佣金计算,优惠折扣计算,设置默认地址,清理购物车
|
||||
* @param $order
|
||||
* @param array $group
|
||||
* @param $activity
|
||||
*/
|
||||
public function orderCreateAfter($order, array $group)
|
||||
public function orderCreateAfter($order, array $group, $activity)
|
||||
{
|
||||
/** @var UserAddressServices $addressServices */
|
||||
$addressServices = app()->make(UserAddressServices::class);
|
||||
@ -362,6 +362,63 @@ class StoreOrderCreateServices extends BaseServices
|
||||
$cartServices = app()->make(StoreCartServices::class);
|
||||
$cartServices->deleteCartStatus($group['cartIds']);
|
||||
}
|
||||
$uid = (int)$order['uid'];
|
||||
$orderId = (int)$order['id'];
|
||||
try {
|
||||
$cartInfo = $group['cartInfo'] ?? [];
|
||||
$priceData = $group['priceData'] ?? [];
|
||||
$addressId = $group['addressId'] ?? 0;
|
||||
$spread_ids = [];
|
||||
/** @var StoreOrderCreateServices $createService */
|
||||
$createService = app()->make(StoreOrderCreateServices::class);
|
||||
if ($cartInfo && $priceData) {
|
||||
/** @var StoreOrderCartInfoServices $cartServices */
|
||||
$cartServices = app()->make(StoreOrderCartInfoServices::class);
|
||||
[$cartInfo, $spread_ids] = $createService->computeOrderProductTruePrice($cartInfo, $priceData, $addressId, $uid, $order);
|
||||
$cartServices->updateCartInfo($orderId, $cartInfo);
|
||||
}
|
||||
|
||||
$orderData = [];
|
||||
$spread_uid = $spread_two_uid = 0;
|
||||
/** @var UserServices $userServices */
|
||||
$userServices = app()->make(UserServices::class);
|
||||
if ($spread_ids) {
|
||||
[$spread_uid, $spread_two_uid] = $spread_ids;
|
||||
$orderData['spread_uid'] = $spread_uid;
|
||||
$orderData['spread_two_uid'] = $spread_two_uid;
|
||||
} else {
|
||||
$spread_uid = $userServices->getSpreadUid($uid);
|
||||
$orderData = ['spread_uid' => 0, 'spread_two_uid' => 0];
|
||||
if ($spread_uid) {
|
||||
$orderData['spread_uid'] = $spread_uid;
|
||||
}
|
||||
if ($spread_uid > 0 && sys_config('brokerage_level') == 2) {
|
||||
$spread_two_uid = $userServices->getSpreadUid($spread_uid, [], false);
|
||||
if ($spread_two_uid) {
|
||||
$orderData['spread_two_uid'] = $spread_two_uid;
|
||||
}
|
||||
}
|
||||
}
|
||||
$isCommission = 0;
|
||||
if ($order['combination_id']) {
|
||||
//检测拼团是否参与返佣
|
||||
/** @var StoreCombinationServices $combinationServices */
|
||||
$combinationServices = app()->make(StoreCombinationServices::class);
|
||||
$isCommission = $combinationServices->value(['id' => $order['combination_id']], 'is_commission');
|
||||
}
|
||||
if ($cartInfo && (!$activity || $isCommission)) {
|
||||
/** @var StoreOrderComputedServices $orderComputed */
|
||||
$orderComputed = app()->make(StoreOrderComputedServices::class);
|
||||
if ($userServices->checkUserPromoter($spread_uid)) $orderData['one_brokerage'] = $orderComputed->getOrderSumPrice($cartInfo, 'one_brokerage', false);
|
||||
if ($userServices->checkUserPromoter($spread_two_uid)) $orderData['two_brokerage'] = $orderComputed->getOrderSumPrice($cartInfo, 'two_brokerage', false);
|
||||
$orderData['staff_brokerage'] = $orderComputed->getOrderSumPrice($cartInfo, 'staff_brokerage', false);
|
||||
$orderData['agent_brokerage'] = $orderComputed->getOrderSumPrice($cartInfo, 'agent_brokerage', false);
|
||||
$orderData['division_brokerage'] = $orderComputed->getOrderSumPrice($cartInfo, 'division_brokerage', false);
|
||||
}
|
||||
$createService->update(['id' => $orderId], $orderData);
|
||||
} catch (\Throwable $e) {
|
||||
throw new ApiException('计算订单实际优惠、积分、邮费、佣金失败,原因:' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -724,8 +781,6 @@ class StoreOrderCreateServices extends BaseServices
|
||||
$cart['agent_brokerage'] = $agentBrokerage;
|
||||
$cart['division_brokerage'] = $divisionBrokerage;
|
||||
}
|
||||
|
||||
return [$cartInfo, [$spread_one_uid, $spread_two_uid]];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user