stanley-king 2 gadi atpakaļ
vecāks
revīzija
67d8392663

+ 64 - 3
crontab/control/minutes.php

@@ -7,6 +7,8 @@
  *
  */
 
+use refill\PolicyUtil;
+
 defined('InShopNC') or exit('Access Invalid!');
 
 require_once (BASE_ROOT_PATH . '/helper/message/publisher.php');
@@ -443,8 +445,10 @@ class minutesControl extends BaseCronControl
         while (true)
         {
             try {
-                $this->_stat_util();
+                $this->_update_earlist_send();
                 $this->_calc_arrears();
+                $this->_update_mixed_cfg();
+
             } catch (Exception $ex) {
                 Log::record($ex->getMessage(), Log::ERR);
             }
@@ -453,9 +457,9 @@ class minutesControl extends BaseCronControl
         }
     }
 
-    private function _stat_util()
+    private function _update_earlist_send()
     {
-        //查找最早的充值中的单子
+        //查找最早的充值中的订单时间
 //        $update_earliest_ordertime = function () {
 //            $mod = Model('refill_detail');
 //            $time = $mod->getEarliestSendTime();
@@ -463,6 +467,7 @@ class minutesControl extends BaseCronControl
 //        };
 //        $update_earliest_ordertime();
 
+        //按各个机构,更新最早的充值中的订单时间
         $update_earliest_ordertime_bymerchant = function () {
             $mod = Model('refill_detail');
             $mtimes = $mod->getEarliestSendTimeByMerchant();
@@ -612,6 +617,62 @@ class minutesControl extends BaseCronControl
         }
     }
 
+    private function _update_mixed_cfg()
+    {
+        $read_cfg = function ($cfg)
+        {
+            $lower_ratio = $cfg['lower_ratio'] ?? [];
+            if (empty($lower_ratio)) {
+                [$ratio, $period] = [0.0, 3600];
+            } else {
+                [$ratio, $period] = [$lower_ratio['ratio'], $lower_ratio['period']];
+            }
+
+            $profit_ratio = $cfg['profit_ratio'] ?? 0.0;
+            $profit_formula = $cfg['profit_formula'] ?? 'qts';
+
+            return ['ratio' => $ratio, 'period' => $period, 'profit_ratio' => $profit_ratio, 'profit_formula' => $profit_formula];
+        };
+
+        $mch_configs = function () use ($read_cfg)
+        {
+            $result = [];
+
+            $i = 0;
+            while (true)
+            {
+                $start = $i * 100;
+                $items = Model()->table('merchant')->where(['mchid' => ['gt', 0], 'merchant_state' => 1])->field('mchid,retry_times_cfg,quality')->order('mchid asc')->limit("{$start},100")->select();
+                if(empty($items)) {
+                    break;
+                }
+                $i++;
+
+                foreach ($items as $item)
+                {
+                    $mchid = intval($item['mchid']);
+                    $quality = intval($item['quality']);
+                    if($mchid <= 0 || $quality <= 0) continue;
+                    if (!PolicyUtil::mixed_quality($quality)) {
+                        continue;
+                    }
+
+                    $retry_times_cfg = unserialize($item['retry_times_cfg']);
+                    if(empty($retry_times_cfg)) continue;
+
+
+                    $result[$mchid] = $read_cfg($retry_times_cfg);
+                }
+            }
+
+            return $result;
+        };
+
+        $result = $mch_configs();
+        $val = json_encode($result);
+        wkcachex('stat-merchant-mixed', $val, 'refill-');
+    }
+
     /**
      * 执行通用任务
      */

+ 1 - 1
docker/compose/stanmac/admin/docker-compose.yml

@@ -16,7 +16,7 @@ services:
     command: [docker-spwan-start]
 
   websrv:
-      image: php-fpm:alpine
+      image: php-fpm-ex:alpine
       ports:
         - "9000:9000"
       volumes:

+ 2 - 2
docker/compose/workcuda/admin/docker-compose.yml

@@ -20,9 +20,9 @@ services:
           cpus: '8'
 
   websrv:
-    image: php-fpm:alpine
+    image: php-fpm-ex:alpine
     ports:
-      - "9000:9000"
+      - 9000:9000
     volumes:
       - ../../../../:/var/www/html
       - ../conf/etc/localtime:/etc/localtime:ro

+ 48 - 5
plot/refill/MerchantCalc.py

@@ -42,6 +42,18 @@ def earliest_time(rclient: redis.client):
     else:
         return result, min_time
 
+def mixed_ratio(rclient: redis.client):
+    result = list()
+    data = rclient.get('nc_refill-stat-merchant-mixed')
+    if data is not None:
+        mch_cfgs = json.loads(data)
+        for mchid,val in mch_cfgs.items():
+            mchid = int(mchid)
+            period = int(val['period'])
+            formula = val['profit_formula'].strip()
+            result.append((mchid, period, formula))
+    return result
+
 
 class MerchantCalc(object):
     def __init__(self):
@@ -60,20 +72,39 @@ class MerchantCalc(object):
             client = redis.Redis(connection_pool=pool)
             return client
 
+        def calc_send_amounts(client):
+            send_amounts = self._send_amounts(client)
+            val = json.dumps({'send_amounts': send_amounts, 'time': int(time.time())})
+            client.set('nc_refill-stat-merchant-sendamount',val)
+            pass
+
+        def calc_profit_ratio(client):
+            profit_ratio = self._profit_ratio(client)
+            pass
+
         client = None
+        loop = 0;
         while self._mQuit == False:
             try:
                 if client is None:
                     client = redis_client()
-                send_amounts = self._send_amounts(client)
-                val = json.dumps({'send_amounts': send_amounts, 'time': int(time.time())})
-                client.set('nc_refill-stat-merchant-sendamount',val)
+
+                #每10秒计算一次欠费金额
+                # if loop % 10 == 0:
+                #     calc_send_amounts(client)
+
+                if loop % 2 == 0:
+                    calc_profit_ratio(client)
+                    pass
+
             except redis.RedisError as ex:
                 logger.error(ex)
             except Exception as ex:
                 logger.error(ex)
             finally:
-                time.sleep(10)
+                time.sleep(1)
+                loop += 1
+
 
     def calc_time(self, start_time: int, end_time: int):
         reader = MerchantReader()
@@ -130,4 +161,16 @@ class MerchantCalc(object):
             result[_mchid] = {'send_amounts': _send_amounts, 'lack_amounts': _lack_amounts}
 
         logger.debug(result)
-        return result
+        return result
+
+    def _profit_ratio(self, rclient):
+        mixed_ratios = mixed_ratio(rclient)
+
+        for mchid, period, formula in mixed_ratios:
+            end_time = int(time.time())
+            reader, days, start_time, end_time = self.calc_time(end_time - period, end_time)
+            day_stamp = days[0]
+            tuple_pathes = reader.many_tuple_path(days, mchids={mchid})
+            gen = detail_paths(reader, tuple_pathes, days)
+
+        pass