Parcourir la source

增加延时队列

stanley-king il y a 4 ans
Parent
commit
6a69587a5f

+ 2 - 2
core/framework/libraries/queue.php

@@ -29,10 +29,10 @@ class QueueClient
     {
         if($period_secs > 0) {
             $model_cron = Model('cron');
-            $model_cron->addCron(['params' => serialize([$key=>$value]),'type' => 8,'exeid' => 0,'exetime' => time() + $period_secs]);
+            return $model_cron->addCron(['params' => serialize([$key=>$value]),'type' => 8,'exeid' => 0,'exetime' => time() + $period_secs]);
         }
         else {
-            self::push($key,$value);
+            return self::push($key,$value);
         }
     }
 }

+ 13 - 4
crontab/control/minutes.php

@@ -18,7 +18,7 @@ class minutesControl extends BaseCronControl
         Log::record(__FUNCTION__ . " start",Log::DEBUG);
         //未付款订单超期自动关闭
         $this->_order_timeout_cancel();
-        $this->_cron_common();
+        $this->_cron_common([1,2,3,4,5,6,7]);
         $this->_web_index_update();
         $this->_check_merchant_alarm_amount();
         $this->check_refill_order_limit();
@@ -262,15 +262,23 @@ class minutesControl extends BaseCronControl
         }
     }
 
+    public function second_queueOp()
+    {
+        while (true) {
+            $this->_cron_common([8]);
+            sleep(1);
+        }
+    }
+
     /**
      * 执行通用任务
      */
-    private function _cron_common()
+    private function _cron_common($types)
     {
         Log::record(__FUNCTION__,Log::DEBUG);
         //查找待执行任务
         $model_cron = Model('cron');
-        $cron = $model_cron->getCronList(['exetime'=> ['elt',time()]]);
+        $cron = $model_cron->getCronList(['exetime'=> ['elt',time()],'type' => ['in',$types]]);
         if (!is_array($cron)) return ;
 
         $cron_array = [];
@@ -288,6 +296,7 @@ class minutesControl extends BaseCronControl
                 $cron_array[$v['type']][$v['exeid']] = $v;
             }
         }
+
         foreach ($cron_array as $k=>$v)
         {
             // 如果方法不存是,直接删除id
@@ -298,7 +307,7 @@ class minutesControl extends BaseCronControl
             }
 
             $method = '_cron_'.$k;
-            Log::record("crontab minutest err:{$method}",Log::DEBUG);
+            Log::record("crontab minutest:{$method}",Log::DEBUG);
 
             $result = call_user_func_array([$this,'_cron_'.$k], [$v]);
             if (is_array($result)){

+ 11 - 0
docker/compose/lz-acc/docker-compose.yml

@@ -107,6 +107,17 @@ services:
     depends_on:
       - "redisrv"
 
+  cronsec:
+    image: php-zts-debug:7.3.18
+    volumes:
+      - ../../conf/etc/localtime:/etc/localtime:ro
+      - ../../../:/var/www/html
+      - /nfs/upload:/var/www/html/data/upload
+      - /mnt/shoplog:/var/www/html/data/log
+      - ../../conf/php/lz-php.ini:/usr/local/etc/php/php.ini
+    container_name: "panda-cronsec"
+    command: [php,"/var/www/html/crontab/index.php",'minutes','second_queue']
+
   phpcli:
     image: php-zts-debug:7.3.18
     volumes:

+ 11 - 0
docker/compose/stanley/docker-compose.yml

@@ -150,6 +150,17 @@ services:
       depends_on:
         - "redisrv"
 
+  cronsec:
+    image: php-zts-debug:7.3.18
+    volumes:
+      - ../../conf/etc/localtime:/etc/localtime:ro
+      - ../../../:/var/www/html
+      - /Volumes/Transcend/upload:/var/www/html/data/upload
+      - /Users/stanley-king/work/PHPProject/shoplog:/var/www/html/data/log
+      - ../../conf/php/php-local-debug.ini:/usr/local/etc/php/php.ini
+    container_name: "panda-cronsec"
+    command: [php,"/var/www/html/crontab/index.php",'minutes','second_queue']
+
   phpcli:
     image: php-zts-debug:7.3.18
     volumes:

+ 11 - 0
docker/compose/xyz-acc/docker-compose.yml

@@ -91,6 +91,17 @@ services:
     depends_on:
       - "redisrv"
 
+  cronsec:
+    image: php-zts-debug:7.3.18
+    volumes:
+      - ../../conf/etc/localtime:/etc/localtime:ro
+      - ../../../:/var/www/html
+      - /nfs/upload:/var/www/html/data/upload
+      - /mnt/shoplog:/var/www/html/data/log
+      - ../../conf/php/xyz-php.ini:/usr/local/etc/php/php.ini
+    container_name: "panda-cronsec"
+    command: [php,"/var/www/html/crontab/index.php",'minutes','second_queue']
+
   wsdsrv:
     image: php-zts-debug:7.3.18
     ports:

+ 1 - 1
helper/refill/policy/xyz/policy.php

@@ -218,7 +218,7 @@ class policy extends ProviderManager implements IPolicy
 
     private function sms($refill_info)
     {
-        $mchids = [10116];
+        $mchids = [1090,10116];
         $mchid = $refill_info['mchid'];
         $official_sn = $refill_info['official_sn'] ?? "";
         $card_type = $refill_info['card_type'];

+ 30 - 2
helper/refill/util.php

@@ -50,6 +50,34 @@ class util
         }
     }
 
