provider_price.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. use refill\chprice_helper;
  3. include(BASE_CONFIG_PATH . CONFIG_PREFIX . '/refill.ini.php');
  4. require_once(BASE_HELPER_PATH . '/refill/chprice_helper.php');
  5. class provider_priceControl extends SystemControl
  6. {
  7. public function __construct()
  8. {
  9. parent::__construct();
  10. }
  11. public function indexOp()
  12. {
  13. global $config;
  14. $chprice_helper = new chprice_helper();
  15. $chprice_helper->load_from_db();
  16. $card_type = $_GET['card_type'] ?? mtopcard\PhoneCardPaper;
  17. if ($card_type == mtopcard\OilCardPaper) {
  18. $configs = $this->map_cfg($config['oil_providers']);
  19. $card_types = [mtopcard\PetroChinaCard, mtopcard\SinopecCard];
  20. $specs = $config['refill_oil_specs'];
  21. } elseif ($card_type == mtopcard\PhoneCardPaper) {
  22. $configs = $this->map_cfg($config['phone_providers']);
  23. $card_types = [mtopcard\ChinaMobileCard, mtopcard\ChinaUnicomCard, mtopcard\ChinaTelecomCard];
  24. $specs = $config['refill_phone_specs'];
  25. } else {
  26. showMessage('卡类型有误');
  27. exit;
  28. }
  29. $condition['type'] = $card_type;
  30. $condition['opened'] = 1;
  31. $all_providers = $this->providers($condition);
  32. if(!empty($_GET['provider_id'])) {
  33. $condition['provider_id'] = $_GET['provider_id'];
  34. }
  35. if(!empty($_GET['quality'])) {
  36. $condition['qualitys'] = ['like', '%' . $_GET['quality'] . '%'];
  37. }
  38. $providers = $this->providers($condition);
  39. $data = [];
  40. foreach ($providers as $provider) {
  41. $provider_id = $provider['provider_id'];
  42. $name = $provider['name'];
  43. $data[$provider_id]['name'] = $name;
  44. $data[$provider_id]['store_name'] = $provider['store_name'];
  45. $price = [];
  46. foreach ($card_types as $card_type) {
  47. foreach ($specs as $spec) {
  48. $key = "{$name}-{$card_type}-{$spec}";
  49. if (!empty($configs[$name][$key]) && array_key_exists($key, $configs[$name])) {
  50. $price[$key] = ncPriceFormat($configs[$name][$key] / $spec);
  51. } else {
  52. $price[$key] = '/';
  53. }
  54. }
  55. }
  56. $data[$provider_id]['price'] = $price;
  57. }
  58. $card_type_texts = [mtopcard\PetroChinaCard => '中石油', mtopcard\SinopecCard => '中石化', mtopcard\ChinaMobileCard => '中国移动', mtopcard\ChinaUnicomCard => '中国联通', mtopcard\ChinaTelecomCard => '中国电信'];
  59. Tpl::output('provider_list', $all_providers);
  60. Tpl::output('card_types', $card_types);
  61. Tpl::output('card_type_text', $card_type_texts);
  62. Tpl::output('data', $data);
  63. Tpl::output('specs', $specs);
  64. Tpl::showpage('provider.price');
  65. }
  66. private function map_cfg($cfgs)
  67. {
  68. $card_types = function ($stypes)
  69. {
  70. $result = [];
  71. $types = explode(',',$stypes);
  72. foreach ($types as $stype) {
  73. $type = mtopcard\topcard_type($stype);
  74. $result[] = $type;
  75. }
  76. return $result;
  77. };
  78. $result = [];
  79. foreach ($cfgs as $item)
  80. {
  81. $name = $item['name'];
  82. $cfg = $item['cfg'];
  83. $amounts = $cfg['amount'] ?? [];
  84. foreach ($amounts as $spec => $goods)
  85. {
  86. foreach ($goods as $gitem)
  87. {
  88. $types = $card_types($gitem['card_type']);
  89. foreach ($types as $type) {
  90. $result[$name]["{$name}-{$type}-{$spec}"] = $gitem['price'] ?? 0;
  91. }
  92. }
  93. }
  94. }
  95. return $result;
  96. }
  97. }