ordersendlist.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567
  1. <?php
  2. require_once(BASE_HELPER_PATH . '/refill/util.php');
  3. use refill\util;
  4. class ordersendlistControl extends SystemControl
  5. {
  6. private $mTimeouts;
  7. public function __construct()
  8. {
  9. $this->mTimeouts = [3 => 180, 4 => 300, 5 => 600, 6 => 900, 7 => 7200];
  10. parent::__construct();
  11. }
  12. private function time_cond($timeout_type,$card_type,$cur_time)
  13. {
  14. $mchid_filter = function ($time_out) {
  15. $mchids = Model('')->table('merchant')->where(['time_out' => ['elt', $time_out]])->field('mchid')->select();
  16. $mchids = array_column($mchids, 'mchid');
  17. $mchids = implode(',', $mchids);
  18. return $mchids;
  19. };
  20. $period = 20;
  21. $start_day = strtotime("-5 days",$cur_time);
  22. $time_cond = [];
  23. $mch_cond = [];
  24. if ($timeout_type > 0)
  25. {
  26. if (in_array($timeout_type, [1, 2]))
  27. {
  28. if ($timeout_type === 1) {
  29. $time_cond['refill_order.order_time'] = ['between', [$cur_time - 3600, $cur_time - 1800]];
  30. $time_cond['vr_order.add_time'] = ['between', [$cur_time - 3600, $cur_time - 1800]];
  31. }
  32. if ($timeout_type === 2) {
  33. $time_cond['refill_order.order_time'] = ['between', [$start_day, $cur_time - 3600]];
  34. $time_cond['vr_order.add_time'] = ['between', [$start_day, $cur_time - 3600]];
  35. }
  36. }
  37. elseif (in_array($timeout_type, [3, 4, 5, 6, 7])) {
  38. $time_out = $this->mTimeouts[$timeout_type];
  39. $mchids = $mchid_filter($time_out);
  40. $time_cond['vr_order.add_time&vr_order.add_time'] = ['_multi' => true, ['egt', $start_day], ['lt', $cur_time - $time_out]];
  41. $time_cond['refill_order.order_time&refill_order.order_time'] = ['_multi' => true, ['egt', $start_day], ['lt', $cur_time - $time_out]];
  42. $mch_cond['refill_order.mchid'] = ['in', $mchids];
  43. $card_type = 'phone';
  44. }
  45. else {
  46. $time_cond = [];
  47. }
  48. }
  49. else
  50. {
  51. $time_cond['vr_order.add_time&vr_order.add_time'] = ['_multi' => true,
  52. ['egt', $start_day],
  53. ['lt', $cur_time]];
  54. $time_cond['refill_order.order_time&refill_order.order_time&refill_order.order_time'] = ['_multi' => true,
  55. ['egt', $start_day],
  56. ['lt', $cur_time],
  57. ['exp', "refill_order.order_time < {$cur_time} - merchant.time_out + {$period}"]];
  58. // $time_cond['refill_order.commit_time'] = ['lt', $cur_time - 180];
  59. }
  60. return [$time_cond, $mch_cond, $card_type];
  61. }
  62. public function indexOp()
  63. {
  64. $model_refill_order = Model('refill_order');
  65. $base_cond['refill_order.inner_status'] = 0;
  66. $base_cond['vr_order.order_state'] = ORDER_STATE_SEND;
  67. $timeout_type = intval($_GET['time']);
  68. $card_type = $_GET['card_type'];
  69. if (!empty($_GET['store_id'])) {
  70. $base_cond['vr_order.store_id'] = $_GET['store_id'];
  71. }
  72. $cur_time = time();
  73. [$time_cond,$mch_cond,$card_type] = $this->time_cond($timeout_type,$card_type,$cur_time);
  74. if (!empty($_GET['mchid'])) {
  75. $base_cond['refill_order.mchid'] = $_GET['mchid'];
  76. } elseif(!empty($_GET['no_mchid'])) {
  77. $no_mchid = explode(',', $_GET['no_mchid']);
  78. $base_cond['refill_order.mchid'] = ['not in', $no_mchid];
  79. } elseif(!empty($mch_cond)) {
  80. $base_cond = array_merge($base_cond,$mch_cond);
  81. }
  82. if (!empty($card_type))
  83. {
  84. if (in_array($card_type, ['1', '2', '4', '5', '6', '7'])) {
  85. $base_cond['refill_order.card_type'] = $card_type;
  86. }
  87. if ($card_type == 'oil') {
  88. $base_cond['refill_order.card_type'] = ['in', ['1', '2']];
  89. }
  90. if ($card_type == 'phone') {
  91. $base_cond['refill_order.card_type'] = ['in', ['4', '5', '6']];
  92. }
  93. }
  94. if (!empty($_GET['quality'])) {
  95. $base_cond['refill_order.quality'] = $_GET['quality'];
  96. }
  97. $orders_cond = array_merge($base_cond,$time_cond);
  98. if (!empty($_GET['order_query'])) {
  99. $this->updateOrderSend($orders_cond);
  100. return;
  101. }
  102. if (!empty($_GET['export'])) {
  103. $this->RefillOrderExport($orders_cond, 'time_out_order');
  104. return;
  105. }
  106. $fields = 'refill_order.*,vr_order.order_state';
  107. $order_by = "( {$cur_time} - refill_order.commit_time ) desc";
  108. $order_stat = Model('')->table('refill_order,vr_order,merchant')
  109. ->join('inner,inner')
  110. ->on('refill_order.order_id=vr_order.order_id,refill_order.mchid=merchant.mchid')
  111. ->field('count(*) as order_count ,sum(refill_amount) as refill_amounts, sum(channel_amount) as channel_amounts, sum(mch_amount) as mch_amounts')
  112. ->where($orders_cond)->find();
  113. $order_list = $model_refill_order->getMerchantTimeOut($orders_cond, 200, $order_stat['order_count'], $fields, $order_by);
  114. $special_stat = $this->extra_stats($base_cond, $timeout_type,$cur_time);
  115. $merchant_list = $this->merchants();
  116. if(!empty($order_list)) {
  117. $order_list = $this->orderFormat($order_list, $merchant_list);
  118. }
  119. $provider_list = $this->providers();
  120. Tpl::output('stat', $order_stat);
  121. Tpl::output('count', $special_stat);
  122. Tpl::output('order_list', $order_list);
  123. Tpl::output('merchant_list', $merchant_list);
  124. Tpl::output('provider_list', $provider_list);
  125. Tpl::output('show_page', $model_refill_order->showpage());
  126. Tpl::showpage('refill.order.send.index');
  127. }
  128. private function notify_time($cur_time,$period)
  129. {
  130. $start_day = strtotime("-5 days",$cur_time);
  131. $time_cond['vr_order.add_time&vr_order.add_time'] = ['_multi' => true,
  132. ['egt', $start_day],
  133. ['lt', $cur_time]];
  134. $time_cond['refill_order.order_time&refill_order.order_time'] = ['_multi' => true,
  135. ['egt', $start_day],
  136. ['lt', $cur_time]];
  137. $time_cond['refill_order.commit_time&refill_order.commit_time'] = ['_multi' => true,
  138. ['egt', $start_day],
  139. ['lt', $cur_time - $period]];
  140. return $time_cond;
  141. }
  142. public function monitor_notifyOp()
  143. {
  144. $model_refill_order = Model('refill_order');
  145. $base_cond['refill_order.inner_status'] = 0;
  146. $base_cond['vr_order.order_state'] = ORDER_STATE_SEND;
  147. $timeout_type = intval($_GET['time']);
  148. $card_type = $_GET['card_type'];
  149. if (!empty($_GET['store_id'])) {
  150. $base_cond['vr_order.store_id'] = $_GET['store_id'];
  151. }
  152. $cur_time = time();
  153. $time_cond = $this->notify_time($cur_time,180);
  154. if (!empty($_GET['mchid'])) {
  155. $base_cond['refill_order.mchid'] = $_GET['mchid'];
  156. } elseif(!empty($_GET['no_mchid'])) {
  157. $no_mchid = explode(',', $_GET['no_mchid']);
  158. $base_cond['refill_order.mchid'] = ['not in', $no_mchid];
  159. } elseif(!empty($mch_cond)) {
  160. $base_cond = array_merge($base_cond,$mch_cond);
  161. }
  162. if (!empty($card_type))
  163. {
  164. if (in_array($card_type, ['1', '2', '4', '5', '6', '7'])) {
  165. $base_cond['refill_order.card_type'] = $card_type;
  166. }
  167. if ($card_type == 'oil') {
  168. $base_cond['refill_order.card_type'] = ['in', ['1', '2']];
  169. }
  170. if ($card_type == 'phone') {
  171. $base_cond['refill_order.card_type'] = ['in', ['4', '5', '6']];
  172. }
  173. }
  174. if (!empty($_GET['quality'])) {
  175. $base_cond['refill_order.quality'] = $_GET['quality'];
  176. }
  177. $orders_cond = array_merge($base_cond,$time_cond);
  178. if (!empty($_GET['order_query'])) {
  179. $this->updateOrderSend($orders_cond);
  180. return;
  181. }
  182. //耗时
  183. $fields = "refill_order.*,vr_order.order_state";
  184. $order_by = "({$cur_time} - refill_order.commit_time) desc";
  185. $order_stat = Model('')->table('refill_order,vr_order,merchant')
  186. ->join('inner,inner')
  187. ->on('refill_order.order_id=vr_order.order_id,refill_order.mchid=merchant.mchid')
  188. ->field('count(*) as order_count, sum(refill_amount) as refill_amounts, sum(channel_amount) as channel_amounts, sum(mch_amount) as mch_amounts')
  189. ->where($orders_cond)->find();
  190. $order_list = $model_refill_order->getMerchantTimeOut($orders_cond, 200, $order_stat['order_count'],$fields, $order_by);
  191. $special_stat = $this->extra_stats($base_cond, $timeout_type,$cur_time);
  192. $merchant_list = $this->merchants();
  193. if(!empty($order_list)) {
  194. $order_list = $this->orderFormat($order_list, $merchant_list);
  195. }
  196. $provider_list = $this->providers();
  197. Tpl::output('stat', $order_stat);
  198. Tpl::output('count', $special_stat);
  199. Tpl::output('order_list', $order_list);
  200. Tpl::output('merchant_list', $merchant_list);
  201. Tpl::output('provider_list', $provider_list);
  202. Tpl::output('show_page', $model_refill_order->showpage());
  203. Tpl::showpage('refill.order.send.index');
  204. }
  205. private function extra_stats($base_cond, $timeout_type,$cur_time): array
  206. {
  207. $stat_order = function ($cond)
  208. {
  209. $stat = Model('')->table('refill_order,vr_order')->join('inner')
  210. ->on('refill_order.order_id=vr_order.order_id')
  211. ->field('count(*) as order_count ')
  212. ->where($cond)->find();
  213. return $stat['order_count'];
  214. };
  215. $result = [];
  216. $start_day = strtotime("-5 days",$cur_time);
  217. $extra_conds = [
  218. ['between', [$cur_time - 3600, $cur_time - 1800]],
  219. ['between', [$start_day, $cur_time - 3600]]
  220. ];
  221. if (array_key_exists($timeout_type, $this->mTimeouts)) {
  222. $time_out = $this->mTimeouts[$timeout_type];
  223. $extra_conds[] = ['_multi' => true,
  224. ['egt', $start_day],
  225. ['lt', $cur_time - $time_out]];
  226. }
  227. foreach ($extra_conds as $stat_cond)
  228. {
  229. if (!empty($time_out)) {
  230. $base_cond['vr_order.add_time&vr_order.add_time'] = $stat_cond;
  231. $base_cond['refill_order.order_time&refill_order.order_time'] = $stat_cond;
  232. } else {
  233. $base_cond['refill_order.order_time'] = $stat_cond;
  234. $base_cond['vr_order.add_time'] = $stat_cond;
  235. }
  236. $result[] = $stat_order($base_cond);
  237. }
  238. return $result;
  239. }
  240. private function RefillOrderExport($cond,$type='order')
  241. {
  242. $result = [];
  243. if($type == 'order') {
  244. $result = Model('refill_order')->getAllOrders($cond);
  245. }elseif($type == 'time_out_order'){
  246. $result = Model('refill_order')->getAllTimeOutOrders($cond);
  247. }
  248. $this->createExcel($result);
  249. }
  250. private function createExcel($data = array())
  251. {
  252. Language::read('export');
  253. import('libraries.excel');
  254. $excel_obj = new Excel();
  255. $excel_data = array();
  256. //设置样式
  257. $excel_obj->setStyle(array('id' => 's_title', 'Font' => array('FontName' => '宋体', 'Size' => '12', 'Bold' => '1')));
  258. //header
  259. $excel_data[0][] = array('styleid' => 's_title', 'data' => '商户号');
  260. $excel_data[0][] = array('styleid' => 's_title', 'data' => '客户订单号');
  261. $excel_data[0][] = array('styleid' => 's_title', 'data' => '平台单号');
  262. $excel_data[0][] = array('styleid' => 's_title', 'data' => '面额');
  263. $excel_data[0][] = array('styleid' => 's_title', 'data' => '充值卡号');
  264. $excel_data[0][] = array('styleid' => 's_title', 'data' => '充值卡类型');
  265. $excel_data[0][] = array('styleid' => 's_title', 'data' => '下单日期');
  266. $excel_data[0][] = array('styleid' => 's_title', 'data' => '完成日期');
  267. $excel_data[0][] = array('styleid' => 's_title', 'data' => '官方流水号');
  268. $excel_data[0][] = array('styleid' => 's_title', 'data' => '订单状态');
  269. $excel_data[0][] = array('styleid' => 's_title', 'data' => '扣款金额');
  270. //data
  271. foreach ((array)$data as $k => $v) {
  272. $tmp = array();
  273. $tmp[] = array('data' => $v['mchid']);
  274. $tmp[] = array('data' => $v['mch_order']);
  275. $tmp[] = array('data' => $v['order_sn']);
  276. $tmp[] = array('data' => $v['refill_amount']);
  277. $tmp[] = array('data' => $v['card_no']);
  278. $tmp[] = array('data' => $this->scard_type($v['card_type']));
  279. $tmp[] = array('data' => date('Y-m-d H:i:s', $v['order_time']));
  280. if (empty($v['notify_time'])) {
  281. $tmp[] = array('data' => '');
  282. } else {
  283. $tmp[] = array('data' => date('Y-m-d H:i:s', $v['notify_time']));
  284. }
  285. $tmp[] = array('data' => $v['official_sn']);
  286. $tmp[] = array('data' => orderState($v));
  287. $tmp[] = array('data' => $v['mch_amount']);
  288. $excel_data[] = $tmp;
  289. }
  290. $excel_data = $excel_obj->charset($excel_data, CHARSET);
  291. $excel_obj->addArray($excel_data);
  292. $excel_obj->addWorksheet($excel_obj->charset(L('exp_od_order'), CHARSET));
  293. $excel_obj->generateXML($excel_obj->charset(L('exp_od_order'), CHARSET) . date('Y-m-d-H', time()));
  294. exit;
  295. }
  296. public function neterr_orderOp()
  297. {
  298. $model_refill_order = Model('refill_order');
  299. if (!empty($_GET['store_id'])) {
  300. $condition['vr_order.store_id'] = $_GET['store_id'];
  301. }
  302. $condition['refill_order.inner_status'] = 0;
  303. $condition['refill_order.neterr'] = 1;
  304. $condition['vr_order.order_state'] = ORDER_STATE_PAY;
  305. if (!empty($_GET['export'])) {
  306. $this->RefillOrderExport($condition);
  307. return;
  308. }
  309. $order_list = $model_refill_order->getMerchantOrderList($condition, 200, 0,'refill_order.*,vr_order.order_state', 'refill_order.order_time asc');
  310. $merchant_list = Model('')->table('merchant')->limit(1000)->order('name asc')->select();
  311. $order_list = $this->orderFormat($order_list, $merchant_list);
  312. $provider_list = $this->providers();
  313. Tpl::output('provider_list', $provider_list);
  314. Tpl::output('order_list', $order_list);
  315. Tpl::output('show_page', $model_refill_order->showpage());
  316. Tpl::showpage('refill.order.neterr.index');
  317. }
  318. public function neterr_order_manualOp()
  319. {
  320. $type = $_GET['type'];
  321. $official_sn = $_GET['official_sn'] ?? '';
  322. if ($type != 'success' && $type != 'cancel') {
  323. showMessage('手动操作类型错误');
  324. }
  325. $order_ids = $_GET['order_ids'];
  326. $model_refill_order = Model('refill_order');
  327. $condition['refill_order.order_id'] = ['in', $order_ids];
  328. $condition['refill_order.inner_status'] = 0;
  329. $condition['refill_order.neterr'] = 1;
  330. $condition['vr_order.order_state'] = ORDER_STATE_PAY;
  331. $order_list = $model_refill_order->getMerchantOrderList($condition);
  332. if (empty($order_list)) {
  333. showMessage('暂无数据');
  334. }
  335. $logic_vr_order = Logic("vr_order");
  336. $mod_vr_order = Model('vr_order');
  337. foreach ($order_list as $order) {
  338. $order_id = $order['order_id'];
  339. if ($type == 'success') {
  340. $logic_vr_order->changeOrderStateSuccess($order_id, true);
  341. if (!empty($official_sn)) {
  342. $model_refill_order->edit($order_id, ['official_sn' => $official_sn]);
  343. }
  344. } elseif ($type == 'cancel') {
  345. $order_info = $mod_vr_order->getOrderInfo(['order_id' => $order_id]);
  346. $logic_vr_order->changeOrderStateCancel($order_info, '', "充值失败", true, true);
  347. } else {
  348. continue;
  349. }
  350. if ($order['notify_time'] == 0) {
  351. $model_refill_order->edit($order_id, ['notify_state' => 1, 'notify_time' => time()]);
  352. }
  353. util::pop_queue_order($order['mchid'], $order['mch_order']);
  354. QueueClient::push("NotifyMerchantComplete", ['order_id' => $order_id, 'manual' => true]);
  355. }
  356. showMessage('操作成功');
  357. }
  358. public function orderFormat($order_list, $merchant_list): array
  359. {
  360. $merchants = [];
  361. foreach ($merchant_list as $value) {
  362. $merchants[$value['mchid']] = $value;
  363. }
  364. $cur_time = time();
  365. foreach ($order_list as $order_id => $order_info) {
  366. $order_list[$order_id]['card_type_text'] = $this->scard_type($order_info['card_type']);
  367. $order_list[$order_id]['mch_name'] = $merchants[$order_info['mchid']]['company_name'];
  368. if ($order_info['notify_time'] > 0) {
  369. $total_diff_time = $order_info['notify_time'] - $order_info['order_time'];
  370. $diff_time = $order_info['notify_time'] - $order_info['commit_time'];
  371. } else {
  372. $total_diff_time = $cur_time - $order_info['order_time'];
  373. $diff_time = $cur_time - $order_info['commit_time'];
  374. }
  375. $order_list[$order_id]['diff_time'] = $diff_time;
  376. $order_list[$order_id]['diff_time_text'] = $this->elapse_time($diff_time);
  377. $order_list[$order_id]['total_diff_time'] = $total_diff_time;
  378. $order_list[$order_id]['total_diff_time_text'] = $this->elapse_time($total_diff_time);
  379. $order_list[$order_id]['quality_text'] = $this->quality_format($order_info['quality'], $order_info['card_type']);
  380. if ($total_diff_time > $merchants[$order_info['mchid']]['time_out'] && $order_info['order_state'] == ORDER_STATE_SEND) {
  381. $order_list[$order_id]['time_out_state'] = 0;
  382. if (in_array($order_info['card_type'], [mtopcard\PetroChinaCard, mtopcard\SinopecCard])) {
  383. $order_list[$order_id]['time_out_state'] = 1;
  384. }
  385. if (in_array($order_info['card_type'], [mtopcard\ChinaMobileCard, mtopcard\ChinaUnicomCard, mtopcard\ChinaTelecomCard])) {
  386. if (in_array($order_info['quality'], [
  387. refill\Quality::SlowTwentyFour,
  388. refill\Quality::SlowSix,
  389. refill\Quality::SlowTwo,
  390. refill\Quality::SlowFortyEight,
  391. refill\Quality::SlowSeventyTwo])) {
  392. $order_list[$order_id]['time_out_state'] = 2;
  393. } elseif (in_array($order_info['mchid'], [10132])) {
  394. //重点机构
  395. $order_list[$order_id]['time_out_state'] = 3;
  396. } else {
  397. $order_list[$order_id]['time_out_state'] = 4;
  398. }
  399. }
  400. } else {
  401. $order_list[$order_id]['time_out_state'] = 0;
  402. }
  403. }
  404. return $order_list;
  405. }
  406. public function notify_err_orderOp()
  407. {
  408. $model_refill_order = Model('refill_order');
  409. $order_state_cancel = ORDER_STATE_CANCEL;
  410. $order_state_success = ORDER_STATE_SUCCESS;
  411. $condition['refill_order.inner_status'] = 0;
  412. $condition['refill_order.is_retrying'] = 0;
  413. $condition['vr_order.order_state'] = ['in', "{$order_state_cancel},{$order_state_success}"];
  414. $condition['refill_order.mch_notify_state'] = ['in', "0,2"];
  415. $condition['refill_order.mch_notify_times'] = ['gt', 0];
  416. if (empty($_GET['time'])) {
  417. $_GET['time'] = 1;
  418. }
  419. if (empty($_GET['notify_time'])) {
  420. $_GET['notify_time'] = 180;
  421. }
  422. $cur_time = time();
  423. $time = $_GET['time'] * 3600;
  424. $condition['refill_order.order_time'] = [['gt', ($cur_time - $time)], ['lt', $cur_time], 'and'];
  425. $condition['vr_order.add_time'] = [['gt', ($cur_time - $time)], ['lt', $cur_time], 'and'];
  426. $notify_time = $_GET['notify_time'];
  427. if($notify_time > 0) {
  428. $start_day = strtotime("-5 days",$cur_time);
  429. $condition['refill_order.notify_time'] = ['lt', (time() - $notify_time)];
  430. $condition['refill_order.notify_time'] = [['gt', $start_day], ['lt', ($cur_time - $notify_time)], 'and'];
  431. }
  432. $order_list = $model_refill_order->getMerchantOrderList($condition, 200, 0,'refill_order.*,vr_order.order_state', 'refill_order.notify_time asc', 1000);
  433. $merchant_list = Model('')->table('merchant')->limit(1000)->order('name asc')->select();
  434. $order_list = $this->orderFormat($order_list, $merchant_list);
  435. Tpl::output('order_list', $order_list);
  436. Tpl::output('show_page', $model_refill_order->showpage());
  437. Tpl::showpage('refill.order.notify.err.index');
  438. }
  439. public function notifyerr_all_notifyOp()
  440. {
  441. if (empty($_GET['time']) || empty($_GET['notify_time'])) {
  442. showMessage('日期条件错误');
  443. }
  444. $model_refill_order = Model('refill_order');
  445. $order_state_cancel = ORDER_STATE_CANCEL;
  446. $order_state_success = ORDER_STATE_SUCCESS;
  447. $condition['refill_order.inner_status'] = 0;
  448. $condition['vr_order.order_state'] = ['in', "{$order_state_cancel},{$order_state_success}"];
  449. $condition['refill_order.mch_notify_state'] = ['in', "0,2"];
  450. $condition['refill_order.is_retrying'] = 0;
  451. $time = $_GET['time'] * 3600;
  452. $condition['refill_order.order_time'] = ['gt', (time() - $time)];
  453. $notify_time = $_GET['notify_time'];
  454. $condition['refill_order.notify_time'] = ['lt', (time() - $notify_time)];
  455. $order_list = $model_refill_order->getMerchantOrderList($condition, '', 0,'refill_order.*,vr_order.order_state', 'refill_order.notify_time asc', 1000);
  456. foreach ($order_list as $order) {
  457. QueueClient::push("NotifyMerchantComplete", ['order_id' => $order['order_id'], 'manual' => true]);
  458. }
  459. showMessage('操作成功');
  460. }
  461. private function updateOrderSend($condition)
  462. {
  463. $condition['order_state'] = ORDER_STATE_SEND;
  464. $orders = $this->getAllTimeOutOrders($condition);
  465. if (!empty($orders)) {
  466. foreach ($orders as $order) {
  467. $order_id = $order['order_id'];
  468. QueueClient::push("QueryRefillState", ['order_id' => $order_id]);
  469. }
  470. }
  471. showMessage('操作成功');
  472. }
  473. private function getAllTimeOutOrders($condition): array
  474. {
  475. $len = 1000;
  476. $i = 0;
  477. $orders = [];
  478. while (true) {
  479. $start = $i * $len;
  480. $items = Model('')->table('refill_order,vr_order,merchant')
  481. ->field('refill_order.*,vr_order.order_state')
  482. ->join('inner,inner')
  483. ->on('refill_order.order_id=vr_order.order_id,refill_order.mchid=merchant.mchid')
  484. ->where($condition)
  485. ->order('refill_order.order_time desc')
  486. ->limit("{$start},{$len}")->select();
  487. $orders = array_merge($orders,$items);
  488. if (empty($items) || count($items) < $len) {
  489. break;
  490. }
  491. $i++;
  492. }
  493. return $orders;
  494. }
  495. }