stanley-king 4 rokov pred
rodič
commit
5286cb2e3e

+ 1 - 1
core/framework/libraries/model.php

@@ -847,7 +847,7 @@ class ModelDb
         //|| is_numeric($value)
         if(is_string($value)) {
             $value = '\''.$this->escapeString($value).'\'';
-        }elseif(isset($value[0]) && is_string($value[0]) && strtolower($value[0]) == 'exp'){
+        }elseif(isset($value[0]) && is_string($value[0]) && strtolower($value[0]) == 'exp') {
             $value   =  $value[1];
         }elseif(is_array($value)) {
             $value   =  array_map([$this, 'parseValue'],$value);

+ 3 - 3
data/config/dev/base.ini.php

@@ -45,7 +45,7 @@ $config['gip'] 		= 0;
 $config['dbdriver'] = 'mysqli';
 $config['tablepre']	= 'lrlz_';
 
-define('SSH_TUNEL_PROD',false);
+define('SSH_TUNEL_PROD',true);
 
 if(SSH_TUNEL_PROD === false) {
     $config['db'][1]['dbhost']       = MASTER_DBHOST;
@@ -68,14 +68,14 @@ else {
     $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]['dbpwd']        = 'XTZ@shop@951688';
     $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]['dbpwd']      = 'XTZ@shop@951688';
     $config['db']['slave'][0]['dbname']     = 'xyzshop';
     $config['db']['slave'][0]['dbcharset']  = 'UTF-8';
 }

+ 2 - 0
helper/refill/LZRefillFactory.php

@@ -9,6 +9,8 @@ require_once(BASE_HELPER_PATH . '/refill/policy/IPolicy.php');
 require_once(BASE_HELPER_PATH . '/refill/policy/lingzh/policy.php');
 require_once(BASE_HELPER_PATH . '/refill/policy/chctl.php');
 require_once(BASE_HELPER_PATH . '/refill/policy/ctl_item.php');
+require_once(BASE_HELPER_PATH . '/refill/policy/mchctl.php');
+
 
 use Log;
 use StatesHelper;

+ 7 - 4
helper/refill/RefillBase.php

@@ -44,6 +44,10 @@ class RefillBase
         $this->mPolicy->load();
     }
 
