0]; $where[] = ['create_time', '<', time() - 600]; // 10分钟前创建的订单 // 删除10分钟未支付的订单 $oid = StoreOrder::where($where)->column('id'); // 删除时间设置为当前时间,即删除 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 = []; $updateDataTwo = []; foreach ($arr as $v) { $updateData[] = [ 'id' => $v['branch_product_id'], 'sales' => ['dec', $v['cart_num']], 'stock' => ['inc', $v['cart_num']], ]; $updateDataTwo[] = [ 'id' => $v['product_id'], 'sales' => ['dec', $v['cart_num']] ]; } (new StoreBranchProduct())->saveAll($updateData); (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]); } }); //每10秒执行一次 new Crontab('*/10 * * * * *', function () { $select=Db::name('wechat_micropay')->limit(100)->select(); $pay = new PayService(); foreach ($select as $k=>$v) { $time = time(); if ($time - $v['create_time'] > 60){ Db::name('wechat_micropay')->where('id',$v['id'])->delete(); continue; } $order = [ 'out_trade_no' => $v['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); }else{ PayNotifyLogic::handle('wechat_common', $res['out_trade_no'], $res); } } } }); } }