123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- <?php
- require_once(BASE_HELPER_PATH . '/refill/policy/rlock.php');
- include(BASE_CONFIG_PATH . CONFIG_PREFIX . '/refill.ini.php');
- require_once(BASE_HELPER_PATH . '/mtopcard/mtopcard.php');
- class refill_stockControl extends SystemControl
- {
- public function __construct()
- {
- parent::__construct();
- }
- public function indexOp()
- {
- global $config;
- $refill_oil_specs = $config['refill_oil_specs'];
- arsort($refill_oil_specs);
- $turn_name = \refill\rlock::locked_open_name;
- if(chksubmit())
- {
- $card_type = $_POST['card_type'];
- $lock_opened = $_POST['lock_opened'];
- if(!in_array($lock_opened, [0,1])) {
- showMessage('开启状态有误', '');
- }
- if($lock_opened == 1) {
- \refill\rlock::set_open($card_type,true);
- wkcache($turn_name, true);
- } elseif ($lock_opened == 0) {
- \refill\rlock::set_open($card_type,false);
- }
- foreach ($refill_oil_specs as $amount) {
- $key = "total-{$amount}-amount";
- \refill\rlock::incr_sys_storage($card_type, $amount, $_POST[$key]);
- }
- $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);
- }
- $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'];
- $mch_storages = $_POST['mch_storage'];
- $mch_storage_turns = $_POST['mch_storage_turn'];
- foreach ($mchids as $key => $mchid) {
- $amount = $amounts[$key];
- $mch_storage_turn = $mch_storage_turns[$key];
- $mch_storage = $mch_storages[$key];
- \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, $_GET['card_type']);
- $lock_opened = \refill\rlock::get_open($_GET['card_type']);
- 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);
- Tpl::showpage('refill_stock');
- }
- }
- public function getTotalStock($amounts,$merchant_list,$card_type)
- {
- $total = 0;
- $amount_stock = $mtactics = [];
- foreach ($amounts as $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'];
- //机构各面值剩余,以及策略的默认值
- $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;
- //机构总量剩余,以及策略的默认值
- $mch_total_storage = \refill\rlock::hget_mch_total_storage($mchid, $card_type);
- $mtactics["{$mchid}-amount"] = $mch_total_storage == false ? 0 : $mch_total_storage;
- $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_emptyOp()
- {
- \refill\rlock::clear_all();
- showMessage('操作成功', '');
- }
- }
|