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']] ]; $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]); } }); } }