mTimeouts = [3 => 180, 4 => 300, 5 => 600, 6 => 900, 7 => 7200]; parent::__construct(); } private function time_cond($timeout_type, $card_type, $cur_time, $manual_time) { $mintime_getter = function () { $mod = Model(); $item = $mod->table('refill_detail')->field('min(order_time) as mintime')->where(['order_state' => 30])->find(); if(empty($item['mintime'])) { return time() - 3600; } else { return intval($item['mintime']); } }; $mchid_filter = function ($time_out) { $mchids = Model('')->table('merchant')->where(['time_out' => ['elt', $time_out]])->field('mchid')->select(); $mchids = array_column($mchids, 'mchid'); $mchids = implode(',', $mchids); return $mchids; }; $period = 20; $start_day = $mintime_getter(); //strtotime("-5 days",$cur_time); $time_cond = []; $mch_cond = []; if ($timeout_type > 0) { if (in_array($timeout_type, [1, 2, 8, 9, 10, 11, 12, 13])) { if ($timeout_type === 1) { $time_cond['refill_order.order_time'] = ['between', [$cur_time - 3600, $cur_time - 1800]]; $time_cond['vr_order.add_time'] = ['between', [$cur_time - 3600, $cur_time]]; } if ($timeout_type === 2) { $time_cond['refill_order.order_time'] = ['between', [$cur_time - 5400, $cur_time - 3600]]; $time_cond['vr_order.add_time'] = ['between', [$cur_time - 5400, $cur_time]]; } if ($timeout_type === 8) { $time_cond['refill_order.order_time'] = ['between', [$cur_time - 7200, $cur_time - 5400]]; $time_cond['vr_order.add_time'] = ['between', [$cur_time - 7200, $cur_time]]; } if ($timeout_type === 9) { $time_cond['refill_order.order_time'] = ['between', [$cur_time - 9000, $cur_time - 7200]]; $time_cond['vr_order.add_time'] = ['between', [$cur_time - 9000, $cur_time]]; } if ($timeout_type === 10) { $time_cond['refill_order.order_time'] = ['between', [$cur_time - 10800, $cur_time - 9000]]; $time_cond['vr_order.add_time'] = ['between', [$cur_time - 10800, $cur_time]]; } if ($timeout_type === 11) { $time_cond['refill_order.order_time'] = ['between', [$cur_time - 12600, $cur_time - 10800]]; $time_cond['vr_order.add_time'] = ['between', [$cur_time - 12600, $cur_time]]; } if ($timeout_type === 12) { $time_cond['refill_order.order_time'] = ['between', [$cur_time - 14400, $cur_time - 12600]]; $time_cond['vr_order.add_time'] = ['between', [$cur_time - 14400, $cur_time]]; } if ($timeout_type === 13) { $time_cond['refill_order.order_time'] = ['between', [$start_day, $cur_time - 14400]]; $time_cond['vr_order.add_time'] = ['between', [$start_day, $cur_time]]; } } elseif (in_array($timeout_type, [3, 4, 5, 6, 7])) { $time_out = $this->mTimeouts[$timeout_type]; $mchids = $mchid_filter($time_out); $time_cond['vr_order.add_time&vr_order.add_time'] = ['_multi' => true, ['egt', $start_day], ['lt', $cur_time]]; $time_cond['refill_order.order_time&refill_order.order_time'] = ['_multi' => true, ['egt', $start_day], ['lt', $cur_time - $time_out]]; $mch_cond['refill_order.mchid'] = ['in', $mchids]; $card_type = 'phone'; } else { $time_cond = []; } } else if ($manual_time && $manual_time < 24) { $end_offset = intval($manual_time * 3600); $time_cond['refill_order.order_time'] = ['between', [$start_day, $cur_time - $end_offset]]; $time_cond['vr_order.add_time'] = ['between', [$start_day, $cur_time]]; } else { $time_cond['vr_order.add_time&vr_order.add_time'] = ['_multi' => true, ['egt', $start_day], ['lt', $cur_time]]; $time_cond['refill_order.order_time&refill_order.order_time&refill_order.order_time'] = ['_multi' => true, ['egt', $start_day], ['lt', $cur_time], ['exp', "refill_order.order_time < {$cur_time} - merchant.time_out + {$period}"]]; } return [$time_cond, $mch_cond, $card_type]; } public function indexOp() { $model_refill_order = Model('refill_order'); $base_cond['refill_order.inner_status'] = 0; $base_cond['vr_order.order_state'] = ORDER_STATE_SEND; $timeout_type = intval($_GET['time']); $card_type = $_GET['card_type']; $manual_time = $_GET['manual_time']; if (!empty($_GET['store_id'])) { $base_cond['vr_order.store_id'] = $_GET['store_id']; } $cur_time = time(); [$time_cond, $mch_cond, $card_type] = $this->time_cond($timeout_type, $card_type, $cur_time, $manual_time); if (!empty($_GET['mchid'])) { $base_cond['refill_order.mchid'] = $_GET['mchid']; } elseif(!empty($_GET['no_mchid'])) { $no_mchid = explode(',', $_GET['no_mchid']); $base_cond['refill_order.mchid'] = ['not in', $no_mchid]; } elseif(!empty($mch_cond)) { $base_cond = array_merge($base_cond,$mch_cond); } if (!empty($card_type)) { if (in_array($card_type, ['1', '2', '4', '5', '6', '7'])) { $base_cond['refill_order.card_type'] = $card_type; } if ($card_type == 'oil') { $base_cond['refill_order.card_type'] = ['in', ['1', '2']]; } if ($card_type == 'phone') { $base_cond['refill_order.card_type'] = ['in', ['4', '5', '6']]; } } if (!empty($_GET['refill_amount'])) { $base_cond['refill_order.refill_amount'] = $_GET['refill_amount']; } if (!empty($_GET['quality'])) { $base_cond['refill_order.quality'] = $_GET['quality']; } $orders_cond = array_merge($base_cond,$time_cond); if (!empty($_GET['order_query'])) { $this->updateOrderSend($orders_cond); return; } if (!empty($_GET['export'])) { $this->RefillOrderExport($orders_cond, '商户超时监控导出', 'time_out_order'); return; } // $store_ids = Model('')->table('refill_order,vr_order,merchant') // ->join('inner,inner') // ->on('refill_order.order_id=vr_order.order_id,refill_order.mchid=merchant.mchid') // ->field('DISTINCT vr_order.store_id') // ->where($orders_cond) // ->group('vr_order.store_id') // ->order('store_id asc') // ->select(); // $store_ids = array_column($store_ids, 'store_id'); $merchant_list = $this->merchants(); // $provider_list = $this->providers(['store.store_id' => ['in', $store_ids]]); $provider_list = $this->providers(); [$merchant_stat, $order_stat] = $this->merchant_timeout_stats($orders_cond); if (empty($_GET['mchid'])) { $order_count = $order_stat['order_count']; }else{ $order_count = $merchant_stat[$_GET['mchid']]['order_count']; } $fields = "refill_order.*,vr_order.order_state,( {$cur_time} - refill_order.order_time - merchant.time_out ) as mtime_out"; $order_by = "mtime_out desc"; $order_list = $model_refill_order->getMerchantTimeOut($orders_cond, 200, $order_count, $fields, $order_by); $special_stat = $this->extra_stats($base_cond, $timeout_type,$cur_time); if(!empty($order_list)) { $order_list = $this->orderFormat($order_list, $merchant_list); } Tpl::output('stat', $order_stat); Tpl::output('count', $special_stat); Tpl::output('merchant_stat', $merchant_stat); Tpl::output('order_list', $order_list); Tpl::output('merchant_list', $merchant_list); Tpl::output('provider_list', $provider_list); Tpl::output('except_stat', $this->except_stat()); Tpl::output('show_page', $model_refill_order->showpage()); Tpl::showpage('refill.order.send.index'); } public function monitor_transferOp() { $merchants_getter = function ($mchids) { $mches = Model('')->table('merchant') ->field('mchid, company_name, name') ->where(['mchid' => ['in',$mchids] ]) ->select(); return $mches; }; $model_refill_order = Model('refill_order'); $base_cond['refill_order.inner_status'] = 0; if (in_array($_GET['order_state'], ['0', '10', '20', '30', '40'])) { $base_cond['vr_order.order_state'] = intval($_GET['order_state']); } // else { // $base_cond['vr_order.order_state'] = ['in', [ORDER_STATE_CANCEL, ORDER_STATE_SEND]]; // } $all_mchids = $this->getAllTransferMchid(); if (!empty($_GET['mchid'])) { $base_cond['refill_order.mchid'] = $_GET['mchid']; } else { $base_cond['refill_order.mchid'] = ['in', $all_mchids]; } $card_type = $_GET['card_type']; if (!empty($card_type)) { if (in_array($card_type, ['1', '2', '4', '5', '6', '7'])) { $base_cond['refill_order.card_type'] = $card_type; } if ($card_type == 'oil') { $base_cond['refill_order.card_type'] = ['in', ['1', '2']]; } if ($card_type == 'phone') { $base_cond['refill_order.card_type'] = ['in', ['4', '5', '6']]; } } if (!empty($_GET['refill_amount'])) { $base_cond['refill_order.refill_amount'] = $_GET['refill_amount']; } $cur_time = time(); $start_unixtime = intval(strtotime($_GET['query_start_time'])); $end_unixtime = intval(strtotime($_GET['query_end_time'])); if(!empty($_GET['time'])) { $end_unixtime = $cur_time + $_GET['time']; } if ($start_unixtime > 0 && $end_unixtime > $start_unixtime) { $base_cond['refill_order.order_time'] = [['egt', $start_unixtime], ['lt', $end_unixtime], 'and']; } elseif ($start_unixtime > 0) { $base_cond['refill_order.order_time'] = ['egt', $start_unixtime]; } elseif ($end_unixtime > 0) { $base_cond['refill_order.order_time'] = ['lt', $end_unixtime]; } else { $_GET['query_start_time'] = date('Y-m-d 00:00:00', time()); $start = strtotime($_GET['query_start_time']); $base_cond['refill_order.order_time'] = ['egt', $start]; } if (!empty($_GET['export'])) { $this->monitor_transfer_export($base_cond, $merchants_getter, $all_mchids); return; } $cur_time = time(); $order_by = 'refill_order.order_time desc'; $order_list = Model('')->table('refill_order,vr_order,merchant') ->join('inner,inner') ->on('refill_order.order_id=vr_order.order_id,refill_order.mchid=merchant.mchid') ->field("refill_order.*,vr_order.order_state,({$cur_time} - refill_order.order_time - merchant.time_out) as mtime_out") ->where($base_cond) ->order($order_by) ->select(); $merchant_list = $merchants_getter($all_mchids); if(!empty($order_list)) { $order_list = $this->orderFormat($order_list, $merchant_list); //补充订单的返销状态,按客户单号判断 $mch_orders = array_column($order_list,'mch_order'); $mch_orders = array_unique($mch_orders); $relate_con = [ 'refill_order.order_time' => $base_cond['refill_order.order_time'], 'refill_order.mch_order' => ['in', $mch_orders], 'vr_order.order_state' => ORDER_STATE_SUCCESS, 'refill_order.inner_status' => 0 ]; $relate_list = Model('')->table('refill_order,vr_order') ->join('inner') ->on('refill_order.order_id=vr_order.order_id') ->field("refill_order.order_id,refill_order.mch_order") ->where($relate_con) ->select(); $relate_order_map = []; foreach ($relate_list as $item) { $relate_order_map[$item['order_id']] = $item['mch_order']; } $order_ids = array_column($relate_list, 'order_id'); $order_ids = array_unique($order_ids); $refill_buyback_model = Model('refill_buyback'); $buybacks = $refill_buyback_model->getBuyBackList(['order_id' => ['in', $order_ids], 'manual_type' => 'buyback'], '', 'order_id'); $mch_order_buyback = []; foreach ($buybacks as $buyback) { $order_id = $buyback['order_id']; $relate_mch_order = $relate_order_map[$order_id]; if (!in_array($relate_mch_order, $mch_order_buyback)) { $mch_order_buyback[] = $relate_mch_order; } } foreach ($order_list as $key => $order) { $mch_order = $order['mch_order']; if (in_array($mch_order, $mch_order_buyback)) { $order_list[$key]['buyback'] = true; } else { $order_list[$key]['buyback'] = false; } } } Tpl::output('order_list', $order_list); Tpl::output('merchant_list', $merchant_list); Tpl::output('except_stat', $this->except_stat()); Tpl::output('show_page', $model_refill_order->showpage()); Tpl::showpage('monitor_transfer'); } private function getAllTransferMchid() { $mchid_parser = function ($mchid, $cfg) { $cfg = unserialize($cfg); if ($cfg === false) { return false; } $opened = intval($cfg['transfer_opened']); $tmchid = intval($cfg['transfer_mchid']); if ($opened == 1 && $tmchid > 0 && $tmchid != $mchid) { return $tmchid; } else { return false; } }; $mchids = []; $i = 0; while (true) { $start = $i * 1000; $items = Model()->table('merchant')->field('mchid,transfer_cfg,timeout_transfer_cfg')->order('mchid asc')->limit("{$start},1000")->select(); if (empty($items)) { return $mchids; } $i++; foreach ($items as $item) { $cfg_rt = $item['transfer_cfg']; $cfg_tm = $item['timeout_transfer_cfg']; $mchid = intval($item['mchid']); if (empty($cfg_rt) and empty($cfg_tm)) { continue; } $rt_mchid = $mchid_parser($mchid,$cfg_rt); $tm_mchid = $mchid_parser($mchid,$cfg_tm); if($rt_mchid !== false) { $mchids[] = $rt_mchid; } if($tm_mchid !== false) { $mchids[] = $tm_mchid; } } } } private function extra_stats($base_cond, $timeout_type,$cur_time): array { $stat_order = function ($cond) { $stat = Model('')->table('refill_order,vr_order')->join('inner') ->on('refill_order.order_id=vr_order.order_id') ->field('count(*) as order_count ') ->where($cond)->find(); return $stat['order_count']; }; $result = []; $start_day = strtotime("-5 days",$cur_time); $extra_conds = [ ['between', [$cur_time - 3600, $cur_time - 1800]], ['between', [$start_day, $cur_time - 3600]] ]; if (array_key_exists($timeout_type, $this->mTimeouts)) { $time_out = $this->mTimeouts[$timeout_type]; $extra_conds[] = ['_multi' => true, ['egt', $start_day], ['lt', $cur_time - $time_out]]; } foreach ($extra_conds as $stat_cond) { if (!empty($time_out)) { $base_cond['vr_order.add_time&vr_order.add_time'] = $stat_cond; $base_cond['refill_order.order_time&refill_order.order_time'] = $stat_cond; } else { $base_cond['refill_order.order_time'] = $stat_cond; $base_cond['vr_order.add_time'] = $stat_cond; } $result[] = $stat_order($base_cond); } return $result; } private function merchant_timeout_stats($cond) { unset($cond['refill_order.mchid']); unset($cond['vr_order.store_id']); $stats = Model('')->table('refill_order,vr_order,merchant') ->join('inner,inner') ->on('refill_order.order_id=vr_order.order_id,refill_order.mchid=merchant.mchid') ->field('count(*) as order_count, sum(refill_amount) as refill_amounts, merchant.mchid, merchant.company_name, merchant.name') ->where($cond) ->group('refill_order.mchid') ->order('order_count desc') ->select(); $special_stat = []; $order_stat = ['order_count' => 0, 'refill_amounts' => 0]; if(empty($stats)) return [$special_stat, $order_stat]; foreach ($stats as $stat) { $mchid = intval($stat['mchid']); $special_stat[$mchid] = [ 'mchid' => $mchid, 'order_count' => $stat['order_count'], 'refill_amounts' => $stat['refill_amounts'], 'company_name' => $stat['company_name'], 'name' => $stat['name'] ]; $order_stat['order_count'] += $stat['order_count']; $order_stat['refill_amounts'] += $stat['refill_amounts']; } return [$special_stat, $order_stat]; } private function notify_time($cur_time,$period,$total_period) { $mintime_getter = function () { $mod = Model(); $item = $mod->table('refill_detail')->field('min(order_time) as mintime')->where(['order_state'=>30])->find(); if(empty($item['mintime'])) { return time() - 3600; } else { return intval($item['mintime']); } }; $start = $mintime_getter();//strtotime("-5 days",$cur_time); // $today = strtotime(date('Y-m-d',time())); // $tomorrow = $today + 86400; $time_cond['vr_order.add_time&vr_order.add_time'] = ['_multi' => true, ['egt', $start], ['elt', $cur_time]]; $time_cond['refill_order.order_time&refill_order.order_time'] = ['_multi' => true, ['egt', $start], ['elt', $cur_time]]; $time_cond['refill_order.commit_time&refill_order.commit_time'] = ['_multi' => true, ['egt', $start], ['elt', $cur_time - $period]]; if ($total_period > 0) { $time_cond['refill_order.order_time&refill_order.order_time'] = ['_multi' => true, ['egt', $start], ['elt', $cur_time - $total_period]]; } return $time_cond; } public function monitor_notifyOp() { $model_refill_order = Model('refill_order'); $base_cond['refill_order.inner_status'] = 0; $base_cond['vr_order.order_state'] = ORDER_STATE_SEND; $card_type = $_GET['card_type']; if (!empty($_GET['store_id'])) { $base_cond['vr_order.store_id'] = $_GET['store_id']; } $cur_time = time(); $period = 180; if(!empty($_GET['time'])) { $period = intval($_GET['time']); }else{ $_GET['time'] = $period; } $total_period = 0; if (!empty($_GET['total_time'])) { $total_period = intval($_GET['total_time']); } $time_cond = $this->notify_time($cur_time, $period, $total_period); if (!empty($_GET['mchid'])) { $base_cond['refill_order.mchid'] = $_GET['mchid']; } if (!empty($card_type)) { if (in_array($card_type, ['1', '2', '4', '5', '6', '7'])) { $base_cond['refill_order.card_type'] = $card_type; } if ($card_type == 'oil') { $base_cond['refill_order.card_type'] = ['in', ['1', '2']]; } if ($card_type == 'phone') { $base_cond['refill_order.card_type'] = ['in', ['4', '5', '6']]; } } if (!empty($_GET['quality'])) { $base_cond['refill_order.quality'] = $_GET['quality']; } $orders_cond = array_merge($base_cond,$time_cond); if (!empty($_GET['order_query'])) { $this->updateOrderSend($orders_cond); return; } if (!empty($_GET['export'])) { $this->RefillOrderExport($orders_cond, '渠道回调超时导出', 'time_out_order'); return; } $mchids = Model('')->table('refill_order,vr_order') ->join('inner') ->on('refill_order.order_id=vr_order.order_id') ->field('DISTINCT refill_order.mchid') ->where($orders_cond) ->group('refill_order.mchid') ->order('mchid asc') ->select(); $mchids = array_column($mchids, 'mchid'); $merchant_list = $this->merchants(['mchid' => ['in', $mchids]]); $provider_list = $this->providers(); //耗时 $fields = "refill_order.*,vr_order.order_state,({$cur_time} - refill_order.commit_time) as ctimeout"; $order_by = "ctimeout desc"; [$special_stat, $order_stat] = $this->provider_timeout_stats($orders_cond, $provider_list); if (empty($_GET['store_id'])) { $order_count = $order_stat['order_count']; }else{ $order_count = $special_stat[$_GET['store_id']]['order_count']; } $order_list = $model_refill_order->getMerchantOrderList($orders_cond, 200, $order_count, $fields, $order_by); if(!empty($order_list)) { $order_list = $this->orderFormat($order_list, $merchant_list); } Tpl::output('stat', $order_stat); Tpl::output('special_stat', $special_stat); Tpl::output('order_list', $order_list); Tpl::output('merchant_list', $merchant_list); Tpl::output('provider_list', $provider_list); Tpl::output('except_stat', $this->except_stat()); Tpl::output('show_page', $model_refill_order->showpage()); Tpl::showpage('refill.order.monitor.notify'); } private function provider_timeout_stats($cond, $provider_list) { unset($cond['refill_order.mchid']); unset($cond['vr_order.store_id']); $stats = Model('')->table('refill_order,vr_order') ->join('inner') ->on('refill_order.order_id=vr_order.order_id') ->field('count(*) as order_count, store_id, sum(refill_amount) as refill_amounts') ->where($cond) ->group('vr_order.store_id') ->order('order_count desc') ->select(); $special_stat = []; $order_stat = ['order_count' => 0, 'refill_amounts' => 0]; if(empty($stats)) return [$special_stat, $order_stat]; foreach ($provider_list as $provider) { $providers[$provider['store_id']] = $provider; } ksort($providers); foreach ($stats as $stat) { $store_id = intval($stat['store_id']); $special_stat[$store_id] = [ 'store_id' => $store_id, 'order_count' => $stat['order_count'], 'refill_amounts' => $stat['refill_amounts'], 'store_name' => $providers[$store_id]['store_name'], 'opened' =>$providers[$store_id]['opened'] ]; $order_stat['order_count'] += $stat['order_count']; $order_stat['refill_amounts'] += $stat['refill_amounts']; } return [$special_stat, $order_stat]; } public function ajaxProviderTimeoutOp() { $base_cond['refill_order.inner_status'] = 0; $base_cond['vr_order.order_state'] = ORDER_STATE_SEND; if (!empty($card_type)) { if (in_array($card_type, ['1', '2', '4', '5', '6', '7'])) { $base_cond['refill_order.card_type'] = $card_type; } if ($card_type == 'oil') { $base_cond['refill_order.card_type'] = ['in', ['1', '2']]; } if ($card_type == 'phone') { $base_cond['refill_order.card_type'] = ['in', ['4', '5', '6']]; } } if (!empty($_GET['quality'])) { $base_cond['refill_order.quality'] = $_GET['quality']; } $cur_time = time(); $period = 180; if(!empty($_GET['time'])) { $period = intval($_GET['time']); } $total_period = 0; if (!empty($_GET['total_time'])) { $total_period = intval($_GET['total_time']); } $time_cond = $this->notify_time($cur_time, $period, $total_period); $orders_cond = array_merge($base_cond,$time_cond); $provider_list = $this->providers(); [$special_stat, $order_stat] = $this->provider_timeout_stats($orders_cond, $provider_list); echo json_encode(['special_stat' => $special_stat, 'order_stat' =>$order_stat]); } private function RefillOrderExport($cond, $method_name = '', $type='order') { $result = []; if ($type == 'order') { $result = Model('refill_order')->getAllOrders($cond); } elseif ($type == 'time_out_order') { $result = Model('refill_order')->getAllTimeOutOrders($cond); } $this->createExcel($result, $method_name); } private function createExcel($data = [], $method_name = '') { Language::read('export'); import('libraries.excel'); $excel_obj = new Excel(); $excel_data = array(); //设置样式 $excel_obj->setStyle(array('id' => 's_title', 'Font' => array('FontName' => '宋体', 'Size' => '12', 'Bold' => '1'))); //header $excel_data[0][] = array('styleid' => 's_title', 'data' => '商户号'); $excel_data[0][] = array('styleid' => 's_title', 'data' => '客户订单号'); $excel_data[0][] = array('styleid' => 's_title', 'data' => '平台单号'); $excel_data[0][] = array('styleid' => 's_title', 'data' => '面额'); $excel_data[0][] = array('styleid' => 's_title', 'data' => '充值卡号'); $excel_data[0][] = array('styleid' => 's_title', 'data' => '充值卡类型'); $excel_data[0][] = array('styleid' => 's_title', 'data' => '下单日期'); $excel_data[0][] = array('styleid' => 's_title', 'data' => '完成日期'); $excel_data[0][] = array('styleid' => 's_title', 'data' => '官方流水号'); $excel_data[0][] = array('styleid' => 's_title', 'data' => '订单状态'); //data foreach ((array)$data as $v) { $tmp = array(); $tmp[] = array('data' => $v['mchid']); $tmp[] = array('data' => $v['mch_order']); $tmp[] = array('data' => $v['order_sn']); $tmp[] = array('data' => $v['refill_amount']); $tmp[] = array('data' => $v['card_no']); $tmp[] = array('data' => $this->scard_type($v['card_type'])); $tmp[] = array('data' => date('Y-m-d H:i:s', $v['order_time'])); if (empty($v['notify_time'])) { $tmp[] = array('data' => ''); } else { $tmp[] = array('data' => date('Y-m-d H:i:s', $v['notify_time'])); } $tmp[] = array('data' => $v['official_sn']); $tmp[] = array('data' => orderState($v)); $excel_data[] = $tmp; } $excel_data = $excel_obj->charset($excel_data, CHARSET); $excel_obj->addArray($excel_data); $excel_obj->addWorksheet($excel_obj->charset(L('exp_od_order'), CHARSET)); $excel_obj->generateXML($method_name . date('Y-m-d-H', time())); } public function neterr_orderOp() { $model_refill_order = Model('refill_order'); if (!empty($_GET['store_id'])) { $condition['vr_order.store_id'] = $_GET['store_id']; } $condition['refill_order.inner_status'] = 0; $condition['refill_order.neterr'] = 1; $condition['vr_order.order_state'] = ORDER_STATE_PAY; $cur_time = time(); $start_day = strtotime("-5 days",$cur_time); $condition['vr_order.add_time&vr_order.add_time'] = ['_multi' => true, ['egt', $start_day], ['lt', $cur_time]]; $condition['refill_order.order_time&refill_order.order_time'] = ['_multi' => true, ['egt', $start_day], ['lt', $cur_time]]; if (!empty($_GET['order_query'])) { $this->updateOrderSend($condition); return; } if (!empty($_GET['export'])) { $this->RefillOrderExport($condition, '网络错误订单导出'); return; } $merchant_list = $this->merchants(); $provider_list = $this->providers(); //耗时 $fields = "refill_order.*,vr_order.order_state"; $order_by = "refill_order.commit_time asc"; [$special_stat, $order_stat] = $this->provider_timeout_stats($condition, $provider_list); $order_list = $model_refill_order->getMerchantOrderList($condition, 200, $order_stat['order_count'],$fields, $order_by); $order_list = $this->orderFormat($order_list, $merchant_list); Tpl::output('stat', $order_stat); Tpl::output('special_stat', $special_stat); Tpl::output('order_list', $order_list); Tpl::output('show_page', $model_refill_order->showpage()); Tpl::showpage('refill.order.neterr.index'); } public function neterr_order_manualOp() { $type = $_GET['type']; $official_sn = $_GET['official_sn'] ?? ''; if ($type != 'success' && $type != 'cancel') { showMessage('手动操作类型错误'); } $order_ids = $_GET['order_ids']; $model_refill_order = Model('refill_order'); $condition['refill_order.order_id'] = ['in', $order_ids]; $condition['refill_order.inner_status'] = 0; $condition['refill_order.neterr'] = 1; $condition['vr_order.order_state'] = ORDER_STATE_PAY; $order_list = $model_refill_order->getMerchantOrderList($condition); if (empty($order_list)) { showMessage('暂无数据'); } foreach ($order_list as $order) { $order_id = $order['order_id']; if ($type == 'success') { if (!empty($official_sn)) { $logic_vr_order = Logic("vr_order"); $logic_vr_order->changeOrderStateSuccess($order_id, true); $model_refill_order->edit($order_id, ['official_sn' => $official_sn,'notify_state' => 1, 'notify_time' => time()]); util::pop_queue_order($order['mchid'], $order['mch_order']); QueueClient::push("NotifyMerchantComplete", ['order_id' => $order_id, 'manual' => true]); } else { refill\util::manual_success($order_id); } } elseif ($type == 'cancel') { refill\util::manual_cancel($order_id); } } $this->log("手动强制处理", 1); showMessage('操作成功'); } public function orderFormat($order_list, $merchant_list): array { $merchants = []; foreach ($merchant_list as $value) { $merchants[$value['mchid']] = $value; } $cur_time = time(); foreach ($order_list as $order_id => $order_info) { $order_list[$order_id]['card_type_text'] = $this->scard_type($order_info['card_type']); $order_list[$order_id]['mch_name'] = $merchants[$order_info['mchid']]['company_name']; if ($order_info['notify_time'] > 0) { $total_diff_time = $order_info['notify_time'] - $order_info['order_time']; $diff_time = $order_info['notify_time'] - $order_info['commit_time']; } else { $total_diff_time = $cur_time - $order_info['order_time']; $diff_time = $cur_time - $order_info['commit_time']; } if($order_info['mtime_out'] > 0) { $order_list[$order_id]['mtime_out_text'] = $this->elapse_time($order_info['mtime_out']); } $order_list[$order_id]['diff_time'] = $diff_time; $order_list[$order_id]['diff_time_text'] = $this->elapse_time($diff_time); $order_list[$order_id]['total_diff_time'] = $total_diff_time; $order_list[$order_id]['total_diff_time_text'] = $this->elapse_time($total_diff_time); $order_list[$order_id]['quality_text'] = $this->quality_format($order_info['quality'], $order_info['card_type']); if ($total_diff_time > $merchants[$order_info['mchid']]['time_out'] && $order_info['order_state'] == ORDER_STATE_SEND) { $order_list[$order_id]['time_out_state'] = 0; if (in_array($order_info['card_type'], [mtopcard\PetroChinaCard, mtopcard\SinopecCard])) { $order_list[$order_id]['time_out_state'] = 1; } if (in_array($order_info['card_type'], [mtopcard\ChinaMobileCard, mtopcard\ChinaUnicomCard, mtopcard\ChinaTelecomCard])) { if (in_array($order_info['quality'], [ refill\Quality::SlowTwentyFour, refill\Quality::SlowSix, refill\Quality::SlowTwo, refill\Quality::SlowFortyEight, refill\Quality::SlowSeventyTwo])) { $order_list[$order_id]['time_out_state'] = 2; } elseif (in_array($order_info['mchid'], [10132])) { //重点机构 $order_list[$order_id]['time_out_state'] = 3; } else { $order_list[$order_id]['time_out_state'] = 4; } } } else { $order_list[$order_id]['time_out_state'] = 0; } } return $order_list; } public function notify_err_orderOp() { $model_refill_order = Model('refill_order'); $order_state_cancel = ORDER_STATE_CANCEL; $order_state_success = ORDER_STATE_SUCCESS; $condition['refill_order.inner_status'] = 0; $condition['refill_order.is_retrying'] = 0; $condition['vr_order.order_state'] = ['in', "{$order_state_cancel},{$order_state_success}"]; $condition['refill_order.mch_notify_state'] = ['in', "0,2"]; $condition['refill_order.mch_notify_times'] = ['gt', 0]; if (empty($_GET['time'])) { $_GET['time'] = 1; } if (empty($_GET['notify_time'])) { $_GET['notify_time'] = 180; } $cur_time = time(); $time = $_GET['time'] * 3600; $condition['refill_order.order_time'] = [['egt', ($cur_time - $time)], ['lt', $cur_time], 'and']; $condition['vr_order.add_time'] = [['egt', ($cur_time - $time)], ['lt', $cur_time], 'and']; $notify_time = $_GET['notify_time']; if($notify_time > 0) { $start_day = strtotime("-5 days",$cur_time); $condition['refill_order.notify_time'] = [['egt', $start_day], ['lt', ($cur_time - $notify_time)], 'and']; } $order_list = $model_refill_order->getMerchantOrderList($condition, 200, 1000,'refill_order.*,vr_order.order_state', '', 1000); $merchant_list = $this->merchants(); $order_list = $this->orderFormat($order_list, $merchant_list); Tpl::output('order_list', $order_list); Tpl::output('show_page', $model_refill_order->showpage()); Tpl::showpage('refill.order.notify.err.index'); } public function notifyerr_all_notifyOp() { if (empty($_GET['time']) || empty($_GET['notify_time'])) { showMessage('日期条件错误'); } $model_refill_order = Model('refill_order'); $order_state_cancel = ORDER_STATE_CANCEL; $order_state_success = ORDER_STATE_SUCCESS; $condition['refill_order.inner_status'] = 0; $condition['vr_order.order_state'] = ['in', "{$order_state_cancel},{$order_state_success}"]; $condition['refill_order.mch_notify_state'] = ['in', "0,2"]; $condition['refill_order.is_retrying'] = 0; $time = $_GET['time'] * 3600; $condition['refill_order.order_time'] = ['gt', (time() - $time)]; $notify_time = $_GET['notify_time']; $condition['refill_order.notify_time'] = ['lt', (time() - $notify_time)]; $order_list = $model_refill_order->getMerchantOrderList($condition, '', 0,'refill_order.*,vr_order.order_state', 'refill_order.notify_time asc', 1000); foreach ($order_list as $order) { QueueClient::push("NotifyMerchantComplete", ['order_id' => $order['order_id'], 'manual' => true]); } showMessage('操作成功'); } private function updateOrderSend($condition) { $condition['order_state'] = ORDER_STATE_SEND; $orders = $this->getAllTimeOutOrders($condition); if (!empty($orders)) { foreach ($orders as $order) { $order_id = $order['order_id']; QueueClient::push("QueryRefillState", ['order_id' => $order_id]); } } showMessage('操作成功'); } private function getAllTimeOutOrders($condition): array { $len = 1000; $i = 0; $orders = []; while (true) { $start = $i * $len; $items = Model('')->table('refill_order,vr_order,merchant') ->field('refill_order.*,vr_order.order_state') ->join('inner,inner') ->on('refill_order.order_id=vr_order.order_id,refill_order.mchid=merchant.mchid') ->where($condition) ->order('refill_order.order_time desc') ->limit("{$start},{$len}")->select(); $orders = array_merge($orders,$items); if (empty($items) || count($items) < $len) { break; } $i++; } return $orders; } public function order_exceptionOp() { $mod_except = Model('refill_exception'); $_GET['except_state'] = $_GET['except_state'] ?? 0; $cond = []; if (!empty($_GET['order_sns'])) { $order_sns = rtrim($_GET['order_sns'],','); $cond['refill_exception.order_sn'] = ['in', $order_sns]; } if(isset($_GET['except_type']) && $_GET['except_type'] !== '') { $_GET['except_type'] = intval($_GET['except_type']); } if(in_array($_GET['except_type'], [refill_exception_type::EUnKnown, refill_exception_type::EOfficialSN, refill_exception_type::ERefundOrder, refill_exception_type::EqualOfficialSN], true)) { $cond['except_type'] = $_GET['except_type']; } if(in_array($_GET['except_state'], ['0', '1'])) { $cond['except_state'] = $_GET['except_state']; } $start_unixtime = intval(strtotime($_GET['query_start_time'])); $end_unixtime = intval(strtotime($_GET['query_end_time'])); if ($start_unixtime > 0 && $end_unixtime > $start_unixtime) { $cond['order_time'] = [['egt', $start_unixtime], ['lt', $end_unixtime], 'and']; } elseif ($start_unixtime > 0) { $cond['order_time'] = ['egt', $start_unixtime]; } elseif ($end_unixtime > 0) { $cond['order_time'] = ['lt', $end_unixtime]; } if (!empty($_GET['export'])) { $this->exception_order_export($cond); return; } $list = $mod_except->getExceptionList($cond, 200, 0, 'refill_exception.*,refill_order.order_time,refill_order.card_no'); $merchant_list = $this->merchants(); foreach ($merchant_list as $value) { $merchants[$value['mchid']] = $value; } Tpl::output('merchant_list', $merchants); Tpl::output('list', $list); Tpl::output('except_stat', $this->except_stat()); Tpl::output('show_page', $mod_except->showpage()); Tpl::showpage('refill.order.exception'); } public function order_exception_handledOp() { $except_ids = $_GET['except_ids']; $except_ids = explode(',', $except_ids); $cond['except_id'] = ['in',$except_ids]; $cond['except_state'] = 0; $mod_except = Model('refill_exception'); $excepts = $mod_except->getExceptionList($cond); if(empty($excepts)) { showMessage('操作完成'); } $admininfo = $this->getAdminInfo(); $update['admin_id'] = $admininfo['id']; $update['admin_name'] = $admininfo['name']; $update['oper_time'] = time(); foreach ($excepts as $except) { $exc_id = $except['except_id']; $mod_except->setHandled($exc_id, $update); } showMessage('操作完成'); } private function except_stat() { $mod_except = Model('refill_exception'); $cond['except_state'] = 0; $except_stat = $mod_except->where($cond)->count(); return intval($except_stat); } public function refill_detail_monitorOp() { $mod_detail = Model('refill_detail'); $cond['order_state'] = ['neq', ORDER_STATE_HANDLED]; $merchant_list = $this->merchants(); foreach ($merchant_list as $value) { $merchants[$value['mchid']] = $value; } $list = $mod_detail->getRefillDetailList($cond, 30, 30, '*', 'order_time asc'); foreach ($list as $key => $value) { $params = json_decode($value['params'],true); $list[$key]['company_name'] = $merchants[$value['mchid']]['company_name']; $list[$key]['params'] = $params; if($value['order_state'] == ORDER_STATE_SEND) { $list[$key]['order_state_text'] = '待收货'; } elseif ($value['order_state'] == ORDER_STATE_QUEUE) { $list[$key]['order_state_text'] = '队列中'; } elseif ($value['order_state'] == ORDER_STATE_HANDLED) { $list[$key]['order_state_text'] = '已处理'; } else { $list[$key]['order_state_text'] = '/'; } } Tpl::output('list', $list); Tpl::output('show_page', $mod_detail->showpage()); Tpl::showpage('refill.detail.monitor'); } public function query_errOp() { $mod = Model('refill_query_err'); $condition = []; $_GET['query_start_time'] = $_GET['query_start_time'] ?? date("Y-m-d 00:00:00"); if(!empty($_GET['mchid'])) { $condition['mchid'] = $_GET['mchid']; } if (!empty($_GET['mch_orders'])) { $mch_orders = rtrim($_GET['mch_orders'],','); $condition['mch_order'] = ['in', $mch_orders]; } $start_unixtime = intval(strtotime($_GET['query_start_time'])); $end_unixtime = intval(strtotime($_GET['query_end_time'])); if ($start_unixtime > 0 && $end_unixtime > $start_unixtime) { $condition['query_time'] = [['egt', $start_unixtime], ['lt', $end_unixtime], 'and']; } elseif ($start_unixtime > 0) { $condition['query_time'] = ['egt', $start_unixtime]; } elseif ($end_unixtime > 0) { $condition['query_time'] = ['lt', $end_unixtime]; } else { $start = strtotime(date('Y-m-d', time())); $condition['query_time'] = ['egt', $start]; } if (!empty($_GET['export'])) { $this->RefillQueryAsyncExport($condition, 'refill_query_err_export'); return; } $merchants = []; $merchant_list = $this->merchants(); foreach ($merchant_list as $value) { $merchants[$value['mchid']] = $value; } $list = $mod->getRefillQueryErrList($condition, 200, 1000); Tpl::output('merchant_list', $merchant_list); Tpl::output('merchants', $merchants); Tpl::output('list', $list); Tpl::output('show_page', $mod->showpage()); Tpl::showpage('refill.query.err'); } private function exception_order_export($cond) { $data = Model('refill_exception')->getAllExceptionOrders($cond); $merchants = []; $merchant_list = $this->merchants(); foreach ($merchant_list as $value) { $merchants[$value['mchid']] = $value; } Language::read('export'); import('libraries.excel'); $excel_obj = new Excel(); $excel_data = array(); //设置样式 $excel_obj->setStyle(array('id' => 's_title', 'Font' => array('FontName' => '宋体', 'Size' => '12', 'Bold' => '1'))); //header $excel_data[0][] = array('styleid' => 's_title', 'data' => '机构编号'); $excel_data[0][] = array('styleid' => 's_title', 'data' => '机构名称'); $excel_data[0][] = array('styleid' => 's_title', 'data' => '通道名称'); $excel_data[0][] = array('styleid' => 's_title', 'data' => '订单号'); $excel_data[0][] = array('styleid' => 's_title', 'data' => '异常事件'); $excel_data[0][] = array('styleid' => 's_title', 'data' => '异常信息'); $excel_data[0][] = array('styleid' => 's_title', 'data' => '异常记录日期'); $excel_data[0][] = array('styleid' => 's_title', 'data' => '异常状态'); $excel_data[0][] = array('styleid' => 's_title', 'data' => '处理人'); //data foreach ((array)$data as $v) { $tmp = array(); $tmp[] = array('data' => $v['mchid']); $tmp[] = array('data' => $merchants[$v['mchid']]['company_name']); $tmp[] = array('data' => $v['store_name']); $tmp[] = array('data' => $v['order_sn']); $tmp[] = array('data' => $v['title']); $tmp[] = array('data' => $v['except_desc']); $tmp[] = array('data' => date('Y-m-d H:i:s', $v['add_time'])); if (empty($v['except_state'])) { $tmp[] = array('data' => '未处理'); } else { $tmp[] = array('data' => '已处理'); } $tmp[] = array('data' => $v['admin_name']); $excel_data[] = $tmp; } $excel_data = $excel_obj->charset($excel_data, CHARSET); $excel_obj->addArray($excel_data); $excel_obj->addWorksheet($excel_obj->charset(L('exp_od_order'), CHARSET)); $excel_obj->generateXML('异常订单导出-' . date('Y-m-d-H', time())); } private function RefillQueryAsyncExport($condition, $type) { if (empty($condition)) { showMessage('请选择导出条件后重新操作', '', '', 'error'); } $title = $_GET['task_title'] ?? ''; $manager = new task\manager(); $task = $manager->add_task($type, $condition, 1, -1, $title); if ($task->completed() && $task->success()) { $file_name = $task->result(); $file_path = UPLOAD_SITE_URL . '/' . ATTACH_TASK . DS . $file_name; header("Content-Disposition: attachment; filename={$file_name}"); readfile($file_path); } else { $task_id = $task->task_id(); showMessage("录入成功,任务ID:{$task_id},请稍后以相同条件再次导出,或在任务列表直接下载。","index.php?act=task&op=index&task_id={$task_id}"); } } private function monitor_transfer_export($cond, &$merchants_getter, $all_mchids) { $order_list = Model('refill_order')->getAllMonitorTransferOrders($cond); $merchant_list = $merchants_getter($all_mchids); if(!empty($order_list)) { $order_list = $this->orderFormat($order_list, $merchant_list); } Language::read('export'); import('libraries.excel'); $excel_obj = new Excel(); $excel_data = array(); //设置样式 $excel_obj->setStyle(array('id' => 's_title', 'Font' => array('FontName' => '宋体', 'Size' => '12', 'Bold' => '1'))); //header $excel_data[0][] = array('styleid' => 's_title', 'data' => '机构编号'); $excel_data[0][] = array('styleid' => 's_title', 'data' => '机构名称'); $excel_data[0][] = array('styleid' => 's_title', 'data' => '订单号'); $excel_data[0][] = array('styleid' => 's_title', 'data' => '充值卡号'); $excel_data[0][] = array('styleid' => 's_title', 'data' => '充值卡类型'); $excel_data[0][] = array('styleid' => 's_title', 'data' => '充值额度'); $excel_data[0][] = array('styleid' => 's_title', 'data' => '下单日期'); $excel_data[0][] = array('styleid' => 's_title', 'data' => '超时'); $excel_data[0][] = array('styleid' => 's_title', 'data' => '当前耗时'); $excel_data[0][] = array('styleid' => 's_title', 'data' => '总耗时'); $excel_data[0][] = array('styleid' => 's_title', 'data' => '订单状态'); $excel_data[0][] = array('styleid' => 's_title', 'data' => '通道质量'); $excel_data[0][] = array('styleid' => 's_title', 'data' => '失败原因'); $excel_data[0][] = array('styleid' => 's_title', 'data' => '商家单号'); $excel_data[0][] = array('styleid' => 's_title', 'data' => '扣款金额'); $excel_data[0][] = array('styleid' => 's_title', 'data' => '渠道单号'); $excel_data[0][] = array('styleid' => 's_title', 'data' => '渠道名称'); //data foreach ($order_list as $order) { $tmp = array(); $tmp[] = array('data' => $order['mchid']); $tmp[] = array('data' => $order['mch_name']); $tmp[] = array('data' => $order['order_sn']); $tmp[] = array('data' => $order['card_no']); $tmp[] = array('data' => $order['card_type_text']); $tmp[] = array('data' => $order['refill_amount']); $tmp[] = array('data' => date('Y-m-d H:i:s', $order['order_time'])); $tmp[] = array('data' => $order['mtime_out_text']); $tmp[] = array('data' => $order['diff_time_text']); $tmp[] = array('data' => $order['total_diff_time_text']); $tmp[] = array('data' => orderState($order)); $tmp[] = array('data' => $order['quality_text']); $tmp[] = array('data' => $order['err_msg']); $tmp[] = array('data' => $order['mch_order']); $tmp[] = array('data' => $order['mch_amount']); $tmp[] = array('data' => $order['ch_trade_no']); $tmp[] = array('data' => $order['channel_name']); $excel_data[] = $tmp; } $excel_data = $excel_obj->charset($excel_data, CHARSET); $excel_obj->addArray($excel_data); $excel_obj->addWorksheet($excel_obj->charset(L('exp_od_order'), CHARSET)); $excel_obj->generateXML('补单导出-' . date('Y-m-d-H', time())); } }