OrderCreateAfterJob.php 4.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. namespace app\jobs;
  3. use app\services\activity\combination\StoreCombinationServices;
  4. use app\services\order\StoreOrderCartInfoServices;
  5. use app\services\order\StoreOrderCreateServices;
  6. use app\services\order\StoreOrderComputedServices;
  7. use app\services\user\UserServices;
  8. use crmeb\basic\BaseJobs;
  9. use crmeb\traits\QueueTrait;
  10. use think\facade\Log;
  11. class OrderCreateAfterJob extends BaseJobs
  12. {
  13. use QueueTrait;
  14. /**
  15. * 订单后置处理
  16. * @param $orderId
  17. * @param $cartInfo
  18. * @param $priceData
  19. * @param $order
  20. * @param $data
  21. * @return bool
  22. */
  23. public function doJob($orderInfo, $data, $activity)
  24. {
  25. $uid = (int)$orderInfo['uid'];
  26. $orderId = (int)$orderInfo['id'];
  27. try {
  28. $cartInfo = $data['cartInfo'] ?? [];
  29. $priceData = $data['priceData'] ?? [];
  30. $addressId = $data['addressId'] ?? 0;
  31. $spread_ids = [];
  32. /** @var StoreOrderCreateServices $createService */
  33. $createService = app()->make(StoreOrderCreateServices::class);
  34. if ($cartInfo && $priceData) {
  35. /** @var StoreOrderCartInfoServices $cartServices */
  36. $cartServices = app()->make(StoreOrderCartInfoServices::class);
  37. [$cartInfo, $spread_ids] = $createService->computeOrderProductTruePrice($cartInfo, $priceData, $addressId, $uid, $orderInfo);
  38. $cartServices->updateCartInfo($orderId, $cartInfo);
  39. }
  40. $orderData = [];
  41. $spread_uid = $spread_two_uid = 0;
  42. /** @var UserServices $userServices */
  43. $userServices = app()->make(UserServices::class);
  44. if ($spread_ids) {
  45. [$spread_uid, $spread_two_uid] = $spread_ids;
  46. $orderData['spread_uid'] = $spread_uid;
  47. $orderData['spread_two_uid'] = $spread_two_uid;
  48. } else {
  49. $spread_uid = $userServices->getSpreadUid($uid);
  50. $orderData = ['spread_uid' => 0, 'spread_two_uid' => 0];
  51. if ($spread_uid) {
  52. $orderData['spread_uid'] = $spread_uid;
  53. }
  54. if ($spread_uid > 0 && sys_config('brokerage_level') == 2) {
  55. $spread_two_uid = $userServices->getSpreadUid($spread_uid, [], false);
  56. if ($spread_two_uid) {
  57. $orderData['spread_two_uid'] = $spread_two_uid;
  58. }
  59. }
  60. }
  61. $isCommission = 0;
  62. if ($orderInfo['combination_id']) {
  63. //检测拼团是否参与返佣
  64. /** @var StoreCombinationServices $combinationServices */
  65. $combinationServices = app()->make(StoreCombinationServices::class);
  66. $isCommission = $combinationServices->value(['id' => $orderInfo['combination_id']], 'is_commission');
  67. }
  68. if ($cartInfo && (!$activity || $isCommission)) {
  69. /** @var StoreOrderComputedServices $orderComputed */
  70. $orderComputed = app()->make(StoreOrderComputedServices::class);
  71. if ($userServices->checkUserPromoter($spread_uid)) $orderData['one_brokerage'] = $orderComputed->getOrderSumPrice($cartInfo, 'one_brokerage', false);
  72. if ($userServices->checkUserPromoter($spread_two_uid)) $orderData['two_brokerage'] = $orderComputed->getOrderSumPrice($cartInfo, 'two_brokerage', false);
  73. $orderData['staff_brokerage'] = $orderComputed->getOrderSumPrice($cartInfo, 'staff_brokerage', false);
  74. $orderData['agent_brokerage'] = $orderComputed->getOrderSumPrice($cartInfo, 'agent_brokerage', false);
  75. $orderData['division_brokerage'] = $orderComputed->getOrderSumPrice($cartInfo, 'division_brokerage', false);
  76. }
  77. $createService->update(['id' => $orderId], $orderData);
  78. } catch (\Throwable $e) {
  79. Log::error('计算订单实际优惠、积分、邮费、佣金失败,原因:' . $e->getMessage());
  80. }
  81. return true;
  82. }
  83. }