refill_analysis.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  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. } else {
  25. return [];
  26. }
  27. Log::record("analysis get timestamp url : {$url}", Log::DEBUG);
  28. $data = http_request($url);
  29. if(empty($data)) return [];
  30. preg_match_all('/\d{10}/', $data, $matches);
  31. $days = $matches[0];
  32. if(empty($days)) return [];
  33. $result = [];
  34. foreach ($days as $day) {
  35. $result[$day] = date("Y-m-d",$day);
  36. }
  37. return $result;
  38. }
  39. public function analysis_time_get_whereOp(){
  40. $type = $_GET['type'] ?? 'provider';
  41. if ($type == 'system') {
  42. $url = $this->ANALYSIS_URL . '/plot/mchpaths?time_stamp='.$_GET['timestamp'];
  43. $pattern = '/\d{10}\/\d+\/\d{1,2}\/\d\/\d{2,4}/';
  44. } elseif($type == 'provider') {
  45. $pattern = '/\d{10}\/[a-z]+_*[a-z]*\/\d{1,2}\/\d\/\d{2,4}/';
  46. $url = $this->ANALYSIS_URL . '/plot/paths?time_stamp='.$_GET['timestamp'];
  47. }
  48. Log::record("analysis get where url : {$url}", Log::DEBUG);
  49. $data = http_request($url);
  50. if(empty($data) || empty($pattern)) {
  51. echo(json_encode(''));
  52. return;
  53. }
  54. preg_match_all($pattern, $data, $matches);
  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. if ($type == 'system') {
  70. $merchants = [];
  71. $merchant_list = Model('')->table('merchant')->limit(1000)->field('mchid,name,company_name,time_out')->select();
  72. foreach ($merchant_list as $merchant) {
  73. $merchants[$merchant['mchid']] = $merchant;
  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}-{$merchants[$mchid]['time_out']}";
  78. }
  79. asort($mchname);
  80. $result['chname'] = $mchname;
  81. } elseif($type == 'provider') {
  82. $providers = [];
  83. $provider_list = $this->providers();
  84. foreach ($provider_list as $provider) {
  85. $providers[$provider['name']] = $provider;
  86. }
  87. foreach ($chnameData as $provider_name) {
  88. $store_names[$provider_name] = $providers[$provider_name]['store_name'];
  89. }
  90. $result['chname'] = $store_names;
  91. }
  92. $amountData = array_unique($amount);
  93. sort($amountData);
  94. $result['amount'] = $amountData;
  95. foreach (array_unique($card_types) as $card_type) {
  96. $card_type_text = $this->scard_type($card_type);
  97. if($card_type_text != 'unknown') {
  98. $card_typeData[$card_type] = $card_type_text;
  99. }
  100. }
  101. ksort($card_typeData);
  102. $result['card_type'] = $card_typeData;
  103. $quality_txt = [refill\Quality::Normal=>'普充', refill\Quality::Quick=>'快充', refill\Quality::CardKey=>'卡密',
  104. refill\Quality::ThirdShop=>'三方', refill\Quality::SlowTwentyFour=>'慢24', refill\Quality::SlowSix=>'慢6', refill\Quality::SlowTwo=>'慢2'];
  105. foreach (array_unique($qualitys) as $quality) {
  106. if(array_key_exists($quality, $quality_txt)) {
  107. $qualityData[$quality] = $quality_txt[$quality];
  108. }
  109. }
  110. ksort($qualityData);
  111. $result['quality'] = $qualityData;
  112. echo(json_encode($result));
  113. }
  114. public function merchant_ratiosOp()
  115. {
  116. //0:成功单,1:失败单,2:成功率
  117. $ins = Cache::getInstance('cacheredis');
  118. $json = $ins->get_org('merchant_card_type_ratios');
  119. $data = json_decode($json);
  120. $data = $this->object_array($data);
  121. $result = [];
  122. $stats = [];
  123. $card_types = ['YD', 'LT', 'DX'];
  124. if(!empty($data)) {
  125. $merchant_list = $this->merchants();
  126. foreach ($merchant_list as $value) {
  127. $mchid = $value['mchid'];
  128. if(array_key_exists($mchid, $data) && is_array($data[$mchid])) {
  129. $result[$mchid]['ratio'] = $data[$mchid];
  130. $result[$mchid]['company_name'] = $value['company_name'];
  131. $result[$mchid]['time_out'] = $this->elapse_time($value['time_out']);
  132. foreach ($card_types as $type) {
  133. if($data[$mchid][$type][3600][0] + $data[$mchid][$type][3600][1] > 0) {
  134. $stats[$type]['success'] += $data[$mchid][$type][3600][0];
  135. $stats[$type]['ratio'] += $data[$mchid][$type][3600][2];
  136. $stats[$type]['count'] += 1;
  137. }
  138. }
  139. }
  140. }
  141. Tpl::output('stats', $stats);
  142. Tpl::output('count', count($result));
  143. }
  144. Tpl::output('list', $result);
  145. Tpl::showpage('merchant.ratios');
  146. }
  147. public function new_versionOp()
  148. {
  149. $type = $_GET['type'] ?? 'provider';
  150. $page = "analysis.cov.{$type}";
  151. if($type == 'provider')
  152. {
  153. global $config;
  154. $cond['type'] = ['in', [mtopcard\OilCardPaper, mtopcard\PhoneCardPaper]];
  155. $cond['opened'] = 1;
  156. $open_providers = $this->providers($cond);
  157. $cond['opened'] = 2;
  158. $cond['oper_time'] = ['gt', time() - 86400 * 7];
  159. $close_providers = $this->providers($cond);
  160. $provider_items = array_merge($open_providers, $close_providers);
  161. foreach ($provider_items as $item) {
  162. $provider_list[$item['type']][] = $item;
  163. }
  164. foreach ($provider_list as $provider_type => $providers)
  165. {
  166. $data = [];
  167. foreach ($providers as $provider) {
  168. $quality = $provider['qualitys'];
  169. if (empty($data[$quality]['name'])) {
  170. $quality_text = $provider['type'] == mtopcard\OilCardPaper ? $config['oil_quality_text'] : $config['phone_quality_text'];
  171. $data[$quality]['name'] = $quality_text[$quality];
  172. }
  173. $data[$quality]['params'][] = [
  174. 'name' => $provider['store_name'],
  175. 'value' => $provider['name']
  176. ];
  177. }
  178. ksort($data);
  179. $result[$provider_type] = $data;
  180. }
  181. ksort($result);
  182. Tpl::output('providers', $result);
  183. }
  184. Tpl::showpage($page);
  185. }
  186. public function provider_dataOp()
  187. {
  188. $cond = [];
  189. if(!empty($_GET['quality'])){
  190. $cond['qualitys'] = $_GET['quality'];
  191. }
  192. $url = $this->ANALYSIS_URL . '/plot/channels';
  193. Log::record("analysis get provider_data url : {$url}", Log::DEBUG);
  194. $resp = http_request($url);
  195. preg_match_all('/[a-z]+_*[a-z]*/', $resp, $matches);
  196. if(empty($resp) || empty($matches)) {
  197. echo(json_encode(''));
  198. return;
  199. }
  200. $cond['name'] = ['in', $matches[0]];
  201. $provider_list = $this->providers($cond);
  202. $result = [];
  203. foreach ($provider_list as $value) {
  204. $data['name'] = "{$value['store_name']}:{$value['name']}";
  205. $data['value'] = $value['name'];
  206. $result[] = $data;
  207. }
  208. echo json_encode($result);
  209. }
  210. public function merchant_dataOp()
  211. {
  212. $cond = [];
  213. $url = $this->ANALYSIS_URL . '/plot/mchids';
  214. Log::record("analysis get merchant_data url : {$url}", Log::DEBUG);
  215. $resp = http_request($url);
  216. preg_match_all('/\d{2,6}/', $resp, $matches);
  217. if(empty($resp) || empty($matches)) {
  218. echo(json_encode(''));
  219. return;
  220. }
  221. $cond['mchid'] = ['in', $matches[0]];
  222. $merchant_list = $this->merchants($cond);
  223. $result = [];
  224. foreach ($merchant_list as $value) {
  225. $name = $value['company_name'] ?? $value['name'];
  226. $data['name'] = $name .' : '. $value['mchid'] .'-'. $value['time_out'];
  227. $data['value'] = $value['mchid'];
  228. $result[] = $data;
  229. }
  230. echo json_encode($result);
  231. }
  232. public function card_type_dataOp()
  233. {
  234. $result = [
  235. ['name' => '中石油', 'value' => mtopcard\PetroChinaCard],
  236. ['name' => '中石化', 'value' => mtopcard\SinopecCard],
  237. ['name' => '中国移动', 'value' => mtopcard\ChinaMobileCard],
  238. ['name' => '中国联通', 'value' => mtopcard\ChinaUnicomCard],
  239. ['name' => '中国电信', 'value' => mtopcard\ChinaTelecomCard],
  240. ];
  241. echo json_encode($result);
  242. }
  243. private function object_array($array)
  244. {
  245. if(is_object($array))
  246. {
  247. $array = (array)$array;
  248. }
  249. if(is_array($array))
  250. {
  251. foreach($array as $key=>$value)
  252. {
  253. $array[$key] = $this->object_array($value);
  254. }
  255. }
  256. return $array;
  257. }
  258. }