refill_order_manual.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. <?php
  2. require_once(BASE_HELPER_PATH . '/refill/util.php');
  3. require_once(BASE_HELPER_PATH . '/algorithm.php');
  4. use refill\util;
  5. class refill_order_manualControl extends SystemControl
  6. {
  7. public function __construct()
  8. {
  9. parent::__construct();
  10. }
  11. public function indexOp()
  12. {
  13. $model_refill_order = Model('refill_order');
  14. $condition['inner_status'] = 0;
  15. $order_list = [];
  16. if (!empty($_GET['order_sn'])) {
  17. $condition['refill_order.order_sn'] = $_GET['order_sn'];
  18. $merchant_list = $this->merchants();
  19. $order_list = $model_refill_order->getMerchantOrderList($condition, 50, 'refill_order.*,vr_order.order_state', 'refill_order.order_time desc','',true);
  20. $order_list = $this->OrderDataFormat($order_list, $merchant_list);
  21. }
  22. Tpl::output('order_list', $order_list);
  23. Tpl::showpage('refill.order.manual.index');
  24. }
  25. public function notify_manual_merchantOp()
  26. {
  27. $order_id = $_GET['order_id'];
  28. $type = $_GET['type'];
  29. $mod_order = Model('vr_order');
  30. $order_info = $mod_order->getOrderInfo(['order_id' => $order_id]);
  31. $mod_refill = Model('refill_order');
  32. $logic_vr_order = Logic("vr_order");
  33. $refill_info = Model('refill_order')->getOrderInfo(['order_id' => $order_id,'inner_status' => 0,'is_retrying' => 0]);
  34. if(empty($refill_info)) {
  35. showMessage('订单不存在,或不符合条件', '');
  36. }
  37. $check_fetch_order = $this->check_fetch_order($order_info['order_sn']);
  38. if($check_fetch_order == false) {
  39. showMessage('此订单不可手动操作,请联系抢单人员操作!');
  40. }
  41. if ($type == 'success') {
  42. $logic_vr_order->changeOrderStateSuccess($order_id,true);
  43. } elseif ($type == 'cancel') {
  44. $logic_vr_order->changeOrderStateCancel($order_info, '', "充值失败", true, true);
  45. } else {
  46. showMessage('手动操作类型错误', 'index.php?act=refill_order&op=index');
  47. }
  48. if($refill_info['notify_time'] == 0) {
  49. $mod_refill->edit($order_id, ['notify_state' =>1, 'notify_time' => time()]);
  50. }
  51. util::pop_queue_order($refill_info['mchid'],$refill_info['mch_order']);
  52. QueueClient::push("NotifyMerchantComplete", ['order_id' => $order_id, 'manual' => true]);
  53. showMessage('操作成功');
  54. }
  55. public function refill_order_batchOp()
  56. {
  57. $model_refill_order = Model('refill_order');
  58. $condition = [];
  59. $order_list = [];
  60. $_GET['query_start_time'] = $_GET['query_start_time'] ?? date("Y-m-d 00:00:00");
  61. if (in_array($_GET['order_state'], ['0', '10', '20', '30', '40']))
  62. {
  63. $condition['vr_order.order_state'] = $_GET['order_state'];
  64. }
  65. if (!empty($_GET['mchid'])) {
  66. $condition['refill_order.mchid'] = $_GET['mchid'];
  67. }
  68. if (!empty($_GET['store_id'])) {
  69. $condition['vr_order.store_id'] = $_GET['store_id'];
  70. }
  71. //批量查询,二者都有,以卡号为主
  72. if(!empty($_GET['card_nos'])) {
  73. $card_nos = trim($_GET['card_nos'], ',');
  74. $condition['refill_order.card_no'] = ['in', $card_nos];
  75. } elseif (!empty($_GET['mch_orders'])) {
  76. $mch_orders = rtrim($_GET['mch_orders'], ',');
  77. $condition['refill_order.mch_order'] = ['in', $mch_orders];
  78. }
  79. if(!empty($_GET['order_sns'])) {
  80. $order_sns = trim($_GET['order_sns'], ',');
  81. $condition['refill_order.order_sn'] = ['in', $order_sns];
  82. }
  83. if (!empty($_GET['card_type'])) {
  84. if (in_array($_GET['card_type'], ['1', '2', '4', '5', '6', '7'])) {
  85. $condition['refill_order.card_type'] = intval($_GET['card_type']);
  86. }
  87. }
  88. $merchant_list = $this->merchants();
  89. $provider_list = $this->providers();
  90. if(!empty($condition)) {
  91. $condition['refill_order.inner_status'] = 0;
  92. $start_unixtime = intval(strtotime($_GET['query_start_time']));
  93. $end_unixtime = intval(strtotime($_GET['query_end_time']));
  94. if ($start_unixtime > 0 && $end_unixtime > $start_unixtime) {
  95. $condition['refill_order.order_time'] = [['egt', $start_unixtime], ['lt', $end_unixtime], 'and'];
  96. $condition['vr_order.add_time'] = [['egt', $start_unixtime],['lt', $end_unixtime], 'and'];
  97. } elseif ($start_unixtime > 0) {
  98. $condition['refill_order.order_time'] = ['egt', $start_unixtime];
  99. $condition['vr_order.add_time'] = ['egt', $start_unixtime];
  100. } elseif ($end_unixtime > 0) {
  101. $condition['refill_order.order_time'] = ['lt', $end_unixtime];
  102. } else {
  103. $start = strtotime(date('Y-m-d', time()));
  104. $condition['refill_order.order_time'] = ['egt', $start];
  105. $condition['vr_order.add_time'] = ['egt', $start];
  106. }
  107. $order_list = $model_refill_order->getMerchantOrderList($condition, 400, 'refill_order.*,vr_order.order_state', 'refill_order.channel_name DESC ');
  108. $order_list = $this->OrderDataFormat($order_list, $merchant_list);
  109. }
  110. Tpl::output('merchant_list', $merchant_list);
  111. Tpl::output('provider_list', $provider_list);
  112. Tpl::output('order_list', $order_list);
  113. Tpl::output('show_page', $model_refill_order->showpage());
  114. Tpl::showpage('refill.order.batch');
  115. }
  116. public function refill_order_batch_disposeOp()
  117. {
  118. $int_array = function ($sids) {
  119. $result = [];
  120. foreach ($sids as $sid) {
  121. $result[] = intval($sid);
  122. }
  123. return $result;
  124. };
  125. $unique_array = function ($ids)
  126. {
  127. $ids = array_unique($ids);
  128. sort($ids);
  129. return $ids;
  130. };
  131. $oid_reader = function ($sids) use ($int_array,$unique_array) {
  132. $sids = explode(',',$sids);
  133. $ids = $int_array($sids);
  134. $result = $unique_array($ids);
  135. return $result;
  136. };
  137. $oper_type = $_GET['type'];
  138. $order_ids = $oid_reader($_GET['order_id']);
  139. $cond = [];
  140. $cond['refill_order.order_id'] = ['in',$order_ids];
  141. $cond['refill_order.is_retrying'] = 0;
  142. if ($oper_type == 'success' || $oper_type == 'cancel') {
  143. $cond['vr_order.order_state'] = ORDER_STATE_SEND;
  144. } elseif ($oper_type == 'buyback') {
  145. $cond['vr_order.order_state'] = ORDER_STATE_SUCCESS;
  146. }
  147. $model_refill_order = Model('refill_order');
  148. $orders = $model_refill_order->getMerchantOrderList($cond,'','refill_order.*,vr_order.order_state','refill_order.order_id desc',2000);
  149. if($oper_type == 'success')
  150. {
  151. foreach ($orders as $order) {
  152. $check_fetch_order = $this->check_fetch_order($order['order_sn']);
  153. if($check_fetch_order == false) continue;
  154. refill\util::manual_success($order['order_id']);
  155. }
  156. }
  157. elseif ($oper_type == 'cancel')
  158. {
  159. foreach ($orders as $order) {
  160. $check_fetch_order = $this->check_fetch_order($order['order_sn']);
  161. if($check_fetch_order == false) continue;
  162. refill\util::manual_cancel($order['order_id']);
  163. }
  164. }
  165. elseif ($oper_type == 'notify')
  166. {
  167. foreach ($orders as $order) {
  168. if ($order['order_state'] == ORDER_STATE_SEND) {
  169. QueueClient::push("QueryRefillState", ['order_id' => $order['order_id']]);
  170. } else {
  171. QueueClient::push("NotifyMerchantComplete", ['order_id' => $order['order_id'], 'manual' => true]);
  172. }
  173. }
  174. }
  175. elseif ($oper_type == 'buyback')
  176. {
  177. $refill_buyback_model = Model('refill_buyback');
  178. $buybacks = $refill_buyback_model->getList(['order_id' => ['in',$order_ids]]);
  179. $buyback_ids = array_column($buybacks, 'order_id');
  180. $buyback_ids = $int_array($buyback_ids);
  181. $buyback_ids = $unique_array($buyback_ids);
  182. foreach ($orders as $order)
  183. {
  184. $order_id = intval($order['order_id']);
  185. if(!algorithm::binary_search($buyback_ids,$order_id)) {
  186. $ins[] = ['order_id' => $order['order_id'], 'order_sn' => $order['order_sn'],'order_time' => $order['order_time'], 'notify_time' => $order['notify_time']];
  187. }
  188. }
  189. if(!empty($ins)) {
  190. $refill_buyback_model->insertAll($ins);
  191. }
  192. }
  193. else {
  194. showMessage('手动操作类型错误');
  195. }
  196. showMessage('操作成功');
  197. }
  198. public function set_cancel_orderOp()
  199. {
  200. $mod = Model('refill_order');
  201. $condition = [];
  202. $order_list = [];
  203. $mch_orderData = [];
  204. if(!empty($_GET['mchid'])) {
  205. $condition['mchid'] = $_GET['mchid'];
  206. }
  207. if (!empty($_GET['mch_orders'])) {
  208. $mch_orders = rtrim($_GET['mch_orders'],',');
  209. $condition['mch_order'] = ['in', $mch_orders];
  210. }
  211. $merchant_list = $this->merchants();
  212. if(!empty($condition)) {
  213. $condition['inner_status'] = 0;
  214. $order_list = $mod->getMerchantOrderList($condition, 200, 'refill_order.*,vr_order.order_state', 'refill_order.order_time desc');
  215. $order_list = $this->OrderDataFormat($order_list, $merchant_list);
  216. if(empty($mch_orders)) {
  217. $mch_orderData = [];
  218. }else{
  219. $mch_orderData = explode(',',$mch_orders);
  220. }
  221. foreach ($order_list as $order_id => $order) {
  222. $mch_order = $order['mch_order'];
  223. if(in_array($mch_order, $mch_orderData)) {
  224. $key = array_search($mch_order, $mch_orderData);
  225. unset($mch_orderData[$key]);
  226. }
  227. $order_list[$order_id]['can_cancel'] = $this->can_cancel_order($order);
  228. }
  229. }
  230. Tpl::output('noexist_mch_order', $mch_orderData);
  231. Tpl::output('merchant_list', $merchant_list);
  232. Tpl::output('list', $order_list);
  233. Tpl::output('show_page', $mod->showpage());
  234. Tpl::showpage('set.cancel.order');
  235. }
  236. public function order_cancel_disposeOp()
  237. {
  238. $order_id = $_GET['order_id'];
  239. $condition['refill_order.order_id'] = ['in',$order_id];
  240. $order_list = Model('refill_order')->getMerchantOrderList($condition,1000,'refill_order.*,vr_order.order_state');
  241. foreach ($order_list as $order) {
  242. if($this->can_cancel_order($order)) {
  243. $mchid = $order['mchid'];
  244. $mch_order = $order['mch_order'];
  245. refill\util::set_cancel_order($mchid,$mch_order);
  246. $this->log("拦截订单,订单号:{$order['order_sn']},商家单号:{$mch_order},机构编码:{$mchid}", 1);
  247. }
  248. }
  249. showMessage('操作成功');
  250. }
  251. private function can_cancel_order($order): bool
  252. {
  253. if($order['order_state'] == ORDER_STATE_SUCCESS) {
  254. return false;
  255. }
  256. if($order['order_state'] == ORDER_STATE_CANCEL && $order['is_retrying'] == 0) {
  257. return false;
  258. }
  259. return true;
  260. }
  261. public function refill_buybackOp()
  262. {
  263. $model_refill_order = Model('refill_order');
  264. $order_list = [];
  265. if(!empty($_GET['card_nos'])) {
  266. $card_nos = trim($_GET['card_nos'], ',');
  267. $condition['refill_order.card_no'] = ['in', $card_nos];
  268. }
  269. if(!empty($_GET['order_sns'])) {
  270. $order_sns = trim($_GET['order_sns'], ',');
  271. $condition['refill_order.order_sn'] = ['in', $order_sns];
  272. }
  273. if(!empty($condition)) {
  274. $condition['inner_status'] = 0;
  275. $merchant_list = $this->merchants();
  276. $order_list = $model_refill_order->getBuyBackList($condition, 50, 'refill_order.*,vr_order.order_state', 'refill_order.order_time desc','',true);
  277. $order_list = $this->OrderDataFormat($order_list, $merchant_list);
  278. }
  279. Tpl::output('order_list', $order_list);
  280. Tpl::showpage('refill.buyback.order');
  281. }
  282. }