正在显示
2 个修改的文件
包含
56 行增加
和
0 行删除
application/api/job/BaseJob.php
0 → 100644
1 | +<?php | ||
2 | + | ||
3 | +namespace app\api\job; | ||
4 | + | ||
5 | +use think\queue\Job; | ||
6 | + | ||
7 | + | ||
8 | +/** | ||
9 | + * BaseJob 基类 | ||
10 | + */ | ||
11 | +class BaseJob | ||
12 | +{ | ||
13 | + | ||
14 | + public function failed($data){ | ||
15 | + // 记录日志 | ||
16 | + \think\Db::name('jobs_failed')->insert([ | ||
17 | + 'data' => json_encode($data), | ||
18 | + 'createtime' => time(), | ||
19 | + 'updatetime' => time() | ||
20 | + ]); | ||
21 | + } | ||
22 | + | ||
23 | +} |
application/api/job/OrderAutoOper.php
0 → 100644
1 | +<?php | ||
2 | + | ||
3 | +namespace app\api\job; | ||
4 | + | ||
5 | +use think\queue\Job; | ||
6 | + | ||
7 | + | ||
8 | +/** | ||
9 | + * 发送优惠券自动操作 | ||
10 | + */ | ||
11 | +class OrderAutoOper extends BaseJob | ||
12 | +{ | ||
13 | + /** | ||
14 | + * 订单自动关闭 | ||
15 | + */ | ||
16 | + public function autoClose(Job $job, $data){ | ||
17 | + try { | ||
18 | + $order_id = $data['order_id']; | ||
19 | + $order = \app\api\model\Order::get($order_id); | ||
20 | + if ($order && $order['pay_status'] == '10' && $order['order_status'] == '10') { | ||
21 | + \think\Db::transaction(function () use ($order) { | ||
22 | + (new \app\api\controller\Order)->cancelOrderAction($order); | ||
23 | + }); | ||
24 | + } | ||
25 | + | ||
26 | + // 删除 job | ||
27 | + $job->delete(); | ||
28 | + } catch (\Exception $e) { | ||
29 | + // 队列执行失败 | ||
30 | + \think\Log::write('queue-' . get_class() . '-autoClose' . ':执行失败,错误信息:' . $e->getMessage()); | ||
31 | + } | ||
32 | + } | ||
33 | +} |
-
请 注册 或 登录 后发表评论