123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 |
- <?php
- include(BASE_CONFIG_PATH . CONFIG_PREFIX . '/refill.ini.php');
- require_once(BASE_ROOT_PATH . '/core/framework/function/http.php');
- class refill_successfulControl extends SystemControl
- {
- private $SUCCESSFUL_URL = BASE_SITE_URL;
-
- public function __construct()
- {
- parent::__construct();
- }
- public function indexOp()
- {
- $type = $_GET['type'] ?? 'provider';
- $page = "{$type}.successful";
- $days = $this->successful_where($type);
- Tpl::output('days', $days);
- Tpl::showpage($page);
- }
- private function successful_where($type) {
- if ($type == 'system') {
- $url = $this->SUCCESSFUL_URL . '/plot/mchdays';
- } else {
- $url = $this->SUCCESSFUL_URL . '/plot/days';
- }
- Log::record("successful 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 successful_time_get_whereOp(){
- $type = $_GET['type'] ?? 'provider';
- if ($type == 'system') {
- $url = $this->SUCCESSFUL_URL . '/plot/mchpaths?time_stamp='.$_GET['timestamp'];
- } else {
- $url = $this->SUCCESSFUL_URL . '/plot/paths?time_stamp='.$_GET['timestamp'];
- }
- Log::record("successful get where url : {$url}", Log::DEBUG);
- $data = http_request($url);
- if(empty($data)) {
- echo(json_encode(''));
- return;
- }
- if($type == 'system') {
- preg_match_all('/\d{10}\/\d+\/\d{1,2}\/\d\/\d{2,4}/', $data, $matches);
- } else {
- preg_match_all('/\d{10}\/[a-z]+_*[a-z]*\/\d{1,2}\/\d\/\d{2,4}/', $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);
- $result['chname'] = $chnameData;
- if ($type == 'system') {
- $merchants = [];
- $merchant_list = Model('')->table('merchant')->limit(1000)->field('mchid,name,company_name,time_out')->select();
- foreach ($merchant_list as $value) {
- $merchants[$value['mchid']] = $value;
- }
- 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;
- }
- $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');
- }
- 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;
- }
- }
|