123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276 |
- <?php
- include(BASE_CONFIG_PATH . CONFIG_PREFIX . '/refill.ini.php');
- require_once(BASE_ROOT_PATH . '/core/framework/function/http.php');
- class refill_analysisControl extends SystemControl
- {
- private $ANALYSIS_URL = 'https://ylweb.xyzshops.cn';
-
- public function __construct()
- {
- parent::__construct();
- }
- public function indexOp()
- {
- $type = $_GET['type'] ?? 'provider';
- $page = "analysis.{$type}";
- $days = $this->analysis_where($type);
- Tpl::output('days', $days);
- Tpl::showpage($page);
- }
- private function analysis_where($type) {
- if ($type == 'system') {
- $url = $this->ANALYSIS_URL . '/plot/mchdays';
- } elseif($type == 'provider') {
- $url = $this->ANALYSIS_URL . '/plot/days';
- }
- Log::record("analysis get timestamp url : {$url}", Log::DEBUG);
- $data = http_request($url);
- if(empty($data)) return [];
- preg_match_all('/\d{10}/', $data, $matches);
- $days = $matches[0];
- if(empty($days)) return [];
- $result = [];
- foreach ($days as $day) {
- $result[$day] = date("Y-m-d",$day);
- }
- return $result;
- }
- public function analysis_time_get_whereOp(){
- $type = $_GET['type'] ?? 'provider';
- if ($type == 'system') {
- $url = $this->ANALYSIS_URL . '/plot/mchpaths?time_stamp='.$_GET['timestamp'];
- $pattern = '/\d{10}\/\d+\/\d{1,2}\/\d\/\d{2,4}/';
- } elseif($type == 'provider') {
- $pattern = '/\d{10}\/[a-z]+_*[a-z]*\/\d{1,2}\/\d\/\d{2,4}/';
- $url = $this->ANALYSIS_URL . '/plot/paths?time_stamp='.$_GET['timestamp'];
- }
- Log::record("analysis get where url : {$url}", Log::DEBUG);
- $data = http_request($url);
- if(empty($data) || empty($pattern)) {
- echo(json_encode(''));
- return;
- }
- preg_match_all($pattern, $data, $matches);
- $conds = $matches[0];
- if(empty($conds)) {
- echo(json_encode(''));
- return;
- }
- foreach ($conds as $cond) {
- $arr = explode('/',$cond);
- $chname[] = $arr[1];
- $qualitys[] = $arr[2];
- $card_types[] = $arr[3];
- $amount[] = intval($arr[4]);
- }
- $chnameData = array_unique($chname);
- sort($chnameData);
- if ($type == 'system') {
- $merchants = [];
- $merchant_list = Model('')->table('merchant')->limit(1000)->field('mchid,name,company_name,time_out')->select();
- foreach ($merchant_list as $merchant) {
- $merchants[$merchant['mchid']] = $merchant;
- }
- foreach ($chnameData as $mchid) {
- $merchant_name = $merchants[$mchid]['company_name'] == '' ? $merchants[$mchid]['name'] : $merchants[$mchid]['company_name'];
- $mchname[$mchid] = "{$mchid}-{$merchant_name}-{$merchants[$mchid]['time_out']}";
- }
- asort($mchname);
- $result['chname'] = $mchname;
- } elseif($type == 'provider') {
- $providers = [];
- $provider_list = $this->providers();
- foreach ($provider_list as $provider) {
- $providers[$provider['name']] = $provider;
- }
- foreach ($chnameData as $provider_name) {
- $store_names[$provider_name] = $providers[$provider_name]['store_name'];
- }
- $result['chname'] = $store_names;
- }
- $amountData = array_unique($amount);
- sort($amountData);
- $result['amount'] = $amountData;
- foreach (array_unique($card_types) as $card_type) {
- $card_type_text = $this->scard_type($card_type);
- if($card_type_text != 'unknown') {
- $card_typeData[$card_type] = $card_type_text;
- }
- }
- ksort($card_typeData);
- $result['card_type'] = $card_typeData;
- $quality_txt = [refill\Quality::Normal=>'普充', refill\Quality::Quick=>'快充', refill\Quality::CardKey=>'卡密',
- refill\Quality::ThirdShop=>'三方', refill\Quality::SlowTwentyFour=>'慢24', refill\Quality::SlowSix=>'慢6', refill\Quality::SlowTwo=>'慢2'];
- foreach (array_unique($qualitys) as $quality) {
- if(array_key_exists($quality, $quality_txt)) {
- $qualityData[$quality] = $quality_txt[$quality];
- }
- }
- ksort($qualityData);
- $result['quality'] = $qualityData;
- echo(json_encode($result));
- }
- public function merchant_ratiosOp()
- {
- //0:成功单,1:失败单,2:成功率
- $ins = Cache::getInstance('cacheredis');
- $json = $ins->get_org('merchant_card_type_ratios');
- $data = json_decode($json);
- $data = $this->object_array($data);
- $result = [];
- $stats = [];
- $card_types = ['YD', 'LT', 'DX'];
- if(!empty($data)) {
- $merchant_list = $this->merchants();
- foreach ($merchant_list as $value) {
- $mchid = $value['mchid'];
- if(array_key_exists($mchid, $data) && is_array($data[$mchid])) {
- $result[$mchid]['ratio'] = $data[$mchid];
- $result[$mchid]['company_name'] = $value['company_name'];
- $result[$mchid]['time_out'] = $this->elapse_time($value['time_out']);
- foreach ($card_types as $type) {
- if($data[$mchid][$type][3600][0] + $data[$mchid][$type][3600][1] > 0) {
- $stats[$type]['success'] += $data[$mchid][$type][3600][0];
- $stats[$type]['ratio'] += $data[$mchid][$type][3600][2];
- $stats[$type]['count'] += 1;
- }
- }
- }
- }
- Tpl::output('stats', $stats);
- Tpl::output('count', count($result));
- }
- Tpl::output('list', $result);
- Tpl::showpage('merchant.ratios');
- }
- public function new_versionOp()
- {
- $type = $_GET['type'] ?? 'provider';
- $page = "analysis.new_version.{$type}";
- if($type == 'provider')
- {
- global $config;
- $cond['type'] = ['in', [mtopcard\OilCardPaper, mtopcard\PhoneCardPaper]];
- $cond['opened'] = 1;
- $open_providers = $this->providers($cond);
- $cond['opened'] = 2;
- $cond['oper_time'] = ['gt', time() - 86400 * 7];
- $close_providers = $this->providers($cond);
- $provider_items = array_merge($open_providers, $close_providers);
- foreach ($provider_items as $item) {
- $provider_list[$item['type']][] = $item;
- }
- foreach ($provider_list as $provider_type => $providers)
- {
- $data = [];
- foreach ($providers as $provider) {
- $quality = $provider['qualitys'];
- if (empty($data[$quality]['name'])) {
- $quality_text = $provider['type'] == mtopcard\OilCardPaper ? $config['oil_quality_text'] : $config['phone_quality_text'];
- $data[$quality]['name'] = $quality_text[$quality];
- }
- $data[$quality]['params'][] = [
- 'name' => $provider['store_name'],
- 'value' => $provider['name']
- ];
- }
- ksort($data);
- $result[$provider_type] = $data;
- }
- ksort($result);
- Tpl::output('providers', $result);
- }
- Tpl::showpage($page);
- }
- public function provider_dataOp()
- {
- $cond = [];
- if(!empty($_GET['quality'])){
- $cond['qualitys'] = $_GET['quality'];
- }
- $url = $this->ANALYSIS_URL . '/plot/channels';
- Log::record("analysis get provider_data url : {$url}", Log::DEBUG);
- $resp = http_request($url);
- preg_match_all('/[a-z]+_*[a-z]*/', $resp, $matches);
- if(empty($resp) || empty($matches)) {
- echo(json_encode(''));
- return;
- }
- $cond['name'] = ['in', $matches[0]];
- $provider_list = $this->providers($cond);
- $result = [];
- foreach ($provider_list as $value) {
- $data['name'] = "{$value['store_name']}:{$value['name']}";
- $data['value'] = $value['name'];
- $result[] = $data;
- }
- echo json_encode($result);
- }
- public function merchant_dataOp()
- {
- $cond = [];
- $url = $this->ANALYSIS_URL . '/plot/mchids';
- Log::record("analysis get merchant_data url : {$url}", Log::DEBUG);
- $resp = http_request($url);
- preg_match_all('/\d{2,6}/', $resp, $matches);
- if(empty($resp) || empty($matches)) {
- echo(json_encode(''));
- return;
- }
- $cond['mchid'] = ['in', $matches[0]];
- $merchant_list = $this->merchants($cond);
- $result = [];
- foreach ($merchant_list as $value) {
- $name = $value['company_name'] ?? $value['name'];
- $data['name'] = $name .' : '. $value['mchid'] .'-'. $value['time_out'];
- $data['value'] = $value['mchid'];
- $result[] = $data;
- }
- echo json_encode($result);
- }
- public function card_type_dataOp()
- {
- $result = [
- ['name' => '中石油', 'value' => mtopcard\PetroChinaCard],
- ['name' => '中石化', 'value' => mtopcard\SinopecCard],
- ['name' => '中国移动', 'value' => mtopcard\ChinaMobileCard],
- ['name' => '中国联通', 'value' => mtopcard\ChinaUnicomCard],
- ['name' => '中国电信', 'value' => mtopcard\ChinaTelecomCard],
- ];
- echo json_encode($result);
- }
- private function object_array($array)
- {
- if(is_object($array))
- {
- $array = (array)$array;
- }
- if(is_array($array))
- {
- foreach($array as $key=>$value)
- {
- $array[$key] = $this->object_array($value);
- }
- }
- return $array;
- }
- }
|