refill_order_manual.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  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. $orders = [];
  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. $int_array = function ($sids) {
  108. $result = [];
  109. foreach ($sids as $sid) {
  110. $result[] = intval($sid);
  111. }
  112. return $result;
  113. };
  114. $unique_array = function ($ids)
  115. {
  116. $ids = array_unique($ids);
  117. sort($ids);
  118. return $ids;
  119. };
  120. $orders = $model_refill_order->getMerchantOrderList($condition, 400, 'refill_order.*,vr_order.order_state', 'refill_order.channel_name DESC ');
  121. $orders = $this->OrderDataFormat($orders, $merchant_list);
  122. $order_ids = array_column($orders,'order_id');
  123. $order_ids = $unique_array($order_ids);
  124. $refill_buyback_model = Model('refill_buyback');
  125. $buybacks = $refill_buyback_model->getList(['order_id' => ['in',$order_ids]]);
  126. $buyback_ids = array_column($buybacks, 'order_id');
  127. $buyback_ids = $int_array($buyback_ids);
  128. $buyback_ids = $unique_array($buyback_ids);
  129. foreach ($orders as $key => $order)
  130. {
  131. if($order['order_state'] != ORDER_STATE_SUCCESS) {
  132. $order[$key]['buyback'] = false;
  133. continue;
  134. }
  135. $order_id = intval($order['order_id']);
  136. if(algorithm::binary_search($buyback_ids,$order_id)) {
  137. $orders[$key]['buyback'] = true;
  138. }else{
  139. $orders[$key]['buyback'] = false;
  140. }
  141. }
  142. }
  143. Tpl::output('merchant_list', $merchant_list);
  144. Tpl::output('provider_list', $provider_list);
  145. Tpl::output('order_list', $orders);
  146. Tpl::output('show_page', $model_refill_order->showpage());
  147. Tpl::showpage('refill.order.batch');
  148. }
  149. public function refill_order_batch_disposeOp()
  150. {
  151. $int_array = function ($sids) {
  152. $result = [];
  153. foreach ($sids as $sid) {
  154. $result[] = intval($sid);
  155. }
  156. return $result;
  157. };
  158. $unique_array = function ($ids)
  159. {
  160. $ids = array_unique($ids);
  161. sort($ids);
  162. return $ids;
  163. };
  164. $oid_reader = function ($sids) use ($int_array,$unique_array) {
  165. $sids = explode(',',$sids);
  166. $ids = $int_array($sids);
  167. return $unique_array($ids);
  168. };
  169. $oper_type = $_GET['type'];
  170. $order_ids = $oid_reader($_GET['order_id']);
  171. $cond = [];
  172. $cond['refill_order.order_id'] = ['in',$order_ids];
  173. $cond['refill_order.is_retrying'] = 0;
  174. if ($oper_type == 'success' || $oper_type == 'cancel') {
  175. $cond['vr_order.order_state'] = ORDER_STATE_SEND;
  176. } elseif ($oper_type == 'buyback') {
  177. $cond['vr_order.order_state'] = ORDER_STATE_SUCCESS;
  178. }
  179. $model_refill_order = Model('refill_order');
  180. $orders = $model_refill_order->getMerchantOrderList($cond,'','refill_order.*,vr_order.order_state','refill_order.order_id desc',2000);
  181. if($oper_type == 'success')
  182. {
  183. foreach ($orders as $order) {
  184. $check_fetch_order = $this->check_fetch_order($order['order_sn']);
  185. if($check_fetch_order == false) continue;
  186. refill\util::manual_success($order['order_id']);
  187. }
  188. }
  189. elseif ($oper_type == 'cancel')
  190. {
  191. foreach ($orders as $order) {
  192. $check_fetch_order = $this->check_fetch_order($order['order_sn']);
  193. if($check_fetch_order == false) continue;
  194. refill\util::manual_cancel($order['order_id']);
  195. }
  196. }
  197. elseif ($oper_type == 'notify')
  198. {
  199. foreach ($orders as $order) {
  200. if ($order['order_state'] == ORDER_STATE_SEND) {
  201. QueueClient::push("QueryRefillState", ['order_id' => $order['order_id']]);
  202. } else {
  203. QueueClient::push("NotifyMerchantComplete", ['order_id' => $order['order_id'], 'manual' => true]);
  204. }
  205. }
  206. }
  207. elseif ($oper_type == 'buyback')
  208. {
  209. $refill_buyback_model = Model('refill_buyback');
  210. $buybacks = $refill_buyback_model->getList(['order_id' => ['in',$order_ids]]);
  211. $buyback_ids = array_column($buybacks, 'order_id');
  212. $buyback_ids = $int_array($buyback_ids);
  213. $buyback_ids = $unique_array($buyback_ids);
  214. foreach ($orders as $order)
  215. {
  216. $order_id = intval($order['order_id']);
  217. if(!algorithm::binary_search($buyback_ids,$order_id)) {
  218. $ins[] = ['order_id' => $order['order_id'], 'order_sn' => $order['order_sn'],'order_time' => $order['order_time'], 'notify_time' => $order['notify_time']];
  219. }
  220. }
  221. if(!empty($ins)) {
  222. $refill_buyback_model->insertAll($ins);
  223. }
  224. }
  225. else {
  226. showMessage('手动操作类型错误');
  227. }
  228. showMessage('操作成功');
  229. }
  230. public function set_cancel_orderOp()
  231. {
  232. $mod = Model('refill_order');
  233. $condition = [];
  234. $order_list = [];
  235. $mch_orderData = [];
  236. if(!empty($_GET['mchid'])) {
  237. $condition['mchid'] = $_GET['mchid'];
  238. }
  239. if (!empty($_GET['mch_orders'])) {
  240. $mch_orders = rtrim($_GET['mch_orders'],',');
  241. $condition['mch_order'] = ['in', $mch_orders];
  242. }
  243. $merchant_list = $this->merchants();
  244. if(!empty($condition)) {
  245. $condition['inner_status'] = 0;
  246. $order_list = $mod->getMerchantOrderList($condition, 200, 'refill_order.*,vr_order.order_state', 'refill_order.order_time desc');
  247. $order_list = $this->OrderDataFormat($order_list, $merchant_list);
  248. if(empty($mch_orders)) {
  249. $mch_orderData = [];
  250. }else{
  251. $mch_orderData = explode(',',$mch_orders);
  252. }
  253. foreach ($order_list as $order_id => $order) {
  254. $mch_order = $order['mch_order'];
  255. if(in_array($mch_order, $mch_orderData)) {
  256. $key = array_search($mch_order, $mch_orderData);
  257. unset($mch_orderData[$key]);
  258. }
  259. $order_list[$order_id]['can_cancel'] = $this->can_cancel_order($order);
  260. }
  261. }
  262. Tpl::output('noexist_mch_order', $mch_orderData);
  263. Tpl::output('merchant_list', $merchant_list);
  264. Tpl::output('list', $order_list);
  265. Tpl::output('show_page', $mod->showpage());
  266. Tpl::showpage('set.cancel.order');
  267. }
  268. public function order_cancel_disposeOp()
  269. {
  270. $order_id = $_GET['order_id'];
  271. $condition['refill_order.order_id'] = ['in',$order_id];
  272. $order_list = Model('refill_order')->getMerchantOrderList($condition,1000,'refill_order.*,vr_order.order_state');
  273. foreach ($order_list as $order) {
  274. if($this->can_cancel_order($order)) {
  275. $mchid = $order['mchid'];
  276. $mch_order = $order['mch_order'];
  277. refill\util::set_cancel_order($mchid,$mch_order);
  278. $this->log("拦截订单,订单号:{$order['order_sn']},商家单号:{$mch_order},机构编码:{$mchid}", 1);
  279. }
  280. }
  281. showMessage('操作成功');
  282. }
  283. private function can_cancel_order($order): bool
  284. {
  285. if($order['order_state'] == ORDER_STATE_SUCCESS) {
  286. return false;
  287. }
  288. if($order['order_state'] == ORDER_STATE_CANCEL && $order['is_retrying'] == 0) {
  289. return false;
  290. }
  291. return true;
  292. }
  293. public function refill_buybackOp()
  294. {
  295. $model_refill_order = Model('refill_order');
  296. $order_list = [];
  297. if(!empty($_GET['card_nos'])) {
  298. $card_nos = trim($_GET['card_nos'], ',');
  299. $condition['refill_order.card_no'] = ['in', $card_nos];
  300. }
  301. if(!empty($_GET['order_sns'])) {
  302. $order_sns = trim($_GET['order_sns'], ',');
  303. $condition['refill_order.order_sn'] = ['in', $order_sns];
  304. }
  305. if(!empty($condition)) {
  306. $condition['inner_status'] = 0;
  307. $merchant_list = $this->merchants();
  308. $order_list = $model_refill_order->getBuyBackList($condition, 50, 'refill_order.*,vr_order.order_state', 'refill_order.order_time desc','',true);
  309. $order_list = $this->OrderDataFormat($order_list, $merchant_list);
  310. }
  311. Tpl::output('order_list', $order_list);
  312. Tpl::showpage('refill.buyback.order');
  313. }
  314. }