123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- <?php
- // +----------------------------------------------------------------------
- // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
- // +----------------------------------------------------------------------
- // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
- // +----------------------------------------------------------------------
- // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
- // +----------------------------------------------------------------------
- // | Author: CRMEB Team <admin@crmeb.com>
- // +----------------------------------------------------------------------
- namespace app\jobs\order;
- use app\services\order\StoreOrderServices;
- use app\services\order\StoreOrderStatusServices;
- use app\services\order\StoreOrderTakeServices;
- use crmeb\basic\BaseJobs;
- use crmeb\traits\QueueTrait;
- use think\facade\Log;
- /**
- * 自动收货消息队列
- * Class TakeOrderJob
- * @package app\jobs
- */
- class TakeOrderJob extends BaseJobs
- {
- use QueueTrait;
- /**
- * @param $id
- * @return bool
- */
- public function doJob($id)
- {
- /** @var StoreOrderTakeServices $services */
- $services = app()->make(StoreOrderTakeServices::class);
- $orderInfo = $services->get($id);
- if (!$orderInfo) {
- return true;
- }
- if (!$orderInfo->paid) {
- return true;
- }
- if ($orderInfo->status == 2) {
- return true;
- }
- if ($orderInfo->refund_status == 2) {
- return true;
- }
- /** @var StoreOrderServices $orderServices */
- $orderServices = app()->make(StoreOrderServices::class);
- $order = $orderServices->tidyOrder($orderInfo);
- if ($order['_status']['_type'] != 2) {
- return true;
- }
- $orderInfo->status = 2;
- /** @var StoreOrderStatusServices $statusService */
- $statusService = app()->make(StoreOrderStatusServices::class);
- $res = $orderInfo->save() && $statusService->save([
- 'oid' => $orderInfo['id'],
- 'change_type' => 'take_delivery',
- 'change_message' => '已收货[自动收货]',
- 'change_time' => time()
- ]);
- try {
- $services->storeProductOrderUserTakeDelivery($order);
- } catch (\Throwable $e) {
- Log::error('自动收货消息队列执行成功,收货后置动作失败,失败原因:' . $e->getMessage());
- }
- return $res;
- }
- }
|