浏览代码

fix merge

stanley-king 4 年之前
父节点
当前提交
e5b9cd5f60

+ 10 - 8
admin/control/merchant.php

@@ -812,6 +812,10 @@ class merchantControl extends SystemControl
             $condition['refill_order.ch_trade_no'] = $_GET['ch_trade_no'];
             $condition['refill_order.ch_trade_no'] = $_GET['ch_trade_no'];
             $fSingle = true;
             $fSingle = true;
         }
         }
+        if (!empty($_GET['card_no'])) {
+            $condition['refill_order.card_no'] = $_GET['card_no'];
+            $fSingle = true;
+        }
 
 
         if (!empty($_GET['mchid'])) {
         if (!empty($_GET['mchid'])) {
             $condition['refill_order.mchid'] = $_GET['mchid'];
             $condition['refill_order.mchid'] = $_GET['mchid'];
@@ -826,11 +830,10 @@ class merchantControl extends SystemControl
             $condition['refill_order.refill_amount'] = $_GET['refill_amount'];
             $condition['refill_order.refill_amount'] = $_GET['refill_amount'];
         }
         }
 
 
-        if (!empty($_GET['card_no'])) {
-            $condition['refill_order.card_no'] = $_GET['card_no'];
-        }
-        if (!empty($_GET['card_type'])) {
-            if (in_array($_GET['card_type'], ['1', '2', '4', '5', '6'])) {
+
+        if (!empty($_GET['card_type']))
+        {
+            if(in_array($_GET['card_type'] , ['1' , '2' , '4' , '5' , '6'])) {
                 $condition['refill_order.card_type'] = $_GET['card_type'];
                 $condition['refill_order.card_type'] = $_GET['card_type'];
             }
             }
             if ($_GET['card_type'] == 'oil') {
             if ($_GET['card_type'] == 'oil') {
@@ -842,7 +845,6 @@ class merchantControl extends SystemControl
         }
         }
 
 
         $fToday = false;
         $fToday = false;
-
         if (!$fSingle) {
         if (!$fSingle) {
             $start_unixtime = intval(strtotime($_GET['query_start_time']));
             $start_unixtime = intval(strtotime($_GET['query_start_time']));
             $end_unixtime = intval(strtotime($_GET['query_end_time']));
             $end_unixtime = intval(strtotime($_GET['query_end_time']));
@@ -919,7 +921,7 @@ class merchantControl extends SystemControl
         } else {
         } else {
             QueueClient::push("NotifyMerchantComplete", ['order_id' => $order_id, 'manual' => true]);
             QueueClient::push("NotifyMerchantComplete", ['order_id' => $order_id, 'manual' => true]);
         }
         }
-        showMessage('操作成功', 'index.php?act=merchant&op=refill_order');
+        showMessage('操作成功', '');
     }
     }
 
 
     public function notify_manual_merchantOp()
     public function notify_manual_merchantOp()
@@ -942,7 +944,7 @@ class merchantControl extends SystemControl
             showMessage('手动操作类型错误', 'index.php?act=merchant&op=refill_order');
             showMessage('手动操作类型错误', 'index.php?act=merchant&op=refill_order');
         }
         }
 
 
-        showMessage('操作成功', 'index.php?act=merchant&op=refill_order');
+        showMessage('操作成功', '');
     }
     }
 
 
     public function providerStatsOp()
     public function providerStatsOp()

+ 11 - 5
admin/templates/default/refill.order.index.php

@@ -174,29 +174,33 @@
                     <div style="display:inlin-block;background:none">
                     <div style="display:inlin-block;background:none">
                         <li class="lineLi" style="color:#000;">总计订单数量:<?php echo $output['stat']['all']['order_count'] ?? 0?></li>
                         <li class="lineLi" style="color:#000;">总计订单数量:<?php echo $output['stat']['all']['order_count'] ?? 0?></li>
                         <li class="lineLi" style="color:#000;">总计充值金额:<?php echo $output['stat']['all']['refill_amounts'] ?? 0?></li>
                         <li class="lineLi" style="color:#000;">总计充值金额:<?php echo $output['stat']['all']['refill_amounts'] ?? 0?></li>
-                        <li class="lineLi" style="color:#000;">总计供方扣款金额:<?php echo $output['stat']['all']['channel_amounts'] ?? 0?></li>
                         <li class="lineLi" style="color:#000;">总计客户扣款金额:<?php echo $output['stat']['all']['mch_amounts'] ?? 0?></li>
                         <li class="lineLi" style="color:#000;">总计客户扣款金额:<?php echo $output['stat']['all']['mch_amounts'] ?? 0?></li>
+                        <li class="lineLi" style="color:#000;">&nbsp;</li>
+                        <li class="lineLi" style="color:#000;">总计供方扣款金额:<?php echo $output['stat']['all']['channel_amounts'] ?? 0?></li>
                         <li class="lineLi" style="color:#000;">总计利润:<?php echo ncPriceFormat($output['stat']['all']['mch_amounts'] - $output['stat']['all']['channel_amounts'])?></li>
                         <li class="lineLi" style="color:#000;">总计利润:<?php echo ncPriceFormat($output['stat']['all']['mch_amounts'] - $output['stat']['all']['channel_amounts'])?></li>
                     </div>
                     </div>
                     <div style="display:inlin-block;background:none">
                     <div style="display:inlin-block;background:none">
                         <li class="lineLi" style="color:#000;">总计充值中订单数量:<?php echo $output['stat']['sending']['order_count'] ?? 0?></li>
                         <li class="lineLi" style="color:#000;">总计充值中订单数量:<?php echo $output['stat']['sending']['order_count'] ?? 0?></li>
                         <li class="lineLi" style="color:#000;">总计充值中订单金额:<?php echo $output['stat']['sending']['refill_amounts'] ?? 0?></li>
                         <li class="lineLi" style="color:#000;">总计充值中订单金额:<?php echo $output['stat']['sending']['refill_amounts'] ?? 0?></li>
-                        <li class="lineLi" style="color:#000;">总计充值中供方扣款金额:<?php echo $output['stat']['sending']['channel_amounts'] ?? 0?></li>
                         <li class="lineLi" style="color:#000;">总计充值中客户扣款金额:<?php echo $output['stat']['sending']['mch_amounts'] ?? 0?></li>
                         <li class="lineLi" style="color:#000;">总计充值中客户扣款金额:<?php echo $output['stat']['sending']['mch_amounts'] ?? 0?></li>
+                        <li class="lineLi" style="color:#000;">&nbsp;</li>
+                        <li class="lineLi" style="color:#000;">总计充值中供方扣款金额:<?php echo $output['stat']['sending']['channel_amounts'] ?? 0?></li>
                         <li class="lineLi" style="color:#000;">总计充值中利润:<?php echo ncPriceFormat($output['stat']['sending']['mch_amounts'] - $output['stat']['sending']['channel_amounts'])?></li>
                         <li class="lineLi" style="color:#000;">总计充值中利润:<?php echo ncPriceFormat($output['stat']['sending']['mch_amounts'] - $output['stat']['sending']['channel_amounts'])?></li>
                     </div>
                     </div>
                     <div style="display:inlin-block;background:none">
                     <div style="display:inlin-block;background:none">
                         <li class="lineLi" style="color:#000;">总计充值成功订单数量:<?php echo $output['stat']['success']['order_count'] ?? 0?></li>
                         <li class="lineLi" style="color:#000;">总计充值成功订单数量:<?php echo $output['stat']['success']['order_count'] ?? 0?></li>
                         <li class="lineLi" style="color:#000;">总计充值成功订单金额:<?php echo $output['stat']['success']['refill_amounts'] ?? 0?></li>
                         <li class="lineLi" style="color:#000;">总计充值成功订单金额:<?php echo $output['stat']['success']['refill_amounts'] ?? 0?></li>
-                        <li class="lineLi" style="color:#000;">总计充值成功供方扣款金额:<?php echo $output['stat']['success']['channel_amounts'] ?? 0?></li>
                         <li class="lineLi" style="color:#000;">总计充值成功客户扣款金额:<?php echo $output['stat']['success']['mch_amounts'] ?? 0?></li>
                         <li class="lineLi" style="color:#000;">总计充值成功客户扣款金额:<?php echo $output['stat']['success']['mch_amounts'] ?? 0?></li>
+                        <li class="lineLi" style="color:#000;">&nbsp;</li>
+                        <li class="lineLi" style="color:#000;">总计充值成功供方扣款金额:<?php echo $output['stat']['success']['channel_amounts'] ?? 0?></li>
                         <li class="lineLi" style="color:#000;">总计充值成功利润:<?php echo ncPriceFormat($output['stat']['success']['mch_amounts'] - $output['stat']['success']['channel_amounts'])?></li>
                         <li class="lineLi" style="color:#000;">总计充值成功利润:<?php echo ncPriceFormat($output['stat']['success']['mch_amounts'] - $output['stat']['success']['channel_amounts'])?></li>
                     </div>
                     </div>
                     <div style="display:inlin-block;background:none">
                     <div style="display:inlin-block;background:none">
                         <li class="lineLi" style="color:#000;">总计充值失败订单数量:<?php echo $output['stat']['cancel']['order_count'] ?? 0?></li>
                         <li class="lineLi" style="color:#000;">总计充值失败订单数量:<?php echo $output['stat']['cancel']['order_count'] ?? 0?></li>
                         <li class="lineLi" style="color:#000;">总计充值失败订单金额:<?php echo $output['stat']['cancel']['refill_amounts'] ?? 0?></li>
                         <li class="lineLi" style="color:#000;">总计充值失败订单金额:<?php echo $output['stat']['cancel']['refill_amounts'] ?? 0?></li>
-                        <li class="lineLi" style="color:#000;">总计充值失败供方扣款金额:<?php echo $output['stat']['cancel']['channel_amounts'] ?? 0?></li>
                         <li class="lineLi" style="color:#000;">总计充值失败客户扣款金额:<?php echo $output['stat']['cancel']['mch_amounts'] ?? 0?></li>
                         <li class="lineLi" style="color:#000;">总计充值失败客户扣款金额:<?php echo $output['stat']['cancel']['mch_amounts'] ?? 0?></li>
+                        <li class="lineLi" style="color:#000;">&nbsp;</li>
+                        <li class="lineLi" style="color:#000;">总计充值失败供方扣款金额:<?php echo $output['stat']['cancel']['channel_amounts'] ?? 0?></li>
                         <li class="lineLi" style="color:#000;">总计充值失败利润:<?php echo ncPriceFormat($output['stat']['cancel']['mch_amounts'] - $output['stat']['cancel']['channel_amounts'])?></li>
                         <li class="lineLi" style="color:#000;">总计充值失败利润:<?php echo ncPriceFormat($output['stat']['cancel']['mch_amounts'] - $output['stat']['cancel']['channel_amounts'])?></li>
                     </div>
                     </div>
                 </ul>
                 </ul>
