123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200 |
- <?php
- require_once(BASE_HELPER_PATH . '/refill/util.php');
- use refill\util;
- class refill_order_manualControl extends SystemControl
- {
- public function __construct()
- {
- parent::__construct();
- }
- public function indexOp()
- {
- $model_refill_order = Model('refill_order');
- $condition['inner_status'] = 0;
- $order_list = [];
- if (!empty($_GET['order_sn'])) {
- $condition['refill_order.order_sn'] = $_GET['order_sn'];
- $merchants = [];
- $merchant_list = Model('')->table('merchant')->limit(1000)->select();
- foreach ($merchant_list as $key => $value) {
- $merchants[$value['mchid']] = $value;
- }
- $order_list = $model_refill_order->getMerchantOrderList($condition, 50, 'refill_order.*,vr_order.order_state', 'refill_order.order_time desc','',true);
- 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_text'] = $this->elapse_time($diff_time);
- $order_list[$order_id]['diff_time'] = $diff_time;
- $order_list[$order_id]['quality_text'] = $this->quality_format($order_info['quality'],$order_info['card_type']);
- $order_list[$order_id]['org_quality_text'] = $this->quality_format($order_info['org_quality'],$order_info['card_type']);
- }
- }
- Tpl::output('order_list', $order_list);
- Tpl::showpage('refill.order.manual.index');
- }
- public function notify_manual_merchantOp()
- {
- $order_id = $_GET['order_id'];
- $type = $_GET['type'];
- $mod_order = Model('vr_order');
- $order_info = $mod_order->getOrderInfo(['order_id' => $order_id]);
- $mod_refill = Model('refill_order');
- $logic_vr_order = Logic("vr_order");
- $refill_info = Model('refill_order')->getOrderInfo(['order_id' => $order_id,'inner_status' => 0,'is_retrying' => 0]);
- if(empty($refill_info)) {
- showMessage('订单不存在,或不符合条件', '');
- }
- $check_fetch_order = $this->check_fetch_order($order_info['order_sn']);
- if($check_fetch_order == false) {
- showMessage('此订单不可手动操作,请联系抢单人员操作!');
- }
- if ($type == 'success') {
- $logic_vr_order->changeOrderStateSuccess($order_id,true);
- } elseif ($type == 'cancel') {
- $logic_vr_order->changeOrderStateCancel($order_info, '', "充值失败", true, true);
- } else {
- showMessage('手动操作类型错误', 'index.php?act=refill_order&op=index');
- }
- if($refill_info['notify_time'] == 0) {
- $mod_refill->edit($order_id, ['notify_state' =>1, 'notify_time' => time()]);
- }
- util::pop_queue_order($refill_info['mchid'],$refill_info['mch_order']);
- QueueClient::push("NotifyMerchantComplete", ['order_id' => $order_id, 'manual' => true]);
- showMessage('操作成功');
- }
- public function refill_order_batchOp()
- {
- if (chksubmit()) {
- $model_refill_order = Model('refill_order');
- $condition = [];
- $type = $_POST['type'];
- $order_sn = $_POST['order_sn'];
- $order_sn = str_replace(["\r\n", "\r", "\n"], ",", $order_sn);
- $condition['refill_order.order_sn'] = ['in', $order_sn];
- $condition['refill_order.is_retrying'] = 0;
- if($type != 'notify') {
- $condition['vr_order.order_state'] = ORDER_STATE_SEND;
- }
- $order_list = $model_refill_order->getMerchantOrderList($condition,'','refill_order.*,vr_order.order_state','refill_order.order_id desc',2000);
- if($type == 'success') {
- foreach ($order_list as $order) {
- $check_fetch_order = $this->check_fetch_order($order['order_sn']);
- if($check_fetch_order == false) continue;
- refill\util::manual_success($order['order_id']);
- }
- } elseif ($type == 'cancel') {
- foreach ($order_list as $order) {
- $check_fetch_order = $this->check_fetch_order($order['order_sn']);
- if($check_fetch_order == false) continue;
- refill\util::manual_cancel($order['order_id']);
- }
- } elseif ($type == 'notify'){
- foreach ($order_list as $order) {
- if ($order['order_state'] == ORDER_STATE_SEND) {
- QueueClient::push("QueryRefillState", ['order_id' => $order['order_id']]);
- } else {
- QueueClient::push("NotifyMerchantComplete", ['order_id' => $order['order_id'], 'manual' => true]);
- }
- }
- } else {
- showMessage('手动操作类型错误');
- }
- showMessage('操作成功');
- } else {
- Tpl::showpage('refill.order.batch');
- }
- }
- public function set_cancel_orderOp()
- {
- $mod = Model('refill_order');
- $condition = [];
- $order_list = [];
- $mch_orderData = [];
- 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];
- }
- $merchants = [];
- $merchant_list = $this->merchants();
- foreach ($merchant_list as $value) {
- $merchants[$value['mchid']] = $value;
- }
- if(!empty($condition)) {
- $condition['inner_status'] = 0;
- $order_list = $mod->getMerchantOrderList($condition, 200, 'refill_order.*,vr_order.order_state', 'refill_order.order_time desc');
- $mch_orderData = explode(',',$mch_orders);
- foreach ($order_list as $order_id => $order) {
- $mch_order = $order['mch_order'];
- if(in_array($mch_order, $mch_orderData)) {
- $key = array_search($mch_order, $mch_orderData);
- unset($mch_orderData[$key]);
- }
- $order_list[$order_id]['card_type_text'] = $this->scard_type($order['card_type']);
- $order_list[$order_id]['company_name'] = $merchants[$order['mchid']]['company_name'];
- if ($order['notify_time'] > 0) {
- $diff_time = $order['notify_time'] - $order['order_time'];
- } else {
- $diff_time = time() - $order['order_time'];
- }
- $order_list[$order_id]['diff_time_text'] = $this->elapse_time($diff_time);
- $order_list[$order_id]['diff_time'] = $diff_time;
- $order_list[$order_id]['can_cancel'] = $this->can_cancel_order($order);
- }
- }
- Tpl::output('noexist_mch_order', $mch_orderData);
- Tpl::output('merchant_list', $merchants);
- Tpl::output('list', $order_list);
- Tpl::output('show_page', $mod->showpage());
- Tpl::showpage('set.cancel.order');
- }
- public function order_cancel_disposeOp()
- {
- $order_id = $_GET['order_id'];
- $condition['refill_order.order_id'] = ['in',$order_id];
- $order_list = Model('refill_order')->getMerchantOrderList($condition,1000,'refill_order.*,vr_order.order_state');
- foreach ($order_list as $order) {
- if($this->can_cancel_order($order)) {
- $mchid = $order['mchid'];
- $mch_order = $order['mch_order'];
- refill\util::set_cancel_order($mchid,$mch_order);
- }
- }
- showMessage('操作成功');
- }
- private function can_cancel_order($order): bool
- {
- if($order['order_state'] == ORDER_STATE_SUCCESS) {
- return false;
- }
- if($order['order_state'] == ORDER_STATE_CANCEL && $order['is_retrying'] == 0) {
- return false;
- }
- return true;
- }
- }
|