refill_successful.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <?php
  2. require_once(BASE_CONFIG_PATH . CONFIG_PREFIX . '/refill.ini.php');
  3. require_once(BASE_ROOT_PATH . '/core/framework/function/http.php');
  4. class refill_successfulControl extends SystemControl
  5. {
  6. public function __construct()
  7. {
  8. parent::__construct();
  9. }
  10. public function indexOp()
  11. {
  12. $type = $_GET['type'] ?? 'provider';
  13. $page = "{$type}.successful";
  14. $days = $this->successful_where($type);
  15. Tpl::output('days', $days);
  16. Tpl::showpage($page);
  17. }
  18. private function successful_where($type) {
  19. if ($type == 'system') {
  20. $url = BASE_SITE_URL . '/plot/mchdays';
  21. } else {
  22. $url = BASE_SITE_URL . '/plot/days';
  23. }
  24. Log::record("successful get timestamp url : {$url}", Log::DEBUG);
  25. $data = http_request($url);
  26. if(empty($data)) return [];
  27. preg_match_all('/\d{10}/', $data, $matches);
  28. $days = $matches[0];
  29. if(empty($days)) return [];
  30. $result = [];
  31. foreach ($days as $day) {
  32. $result[$day] = date("Y-m-d",$day);
  33. }
  34. return $result;
  35. }
  36. public function successful_time_get_whereOp(){
  37. $type = $_GET['type'] ?? 'provider';
  38. if ($type == 'system') {
  39. $url = BASE_SITE_URL . '/plot/mchpaths?time_stamp='.$_GET['timestamp'];
  40. } else {
  41. $url = BASE_SITE_URL . '/plot/paths?time_stamp='.$_GET['timestamp'];
  42. }
  43. Log::record("successful get where url : {$url}", Log::DEBUG);
  44. $data = http_request($url);
  45. if(empty($data)) {
  46. echo(json_encode(''));
  47. exit;
  48. }
  49. if($type == 'system') {
  50. preg_match_all('/\d{10}\/\d+\/\d{1,2}\/\d\/\d{2,4}/', $data, $matches);
  51. } else {
  52. preg_match_all('/\d{10}\/[a-z]+\/\d{1,2}\/\d\/\d{2,4}/', $data, $matches);
  53. }
  54. $conds = $matches[0];
  55. if(empty($conds)) {
  56. echo(json_encode(''));
  57. exit;
  58. }
  59. foreach ($conds as $cond) {
  60. $arr = explode('/',$cond);
  61. $chname[] = $arr[1];
  62. $qualitys[] = $arr[2];
  63. $card_types[] = $arr[3];
  64. $amount[] = intval($arr[4]);
  65. }
  66. $chnameData = array_unique($chname);
  67. sort($chnameData);
  68. $result['chname'] = $chnameData;
  69. if ($type == 'system') {
  70. $merchants = [];
  71. $merchant_list = Model('')->table('merchant')->limit(1000)->field('mchid,name,company_name')->select();
  72. foreach ($merchant_list as $key => $value) {
  73. $merchants[$value['mchid']] = $value;
  74. }
  75. foreach ($chnameData as $mchid) {
  76. $merchant_name = $merchants[$mchid]['company_name'] == '' ? $merchants[$mchid]['name'] : $merchants[$mchid]['company_name'];
  77. $mchname[$mchid] = "{$mchid}-{$merchant_name}";
  78. }
  79. asort($mchname);
  80. $result['chname'] = $mchname;
  81. }
  82. $amountData = array_unique($amount);
  83. sort($amountData);
  84. $result['amount'] = $amountData;
  85. foreach (array_unique($card_types) as $card_type) {
  86. $card_typeData[$card_type] = $this->scard_type($card_type);
  87. }
  88. ksort($card_typeData);
  89. $result['card_type'] = $card_typeData;
  90. $quality_txt = [1=>'普充', 2=>'快充', 3=>'卡密', 4=>'三方', 5=>'慢充二十四小时', 6=>'慢充六小时', 7=>'慢充两小时'];
  91. foreach (array_unique($qualitys) as $quality) {
  92. $qualityData[$quality] = $quality_txt[$quality];
  93. }
  94. ksort($qualityData);
  95. $result['quality'] = $qualityData;
  96. echo(json_encode($result));
  97. exit;
  98. }
  99. private function scard_type(int $card_type)
  100. {
  101. if ($card_type == 1) { //中石油
  102. return '中石油';
  103. } elseif ($card_type == 2) { //中石化
  104. return '中石化';
  105. } elseif ($card_type == 4) { //中国移动
  106. return '中国移动';
  107. } elseif ($card_type == 5) { //中国联通
  108. return '中国联通';
  109. } elseif ($card_type == 6) { //中国电信
  110. return '中国电信';
  111. } elseif ($card_type == 7) { //中国电信
  112. return '增值业务';
  113. } else {
  114. return 'unknown';
  115. }
  116. }
  117. }