123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198 |
- <?php
- include(BASE_CONFIG_PATH . CONFIG_PREFIX . '/refill.ini.php');
- class provider_ctlControl extends SystemControl
- {
- public function __construct()
- {
- parent::__construct();
- }
- public function indexOp()
- {
- $type = $_GET['type'] ?? $_POST['type'];
- if(empty($type)) $type = 2;
- $form = $_GET['form'] ?? $_POST['form'];
- if(empty($form)) $form = 'common';
- $rkey = $this->speed_key($type, $form);
- $quality = [
- 'common' => refill\Quality::Normal, 'fast' => refill\Quality::Quick, 'card' => refill\Quality::CardKey,
- 'third' => refill\Quality::ThirdShop, 'slow' => refill\Quality::SlowTwentyFour, 'slow6' => refill\Quality::SlowSix,
- 'slow2' => refill\Quality::SlowTwo, 'slow48' => refill\Quality::SlowFortyEight, 'slow72' => refill\Quality::SlowSeventyTwo,
- 'fastest' => refill\Quality::Fastest
- ];
- if (chksubmit()) {
- $provider_list = $this->providers();
- foreach ($provider_list as $provider) {
- $providers[$provider['provider_id']] = $provider;
- }
- $strs = $_POST['str'];
- $speeds = $_POST['speed'];
- $sorts = $_POST['sort'];
- $openeds = $_POST['opened'];
- foreach ($strs as $key => $str) {
- $item = explode('-', $str);
- $pid = $item[0];
- $type = $item[1];
- $amount = $item[2];
- $has = $item[3];
- if ($has == 0) {
- continue;
- }
- $data['pid'] = intval($pid);
- $data['name'] = $providers[$pid]['name'];
- $data['type'] = intval($type);
- $data['amount'] = intval($amount);
- $data['speed'] = intval($speeds[$key]);
- $data['sort'] = intval($sorts[$key]);
- $data['opened'] = intval($openeds[$key]);
- $index = "{$data['type']}-{$data['amount']}";
- $result[$index][] = $data;
- }
- wcache($rkey, ['data' => serialize($result)], 'provider-');
- showMessage('编辑成功');
- } else {
- $speed_limit = rcache($rkey, 'provider-');
- if (empty($speed_limit)) {
- $speed_limit = [];
- } else {
- $speed_limit = unserialize($speed_limit['data']);
- }
- // $ins = Cache::getInstance('cacheredis');
- $channel_ctl_model_body = rkcachex('refill_channel_control_model');
- // $channel_ctl_model_body = rkcache('refill_channel_control_model');
- $channel_ctl_model = json_decode($channel_ctl_model_body, true);
- Log::record("refill_channel_control_model : {$channel_ctl_model}");
- $channel_ctl_model = json_decode($channel_ctl_model_body, true);
- if(empty($channel_ctl_model)) $channel_ctl_model = [];
- $initialiser = function ($provider) {
- $data['pid'] = $provider['provider_id'];
- $data['name'] = $provider['name'];
- $data['speed'] = -1;
- $data['sort'] = 1;
- $data['opened'] = 1;
- return $data;
- };
- $providers = Model('')->table('refill_provider,store')
- ->field('refill_provider.*,store.store_name')
- ->join('inner')
- ->on('store.store_id=refill_provider.store_id')
- ->where(['type' => $type, 'qualitys' => ['like', '%' . $quality[$form] . '%']])
- ->limit(1000)
- ->order('opened asc , sort desc')
- ->select();
- if (empty($providers)) {
- showMessage('暂无相关通道', 'index.php?act=provider&op=index');
- }
- $formData = $this->formData($type, $form);
- $amounts = $formData['amounts'];
- $cfgs = $formData['cfgs'];
- $types = $formData['types'];
- if (!empty($speed_limit)) {
- foreach ($speed_limit as $key => $speed) {
- foreach ($speed as $value) {
- $speed_limit[$key][$value['pid']] = $value;
- }
- }
- }
- $ProviderManager = new refill\ProviderManager();
- $ProviderManager->load();
- $QPTA = $ProviderManager->getQPTA();
- $QPTA = $QPTA[$quality[$form]];
- foreach ($providers as $key => $provider) {
- $result = [];
- $pid = $provider['provider_id'];
- $name = $provider['name'];
- if (empty($cfgs) || !array_key_exists($name, $cfgs)) {
- unset($providers[$key]);
- continue;
- }
- foreach ($types as $type) {
- foreach ($amounts as $k => $amount) {
- $key = $type . '-' . $amount;
- if (is_array($speed_limit[$key]) && array_key_exists($pid, $speed_limit[$key])) {
- $speed = $speed_limit[$key][$pid];
- } else {
- $speed = $initialiser($provider);
- }
- if (is_array($QPTA["{$name}-{$type}-{$amount}"]) && array_key_exists("{$name}-{$type}-{$amount}", $QPTA)) {
- $speed['has'] = 1;
- } else {
- $speed['has'] = 0;
- }
- $result[] = $speed;
- }
- }
- $datas[$pid] = $result;
- }
- if (empty($datas)) {
- showMessage('暂无相关通道配置', 'index.php?act=provider&op=index');
- }
- Tpl::output('form', $formData);
- Tpl::output('datas', $datas);
- Tpl::output('providers', $providers);
- Tpl::output('channel_ctl_model', $channel_ctl_model);
- Tpl::showpage('provider.amount.control');
- }
- }
- private function speed_key($type, $form)
- {
- if ($type == 1) {
- $rkey = "channel-ctl-oil-{$form}-limit";
- } elseif ($type == 2) {
- $rkey = "channel-ctl-phone-{$form}-limit";
- } else {
- showMessage('类型有误', "index.php?act=provider&op=index");
- }
- Log::record($rkey, Log::DEBUG);
- return $rkey;
- }
- private function formData($type, $form)
- {
- global $config;
- $texts = [
- ["中石油", '中石化'], ['移动', '联通', '电信']
- ];
- $type_data = [[1, 2], [4, 5, 6]];
- $type_text = $texts[$type - 1];
- $type_data = $type_data[$type - 1];
- $amounts = [];
- if ($type == 1) {
- $amounts = $config['refill_oil_specs'];
- $cfgs = $config['oil_providers'];
- }
- if ($type == 2) {
- $amounts = $config['refill_phone_specs'];
- $cfgs = $config['phone_providers'];
- if ($form == 'fast') {
- //快充质量,加小面值
- $amounts = array_merge($config['refill_phone_small_specs'], $amounts);
- }
- }
- foreach ($type_text as $key => $value) {
- foreach ($amounts as $amount) {
- $data['text'] = $value . '-' . $amount . '元';
- $data['type'] = $type_data[$key];
- $data['amount'] = $amount;
- $amountData[] = $data;
- }
- }
- foreach ($cfgs as $cfg) {
- $pcfgs[$cfg['name']] = $cfg;
- }
- return ['amountData' => $amountData, 'form' => $form, 'amounts' => $amounts, 'types' => $type_data, 'cfgs' => $pcfgs];
- }
- }
|