refill_stock.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. require_once(BASE_HELPER_PATH . '/refill/policy/rlock.php');
  3. include(BASE_CONFIG_PATH . CONFIG_PREFIX . '/refill.ini.php');
  4. require_once(BASE_HELPER_PATH . '/mtopcard/mtopcard.php');
  5. class refill_stockControl extends SystemControl
  6. {
  7. public function __construct()
  8. {
  9. parent::__construct();
  10. }
  11. public function indexOp()
  12. {
  13. global $config;
  14. $refill_oil_specs = $config['refill_oil_specs'];
  15. arsort($refill_oil_specs);
  16. $turn_name = \refill\rlock::locked_open_name;
  17. if(chksubmit())
  18. {
  19. $card_type = $_POST['card_type'];
  20. $lock_opened = $_POST['lock_opened'];
  21. if(!in_array($lock_opened, [0,1])) {
  22. showMessage('开启状态有误', '');
  23. }
  24. if($lock_opened == 1) {
  25. \refill\rlock::set_open($card_type,true);
  26. wkcache($turn_name, true);
  27. } elseif ($lock_opened == 0) {
  28. \refill\rlock::set_open($card_type,false);
  29. }
  30. foreach ($refill_oil_specs as $amount) {
  31. $key = "total-{$amount}-amount";
  32. \refill\rlock::incr_sys_storage($card_type, $amount, $_POST[$key]);
  33. }
  34. $mch_total_storage = $_POST['mch_total_storage'];
  35. foreach ($mch_total_storage as $mchid => $total_storage) {
  36. \refill\rlock::incr_mch_total_storage($mchid, $card_type, $total_storage);
  37. }
  38. $mch_total_storage_turn = $_POST['mch_total_storage_turn'];
  39. foreach ($mch_total_storage_turn as $mchid => $total_storage_turn) {
  40. \refill\rlock::hset_mch_total_storage_turn($mchid, $card_type, $total_storage_turn);
  41. }
  42. $mchids = $_POST['mchid'];
  43. $amounts = $_POST['amount'];
  44. $mch_storages = $_POST['mch_storage'];
  45. $mch_storage_turns = $_POST['mch_storage_turn'];
  46. foreach ($mchids as $key => $mchid) {
  47. $amount = $amounts[$key];
  48. $mch_storage_turn = $mch_storage_turns[$key];
  49. $mch_storage = $mch_storages[$key];
  50. \refill\rlock::incr_mch_storage($mchid, $card_type, $amount, $mch_storage);
  51. \refill\rlock::hset_mch_storage_turn($mchid, $card_type, $amount, $mch_storage_turn);
  52. }
  53. showMessage('编辑成功', '');
  54. }
  55. else
  56. {
  57. $_GET['card_type'] = $_GET['card_type'] ?? mtopcard\PetroChinaCard;
  58. $model_merchant = Model('merchant');
  59. $cond['merchant_state'] = 1;
  60. $cond['available_predeposit'] = ['gt', 0];
  61. $merchant_list = $model_merchant->getMerchantList($cond, 1000, 'available_predeposit desc', 'mchid,company_name,available_predeposit');
  62. $total_stock = $this->getTotalStock($refill_oil_specs, $merchant_list, $_GET['card_type']);
  63. $lock_opened = \refill\rlock::get_open($_GET['card_type']);
  64. Tpl::output('lock_opened', $lock_opened);
  65. Tpl::output('total_stock', $total_stock);
  66. Tpl::output('merchant_list', $merchant_list);
  67. Tpl::output('refill_oil_specs', $refill_oil_specs);
  68. Tpl::showpage('refill_stock');
  69. }
  70. }
  71. public function getTotalStock($amounts,$merchant_list,$card_type)
  72. {
  73. $total = 0;
  74. $amount_stock = $mtactics = [];
  75. foreach ($amounts as $amount) {
  76. $sys_storage = \refill\rlock::hget_sys_storage($card_type, $amount);
  77. $amount_stock[$amount] = intval($sys_storage / $amount);
  78. $total += $sys_storage;
  79. foreach ($merchant_list as $merchant) {
  80. $data = [];
  81. $mchid = $merchant['mchid'];
  82. //机构各面值剩余,以及策略的默认值
  83. $mch_storage_turn = \refill\rlock::hget_mch_storage_turn($mchid, $card_type, $amount);
  84. $data['turn'] = $mch_storage_turn == false ? 1 : $mch_storage_turn;
  85. $mch_storage = \refill\rlock::hget_mch_storage($mchid, $card_type, $amount);
  86. $data['default_count'] = intval($mch_storage / $amount);
  87. $mtactics["{$mchid}-{$amount}"] = $data;
  88. //机构总量剩余,以及策略的默认值
  89. $mch_total_storage = \refill\rlock::hget_mch_total_storage($mchid, $card_type);
  90. $mtactics["{$mchid}-amount"] = $mch_total_storage == false ? 0 : $mch_total_storage;
  91. $mch_total_storage_turn = \refill\rlock::hget_mch_total_storage_turn($mchid, $card_type);
  92. $mtactics["{$mchid}-turn"] = $mch_total_storage_turn == false ? 1 : $mch_total_storage_turn;
  93. }
  94. }
  95. return ['total' => $total, 'amount_stock' => $amount_stock, 'mtactics' => $mtactics];
  96. }
  97. public function system_merchant_storage_emptyOp()
  98. {
  99. \refill\rlock::clear_all();
  100. showMessage('操作成功', '');
  101. }
  102. }