+    public static function can_commit($card_no, $card_type)
+    {
+        if ($card_type == mtopcard\SinopecCard || $card_type == mtopcard\PetroChinaCard)
+        {
+            $result = rcache('card_expired', '', "{$card_no}");
+            if (empty($result)) {
+                wcache("card_expired", [$card_no => time()], '');
+                return [true, 0];
+            }
+            else
+            {
+                $latest = current($result);
+                $cur = time();
+
+                if ($cur > $latest && ($cur - $latest) >= 2) {
+                    wcache("card_expired", [$card_no => time()], '');
+                    return [true, 0];
+                } else {
+                    wcache("card_expired", [$card_no => $latest + 2], '');
+                    return [false, $latest + 2 - $cur];
+                }
+            }
+        }
+        else {
+            return [true, 0];
+        }
+    }
+
     static function read_card($card_no, $card_type = 0)
     {
         if (empty($card_no)) return false;
@@ -169,10 +197,10 @@ class util
         return true;
     }
 
-    public static function async_add($method, $params)
+    public static function async_add($method, $params,$period = 10)
     {
         try {
-            QueueClient::async_push("AysncAddDispatcher", ['method' => $method, 'params' => $params], 10);
+            QueueClient::async_push("AysncAddDispatcher", ['method' => $method, 'params' => $params], $period);
             return true;
         } catch (Exception $ex) {
             return false;

+ 10 - 11
mobile/control/refill.php

@@ -83,12 +83,6 @@ class refillControl extends merchantControl
         $card_type = mtopcard\simple_card_type($card_no);
         if($card_type === mtopcard\SinopecCard || $card_type === mtopcard\PetroChinaCard)
         {
-            [$can_refill,$period] = refill\util::can_refill($card_no,$card_type);
-            if($can_refill === false) {
-                Log::record("请{$card_no}至少在{$period}秒后再试.");
-                return self::outerr(208,"请{$card_no}至少在{$period}秒后再试.");
-            }
-
             if(!$this->can_refill($card_no)) {
                 return self::outerr(206,"平台不支持该卡充值.");
             }
@@ -114,13 +108,18 @@ class refillControl extends merchantControl
             'notify_url' => $notify_url,
             'org_quality' => $quality];
 
-        $state = refill\util::push_add($params);
-        if($state === true) {
-            return self::outsuccess(['state' => true]);
+        [$can_refill, $period] = refill\util::can_commit($card_no, $card_type);
+        if ($can_refill === false) {
+            $state = refill\util::async_add($params, $period, $period);
+        } else {
+            $state = refill\util::push_add($params);
         }
-        else {
+
+        if ($state === true) {
+            return self::outsuccess(['state' => true]);
+        } else {
             $code = $state;
-            return self::outerr($code,'提交失败');
+            return self::outerr($code, '提交失败');
         }
     }