OrderPayed.php
1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
namespace addons\shopro\job;
use addons\shopro\library\traits\ActivityCache;
use addons\shopro\library\traits\Groupon;
use addons\shopro\library\traits\StockSale;
use addons\shopro\model\GoodsComment;
use addons\shopro\model\Order;
use addons\shopro\model\OrderAction;
use addons\shopro\model\OrderItem;
use think\queue\Job;
/**
* 订单支付完成
*/
class OrderPayed extends BaseJob
{
use StockSale, ActivityCache, Groupon;
/**
* 订单支付完成
*/
public function payed(Job $job, $data){
try {
$order = $data['order'];
$user = $data['user'];
$order = Order::with('item')->where('id', $order['id'])->find();
\think\Db::transaction(function () use ($order, $user, $data) {
// 订单减库存
$this->realForwardStockSale($order);
// 判断,如果是拼团 真实加入团
if (strpos($order['activity_type'], 'groupon') !== false) {
$this->joinGroupon($order, $user);
}
// 检测有没有自动发货的商品,有就自动发货
$order->checkDispatchAndSend($order, ['user' => $user]);
// 触发订单支付完成事件
$data = ['order' => $order];
\think\Hook::listen('order_payed_after', $data);
});
// 删除 job
$job->delete();
} catch (\Exception $e) {
// 队列执行失败
\think\Log::write('queue-' . get_class() . '-payed' . ':执行失败,错误信息:' . $e->getMessage());
}
}
}