ordersendlist.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604
  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 extra_stats($base_cond, $timeout_type,$cur_time): array
  129. {
  130. $stat_order = function ($cond)
  131. {
  132. $stat = Model('')->table('refill_order,vr_order')->join('inner')
  133. ->on('refill_order.order_id=vr_order.order_id')
  134. ->field('count(*) as order_count ')
  135. ->where($cond)->find();
  136. return $stat['order_count'];
  137. };
  138. $result = [];
  139. $start_day = strtotime("-5 days",$cur_time);
  140. $extra_conds = [
  141. ['between', [$cur_time - 3600, $cur_time - 1800]],
  142. ['between', [$start_day, $cur_time - 3600]]
  143. ];
  144. if (array_key_exists($timeout_type, $this->mTimeouts)) {
  145. $time_out = $this->mTimeouts[$timeout_type];
  146. $extra_conds[] = ['_multi' => true,
  147. ['egt', $start_day],
  148. ['lt', $cur_time - $time_out]];
  149. }
  150. foreach ($extra_conds as $stat_cond)
  151. {
  152. if (!empty($time_out)) {
  153. $base_cond['vr_order.add_time&vr_order.add_time'] = $stat_cond;
  154. $base_cond['refill_order.order_time&refill_order.order_time'] = $stat_cond;
  155. } else {
  156. $base_cond['refill_order.order_time'] = $stat_cond;
  157. $base_cond['vr_order.add_time'] = $stat_cond;
  158. }
  159. $result[] = $stat_order($base_cond);
  160. }
  161. return $result;
  162. }
  163. private function notify_time($cur_time,$period)
  164. {
  165. $start_day = strtotime("-5 days",$cur_time);
  166. $time_cond['vr_order.add_time&vr_order.add_time'] = ['_multi' => true,
  167. ['egt', $start_day],
  168. ['lt', $cur_time]];
  169. $time_cond['refill_order.order_time&refill_order.order_time'] = ['_multi' => true,
  170. ['egt', $start_day],
  171. ['lt', $cur_time]];
  172. $time_cond['refill_order.commit_time&refill_order.commit_time'] = ['_multi' => true,
  173. ['egt', $start_day],
  174. ['lt', $cur_time - $period]];
  175. return $time_cond;
  176. }
  177. public function monitor_notifyOp()
  178. {
  179. $model_refill_order = Model('refill_order');
  180. $base_cond['refill_order.inner_status'] = 0;
  181. $base_cond['vr_order.order_state'] = ORDER_STATE_SEND;
  182. $timeout_type = intval($_GET['time']);
  183. $card_type = $_GET['card_type'];
  184. if (!empty($_GET['store_id'])) {
  185. $base_cond['vr_order.store_id'] = $_GET['store_id'];
  186. }
  187. $cur_time = time();
  188. $period = 180;
  189. if(!empty($_GET['time'])) {
  190. $period = intval($_GET['time']);
  191. }
  192. $time_cond = $this->notify_time($cur_time,$period);
  193. if (!empty($_GET['mchid'])) {
  194. $base_cond['refill_order.mchid'] = $_GET['mchid'];
  195. } elseif(!empty($_GET['no_mchid'])) {
  196. $no_mchid = explode(',', $_GET['no_mchid']);
  197. $base_cond['refill_order.mchid'] = ['not in', $no_mchid];
  198. } elseif(!empty($mch_cond)) {
  199. $base_cond = array_merge($base_cond,$mch_cond);
  200. }
  201. if (!empty($card_type))
  202. {
  203. if (in_array($card_type, ['1', '2', '4', '5', '6', '7'])) {
  204. $base_cond['refill_order.card_type'] = $card_type;
  205. }
  206. if ($card_type == 'oil') {
  207. $base_cond['refill_order.card_type'] = ['in', ['1', '2']];
  208. }
  209. if ($card_type == 'phone') {
  210. $base_cond['refill_order.card_type'] = ['in', ['4', '5', '6']];
  211. }
  212. }
  213. if (!empty($_GET['quality'])) {
  214. $base_cond['refill_order.quality'] = $_GET['quality'];
  215. }
  216. $orders_cond = array_merge($base_cond,$time_cond);
  217. if (!empty($_GET['order_query'])) {
  218. $this->updateOrderSend($orders_cond);
  219. return;
  220. }
  221. if (!empty($_GET['export'])) {
  222. $this->RefillOrderExport($orders_cond, 'time_out_order');
  223. return;
  224. }
  225. $merchant_list = $this->merchants();
  226. $provider_list = $this->providers();
  227. //耗时
  228. $fields = "refill_order.*,vr_order.order_state";
  229. $order_by = "({$cur_time} - refill_order.commit_time) desc";
  230. $order_stat = Model('')->table('refill_order,vr_order')
  231. ->join('inner')
  232. ->on('refill_order.order_id=vr_order.order_id')
  233. ->field('count(*) as order_count, sum(refill_amount) as refill_amounts, sum(channel_amount) as channel_amounts, sum(mch_amount) as mch_amounts')
  234. ->where($orders_cond)->find();
  235. $order_list = $model_refill_order->getMerchantTimeOut($orders_cond, 200, $order_stat['order_count'],$fields, $order_by);
  236. if(!empty($order_list)) {
  237. $order_list = $this->orderFormat($order_list, $merchant_list);
  238. }
  239. $special_stat = $this->provider_timeout_stats($orders_cond, $provider_list);
  240. Tpl::output('stat', $order_stat);
  241. Tpl::output('special_stat', $special_stat);
  242. Tpl::output('order_list', $order_list);
  243. Tpl::output('merchant_list', $merchant_list);
  244. Tpl::output('provider_list', $provider_list);
  245. Tpl::output('show_page', $model_refill_order->showpage());
  246. Tpl::showpage('refill.order.monitor.notify');
  247. }
  248. private function provider_timeout_stats($cond, $provider_list)
  249. {
  250. unset($cond['vr_order.store_id']);
  251. $order_stat = Model('')->table('refill_order,vr_order')
  252. ->join('inner')
  253. ->on('refill_order.order_id=vr_order.order_id')
  254. ->field('count(*) as order_count, store_id')
  255. ->where($cond)
  256. ->group('vr_order.store_id')
  257. ->order('order_count desc')
  258. ->select();
  259. if(empty($order_stat)) return [];
  260. foreach ($provider_list as $provider) {
  261. $providers[$provider['provider_id']] = $provider;
  262. }
  263. ksort($providers);
  264. foreach ($order_stat as $key => $stat) {
  265. $store_id = intval($stat['store_id']);
  266. $order_stat[$key]['store_name'] = $providers[$store_id]['store_name'];
  267. $order_stat[$key]['opened'] = $providers[$store_id]['opened'];
  268. }
  269. return $order_stat;
  270. }
  271. private function RefillOrderExport($cond,$type='order')
  272. {
  273. $result = [];
  274. if($type == 'order') {
  275. $result = Model('refill_order')->getAllOrders($cond);
  276. }elseif($type == 'time_out_order'){
  277. $result = Model('refill_order')->getAllTimeOutOrders($cond);
  278. }
  279. $this->createExcel($result);
  280. }
  281. private function createExcel($data = array())
  282. {
  283. Language::read('export');
  284. import('libraries.excel');
  285. $excel_obj = new Excel();
  286. $excel_data = array();
  287. //设置样式
  288. $excel_obj->setStyle(array('id' => 's_title', 'Font' => array('FontName' => '宋体', 'Size' => '12', 'Bold' => '1')));
  289. //header
  290. $excel_data[0][] = array('styleid' => 's_title', 'data' => '商户号');
  291. $excel_data[0][] = array('styleid' => 's_title', 'data' => '客户订单号');
  292. $excel_data[0][] = array('styleid' => 's_title', 'data' => '平台单号');
  293. $excel_data[0][] = array('styleid' => 's_title', 'data' => '面额');
  294. $excel_data[0][] = array('styleid' => 's_title', 'data' => '充值卡号');
  295. $excel_data[0][] = array('styleid' => 's_title', 'data' => '充值卡类型');
  296. $excel_data[0][] = array('styleid' => 's_title', 'data' => '下单日期');
  297. $excel_data[0][] = array('styleid' => 's_title', 'data' => '完成日期');
  298. $excel_data[0][] = array('styleid' => 's_title', 'data' => '官方流水号');
  299. $excel_data[0][] = array('styleid' => 's_title', 'data' => '订单状态');
  300. $excel_data[0][] = array('styleid' => 's_title', 'data' => '扣款金额');
  301. //data
  302. foreach ((array)$data as $k => $v) {
  303. $tmp = array();
  304. $tmp[] = array('data' => $v['mchid']);
  305. $tmp[] = array('data' => $v['mch_order']);
  306. $tmp[] = array('data' => $v['order_sn']);
  307. $tmp[] = array('data' => $v['refill_amount']);
  308. $tmp[] = array('data' => $v['card_no']);
  309. $tmp[] = array('data' => $this->scard_type($v['card_type']));
  310. $tmp[] = array('data' => date('Y-m-d H:i:s', $v['order_time']));
  311. if (empty($v['notify_time'])) {
  312. $tmp[] = array('data' => '');
  313. } else {
  314. $tmp[] = array('data' => date('Y-m-d H:i:s', $v['notify_time']));
  315. }
  316. $tmp[] = array('data' => $v['official_sn']);
  317. $tmp[] = array('data' => orderState($v));
  318. $tmp[] = array('data' => $v['mch_amount']);
  319. $excel_data[] = $tmp;
  320. }
  321. $excel_data = $excel_obj->charset($excel_data, CHARSET);
  322. $excel_obj->addArray($excel_data);
  323. $excel_obj->addWorksheet($excel_obj->charset(L('exp_od_order'), CHARSET));
  324. $excel_obj->generateXML($excel_obj->charset(L('exp_od_order'), CHARSET) . date('Y-m-d-H', time()));
  325. exit;
  326. }
  327. public function neterr_orderOp()
  328. {
  329. $model_refill_order = Model('refill_order');
  330. if (!empty($_GET['store_id'])) {
  331. $condition['vr_order.store_id'] = $_GET['store_id'];
  332. }
  333. $condition['refill_order.inner_status'] = 0;
  334. $condition['refill_order.neterr'] = 1;
  335. $condition['vr_order.order_state'] = ORDER_STATE_PAY;
  336. if (!empty($_GET['export'])) {
  337. $this->RefillOrderExport($condition);
  338. return;
  339. }
  340. $order_stat = Model('')->table('refill_order,vr_order')
  341. ->join('inner')
  342. ->on('refill_order.order_id=vr_order.order_id')
  343. ->field('count(*) as order_count')
  344. ->where($condition)->find();
  345. $order_list = $model_refill_order->getMerchantOrderList($condition, 200, $order_stat['order_count'],'refill_order.*,vr_order.order_state', 'refill_order.order_time asc');
  346. $merchant_list = Model('')->table('merchant')->limit(1000)->order('name asc')->select();
  347. $order_list = $this->orderFormat($order_list, $merchant_list);
  348. $provider_list = $this->providers();
  349. Tpl::output('stat', $order_stat);
  350. Tpl::output('provider_list', $provider_list);
  351. Tpl::output('order_list', $order_list);
  352. Tpl::output('show_page', $model_refill_order->showpage());
  353. Tpl::showpage('refill.order.neterr.index');
  354. }
  355. public function neterr_order_manualOp()
  356. {
  357. $type = $_GET['type'];
  358. $official_sn = $_GET['official_sn'] ?? '';
  359. if ($type != 'success' && $type != 'cancel') {
  360. showMessage('手动操作类型错误');
  361. }
  362. $order_ids = $_GET['order_ids'];
  363. $model_refill_order = Model('refill_order');
  364. $condition['refill_order.order_id'] = ['in', $order_ids];
  365. $condition['refill_order.inner_status'] = 0;
  366. $condition['refill_order.neterr'] = 1;
  367. $condition['vr_order.order_state'] = ORDER_STATE_PAY;
  368. $order_list = $model_refill_order->getMerchantOrderList($condition);
  369. if (empty($order_list)) {
  370. showMessage('暂无数据');
  371. }
  372. $logic_vr_order = Logic("vr_order");
  373. $mod_vr_order = Model('vr_order');
  374. foreach ($order_list as $order) {
  375. $order_id = $order['order_id'];
  376. if ($type == 'success') {
  377. $logic_vr_order->changeOrderStateSuccess($order_id, true);
  378. if (!empty($official_sn)) {
  379. $model_refill_order->edit($order_id, ['official_sn' => $official_sn]);
  380. }
  381. } elseif ($type == 'cancel') {
  382. $order_info = $mod_vr_order->getOrderInfo(['order_id' => $order_id]);
  383. $logic_vr_order->changeOrderStateCancel($order_info, '', "充值失败", true, true);
  384. } else {
  385. continue;
  386. }
  387. if ($order['notify_time'] == 0) {
  388. $model_refill_order->edit($order_id, ['notify_state' => 1, 'notify_time' => time()]);
  389. }
  390. util::pop_queue_order($order['mchid'], $order['mch_order']);
  391. QueueClient::push("NotifyMerchantComplete", ['order_id' => $order_id, 'manual' => true]);
  392. }
  393. showMessage('操作成功');
  394. }
  395. public function orderFormat($order_list, $merchant_list): array
  396. {
  397. $merchants = [];
  398. foreach ($merchant_list as $value) {
  399. $merchants[$value['mchid']] = $value;
  400. }
  401. $cur_time = time();
  402. foreach ($order_list as $order_id => $order_info) {
  403. $order_list[$order_id]['card_type_text'] = $this->scard_type($order_info['card_type']);
  404. $order_list[$order_id]['mch_name'] = $merchants[$order_info['mchid']]['company_name'];
  405. if ($order_info['notify_time'] > 0) {
  406. $total_diff_time = $order_info['notify_time'] - $order_info['order_time'];
  407. $diff_time = $order_info['notify_time'] - $order_info['commit_time'];
  408. } else {
  409. $total_diff_time = $cur_time - $order_info['order_time'];
  410. $diff_time = $cur_time - $order_info['commit_time'];
  411. }
  412. $order_list[$order_id]['diff_time'] = $diff_time;
  413. $order_list[$order_id]['diff_time_text'] = $this->elapse_time($diff_time);
  414. $order_list[$order_id]['total_diff_time'] = $total_diff_time;
  415. $order_list[$order_id]['total_diff_time_text'] = $this->elapse_time($total_diff_time);
  416. $order_list[$order_id]['quality_text'] = $this->quality_format($order_info['quality'], $order_info['card_type']);
  417. if ($total_diff_time > $merchants[$order_info['mchid']]['time_out'] && $order_info['order_state'] == ORDER_STATE_SEND) {
  418. $order_list[$order_id]['time_out_state'] = 0;
  419. if (in_array($order_info['card_type'], [mtopcard\PetroChinaCard, mtopcard\SinopecCard])) {
  420. $order_list[$order_id]['time_out_state'] = 1;
  421. }
  422. if (in_array($order_info['card_type'], [mtopcard\ChinaMobileCard, mtopcard\ChinaUnicomCard, mtopcard\ChinaTelecomCard])) {
  423. if (in_array($order_info['quality'], [
  424. refill\Quality::SlowTwentyFour,
  425. refill\Quality::SlowSix,
  426. refill\Quality::SlowTwo,
  427. refill\Quality::SlowFortyEight,
  428. refill\Quality::SlowSeventyTwo])) {
  429. $order_list[$order_id]['time_out_state'] = 2;
  430. } elseif (in_array($order_info['mchid'], [10132])) {
  431. //重点机构
  432. $order_list[$order_id]['time_out_state'] = 3;
  433. } else {
  434. $order_list[$order_id]['time_out_state'] = 4;
  435. }
  436. }
  437. } else {
  438. $order_list[$order_id]['time_out_state'] = 0;
  439. }
  440. }
  441. return $order_list;
  442. }
  443. public function notify_err_orderOp()
  444. {
  445. $model_refill_order = Model('refill_order');
  446. $order_state_cancel = ORDER_STATE_CANCEL;
  447. $order_state_success = ORDER_STATE_SUCCESS;
  448. $condition['refill_order.inner_status'] = 0;
  449. $condition['refill_order.is_retrying'] = 0;
  450. $condition['vr_order.order_state'] = ['in', "{$order_state_cancel},{$order_state_success}"];
  451. $condition['refill_order.mch_notify_state'] = ['in', "0,2"];
  452. $condition['refill_order.mch_notify_times'] = ['gt', 0];
  453. if (empty($_GET['time'])) {
  454. $_GET['time'] = 1;
  455. }
  456. if (empty($_GET['notify_time'])) {
  457. $_GET['notify_time'] = 180;
  458. }
  459. $cur_time = time();
  460. $time = $_GET['time'] * 3600;
  461. $condition['refill_order.order_time'] = [['gt', ($cur_time - $time)], ['lt', $cur_time], 'and'];
  462. $condition['vr_order.add_time'] = [['gt', ($cur_time - $time)], ['lt', $cur_time], 'and'];
  463. $notify_time = $_GET['notify_time'];
  464. if($notify_time > 0) {
  465. $start_day = strtotime("-5 days",$cur_time);
  466. $condition['refill_order.notify_time'] = ['lt', (time() - $notify_time)];
  467. $condition['refill_order.notify_time'] = [['gt', $start_day], ['lt', ($cur_time - $notify_time)], 'and'];
  468. }
  469. $order_list = $model_refill_order->getMerchantOrderList($condition, 200, 0,'refill_order.*,vr_order.order_state', 'refill_order.notify_time asc', 1000);
  470. $merchant_list = Model('')->table('merchant')->limit(1000)->order('name asc')->select();
  471. $order_list = $this->orderFormat($order_list, $merchant_list);
  472. Tpl::output('order_list', $order_list);
  473. Tpl::output('show_page', $model_refill_order->showpage());
  474. Tpl::showpage('refill.order.notify.err.index');
  475. }
  476. public function notifyerr_all_notifyOp()
  477. {
  478. if (empty($_GET['time']) || empty($_GET['notify_time'])) {
  479. showMessage('日期条件错误');
  480. }
  481. $model_refill_order = Model('refill_order');
  482. $order_state_cancel = ORDER_STATE_CANCEL;
  483. $order_state_success = ORDER_STATE_SUCCESS;
  484. $condition['refill_order.inner_status'] = 0;
  485. $condition['vr_order.order_state'] = ['in', "{$order_state_cancel},{$order_state_success}"];
  486. $condition['refill_order.mch_notify_state'] = ['in', "0,2"];
  487. $condition['refill_order.is_retrying'] = 0;
  488. $time = $_GET['time'] * 3600;
  489. $condition['refill_order.order_time'] = ['gt', (time() - $time)];
  490. $notify_time = $_GET['notify_time'];
  491. $condition['refill_order.notify_time'] = ['lt', (time() - $notify_time)];
  492. $order_list = $model_refill_order->getMerchantOrderList($condition, '', 0,'refill_order.*,vr_order.order_state', 'refill_order.notify_time asc', 1000);
  493. foreach ($order_list as $order) {
  494. QueueClient::push("NotifyMerchantComplete", ['order_id' => $order['order_id'], 'manual' => true]);
  495. }
  496. showMessage('操作成功');
  497. }
  498. private function updateOrderSend($condition)
  499. {
  500. $condition['order_state'] = ORDER_STATE_SEND;
  501. $orders = $this->getAllTimeOutOrders($condition);
  502. if (!empty($orders)) {
  503. foreach ($orders as $order) {
  504. $order_id = $order['order_id'];
  505. QueueClient::push("QueryRefillState", ['order_id' => $order_id]);
  506. }
  507. }
  508. showMessage('操作成功');
  509. }
  510. private function getAllTimeOutOrders($condition): array
  511. {
  512. $len = 1000;
  513. $i = 0;
  514. $orders = [];
  515. while (true) {
  516. $start = $i * $len;
  517. $items = Model('')->table('refill_order,vr_order,merchant')
  518. ->field('refill_order.*,vr_order.order_state')
  519. ->join('inner,inner')
  520. ->on('refill_order.order_id=vr_order.order_id,refill_order.mchid=merchant.mchid')
  521. ->where($condition)
  522. ->order('refill_order.order_time desc')
  523. ->limit("{$start},{$len}")->select();
  524. $orders = array_merge($orders,$items);
  525. if (empty($items) || count($items) < $len) {
  526. break;
  527. }
  528. $i++;
  529. }
  530. return $orders;
  531. }
  532. }