1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258 |
- <?php
- require_once(BASE_HELPER_PATH . '/refill/util.php');
- require_once(BASE_HELPER_PATH . '/task/task_helper.php');
- use refill\util;
- class ordersendlistControl extends SystemControl
- {
- private $mTimeouts;
- public function __construct()
- {
- $this->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;
- $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];
- }
- //根据客户单号来识别订单是否返销
- $mod_buyback = Model('refill_buyback');
- $buyback_cond['refill_buyback.order_time'] = $base_cond['refill_order.order_time'];
- $buyback_cond['refill_order.order_time'] = $base_cond['refill_order.order_time'];
- $buyback_cond['vr_order.order_state'] = ORDER_STATE_SUCCESS;
- $buyback_list = $mod_buyback->getAllBuybackOrder($buyback_cond, 'distinct refill_order.mch_order');
- $buyback_mch_orders = array_column($buyback_list, 'mch_order');
- $order_state = $_GET['order_state'];
- if ($order_state === '-2' && !empty($buyback_mch_orders))
- {
- $base_cond['refill_order.mch_order'] = ['in', $buyback_mch_orders];
- }
- else if (in_array($_GET['order_state'], ['30', '40']))
- {
- $base_cond['vr_order.order_state'] = intval($_GET['order_state']);
- }
- else if ($_GET['order_state'] === '0')
- {
- $base_cond['vr_order.order_state'] = intval($_GET['order_state']);
- if (!empty($buyback_mch_orders)) {
- $base_cond['refill_order.mch_order'] = ['not in', $buyback_mch_orders];
- }
- }
- else if (empty($order_state))
- { //没选择订单状态,默认只显示充值中和已取消(未返销)
- $base_cond['vr_order.order_state'] = ['in', [ORDER_STATE_CANCEL, ORDER_STATE_SEND]];
- if (!empty($buyback_mch_orders)) {
- $base_cond['refill_order.mch_order'] = ['not in', $buyback_mch_orders];
- }
- }
- if (!empty($_GET['export'])) {
- $this->monitor_transfer_export($base_cond, $merchants_getter, $all_mchids);
- return;
- }
- if ($order_state === '-2' && empty($buyback_mch_orders))
- { //仅查询返销,不存在返销数据
- $order_list = [];
- }
- else
- {
- // $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();
- $order_list = $model_refill_order->getOrderMonitorTransfer($base_cond, 200, 5000,
- "refill_order.*,vr_order.order_state,({$cur_time} - refill_order.order_time - merchant.time_out) as mtime_out");
- $merchant_list = $merchants_getter($all_mchids);
- if(!empty($order_list))
- {
- $order_list = $this->orderFormat($order_list, $merchant_list);
- foreach ($order_list as $key => $item)
- {
- if (in_array($item['mch_order'], $buyback_mch_orders)) {
- $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()));
- }
- }
|