refill_successful.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <?php
  2. include(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. private $SUCCESSFUL_URL = BASE_SITE_URL;
  7. public function __construct()
  8. {
  9. parent::__construct();
  10. }
  11. public function indexOp()
  12. {
  13. $type = $_GET['type'] ?? 'provider';
  14. $page = "{$type}.successful";
  15. $days = $this->successful_where($type);
  16. Tpl::output('days', $days);
  17. Tpl::showpage($page);
  18. }
  19. private function successful_where($type) {
  20. if ($type == 'system') {
  21. $url = $this->SUCCESSFUL_URL . '/plot/mchdays';
  22. } else {
  23. $url = $this->SUCCESSFUL_URL . '/plot/days';
  24. }
  25. Log::record("successful get timestamp url : {$url}", Log::DEBUG);
  26. $data = http_request($url);
  27. if(empty($data)) return [];
  28. preg_match_all('/\d{10}/', $data, $matches);
  29. $days = $matches[0];
  30. if(empty($days)) return [];
  31. $result = [];
  32. foreach ($days as $day) {
  33. $result[$day] = date("Y-m-d",$day);
  34. }
  35. return $result;
  36. }
  37. public function successful_time_get_whereOp(){
  38. $type = $_GET['type'] ?? 'provider';
  39. if ($type == 'system') {
  40. $url = $this->SUCCESSFUL_URL . '/plot/mchpaths?time_stamp='.$_GET['timestamp'];
  41. } else {
  42. $url = $this->SUCCESSFUL_URL . '/plot/paths?time_stamp='.$_GET['timestamp'];
  43. }
  44. Log::record("successful get where url : {$url}", Log::DEBUG);
  45. $data = http_request($url);
  46. if(empty($data)) {
  47. echo(json_encode(''));
  48. return;
  49. }
  50. if($type == 'system') {
  51. preg_match_all('/\d{10}\/\d+\/\d{1,2}\/\d\/\d{2,4}/', $data, $matches);
  52. } else {
  53. preg_match_all('/\d{10}\/[a-z]+_*[a-z]*\/\d{1,2}\/\d\/\d{2,4}/', $data, $matches);
  54. }
  55. $conds = $matches[0];
  56. if(empty($conds)) {
  57. echo(json_encode(''));
  58. return;
  59. }
  60. foreach ($conds as $cond) {
  61. $arr = explode('/',$cond);
  62. $chname[] = $arr[1];
  63. $qualitys[] = $arr[2];
  64. $card_types[] = $arr[3];
  65. $amount[] = intval($arr[4]);
  66. }
  67. $chnameData = array_unique($chname);
  68. sort($chnameData);
  69. $result['chname'] = $chnameData;
  70. if ($type == 'system') {
  71. $merchants = [];
  72. $merchant_list = Model('')->table('merchant')->limit(1000)->field('mchid,name,company_name,time_out')->select();
  73. foreach ($merchant_list as $value) {
  74. $merchants[$value['mchid']] = $value;
  75. }
  76. foreach ($chnameData as $mchid) {
  77. $merchant_name = $merchants[$mchid]['company_name'] == '' ? $merchants[$mchid]['name'] : $merchants[$mchid]['company_name'];
  78. $mchname[$mchid] = "{$mchid}-{$merchant_name}-{$merchants[$mchid]['time_out']}";
  79. }
  80. asort($mchname);
  81. $result['chname'] = $mchname;
  82. }
  83. $amountData = array_unique($amount);
  84. sort($amountData);
  85. $result['amount'] = $amountData;
  86. foreach (array_unique($card_types) as $card_type) {
  87. $card_type_text = $this->scard_type($card_type);
  88. if($card_type_text != 'unknown') {
  89. $card_typeData[$card_type] = $card_type_text;
  90. }
  91. }
  92. ksort($card_typeData);
  93. $result['card_type'] = $card_typeData;
  94. $quality_txt = [refill\Quality::Normal=>'普充', refill\Quality::Quick=>'快充', refill\Quality::CardKey=>'卡密',
  95. refill\Quality::ThirdShop=>'三方', refill\Quality::SlowTwentyFour=>'慢24', refill\Quality::SlowSix=>'慢6', refill\Quality::SlowTwo=>'慢2'];
  96. foreach (array_unique($qualitys) as $quality) {
  97. if(array_key_exists($quality, $quality_txt)) {
  98. $qualityData[$quality] = $quality_txt[$quality];
  99. }
  100. }
  101. ksort($qualityData);
  102. $result['quality'] = $qualityData;
  103. echo(json_encode($result));
  104. }
  105. public function merchant_ratiosOp()
  106. {
  107. //0:成功单,1:失败单,2:成功率
  108. $ins = Cache::getInstance('cacheredis');
  109. $json = $ins->get_org('merchant_card_type_ratios');
  110. $data = json_decode($json);
  111. $data = $this->object_array($data);
  112. $result = [];
  113. $stats = [];
  114. $card_types = ['YD', 'LT', 'DX'];
  115. if(!empty($data)) {
  116. $merchant_list = $this->merchants();
  117. foreach ($merchant_list as $value) {
  118. $mchid = $value['mchid'];
  119. if(array_key_exists($mchid, $data) && is_array($data[$mchid])) {
  120. $result[$mchid]['ratio'] = $data[$mchid];
  121. $result[$mchid]['company_name'] = $value['company_name'];
  122. $result[$mchid]['time_out'] = $this->elapse_time($value['time_out']);
  123. foreach ($card_types as $type) {
  124. if($data[$mchid][$type][3600][0] + $data[$mchid][$type][3600][1] > 0) {
  125. $stats[$type]['success'] += $data[$mchid][$type][3600][0];
  126. $stats[$type]['ratio'] += $data[$mchid][$type][3600][2];
  127. $stats[$type]['count'] += 1;
  128. }
  129. }
  130. }
  131. }
  132. Tpl::output('stats', $stats);
  133. Tpl::output('count', count($result));
  134. }
  135. Tpl::output('list', $result);
  136. Tpl::showpage('merchant.ratios');
  137. }
  138. private function object_array($array)
  139. {
  140. if(is_object($array))
  141. {
  142. $array = (array)$array;
  143. }
  144. if(is_array($array))
  145. {
  146. foreach($array as $key=>$value)
  147. {
  148. $array[$key] = $this->object_array($value);
  149. }
  150. }
  151. return $array;
  152. }
  153. }