TakeOrderJob.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\jobs;
  12. use app\services\order\StoreOrderServices;
  13. use app\services\order\StoreOrderStatusServices;
  14. use app\services\order\StoreOrderTakeServices;
  15. use crmeb\basic\BaseJobs;
  16. use crmeb\traits\QueueTrait;
  17. use think\facade\Log;
  18. /**
  19. * 自动收货消息队列
  20. * Class TakeOrderJob
  21. * @package crmeb\jobs
  22. */
  23. class TakeOrderJob extends BaseJobs
  24. {
  25. use QueueTrait;
  26. /**
  27. * @param $id
  28. * @return bool
  29. */
  30. public function doJob($id)
  31. {
  32. /** @var StoreOrderTakeServices $services */
  33. $services = app()->make(StoreOrderTakeServices::class);
  34. $orderInfo = $services->get($id);
  35. if (!$orderInfo) {
  36. return true;
  37. }
  38. if (!$orderInfo->paid) {
  39. return true;
  40. }
  41. if ($orderInfo->refund_status == 2) {
  42. return true;
  43. }
  44. /** @var StoreOrderServices $orderServices */
  45. $orderServices = app()->make(StoreOrderServices::class);
  46. $order = $orderServices->tidyOrder($orderInfo);
  47. if ($order['_status']['_type'] != 2) {
  48. return true;
  49. }
  50. $orderInfo->status = 2;
  51. /** @var StoreOrderStatusServices $statusService */
  52. $statusService = app()->make(StoreOrderStatusServices::class);
  53. $res = $orderInfo->save() && $statusService->save([
  54. 'oid' => $orderInfo['id'],
  55. 'change_type' => 'take_delivery',
  56. 'change_message' => '已收货[自动收货]',
  57. 'change_time' => time()
  58. ]);
  59. try {
  60. $services->storeProductOrderUserTakeDelivery($order);
  61. } catch (\Throwable $e) {
  62. Log::error('自动收货消息队列执行成功,收货后置动作失败,失败原因:' . $e->getMessage());
  63. }
  64. return $res;
  65. }
  66. }