joe 3 years ago
parent
commit
57ca0bcf46
3 changed files with 21 additions and 4 deletions
  1. 5 2
      crmeb/subscribes/TimerSubscribe.php
  2. 1 1
      tw/command/Maintain.php
  3. 15 1
      tw/lib/robot/Robots.php

+ 5 - 2
crmeb/subscribes/TimerSubscribe.php

@@ -15,6 +15,7 @@ use tw\async\activities\LuckyExtACalc;
 use tw\async\activities\LuckyExtBCalc;
 use think\facade\Db;
 use app\admin\model\system\SystemLog;
+use tw\command\Maintain;
 
 /**
  * 定时任务类
@@ -93,8 +94,8 @@ class TimerSubscribe
         
         // 缓存排行榜
         if (intval($tm['tm_min']) % 5 == 0) {
-            $ctl = new UserBoardController();
-            $ctl->cache_board();
+            // $ctl = new UserBoardController();
+            // $ctl->cache_board();
             // TODO: for testing, remove line below
             // SystemCarousel::add('who will win next race?', '/pages/leader_board/index');
         }
@@ -113,6 +114,8 @@ class TimerSubscribe
             if (intval($tm['tm_hour']) == 0) {
                 SystemLog::deleteLog();
                 warnlog('onTimer_60() remove outdated admin logs');
+
+                // 删过期商品
             }
         }
     }

+ 1 - 1
tw/command/Maintain.php

@@ -262,7 +262,7 @@ class Maintain extends Command
     /**
      * 让一定时间之前的商品下架
      */
-    protected function prod()
+    public function prod()
     {
         $now = time();
         $days = sys_config_int('off_days_before');

+ 15 - 1
tw/lib/robot/Robots.php

@@ -177,6 +177,11 @@ class Robots
             self::build();
         }
 
+        if (count(self::$robots) <= 0) {
+            errlog('build robots failed?');
+            return;
+        }
+
         foreach (self::$robots as $robot) {
             (new RobotsInfoRds)->hset(false, $robot['uid'], $robot);
         }
@@ -201,9 +206,14 @@ class Robots
      */
     public static function order()
     {
-        if (!self::$robots) {
+        if (count(self::$robots) <= 0) {
             self::from_redis();
         }
+
+        if (count(self::$robots) <= 0) {
+            errlog("load robots from redis failed.");
+            return;
+        }
         // 下单人数
         $robot_num = tw_rand(0, count(self::$robots) / 2);
 
@@ -214,6 +224,8 @@ class Robots
             $min = $max;
             $max = $t;
         }
+        debuglog("there will be $robot_num robot making order. will earn: min=$min,max=$max");
+        
         for ($i = 0; $i < $robot_num; $i++) {
             // 下单人UID
             $index = tw_rand(0, count(self::$robots));
@@ -230,6 +242,8 @@ class Robots
             $robot['value'] = tw_addf($robot['value'], $value, 2);
 
             (new RobotsInfoRds)->hset(false, $uid, $robot);
+
+            debuglog("robot $uid order win $value");
         }
     }