@@ -218,10 +222,11 @@
             <th class="align-right">耗时</th>
             <th class="align-right">耗时</th>
             <th class="align-center">订单状态</th>
             <th class="align-center">订单状态</th>
             <th class="align-center">运营商流水号</th>
             <th class="align-center">运营商流水号</th>
-            <th class="align-center">失败原因</th>
+            <th class="align-center">备注</th>
             <th class="align-center">商家单号</th>
             <th class="align-center">商家单号</th>
             <th class="align-center">渠道单号</th>
             <th class="align-center">渠道单号</th>
             <th class="align-center">渠道名称</th>
             <th class="align-center">渠道名称</th>
+            <th class="align-center">次数</th>
             <th class="align-center">质量</th>
             <th class="align-center">质量</th>
             <th class="align-center">初始质量</th>
             <th class="align-center">初始质量</th>
             <th class="align-center">扣款金额</th>
             <th class="align-center">扣款金额</th>
@@ -261,6 +266,7 @@
                     <td class="align-left"><?php echo $order['mch_order']; ?></td>
                     <td class="align-left"><?php echo $order['mch_order']; ?></td>
                     <td class="align-left" class="ch_trade_no"><?php echo $order['ch_trade_no']; ?></td>
                     <td class="align-left" class="ch_trade_no"><?php echo $order['ch_trade_no']; ?></td>
                     <td class="align-center"><?php echo $order['channel_name']; ?></td>
                     <td class="align-center"><?php echo $order['channel_name']; ?></td>
+                    <td class="align-center"><?php echo $order['commit_times']; ?></td>
                     <td class="align-center"><?php echo $order['quality']; ?></td>
                     <td class="align-center"><?php echo $order['quality']; ?></td>
                     <td class="align-center"><?php echo $order['org_quality']; ?></td>
                     <td class="align-center"><?php echo $order['org_quality']; ?></td>
                     <td class="align-center"><?php echo $order['mch_amount']; ?></td>
                     <td class="align-center"><?php echo $order['mch_amount']; ?></td>

+ 12 - 3
core/framework/cache/cache.redis.php

@@ -164,7 +164,7 @@ class CacheRedis extends Cache
                 $value[1] = str_replace(' ', '', $value[1]);
                 $value[1] = str_replace(' ', '', $value[1]);
                 preg_match('/^[A-Za-z_]+([+-]\d+(\.\d+)?)$/',$value[1],$matches);
                 preg_match('/^[A-Za-z_]+([+-]\d+(\.\d+)?)$/',$value[1],$matches);
                 if (is_numeric($matches[1])) {
                 if (is_numeric($matches[1])) {
-                    $this->hIncrBy($name, $prefix, $key, $matches[1]);
+                    $this->hIncrByFloat($name, $prefix, $key, $matches[1]);
                 }
                 }
                 unset($data[$key]);
                 unset($data[$key]);
             }
             }
@@ -185,7 +185,7 @@ class CacheRedis extends Cache
         } elseif (strpos($key,',') != false) {
         } elseif (strpos($key,',') != false) {
             return $this->handler->hmGet($this->_key($name), explode(',',$key));
             return $this->handler->hmGet($this->_key($name), explode(',',$key));
         } else {
         } else {
-            return $this->handler->hget($this->_key($name), $key);
+            return $this->handler->hGet($this->_key($name), $key);
         }
         }
     }
     }
 
 
@@ -210,7 +210,16 @@ class CacheRedis extends Cache
         }
         }
     }
     }
 
 
