TakeOrderJob.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 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\order;
  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 app\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->status == 2) {
  42. return true;
  43. }
  44. if ($orderInfo->refund_status == 2) {
  45. return true;
  46. }
  47. /** @var StoreOrderServices $orderServices */
  48. $orderServices = app()->make(StoreOrderServices::class);
  49. $order = $orderServices->tidyOrder($orderInfo);
  50. if ($order['_status']['_type'] != 2) {
  51. return true;
  52. }
  53. $orderInfo->status = 2;
  54. /** @var StoreOrderStatusServices $statusService */
  55. $statusService = app()->make(StoreOrderStatusServices::class);
  56. $res = $orderInfo->save() && $statusService->save([
  57. 'oid' => $orderInfo['id'],
  58. 'change_type' => 'take_delivery',
  59. 'change_message' => '已收货[自动收货]',
  60. 'change_time' => time()
  61. ]);
  62. try {
  63. $services->storeProductOrderUserTakeDelivery($order);
  64. } catch (\Throwable $e) {
  65. Log::error('自动收货消息队列执行成功,收货后置动作失败,失败原因:' . $e->getMessage());
  66. }
  67. return $res;
  68. }
  69. }