123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349 |
- <?php
- require_once(BASE_HELPER_PATH . '/refill/RefillFactory.php');
- require_once(BASE_HELPER_PATH . '/refill/util.php');
- use refill\util;
- class ordersendlistControl extends SystemControl
- {
- public function __construct()
- {
- parent::__construct();
- }
- public function indexOp()
- {
- $model_refill_order = Model('refill_order');
- $condition['refill_order.inner_status'] = 0;
- $condition['vr_order.order_state'] = ORDER_STATE_SEND;
- // if(empty($_GET['quality'])) {
- // //默认普充
- // $_GET['quality'] = 2;
- // }
- //提前20s
- $time = time() + 20;
- $condition['refill_order.order_time'] = ['exp', "refill_order.order_time < ({$time} - merchant.time_out)"];
- // $condition['refill_order.order_time'] = ['lt',time()-300];
- if (!empty($_GET['mchid'])) {
- $condition['refill_order.mchid'] = $_GET['mchid'];
- }
- if (!empty($_GET['store_id'])) {
- $condition['vr_order.store_id'] = $_GET['store_id'];
- }
- $time_cond = [
- ['between', [(time() - 3600), (time() - 1800)]],
- ['lt', (time() - 3600)]];
- if ($_GET['time'] == 1) {
- $condition['refill_order.order_time'] = ['between', [(time() - 3600), (time() - 1800)]];
- }
- if ($_GET['time'] == 2) {
- $condition['refill_order.order_time'] = ['lt', (time() - 3600)];
- }
- $time_out_order = function ($time_out, $condition) {
- $mchids = Model('')->table('merchant')->where(['time_out' => ['elt', $time_out]])->field('mchid')->select();
- $mchids = array_column($mchids, 'mchid');
- $mchids = implode(',', $mchids);
- $condition['refill_order.order_time'] = ['lt', (time() - $time_out)];
- $condition['refill_order.mchid'] = ['in', $mchids];
- return $condition;
- };
- if ($_GET['time'] == 3) {
- $condition = $time_out_order(180, $condition);
- $time_cond[] = ['lt', (time() - 180)];
- $_GET['card_type'] = 'phone';
- }
- if ($_GET['time'] == 4) {
- $condition = $time_out_order(300, $condition);
- $time_cond[] = ['lt', (time() - 300)];
- $_GET['card_type'] = 'phone';
- }
- if ($_GET['time'] == 5) {
- $condition = $time_out_order(600, $condition);
- $time_cond[] = ['lt', (time() - 600)];
- $_GET['card_type'] = 'phone';
- }
- if ($_GET['time'] == 6) {
- $condition = $time_out_order(900, $condition);
- $time_cond[] = ['lt', (time() - 900)];
- $_GET['card_type'] = 'phone';
- }
- if ($_GET['time'] == 7) {
- $condition = $time_out_order(7200, $condition);
- $time_cond[] = ['lt', (time() - 7200)];
- $_GET['card_type'] = 'phone';
- }
- if (!empty($_GET['card_type'])) {
- if (in_array($_GET['card_type'], ['1', '2', '4', '5', '6', '7'])) {
- $condition['refill_order.card_type'] = $_GET['card_type'];
- }
- if ($_GET['card_type'] == 'oil') {
- $condition['refill_order.card_type'] = ['in', ['1', '2']];
- }
- if ($_GET['card_type'] == 'phone') {
- $condition['refill_order.card_type'] = ['in', ['4', '5', '6']];
- }
- }
- if (!empty($_GET['quality'])) {
- $condition['refill_order.quality'] = $_GET['quality'];
- }
- if (!empty($_GET['order_query'])) {
- $this->updateOrderSend($condition);
- exit;
- }
- $order_list = $model_refill_order->getMerchantTimeOut($condition, 200, 'refill_order.*,vr_order.order_state', 'refill_order.quality asc,refill_order.order_time asc');
- // $order_list = $model_refill_order->getMerchantOrderList($condition, 50, 'refill_order.*,vr_order.order_state', 'refill_order.order_time asc');
- $stat = 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, sum(channel_amount) as channel_amounts, sum(mch_amount) as mch_amounts')
- ->where($condition)->find();
- // $stat = Model('')->table('refill_order,vr_order')->join('inner')
- // ->on('refill_order.order_id=vr_order.order_id')
- // ->field('count(*) as order_count ,sum(refill_amount) as refill_amounts, sum(channel_amount) as channel_amounts, sum(mch_amount) as mch_amounts')
- // ->where($condition)->find();
- $count = $this->refill_stats($condition, $time_cond);
- $merchant_list = $this->merchants();
- if(!empty($order_list)) {
- $order_list = $this->orderFormat($order_list, $merchant_list);
- }
- $provider_list = $this->providers();
- Tpl::output('stat', $stat);
- Tpl::output('count', $count);
- 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 refill_stats($condition, $times): array
- {
- $stat_order = function ($condition) {
- $stat = Model('')->table('refill_order,vr_order')->join('inner')
- ->on('refill_order.order_id=vr_order.order_id')
- ->field('count(*) as order_count ')
- ->where($condition)->find();
- return $stat['order_count'];
- };
- $result = [];
- $condition['order_state'] = ORDER_STATE_SEND;
- foreach ($times as $time) {
- $condition['refill_order.order_time'] = $time;
- $result[] = $stat_order($condition);
- }
- return $result;
- }
- 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;
- $order_list = $model_refill_order->getMerchantOrderList($condition, 50, 'refill_order.*,vr_order.order_state', 'refill_order.order_time asc');
- $merchant_list = Model('')->table('merchant')->limit(1000)->order('name asc')->select();
- $order_list = $this->orderFormat($order_list, $merchant_list);
- $provider_list = $this->providers();
- Tpl::output('provider_list', $provider_list);
- 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;
- }
- 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) {
- $diff_time = $order_info['notify_time'] - $order_info['order_time'];
- } else {
- $diff_time = time() - $order_info['order_time'];
- }
- $order_list[$order_id]['diff_time'] = $diff_time;
- $order_list[$order_id]['diff_time_text'] = $this->elapse_time($diff_time);
- $order_list[$order_id]['quality_text'] = $this->quality_format($order_info['quality'], $order_info['card_type']);
- if ($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;
- }
- $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, '', 'refill_order.*,vr_order.order_state', 'refill_order.notify_time asc', 1000);
- $merchant_list = Model('')->table('merchant')->limit(1000)->order('name asc')->select();
- $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, '', '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;
- }
- }
|