stanley-king 4 lat temu
rodzic
commit
5d39bcb1e5

+ 5 - 8
helper/refill/RefillBase.php

@@ -102,6 +102,7 @@ class RefillBase
             $quality = intval($refill_info['quality']);
             $card_type = intval($refill_info['card_type']);
             $spec = intval($refill_info['refill_amount']);
+            $mchid = intval($refill_info['mchid']);
 
             if ($success) {
                 util::incr_notify($chname, $card_type, $spec, $quality, true);
@@ -112,7 +113,7 @@ class RefillBase
                 if(!empty($refill_info))
                 {
                     util::incr_notify($chname, $card_type, $spec, $quality, false);
-                    util::incr_amount_lock($refill_info['mchid'],$card_type,$refill_info['refill_amount']);
+                    util::incr_amount_lock($mchid,$card_type,$spec);
 
                     $logic_vr_order->changeOrderStateCancel($order_info, '', "{$chname}接口回调通知失败,正在重试");
 
@@ -121,11 +122,6 @@ class RefillBase
                     {
                         $mod_refill->edit($order_id, ['is_retrying' => 1]);
                         $tran->commit();
-
-//                        if(defined('USE_COROUTINE') && USE_COROUTINE) {
-//                            \Swoole\Coroutine::sleep(1);
-//                        }
-
                         util::push_add($params);
                         return true;
                     }
@@ -133,7 +129,7 @@ class RefillBase
             }
             else {
                 util::incr_notify($chname, $card_type, $spec, $quality, false);
-                util::incr_amount_lock($refill_info['mchid'],$card_type,$refill_info['refill_amount']);
+                util::incr_amount_lock($mchid,$card_type,$spec);
 
                 $logic_vr_order->changeOrderStateCancel($order_info, '', "{$chname}接口回调通知失败,不可重试.");
             }
@@ -345,6 +341,7 @@ class RefillBase
                 'quality' => $quality,'order_id' => $order_id];
 
             util::incr_commit_pre($channel_name,$card_type,$amount,$quality);
+            util::decr_amount_lock($mchid,$card_type,$amount);
 
             $start = microtime(true);
             [$state, $errmsg, $neterr] = $provider->add($card_no, $card_type, $amount, $params);
