ordersendlist.php 26 KB

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