xxxrrrdddd il y a 3 ans
Parent
commit
3ecb091b48

+ 3 - 3
commands/mobile_activity.php

@@ -1,12 +1,13 @@
 <?php
 use app\common\model\Mobile;
+use Workerman\Lib\Timer;
 use Workerman\Worker as WO;
 
 class MobileActivity extends Com{
     public static function run(){
         $work=new WO();
         $work->onWorkerStart=function (WO $worker){
-            while (true){
+            Timer::add(3,function (){
                 $ids=Mobile::where('activity_time_end','<=',time())
                     ->where('is_activity',1)
                     ->where('type',1)
@@ -16,8 +17,7 @@ class MobileActivity extends Com{
                     $mobile=Mobile::find($id);
                     $mobile->makeNotActivity();
                 }
-                sleep(3);
-            }
+            });
         };
     }
 }

+ 3 - 3
commands/mobile_order_expired.php

@@ -2,6 +2,7 @@
 use app\common\model\MobileOrder;
 use think\Db;
 use think\Log;
+use Workerman\Lib\Timer;
 use Workerman\Worker as WO;
 
 class MobileOrderExpired extends Com{
@@ -9,7 +10,7 @@ class MobileOrderExpired extends Com{
     {
         $work=new WO();
         $work->onWorkerStart=function ($conn){
-            while (true){
+            Timer::add(3,function (){
                 $orders= MobileOrder::expired()->field('id')->select();
                 self::log(sprintf('%d条数据',count($orders)));
                 foreach ($orders as $order){
@@ -23,8 +24,7 @@ class MobileOrderExpired extends Com{
                         Log::error("关闭订单[$order->id]失败:{$e->getMessage()}");
                     }
                 }
-                sleep(3);
-            }
+            });
         };
     }
 }

+ 3 - 3
commands/mobile_order_unpay_notify.php

@@ -2,6 +2,7 @@
 use app\common\model\MobileOrder;
 use app\common\service\SmsSend;
 
+use Workerman\Lib\Timer;
 use Workerman\Worker as WO;
 
 class MobileOrderUnPayNotify extends Com{
@@ -9,7 +10,7 @@ class MobileOrderUnPayNotify extends Com{
     {
         $work=new WO();
         $work->onWorkerStart=function ($conn){
-            while (true){
+            Timer::add(1,function (){
                 $orders= MobileOrder::waitPay()
                     ->where('type',1)
                     ->whereRaw('create_time+300<'.time())
@@ -30,8 +31,7 @@ class MobileOrderUnPayNotify extends Com{
                         self::logError($e);
                     }
                 }
-                sleep(1);
-            }
+            });
         };
     }