@@ -354,7 +351,6 @@ class RefillBase
             {
                 //提交成功
                 util::incr_commit($channel_name,$card_type,$amount,$quality,true);
-                util::decr_amount_lock($mchid,$card_type,$amount);
                 $trade_no = $errmsg;
                 if ($provider->refill_type() == 'api') {
                     $logic_vr_order = Logic("vr_order");
@@ -375,6 +371,7 @@ class RefillBase
             else {
                 //提交失败
                 util::incr_commit($channel_name,$card_type,$amount,$quality,false);
+                util::incr_amount_lock($mchid,$card_type,$amount);
 
                 Log::record("channel:{$channel_name} err:{$errmsg}");
                 $logic_vr_order = Logic("vr_order");

+ 16 - 18
helper/refill/policy/rlock.php

@@ -10,11 +10,14 @@ class rlock
     const RETAIN = 2;
     const ASSIGN = 3;
 
+    const sys_storge_name = 'system_storge';
+    const mch_storge_name = 'merchant_storge';
+
     //system storge
     public static function incr_sys_storge($card_type,$spec,$count)
     {
         $ins = Cache::getInstance('cacheredis');
-        $name = 'system_storge';
+        $name = self::sys_storge_name;
         $key = "{$card_type}-{$spec}";
 
         return $ins->hIncrBy($name, $key, $spec * $count);
@@ -23,18 +26,16 @@ class rlock
     public static function decr_sys_storge($card_type,$spec,$count)
     {
         $ins = Cache::getInstance('cacheredis');
-        $name = 'system_storge';
+        $name = self::sys_storge_name;
         $key = "{$card_type}-{$spec}";
-
         return $ins->hIncrBy($name, $key, -1 * $spec * $count);
     }
 
     public static function hget_sys_storge($card_type,$spec)
     {
         $ins = Cache::getInstance('cacheredis');
-        $name = 'system_storge';
+        $name = self::sys_storge_name;
         $key = "{$card_type}-{$spec}";
-
         $value = $ins->hget($name, '', $key);
         return $value;
     }
@@ -43,7 +44,7 @@ class rlock
     public static function incr_mch_total_storge($mchid,$card_type,$amount)
     {
         $ins = Cache::getInstance('cacheredis');
-        $name = 'merchant_storge';
+        $name = self::mch_storge_name;
         $key = "{$mchid}-{$card_type}-total";
         return $ins->hIncrBy($name, $key, $amount);
     }
@@ -51,7 +52,7 @@ class rlock
     public static function decr_mch_total_storge($mchid,$card_type,$amount)
     {
         $ins = Cache::getInstance('cacheredis');
-        $name = 'merchant_storge';
+        $name = self::mch_storge_name;
         $key = "{$mchid}-{$card_type}-total";
 
         return $ins->hIncrBy($name, $key, -1 * $amount);
@@ -60,7 +61,7 @@ class rlock
     public static function hget_mch_total_storge($mchid,$card_type)
     {
         $ins = Cache::getInstance('cacheredis');
-        $name = 'merchant_storge';
+        $name = self::mch_storge_name;
         $key = "{$mchid}-{$card_type}-total";
 
         $value = $ins->hget($name, '', $key);
@@ -70,7 +71,7 @@ class rlock
     public static function hset_mch_total_storge_turn($mchid,$card_type,$val)
     {
         $ins = Cache::getInstance('cacheredis');
-        $name = 'merchant_storge';
+        $name = self::mch_storge_name;
         $key = "{$mchid}-{$card_type}-turn";
 
         $ins->hset($name, '', [$key => $val]);
@@ -79,7 +80,7 @@ class rlock
     public static function hget_mch_total_storge_turn($mchid,$card_type)
     {
         $ins = Cache::getInstance('cacheredis');
-        $name = 'merchant_storge';
+        $name = self::mch_storge_name;
         $key = "{$mchid}-{$card_type}-turn";
 
         return $ins->hget($name, '', $key);
@@ -89,7 +90,7 @@ class rlock
     public static function incr_mch_storge($mchid,$card_type,$spec,$count)
     {
         $ins = Cache::getInstance('cacheredis');
-        $name = 'merchant_storge';
+        $name = self::mch_storge_name;
         $key = "{$mchid}-{$card_type}-{$spec}";
 
         return $ins->hIncrBy($name, $key, $spec * $count);
@@ -98,7 +99,7 @@ class rlock
     public static function decr_mch_storge($mchid,$card_type,$spec,$count)
     {
         $ins = Cache::getInstance('cacheredis');
-        $name = 'merchant_storge';
+        $name = self::mch_storge_name;
         $key = "{$mchid}-{$card_type}-{$spec}";
 
         return $ins->hIncrBy($name, $key, -1 * $spec * $count);
@@ -107,7 +108,7 @@ class rlock
     public static function hget_mch_storge($mchid,$card_type,$spec)
     {
         $ins = Cache::getInstance('cacheredis');
-        $name = 'merchant_storge';
+        $name = self::mch_storge_name;
         $key = "{$mchid}-{$card_type}-{$spec}";
 
         $value = $ins->hget($name, '', $key);
@@ -117,7 +118,7 @@ class rlock
     public static function hset_mch_storge_turn($mchid,$card_type,$spec,$val)
     {
         $ins = Cache::getInstance('cacheredis');
-        $name = 'merchant_storge';
+        $name = self::mch_storge_name;
         $key = "{$mchid}-{$card_type}-{$spec}-turn";
 
         $ins->hset($name, '', [$key => $val]);
@@ -126,15 +127,12 @@ class rlock
     public static function hget_mch_storge_turn($mchid,$card_type,$spec)
     {
         $ins = Cache::getInstance('cacheredis');
-        $name = 'merchant_storge';
+        $name = self::mch_storge_name;
         $key = "{$mchid}-{$card_type}-{$spec}-turn";
 
         return $ins->hget($name, '', $key);
     }
     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
-    
-    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     public static function set_total_amount($key, $spec)
     {
         $ins = Cache::getInstance('cacheredis');

+ 23 - 0
helper/refill/policy/rstorge.php

@@ -0,0 +1,23 @@
+<?php
+
+namespace refill;
+
+class sys_amount
+{
+
+}
+
+class rstorge
+{
+
+    public function __construct()
+    {
+    }
+
+    public function load()
+    {
+
+    }
+
+    private function
+}

+ 10 - 7
helper/refill/util.php

@@ -4,6 +4,7 @@ namespace refill;
 
 require_once(BASE_HELPER_PATH . '/mtopcard/mtopcard.php');
 require_once(BASE_HELPER_PATH . '/queue/rdispatcher.php');
+require_once(BASE_HELPER_PATH . '/refill/rlock.php');
 
 use queue;
 use mtopcard;
@@ -11,7 +12,7 @@ use Log;
 use Exception;
 use Cache;
 use QueueClient;
-use function PHPUnit\Framework\returnArgument;
+use refill;
 
 class util
 {
@@ -357,21 +358,22 @@ class util
     public static function incr_amount_lock($mchid, $card_type, $spec)
     {
         if ($card_type == mtopcard\SinopecCard || $card_type == mtopcard\PetroChinaCard) {
-            $ins = Cache::getInstance('cacheredis');
-            $name = 'mechant_amount_lock';
-            return $ins->hIncrBy($name, "{$mchid}", intval($spec));
+            refill\rlock::incr_sys_storge($card_type,$spec,1);
+            refill\rlock::incr_mch_total_storge($mchid,$card_type,$spec);
+            refill\rlock::incr_mch_storge($mchid,$card_type,$spec,1);
         }
     }
 
     public static function decr_amount_lock($mchid, $card_type, $spec)
     {
         if ($card_type == mtopcard\SinopecCard || $card_type == mtopcard\PetroChinaCard) {
-            $ins = Cache::getInstance('cacheredis');
-            $name = 'mechant_amount_lock';
-            return $ins->hIncrBy($name, "{$mchid}", -1 * intval($spec));
+            refill\rlock::decr_sys_storge($card_type,$spec,1);
+            refill\rlock::decr_mch_total_storge($mchid,$card_type,$spec);
+            refill\rlock::decr_mch_storge($mchid,$card_type,$spec,1);
         }
     }
 
+    //todo delete this function
     public static function set_amount_lock($mchid, $spec)
     {
         $ins = Cache::getInstance('cacheredis');
@@ -379,6 +381,7 @@ class util
         return $ins->hIncrBy($name, "{$mchid}", intval($spec));
     }
 
+    //todo delete this function
     public static function get_amount_lock($mchid)
     {
         $ins = Cache::getInstance('cacheredis');