Bladeren bron

admin refill stock and rolock

ayHaru 4 jaren geleden
bovenliggende
commit
8a9600c128

+ 0 - 187
admin/control/merchant.php

@@ -207,193 +207,6 @@ class merchantControl extends SystemControl
         return [true, 'success'];
     }
 
-    public function oilAmountLockOp()
-    {
-        $turn_name = 'oil_amount_lock_turn';
-
-        if(chksubmit())
-        {
-            $lock_opened = $_POST['lock_opened'];
-            if(!in_array($lock_opened, [0,1])) {
-                showMessage('开启状态有误', '');
-            }
-            if($lock_opened == 1) {
-                wkcache($turn_name, true);
-            } elseif ($lock_opened == 0) {
-                wkcache($turn_name, false);
-            }
-
-            $mchids = $_POST['mchid'];
-            $change_amounts = $_POST['change'];
-            foreach ($mchids as $key => $mchid)
-            {
-                $mchid = intval($mchid);
-                $amount = $change_amounts[$key] ?? 0;
-                if(!empty($amount)){
-                    refill\util::set_amount_lock($mchid, $amount);
-                }
-            }
-            showMessage('编辑成功', 'index.php?act=merchant&op=merchant');
-        }
-        else
-        {
-            $lock_opened = rkcache($turn_name);
-
-            $model_merchant = Model('merchant');
-            $cond['merchant_state'] = 1;
-            $cond['available_predeposit'] = ['gt', 0];
-
-            $merchant_list = $model_merchant->getMerchantList($cond, 1000, 'available_predeposit desc', 'mchid,company_name,available_predeposit');
-            $condition['card_types'] = [['like', '%1%'], ['like', '%2%'], 'or'];
-            $check_prices = Model('')->table('merchant_price')
-                ->where($condition)
-                ->field('mchid')
-                ->group('mchid')
-                ->select();
-            if(empty($check_prices)) {
-                $merchant_list = [];
-            } else {
-                foreach ($check_prices as $value) {
-                    $prices[$value['mchid']] = $value;
-                }
-            }
-            $result = $data = [];
-            foreach ($merchant_list as $merchant)
-            {
-                $mchid = intval($merchant['mchid']);
-                if(!array_key_exists($mchid, $prices)) {
-                    continue;
-                }
-                $amount_lock = \refill\util::get_amount_lock($mchid);
-                Log::record("mchid: {$mchid}, amount_lock: {$amount_lock}", Log::DEBUG);
-                $result['mchid'] = $mchid;
-                if (!empty($amount_lock)) {
-                    $result['amount'] = $amount_lock;
-                } else {
-                    $result['amount'] = 0;
-                }
-                $result['company_name'] = $merchant['company_name'];
-                $result['available_predeposit'] = $merchant['available_predeposit'];
-                $data[] = $result;
-            }
-
-            Tpl::output('data', $data);
-            Tpl::output('lock_opened', $lock_opened);
-            Tpl::showpage('oil.amount.lock');
-        }
-    }
-
-    public function amount_lock_emptyOp()
-    {
-        $cond['mchid'] = ['gt', 0];
-        $merchant_list = Model()->table('merchant')->where($cond)->select();
-        if(empty($merchant_list)) {
-            showMessage('操作成功', '');
-        }
-        foreach ($merchant_list as $merchant) {
-            $mchid = intval($merchant['mchid']);
-            $num = \refill\util::get_amount_lock($mchid);
-            $num = 0-$num;
-            refill\util::set_amount_lock($mchid, $num);
-        }
-        showMessage('操作成功', '');
-    }
-
-    public function orderStorgeOp()
-    {
-        if (chksubmit()) {
-            $mchids = $_POST['mchid'];
-            $petrochinas = $_POST['petrochina'];
-            $sinopecs = $_POST['sinopec'];
-            foreach ($mchids as $pos => $mchid) {
-                $mchid = intval($mchid);
-                $data['mchid'] = $mchid;
-                $data['petrochina'] = ['100' => intval($petrochinas[100][$pos]), '200' => intval($petrochinas[200][$pos]), '500' => intval($petrochinas[500][$pos]), '1000' => intval($petrochinas[1000][$pos])];
-                $data['sinopec'] = ['100' => intval($sinopecs[100][$pos]), '200' => intval($sinopecs[200][$pos]), '500' => intval($sinopecs[500][$pos]), '1000' => intval($sinopecs[1000][$pos])];
-                $data['time'] = time();
-                $result[$mchid] = $data;
-            }
-            $this->cache_storge_limit($result);
-            showMessage('编辑成功', 'index.php?act=merchant&op=merchant');
-        } else {
-            $order_limit = rcache('storge_limit', 'merchant-');
-
-            if (empty($order_limit)) {
-                $order_limit = [];
-            } else {
-                $order_limit = unserialize($order_limit['data']);
-            }
-
-            $initialiser = function ($merchant) {
-                $amount = [
-                    '100' => -1,
-                    '200' => -1,
-                    '500' => -1,
-                    '1000' => -1
-                ];
-                $data['mchid'] = $merchant['mchid'];
-                $data['petrochina'] = $data['sinopec'] = $amount;
-                $data['time'] = time();
-                return $data;
-            };
-
-            $reader = function ($mchid, $time) {
-                $cond['mchid'] = $mchid;
-                $cond['inner_status'] = 0;
-                $cond['order_state'] = ORDER_STATE_SUCCESS;
-                $cond['refill_order.order_time'] = ['egt', $time];
-
-                $items = Model('')->table('refill_order,vr_order')->join('inner')
-                    ->on('refill_order.order_id=vr_order.order_id')
-                    ->field('refill_order.mchid,refill_order.card_type,refill_order.refill_amount,count(*) as num')
-                    ->group('refill_order.card_type,refill_order.refill_amount')
-                    ->where($cond)->select();
-
-                return $items;
-            };
-
-            $type_map = [1 => 'petrochina', 2 => 'sinopec'];
-
-            $cur_limits = [];
-            $model_merchant = model('merchant');
-            $merchant_list = $model_merchant->getMerchantList([], 1000, 'mchid asc', 'mchid,company_name');
-            foreach ($merchant_list as $merchant) {
-                $mchid = intval($merchant['mchid']);
-
-                if (array_key_exists($mchid, $order_limit)) {
-                    $result[$mchid] = $order_limit[$mchid];
-                } else {
-                    $result[$mchid] = $initialiser($merchant);
-                }
-                $start = $result[$mchid]['time'];
-                $items = $reader($mchid, $start);
-                $cur_limits[$mchid] = $result[$mchid];
-                foreach ($items as $item) {
-                    $refill_amount = intval($item['refill_amount'] + 0.005);
-                    $card_type = $type_map[$item['card_type']];
-                    $cache_num = $result[$mchid][$card_type][$refill_amount];
-                    if ($cache_num == -1) {
-                        $new_num = -1;
-                    } else {
-                        $new_num = ($cache_num - $item['num']) >= 0 ? $cache_num - $item['num'] : 0;
-                    }
-                    $cur_limits[$mchid][$card_type][$refill_amount] = $new_num;
-                }
-                $cur_limits[$mchid]['company_name'] = $merchant['company_name'];
-            }
-
-            Tpl::output('data', $cur_limits);
-            Tpl::showpage('merchant.orderlimit');
-        }
-    }
-
-    private function cache_storge_limit($data)
-    {
-        Model('')->table('setting')->where(['name' => 'storge_limit'])->delete();
-        Model('')->table('setting')->insert(['name' => 'storge_limit', 'value' => serialize($data)]);
-        wcache('storge_limit', ['data' => serialize($data)], 'merchant-');
-    }
-
     public function priceOp()
     {
         $quality = $_GET['quality'] ? $_GET['quality'] : 1;

+ 55 - 40
admin/control/refill_stock.php

@@ -2,6 +2,7 @@
 
 require_once(BASE_HELPER_PATH . '/refill/policy/rlock.php');
 require_once(BASE_CONFIG_PATH . CONFIG_PREFIX . '/refill.ini.php');
+require_once(BASE_HELPER_PATH . '/mtopcard/mtopcard.php');
 
 class refill_stockControl extends SystemControl
 {
@@ -15,49 +16,61 @@ class refill_stockControl extends SystemControl
         global $config;
         $refill_oil_specs = $config['refill_oil_specs'];
         arsort($refill_oil_specs);
+        $turn_name = \refill\rlock::locked_open_name;
         if(chksubmit())
         {
-            $total = 0;
+            $lock_opened = $_POST['lock_opened'];
+            if(!in_array($lock_opened, [0,1])) {
+                showMessage('开启状态有误', '');
+            }
+            if($lock_opened == 1) {
+                wkcache($turn_name, true);
+            } elseif ($lock_opened == 0) {
+                wkcache($turn_name, false);
+            }
+
+            $card_type = $_POST['card_type'];
             foreach ($refill_oil_specs as $amount) {
                 $key = "total-{$amount}-amount";
-                $incr = $_POST[$key] * $amount;
-                $total += $incr;
-                \refill\rlock::set_total_amount($key, $incr);
+                \refill\rlock::incr_sys_storage($card_type, $amount, $_POST[$key]);
             }
-            \refill\rlock::set_total_amount('total-amount', $total);
-            $mtotal_amounts = $_POST['mtotal_amount'];
-            foreach ($mtotal_amounts as $key => $mtotal_amount) {
-                \refill\rlock::set_amount_stock($key, $mtotal_amount);
+
+            $mch_total_storage = $_POST['mch_total_storage'];
+            foreach ($mch_total_storage as $mchid => $total_storage) {
+                \refill\rlock::incr_mch_total_storage($mchid, $card_type, $total_storage);
             }
-            $mtotal_turns = $_POST['mtotal_turn'];
-            foreach ($mtotal_turns as $turn_key => $mtotal_turn) {
-                \refill\rlock::set_amount_turn($turn_key, $mtotal_turn);
+            $mch_total_storage_turn = $_POST['mch_total_storage_turn'];
+            foreach ($mch_total_storage_turn as $mchid => $total_storage_turn) {
+                \refill\rlock::hset_mch_total_storage_turn($mchid, $card_type, $total_storage_turn);
             }
 
             $mchids = $_POST['mchid'];
             $amounts = $_POST['amount'];
-            $mtotals = $_POST['mtotal'];
-            $mturns = $_POST['mturn'];
+            $mch_storages = $_POST['mch_storage'];
+            $mch_storage_turns = $_POST['mch_storage_turn'];
             foreach ($mchids as $key => $mchid) {
                 $amount = $amounts[$key];
-                $mturn  = $mturns[$key];
-                $mtotal = $mtotals[$key];
+                $mch_storage_turn  = $mch_storage_turns[$key];
+                $mch_storage = $mch_storages[$key];
 
-                $mturn_key = "{$mchid}-{$amount}-turn";
-                $mtotal_key = "{$mchid}-{$amount}-total";
-                \refill\rlock::set_amount_stock($mtotal_key, intval($mtotal * $amount));
-                \refill\rlock::set_amount_turn($mturn_key, $mturn);
+                \refill\rlock::incr_mch_storage($mchid, $card_type, $amount, $mch_storage);
+                \refill\rlock::hset_mch_storage_turn($mchid, $card_type, $amount, $mch_storage_turn);
             }
             showMessage('编辑成功', '');
         }
         else
         {
+            $_GET['card_type'] = $_GET['card_type'] ?? mtopcard\PetroChinaCard;
+
             $model_merchant = Model('merchant');
             $cond['merchant_state'] = 1;
             $cond['available_predeposit'] = ['gt', 0];
             $merchant_list = $model_merchant->getMerchantList($cond, 1000, 'available_predeposit desc', 'mchid,company_name,available_predeposit');
 
-            $total_stock = $this->getTotalStock($refill_oil_specs, $merchant_list);
+            $total_stock = $this->getTotalStock($refill_oil_specs, $merchant_list, $_GET['card_type']);
+            $lock_opened = rkcache($turn_name);
+
+            Tpl::output('lock_opened', $lock_opened);
             Tpl::output('total_stock', $total_stock);
             Tpl::output('merchant_list', $merchant_list);
             Tpl::output('refill_oil_specs', $refill_oil_specs);
@@ -65,38 +78,40 @@ class refill_stockControl extends SystemControl
         }
     }
 
-    public function getTotalStock($amounts,$merchant_list)
+    public function getTotalStock($amounts,$merchant_list,$card_type)
     {
-        $total = \refill\rlock::get_total_amount('total-amount');
-        $total = $total == false ? 0 : $total;
+        $total = 0;
         $amount_stock = $mtactics = [];
         foreach ($amounts as $amount) {
-            $key = "total-{$amount}-amount";
-            $tamount = \refill\rlock::get_total_amount($key);
-            $amount_stock[$amount] = intval($tamount / $amount);
-
+            $sys_storage = \refill\rlock::hget_sys_storage($card_type, $amount);
+            $amount_stock[$amount] = intval($sys_storage / $amount);
+            $total += $sys_storage;
             foreach ($merchant_list as $merchant) {
                 $data = [];
-
                 $mchid = $merchant['mchid'];
-                $mamount_turn_key = "{$mchid}-{$amount}-turn";
-                $mamount_turn = \refill\rlock::get_amount_turn($mamount_turn_key);
-                $data['turn'] = $mamount_turn == false ? 1 : $mamount_turn;
 
-                $mamount_key = "{$mchid}-{$amount}-total";
-                $mamount = \refill\rlock::get_amount_stock($mamount_key);
-                $data['default_count'] = intval($mamount / $amount);
+                //机构各面值剩余,以及策略的默认值
+                $mch_storage_turn = \refill\rlock::hget_mch_storage_turn($mchid, $card_type, $amount);
+                $data['turn'] = $mch_storage_turn == false ? 1 : $mch_storage_turn;
+
+                $mch_storage = \refill\rlock::hget_mch_storage($mchid, $card_type, $amount);
+                $data['default_count'] = intval($mch_storage / $amount);
+
                 $mtactics["{$mchid}-{$amount}"] = $data;
 
-                $mtotal_key = "{$mchid}-amount";
-                $mtotal = \refill\rlock::get_amount_stock($mtotal_key);
-                $mtactics["{$mchid}-amount"] = $mtotal == false ? 0 : $mtotal;
+                //机构总量剩余,以及策略的默认值
+                $mch_total_storage = \refill\rlock::hget_mch_total_storage($mchid, $card_type);
+                $mtactics["{$mchid}-amount"] = $mch_total_storage == false ? 0 : $mch_total_storage;
 
-                $mturn_key = "{$mchid}-turn";
-                $mturn = \refill\rlock::get_amount_turn($mturn_key);
-                $mtactics["{$mchid}-turn"] = $mturn == false ? 1 : $mturn;
+                $mch_total_storage_turn = \refill\rlock::hget_mch_total_storage_turn($mchid, $card_type);
+                $mtactics["{$mchid}-turn"] = $mch_total_storage_turn == false ? 1 : $mch_total_storage_turn;
             }
         }
         return ['total' => $total, 'amount_stock' => $amount_stock, 'mtactics' => $mtactics];
     }
+
+    public function system_merchant_storage_empty()
+    {
+
+    }
 }

+ 0 - 2
admin/templates/default/merchant.add.php

@@ -7,8 +7,6 @@
             <ul class="tab-base">
                 <li><a href="index.php?act=merchant&op=merchant"><span><?php echo $lang['nc_manage'] ?></span></a></li>
                 <li><a href="JavaScript:void(0);" class="current"><span><?php echo $lang['nc_new'] ?></span></a></li>
-                <li><a href="index.php?act=merchant&op=orderStorge"><span>机构库存锁定</span></a></li>
-                <li><a href="index.php?act=merchant&op=oilAmountLock"><span>机构油卡金额锁定</span></a></li>
             </ul>
         </div>
     </div>

+ 0 - 2
admin/templates/default/merchant.edit.php

@@ -7,8 +7,6 @@
             <ul class="tab-base">
                 <li><a href="index.php?act=merchant&op=merchant"><span><?php echo $lang['nc_manage'] ?></span></a></li>
                 <li><a href="JavaScript:void(0);" class="current"><span>编辑</span></a></li>
-                <li><a href="index.php?act=merchant&op=orderStorge"><span>机构库存锁定</span></a></li>
-                <li><a href="index.php?act=merchant&op=oilAmountLock"><span>机构油卡金额锁定</span></a></li>
             </ul>
         </div>
     </div>

+ 0 - 2
admin/templates/default/merchant.index.php

@@ -9,8 +9,6 @@ defined('InShopNC') or exit('Access Invalid!'); ?>
             <ul class="tab-base">
                 <li><a href="JavaScript:void(0);" class="current"><span><?php echo $lang['nc_manage'] ?></span></a></li>
                 <li><a href="index.php?act=merchant&op=merchant_add"><span><?php echo $lang['nc_new'] ?></span></a></li>
-                <li><a href="index.php?act=merchant&op=orderStorge"><span>机构库存锁定</span></a></li>
-                <li><a href="index.php?act=merchant&op=oilAmountLock"><span>机构油卡金额锁定</span></a></li>
             </ul>
         </div>
     </div>

+ 0 - 1
admin/templates/default/merchant.price.php

@@ -82,7 +82,6 @@
             <ul class="tab-base">
                 <li><a href="index.php?act=merchant&op=merchant"><span><?php echo $lang['nc_manage'] ?></span></a></li>
                 <li><a href="index.php?act=merchant&op=merchant_add"><span><?php echo $lang['nc_new'] ?></span></a></li>
-                <li><a href="index.php?act=merchant&op=orderStorge"><span>机构库存锁定</span></a></li>
 
                 <li><a href="index.php?act=merchant&op=price&quality=1&mchid=<?php echo $_GET['mchid'] ?>" class="classA" data-quality="1"><span>普通通道费率设置</span></a></li>
                 <li><a href="index.php?act=merchant&op=price&quality=2&mchid=<?php echo $_GET['mchid'] ?>" class="classA" data-quality="2"><span>快速通道费率设置</span></a></li>

+ 0 - 1
admin/templates/default/recharge.manual.add.php

@@ -7,7 +7,6 @@
       <ul class="tab-base">
           <li><a href="index.php?act=merchant&op=merchant" ><span><?php echo $lang['nc_manage'] ?></span></a></li>
           <li><a href="index.php?act=merchant&op=merchant_add"><span><?php echo $lang['nc_new'] ?></span></a></li>
-          <li><a href="index.php?act=merchant&op=orderStorge"><span>机构库存锁定</span></a></li>
         <li><a href="JavaScript:void(0);"  class="current"><span>加款</span></a></li>
       </ul>
     </div>

+ 0 - 1
admin/templates/default/recharge.manual.edit.php

@@ -7,7 +7,6 @@
       <ul class="tab-base">
           <li><a href="index.php?act=merchant&op=merchant" ><span><?php echo $lang['nc_manage'] ?></span></a></li>
           <li><a href="index.php?act=merchant&op=merchant_add"><span><?php echo $lang['nc_new'] ?></span></a></li>
-          <li><a href="index.php?act=merchant&op=orderStorge"><span>机构库存锁定</span></a></li>
         <li><a href="JavaScript:void(0);"  class="current"><span>调款</span></a></li>
       </ul>
     </div>

+ 30 - 7
admin/templates/default/refill_stock.php

@@ -5,18 +5,33 @@
         <div class="item-title">
             <h3>库存管理</h3>
             <ul class="tab-base">
-                <li><a href="JavaScript:void(0);"  class="current"><span>机构库存</span></a></li>
+                <li><a href="index.php?act=refill_stock&op=index&card_type=<?php echo mtopcard\PetroChinaCard;?>" class="classA" data-type="<?php echo mtopcard\PetroChinaCard;?>"><span>机构中石油库存控制</span></a></li>
+                <li><a href="index.php?act=refill_stock&op=index&card_type=<?php echo mtopcard\SinopecCard;?>" class="classA" data-type="<?php echo mtopcard\SinopecCard;?>"><span>机构中石化库存控制</span></a></li>
             </ul>
         </div>
     </div>
     <div class="fixed-empty"></div>
     <form id="price_form" enctype="multipart/form-data" method="post">
         <input type="hidden" name="form_submit" value="ok"/>
+        <input type="hidden" name="card_type" value="<?php echo $_GET['card_type'];?>"/>
         <table class="table tb-type2 tableFixed">
             <tbody style="display:block;width:830px">
             <tr>
                 <td colspan="2" class="required"><label>机构库存:</label></td>
             </tr>
+            <tr class="trStatus noborder">
+                <td colspan="4">
+                    油卡库存状态:
+                    <label style="margin-right: 10px;">
+                        <input name="lock_opened" type="radio" value="1" <?php if($output['lock_opened'] === true){ echo 'checked'; }?>/>
+                        开启
+                    </label>
+                    <label>
+                        <input name="lock_opened" type="radio" value="0" <?php if($output['lock_opened'] === false){ echo 'checked'; }?>/>
+                        关闭
+                    </label>
+                </td>
+            </tr>
             <tr class="noborder">
                 <?php foreach ($output['refill_oil_specs'] as $amount) {?>
                 <td class="moneySum w160">
@@ -55,7 +70,7 @@
             </tr>
             <tr class="noborder">
                 <table class="table tb-type2" style="margin-top:180px">
-                    <thead class="flex_thead" style="top:200px" id="tableHread">
+                    <thead class="flex_thead" style="top:215px" id="tableHread">
 
                         <tr class="w500">
                             <th class="align-center w96 mw96" rowspan="2">机构名称</th>
@@ -79,7 +94,7 @@
                             <?php }?>
                         </tr>
                     </thead>
-                    <tbody class="tbody" style="display: block;padding-top: 37px;">
+                    <tbody class="tbody" style="display: block;padding-top: 50px;">
                         <?php foreach ($output['merchant_list'] as $merchant) {?>
                         <tr class="w500 trFlex">
                             <td class="w96 align-center" style="min-width:96px">
@@ -91,10 +106,10 @@
                                        value="<?php echo $output['total_stock']['mtactics']["{$merchant['mchid']}-amount"];?>" style="background-color: #eaeaea;">
                             </td>
                             <td class="w50 align-center">
-                                <input type="number" class="w50 mecChange" name="mtotal_amount[<?php echo $merchant['mchid'];?>-amount]" value="0">
+                                <input type="number" class="w50 mecChange" name="mch_total_storage[<?php echo $merchant['mchid'];?>]" value="0">
                             </td>
                             <td class="w60 align-center">
-                                <select class="select1 w60" name="mtotal_turn[<?php echo $merchant['mchid'];?>-turn]">
+                                <select class="select1 w60" name="mch_total_storage_turn[<?php echo $merchant['mchid'];?>]">
                                     <option value="1" <?php if($output['total_stock']['mtactics']["{$merchant['mchid']}-turn"] == 1){ echo 'selected';}?>>关闭</option>
                                     <option value="2" <?php if($output['total_stock']['mtactics']["{$merchant['mchid']}-turn"] == 2){ echo 'selected';}?>>预留</option>
                                     <option value="3" <?php if($output['total_stock']['mtactics']["{$merchant['mchid']}-turn"] == 3){ echo 'selected';}?>>分配</option>
@@ -109,10 +124,10 @@
                                        value="<?php echo $output['total_stock']['mtactics']["{$merchant['mchid']}-{$amount}"]['default_count'];?>" style="background-color: #eaeaea;">
                             </td>
                             <td class="w50 align-center">
-                                <input type="number" class="w50 tbChange amountInput" name="mtotal[]" value="0" data-tbMoney="<?php echo $amount;?>">
+                                <input type="number" class="w50 tbChange amountInput" name="mch_storage[]" value="0" data-tbMoney="<?php echo $amount;?>">
                             </td>
                             <td class="w60 align-center tbSelect">
-                                <select class="select2 w60" name="mturn[]">
+                                <select class="select2 w60" name="mch_storage_turn[]">
                                     <option value="1" <?php if($output['total_stock']['mtactics']["{$merchant['mchid']}-{$amount}"]['turn'] == 1){ echo 'selected';}?>>关闭</option>
                                     <option value="2" <?php if($output['total_stock']['mtactics']["{$merchant['mchid']}-{$amount}"]['turn'] == 2){ echo 'selected';}?>>预留</option>
                                     <option value="3" <?php if($output['total_stock']['mtactics']["{$merchant['mchid']}-{$amount}"]['turn'] == 3){ echo 'selected';}?>>分配</option>
@@ -144,6 +159,14 @@
       id="cssfile2"/>
 <script type="text/javascript">
     $(function () {
+        let type = '<?php echo $_GET['card_type'];?>';
+        $(".classA").each(function () {
+            if (type == $(this).attr("data-type")) {
+                $(this).addClass('current')
+                $(this).attr('href','JavaScript:void(0);')
+            }
+        })
+
         let isSubmit = true
         let isOk = true
         let isMoney = true

+ 31 - 30
helper/refill/policy/rlock.php

@@ -10,124 +10,125 @@ class rlock
     const RETAIN = 2;
     const ASSIGN = 3;
 
-    const sys_storge_name = 'system_storge';
-    const mch_storge_name = 'merchant_storge';
+    const sys_storage_name = 'system_storage';
+    const mch_storage_name = 'merchant_storage';
+    const locked_open_name = 'oil_amount_lock_turn';
 
-    //system storge
-    public static function incr_sys_storge($card_type,$spec,$count)
+    //system storage
+    public static function incr_sys_storage($card_type,$spec,$count)
     {
         $ins = Cache::getInstance('cacheredis');
-        $name = self::sys_storge_name;
+        $name = self::sys_storage_name;
         $key = "{$card_type}-{$spec}";
 
         return $ins->hIncrBy($name, $key, $spec * $count);
     }
 
-    public static function decr_sys_storge($card_type,$spec,$count)
+    public static function decr_sys_storage($card_type,$spec,$count)
     {
         $ins = Cache::getInstance('cacheredis');
-        $name = self::sys_storge_name;
+        $name = self::sys_storage_name;
         $key = "{$card_type}-{$spec}";
         return $ins->hIncrBy($name, $key, -1 * $spec * $count);
     }
 
-    public static function hget_sys_storge($card_type,$spec)
+    public static function hget_sys_storage($card_type,$spec)
     {
         $ins = Cache::getInstance('cacheredis');
-        $name = self::sys_storge_name;
+        $name = self::sys_storage_name;
         $key = "{$card_type}-{$spec}";
         $value = $ins->hget($name, '', $key);
         return $value;
     }
 
     //merchant 总金额分配策略开关,及剩余金额变动和获取
-    public static function incr_mch_total_storge($mchid,$card_type,$amount)
+    public static function incr_mch_total_storage($mchid,$card_type,$amount)
     {
         $ins = Cache::getInstance('cacheredis');
-        $name = self::mch_storge_name;
+        $name = self::mch_storage_name;
         $key = "{$mchid}-{$card_type}-total";
         return $ins->hIncrBy($name, $key, $amount);
     }
 
-    public static function decr_mch_total_storge($mchid,$card_type,$amount)
+    public static function decr_mch_total_storage($mchid,$card_type,$amount)
     {
         $ins = Cache::getInstance('cacheredis');
-        $name = self::mch_storge_name;
+        $name = self::mch_storage_name;
         $key = "{$mchid}-{$card_type}-total";
 
         return $ins->hIncrBy($name, $key, -1 * $amount);
     }
 
-    public static function hget_mch_total_storge($mchid,$card_type)
+    public static function hget_mch_total_storage($mchid,$card_type)
     {
         $ins = Cache::getInstance('cacheredis');
-        $name = self::mch_storge_name;
+        $name = self::mch_storage_name;
         $key = "{$mchid}-{$card_type}-total";
 
         $value = $ins->hget($name, '', $key);
         return $value;
     }
 
-    public static function hset_mch_total_storge_turn($mchid,$card_type,$val)
+    public static function hset_mch_total_storage_turn($mchid,$card_type,$val)
     {
         $ins = Cache::getInstance('cacheredis');
-        $name = self::mch_storge_name;
+        $name = self::mch_storage_name;
         $key = "{$mchid}-{$card_type}-turn";
 
         $ins->hset($name, '', [$key => $val]);
     }
 
-    public static function hget_mch_total_storge_turn($mchid,$card_type)
+    public static function hget_mch_total_storage_turn($mchid,$card_type)
     {
         $ins = Cache::getInstance('cacheredis');
-        $name = self::mch_storge_name;
+        $name = self::mch_storage_name;
         $key = "{$mchid}-{$card_type}-turn";
 
         return $ins->hget($name, '', $key);
     }
 
-    //mchid storge count-lock
-    public static function incr_mch_storge($mchid,$card_type,$spec,$count)
+    //mchid storage count-lock
+    public static function incr_mch_storage($mchid,$card_type,$spec,$count)
     {
         $ins = Cache::getInstance('cacheredis');
-        $name = self::mch_storge_name;
+        $name = self::mch_storage_name;
         $key = "{$mchid}-{$card_type}-{$spec}";
 
         return $ins->hIncrBy($name, $key, $spec * $count);
     }
 
-    public static function decr_mch_storge($mchid,$card_type,$spec,$count)
+    public static function decr_mch_storage($mchid,$card_type,$spec,$count)
     {
         $ins = Cache::getInstance('cacheredis');
-        $name = self::mch_storge_name;
+        $name = self::mch_storage_name;
         $key = "{$mchid}-{$card_type}-{$spec}";
 
         return $ins->hIncrBy($name, $key, -1 * $spec * $count);
     }
 
-    public static function hget_mch_storge($mchid,$card_type,$spec)
+    public static function hget_mch_storage($mchid,$card_type,$spec)
     {
         $ins = Cache::getInstance('cacheredis');
-        $name = self::mch_storge_name;
+        $name = self::mch_storage_name;
         $key = "{$mchid}-{$card_type}-{$spec}";
 
         $value = $ins->hget($name, '', $key);
         return $value;
     }
 
-    public static function hset_mch_storge_turn($mchid,$card_type,$spec,$val)
+    public static function hset_mch_storage_turn($mchid,$card_type,$spec,$val)
     {
         $ins = Cache::getInstance('cacheredis');
-        $name = self::mch_storge_name;
+        $name = self::mch_storage_name;
         $key = "{$mchid}-{$card_type}-{$spec}-turn";
 
         $ins->hset($name, '', [$key => $val]);
     }
 
-    public static function hget_mch_storge_turn($mchid,$card_type,$spec)
+    public static function hget_mch_storage_turn($mchid,$card_type,$spec)
     {
         $ins = Cache::getInstance('cacheredis');
-        $name = self::mch_storge_name;
+        $name = self::mch_storage_name;
         $key = "{$mchid}-{$card_type}-{$spec}-turn";
 
         return $ins->hget($name, '', $key);

+ 7 - 7
helper/refill/util.php

@@ -4,7 +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');
+require_once(BASE_HELPER_PATH . '/refill/policy/rlock.php');
 
 use queue;
 use mtopcard;
@@ -358,18 +358,18 @@ class util
     public static function incr_amount_lock($mchid, $card_type, $spec)
     {
         if ($card_type == mtopcard\SinopecCard || $card_type == mtopcard\PetroChinaCard) {
-            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);
+            refill\rlock::incr_sys_storage($card_type,$spec,1);
+            refill\rlock::incr_mch_total_storage($mchid,$card_type,$spec);
+            refill\rlock::incr_mch_storage($mchid,$card_type,$spec,1);
         }
     }
 
     public static function decr_amount_lock($mchid, $card_type, $spec)
     {
         if ($card_type == mtopcard\SinopecCard || $card_type == mtopcard\PetroChinaCard) {
-            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);
+            refill\rlock::decr_sys_storage($card_type,$spec,1);
+            refill\rlock::decr_mch_total_storage($mchid,$card_type,$spec);
+            refill\rlock::decr_mch_storage($mchid,$card_type,$spec,1);
         }
     }
 

+ 7 - 8
test/TestRefill.php

@@ -331,12 +331,11 @@ class TestRefill extends TestCase
 
     public function testPrice()
     {
-//        $amounts = [10, 20, 30, 50, 100, 200, 300, 500];
-//        $rate = 0.94;
-//        foreach ($amounts as $amount) {
-//            $price[] = $amount * $rate;
-//        }
-        mtopcard\card_type(17801048874);
+        $amounts = [10, 20, 30, 50, 100, 200, 300, 500];
+        $rate = 0.94;
+        foreach ($amounts as $amount) {
+            $price[] = $amount * $rate;
+        }
     }
 
     public function testWeisPhone()
@@ -493,10 +492,10 @@ class TestRefill extends TestCase
     {
         $providers = new refill\luqian\RefillPhone([]);
 //        $resp = $providers->add(18500608333, 5, 100, ['order_sn' => $this->make_sn()]);
-//        $resp = $providers->query(['order_sn' => '34101618897099329575']);
+        $resp = $providers->query(['order_sn' => '2829660672500596314764']);
         $data = '{"amount":"100","charge_type":"0","code":"1","partner_id":"38","phone":"18500608333","sign":"c2c86cccc73fa991a63c369e683c91f2","partner_order_no":"34101618897099329575","official_order_id":"110103308072104201338340278420"}';
         $input = json_decode($data, true);
-        refill\RefillFactory::instance()->notify('luqian',$input);
+//        refill\RefillFactory::instance()->notify('luqian',$input);
     }
 
     public function testAfandfsPhone()