refill_analysis.php 6.6 KB

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