stanley-king 4 years ago
parent
commit
6df7d558fe
3 changed files with 35 additions and 8 deletions
  1. 11 7
      admin/control/merchant.php
  2. 7 0
      helper/refill/RefillBase.php
  3. 17 1
      helper/refill/policy/xyz/policy.php

+ 11 - 7
admin/control/merchant.php

@@ -208,6 +208,8 @@ class merchantControl extends SystemControl
 
     public function oilAmountLockOp()
     {
+        $turn_name = 'oil_amount_lock_turn';
+
         if(chksubmit())
         {
             $lock_opened = $_POST['lock_opened'];
@@ -215,30 +217,32 @@ class merchantControl extends SystemControl
                 showMessage('开启状态有误', '');
             }
             if($lock_opened == 1) {
-                wkcache('oil_amount_lock_opened', true);
+                wkcache($turn_name, true);
             } elseif ($lock_opened == 0) {
-                wkcache('oil_amount_lock_opened', false);
+                wkcache($turn_name, false);
             }
 
             $mchids = $_POST['mchid'];
             $change_amounts = $_POST['change'];
-            foreach ($mchids as $key => $mchid) {
+            foreach ($mchids as $key => $mchid)
+            {
                 $mchid = intval($mchid);
                 $amount = $change_amounts[$key];
                 if(!empty($amount)){
-                    \refill\util::set_amount_lock($mchid, $amount);
+                    refill\util::set_amount_lock($mchid, $amount);
                 }
             }
             showMessage('编辑成功', 'index.php?act=merchant&op=merchant');
         }
         else
         {
-            $lock_opened = rkcache('oil_amount_lock_opened');
+            $lock_opened = rkcache($turn_name);
 
-            $model_merchant = model('merchant');
+            $model_merchant = Model('merchant');
             $merchant_list = $model_merchant->getMerchantList([], 1000, 'mchid asc', 'mchid,company_name');
             $result = $data = [];
-            foreach ($merchant_list as $merchant) {
+            foreach ($merchant_list as $merchant)
+            {
                 $mchid = intval($merchant['mchid']);
                 $amount_lock = \refill\util::get_amount_lock($mchid);
                 $result['mchid'] = $mchid;

+ 7 - 0
helper/refill/RefillBase.php

@@ -112,6 +112,8 @@ class RefillBase
                 if(!empty($refill_info))
                 {
                     util::incr_notify($chname, $card_type, $spec, $quality, false);
+                    util::decr_amount_lock($refill_info['mchiid'],$card_type,$refill_info['refill_amount']);
+
                     $logic_vr_order->changeOrderStateCancel($order_info, '', "{$chname}接口回调通知失败,正在重试");
 
                     [$can_retry,$params] = $this->retry($refill_info, $order_info);
@@ -132,6 +134,8 @@ class RefillBase
             }
             else {
                 util::incr_notify($chname, $card_type, $spec, $quality, false);
+                util::decr_amount_lock($refill_info['mchiid'],$card_type,$refill_info['refill_amount']);
+
                 $logic_vr_order->changeOrderStateCancel($order_info, '', "{$chname}接口回调通知失败,不可重试.");
             }
             $tran->commit();
@@ -349,6 +353,7 @@ class RefillBase
             {
                 //提交成功
                 util::incr_commit($channel_name,$card_type,$amount,$quality,true);
+                util::incr_amount_lock($mchid,$card_type,$amount);
                 $trade_no = $errmsg;
                 if ($provider->refill_type() == 'api') {
                     $logic_vr_order = Logic("vr_order");
@@ -369,6 +374,8 @@ class RefillBase
             else {
                 //提交失败
                 util::incr_commit($channel_name,$card_type,$amount,$quality,false);
+                util::decr_amount_lock($mchid,$card_type,$amount);
+
                 Log::record("channel:{$channel_name} err:{$errmsg}");
                 $logic_vr_order = Logic("vr_order");
                 $order_info = Model('vr_order')->getOrderInfo(['order_id' => $order_id]);

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

@@ -14,6 +14,7 @@ class policy extends ProviderManager implements IPolicy
     protected $mMchctl;
     protected $mQuality;
     protected $mPrices;
+    protected $mAmountLockTurn;
 
     public function __construct()
     {
@@ -32,8 +33,12 @@ class policy extends ProviderManager implements IPolicy
         $this->mMchctl->load();
         $this->mQuality->load();
         $this->mPrices->load();
+
+        $turn_name = 'oil_amount_lock_turn';
+        $this->mAmountLockTurn = rkcache($turn_name);
     }
 
+
     public function find_providers(int $spec, int $card_type,int $quality): array
     {
         $providers = parent::find_providers($spec,$card_type,$quality);
@@ -115,7 +120,18 @@ class policy extends ProviderManager implements IPolicy
 
     public function allow($mchid,$card_type,$amount,$quality) : bool
     {
-        $reader = function () {
+        if($this->mAmountLockTurn) {
+            return util::get_amount_lock($mchid) > 0;
+        }
+        else {
+            return true;
+        }
+    }
+
+    private function allow_storge($mchid,$card_type,$amount,$quality)
+    {
+        $reader = function ()
+        {
             $cache = rcache("refill_able",'merchant-');
             if(!empty($cache)) {
                 $result = unserialize($cache['data']);