ordersendlist.php 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697
  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. }
  59. return [$time_cond, $mch_cond, $card_type];
  60. }
  61. public function indexOp()
  62. {
  63. $model_refill_order = Model('refill_order');
  64. $base_cond['refill_order.inner_status'] = 0;
  65. $base_cond['vr_order.order_state'] = ORDER_STATE_SEND;
  66. $timeout_type = intval($_GET['time']);
  67. $card_type = $_GET['card_type'];
  68. if (!empty($_GET['store_id'])) {
  69. $base_cond['vr_order.store_id'] = $_GET['store_id'];
  70. }
  71. $cur_time = time();
  72. [$time_cond,$mch_cond,$card_type] = $this->time_cond($timeout_type,$card_type,$cur_time);
  73. if (!empty($_GET['mchid'])) {
  74. $base_cond['refill_order.mchid'] = $_GET['mchid'];
  75. } elseif(!empty($_GET['no_mchid'])) {
  76. $no_mchid = explode(',', $_GET['no_mchid']);
  77. $base_cond['refill_order.mchid'] = ['not in', $no_mchid];
  78. } elseif(!empty($mch_cond)) {
  79. $base_cond = array_merge($base_cond,$mch_cond);
  80. }
  81. if (!empty($card_type))
  82. {
  83. if (in_array($card_type, ['1', '2', '4', '5', '6', '7'])) {
  84. $base_cond['refill_order.card_type'] = $card_type;
  85. }
  86. if ($card_type == 'oil') {
  87. $base_cond['refill_order.card_type'] = ['in', ['1', '2']];
  88. }
  89. if ($card_type == 'phone') {
  90. $base_cond['refill_order.card_type'] = ['in', ['4', '5', '6']];
  91. }
  92. }
  93. if (!empty($_GET['quality'])) {
  94. $base_cond['refill_order.quality'] = $_GET['quality'];
  95. }
  96. $orders_cond = array_merge($base_cond,$time_cond);
  97. if (!empty($_GET['order_query'])) {
  98. $this->updateOrderSend($orders_cond);
  99. return;
  100. }
  101. if (!empty($_GET['export'])) {
  102. $this->RefillOrderExport($orders_cond, '商户超时监控导出', 'time_out_order');
  103. return;
  104. }
  105. $store_ids = Model('')->table('refill_order,vr_order,merchant')
  106. ->join('inner,inner')
  107. ->on('refill_order.order_id=vr_order.order_id,refill_order.mchid=merchant.mchid')
  108. ->field('DISTINCT vr_order.store_id')
  109. ->where($orders_cond)
  110. ->group('vr_order.store_id')
  111. ->order('store_id asc')
  112. ->select();
  113. $store_ids = array_column($store_ids, 'store_id');
  114. $merchant_list = $this->merchants();
  115. $provider_list = $this->providers(['store.store_id' => ['in', $store_ids]]);
  116. [$merchant_stat, $order_stat] = $this->merchant_timeout_stats($orders_cond);
  117. if (empty($_GET['mchid'])) {
  118. $order_count = $order_stat['order_count'];
  119. }else{
  120. $order_count = $merchant_stat[$_GET['mchid']]['order_count'];
  121. }
  122. $fields = "refill_order.*,vr_order.order_state,( {$cur_time} - refill_order.order_time - merchant.time_out ) as mtime_out";
  123. $order_by = "( {$cur_time} - refill_order.order_time - merchant.time_out ) desc";
  124. $order_list = $model_refill_order->getMerchantTimeOut($orders_cond, 200, $order_count, $fields, $order_by);
  125. $special_stat = $this->extra_stats($base_cond, $timeout_type,$cur_time);
  126. if(!empty($order_list)) {
  127. $order_list = $this->orderFormat($order_list, $merchant_list);
  128. }
  129. Tpl::output('stat', $order_stat);
  130. Tpl::output('count', $special_stat);
  131. Tpl::output('merchant_stat', $merchant_stat);
  132. Tpl::output('order_list', $order_list);
  133. Tpl::output('merchant_list', $merchant_list);
  134. Tpl::output('provider_list', $provider_list);
  135. Tpl::output('show_page', $model_refill_order->showpage());
  136. Tpl::showpage('refill.order.send.index');
  137. }
  138. private function extra_stats($base_cond, $timeout_type,$cur_time): array
  139. {
  140. $stat_order = function ($cond)
  141. {
  142. $stat = Model('')->table('refill_order,vr_order')->join('inner')
  143. ->on('refill_order.order_id=vr_order.order_id')
  144. ->field('count(*) as order_count ')
  145. ->where($cond)->find();
  146. return $stat['order_count'];
  147. };
  148. $result = [];
  149. $start_day = strtotime("-5 days",$cur_time);
  150. $extra_conds = [
  151. ['between', [$cur_time - 3600, $cur_time - 1800]],
  152. ['between', [$start_day, $cur_time - 3600]]
  153. ];
  154. if (array_key_exists($timeout_type, $this->mTimeouts)) {
  155. $time_out = $this->mTimeouts[$timeout_type];
  156. $extra_conds[] = ['_multi' => true,
  157. ['egt', $start_day],
  158. ['lt', $cur_time - $time_out]];
  159. }
  160. foreach ($extra_conds as $stat_cond)
  161. {
  162. if (!empty($time_out)) {
  163. $base_cond['vr_order.add_time&vr_order.add_time'] = $stat_cond;
  164. $base_cond['refill_order.order_time&refill_order.order_time'] = $stat_cond;
  165. } else {
  166. $base_cond['refill_order.order_time'] = $stat_cond;
  167. $base_cond['vr_order.add_time'] = $stat_cond;
  168. }
  169. $result[] = $stat_order($base_cond);
  170. }
  171. return $result;
  172. }
  173. private function merchant_timeout_stats($cond)
  174. {
  175. unset($cond['refill_order.mchid']);
  176. unset($cond['vr_order.store_id']);
  177. $stats = Model('')->table('refill_order,vr_order,merchant')
  178. ->join('inner,inner')
  179. ->on('refill_order.order_id=vr_order.order_id,refill_order.mchid=merchant.mchid')
  180. ->field('count(*) as order_count, sum(refill_amount) as refill_amounts, merchant.mchid, merchant.company_name, merchant.name')
  181. ->where($cond)
  182. ->group('refill_order.mchid')
  183. ->order('order_count desc')
  184. ->select();
  185. $special_stat = [];
  186. $order_stat = ['order_count' => 0, 'refill_amounts' => 0];
  187. if(empty($stats)) return [$special_stat, $order_stat];
  188. foreach ($stats as $stat) {
  189. $mchid = intval($stat['mchid']);
  190. $special_stat[$mchid] = [
  191. 'mchid' => $mchid, 'order_count' => $stat['order_count'], 'refill_amounts' => $stat['refill_amounts'],
  192. 'company_name' => $stat['company_name'], 'name' => $stat['name']
  193. ];
  194. $order_stat['order_count'] += $stat['order_count'];
  195. $order_stat['refill_amounts'] += $stat['refill_amounts'];
  196. }
  197. return [$special_stat, $order_stat];
  198. }
  199. private function notify_time($cur_time,$period)
  200. {
  201. $start_day = strtotime("-5 days",$cur_time);
  202. $time_cond['vr_order.add_time&vr_order.add_time'] = ['_multi' => true,
  203. ['egt', $start_day],
  204. ['lt', $cur_time]];
  205. $time_cond['refill_order.order_time&refill_order.order_time'] = ['_multi' => true,
  206. ['egt', $start_day],
  207. ['lt', $cur_time]];
  208. $time_cond['refill_order.commit_time&refill_order.commit_time'] = ['_multi' => true,
  209. ['egt', $start_day],
  210. ['lt', $cur_time - $period]];
  211. return $time_cond;
  212. }
  213. public function monitor_notifyOp()
  214. {
  215. $model_refill_order = Model('refill_order');
  216. $base_cond['refill_order.inner_status'] = 0;
  217. $base_cond['vr_order.order_state'] = ORDER_STATE_SEND;
  218. $card_type = $_GET['card_type'];
  219. if (!empty($_GET['store_id'])) {
  220. $base_cond['vr_order.store_id'] = $_GET['store_id'];
  221. }
  222. $cur_time = time();
  223. $period = 180;
  224. if(!empty($_GET['time'])) {
  225. $period = intval($_GET['time']);
  226. }else{
  227. $_GET['time'] = $period;
  228. }
  229. $time_cond = $this->notify_time($cur_time,$period);
  230. if (!empty($_GET['mchid'])) {
  231. $base_cond['refill_order.mchid'] = $_GET['mchid'];
  232. }
  233. if (!empty($card_type))
  234. {
  235. if (in_array($card_type, ['1', '2', '4', '5', '6', '7'])) {
  236. $base_cond['refill_order.card_type'] = $card_type;
  237. }
  238. if ($card_type == 'oil') {
  239. $base_cond['refill_order.card_type'] = ['in', ['1', '2']];
  240. }
  241. if ($card_type == 'phone') {
  242. $base_cond['refill_order.card_type'] = ['in', ['4', '5', '6']];
  243. }
  244. }
  245. if (!empty($_GET['quality'])) {
  246. $base_cond['refill_order.quality'] = $_GET['quality'];
  247. }
  248. $orders_cond = array_merge($base_cond,$time_cond);
  249. if (!empty($_GET['order_query'])) {
  250. $this->updateOrderSend($orders_cond);
  251. return;
  252. }
  253. if (!empty($_GET['export'])) {
  254. $this->RefillOrderExport($orders_cond, '渠道回调超时导出', 'time_out_order');
  255. return;
  256. }
  257. $mchids = Model('')->table('refill_order,vr_order')
  258. ->join('inner')
  259. ->on('refill_order.order_id=vr_order.order_id')
  260. ->field('DISTINCT refill_order.mchid')
  261. ->where($orders_cond)
  262. ->group('refill_order.mchid')
  263. ->order('mchid asc')
  264. ->select();
  265. $mchids = array_column($mchids, 'mchid');
  266. $merchant_list = $this->merchants(['mchid' => ['in', $mchids]]);
  267. $provider_list = $this->providers();
  268. //耗时
  269. $fields = "refill_order.*,vr_order.order_state";
  270. $order_by = "({$cur_time} - refill_order.commit_time) desc";
  271. [$special_stat, $order_stat] = $this->provider_timeout_stats($orders_cond, $provider_list);
  272. if (empty($_GET['store_id'])) {
  273. $order_count = $order_stat['order_count'];
  274. }else{
  275. $order_count = $special_stat[$_GET['store_id']]['order_count'];
  276. }
  277. $order_list = $model_refill_order->getMerchantTimeOut($orders_cond, 200, $order_count, $fields, $order_by);
  278. if(!empty($order_list)) {
  279. $order_list = $this->orderFormat($order_list, $merchant_list);
  280. }
  281. Tpl::output('stat', $order_stat);
  282. Tpl::output('special_stat', $special_stat);
  283. Tpl::output('order_list', $order_list);
  284. Tpl::output('merchant_list', $merchant_list);
  285. Tpl::output('provider_list', $provider_list);
  286. Tpl::output('show_page', $model_refill_order->showpage());
  287. Tpl::showpage('refill.order.monitor.notify');
  288. }
  289. private function provider_timeout_stats($cond, $provider_list)
  290. {
  291. unset($cond['refill_order.mchid']);
  292. unset($cond['vr_order.store_id']);
  293. $stats = Model('')->table('refill_order,vr_order')
  294. ->join('inner')
  295. ->on('refill_order.order_id=vr_order.order_id')
  296. ->field('count(*) as order_count, store_id, sum(refill_amount) as refill_amounts')
  297. ->where($cond)
  298. ->group('vr_order.store_id')
  299. ->order('order_count desc')
  300. ->select();
  301. $special_stat = [];
  302. $order_stat = ['order_count' => 0, 'refill_amounts' => 0];
  303. if(empty($stats)) return [$special_stat, $order_stat];
  304. foreach ($provider_list as $provider) {
  305. $providers[$provider['store_id']] = $provider;
  306. }
  307. ksort($providers);
  308. foreach ($stats as $stat) {
  309. $store_id = intval($stat['store_id']);
  310. $special_stat[$store_id] = [
  311. 'store_id' => $store_id, 'order_count' => $stat['order_count'], 'refill_amounts' => $stat['refill_amounts'],
  312. 'store_name' => $providers[$store_id]['store_name'], 'opened' =>$providers[$store_id]['opened']
  313. ];
  314. $order_stat['order_count'] += $stat['order_count'];
  315. $order_stat['refill_amounts'] += $stat['refill_amounts'];
  316. }
  317. return [$special_stat, $order_stat];
  318. }
  319. public function ajaxProviderTimeoutOp()
  320. {
  321. $base_cond['refill_order.inner_status'] = 0;
  322. $base_cond['vr_order.order_state'] = ORDER_STATE_SEND;
  323. if (!empty($card_type)) {
  324. if (in_array($card_type, ['1', '2', '4', '5', '6', '7'])) {
  325. $base_cond['refill_order.card_type'] = $card_type;
  326. }
  327. if ($card_type == 'oil') {
  328. $base_cond['refill_order.card_type'] = ['in', ['1', '2']];
  329. }
  330. if ($card_type == 'phone') {
  331. $base_cond['refill_order.card_type'] = ['in', ['4', '5', '6']];
  332. }
  333. }
  334. if (!empty($_GET['quality'])) {
  335. $base_cond['refill_order.quality'] = $_GET['quality'];
  336. }
  337. $cur_time = time();
  338. $period = 180;
  339. if(!empty($_GET['time'])) {
  340. $period = intval($_GET['time']);
  341. }
  342. $time_cond = $this->notify_time($cur_time,$period);
  343. $orders_cond = array_merge($base_cond,$time_cond);
  344. $provider_list = $this->providers();
  345. [$special_stat, $order_stat] = $this->provider_timeout_stats($orders_cond, $provider_list);
  346. echo json_encode(['special_stat' => $special_stat, 'order_stat' =>$order_stat]);
  347. }
  348. private function RefillOrderExport($cond, $method_name = '', $type='order')
  349. {
  350. $result = [];
  351. if($type == 'order') {
  352. $result = Model('refill_order')->getAllOrders($cond);
  353. }elseif($type == 'time_out_order'){
  354. $result = Model('refill_order')->getAllTimeOutOrders($cond);
  355. }
  356. $this->createExcel($result, $method_name);
  357. }
  358. private function createExcel($data = [], $method_name = '')
  359. {
  360. Language::read('export');
  361. import('libraries.excel');
  362. $excel_obj = new Excel();
  363. $excel_data = array();
  364. //设置样式
  365. $excel_obj->setStyle(array('id' => 's_title', 'Font' => array('FontName' => '宋体', 'Size' => '12', 'Bold' => '1')));
  366. //header
  367. $excel_data[0][] = array('styleid' => 's_title', 'data' => '商户号');
  368. $excel_data[0][] = array('styleid' => 's_title', 'data' => '客户订单号');
  369. $excel_data[0][] = array('styleid' => 's_title', 'data' => '平台单号');
  370. $excel_data[0][] = array('styleid' => 's_title', 'data' => '面额');
  371. $excel_data[0][] = array('styleid' => 's_title', 'data' => '充值卡号');
  372. $excel_data[0][] = array('styleid' => 's_title', 'data' => '充值卡类型');
  373. $excel_data[0][] = array('styleid' => 's_title', 'data' => '下单日期');
  374. $excel_data[0][] = array('styleid' => 's_title', 'data' => '完成日期');
  375. $excel_data[0][] = array('styleid' => 's_title', 'data' => '官方流水号');
  376. $excel_data[0][] = array('styleid' => 's_title', 'data' => '订单状态');
  377. $excel_data[0][] = array('styleid' => 's_title', 'data' => '扣款金额');
  378. //data
  379. foreach ((array)$data as $v) {
  380. $tmp = array();
  381. $tmp[] = array('data' => $v['mchid']);
  382. $tmp[] = array('data' => $v['mch_order']);
  383. $tmp[] = array('data' => $v['order_sn']);
  384. $tmp[] = array('data' => $v['refill_amount']);
  385. $tmp[] = array('data' => $v['card_no']);
  386. $tmp[] = array('data' => $this->scard_type($v['card_type']));
  387. $tmp[] = array('data' => date('Y-m-d H:i:s', $v['order_time']));
  388. if (empty($v['notify_time'])) {
  389. $tmp[] = array('data' => '');
  390. } else {
  391. $tmp[] = array('data' => date('Y-m-d H:i:s', $v['notify_time']));
  392. }
  393. $tmp[] = array('data' => $v['official_sn']);
  394. $tmp[] = array('data' => orderState($v));
  395. $tmp[] = array('data' => $v['mch_amount']);
  396. $excel_data[] = $tmp;
  397. }
  398. $excel_data = $excel_obj->charset($excel_data, CHARSET);
  399. $excel_obj->addArray($excel_data);
  400. $excel_obj->addWorksheet($excel_obj->charset(L('exp_od_order'), CHARSET));
  401. $excel_obj->generateXML($method_name . date('Y-m-d-H', time()));
  402. }
  403. public function neterr_orderOp()
  404. {
  405. $model_refill_order = Model('refill_order');
  406. if (!empty($_GET['store_id'])) {
  407. $condition['vr_order.store_id'] = $_GET['store_id'];
  408. }
  409. $condition['refill_order.inner_status'] = 0;
  410. $condition['refill_order.neterr'] = 1;
  411. $condition['vr_order.order_state'] = ORDER_STATE_PAY;
  412. $cur_time = time();
  413. $start_day = strtotime("-5 days",$cur_time);
  414. $condition['vr_order.add_time&vr_order.add_time'] = ['_multi' => true,
  415. ['egt', $start_day],
  416. ['lt', $cur_time]];
  417. $condition['refill_order.order_time&refill_order.order_time'] = ['_multi' => true,
  418. ['egt', $start_day],
  419. ['lt', $cur_time]];
  420. if (!empty($_GET['order_query'])) {
  421. $this->updateOrderSend($condition);
  422. return;
  423. }
  424. if (!empty($_GET['export'])) {
  425. $this->RefillOrderExport($condition, '网络错误订单导出');
  426. return;
  427. }
  428. $merchant_list = $this->merchants();
  429. $provider_list = $this->providers();
  430. //耗时
  431. $fields = "refill_order.*,vr_order.order_state";
  432. $order_by = "refill_order.commit_time asc";
  433. [$special_stat, $order_stat] = $this->provider_timeout_stats($condition, $provider_list);
  434. $order_list = $model_refill_order->getMerchantOrderList($condition, 200, $order_stat['order_count'],$fields, $order_by);
  435. $order_list = $this->orderFormat($order_list, $merchant_list);
  436. Tpl::output('stat', $order_stat);
  437. Tpl::output('special_stat', $special_stat);
  438. Tpl::output('order_list', $order_list);
  439. Tpl::output('show_page', $model_refill_order->showpage());
  440. Tpl::showpage('refill.order.neterr.index');
  441. }
  442. public function neterr_order_manualOp()
  443. {
  444. $type = $_GET['type'];
  445. $official_sn = $_GET['official_sn'] ?? '';
  446. if ($type != 'success' && $type != 'cancel') {
  447. showMessage('手动操作类型错误');
  448. }
  449. $order_ids = $_GET['order_ids'];
  450. $model_refill_order = Model('refill_order');
  451. $condition['refill_order.order_id'] = ['in', $order_ids];
  452. $condition['refill_order.inner_status'] = 0;
  453. $condition['refill_order.neterr'] = 1;
  454. $condition['vr_order.order_state'] = ORDER_STATE_PAY;
  455. $order_list = $model_refill_order->getMerchantOrderList($condition);
  456. if (empty($order_list)) {
  457. showMessage('暂无数据');
  458. }
  459. $logic_vr_order = Logic("vr_order");
  460. $mod_vr_order = Model('vr_order');
  461. foreach ($order_list as $order) {
  462. $order_id = $order['order_id'];
  463. if ($type == 'success') {
  464. $logic_vr_order->changeOrderStateSuccess($order_id, true);
  465. if (!empty($official_sn)) {
  466. $model_refill_order->edit($order_id, ['official_sn' => $official_sn]);
  467. }
  468. } elseif ($type == 'cancel') {
  469. $order_info = $mod_vr_order->getOrderInfo(['order_id' => $order_id]);
  470. $logic_vr_order->changeOrderStateCancel($order_info, '', "充值失败", true, true);
  471. } else {
  472. continue;
  473. }
  474. if ($order['notify_time'] == 0) {
  475. $model_refill_order->edit($order_id, ['notify_state' => 1, 'notify_time' => time()]);
  476. }
  477. util::pop_queue_order($order['mchid'], $order['mch_order']);
  478. QueueClient::push("NotifyMerchantComplete", ['order_id' => $order_id, 'manual' => true]);
  479. }
  480. showMessage('操作成功');
  481. }
  482. public function orderFormat($order_list, $merchant_list): array
  483. {
  484. $merchants = [];
  485. foreach ($merchant_list as $value) {
  486. $merchants[$value['mchid']] = $value;
  487. }
  488. $cur_time = time();
  489. foreach ($order_list as $order_id => $order_info) {
  490. $order_list[$order_id]['card_type_text'] = $this->scard_type($order_info['card_type']);
  491. $order_list[$order_id]['mch_name'] = $merchants[$order_info['mchid']]['company_name'];
  492. if ($order_info['notify_time'] > 0) {
  493. $total_diff_time = $order_info['notify_time'] - $order_info['order_time'];
  494. $diff_time = $order_info['notify_time'] - $order_info['commit_time'];
  495. } else {
  496. $total_diff_time = $cur_time - $order_info['order_time'];
  497. $diff_time = $cur_time - $order_info['commit_time'];
  498. }
  499. if($order_info['mtime_out'] > 0) {
  500. $order_list[$order_id]['mtime_out_text'] = $this->elapse_time($order_info['mtime_out']);
  501. }
  502. $order_list[$order_id]['diff_time'] = $diff_time;
  503. $order_list[$order_id]['diff_time_text'] = $this->elapse_time($diff_time);
  504. $order_list[$order_id]['total_diff_time'] = $total_diff_time;
  505. $order_list[$order_id]['total_diff_time_text'] = $this->elapse_time($total_diff_time);
  506. $order_list[$order_id]['quality_text'] = $this->quality_format($order_info['quality'], $order_info['card_type']);
  507. if ($total_diff_time > $merchants[$order_info['mchid']]['time_out'] && $order_info['order_state'] == ORDER_STATE_SEND) {
  508. $order_list[$order_id]['time_out_state'] = 0;
  509. if (in_array($order_info['card_type'], [mtopcard\PetroChinaCard, mtopcard\SinopecCard])) {
  510. $order_list[$order_id]['time_out_state'] = 1;
  511. }
  512. if (in_array($order_info['card_type'], [mtopcard\ChinaMobileCard, mtopcard\ChinaUnicomCard, mtopcard\ChinaTelecomCard])) {
  513. if (in_array($order_info['quality'], [
  514. refill\Quality::SlowTwentyFour,
  515. refill\Quality::SlowSix,
  516. refill\Quality::SlowTwo,
  517. refill\Quality::SlowFortyEight,
  518. refill\Quality::SlowSeventyTwo])) {
  519. $order_list[$order_id]['time_out_state'] = 2;
  520. } elseif (in_array($order_info['mchid'], [10132])) {
  521. //重点机构
  522. $order_list[$order_id]['time_out_state'] = 3;
  523. } else {
  524. $order_list[$order_id]['time_out_state'] = 4;
  525. }
  526. }
  527. } else {
  528. $order_list[$order_id]['time_out_state'] = 0;
  529. }
  530. }
  531. return $order_list;
  532. }
  533. public function notify_err_orderOp()
  534. {
  535. $model_refill_order = Model('refill_order');
  536. $order_state_cancel = ORDER_STATE_CANCEL;
  537. $order_state_success = ORDER_STATE_SUCCESS;
  538. $condition['refill_order.inner_status'] = 0;
  539. $condition['refill_order.is_retrying'] = 0;
  540. $condition['vr_order.order_state'] = ['in', "{$order_state_cancel},{$order_state_success}"];
  541. $condition['refill_order.mch_notify_state'] = ['in', "0,2"];
  542. $condition['refill_order.mch_notify_times'] = ['gt', 0];
  543. if (empty($_GET['time'])) {
  544. $_GET['time'] = 1;
  545. }
  546. if (empty($_GET['notify_time'])) {
  547. $_GET['notify_time'] = 180;
  548. }
  549. $cur_time = time();
  550. $time = $_GET['time'] * 3600;
  551. $condition['refill_order.order_time'] = [['egt', ($cur_time - $time)], ['lt', $cur_time], 'and'];
  552. $condition['vr_order.add_time'] = [['egt', ($cur_time - $time)], ['lt', $cur_time], 'and'];
  553. $notify_time = $_GET['notify_time'];
  554. if($notify_time > 0) {
  555. $start_day = strtotime("-5 days",$cur_time);
  556. $condition['refill_order.notify_time'] = [['egt', $start_day], ['lt', ($cur_time - $notify_time)], 'and'];
  557. }
  558. $order_list = $model_refill_order->getMerchantOrderList($condition, 200, 0,'refill_order.*,vr_order.order_state', '', 1000);
  559. $merchant_list = $this->merchants();
  560. $order_list = $this->orderFormat($order_list, $merchant_list);
  561. Tpl::output('order_list', $order_list);
  562. Tpl::output('show_page', $model_refill_order->showpage());
  563. Tpl::showpage('refill.order.notify.err.index');
  564. }
  565. public function notifyerr_all_notifyOp()
  566. {
  567. if (empty($_GET['time']) || empty($_GET['notify_time'])) {
  568. showMessage('日期条件错误');
  569. }
  570. $model_refill_order = Model('refill_order');
  571. $order_state_cancel = ORDER_STATE_CANCEL;
  572. $order_state_success = ORDER_STATE_SUCCESS;
  573. $condition['refill_order.inner_status'] = 0;
  574. $condition['vr_order.order_state'] = ['in', "{$order_state_cancel},{$order_state_success}"];
  575. $condition['refill_order.mch_notify_state'] = ['in', "0,2"];
  576. $condition['refill_order.is_retrying'] = 0;
  577. $time = $_GET['time'] * 3600;
  578. $condition['refill_order.order_time'] = ['gt', (time() - $time)];
  579. $notify_time = $_GET['notify_time'];
  580. $condition['refill_order.notify_time'] = ['lt', (time() - $notify_time)];
  581. $order_list = $model_refill_order->getMerchantOrderList($condition, '', 0,'refill_order.*,vr_order.order_state', 'refill_order.notify_time asc', 1000);
  582. foreach ($order_list as $order) {
  583. QueueClient::push("NotifyMerchantComplete", ['order_id' => $order['order_id'], 'manual' => true]);
  584. }
  585. showMessage('操作成功');
  586. }
  587. private function updateOrderSend($condition)
  588. {
  589. $condition['order_state'] = ORDER_STATE_SEND;
  590. $orders = $this->getAllTimeOutOrders($condition);
  591. if (!empty($orders)) {
  592. foreach ($orders as $order) {
  593. $order_id = $order['order_id'];
  594. QueueClient::push("QueryRefillState", ['order_id' => $order_id]);
  595. }
  596. }
  597. showMessage('操作成功');
  598. }
  599. private function getAllTimeOutOrders($condition): array
  600. {
  601. $len = 1000;
  602. $i = 0;
  603. $orders = [];
  604. while (true) {
  605. $start = $i * $len;
  606. $items = Model('')->table('refill_order,vr_order,merchant')
  607. ->field('refill_order.*,vr_order.order_state')
  608. ->join('inner,inner')
  609. ->on('refill_order.order_id=vr_order.order_id,refill_order.mchid=merchant.mchid')
  610. ->where($condition)
  611. ->order('refill_order.order_time desc')
  612. ->limit("{$start},{$len}")->select();
  613. $orders = array_merge($orders,$items);
  614. if (empty($items) || count($items) < $len) {
  615. break;
  616. }
  617. $i++;
  618. }
  619. return $orders;
  620. }
  621. }