stanley-king 4 年 前
コミット
816493182b

+ 3 - 0
admin/control/cache.php

@@ -202,6 +202,9 @@ class cacheControl extends SystemControl
             if(in_array('bargain_goods',$todo)) {
                 $this->mPublisher->modify_activity_bargain_goods();
             }
+            if(in_array('refill_channel',$todo)) {
+                $this->mPublisher->modify_refill_channel();
+            }
         }
 
         $this->log(L('cache_cls_operate'));

+ 1 - 0
admin/language/zh/cache.php

@@ -28,6 +28,7 @@ $lang['cache_cls_payfcode']	    = '支付后F码商品';
 $lang['cache_cls_optionalgoods']= '任选专区信息';
 $lang['cache_cls_goodssampler'] = '红包内推荐商品';
 $lang['cache_cls_bargaingoods'] = '砍价商品';
+$lang['cache_cls_refill_channel'] = '更新渠道缓存';
 
 
 

+ 1 - 0
admin/language/zh_cn/cache.php

@@ -28,6 +28,7 @@ $lang['cache_cls_payfcode']	    = '支付后F码商品';
 $lang['cache_cls_optionalgoods']= '任选专区信息';
 $lang['cache_cls_goodssampler'] = '红包内推荐商品';
 $lang['cache_cls_bargaingoods'] = '砍价商品';
+$lang['cache_cls_refill_channel'] = '更新渠道缓存';
 
 $lang['cache_cls_salelist']	    = '手机品牌相关缓存';
 $lang['cache_cls_appversion']	= 'Andrid手机版本信息缓存';

+ 7 - 0
admin/templates/default/cache.clear.php

@@ -184,6 +184,13 @@
                                             &nbsp;<?php echo $lang['cache_cls_bargaingoods'] ?>
                                         </label>
                                     </li>
+                                    <li class="left w18pre">
+                                        <label>
+                                            <input type="checkbox" name="cache[]" id="refill_channel"
+                                                   value="refill_channel">
+                                            &nbsp;<?php echo $lang['cache_cls_refill_channel'] ?>
+                                        </label>
+                                    </li>
                                 </ul>
                             </td>
                         </tr>

+ 42 - 0
crontab/control/minutes.php

@@ -9,6 +9,7 @@
 
 defined('InShopNC') or exit('Access Invalid!');
 
+
 class minutesControl extends BaseCronControl
 {
     public function indexOp()
@@ -18,10 +19,51 @@ class minutesControl extends BaseCronControl
         $this->_order_timeout_cancel();
         $this->_cron_common();
         $this->_web_index_update();
+        $this->_check_merchant_alarm_amount();
 //      $this->_cron_mail_send();
         Log::record(__FUNCTION__ . " end",Log::DEBUG);
     }
 
+    private function _check_merchant_alarm_amount()
+    {
+        $mch_cache = rcache("merchant-notify" , 'refill-');
+        $caches = empty($mch_cache['data']) ? [] : unserialize($mch_cache['data']);
+
+        $new_caches = [];
+        $merchants = Model('merchant')->getMerchantList([],'','','merchant.*,member.available_predeposit' ,"0,1000");
+        foreach ($merchants as $merchant)
+        {
+            $mchid = $merchant['mchid'];
+            $phone = $merchant['contact_phone'] ?? "";
+            $available_pd = intval($merchant['available_predeposit']);
+            $alarm_pd = intval($merchant['alarm_amount']);
+
+            if(array_key_exists($mchid,$caches)) {
+                $mch_cache = $caches[$mchid];
+            }
+            else {
+                $mch_cache = ['last_time' => 0, 'send_count' => 0];
+            }
+
+            if(!empty($phone) && ($available_pd < $alarm_pd || $available_pd < 10000))
+            {
+                $counts =  $mch_cache['send_count'];
+                if(($mch_cache['last_time'] + 300 < time()) && $counts < 5) {
+                    $mch_cache = ['last_time' => time(), 'send_count' => $counts + 1];
+                    QueueClient::push('sendSMS', ['mobile'=>$merchant['contact_phone'],
+                        'type'=>'balance_warning','datas' => [date("m月d日H时") , $merchant['available_predeposit']]]);
+
+                }
+            }
+            else {
+                $mch_cache = ['last_time' => 0, 'send_count' => 0];
+            }
+            $new_caches[$mchid] = $mch_cache;
+        }
+
+        wcache("merchant-notify", ['data' => serialize($new_caches)], 'refill-');
+    }
+
     /**
      * 未付款订单超期自动关闭
      */

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

@@ -51,7 +51,7 @@ $config['gip'] 		= 0;
 $config['dbdriver'] = 'mysqli';
 $config['tablepre']	= 'lrlz_';
 