-    public function hIncrBy($name, $prefix, $key, $num = 1) {
+    public function hIncrBy($name, $key, $value)
+    {
+        $this->init_master();
+        if (!$this->enable) return false;
+
+        $this->type = '';
+        return $this->handler->hIncrBy($this->_key($name), $key, $value);
+    }
+
+    public function hIncrByFloat($name, $prefix, $key, $num = 1) {
         if ($this->hget($name, $prefix,$key) !== false) {
         if ($this->hget($name, $prefix,$key) !== false) {
             $this->handler->hIncrByFloat($this->_key($name), $key, floatval($num));
             $this->handler->hIncrByFloat($this->_key($name), $key, floatval($num));
         }
         }

+ 21 - 2
data/config/dev/base.ini.php

@@ -45,7 +45,9 @@ $config['gip'] 		= 0;
 $config['dbdriver'] = 'mysqli';
 $config['dbdriver'] = 'mysqli';
 $config['tablepre']	= 'lrlz_';
 $config['tablepre']	= 'lrlz_';
 
 
-define('SSH_TUNEL_PROD',true);
+//define('SSH_TUNEL_PROD',true);
+define('SSH_TUNEL_PROD','xyz');
+//define('SSH_TUNEL_PROD','lingzh');
 
 
 if(SSH_TUNEL_PROD === false) {
 if(SSH_TUNEL_PROD === false) {
     $config['db'][1]['dbhost']       = MASTER_DBHOST;
     $config['db'][1]['dbhost']       = MASTER_DBHOST;
@@ -62,7 +64,7 @@ if(SSH_TUNEL_PROD === false) {
     $config['db']['slave'][0]['dbname']     = 'xyzshop';
     $config['db']['slave'][0]['dbname']     = 'xyzshop';
     $config['db']['slave'][0]['dbcharset']  = 'UTF-8';
     $config['db']['slave'][0]['dbcharset']  = 'UTF-8';
 }
 }
-else {
+elseif(SSH_TUNEL_PROD === 'xyz') {
     //调试是先执行这行命令
     //调试是先执行这行命令
     //shell_exec("ssh -NCPf root@121.89.223.81 -L 3307:127.0.0.1:3306");
     //shell_exec("ssh -NCPf root@121.89.223.81 -L 3307:127.0.0.1:3306");
     $config['db'][1]['dbhost']       = MASTER_DBHOST;
     $config['db'][1]['dbhost']       = MASTER_DBHOST;
@@ -79,6 +81,23 @@ else {
     $config['db']['slave'][0]['dbname']     = 'xyzshop';
     $config['db']['slave'][0]['dbname']     = 'xyzshop';
     $config['db']['slave'][0]['dbcharset']  = 'UTF-8';
     $config['db']['slave'][0]['dbcharset']  = 'UTF-8';
 }
 }
+elseif(SSH_TUNEL_PROD === 'lingzh') {
+    //调试是先执行这行命令
+    //shell_exec("ssh -NCPf root@121.89.212.167 -L 3307:127.0.0.1:3306");
+    $config['db'][1]['dbhost']       = MASTER_DBHOST;
+    $config['db'][1]['dbport']       = '3307';
+    $config['db'][1]['dbuser']       = 'root';
+    $config['db'][1]['dbpwd']        = 'Linzhuhmnbmhhah#2021';
+    $config['db'][1]['dbname']       = 'xyzshop';
+    $config['db'][1]['dbcharset']    = 'UTF-8';
+
+    $config['db']['slave'][0]['dbhost']     = SLAVE_DBHOST;
+    $config['db']['slave'][0]['dbport']     = '3307';
+    $config['db']['slave'][0]['dbuser']     = 'root';
+    $config['db']['slave'][0]['dbpwd']      = 'Linzhuhmnbmhhah#2021';
+    $config['db']['slave'][0]['dbname']     = 'xyzshop';
+    $config['db']['slave'][0]['dbcharset']  = 'UTF-8';
+}
 
 
 $config['session_expire'] 	= 3600;
 $config['session_expire'] 	= 3600;
 $config['lang_type'] 		= 'zh_cn';
 $config['lang_type'] 		= 'zh_cn';

+ 8 - 3
data/config/xyz/refill.ini.php

@@ -213,9 +213,14 @@ $bjbyd_phone = ['name' => 'bjbyd', 'store_id' => 24,'qualitys' => '1',
 
 
 $afandnew_phone = ['name' => 'afandnew', 'store_id' => 25,'qualitys' => '1',
 $afandnew_phone = ['name' => 'afandnew', 'store_id' => 25,'qualitys' => '1',
     'amount' => [
     'amount' => [
+        10 => [['goods_id' => 6454, 'price' => 9.55, 'quality' => 1, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']],
+        20 => [['goods_id' => 6455, 'price' => 19.1, 'quality' => 1, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']],
+        30 => [['goods_id' => 6386, 'price' => 28.65, 'quality' => 1, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']],
         50 => [['goods_id' => 6371, 'price' => 47.75, 'quality' => 1, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']],
         50 => [['goods_id' => 6371, 'price' => 47.75, 'quality' => 1, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']],
         100 => [['goods_id' => 6372, 'price' => 95.5, 'quality' => 1, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']],
         100 => [['goods_id' => 6372, 'price' => 95.5, 'quality' => 1, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']],
-        200 => [['goods_id' => 6373, 'price' => 191, 'quality' => 1, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']]
+        200 => [['goods_id' => 6373, 'price' => 191, 'quality' => 1, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']],
+        300 => [['goods_id' => 6387, 'price' => 286.5, 'quality' => 1, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']],
+        500 => [['goods_id' => 6388, 'price' => 477.5, 'quality' => 1, 'card_type' => 'chinamobile,chinaunicom,chinatelecom']]
     ],
     ],
     'refill_type' => 'api'];
     'refill_type' => 'api'];
 
 
@@ -404,8 +409,8 @@ $wantong_phone = ['name' => 'wantong', 'store_id' => 36, 'qualitys' => '4',
 $phone_providers = [
 $phone_providers = [
 //    ['name' => 'beixt', 'cfg' => $beixt_phone],
 //    ['name' => 'beixt', 'cfg' => $beixt_phone],
 //    ['name' => 'bxtwt', 'cfg' => $bxtwt_phone],
 //    ['name' => 'bxtwt', 'cfg' => $bxtwt_phone],
-//    ['name' => 'bjb', 'cfg' => $bjb_phone],
-//    ['name' => 'bjbyd', 'cfg' => $bjbyd_phone],
+    ['name' => 'bjb', 'cfg' => $bjb_phone],
+    ['name' => 'bjbyd', 'cfg' => $bjbyd_phone],
 //    ['name' => 'yifa', 'cfg' => $yifa_phone],
 //    ['name' => 'yifa', 'cfg' => $yifa_phone],
 //    ['name' => 'jiec', 'cfg' => $jiec_phone],
 //    ['name' => 'jiec', 'cfg' => $jiec_phone],
 //    ['name' => 'weit', 'cfg' => $weit_phone],
 //    ['name' => 'weit', 'cfg' => $weit_phone],

+ 12 - 6
data/logic/buy_virtual.logic.php

@@ -178,7 +178,7 @@ class buy_virtualLogic
 
 
         //存储生成的订单,函数会返回该数组
         //存储生成的订单,函数会返回该数组
         $order = [];
         $order = [];
-        $order['order_sn'] = $this->_makeOrderSn($member_info['member_id']);
+        $order['order_sn'] = $this->_makeOrderSn();
         $order['store_id'] = $goods_info['store_id'];
         $order['store_id'] = $goods_info['store_id'];
         $order['store_name'] = $goods_info['store_name'];
         $order['store_name'] = $goods_info['store_name'];
         $order['buyer_id'] = $member_info['member_id'];
         $order['buyer_id'] = $member_info['member_id'];
@@ -227,11 +227,17 @@ class buy_virtualLogic
      * 1000个会员同一微秒提订单,重复机率为1/100
      * 1000个会员同一微秒提订单,重复机率为1/100
      * @return string
      * @return string
      */
      */
-    private function _makeOrderSn($member_id) {
-        return mt_rand(10,99)
-        . sprintf('%010d',time() - 946656000)
-        . sprintf('%03d', (float) microtime() * 1000)
-        . sprintf('%03d', (int) $member_id % 1000);
+    private function _makeOrderSn()
+    {
+        static $prime_num = [11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97];
+        $pos = mt_rand(0,count($prime_num) - 1);
+        $factor = $prime_num[$pos];
+        $prefix = (getmypid() * $factor) % 1000;
+
+        return sprintf('%03d', $prefix)
+            . sprintf('%03d', mt_rand(100,999))
+            . sprintf('%010d', time() - 946656000)
+            . sprintf('%06d', (float)microtime() * 1000000);
     }
     }
 
 
     /**
     /**

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

@@ -118,6 +118,7 @@ services:
       - ../../conf/etc/localtime:/etc/localtime:ro
       - ../../conf/etc/localtime:/etc/localtime:ro
       - ../../../:/var/www/html
       - ../../../:/var/www/html
       - /Volumes/Transcend/upload:/var/www/html/data/upload
       - /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
       - ../../conf/php/php-local-debug.ini:/usr/local/etc/php/php.ini
     container_name: "panda-wsd"
     container_name: "panda-wsd"
     command: [php,"/var/www/html/wsd_bridge.php"]
     command: [php,"/var/www/html/wsd_bridge.php"]

+ 1 - 1
docker/compose/xyz-acc/docker-compose.yml

@@ -98,7 +98,7 @@ services:
     volumes:
     volumes:
       - ../../conf/etc/localtime:/etc/localtime:ro
       - ../../conf/etc/localtime:/etc/localtime:ro
       - ../../../:/var/www/html
       - ../../../:/var/www/html
-      - /Volumes/Transcend/upload:/var/www/html/data/upload
+      - /nfs/upload:/var/www/html/data/upload
       - /mnt/shoplog:/var/www/html/data/log
       - /mnt/shoplog:/var/www/html/data/log
       - ../../conf/php/xyz-php.ini:/usr/local/etc/php/php.ini
       - ../../conf/php/xyz-php.ini:/usr/local/etc/php/php.ini
     container_name: "panda-wsd"
     container_name: "panda-wsd"

+ 10 - 13
helper/mtopcard/mtopcard.php

@@ -131,22 +131,19 @@ function topcard_format($card_list)
 
 
 function simple_card_type($cardno)
 function simple_card_type($cardno)
 {
 {
-    if(preg_match( '/^1[0-9]{18}$/',$cardno,$matches)) {
+    if (preg_match('/^1[0-9]{18}$/', $cardno, $matches)) {
         return SinopecCard;
         return SinopecCard;
-    }
-    elseif(preg_match( '/^9[0-9]{15}$/',$cardno,$matches)) {
+    } elseif (preg_match('/^9[0-9]{15}$/', $cardno, $matches)) {
         return PetroChinaCard;
         return PetroChinaCard;
-    }
-    elseif(preg_match('/^1\d{10}$/',$cardno,$matches)) {
+    } elseif (preg_match('/^134[0-8]\d{7}$|^(?:13[5-9]|147|15[0-27-9]|17[28]|18[2-478]|19[578])\d{8}$/', $cardno, $matches)) {
+        return ChinaMobileCard;
+    } elseif (preg_match('/^(?:13[0-2]|145|15[56]|166|17[156]|18[56]|196)\d{8}$/', $cardno, $matches)) {
+        return ChinaUnicomCard;
+    } elseif (preg_match('/^(?:133|149|153|177|173|18[019]|19[0139])\d{8}$/', $cardno, $matches)) {
+        return ChinaTelecomCard;
+    } elseif (preg_match('/^1\d{10}$/', $cardno, $matches)) {
         return PhoneCard;
         return PhoneCard;
-
-    }elseif(preg_match( '/^1[0-9]{18}$/',$cardno,$matches)) {
-        return SinopecCard;
-    }
-    elseif(preg_match( '/^9[0-9]{15}$/',$cardno,$matches)) {
-        return PetroChinaCard;
-    }
-    else {
+    } else {
         return UnknownCard;
         return UnknownCard;
     }
     }
 }
 }

+ 13 - 3
helper/refill/RefillBase.php

@@ -97,14 +97,21 @@ class RefillBase
                 return false;
                 return false;
             }
             }
 
 
+            $refill_info = $mod_refill->getOrderInfo(['order_id' => $order_id,'inner_status' => 0]);
+
+            $quality = intval($refill_info['quality']);
+            $card_type = intval($refill_info['card_type']);
+            $spec = intval($refill_info['refill_amount']);
+
             if ($success) {
             if ($success) {
+                util::incr_notify($chname, $card_type, $spec, $quality, true);
                 $logic_vr_order->changeOrderStateSuccess($order_id);
                 $logic_vr_order->changeOrderStateSuccess($order_id);
             }
             }
             elseif ($can_try)
             elseif ($can_try)
             {
             {
-                $refill_info = $mod_refill->getOrderInfo(['order_id' => $order_id,'inner_status' => 0]);
                 if(!empty($refill_info))
                 if(!empty($refill_info))
                 {
                 {
+                    util::incr_notify($chname, $card_type, $spec, $quality, false);
                     $logic_vr_order->changeOrderStateCancel($order_info, '', "{$chname}接口回调通知失败,正在重试");
                     $logic_vr_order->changeOrderStateCancel($order_info, '', "{$chname}接口回调通知失败,正在重试");
                     if ($this->retry($refill_info, $order_info)) {
                     if ($this->retry($refill_info, $order_info)) {
                         $mod_refill->edit($order_id, ['is_retrying' => 1]);
                         $mod_refill->edit($order_id, ['is_retrying' => 1]);
@@ -114,6 +121,7 @@ class RefillBase
                 }
                 }
             }
             }
             else {
             else {
+                util::incr_notify($chname, $card_type, $spec, $quality, false);
                 $logic_vr_order->changeOrderStateCancel($order_info, '', "{$chname}接口回调通知失败,不可重试.");
                 $logic_vr_order->changeOrderStateCancel($order_info, '', "{$chname}接口回调通知失败,不可重试.");
             }
             }
             $tran->commit();
             $tran->commit();
@@ -264,7 +272,7 @@ class RefillBase
 
 
             //通道价格大于客户价格,换通道.
             //通道价格大于客户价格,换通道.
             [$goods_id, $price] = $provider->goods($quality,$amount,$card_type);
             [$goods_id, $price] = $provider->goods($quality,$amount,$card_type);
-            if ($price > $mch_amount) continue;
+            if ($price >= $mch_amount) continue;
 
 
             Log::record("start create order",Log::DEBUG);
             Log::record("start create order",Log::DEBUG);
 
 
@@ -315,15 +323,16 @@ class RefillBase
             }
             }
 
 
             $order_success = true;
             $order_success = true;
-            util::incr_order($channel_name,$card_type,$amount,$quality);
             $params = ['order_sn' => $order_sn, 'idcard' => $idcard, 'card_name' => $card_name,
             $params = ['order_sn' => $order_sn, 'idcard' => $idcard, 'card_name' => $card_name,
                 'buyer_id' => $buyer_id,
                 'buyer_id' => $buyer_id,
                 'quality' => $quality,'order_id' => $order_id];
                 'quality' => $quality,'order_id' => $order_id];
 
 
+            util::incr_commit_pre($channel_name,$card_type,$amount,$quality);
             [$state, $errmsg,$neterr] = $provider->add($card_no, $card_type, $amount, $params);
             [$state, $errmsg,$neterr] = $provider->add($card_no, $card_type, $amount, $params);
             if ($state)
             if ($state)
             {
             {
                 //提交成功
                 //提交成功
+                util::incr_commit($channel_name,$card_type,$amount,$quality,true);
                 $trade_no = $errmsg;
                 $trade_no = $errmsg;
                 if ($provider->refill_type() == 'api') {
                 if ($provider->refill_type() == 'api') {
                     $logic_vr_order = Logic("vr_order");
                     $logic_vr_order = Logic("vr_order");
@@ -343,6 +352,7 @@ class RefillBase
             }
             }
             else {
             else {
                 //提交失败
                 //提交失败
+                util::incr_commit($channel_name,$card_type,$amount,$quality,false);
                 Log::record("channel:{$channel_name} err:{$errmsg}");
                 Log::record("channel:{$channel_name} err:{$errmsg}");
                 $logic_vr_order = Logic("vr_order");
                 $logic_vr_order = Logic("vr_order");
                 $order_info = Model('vr_order')->getOrderInfo(['order_id' => $order_id]);
                 $order_info = Model('vr_order')->getOrderInfo(['order_id' => $order_id]);

+ 9 - 11
helper/refill/api/lingzh/amingyd/RefillCallBack.php

@@ -26,12 +26,12 @@ class RefillCallBack implements refill\IRefillCallBack
     {
     {
         $content = '';
         $content = '';
         ksort($params);
         ksort($params);
-        foreach ($params as $key => $val){
+        foreach ($params as $key => $val) {
             if (false === $this->check_empty($val) && "@" != substr($val, 0, 1)) {
             if (false === $this->check_empty($val) && "@" != substr($val, 0, 1)) {
                 $content .= "{$key}={$val}&";
                 $content .= "{$key}={$val}&";
             }
             }
         }
         }
-        $content .= "appSecret=".config::AppSecret;
+        $content .= "appSecret=" . config::AppSecret;
 
 
         return strtoupper(md5($content));
         return strtoupper(md5($content));
     }
     }
@@ -43,21 +43,19 @@ class RefillCallBack implements refill\IRefillCallBack
         $order_sn = $params['orderId'];
         $order_sn = $params['orderId'];
         $order_info = Model('vr_order')->getOrderInfo(['order_sn' => $order_sn]);
         $order_info = Model('vr_order')->getOrderInfo(['order_sn' => $order_sn]);
         if (empty($order_info)) {
         if (empty($order_info)) {
-            return [false, false, false,false];
+            return [false, false, false, false];
         }
         }
         $order_id = $order_info['order_id'];
         $order_id = $order_info['order_id'];
-        
+
         $data['official_sn'] = strtolower($params['operatorId']) == 'null' ? '' : $params['operatorId'];
         $data['official_sn'] = strtolower($params['operatorId']) == 'null' ? '' : $params['operatorId'];
 
 
         if ($status === 3) {
         if ($status === 3) {
             Model('refill_order')->edit($order_id, $data);
             Model('refill_order')->edit($order_id, $data);
-            return [$order_id, true, false,true];
-        }
-        elseif ($status === 2) {
-            return [$order_id, false, false,true];
-        }
-        else {
-            return [$order_id, false, false,false];
+            return [$order_id, true, false, true];
+        } elseif ($status === 2) {
+            return [$order_id, false, false, true];
+        } else {
+            return [$order_id, false, false, false];
         }
         }
     }
     }
 
 

+ 5 - 3
helper/refill/api/lingzh/binghc/RefillPhone.php

@@ -35,13 +35,15 @@ class RefillPhone extends refill\IRefillPhone
         $resp = http_request(config::ORDER_URL, $params , 'POST' , false);
         $resp = http_request(config::ORDER_URL, $params , 'POST' , false);
         if ($resp === false) {
         if ($resp === false) {
             return [false, '系统错误', true];
             return [false, '系统错误', true];
-        } else {
+        }
+        else {
             Log::record($resp, Log::DEBUG);
             Log::record($resp, Log::DEBUG);
             $resp = json_decode($resp ,true);
             $resp = json_decode($resp ,true);
-            if($resp['result'] == 'SUCCESS') {
+            if ($resp['result'] == 'SUCCESS') {
                 return [true, $resp['orderNo'], false];
                 return [true, $resp['orderNo'], false];
+            } else {
+                return [false, $resp['msg'], false];
             }
             }
-            return [false , $resp['msg'], false];
         }
         }
     }
     }
 
 

+ 1 - 1
helper/refill/api/xyz/gftd/config.php

@@ -14,5 +14,5 @@ class config
 
 
     const NOTIFY_URL =  BASE_SITE_URL."/mobile/refill_gftd.php";
     const NOTIFY_URL =  BASE_SITE_URL."/mobile/refill_gftd.php";
     const ExtHeaders = ['Content-Type: application/json;charset=UTF-8;','Accept:application/json;charset=UTF-8;'];
     const ExtHeaders = ['Content-Type: application/json;charset=UTF-8;','Accept:application/json;charset=UTF-8;'];
-    const BlackMsgs = ["只能给绑定正确手机号的油卡充值或只能给主卡充值","只能给主卡且卡状态正常的加油卡充值","加油卡卡号错误或不支持"];
+    const BlackMsgs = ["只能给主卡且卡状态正常的加油卡充值","加油卡卡号错误或不支持"];
 }
 }

+ 1 - 1
helper/refill/api/xyz/gftdsinop/config.php

@@ -14,5 +14,5 @@ class config
 
 
     const NOTIFY_URL =  BASE_SITE_URL."/mobile/refill_gftd.php";
     const NOTIFY_URL =  BASE_SITE_URL."/mobile/refill_gftd.php";
     const ExtHeaders = ['Content-Type: application/json;charset=UTF-8;','Accept:application/json;charset=UTF-8;'];
     const ExtHeaders = ['Content-Type: application/json;charset=UTF-8;','Accept:application/json;charset=UTF-8;'];
-    const BlackMsgs = ["只能给绑定正确手机号的油卡充值或只能给主卡充值","只能给主卡且卡状态正常的加油卡充值","加油卡卡号错误或不支持"];
+    const BlackMsgs = ["只能给主卡且卡状态正常的加油卡充值","加油卡卡号错误或不支持"];
 }
 }

+ 6 - 12
helper/refill/policy/chctl.php

@@ -70,6 +70,7 @@ class chctl
             }
             }
         }
         }
 
 
+        //去掉已经关闭通道
         $usable_items = [];
         $usable_items = [];
         foreach ($ctl_items as $item) {
         foreach ($ctl_items as $item) {
             if($item->opened()) {
             if($item->opened()) {
@@ -77,6 +78,7 @@ class chctl
             }
             }
         }
         }
 
 
+        //不过载的排在前面
         $ascending = function ($l, $r) {
         $ascending = function ($l, $r) {
             $lproity = $l->priority();
             $lproity = $l->priority();
             $rproity = $r->priority();
             $rproity = $r->priority();
@@ -100,20 +102,12 @@ class chctl
         usort($usable_items, $ascending);
         usort($usable_items, $ascending);
 
 
         $result = [];
         $result = [];
-        $overload = false;
-        foreach ($usable_items as $item)
-        {
-            if(!$item->speed_overload()) {
-                $result[] = $item->name();
-                $overload = true;
-            }
-        }
-
-        if(count($result) > 0) {
-            $overload = false;
+        foreach ($usable_items as $item) {
+            $name = $item->name();
+            $result[$name] = $item->speed_overload();
         }
         }
 
 
-        return [$result,$overload];
+        return $result;
     }
     }
 
 
     private function prefix($name,$spec,$card_type,$quality)
     private function prefix($name,$spec,$card_type,$quality)

+ 12 - 10
helper/refill/policy/ctl_item.php

@@ -2,7 +2,6 @@
 
 
 namespace refill;
 namespace refill;
 
 
-use Cache;
 use Log;
 use Log;
 
 
 class ctl_item
 class ctl_item
@@ -12,6 +11,7 @@ class ctl_item
     private $mName;
     private $mName;
     private $mCardType;
     private $mCardType;
     private $mAmount;
     private $mAmount;
+    private $mQuality;
 
 
     private $mMaxSpeed;
     private $mMaxSpeed;
     private $mPrefix;
     private $mPrefix;
@@ -24,11 +24,13 @@ class ctl_item
 
 
     public function __construct($chname,$card_type,$amount,$max_speed,$priority,$storge,$opened,$quality)
     public function __construct($chname,$card_type,$amount,$max_speed,$priority,$storge,$opened,$quality)
     {
     {
-        $this->mPrefix = "speed-{$chname}-{$quality}-{$card_type}-{$amount}-";
+        $this->mPrefix = "{$chname}-{$quality}-{$card_type}-{$amount}";
 
 
         $this->mName = $chname;
         $this->mName = $chname;
         $this->mCardType = $card_type;
         $this->mCardType = $card_type;
         $this->mAmount = $amount;
         $this->mAmount = $amount;
+        $this->mQuality = $quality;
+
         $this->mMaxSpeed = $max_speed;
         $this->mMaxSpeed = $max_speed;
         $this->mPriority = $priority;
         $this->mPriority = $priority;
         $this->mStorge = $storge;
         $this->mStorge = $storge;
@@ -40,13 +42,9 @@ class ctl_item
 
 
     private function load($start_time)
     private function load($start_time)
     {
     {
-        $ins = Cache::getInstance('cacheredis');
         $end = time();
         $end = time();
-
         for($time = $start_time; $time <= $end; $time++) {
         for($time = $start_time; $time <= $end; $time++) {
-            $key = $this->mPrefix . "{$time}";
-            $val = $ins->get_org($key);
-            $val = $val == false ? 0 : $val;
+            $val = util::hget_commit_pre_sec($this->mName,$this->mCardType,$this->mAmount,$this->mQuality,$time);
             $this->mRecords[$time] = $val;
             $this->mRecords[$time] = $val;
         }
         }
         $this->mLastReadTime = $end;
         $this->mLastReadTime = $end;
@@ -69,17 +67,21 @@ class ctl_item
     {
     {
         $this->load($this->mLastReadTime);
         $this->load($this->mLastReadTime);
         $speed = array_sum($this->mRecords);
         $speed = array_sum($this->mRecords);
-        Log::record("{$this->mPrefix} = {$speed}  max_speed={$this->mMaxSpeed}",Log::DEBUG);
+        Log::record("{$this->mPrefix} speed = {$speed} max_speed={$this->mMaxSpeed}",Log::DEBUG);
 
 
         return $speed;
         return $speed;
     }
     }
 
 
-    public function speed_overload() : bool {
+    public function speed_overload() : bool
+    {
         if($this->mMaxSpeed < 0) {
         if($this->mMaxSpeed < 0) {
             return false;
             return false;
         }
         }
+        elseif ($this->mMaxSpeed == 0) {
+            return true;
+        }
         else {
         else {
-            return $this->cur_speed() > $this->mMaxSpeed;
+            return $this->cur_speed() >= $this->mMaxSpeed;
         }
         }
     }
     }
 
 

+ 27 - 15
helper/refill/policy/lingzh/policy.php

@@ -44,12 +44,18 @@ class policy extends ProviderManager implements IPolicy
             $names[] = $provider->name();
             $names[] = $provider->name();
         }
         }
 
 
-        [$names,$overload] = $this->mChannelControl->match($names,$spec,$card_type,$quality);
-        Log::record("policy::find_providers match result=" . implode($names),Log::DEBUG);
+        $name_overloads = $this->mChannelControl->match($names,$spec,$card_type,$quality);
+        Log::record("policy::find_providers match result=" . implode(',',$names),Log::DEBUG);
 
 
         $result = [];
         $result = [];
-        foreach ($names as $name)
+        foreach ($name_overloads as $name => $overload)
         {
         {
+            if(!isset($first)) {
+                $first = $overload;
+            }
+
+            if($overload) continue;
+
             foreach ($providers as $provider)
             foreach ($providers as $provider)
             {
             {
                 if($name == $provider->name()) {
                 if($name == $provider->name()) {
@@ -58,7 +64,11 @@ class policy extends ProviderManager implements IPolicy
             }
             }
         }
         }
 
 
-        return [$result,$overload];
+        if(!isset($first)) {
+            $first = false;
+        }
+
+        return [$result,$first];
     }
     }
 
 
     public function price($mchid,$spec,$card_type,$quality)
     public function price($mchid,$spec,$card_type,$quality)
@@ -81,17 +91,19 @@ class policy extends ProviderManager implements IPolicy
                 continue;
                 continue;
             }
             }
 
 
-            [$names,$overload] = $this->find_providers($spec,$card_type,$quality);
-            if($overload) {
-                Log::record("Policy::find_quality:{$quality}-{$spec}-{$card_type} is ok",Log::DEBUG);
-                return [$org_quality,$quality];
-            }
-            if(!empty($names)) {
-                Log::record("Policy::find_quality:{$quality}-{$spec}-{$card_type} is ok",Log::DEBUG);
-                return [$org_quality,$quality];
-            }
-            else {
-                Log::record("Policy::find_quality:{$quality}-{$spec}-{$card_type} is fail",Log::DEBUG);
+            [$providers,$overload] = $this->find_providers($spec,$card_type,$quality);
+            if (!empty($providers))
+            {
+                if (!$overload) {
+                    Log::record("Policy::find_quality:{$quality}-{$spec}-{$card_type} is ok", Log::DEBUG);
+                }
+                else {
+                    Log::record("Policy::find_quality:{$quality}-{$spec}-{$card_type} is overload", Log::DEBUG);
+                }
+
+                return [$org_quality, $quality];
+            } else {
+                Log::record("Policy::find_quality:{$quality}-{$spec}-{$card_type} is fail", Log::DEBUG);
             }
             }
         }
         }
 
 

+ 31 - 17
helper/refill/policy/xyz/policy.php

@@ -46,12 +46,18 @@ class policy extends ProviderManager implements IPolicy
             $names[] = $provider->name();
             $names[] = $provider->name();
         }
         }
 
 
-        [$names,$overload] = $this->mChannelControl->match($names,$spec,$card_type,$quality);
-        Log::record("policy::find_providers match result=" . implode($names),Log::DEBUG);
+        $name_overloads = $this->mChannelControl->match($names,$spec,$card_type,$quality);
+        Log::record("policy::find_providers match result=" . implode(',',$names),Log::DEBUG);
 
 
         $result = [];
         $result = [];
-        foreach ($names as $name)
+        foreach ($name_overloads as $name => $overload)
         {
         {
+            if(!isset($first)) {
+                $first = $overload;
+            }
+
+            if($overload) continue;
+
             foreach ($providers as $provider)
             foreach ($providers as $provider)
             {
             {
                 if($name == $provider->name()) {
                 if($name == $provider->name()) {
@@ -60,7 +66,11 @@ class policy extends ProviderManager implements IPolicy
             }
             }
         }
         }
 
 
-        return [$result,$overload];
+        if(!isset($first)) {
+            $first = false;
+        }
+
+        return [$result,$first];
     }
     }
 
 
     public function price($mchid,$spec,$card_type,$quality)
     public function price($mchid,$spec,$card_type,$quality)
@@ -78,26 +88,30 @@ class policy extends ProviderManager implements IPolicy
         foreach ($qualities as $quality)
         foreach ($qualities as $quality)
         {
         {
             $price = $this->mPrices->price($mchid,$card_type,$spec,$quality);
             $price = $this->mPrices->price($mchid,$card_type,$spec,$quality);
-            if($price === false) continue;
-
-            [$names,$overload] = $this->find_providers($spec,$card_type,$quality);
-            if($overload) {
-                Log::record("Policy::find_quality:{$quality}-{$spec}-{$card_type} is ok",Log::DEBUG);
-                return [$org_quality,$quality];
-            }
-            if(!empty($names)) {
-                Log::record("Policy::find_quality:{$quality}-{$spec}-{$card_type} is ok",Log::DEBUG);
-                return [$org_quality,$quality];
+            if($price === false) {
+                Log::record("{$mchid} 没有协商 quality = {$quality} 价格",Log::DEBUG);
+                continue;
             }
             }
-            else {
-                Log::record("Policy::find_quality:{$quality}-{$spec}-{$card_type} is fail",Log::DEBUG);
+
+            [$providers,$overload] = $this->find_providers($spec,$card_type,$quality);
+            if (!empty($providers))
+            {
+                if (!$overload) {
+                    Log::record("Policy::find_quality:{$quality}-{$spec}-{$card_type} is ok", Log::DEBUG);
+                }
+                else {
+                    Log::record("Policy::find_quality:{$quality}-{$spec}-{$card_type} is overload", Log::DEBUG);
+                }
+
+                return [$org_quality, $quality];
+            } else {
+                Log::record("Policy::find_quality:{$quality}-{$spec}-{$card_type} is fail", Log::DEBUG);
             }
             }
         }
         }
 
 
         return [$org_quality,0];
         return [$org_quality,0];
     }
     }
 
 
-
     public function allow($mchid,$card_type,$amount,$quality) : bool
     public function allow($mchid,$card_type,$amount,$quality) : bool
     {
     {
         $reader = function () {
         $reader = function () {

+ 188 - 72
helper/refill/util.php

@@ -11,46 +11,67 @@ use Log;
 use Exception;
 use Exception;
 use Cache;
 use Cache;
 use QueueClient;
 use QueueClient;
+use function PHPUnit\Framework\returnArgument;
 
 
 class util
 class util
 {
 {
     static function make_mobile()
     static function make_mobile()
     {
     {
-        static $prefix = ["139","138","137","136","135","134","159","158","157","150","151","152",
-            "188","187","182","183","184","178","130","131","132","156","155","186","185",
-            "176","133","153","189","180","181","177"];
+        static $prefix = ["139", "138", "137", "136", "135", "134", "159", "158", "157", "150", "151", "152",
+            "188", "187", "182", "183", "184", "178", "130", "131", "132", "156", "155", "186", "185",
+            "176", "133", "153", "189", "180", "181", "177"];
 
 
-        $pos = mt_rand(0,count($prefix) - 1);
+        $pos = mt_rand(0, count($prefix) - 1);
         $no = "{$prefix[$pos]}" . mt_rand(10000000, 99999999);
         $no = "{$prefix[$pos]}" . mt_rand(10000000, 99999999);
 
 
         return $no;
         return $no;
     }
     }
 
 
-    static function read_card($card_no,$card_type = 0)
+    public static function can_refill($card_no, $card_type)
     {
     {
-        if(empty($card_no)) return false;
+        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();
+                $success = ($cur - $latest) > 120;
+
+                if ($success) {
+                    wcache("card_expired", [$card_no => time()], '');
+                }
+
+                return [$success, $latest + 120 - $cur];
+            }
+        } else {
+            return [true, 0];
+        }
+    }
+
+    static function read_card($card_no, $card_type = 0)
+    {
+        if (empty($card_no)) return false;
 
 
         $data = rcache($card_no, 'cardrefill-');
         $data = rcache($card_no, 'cardrefill-');
-        if(empty($data))
-        {
+        if (empty($data)) {
             $mod_topcard = Model('topcard');
             $mod_topcard = Model('topcard');
             $ret = $mod_topcard->get_card($card_no);
             $ret = $mod_topcard->get_card($card_no);
-            if(empty($ret))
-            {
-                if($card_type === 0) {
+            if (empty($ret)) {
+                if ($card_type === 0) {
                     $card_type = mtopcard\card_type($card_no);
                     $card_type = mtopcard\card_type($card_no);
                 }
                 }
                 $bind_phone = util::make_mobile();
                 $bind_phone = util::make_mobile();
-                $mod_topcard->add($card_no,$card_type,time(),$bind_phone);
+                $mod_topcard->add($card_no, $card_type, time(), $bind_phone);
 
 
                 $data['bind_phone'] = $bind_phone;
                 $data['bind_phone'] = $bind_phone;
                 $data['refill_time'] = time();
                 $data['refill_time'] = time();
                 $data['times'] = 0;
                 $data['times'] = 0;
                 $data['black_card'] = 0;
                 $data['black_card'] = 0;
 
 
-                wcache($card_no,$data,'cardrefill-');
-            }
-            else {
+                wcache($card_no, $data, 'cardrefill-');
+            } else {
                 $val = $ret[0];
                 $val = $ret[0];
 
 
                 $data['bind_phone'] = $val['bind_phone'];
                 $data['bind_phone'] = $val['bind_phone'];
@@ -61,7 +82,7 @@ class util
         }
         }
 
 
         //之前没加black_card处理,这个字段不存在.
         //之前没加black_card处理,这个字段不存在.
-        if(!array_key_exists('black_card',$data)) {
+        if (!array_key_exists('black_card', $data)) {
             $data['black_card'] = 0;
             $data['black_card'] = 0;
         }
         }
 
 
@@ -72,45 +93,43 @@ class util
     {
     {
         $card_info['times'] += 1;
         $card_info['times'] += 1;
         $card_info['refill_time'] = time();
         $card_info['refill_time'] = time();
-        wcache($card_no,$card_info,'cardrefill-');
+        wcache($card_no, $card_info, 'cardrefill-');
     }
     }
 
 
     public static function del_card($card_no)
     public static function del_card($card_no)
     {
     {
-        dcache($card_no,'cardrefill-');
+        dcache($card_no, 'cardrefill-');
     }
     }
 
 
     public static function set_black($card_no)
     public static function set_black($card_no)
     {
     {
-        if(empty($card_no)) return false;
+        if (empty($card_no)) return false;
 
 
         $card_info = util::read_card($card_no);
         $card_info = util::read_card($card_no);
-        if(!empty($card_info)) {
+        if (!empty($card_info)) {
             $card_info['black_card'] = 1;
             $card_info['black_card'] = 1;
             $mod_topcard = Model('topcard');
             $mod_topcard = Model('topcard');
             $mod_topcard->table('topcard')->where(['card_no' => $card_no])->update(['black_card' => 1]);
             $mod_topcard->table('topcard')->where(['card_no' => $card_no])->update(['black_card' => 1]);
-            wcache($card_no,$card_info,'cardrefill-');
+            wcache($card_no, $card_info, 'cardrefill-');
 
 
             return true;
             return true;
-        }
-        else {
+        } else {
             return false;
             return false;
         }
         }
     }
     }
 
 
-    private static function black_order($order_sn,$msg)
+    private static function black_order($order_sn, $msg)
     {
     {
-        static $errMsgs = ["只能给绑定正确手机号的油卡充值或只能给主卡充值","只能给主卡且卡状态正常的加油卡充值","加油卡卡号错误或不支持"];
+        static $errMsgs = ["只能给主卡且卡状态正常的加油卡充值", "加油卡卡号错误或不支持"];
 
 
-        if(empty($msg)) return false;
+        if (empty($msg)) return false;
 
 
-        if(in_array($msg,$errMsgs))
-        {
+        if (in_array($msg, $errMsgs)) {
 
 
             $refill = Model('refill_order');
             $refill = Model('refill_order');
             $order = $refill->getOrderInfo(['order_sn' => $order_sn]);
             $order = $refill->getOrderInfo(['order_sn' => $order_sn]);
 
 
-            if(empty($order)) return false;
+            if (empty($order)) return false;
 
 
             $card_no = $order['card_no'];
             $card_no = $order['card_no'];
             return util::set_black($card_no);
             return util::set_black($card_no);
@@ -119,31 +138,30 @@ class util
 
 
     public static function black_from_log($file_name)
     public static function black_from_log($file_name)
     {
     {
-        $fn = fopen($file_name,"r");
-        if(empty($fn)) {
-            Log::record("Open File {$file_name} error.",Log::ERR);
+        $fn = fopen($file_name, "r");
+        if (empty($fn)) {
+            Log::record("Open File {$file_name} error.", Log::ERR);
             return false;
             return false;
-        }
-        else {
-            Log::record("{$file_name} start woring",Log::DEBUG);
+        } else {
+            Log::record("{$file_name} start woring", Log::DEBUG);
         }
         }
 
 
         $errs = [];
         $errs = [];
-        while(! feof($fn))  {
+        while (!feof($fn)) {
             $line = trim(fgets($fn));
             $line = trim(fgets($fn));
-            $ret = preg_match('/[\w\W]+"channelOrderNumber":"(?P<order_sn>[^"]+)"[\w\W]+"message":"(?P<message>[\x{4e00}-\x{9fa5}]+)"[\w\W]+"status":109/u',$line,$matches);
-            if($ret) {
+            $ret = preg_match('/[\w\W]+"channelOrderNumber":"(?P<order_sn>[^"]+)"[\w\W]+"message":"(?P<message>[\x{4e00}-\x{9fa5}]+)"[\w\W]+"status":109/u', $line, $matches);
+            if ($ret) {
                 $order_sn = $matches['order_sn'];
                 $order_sn = $matches['order_sn'];
                 $message = $matches['message'];
                 $message = $matches['message'];
 
 
-                self::black_order($order_sn,$message);
+                self::black_order($order_sn, $message);
 
 
                 $errs[$message] = empty($errs[$message]) ? 1 : $errs[$message] + 1;
                 $errs[$message] = empty($errs[$message]) ? 1 : $errs[$message] + 1;
             }
             }
         }
         }
 
 
         foreach ($errs as $msg => $count) {
         foreach ($errs as $msg => $count) {
-            Log::record("msg:{$msg} count:{$count}",Log::DEBUG);
+            Log::record("msg:{$msg} count:{$count}", Log::DEBUG);
         }
         }
 
 
         fclose($fn);
         fclose($fn);
@@ -151,13 +169,12 @@ class util
         return true;
         return true;
     }
     }
 
 
-    public static function async_add($method,$params)
+    public static function async_add($method, $params)
     {
     {
         try {
         try {
-            QueueClient::async_push("AysncAddDispatcher",['method' => $method,'params'=> $params],10);
+            QueueClient::async_push("AysncAddDispatcher", ['method' => $method, 'params' => $params], 10);
             return true;
             return true;
-        }
-        catch (Exception $ex) {
+        } catch (Exception $ex) {
             return false;
             return false;
         }
         }
     }
     }
@@ -165,32 +182,29 @@ class util
     public static function push_add($params)
     public static function push_add($params)
     {
     {
         try {
         try {
-            queue\DispatcherClient::instance()->push('add',$params);
+            queue\DispatcherClient::instance()->push('add', $params);
             return true;
             return true;
-        }
-        catch (Exception $ex) {
+        } catch (Exception $ex) {
             return false;
             return false;
         }
         }
     }
     }
 
 
-    public static function push_notify($chname,$params)
+    public static function push_notify($chname, $params)
     {
     {
         try {
         try {
-            queue\DispatcherClient::instance()->push('notify',['channel' => $chname,'params' => $params]);
+            queue\DispatcherClient::instance()->push('notify', ['channel' => $chname, 'params' => $params]);
             return true;
             return true;
-        }
-        catch (Exception $ex) {
+        } catch (Exception $ex) {
             return false;
             return false;
         }
         }
     }
     }
 
 
-    public static function push_notify_merchant($order_id,$manual)
+    public static function push_notify_merchant($order_id, $manual)
     {
     {
         try {
         try {
-            queue\DispatcherClient::instance()->push('notify_mechant',['order_id' => $order_id,'manual' => $manual]);
+            queue\DispatcherClient::instance()->push('notify_mechant', ['order_id' => $order_id, 'manual' => $manual]);
             return true;
             return true;
-        }
-        catch (Exception $ex) {
+        } catch (Exception $ex) {
             return false;
             return false;
         }
         }
     }
     }
@@ -198,56 +212,158 @@ class util
     public static function push_query($order_id)
     public static function push_query($order_id)
     {
     {
         try {
         try {
-            queue\DispatcherClient::instance()->push('query',['order_id' => $order_id]);
+            queue\DispatcherClient::instance()->push('query', ['order_id' => $order_id]);
             return true;
             return true;
-        }
-        catch (Exception $ex) {
+        } catch (Exception $ex) {
             return false;
             return false;
         }
         }
     }
     }
+
     public static function manual_success($order_id)
     public static function manual_success($order_id)
     {
     {
         try {
         try {
-            queue\DispatcherClient::instance()->push('manual_success',['order_id' => $order_id]);
+            queue\DispatcherClient::instance()->push('manual_success', ['order_id' => $order_id]);
             return true;
             return true;
-        }
-        catch (Exception $ex) {
+        } catch (Exception $ex) {
             return false;
             return false;
         }
         }
     }
     }
+
     public static function manual_cancel($order_id)
     public static function manual_cancel($order_id)
     {
     {
         try {
         try {
-            queue\DispatcherClient::instance()->push('manual_cancel',['order_id' => $order_id]);
+            queue\DispatcherClient::instance()->push('manual_cancel', ['order_id' => $order_id]);
             return true;
             return true;
-        }
-        catch (Exception $ex) {
+        } catch (Exception $ex) {
             return false;
             return false;
         }
         }
     }
     }
 
 
-    public static function incr_order($chname,$card_type,$amout,$quality)
+    //统计提交订单数据
+    public static function incr_commit_pre($chname, $card_type, $spec, $quality)
+    {
+        $ins = Cache::getInstance('cacheredis');
+
+        $name = 'channel_monitor_commit';
+        $sec = time();
+        $key_sec = "pre-{$chname}-{$quality}-{$card_type}-{$spec}-{$sec}";
+
+        $ins->hIncrBy($name, $key_sec, 1);
+    }
+
+    public static function hget_commit_pre_sec($chname, $card_type, $spec, $quality, $time_stamp)
+    {
+        $ins = Cache::getInstance('cacheredis');
+
+        $name = 'channel_monitor_commit';
+        $key_sec = "pre-{$chname}-{$quality}-{$card_type}-{$spec}-{$time_stamp}";
+        $value = $ins->hget($name, '', $key_sec);
+
+        return intval($value);
+    }
+
+    public static function incr_commit($chname, $card_type, $spec, $quality, $fsuccess = true)
     {
     {
         $ins = Cache::getInstance('cacheredis');
         $ins = Cache::getInstance('cacheredis');
 
 
+        $name = 'channel_monitor_commit';
         $sec = time();
         $sec = time();
         $min = $sec - $sec % 60;
         $min = $sec - $sec % 60;
 
 
-        $key = "storge-push-{$chname}-{$quality}-{$card_type}-{$amout}-{$min}";
-        $ins->incr($key);
+        if ($fsuccess) {
+            $key_sec = "succ-{$chname}-{$quality}-{$card_type}-{$spec}-{$sec}";
+            $key_min = "succm-{$chname}-{$quality}-{$card_type}-{$spec}-{$min}";
+        } else {
+            $key_sec = "fail-{$chname}-{$quality}-{$card_type}-{$spec}-{$sec}";
+            $key_min = "failm-{$chname}-{$quality}-{$card_type}-{$spec}-{$min}";
+        }
 
 
-        $key = "speed-{$chname}-{$quality}-{$card_type}-{$amout}-{$sec}";
-        $ins->incr($key);
+        $ins->hIncrBy($name, $key_sec, 1);
+        $ins->hIncrBy($name, $key_min, 1);
     }
     }
 
 
-    public static function decr_order($chname,$card_type,$amout,$quality)
+    public static function hget_commit_sec($chname, $card_type, $spec, $quality, $time_stamp, $fsuccess = true)
     {
     {
         $ins = Cache::getInstance('cacheredis');
         $ins = Cache::getInstance('cacheredis');
 
 
+        $name = 'channel_monitor_commit';
+        if ($fsuccess) {
+            $key_sec = "succ-{$chname}-{$quality}-{$card_type}-{$spec}-{$time_stamp}";
+        } else {
+            $key_sec = "fail-{$chname}-{$quality}-{$card_type}-{$spec}-{$time_stamp}";
+        }
+        $value = $ins->hget($name, '', $key_sec);
+
+        return intval($value);
+    }
+
+    public static function hget_commit_min($chname, $card_type, $spec, $quality, $time_stamp, $fsuccess = true)
+    {
+        $ins = Cache::getInstance('cacheredis');
+
+        $name = 'channel_monitor_commit';
+        $min = $time_stamp - $time_stamp % 60;
+
+        if ($fsuccess) {
+            $key_sec = "succm-{$chname}-{$quality}-{$card_type}-{$spec}-{$min}";
+        } else {
+            $key_sec = "failm-{$chname}-{$quality}-{$card_type}-{$spec}-{$min}";
+        }
+        $value = $ins->hget($name, '', $key_sec);
+
+        return intval($value);
+    }
+
+    //统计回调通知数据
+    public static function incr_notify($chname, $card_type, $spec, $quality, $fsuccess = true)
+    {
+        $ins = Cache::getInstance('cacheredis');
+
+        $name = 'channel_monitor_notify';
         $sec = time();
         $sec = time();
         $min = $sec - $sec % 60;
         $min = $sec - $sec % 60;
 
 
-        $key = "storge-pop-{$chname}-{$quality}-{$card_type}-{$amout}-{$min}";
-        $ins->decr($key);
+        if ($fsuccess) {
+            $key_sec = "succ-{$chname}-{$quality}-{$card_type}-{$spec}-{$sec}";
+            $key_min = "succm-{$chname}-{$quality}-{$card_type}-{$spec}-{$min}";
+        } else {
+            $key_sec = "fail-{$chname}-{$quality}-{$card_type}-{$spec}-{$sec}";
+            $key_min = "failm-{$chname}-{$quality}-{$card_type}-{$spec}-{$min}";
+        }
+
+        $ins->hIncrBy($name, $key_sec, 1);
+        $ins->hIncrBy($name, $key_min, 1);
+    }
+
+    public static function hget_notify_sec($chname, $card_type, $spec, $quality, $time_stamp, $fsuccess = true)
+    {
+        $ins = Cache::getInstance('cacheredis');
+
+        $name = 'channel_monitor_notify';
+        if ($fsuccess) {
+            $key_sec = "succ-{$chname}-{$quality}-{$card_type}-{$spec}-{$time_stamp}";
+        } else {
+            $key_sec = "fail-{$chname}-{$quality}-{$card_type}-{$spec}-{$time_stamp}";
+        }
+        $value = $ins->hget($name, '', $key_sec);
+
+        return intval($value);
+    }
+
+    public static function hget_notify_min($chname, $card_type, $spec, $quality, $time_stamp, $fsuccess = true)
+    {
+        $ins = Cache::getInstance('cacheredis');
+
+        $name = 'channel_monitor_notify';
+        $min = $time_stamp - $time_stamp % 60;
+
+        if ($fsuccess) {
+            $key_sec = "succm-{$chname}-{$quality}-{$card_type}-{$spec}-{$min}";
+        } else {
+            $key_sec = "failm-{$chname}-{$quality}-{$card_type}-{$spec}-{$min}";
+        }
+        $value = $ins->hget($name, '', $key_sec);
+
+        return intval($value);
     }
     }
 }
 }

+ 9 - 0
mobile/control/merchant_refill.php

@@ -100,6 +100,15 @@ class merchant_refillControl extends mbMerchantControl
                     'mch_order' => "",
                     'mch_order' => "",
                     'notify_url' => ""];
                     'notify_url' => ""];
 
 
+                $card_type = mtopcard\simple_card_type($no);
+                if($card_type === mtopcard\SinopecCard || $card_type === mtopcard\PetroChinaCard)
+                {
+                    [$can_refill, $period] = refill\util::can_refill($no, $card_type);
+                    if ($can_refill === false) {
+                        Log::record("请{$no}至少在{$period}秒后再试.");
+                    }
+                }
+
                 $ret = refill\util::push_add($params);
                 $ret = refill\util::push_add($params);
                 if($ret) {
                 if($ret) {
                     $arr['state'] = $ret;
                     $arr['state'] = $ret;

+ 24 - 11
mobile/control/refill.php

@@ -16,7 +16,7 @@ class refillControl extends merchantControl
 
 
     public function goodsOp()
     public function goodsOp()
     {
     {
-        $result = refill\RefillFactory::instance()->goods();
+        $goods_list = refill\RefillFactory::instance()->goods();
 
 
         $sorter = function (array $items) {
         $sorter = function (array $items) {
             $ret = [];
             $ret = [];
@@ -27,7 +27,14 @@ class refillControl extends merchantControl
             return $ret;
             return $ret;
         };
         };
 
 
-        $result = $sorter($result);
+        $goods_list = $sorter($goods_list);
+
+        $result = [];
+        foreach ($goods_list as $card_type => $value) {
+            $key = mtopcard\scard_type($card_type);
+            $result[$key] = $value;
+        }
+
         return self::outsuccess($result);
         return self::outsuccess($result);
     }
     }
 
 
@@ -73,15 +80,22 @@ class refillControl extends merchantControl
             return self::outerr(205,"客户订单号重复或者为空.");
             return self::outerr(205,"客户订单号重复或者为空.");
         }
         }
 
 
-        if(!$this->can_refill($card_no)) {
-            return self::outerr(206,"平台不支持该卡充值.");
-        }
-
-        $card_type = mtopcard\card_type($card_no);
+        $card_type = mtopcard\simple_card_type($card_no);
         if($card_type === mtopcard\SinopecCard || $card_type === mtopcard\PetroChinaCard)
         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,"平台不支持该卡充值.");
+            }
+
             $allow = refill\RefillFactory::instance()->allow($this->mchid(),$card_type,$amount,$quality);
             $allow = refill\RefillFactory::instance()->allow($this->mchid(),$card_type,$amount,$quality);
-            if(!$allow) {
+            if(!$allow)
+            {
                 if ($card_type === mtopcard\SinopecCard) {
                 if ($card_type === mtopcard\SinopecCard) {
                     $text = "中石化";
                     $text = "中石化";
                 }
                 }
@@ -92,14 +106,13 @@ class refillControl extends merchantControl
             }
             }
         }
         }
 
 
-        $params = [ 'mchid' => $this->mchid(),
+        $params = ['mchid' => $this->mchid(),
             'buyer_id' => $this->adminid(),
             'buyer_id' => $this->adminid(),
             'amount' => $amount,
             'amount' => $amount,
             'card_no' => $card_no,
             'card_no' => $card_no,
             'mch_order' => $mch_order,
             'mch_order' => $mch_order,
             'notify_url' => $notify_url,
             'notify_url' => $notify_url,
-            'org_quality' => $quality
-            ];
+            'org_quality' => $quality];
 
 
         $state = refill\util::push_add($params);
         $state = refill\util::push_add($params);
         if($state === true) {
         if($state === true) {

+ 3 - 3
racc/control/lzrefill.php

@@ -85,9 +85,9 @@ class lzrefillControl extends lzbaseControl
             return self::outerr(11,$this->merchant_available);
             return self::outerr(11,$this->merchant_available);
         }
         }
 
 
-        if(!$this->can_refill($card_no)) {
-            return self::outerr(10,$this->merchant_available);
-        }
+//        if(!$this->can_refill($card_no)) {
+//            return self::outerr(10,$this->merchant_available);
+//        }
 
 
         $params = [ 'mchid' => $this->mchid(),
         $params = [ 'mchid' => $this->mchid(),
             'buyer_id' => $this->adminid(),
             'buyer_id' => $this->adminid(),

+ 3 - 3
rdispatcher/proxy.php

@@ -77,9 +77,9 @@ class proxy
                     if($order_id > 0) {
                     if($order_id > 0) {
                         $refill_order->edit($order_id, ['is_retrying' => 1]);
                         $refill_order->edit($order_id, ['is_retrying' => 1]);
                     }
                     }
-//                    if(defined('USE_COROUTINE') && USE_COROUTINE) {
-//                        \Swoole\Coroutine::sleep(2);
-//                    }
+                    if(defined('USE_COROUTINE') && USE_COROUTINE && $errcode == refill\errcode::PROVIDER_OVERLOAD) {
+                        \Swoole\Coroutine::sleep(1);
+                    }
                     refill\util::push_add($params);
                     refill\util::push_add($params);
                 }
                 }
             }
             }

+ 65 - 13
shop/control/card_keylist.php

@@ -22,7 +22,7 @@ class card_keylistcontrol extends BaseSellerControl
         if (!empty($_GET['amount'])) {
         if (!empty($_GET['amount'])) {
             $condition['amount'] = $_GET['amount'];
             $condition['amount'] = $_GET['amount'];
         }
         }
-        if (in_array($_GET['card_state'] , ['0','1','2','3'])) {
+        if (in_array($_GET['card_state'], ['0', '1', '2', '3'])) {
             $condition['card_state'] = $_GET['card_state'];
             $condition['card_state'] = $_GET['card_state'];
         }
         }
         $cards = $mod_card->getCardsList($condition, 15);
         $cards = $mod_card->getCardsList($condition, 15);
@@ -41,26 +41,78 @@ class card_keylistcontrol extends BaseSellerControl
 
 
     public function statsOp()
     public function statsOp()
     {
     {
-        $condition = [];
-        if (isset($_GET['card_state'])) {
-            $condition['card_state'] = $_GET['card_state'];
+        $condition = ['card_id' => ['gt', 0]];
+        $start_unixtime = intval(strtotime($_GET['query_start_time']));
+        $end_unixtime   = intval(strtotime($_GET['query_end_time']));
+
+        if ($start_unixtime > 0 && $end_unixtime > $start_unixtime) {
+            $condition['assigned_time'] = [ ['egt', $start_unixtime] , ['lt', $end_unixtime] , 'and'];
+        }
+        elseif ($start_unixtime > 0) {
+            $condition['assigned_time'] = ['egt', $start_unixtime];
         }
         }
-        $counts = Model('')->table('card_key')
-            ->field('count(*) as card_count, card_type, amount')
+        elseif ($end_unixtime > 0) {
+            $condition['assigned_time'] = ['lt', $end_unixtime];
+        }
+        $items = Model('')->table('card_key')
+            ->field('card_type, amount, card_state, count(*) as card_count, sum(amount) as card_amounts')
             ->where($condition)
             ->where($condition)
-            ->group('card_type,amount')
+            ->group('card_type,amount,card_state')
+            ->order('card_type asc, amount asc, card_state asc')
             ->select();
             ->select();
+
         $card_count = 0;
         $card_count = 0;
         $card_type_texts = [1 => '中石油', 2 => '中石化', 4 => '中国移动', 5 => '中国联通', 6 => '中国电信'];
         $card_type_texts = [1 => '中石油', 2 => '中石化', 4 => '中国移动', 5 => '中国联通', 6 => '中国电信'];
         $stats = [];
         $stats = [];
-        foreach ($counts as $key => $count) {
-            $card_count += $count['card_count'];
-            $count['card_type_text'] = $card_type_texts[$count['card_type']];
-            $count['amount'] = intval($count['amount']);
-            $stats[$count['card_type']][] = $count;
+        foreach ($items as $item) {
+            $card_count += $item['card_count'];
+            $card_type = $item['card_type'];
+            $item['amount'] = intval($item['amount']);
+            $item['card_amounts'] = intval($item['card_amounts']);
+            $key = "{$card_type_texts[$card_type]}-{$item['amount']}元";
+            $stats[$key][] = $item;
+        }
+        $card_state_stats = function($stats) {
+            $data = [];
+            foreach ($stats as $key => $value) {
+                foreach ($value as $stat) {
+                    if (empty($data[$key]['UnusedCardCount'])) {
+                        $data[$key]['UnusedCardCount'] = $stat['card_state'] == mtopcard\UnusedCard ? $stat['card_count'] : 0;
+                        $data[$key]['UnusedCardAmounts'] = $stat['card_state'] == mtopcard\UnusedCard ? $stat['card_amounts'] : 0;
+                    }
+                    if (empty($data[$key]['ReserveCardCount'])) {
+                        $data[$key]['ReserveCardCount'] = $stat['card_state'] == mtopcard\ReserveCard ? $stat['card_count'] : 0;
+                        $data[$key]['ReserveCardAmounts'] = $stat['card_state'] == mtopcard\ReserveCard ? $stat['card_amounts'] : 0;
+                    }
+                    if (empty($data[$key]['AssignedCardCount'])) {
+                        $data[$key]['AssignedCardCount'] = $stat['card_state'] == mtopcard\AssignedCard ? $stat['card_count'] : 0;
+                        $data[$key]['AssignedCardAmounts'] = $stat['card_state'] == mtopcard\AssignedCard ? $stat['card_amounts'] : 0;
+                    }
+                    if (empty($data[$key]['FreezedCardCount'])) {
+                        $data[$key]['FreezedCardCount'] = $stat['card_state'] == mtopcard\FreezedCard ? $stat['card_count'] : 0;
+                        $data[$key]['FreezedCardAmounts'] = $stat['card_state'] == mtopcard\FreezedCard ? $stat['card_amounts'] : 0;
+                    }
+                }
+            }
+            return $data;
+        };
+        $data = $card_state_stats($stats);
+        $totals = [];
+        $items = Model('')->table('card_key')
+            ->field('card_type, card_state, count(*) as card_count, sum(amount) as card_amounts')
+            ->where($condition)
+            ->group('card_type,card_state')
+            ->order('card_type asc, card_state asc')
+            ->select();
+        foreach ($items as $item) {
+            $card_type = $item['card_type'];
+            $key = "{$card_type_texts[$card_type]}-总计:";
+            $totals[$key][] = $item;
         }
         }
+        $total = $card_state_stats($totals);
         Tpl::output('card_count', $card_count);
         Tpl::output('card_count', $card_count);
-        Tpl::output('stats', $stats);
+        Tpl::output('stats', $data);
+        Tpl::output('totals', $total);
         Tpl::showpage('card_key.stats');
         Tpl::showpage('card_key.stats');
     }
     }
 
 

+ 67 - 30
shop/templates/default/seller/card_key.stats.php

@@ -11,19 +11,6 @@
         padding: 0 20px;
         padding: 0 20px;
         font-size: 13px;
         font-size: 13px;
     }
     }
-    .ncsc-default-table tbody td {
-        text-align: left;
-        color: #040404;
-    }
-    .cardPassword {
-        width: 100px;
-    }
-    .money {
-        color: red;
-    }
-    .number {
-        color: #1890FF;
-    }
 </style>
 </style>
 <div class="tabmenu">
 <div class="tabmenu">
     <ul class="tab pngFix" id="tab">
     <ul class="tab pngFix" id="tab">
@@ -38,15 +25,13 @@
         <input type="hidden" name="op" value="stats"/>
         <input type="hidden" name="op" value="stats"/>
         <tr>
         <tr>
             <td class="count">共<?php echo $output['card_count']?>张&nbsp;</td>
             <td class="count">共<?php echo $output['card_count']?>张&nbsp;</td>
-            <th>卡密状态</th>
-            <td class="w100">
-                <select name="card_state">
-                    <option value=""><?php echo $lang['nc_please_choose']; ?></option>
-                    <option value="0" <?php if (isset($_GET['card_state']) && $_GET['card_state'] == 0) { ?>selected="selected"<?php } ?>>未使用</option>
-                    <option value="1" <?php if ($_GET['card_state'] == 1) { ?>selected="selected"<?php } ?>>充值中</option>
-                    <option value="2" <?php if ($_GET['card_state'] == 2) { ?>selected="selected"<?php } ?>>已使用</option>
-                    <option value="3" <?php if ($_GET['card_state'] == 3) { ?>selected="selected"<?php } ?>>冻结</option>
-                </select>
+            <th style="width: 100px;">卡密使用时间</th>
+            <td class="w400">
+                <input class="txt date" type="text" value="<?php echo $_GET['query_start_time']; ?>"
+                       id="startTime" name="query_start_time" autocomplete="off" style="width:120px" />
+                <label for="query_start_time">~</label>
+                <input class="txt date" type="text" value="<?php echo $_GET['query_end_time']; ?>"
+                       id="endTime" name="query_end_time" autocomplete="off" style="width:120px" />
             </td>
             </td>
             <td class="w70 tc"><label class="submit-border">
             <td class="w70 tc"><label class="submit-border">
                     <input type="submit" class="submit" value="搜索"/>
                     <input type="submit" class="submit" value="搜索"/>
@@ -54,17 +39,57 @@
         </tr>
         </tr>
     </table>
     </table>
 </form>
 </form>
-<table class="ncsc-default-table">
+<table class="ncsc-default-table" id="card_stats">
+    <thead>
+    <tr>
+        <th class="w150">卡密</th>
+        <th class="w100">未使用数量</th>
+        <th class="w100">金额</th>
+        <th class="w100">充值中数量</th>
+        <th class="w100">金额</th>
+        <th class="w100">已使用数量</th>
+        <th class="w100">金额</th>
+        <th class="w100">冻结中数量</th>
+        <th class="w100">金额</th>
+    </tr>
+    </thead>
     <tbody>
     <tbody>
     <?php if (!empty($output['stats'])) { ?>
     <?php if (!empty($output['stats'])) { ?>
-        <?php foreach ($output['stats'] as $val) { ?>
+        <?php foreach ($output['stats'] as $key => $stats) { ?>
             <tr>
             <tr>
-            <td class="cardPassword"><?php echo $val[0]['card_type_text']?>卡密</td>
-            <td>
-            <?php foreach($val as $count) {?>
-                <span class="money"><?php echo $count['amount']?>元:</span><span class="number"><?php echo $count['card_count']?>张</span>&nbsp;&nbsp;&nbsp;
-            <?php }?>
-            </td>
+                <td class="w150"><?php echo $key;?></td>
+                <td class="w100"><?php echo $stats['UnusedCardCount'];?></td>
+                <td class="w100"><?php echo $stats['UnusedCardAmounts'];?></td>
+                <td class="w100"><?php echo $stats['ReserveCardCount'];?></td>
+                <td class="w100"><?php echo $stats['ReserveCardAmounts'];?></td>
+                <td class="w100"><?php echo $stats['AssignedCardCount'];?></td>
+                <td class="w100"><?php echo $stats['AssignedCardAmounts'];?></td>
+                <td class="w100"><?php echo $stats['FreezedCardCount'];?></td>
+                <td class="w100"><?php echo $stats['FreezedCardAmounts'];?></td>
+            </tr>
+        <?php } ?>
+        <tr>
+            <td><hr/></td>
+            <td><hr/></td>
+            <td><hr/></td>
+            <td><hr/></td>
+            <td><hr/></td>
+            <td><hr/></td>
+            <td><hr/></td>
+            <td><hr/></td>
+            <td><hr/></td>
+        </tr>
+        <?php foreach ($output['totals'] as $key => $total) { ?>
+            <tr>
+                <td class="w150"><?php echo $key;?></td>
+                <td class="w100"><?php echo $total['UnusedCardCount'];?></td>
+                <td class="w100"><?php echo $total['UnusedCardAmounts'];?></td>
+                <td class="w100"><?php echo $total['ReserveCardCount'];?></td>
+                <td class="w100"><?php echo $total['ReserveCardAmounts'];?></td>
+                <td class="w100"><?php echo $total['AssignedCardCount'];?></td>
+                <td class="w100"><?php echo $total['AssignedCardAmounts'];?></td>
+                <td class="w100"><?php echo $total['FreezedCardCount'];?></td>
+                <td class="w100"><?php echo $total['FreezedCardAmounts'];?></td>
             </tr>
             </tr>
         <?php } ?>
         <?php } ?>
     <?php } else { ?>
     <?php } else { ?>
@@ -86,5 +111,17 @@
 </table>
 </table>
 <script src="<?php echo RESOURCE_SITE_URL; ?>/js/jquery.poshytip.min.js"></script>
 <script src="<?php echo RESOURCE_SITE_URL; ?>/js/jquery.poshytip.min.js"></script>
 <script src="<?php echo SHOP_RESOURCE_SITE_URL; ?>/js/store_goods_list.js"></script>
 <script src="<?php echo SHOP_RESOURCE_SITE_URL; ?>/js/store_goods_list.js"></script>
+<script type="text/javascript" src="<?php echo RESOURCE_SITE_URL; ?>/laydate/laydate.js"></script>
 <script>
 <script>
+    $(function(){
+        // 日期选择器
+        laydate.render({
+            elem: '#startTime',
+            type: 'datetime'
+        });
+        laydate.render({
+            elem: '#endTime',
+            type: 'datetime'
+        });
+    });
 </script>
 </script>

+ 45 - 0
test/TestRedis.php

@@ -8,6 +8,7 @@ require_once(BASE_CORE_PATH . '/lrlz.php');
 require_once(BASE_ROOT_PATH . '/fooder.php');
 require_once(BASE_ROOT_PATH . '/fooder.php');
 
 
 require_once (BASE_ROOT_PATH . '/helper/util_helper.php');
 require_once (BASE_ROOT_PATH . '/helper/util_helper.php');
+require_once(BASE_HELPER_PATH . '/refill/RefillFactory.php');
 
 
 
 
 function sub_callback($redis, $chan, $msg)
 function sub_callback($redis, $chan, $msg)
@@ -134,8 +135,52 @@ class TestRedis extends TestCase
         $z = !isset($y) || (is_object($y) == false);
         $z = !isset($y) || (is_object($y) == false);
     }
     }
 
 
+    public function testWRcache()
+    {
+        $t = current(['1000119000003695610' => time()]);
+        wcache("card_expired",['1000119000003695610' => time()],'');
+        $x = rcache('card_expired','','1000119000003695610');
+    }
+
+    public function testSpeed()
+    {
+        for ($i = 0; $i < 1000000; ++$i) {
+            refill\util::incr_commit('lingzh',1,100,1,true);
+            $ret = refill\util::hget_commit_sec('lingzh',1,100,1,time(),true);
+        }
+    }
+
+    public function testOrderSn()
+    {
+        $order_sn = $this->_makeOrderSn();
+    }
+
+    private function _makeOrderSn()
+    {
+        static $prime_num = [11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97];
+        static $factor = 0;
+        if($factor == 0) {
+            $pos = mt_rand(0,count($prime_num) - 1);
+            $factor = $prime_num[$pos];
+            if($factor < 100) {
+                $factor += mt_rand(100,count($prime_num) - 1);
+            }
+        }
+
+        $prefix = (getmypid() * $factor) % 1000;
+        return sprintf('%03d', $prefix)
+            . sprintf('%03d', mt_rand(100,999))
+            . sprintf('%010d', time() - 946656000)
+            . sprintf('%06d', (float)microtime() * 1000000);
+    }
+
+    public function testSHA1()
+    {
+        $x = sha1('xxxxxxxx',true);
+    }
 
 
     public static function tearDownAfterClass() : void
     public static function tearDownAfterClass() : void
     {
     {
+
     }
     }
 }
 }

+ 6 - 0
test/TestTime.php

@@ -25,6 +25,12 @@ class TestTime extends TestCase
         Base::run_util();
         Base::run_util();
     }
     }
 
 
+    public function testMicro()
+    {
+        $y = (float) microtime();
+        $x = sprintf('%03d', $y * 1000000);
+    }
+
     public function testS()
     public function testS()
     {
     {
         $date = date('Y-m-d H:i:S',1517399862);
         $date = date('Y-m-d H:i:S',1517399862);