SpliteOrderAfterJob.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace app\jobs\order;
  3. use app\services\order\StoreOrderStatusServices;
  4. use crmeb\basic\BaseJobs;
  5. use crmeb\traits\QueueTrait;
  6. use think\facade\Log;
  7. /**
  8. * 拆分订单后置队列
  9. * Class SpliteOrderAfterJob
  10. * @package app\jobs\order
  11. */
  12. class SpliteOrderAfterJob extends BaseJobs
  13. {
  14. use QueueTrait;
  15. /**
  16. * 门店分配订单
  17. * @param $orderInfo
  18. * @return bool
  19. */
  20. public function doJob($oid, $orderData)
  21. {
  22. if (!$oid || !$orderData || count($orderData) != 2) {
  23. return true;
  24. }
  25. [$orderInfo, $otherOrder] = $orderData;
  26. try {
  27. /** @var StoreOrderStatusServices $statusService */
  28. $statusService = app()->make(StoreOrderStatusServices::class);
  29. $statusData = $statusService->getColumn(['oid' => $oid], '*');
  30. if (!$statusData) {
  31. return true;
  32. }
  33. $ids = [];
  34. if ($orderInfo['id'] != $oid) {
  35. $ids[] = $orderInfo['id'];
  36. }
  37. if ($otherOrder['id'] != $oid) {
  38. $ids[] = $otherOrder['id'];
  39. }
  40. if ($ids) {
  41. $allData = [];
  42. foreach ($ids as $id) {
  43. foreach ($statusData as $data) {
  44. $data['oid'] = $id;
  45. $allData[] = $data;
  46. }
  47. }
  48. if ($allData) {
  49. $statusService->saveAll($allData);
  50. }
  51. }
  52. } catch (\Throwable $e) {
  53. Log::error('处理拆分订单记录失败,原因:' . $e->getMessage());
  54. }
  55. return true;
  56. }
  57. }