浏览代码

no message

panghu 7 月之前
父节点
当前提交
3febe9caa3
共有 1 个文件被更改,包括 18 次插入 和 17 次删除
  1. 18 17
      app/Console/Commands/CheckOrderExpire.php

+ 18 - 17
app/Console/Commands/CheckOrderExpire.php

@@ -41,25 +41,26 @@ class CheckOrderExpire extends Command
      */
      */
     public function handle()
     public function handle()
     {
     {
-        $date = date('Y-m-d H:i:s', time() - 1800);//30分钟
+        while (true){
+            $date = date('Y-m-d H:i:s', time() - 1800);//30分钟
 
 
-        Order::where('order_status', 1)
-            ->where('created_at', '<=', $date)
-            ->chunkById(100,function ($list){
-                foreach ($list as $item){
-                    DB::beginTransaction();
-                    try {
-                        //取消订单
-                        Order::where('id',$item->{'id'})->update(['order_status'=>3]);
+            Order::where('order_status', 1)
+                ->where('created_at', '<=', $date)
+                ->chunkById(100,function ($list){
+                    foreach ($list as $item){
+                        DB::beginTransaction();
+                        try {
+                            //取消订单
+                            Order::where('id',$item->{'id'})->update(['order_status'=>3]);
 
 
-                        DB::commit();
-                    }catch (\Exception $e){
-                        DB::rollBack();
-                    }
-
-                }
-            });
+                            DB::commit();
+                        }catch (\Exception $e){
+                            DB::rollBack();
+                        }
 
 
-        return true;
+                    }
+                });
+            sleep(5);
+        }
     }
     }
 }
 }