-define('SSH_TUNEL_PROD',true);
+define('SSH_TUNEL_PROD',false);
 
 if(SSH_TUNEL_PROD === false) {
     $config['db'][1]['dbhost']       = 'host.docker.internal';
@@ -71,7 +71,6 @@ if(SSH_TUNEL_PROD === false) {
 else {
     //调试是先执行这行命令
     //shell_exec("ssh -NCPf root@121.89.223.81 -L 3307:127.0.0.1:3306");
-
     $config['db'][1]['dbhost']       = 'host.docker.internal';
     $config['db'][1]['dbport']       = '3307';
     $config['db'][1]['dbuser']       = 'root';

+ 1 - 1
fcgi_run.php

@@ -36,7 +36,7 @@ require_once(BASE_ROOT_PATH . '/helper/url_helper.php');
 require_once(BASE_ROOT_PATH . '/helper/activity_helper.php');
 
 function all_channels() {
-    return ['ch_index','activity','goods'];
+    return ['ch_index','activity','goods','refill'];
 }
 
 Base::mobile_init();

+ 2 - 2
helper/message/msgutil.php

@@ -86,10 +86,10 @@ class StatesHelper
     {
         $type = $msg['type'];
         if($type == 'channel') {
-            $states['init'] = true;
+            $states['channel'] = true;
         }
         elseif($type == "merchant") {
-            $states['init'] = true;
+            $states['merchant'] = true;
         }
     }
 

+ 7 - 0
helper/message/publisher.php

@@ -141,6 +141,13 @@ class publisher
         }
     }
 
+    public function modify_refill_channel()
+    {
+        if($this->mConnected) {
+            $this->mRedis->publish('refill',serialize(['type'=>'channel','value' => 0]));
+        }
+    }
+
     public function modify_activity()
     {
         $this->modify_activity_fullsent();

+ 2 - 0
helper/message/subscriber.php

@@ -81,6 +81,8 @@ class subscriber extends Thread
             StatesHelper::onActivity($this->mStates,$msg);
         } elseif($channel == 'goods') {
             StatesHelper::onGoods($this->mStates,$msg);
+        } elseif($channel == 'refill') {
+            StatesHelper::onRefill($this->mStates,$msg);
         } else {
             $ret = false;
         }

+ 51 - 15
helper/refill/RefillFactory.php

@@ -6,6 +6,9 @@ namespace refill;
 require_once(BASE_HELPER_PATH . '/mtopcard/mtopcard.php');
 require_once(BASE_HELPER_PATH . '/rbridge/RBridgeFactory.php');
 
+require_once(BASE_ROOT_PATH . '/helper/message/msgutil.php');
+require_once(BASE_ROOT_PATH . '/helper/message/subscriber.php');
+
 require_once(BASE_HELPER_PATH . '/refill/IRefill.php');
 require_once(BASE_HELPER_PATH . '/refill/IRefillOil.php');
 require_once(BASE_HELPER_PATH . '/refill/IRefillPhone.php');
@@ -75,6 +78,8 @@ use member_info;
 use Exception;
 use rbridge\RBridgeFactory;
 use trans_wapper;
+use StatesHelper;
+
 
 class RefillFactory
 {
@@ -85,16 +90,20 @@ class RefillFactory
         if (self::$stInstance == null) {
             self::$stInstance = new RefillFactory();
         }
+
+        if(StatesHelper::fetch_state('channel')) {
+            Log::record("RefillFactory reload channel config.",Log::DEBUG);
+            self::$stInstance->load();
+        }
         return self::$stInstance;
     }
 
-    private $mOilProvider = [];
-    private $mPhoneProvider = [];
-    private $mProviderNames = [];
+    private $mOilProvider;
+    private $mPhoneProvider;
+    private $mProviderNames;
 
     private function __construct()
     {
-        $this->load();
     }
 
     public function goods()
@@ -148,29 +157,53 @@ class RefillFactory
         return $result;
     }
 
