commit | author | age
|
90c639
|
1 |
<?php |
Z |
2 |
/** |
|
3 |
* Created by PhpStorm. |
|
4 |
* User: 风哀伤 |
|
5 |
* Date: 2019/2/14 |
|
6 |
* Time: 16:10 |
|
7 |
* @copyright: ©2019 浙江禾匠信息科技 |
|
8 |
* @link: http://www.zjhejiang.com |
|
9 |
*/ |
|
10 |
|
|
11 |
namespace app\jobs; |
|
12 |
|
|
13 |
use app\events\OrderEvent; |
|
14 |
use app\models\Mall; |
|
15 |
use app\models\Order; |
|
16 |
use app\models\OrderRefund; |
|
17 |
use yii\base\Component; |
|
18 |
use yii\helpers\ArrayHelper; |
|
19 |
use yii\queue\JobInterface; |
|
20 |
|
|
21 |
class OrderSalesJob extends BaseJob implements JobInterface |
|
22 |
{ |
|
23 |
public $orderId; |
|
24 |
|
|
25 |
public function execute($queue) |
|
26 |
{ |
|
27 |
\Yii::error('order sales job->>' . $this->orderId); |
|
28 |
$this->setRequest(); |
|
29 |
$order = Order::findOne([ |
|
30 |
'id' => $this->orderId, |
|
31 |
'is_delete' => 0, |
|
32 |
'is_send' => 1, |
|
33 |
'is_confirm' => 1, |
|
34 |
'is_sale' => 0, |
|
35 |
]); |
|
36 |
if (!$order) { |
|
37 |
$newOrder = Order::findOne($this->orderId); |
|
38 |
$array = $newOrder ? ArrayHelper::toArray($newOrder) : []; |
|
39 |
\Yii::warning('创建自动过售后,订单不存在'); |
|
40 |
\Yii::warning($array); |
|
41 |
return false; |
|
42 |
} |
|
43 |
$mall = Mall::findOne(['id' => $order->mall_id]); |
|
44 |
\Yii::$app->setMall($mall); |
|
45 |
|
|
46 |
$orderRefundList = OrderRefund::find()->where(['order_id' => $order->id, 'is_delete' => 0])->all(); |
|
47 |
if ($orderRefundList) { |
|
48 |
/* @var OrderRefund[] $orderRefundList */ |
|
49 |
foreach ($orderRefundList as $orderRefund) { |
|
50 |
if ($orderRefund->status != 3 && in_array($orderRefund->type, [1, 3]) && $orderRefund->is_refund == 0) { |
|
51 |
return false; |
|
52 |
} else if ($orderRefund->status != 3 && $orderRefund->type == 2 && $orderRefund->is_confirm == 0) { |
|
53 |
return false; |
|
54 |
} |
|
55 |
} |
|
56 |
} |
|
57 |
|
|
58 |
$order->is_sale = 1; |
|
59 |
if ($order->save()) { |
|
60 |
$event = new OrderEvent([ |
|
61 |
'order' => $order, |
|
62 |
]); |
|
63 |
\Yii::$app->trigger(Order::EVENT_SALES, $event); |
|
64 |
} |
|
65 |
} |
|
66 |
} |