123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723 |
- <?php
- require_once(BASE_HELPER_PATH . '/refill/util.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)
- {
- $mintime_getter = function () {
- $mod = Model();
- $item = $mod->table('refill_detail')->field('min(order_time) as mintime')->where(['order_time' => ['egt',time()-1 * 86400],'order_state'=>30])->find();
- if(empty($item)) {
- 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]))
- {
- 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', [$start_day, $cur_time - 3600]];
- $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
- {
- $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'];
- 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);
- 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['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('show_page', $model_refill_order->showpage());
- Tpl::showpage('refill.order.send.index');
- }
- 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)
- {
- $mintime_getter = function () {
- $mod = Model();
- $item = $mod->table('refill_detail')->field('min(order_time) as mintime')->where(['order_time' => ['egt',time()-1 * 86400],'order_state'=>30])->find();
- if(empty($item)) {
- 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]];
- 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;
- }
- $time_cond = $this->notify_time($cur_time,$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('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']);
- }
- $time_cond = $this->notify_time($cur_time,$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' => '订单状态');
- $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));
- $tmp[] = array('data' => $v['mch_amount']);
- $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('暂无数据');
- }
- $logic_vr_order = Logic("vr_order");
- $mod_vr_order = Model('vr_order');
- foreach ($order_list as $order) {
- $order_id = $order['order_id'];
- if ($type == 'success') {
- $logic_vr_order->changeOrderStateSuccess($order_id, true);
- if (!empty($official_sn)) {
- $model_refill_order->edit($order_id, ['official_sn' => $official_sn]);
- }
- } elseif ($type == 'cancel') {
- $order_info = $mod_vr_order->getOrderInfo(['order_id' => $order_id]);
- $logic_vr_order->changeOrderStateCancel($order_info, '', "充值失败", true, true);
- } else {
- continue;
- }
- if ($order['notify_time'] == 0) {
- $model_refill_order->edit($order_id, ['notify_state' => 1, 'notify_time' => time()]);
- }
- util::pop_queue_order($order['mchid'], $order['mch_order']);
- QueueClient::push("NotifyMerchantComplete", ['order_id' => $order_id, 'manual' => true]);
- }
- 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;
- }
- }
|