provider_ctl.php 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. <?php
  2. include(BASE_CONFIG_PATH . CONFIG_PREFIX . '/refill.ini.php');
  3. class provider_ctlControl extends SystemControl
  4. {
  5. public function __construct()
  6. {
  7. parent::__construct();
  8. }
  9. public function indexOp()
  10. {
  11. $type = $_GET['type'] ?? $_POST['type'];
  12. if(empty($type)) $type = 2;
  13. $form = $_GET['form'] ?? $_POST['form'];
  14. if(empty($form)) $form = 'common';
  15. $rkey = $this->speed_key($type, $form);
  16. $quality = [
  17. 'common' => refill\Quality::Normal, 'fast' => refill\Quality::Quick, 'card' => refill\Quality::CardKey,
  18. 'third' => refill\Quality::ThirdShop, 'slow' => refill\Quality::SlowTwentyFour, 'slow6' => refill\Quality::SlowSix,
  19. 'slow2' => refill\Quality::SlowTwo, 'slow48' => refill\Quality::SlowFortyEight, 'slow72' => refill\Quality::SlowSeventyTwo,
  20. 'fastest' => refill\Quality::Fastest
  21. ];
  22. if (chksubmit()) {
  23. $provider_list = $this->providers();
  24. foreach ($provider_list as $provider) {
  25. $providers[$provider['provider_id']] = $provider;
  26. }
  27. $strs = $_POST['str'];
  28. $speeds = $_POST['speed'];
  29. $sorts = $_POST['sort'];
  30. $openeds = $_POST['opened'];
  31. foreach ($strs as $key => $str) {
  32. $item = explode('-', $str);
  33. $pid = $item[0];
  34. $type = $item[1];
  35. $amount = $item[2];
  36. $has = $item[3];
  37. if ($has == 0) {
  38. continue;
  39. }
  40. $data['pid'] = intval($pid);
  41. $data['name'] = $providers[$pid]['name'];
  42. $data['type'] = intval($type);
  43. $data['amount'] = intval($amount);
  44. $data['speed'] = intval($speeds[$key]);
  45. $data['sort'] = intval($sorts[$key]);
  46. $data['opened'] = intval($openeds[$key]);
  47. $index = "{$data['type']}-{$data['amount']}";
  48. $result[$index][] = $data;
  49. }
  50. wcache($rkey, ['data' => serialize($result)], 'provider-');
  51. showMessage('编辑成功');
  52. } else {
  53. $speed_limit = rcache($rkey, 'provider-');
  54. if (empty($speed_limit)) {
  55. $speed_limit = [];
  56. } else {
  57. $speed_limit = unserialize($speed_limit['data']);
  58. }
  59. // $ins = Cache::getInstance('cacheredis');
  60. $channel_ctl_model_body = rkcachex('refill_channel_control_model');
  61. // $channel_ctl_model_body = rkcache('refill_channel_control_model');
  62. $channel_ctl_model = json_decode($channel_ctl_model_body, true);
  63. Log::record("refill_channel_control_model : {$channel_ctl_model}");
  64. $channel_ctl_model = json_decode($channel_ctl_model_body, true);
  65. if(empty($channel_ctl_model)) $channel_ctl_model = [];
  66. $initialiser = function ($provider) {
  67. $data['pid'] = $provider['provider_id'];
  68. $data['name'] = $provider['name'];
  69. $data['speed'] = -1;
  70. $data['sort'] = 1;
  71. $data['opened'] = 1;
  72. return $data;
  73. };
  74. $providers = Model('')->table('refill_provider,store')
  75. ->field('refill_provider.*,store.store_name')
  76. ->join('inner')
  77. ->on('store.store_id=refill_provider.store_id')
  78. ->where(['type' => $type, 'qualitys' => ['like', '%' . $quality[$form] . '%']])
  79. ->limit(1000)
  80. ->order('opened asc , sort desc')
  81. ->select();
  82. if (empty($providers)) {
  83. showMessage('暂无相关通道', 'index.php?act=provider&op=index');
  84. }
  85. $formData = $this->formData($type, $form);
  86. $amounts = $formData['amounts'];
  87. $cfgs = $formData['cfgs'];
  88. $types = $formData['types'];
  89. if (!empty($speed_limit)) {
  90. foreach ($speed_limit as $key => $speed) {
  91. foreach ($speed as $value) {
  92. $speed_limit[$key][$value['pid']] = $value;
  93. }
  94. }
  95. }
  96. $ProviderManager = new refill\ProviderManager();
  97. $ProviderManager->load();
  98. $QPTA = $ProviderManager->getQPTA();
  99. $QPTA = $QPTA[$quality[$form]];
  100. foreach ($providers as $key => $provider) {
  101. $result = [];
  102. $pid = $provider['provider_id'];
  103. $name = $provider['name'];
  104. if (empty($cfgs) || !array_key_exists($name, $cfgs)) {
  105. unset($providers[$key]);
  106. continue;
  107. }
  108. foreach ($types as $type) {
  109. foreach ($amounts as $k => $amount) {
  110. $key = $type . '-' . $amount;
  111. if (is_array($speed_limit[$key]) && array_key_exists($pid, $speed_limit[$key])) {
  112. $speed = $speed_limit[$key][$pid];
  113. } else {
  114. $speed = $initialiser($provider);
  115. }
  116. if (is_array($QPTA["{$name}-{$type}-{$amount}"]) && array_key_exists("{$name}-{$type}-{$amount}", $QPTA)) {
  117. $speed['has'] = 1;
  118. } else {
  119. $speed['has'] = 0;
  120. }
  121. $result[] = $speed;
  122. }
  123. }
  124. $datas[$pid] = $result;
  125. }
  126. if (empty($datas)) {
  127. showMessage('暂无相关通道配置', 'index.php?act=provider&op=index');
  128. }
  129. Tpl::output('form', $formData);
  130. Tpl::output('datas', $datas);
  131. Tpl::output('providers', $providers);
  132. Tpl::output('channel_ctl_model', $channel_ctl_model);
  133. Tpl::showpage('provider.amount.control');
  134. }
  135. }
  136. private function speed_key($type, $form)
  137. {
  138. if ($type == 1) {
  139. $rkey = "channel-ctl-oil-{$form}-limit";
  140. } elseif ($type == 2) {
  141. $rkey = "channel-ctl-phone-{$form}-limit";
  142. } else {
  143. showMessage('类型有误', "index.php?act=provider&op=index");
  144. }
  145. Log::record($rkey, Log::DEBUG);
  146. return $rkey;
  147. }
  148. private function formData($type, $form)
  149. {
  150. global $config;
  151. $texts = [
  152. ["中石油", '中石化'], ['移动', '联通', '电信']
  153. ];
  154. $type_data = [[1, 2], [4, 5, 6]];
  155. $type_text = $texts[$type - 1];
  156. $type_data = $type_data[$type - 1];
  157. $amounts = [];
  158. if ($type == 1) {
  159. $amounts = $config['refill_oil_specs'];
  160. $cfgs = $config['oil_providers'];
  161. }
  162. if ($type == 2) {
  163. $amounts = $config['refill_phone_specs'];
  164. $cfgs = $config['phone_providers'];
  165. if ($form == 'fast') {
  166. //快充质量,加小面值
  167. $amounts = array_merge($config['refill_phone_small_specs'], $amounts);
  168. }
  169. }
  170. foreach ($type_text as $key => $value) {
  171. foreach ($amounts as $amount) {
  172. $data['text'] = $value . '-' . $amount . '元';
  173. $data['type'] = $type_data[$key];
  174. $data['amount'] = $amount;
  175. $amountData[] = $data;
  176. }
  177. }
  178. foreach ($cfgs as $cfg) {
  179. $pcfgs[$cfg['name']] = $cfg;
  180. }
  181. return ['amountData' => $amountData, 'form' => $form, 'amounts' => $amounts, 'types' => $type_data, 'cfgs' => $pcfgs];
  182. }
  183. }