From c3bca1b8a12027978ede12b17706015b5d2c2afc Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Mon, 22 Jul 2024 17:38:57 +0800 Subject: [PATCH] =?UTF-8?q?feat(process/Task.php):=20=E8=B0=83=E6=95=B4?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E8=B0=83=E5=BA=A6=EF=BC=8C=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E5=AE=9A=E6=97=B6=E4=BB=BB=E5=8A=A1=E5=A4=84=E7=90=86=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/queue/redis/TaskRechargeQuerySend.php | 44 +++++++++++++++++++++++ process/Task.php | 23 ++++++++++-- 2 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 app/queue/redis/TaskRechargeQuerySend.php diff --git a/app/queue/redis/TaskRechargeQuerySend.php b/app/queue/redis/TaskRechargeQuerySend.php new file mode 100644 index 00000000..e42d4d6e --- /dev/null +++ b/app/queue/redis/TaskRechargeQuerySend.php @@ -0,0 +1,44 @@ + $data['order_id'], + ]; + $res = $pay->wechat->query($order); + if ($res['trade_state'] == 'SUCCESS' && $res['trade_state_desc'] == '支付成功') { + if(isset($data['pay_type']) && $data['pay_type']=='recharge'){ + PayNotifyLogic::handle('recharge', $res['out_trade_no'], $res); + } + } + } + // 消费失败时 + public function onConsumeFailure(\Throwable $exception, $package) + { + return $package; + } +} diff --git a/process/Task.php b/process/Task.php index 2fe2a653..789c98e8 100644 --- a/process/Task.php +++ b/process/Task.php @@ -6,6 +6,8 @@ use app\common\model\store_branch_product\StoreBranchProduct; use app\common\model\store_order\StoreOrder; use app\common\model\store_order_cart_info\StoreOrderCartInfo; use app\common\model\store_product\StoreProduct; +use app\common\model\user_recharge\UserRecharge; +use Webman\RedisQueue\Redis; use Workerman\Crontab\Crontab; class Task @@ -13,13 +15,13 @@ class Task public function onWorkerStart() { - // 每5分钟执行一次 + // 每10分钟执行一次 new Crontab('0 */10 * * * *', function () { $where = ['paid' => 0]; $where[] = ['create_time', '<', time() - 600]; // 10分钟前创建的订单 // 删除10分钟未支付的订单 $oid = StoreOrder::where($where)->column('id'); // 删除时间设置为当前时间,即删除 - if($oid){ + if ($oid) { StoreOrder::where('id', 'in', $oid)->update(['delete_time' => time()]); $arr = StoreOrderCartInfo::where('oid', 'in', $oid)->field('store_id,product_id,cart_num')->select(); $updateData = []; @@ -38,6 +40,23 @@ class Task (new StoreProduct())->saveAll($updateDataTwo); } + // 获取当前时间 + $now = time(); + // 计算一个小时前的时间戳 + $oneHourAgo = $now - 3600; + //删除未充值的订单 + UserRecharge::where('paid', 0)->where('status', 1)->where('create_time', '<', $oneHourAgo)->update(['delete_time' => time()]); + }); + + new Crontab('0 */1 * * * *', function () { + $endTime = time(); + + // 计算10分钟前的时间戳 + $startTime = $endTime - 10 * 60; + $arr = UserRecharge::where('paid', 0)->where('status', 1)->whereBetweenTime('create_time', $startTime, $endTime)->column('order_id'); + foreach ($arr as $v) { + Redis::send('task-recharge-query', ['order_id' => $v]); + } }); } }