ordersendlist.php 30 KB

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