provider_price.php 3.7 KB

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