+    public function first_quality($mchid) {
+        return $this->mPolicy->first_quality($mchid);
+    }
+
     public function notify($chname, $input)
     {
         $caller = $this->mPolicy->getCaller($chname);
@@ -127,15 +131,14 @@ class RefillBase
 
     private function retry(array $refill_info, array $order_info)
     {
-        if(!$this->mPolicy->can_retry($refill_info,$order_info)) {
-            return false;
-        }
+        [$cantry,$quality] = $this->mPolicy->can_retry($refill_info,$order_info);
+        if(!$cantry) return false;
 
         $params = [ 'mchid' => $refill_info['mchid'],
             'buyer_id' => $order_info['buyer_id'],
             'amount' => $refill_info['refill_amount'],
             'card_no' => $refill_info['card_no'],
-            'quality' => $refill_info['quality'],
+            'quality' => $quality,
             'mch_order' =>  $refill_info['mch_order'],
             'notify_url' => $refill_info['notify_url'],
             'idcard' => $refill_info['idcard'] ?? '',

+ 1 - 0
helper/refill/XYZRefillFactory.php

@@ -11,6 +11,7 @@ require_once(BASE_HELPER_PATH . '/refill/policy/IPolicy.php');
 require_once(BASE_HELPER_PATH . '/refill/policy/xyz/policy.php');
 require_once(BASE_HELPER_PATH . '/refill/policy/chctl.php');
 require_once(BASE_HELPER_PATH . '/refill/policy/ctl_item.php');
+require_once(BASE_HELPER_PATH . '/refill/policy/mchctl.php');
 
 use Log;
 use StatesHelper;

+ 3 - 1
helper/refill/policy/IPolicy.php

@@ -6,7 +6,9 @@ namespace refill;
 
 interface IPolicy
 {
-    public function can_retry(array $refill_info, array $order_info) : bool;
+    //[can_try,quality]
+    public function can_retry(array $refill_info, array $order_info) : array;
+    public function first_quality($mchid): int;
     public function allow($mchid,$card_type,$amount,$quality) : bool;
     public function can_nettry($quality,$order_time,$commit_times) : bool;
     public function notify($order_info, $refill_info) : bool;

+ 6 - 2
helper/refill/policy/lingzh/policy.php

@@ -55,9 +55,13 @@ class policy extends ProviderManager implements IPolicy
         return [$result,$overload];
     }
 
-    public function can_retry(array $refill_info, array $order_info): bool
+    public function first_quality($mchid): int
     {
-        return false;
+
+    }
+    public function can_retry(array $refill_info, array $order_info): array
+    {
+        return [false,0];
     }
 
     public function allow($mchid, $card_type, $amount, $quality): bool

+ 56 - 0
helper/refill/policy/mchctl.php

@@ -0,0 +1,56 @@
+<?php
+
+
+namespace refill;
+
+class mchctl
+{
+    private $mMchidMapCtls;
+    public function __construct()
+    {
+        $this->load();
+
+    }
+
+    public function load()
+    {
+        $this->update_ctl();
+    }
+
+    private function update_price()
+    {
+
+    }
+
+    private function update_ctl()
+    {
+        $this->mMchidMapCtls = [];
+        $mod_merchant = Model('merchant');
+        $merchants = $mod_merchant->getMerchantList([]);
+
+        foreach ($merchants as $item) {
+            $mchid = $item['mchid'];
+            $quality = intval($item['quality']);
+            $time_out = $item['time_out'];
+
+            if ($quality < 1 || $quality > 3) {
+                $quality = 1;
+            }
+
+            $this->mMchidMapCtls[$mchid] = ['quality' => $quality,'time_out' => $time_out];
+        }
+    }
+
+    public function getCtls($mchid)
+    {
+        if(array_key_exists($mchid,$this->mMchidMapCtls)) {
+            $quality = $this->mMchidMapCtls[$mchid]['quality'];
+            $time_out = $this->mMchidMapCtls[$mchid]['time_out'];
+
+            return [true,$quality,$time_out];
+        }
+        else {
+            return [false,0,0];
+        }
+    }
+}

+ 35 - 9
helper/refill/policy/xyz/policy.php

@@ -16,16 +16,19 @@ class policy extends ProviderManager implements IPolicy
     const high_time_out = 60;
 
     protected $mChannelControl;
+    protected $mMchctl;
     public function __construct()
     {
         parent::__construct();
         $this->mChannelControl = new chctl();
+        $this->mMchctl = new mchctl();
     }
 
     public function load()
     {
         parent::load();
         $this->mChannelControl->load();
+        $this->mMchctl->load();
     }
 
     public function find_providers(int $spec, int $card_type,int $quality): array
@@ -81,33 +84,56 @@ class policy extends ProviderManager implements IPolicy
         return $providers;
     }
 
-    public function can_retry(array $refill_info, array $order_info) : bool
+    public function can_retry(array $refill_info, array $order_info) : array
     {
-        $checker = function ($refill, $order)
+        $checker = function ($refill, $order,$time_out,$quality)
         {
             $state = intval($order['order_state']);
             if ($state !== ORDER_STATE_SEND) {
                 Log::record("retry false:order_state != send", Log::DEBUG);
-                return false;
+                return [false,0];
             }
 
             $times = intval($refill['commit_times']);
             if ($times > policy::normal_times) {
-                return false;
+                return [false,0];
             }
 
             $period = time() - $refill['order_time'];
-            if ($period >= policy::normle_time_out) {
+            if ($period >= $time_out) {
                 Log::record("retry false:time > 15m", Log::DEBUG);
-                return false;
+                return [false,0];
+            }
+            elseif($period + 60 > $time_out && $quality == 3) {
+                return [true,2];
+            }
+            else {
+                return [true,$quality];
             }
-
-            return true;
         };
 
-        return $checker($refill_info, $order_info);
+        $mchid = $refill_info['mchid'];
+        [$sucdess,$quality,$time_out] = $this->mMchctl->getCtls($mchid);
+
+        if($sucdess) {
+            return $checker($refill_info, $order_info,$time_out,$quality);
+        }
+        else {
+            return $checker($refill_info, $order_info,policy::normle_time_out,1);
+        }
+    }
+
+    public function first_quality($mchid): int
+    {
+        [$sucdess,$quality,$time_out] = $this->mMchctl->getCtls($mchid);
+        if($sucdess) {
+            return $quality;
+        } else {
+            return 1;
+        }
     }
 
+
     public function allow($mchid,$card_type,$amount,$quality) : bool
     {
         $reader = function () {

+ 2 - 1
mobile/control/refill.php

@@ -67,7 +67,8 @@ class refillControl extends merchantControl
         $card_no = $_GET['cardno'];
         $notify_url = $_GET['notifyurl'];
         $mch_order = $_GET['order_sn']; //对方的order编号
-        $quality = $_GET['quality'] ?? 1;
+
+        $quality = refill\RefillFactory::instance()->first_quality($this->mchid());
 
         if(!$this->check_mchorder($this->mchid(),$mch_order)) {
             return self::outerr(205,"客户订单号重复或者为空.");

+ 6 - 0
test/TestRefill.php

@@ -1140,6 +1140,12 @@ class TestRefill extends TestCase
 
 
     }
+
+    public function testMchctl()
+    {
+        $ctl = new refill\mchctl();
+
+    }
 }