123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- <?php
- use refill\chprice_helper;
- include(BASE_CONFIG_PATH . CONFIG_PREFIX . '/refill.ini.php');
- require_once(BASE_HELPER_PATH . '/refill/chprice_helper.php');
- class provider_priceControl extends SystemControl
- {
- public function __construct()
- {
- parent::__construct();
- }
- public function indexOp()
- {
- global $config;
- $chprice_helper = new chprice_helper();
- $chprice_helper->load_from_db();
- $card_type = $_GET['card_type'] ?? mtopcard\PhoneCardPaper;
- if ($card_type == mtopcard\OilCardPaper) {
- $configs = $this->map_cfg($config['oil_providers']);
- $card_types = [mtopcard\PetroChinaCard, mtopcard\SinopecCard];
- $specs = $config['refill_oil_specs'];
- } elseif ($card_type == mtopcard\PhoneCardPaper) {
- $configs = $this->map_cfg($config['phone_providers']);
- $card_types = [mtopcard\ChinaMobileCard, mtopcard\ChinaUnicomCard, mtopcard\ChinaTelecomCard];
- $specs = $config['refill_phone_specs'];
- } else {
- showMessage('卡类型有误');
- exit;
- }
- $condition['type'] = $card_type;
- $condition['opened'] = 1;
- $all_providers = $this->providers($condition);
- if(!empty($_GET['provider_id'])) {
- $condition['provider_id'] = $_GET['provider_id'];
- }
- if(!empty($_GET['quality'])) {
- $condition['qualitys'] = ['like', '%' . $_GET['quality'] . '%'];
- }
- $providers = $this->providers($condition);
- $data = [];
- foreach ($providers as $provider) {
- $provider_id = $provider['provider_id'];
- $name = $provider['name'];
- $data[$provider_id]['name'] = $name;
- $data[$provider_id]['store_name'] = $provider['store_name'];
- $price = [];
- foreach ($card_types as $card_type) {
- foreach ($specs as $spec) {
- $key = "{$name}-{$card_type}-{$spec}";
- if (!empty($configs[$name][$key]) && array_key_exists($key, $configs[$name])) {
- $price[$key] = ncPriceFormat($configs[$name][$key] / $spec);
- } else {
- $price[$key] = '/';
- }
- }
- }
- $data[$provider_id]['price'] = $price;
- }
- $card_type_texts = [mtopcard\PetroChinaCard => '中石油', mtopcard\SinopecCard => '中石化', mtopcard\ChinaMobileCard => '中国移动', mtopcard\ChinaUnicomCard => '中国联通', mtopcard\ChinaTelecomCard => '中国电信'];
- Tpl::output('provider_list', $all_providers);
- Tpl::output('card_types', $card_types);
- Tpl::output('card_type_text', $card_type_texts);
- Tpl::output('data', $data);
- Tpl::output('specs', $specs);
- Tpl::showpage('provider.price');
- }
- private function map_cfg($cfgs)
- {
- $card_types = function ($stypes)
- {
- $result = [];
- $types = explode(',',$stypes);
- foreach ($types as $stype) {
- $type = mtopcard\topcard_type($stype);
- $result[] = $type;
- }
- return $result;
- };
- $result = [];
- foreach ($cfgs as $item)
- {
- $name = $item['name'];
- $cfg = $item['cfg'];
- $amounts = $cfg['amount'] ?? [];
- foreach ($amounts as $spec => $goods)
- {
- foreach ($goods as $gitem)
- {
- $types = $card_types($gitem['card_type']);
- foreach ($types as $type) {
- $result[$name]["{$name}-{$type}-{$spec}"] = $gitem['price'] ?? 0;
- }
- }
- }
- }
- return $result;
- }
- }
|