refill_analysis.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  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 = 'https://ylweb.xyzshops.cn';
  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 new_versionOp()
  146. {
  147. $type = $_GET['type'] ?? 'provider';
  148. $page = "analysis.new_version.{$type}";
  149. if($type == 'provider')
  150. {
  151. global $config;
  152. $cond['type'] = ['in', [mtopcard\OilCardPaper, mtopcard\PhoneCardPaper]];
  153. $cond['opened'] = 1;
  154. $open_providers = $this->providers($cond);
  155. $cond['opened'] = 2;
  156. $cond['oper_time'] = ['gt', time() - 86400 * 7];
  157. $close_providers = $this->providers($cond);
  158. $provider_items = array_merge($open_providers, $close_providers);
  159. foreach ($provider_items as $item) {
  160. $provider_list[$item['type']][] = $item;
  161. }
  162. foreach ($provider_list as $provider_type => $providers)
  163. {
  164. $data = [];
  165. foreach ($providers as $provider) {
  166. $quality = $provider['qualitys'];
  167. if (empty($data[$quality]['name'])) {
  168. $quality_text = $provider['type'] == mtopcard\OilCardPaper ? $config['oil_quality_text'] : $config['phone_quality_text'];
  169. $data[$quality]['name'] = $quality_text[$quality];
  170. }
  171. $data[$quality]['params'][] = [
  172. 'name' => $provider['store_name'],
  173. 'value' => $provider['name']
  174. ];
  175. }
  176. ksort($data);
  177. $result[$provider_type] = $data;
  178. }
  179. ksort($result);
  180. Tpl::output('providers', $result);
  181. }
  182. Tpl::showpage($page);
  183. }
  184. public function provider_dataOp()
  185. {
  186. $cond = [];
  187. if(!empty($_GET['quality'])){
  188. $cond['qualitys'] = $_GET['quality'];
  189. }
  190. $url = $this->ANALYSIS_URL . '/plot/channels';
  191. Log::record("analysis get provider_data url : {$url}", Log::DEBUG);
  192. $resp = http_request($url);
  193. preg_match_all('/[a-z]+_*[a-z]*/', $resp, $matches);
  194. if(empty($resp) || empty($matches)) {
  195. echo(json_encode(''));
  196. return;
  197. }
  198. $cond['name'] = ['in', $matches[0]];
  199. $provider_list = $this->providers($cond);
  200. $result = [];
  201. foreach ($provider_list as $value) {
  202. $data['name'] = "{$value['store_name']}:{$value['name']}";
  203. $data['value'] = $value['name'];
  204. $result[] = $data;
  205. }
  206. echo json_encode($result);
  207. }
  208. public function merchant_dataOp()
  209. {
  210. $cond = [];
  211. $url = $this->ANALYSIS_URL . '/plot/mchids';
  212. Log::record("analysis get merchant_data url : {$url}", Log::DEBUG);
  213. $resp = http_request($url);
  214. preg_match_all('/\d{2,6}/', $resp, $matches);
  215. if(empty($resp) || empty($matches)) {
  216. echo(json_encode(''));
  217. return;
  218. }
  219. $cond['mchid'] = ['in', $matches[0]];
  220. $merchant_list = $this->merchants($cond);
  221. $result = [];
  222. foreach ($merchant_list as $value) {
  223. $name = $value['company_name'] ?? $value['name'];
  224. $data['name'] = $name .' : '. $value['mchid'] .'-'. $value['time_out'];
  225. $data['value'] = $value['mchid'];
  226. $result[] = $data;
  227. }
  228. echo json_encode($result);
  229. }
  230. public function card_type_dataOp()
  231. {
  232. $result = [
  233. ['name' => '中石油', 'value' => mtopcard\PetroChinaCard],
  234. ['name' => '中石化', 'value' => mtopcard\SinopecCard],
  235. ['name' => '中国移动', 'value' => mtopcard\ChinaMobileCard],
  236. ['name' => '中国联通', 'value' => mtopcard\ChinaUnicomCard],
  237. ['name' => '中国电信', 'value' => mtopcard\ChinaTelecomCard],
  238. ];
  239. echo json_encode($result);
  240. }
  241. private function object_array($array)
  242. {
  243. if(is_object($array))
  244. {
  245. $array = (array)$array;
  246. }
  247. if(is_array($array))
  248. {
  249. foreach($array as $key=>$value)
  250. {
  251. $array[$key] = $this->object_array($value);
  252. }
  253. }
  254. return $array;
  255. }
  256. }