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; } }