ordersendlist.php 27 KB

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