+    public function read_channel()
+    {
+        $refill_provider = Model('refill_provider');
+        $items = $refill_provider->getProviderList([]);
+
+        $result = [];
+        foreach ($items as $item) {
+            $name = $item['name'];
+            $val = ['type' => intval($item['type']),
+                    'opened' => (intval($item['opened']) == 1) ? true : false,
+                    'sort' => intval($item['sort'])];
+            $result[$name] = $val;
+        }
+
+        return $result;
+    }
+
     private function load()
     {
+        $this->mOilProvider = [];
+        $this->mPhoneProvider = [];
+        $this->mProviderNames = [];
+
         global $config;
         $oil_configs = $config['oil_providers'];
 
+        $cfg_table = $this->read_channel();
         $names = [];
         foreach ($oil_configs as $item)
         {
             $name = $item['name'];
             $cfg = $item['cfg'];
 
-            $opened = $item['opened'] ?? true;
-            $sort = $item['sort'] ?? 65536;
-
-            $names[] = $name;
+            if(!array_key_exists($name,$cfg_table)) {
+                continue;
+            }
 
             try {
                 $class = "refill\\{$name}\\RefillOil";
+                $table = $cfg_table[$name];
+
                 if (class_exists($class, false)) {
                     $provider = new $class($cfg);
-                    $provider->setOpened($opened);
-                    $provider->setSort($sort);
+                    $provider->setOpened($table['opened']);
+                    $provider->setSort($table['sort']);
 
+                    $names[] = $name;
                     $this->mOilProvider[] = $provider;
                 } else {
                     $error = "Base Error: class {$class} isn't exists!";
@@ -186,17 +219,20 @@ class RefillFactory
         {
             $name = $item['name'];
             $cfg = $item['cfg'];
-            $opened = $item['opened'] ?? true;
-            $sort = $item['sort'] ?? 65536;
 
-            $names[] = $name;
+            if(!array_key_exists($name,$cfg_table)) {
+                continue;
+            }
 
             try {
                 $class = "refill\\{$name}\\RefillPhone";
+                $table = $cfg_table[$name];
+
                 if (class_exists($class, false)) {
                     $provider = new $class($cfg);
-                    $provider->setOpened($opened);
-                    $provider->setSort($sort);
+                    $provider->setOpened($table['opened']);
+                    $provider->setSort($table['sort']);
+                    $names[] = $name;
 
                     $this->mPhoneProvider[] = $provider;
                 } else {

+ 1 - 0
mobile/control/merchant.php

@@ -16,6 +16,7 @@ class merchantControl
         else {
             $this->mAdminid = intval($mchinfo['admin_id']);
         }
+
         if ($mchinfo['merchant_state'] != 1) {
             throw new Exception("机构已被关闭。");
         }

+ 3 - 3
mobile/control/merchant_info.php

@@ -105,7 +105,7 @@ class merchant_infoControl extends mbMerchantControl
             $result[$begin] = $item;
 
             //判断item 中充值中的状态是否为0,为0且不是今天的情况下放进cache
-            if($item['otherCount'] == 0 && $begin != $today){
+            if($item['sendCount'] == 0 && $begin != $today){
                 $cache[$begin] = $item;
             }
         }
@@ -124,11 +124,11 @@ class merchant_infoControl extends mbMerchantControl
 
     private function refillCountDispose($stats)
     {
-        $result['count'] = $result['otherCount'] = $result['errorCount'] = $result['successCount'] = $result['amountCount'] = 0;
+        $result['count'] = $result['sendCount'] = $result['errorCount'] = $result['successCount'] = $result['amountCount'] = 0;
         foreach ($stats as $count) {
             $result['count'] += $count['order_count'];
             if($count['order_state'] == ORDER_STATE_SEND) {
-                $result['otherCount'] = $count['order_count'];
+                $result['sendCount'] = $count['order_count'];
             }
             if($count['order_state'] == ORDER_STATE_CANCEL) {
                 $result['errorCount'] = $count['order_count'];

+ 43 - 0
test/TestRefill.php

@@ -823,7 +823,50 @@ class TestRefill extends TestCase
         return $result;
     }
 
+    public function testNotify()
+    {
+        $mch_cache = rcache("merchant-notify" , 'refill-');
+        $caches = empty($mch_cache['data']) ? [] : unserialize($mch_cache['data']);
+
+        $new_caches = [];
+        $merchants = Model('merchant')->getMerchantList([],'','','merchant.*,member.available_predeposit' ,"0,1000");
+        foreach ($merchants as $merchant)
+        {
+            $mchid = $merchant['mchid'];
+            $phone = $merchant['contact_phone'] ?? "";
+            $available_pd = intval($merchant['available_predeposit']);
+            $alarm_pd = intval($merchant['alarm_amount']) < 10000 ? 10000 : intval($merchant['alarm_amount']);
+
+            if(array_key_exists($mchid,$caches)) {
+                $mch_cache = $caches[$mchid];
+            }
+            else {
+                $mch_cache = ['last_time' => 0, 'send_count' => 0];
+            }
 
+            if(!empty($phone) && ($available_pd < $alarm_pd))
+            {
+                $counts =  $mch_cache['send_count'];
+                if(($mch_cache['last_time'] + 300 < time()) && $counts < 5) {
+                    $mch_cache = ['last_time' => time(), 'send_count' => $counts + 1];
+                    QueueClient::push('sendSMS', ['mobile'=>$merchant['contact_phone'],
+                        'type'=>'balance_warning','datas' => [date("m月d日H时") , $merchant['available_predeposit']]]);
+
+                }
+            }
+            else {
+                $mch_cache = ['last_time' => 0, 'send_count' => 0];
+            }
+            $new_caches[$mchid] = $mch_cache;
+        }
+
+        wcache("merchant-notify", ['data' => serialize($new_caches)], 'refill-');
+    }
+
+    public function testReadChannel()
+    {
+        refill\RefillFactory::instance()->read_channel();
+    }
 }