ordersendlist.php 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258
  1. <?php
  2. require_once(BASE_HELPER_PATH . '/refill/util.php');
  3. require_once(BASE_HELPER_PATH . '/task/task_helper.php');
  4. use refill\util;
  5. class ordersendlistControl extends SystemControl
  6. {
  7. private $mTimeouts;
  8. public function __construct()
  9. {
  10. $this->mTimeouts = [3 => 180, 4 => 300, 5 => 600, 6 => 900, 7 => 7200];
  11. parent::__construct();
  12. }
  13. private function time_cond($timeout_type, $card_type, $cur_time, $manual_time)
  14. {
  15. $mintime_getter = function ()
  16. {
  17. $mod = Model();
  18. $item = $mod->table('refill_detail')->field('min(order_time) as mintime')->where(['order_state' => 30])->find();
  19. if(empty($item['mintime'])) {
  20. return time() - 3600;
  21. }
  22. else {
  23. return intval($item['mintime']);
  24. }
  25. };
  26. $mchid_filter = function ($time_out) {
  27. $mchids = Model('')->table('merchant')->where(['time_out' => ['elt', $time_out]])->field('mchid')->select();
  28. $mchids = array_column($mchids, 'mchid');
  29. $mchids = implode(',', $mchids);
  30. return $mchids;
  31. };
  32. $period = 20;
  33. $start_day = $mintime_getter(); //strtotime("-5 days",$cur_time);
  34. $time_cond = [];
  35. $mch_cond = [];
  36. if ($timeout_type > 0)
  37. {
  38. if (in_array($timeout_type, [1, 2, 8, 9, 10, 11, 12, 13]))
  39. {
  40. if ($timeout_type === 1) {
  41. $time_cond['refill_order.order_time'] = ['between', [$cur_time - 3600, $cur_time - 1800]];
  42. $time_cond['vr_order.add_time'] = ['between', [$cur_time - 3600, $cur_time]];
  43. }
  44. if ($timeout_type === 2) {
  45. $time_cond['refill_order.order_time'] = ['between', [$cur_time - 5400, $cur_time - 3600]];
  46. $time_cond['vr_order.add_time'] = ['between', [$cur_time - 5400, $cur_time]];
  47. }
  48. if ($timeout_type === 8) {
  49. $time_cond['refill_order.order_time'] = ['between', [$cur_time - 7200, $cur_time - 5400]];
  50. $time_cond['vr_order.add_time'] = ['between', [$cur_time - 7200, $cur_time]];
  51. }
  52. if ($timeout_type === 9) {
  53. $time_cond['refill_order.order_time'] = ['between', [$cur_time - 9000, $cur_time - 7200]];
  54. $time_cond['vr_order.add_time'] = ['between', [$cur_time - 9000, $cur_time]];
  55. }
  56. if ($timeout_type === 10) {
  57. $time_cond['refill_order.order_time'] = ['between', [$cur_time - 10800, $cur_time - 9000]];
  58. $time_cond['vr_order.add_time'] = ['between', [$cur_time - 10800, $cur_time]];
  59. }
  60. if ($timeout_type === 11) {
  61. $time_cond['refill_order.order_time'] = ['between', [$cur_time - 12600, $cur_time - 10800]];
  62. $time_cond['vr_order.add_time'] = ['between', [$cur_time - 12600, $cur_time]];
  63. }
  64. if ($timeout_type === 12) {
  65. $time_cond['refill_order.order_time'] = ['between', [$cur_time - 14400, $cur_time - 12600]];
  66. $time_cond['vr_order.add_time'] = ['between', [$cur_time - 14400, $cur_time]];
  67. }
  68. if ($timeout_type === 13) {
  69. $time_cond['refill_order.order_time'] = ['between', [$start_day, $cur_time - 14400]];
  70. $time_cond['vr_order.add_time'] = ['between', [$start_day, $cur_time]];
  71. }
  72. }
  73. elseif (in_array($timeout_type, [3, 4, 5, 6, 7])) {
  74. $time_out = $this->mTimeouts[$timeout_type];
  75. $mchids = $mchid_filter($time_out);
  76. $time_cond['vr_order.add_time&vr_order.add_time'] = ['_multi' => true, ['egt', $start_day], ['lt', $cur_time]];
  77. $time_cond['refill_order.order_time&refill_order.order_time'] = ['_multi' => true, ['egt', $start_day], ['lt', $cur_time - $time_out]];
  78. $mch_cond['refill_order.mchid'] = ['in', $mchids];
  79. $card_type = 'phone';
  80. }
  81. else {
  82. $time_cond = [];
  83. }
  84. } else if ($manual_time && $manual_time < 24) {
  85. $end_offset = intval($manual_time * 3600);
  86. $time_cond['refill_order.order_time'] = ['between', [$start_day, $cur_time - $end_offset]];
  87. $time_cond['vr_order.add_time'] = ['between', [$start_day, $cur_time]];
  88. }
  89. else
  90. {
  91. $time_cond['vr_order.add_time&vr_order.add_time'] = ['_multi' => true,
  92. ['egt', $start_day],
  93. ['lt', $cur_time]];
  94. $time_cond['refill_order.order_time&refill_order.order_time&refill_order.order_time'] = ['_multi' => true,
  95. ['egt', $start_day],
  96. ['lt', $cur_time],
  97. ['exp', "refill_order.order_time < {$cur_time} - merchant.time_out + {$period}"]];
  98. }
  99. return [$time_cond, $mch_cond, $card_type];
  100. }
  101. public function indexOp()
  102. {
  103. $model_refill_order = Model('refill_order');
  104. $base_cond['refill_order.inner_status'] = 0;
  105. $base_cond['vr_order.order_state'] = ORDER_STATE_SEND;
  106. $timeout_type = intval($_GET['time']);
  107. $card_type = $_GET['card_type'];
  108. $manual_time = $_GET['manual_time'];
  109. if (!empty($_GET['store_id'])) {
  110. $base_cond['vr_order.store_id'] = $_GET['store_id'];
  111. }
  112. $cur_time = time();
  113. [$time_cond, $mch_cond, $card_type] = $this->time_cond($timeout_type, $card_type, $cur_time, $manual_time);
  114. if (!empty($_GET['mchid'])) {
  115. $base_cond['refill_order.mchid'] = $_GET['mchid'];
  116. } elseif(!empty($_GET['no_mchid'])) {
  117. $no_mchid = explode(',', $_GET['no_mchid']);
  118. $base_cond['refill_order.mchid'] = ['not in', $no_mchid];
  119. } elseif(!empty($mch_cond)) {
  120. $base_cond = array_merge($base_cond,$mch_cond);
  121. }
  122. if (!empty($card_type))
  123. {
  124. if (in_array($card_type, ['1', '2', '4', '5', '6', '7'])) {
  125. $base_cond['refill_order.card_type'] = $card_type;
  126. }
  127. if ($card_type == 'oil') {
  128. $base_cond['refill_order.card_type'] = ['in', ['1', '2']];
  129. }
  130. if ($card_type == 'phone') {
  131. $base_cond['refill_order.card_type'] = ['in', ['4', '5', '6']];
  132. }
  133. }
  134. if (!empty($_GET['refill_amount'])) {
  135. $base_cond['refill_order.refill_amount'] = $_GET['refill_amount'];
  136. }
  137. if (!empty($_GET['quality'])) {
  138. $base_cond['refill_order.quality'] = $_GET['quality'];
  139. }
  140. $orders_cond = array_merge($base_cond,$time_cond);
  141. if (!empty($_GET['order_query'])) {
  142. $this->updateOrderSend($orders_cond);
  143. return;
  144. }
  145. if (!empty($_GET['export'])) {
  146. $this->RefillOrderExport($orders_cond, '商户超时监控导出', 'time_out_order');
  147. return;
  148. }
  149. // $store_ids = Model('')->table('refill_order,vr_order,merchant')
  150. // ->join('inner,inner')
  151. // ->on('refill_order.order_id=vr_order.order_id,refill_order.mchid=merchant.mchid')
  152. // ->field('DISTINCT vr_order.store_id')
  153. // ->where($orders_cond)
  154. // ->group('vr_order.store_id')
  155. // ->order('store_id asc')
  156. // ->select();
  157. // $store_ids = array_column($store_ids, 'store_id');
  158. $merchant_list = $this->merchants();
  159. // $provider_list = $this->providers(['store.store_id' => ['in', $store_ids]]);
  160. $provider_list = $this->providers();
  161. [$merchant_stat, $order_stat] = $this->merchant_timeout_stats($orders_cond);
  162. if (empty($_GET['mchid'])) {
  163. $order_count = $order_stat['order_count'];
  164. }else{
  165. $order_count = $merchant_stat[$_GET['mchid']]['order_count'];
  166. }
  167. $fields = "refill_order.*,vr_order.order_state,( {$cur_time} - refill_order.order_time - merchant.time_out ) as mtime_out";
  168. $order_by = "mtime_out desc";
  169. $order_list = $model_refill_order->getMerchantTimeOut($orders_cond, 200, $order_count, $fields, $order_by);
  170. $special_stat = $this->extra_stats($base_cond, $timeout_type,$cur_time);
  171. if(!empty($order_list)) {
  172. $order_list = $this->orderFormat($order_list, $merchant_list);
  173. }
  174. Tpl::output('stat', $order_stat);
  175. Tpl::output('count', $special_stat);
  176. Tpl::output('merchant_stat', $merchant_stat);
  177. Tpl::output('order_list', $order_list);
  178. Tpl::output('merchant_list', $merchant_list);
  179. Tpl::output('provider_list', $provider_list);
  180. Tpl::output('except_stat', $this->except_stat());
  181. Tpl::output('show_page', $model_refill_order->showpage());
  182. Tpl::showpage('refill.order.send.index');
  183. }
  184. public function monitor_transferOp()
  185. {
  186. $merchants_getter = function ($mchids)
  187. {
  188. $mches = Model('')->table('merchant')
  189. ->field('mchid, company_name, name')
  190. ->where(['mchid' => ['in',$mchids] ])
  191. ->select();
  192. return $mches;
  193. };
  194. $model_refill_order = Model('refill_order');
  195. $base_cond['refill_order.inner_status'] = 0;
  196. $all_mchids = $this->getAllTransferMchid();
  197. if (!empty($_GET['mchid'])) {
  198. $base_cond['refill_order.mchid'] = $_GET['mchid'];
  199. } else {
  200. $base_cond['refill_order.mchid'] = ['in', $all_mchids];
  201. }
  202. $card_type = $_GET['card_type'];
  203. if (!empty($card_type))
  204. {
  205. if (in_array($card_type, ['1', '2', '4', '5', '6', '7'])) {
  206. $base_cond['refill_order.card_type'] = $card_type;
  207. }
  208. if ($card_type == 'oil') {
  209. $base_cond['refill_order.card_type'] = ['in', ['1', '2']];
  210. }
  211. if ($card_type == 'phone') {
  212. $base_cond['refill_order.card_type'] = ['in', ['4', '5', '6']];
  213. }
  214. }
  215. if (!empty($_GET['refill_amount'])) {
  216. $base_cond['refill_order.refill_amount'] = $_GET['refill_amount'];
  217. }
  218. $cur_time = time();
  219. $start_unixtime = intval(strtotime($_GET['query_start_time']));
  220. $end_unixtime = intval(strtotime($_GET['query_end_time']));
  221. if(!empty($_GET['time'])) {
  222. $end_unixtime = $cur_time + $_GET['time'];
  223. }
  224. if ($start_unixtime > 0 && $end_unixtime > $start_unixtime) {
  225. $base_cond['refill_order.order_time'] = [['egt', $start_unixtime], ['lt', $end_unixtime], 'and'];
  226. } elseif ($start_unixtime > 0) {
  227. $base_cond['refill_order.order_time'] = ['egt', $start_unixtime];
  228. } elseif ($end_unixtime > 0) {
  229. $base_cond['refill_order.order_time'] = ['lt', $end_unixtime];
  230. } else {
  231. $_GET['query_start_time'] = date('Y-m-d 00:00:00', time());
  232. $start = strtotime($_GET['query_start_time']);
  233. $base_cond['refill_order.order_time'] = ['egt', $start];
  234. }
  235. //根据客户单号来识别订单是否返销
  236. $mod_buyback = Model('refill_buyback');
  237. $buyback_cond['refill_buyback.order_time'] = $base_cond['refill_order.order_time'];
  238. $buyback_cond['refill_order.order_time'] = $base_cond['refill_order.order_time'];
  239. $buyback_cond['vr_order.order_state'] = ORDER_STATE_SUCCESS;
  240. $buyback_list = $mod_buyback->getAllBuybackOrder($buyback_cond, 'distinct refill_order.mch_order');
  241. $buyback_mch_orders = array_column($buyback_list, 'mch_order');
  242. $order_state = $_GET['order_state'];
  243. if ($order_state === '-2' && !empty($buyback_mch_orders))
  244. {
  245. $base_cond['refill_order.mch_order'] = ['in', $buyback_mch_orders];
  246. }
  247. else if (in_array($_GET['order_state'], ['30', '40']))
  248. {
  249. $base_cond['vr_order.order_state'] = intval($_GET['order_state']);
  250. }
  251. else if ($_GET['order_state'] === '0')
  252. {
  253. $base_cond['vr_order.order_state'] = intval($_GET['order_state']);
  254. if (!empty($buyback_mch_orders)) {
  255. $base_cond['refill_order.mch_order'] = ['not in', $buyback_mch_orders];
  256. }
  257. }
  258. else if (empty($order_state))
  259. { //没选择订单状态,默认只显示充值中和已取消(未返销)
  260. $base_cond['vr_order.order_state'] = ['in', [ORDER_STATE_CANCEL, ORDER_STATE_SEND]];
  261. if (!empty($buyback_mch_orders)) {
  262. $base_cond['refill_order.mch_order'] = ['not in', $buyback_mch_orders];
  263. }
  264. }
  265. if (!empty($_GET['export'])) {
  266. $this->monitor_transfer_export($base_cond, $merchants_getter, $all_mchids);
  267. return;
  268. }
  269. if ($order_state === '-2' && empty($buyback_mch_orders))
  270. { //仅查询返销,不存在返销数据
  271. $order_list = [];
  272. }
  273. else
  274. {
  275. // $order_by = 'refill_order.order_time desc';
  276. // $order_list = Model('')->table('refill_order,vr_order,merchant')
  277. // ->join('inner,inner')
  278. // ->on('refill_order.order_id=vr_order.order_id,refill_order.mchid=merchant.mchid')
  279. // ->field("refill_order.*,vr_order.order_state,({$cur_time} - refill_order.order_time - merchant.time_out) as mtime_out")
  280. // ->where($base_cond)
  281. // ->order($order_by)
  282. // ->select();
  283. $order_list = $model_refill_order->getOrderMonitorTransfer($base_cond, 200, 5000,
  284. "refill_order.*,vr_order.order_state,({$cur_time} - refill_order.order_time - merchant.time_out) as mtime_out");
  285. $merchant_list = $merchants_getter($all_mchids);
  286. if(!empty($order_list))
  287. {
  288. $order_list = $this->orderFormat($order_list, $merchant_list);
  289. foreach ($order_list as $key => $item)
  290. {
  291. if (in_array($item['mch_order'], $buyback_mch_orders)) {
  292. $order_list[$key]['buyback'] = true;
  293. } else {
  294. $order_list[$key]['buyback'] = false;
  295. }
  296. }
  297. }
  298. }
  299. Tpl::output('order_list', $order_list);
  300. Tpl::output('merchant_list', $merchant_list);
  301. Tpl::output('except_stat', $this->except_stat());
  302. Tpl::output('show_page', $model_refill_order->showpage());
  303. Tpl::showpage('monitor_transfer');
  304. }
  305. private function getAllTransferMchid()
  306. {
  307. $mchid_parser = function ($mchid, $cfg)
  308. {
  309. $cfg = unserialize($cfg);
  310. if ($cfg === false) {
  311. return false;
  312. }
  313. $opened = intval($cfg['transfer_opened']);
  314. $tmchid = intval($cfg['transfer_mchid']);
  315. if ($opened == 1 && $tmchid > 0 && $tmchid != $mchid) {
  316. return $tmchid;
  317. } else {
  318. return false;
  319. }
  320. };
  321. $mchids = [];
  322. $i = 0;
  323. while (true)
  324. {
  325. $start = $i * 1000;
  326. $items = Model()->table('merchant')->field('mchid,transfer_cfg,timeout_transfer_cfg')->order('mchid asc')->limit("{$start},1000")->select();
  327. if (empty($items)) {
  328. return $mchids;
  329. }
  330. $i++;
  331. foreach ($items as $item)
  332. {
  333. $cfg_rt = $item['transfer_cfg'];
  334. $cfg_tm = $item['timeout_transfer_cfg'];
  335. $mchid = intval($item['mchid']);
  336. if (empty($cfg_rt) and empty($cfg_tm)) {
  337. continue;
  338. }
  339. $rt_mchid = $mchid_parser($mchid,$cfg_rt);
  340. $tm_mchid = $mchid_parser($mchid,$cfg_tm);
  341. if($rt_mchid !== false) {
  342. $mchids[] = $rt_mchid;
  343. }
  344. if($tm_mchid !== false) {
  345. $mchids[] = $tm_mchid;
  346. }
  347. }
  348. }
  349. }
  350. private function extra_stats($base_cond, $timeout_type,$cur_time): array
  351. {
  352. $stat_order = function ($cond)
  353. {
  354. $stat = Model('')->table('refill_order,vr_order')->join('inner')
  355. ->on('refill_order.order_id=vr_order.order_id')
  356. ->field('count(*) as order_count ')
  357. ->where($cond)->find();
  358. return $stat['order_count'];
  359. };
  360. $result = [];
  361. $start_day = strtotime("-5 days",$cur_time);
  362. $extra_conds = [
  363. ['between', [$cur_time - 3600, $cur_time - 1800]],
  364. ['between', [$start_day, $cur_time - 3600]]
  365. ];
  366. if (array_key_exists($timeout_type, $this->mTimeouts)) {
  367. $time_out = $this->mTimeouts[$timeout_type];
  368. $extra_conds[] = ['_multi' => true,
  369. ['egt', $start_day],
  370. ['lt', $cur_time - $time_out]];
  371. }
  372. foreach ($extra_conds as $stat_cond)
  373. {
  374. if (!empty($time_out)) {
  375. $base_cond['vr_order.add_time&vr_order.add_time'] = $stat_cond;
  376. $base_cond['refill_order.order_time&refill_order.order_time'] = $stat_cond;
  377. } else {
  378. $base_cond['refill_order.order_time'] = $stat_cond;
  379. $base_cond['vr_order.add_time'] = $stat_cond;
  380. }
  381. $result[] = $stat_order($base_cond);
  382. }
  383. return $result;
  384. }
  385. private function merchant_timeout_stats($cond)
  386. {
  387. unset($cond['refill_order.mchid']);
  388. unset($cond['vr_order.store_id']);
  389. $stats = Model('')->table('refill_order,vr_order,merchant')
  390. ->join('inner,inner')
  391. ->on('refill_order.order_id=vr_order.order_id,refill_order.mchid=merchant.mchid')
  392. ->field('count(*) as order_count, sum(refill_amount) as refill_amounts, merchant.mchid, merchant.company_name, merchant.name')
  393. ->where($cond)
  394. ->group('refill_order.mchid')
  395. ->order('order_count desc')
  396. ->select();
  397. $special_stat = [];
  398. $order_stat = ['order_count' => 0, 'refill_amounts' => 0];
  399. if(empty($stats)) return [$special_stat, $order_stat];
  400. foreach ($stats as $stat) {
  401. $mchid = intval($stat['mchid']);
  402. $special_stat[$mchid] = [
  403. 'mchid' => $mchid, 'order_count' => $stat['order_count'], 'refill_amounts' => $stat['refill_amounts'],
  404. 'company_name' => $stat['company_name'], 'name' => $stat['name']
  405. ];
  406. $order_stat['order_count'] += $stat['order_count'];
  407. $order_stat['refill_amounts'] += $stat['refill_amounts'];
  408. }
  409. return [$special_stat, $order_stat];
  410. }
  411. private function notify_time($cur_time,$period,$total_period)
  412. {
  413. $mintime_getter = function () {
  414. $mod = Model();
  415. $item = $mod->table('refill_detail')->field('min(order_time) as mintime')->where(['order_state'=>30])->find();
  416. if(empty($item['mintime'])) {
  417. return time() - 3600;
  418. }
  419. else {
  420. return intval($item['mintime']);
  421. }
  422. };
  423. $start = $mintime_getter();//strtotime("-5 days",$cur_time);
  424. // $today = strtotime(date('Y-m-d',time()));
  425. // $tomorrow = $today + 86400;
  426. $time_cond['vr_order.add_time&vr_order.add_time'] = ['_multi' => true,
  427. ['egt', $start],
  428. ['elt', $cur_time]];
  429. $time_cond['refill_order.order_time&refill_order.order_time'] = ['_multi' => true,
  430. ['egt', $start],
  431. ['elt', $cur_time]];
  432. $time_cond['refill_order.commit_time&refill_order.commit_time'] = ['_multi' => true,
  433. ['egt', $start],
  434. ['elt', $cur_time - $period]];
  435. if ($total_period > 0) {
  436. $time_cond['refill_order.order_time&refill_order.order_time'] = ['_multi' => true,
  437. ['egt', $start],
  438. ['elt', $cur_time - $total_period]];
  439. }
  440. return $time_cond;
  441. }
  442. public function monitor_notifyOp()
  443. {
  444. $model_refill_order = Model('refill_order');
  445. $base_cond['refill_order.inner_status'] = 0;
  446. $base_cond['vr_order.order_state'] = ORDER_STATE_SEND;
  447. $card_type = $_GET['card_type'];
  448. if (!empty($_GET['store_id'])) {
  449. $base_cond['vr_order.store_id'] = $_GET['store_id'];
  450. }
  451. $cur_time = time();
  452. $period = 180;
  453. if(!empty($_GET['time'])) {
  454. $period = intval($_GET['time']);
  455. }else{
  456. $_GET['time'] = $period;
  457. }
  458. $total_period = 0;
  459. if (!empty($_GET['total_time'])) {
  460. $total_period = intval($_GET['total_time']);
  461. }
  462. $time_cond = $this->notify_time($cur_time, $period, $total_period);
  463. if (!empty($_GET['mchid'])) {
  464. $base_cond['refill_order.mchid'] = $_GET['mchid'];
  465. }
  466. if (!empty($card_type))
  467. {
  468. if (in_array($card_type, ['1', '2', '4', '5', '6', '7'])) {
  469. $base_cond['refill_order.card_type'] = $card_type;
  470. }
  471. if ($card_type == 'oil') {
  472. $base_cond['refill_order.card_type'] = ['in', ['1', '2']];
  473. }
  474. if ($card_type == 'phone') {
  475. $base_cond['refill_order.card_type'] = ['in', ['4', '5', '6']];
  476. }
  477. }
  478. if (!empty($_GET['quality'])) {
  479. $base_cond['refill_order.quality'] = $_GET['quality'];
  480. }
  481. $orders_cond = array_merge($base_cond,$time_cond);
  482. if (!empty($_GET['order_query'])) {
  483. $this->updateOrderSend($orders_cond);
  484. return;
  485. }
  486. if (!empty($_GET['export'])) {
  487. $this->RefillOrderExport($orders_cond, '渠道回调超时导出', 'time_out_order');
  488. return;
  489. }
  490. $mchids = Model('')->table('refill_order,vr_order')
  491. ->join('inner')
  492. ->on('refill_order.order_id=vr_order.order_id')
  493. ->field('DISTINCT refill_order.mchid')
  494. ->where($orders_cond)
  495. ->group('refill_order.mchid')
  496. ->order('mchid asc')
  497. ->select();
  498. $mchids = array_column($mchids, 'mchid');
  499. $merchant_list = $this->merchants(['mchid' => ['in', $mchids]]);
  500. $provider_list = $this->providers();
  501. //耗时
  502. $fields = "refill_order.*,vr_order.order_state,({$cur_time} - refill_order.commit_time) as ctimeout";
  503. $order_by = "ctimeout desc";
  504. [$special_stat, $order_stat] = $this->provider_timeout_stats($orders_cond, $provider_list);
  505. if (empty($_GET['store_id'])) {
  506. $order_count = $order_stat['order_count'];
  507. }else{
  508. $order_count = $special_stat[$_GET['store_id']]['order_count'];
  509. }
  510. $order_list = $model_refill_order->getMerchantOrderList($orders_cond, 200, $order_count, $fields, $order_by);
  511. if(!empty($order_list)) {
  512. $order_list = $this->orderFormat($order_list, $merchant_list);
  513. }
  514. Tpl::output('stat', $order_stat);
  515. Tpl::output('special_stat', $special_stat);
  516. Tpl::output('order_list', $order_list);
  517. Tpl::output('merchant_list', $merchant_list);
  518. Tpl::output('provider_list', $provider_list);
  519. Tpl::output('except_stat', $this->except_stat());
  520. Tpl::output('show_page', $model_refill_order->showpage());
  521. Tpl::showpage('refill.order.monitor.notify');
  522. }
  523. private function provider_timeout_stats($cond, $provider_list)
  524. {
  525. unset($cond['refill_order.mchid']);
  526. unset($cond['vr_order.store_id']);
  527. $stats = Model('')->table('refill_order,vr_order')
  528. ->join('inner')
  529. ->on('refill_order.order_id=vr_order.order_id')
  530. ->field('count(*) as order_count, store_id, sum(refill_amount) as refill_amounts')
  531. ->where($cond)
  532. ->group('vr_order.store_id')
  533. ->order('order_count desc')
  534. ->select();
  535. $special_stat = [];
  536. $order_stat = ['order_count' => 0, 'refill_amounts' => 0];
  537. if(empty($stats)) return [$special_stat, $order_stat];
  538. foreach ($provider_list as $provider) {
  539. $providers[$provider['store_id']] = $provider;
  540. }
  541. ksort($providers);
  542. foreach ($stats as $stat) {
  543. $store_id = intval($stat['store_id']);
  544. $special_stat[$store_id] = [
  545. 'store_id' => $store_id, 'order_count' => $stat['order_count'], 'refill_amounts' => $stat['refill_amounts'],
  546. 'store_name' => $providers[$store_id]['store_name'], 'opened' =>$providers[$store_id]['opened']
  547. ];
  548. $order_stat['order_count'] += $stat['order_count'];
  549. $order_stat['refill_amounts'] += $stat['refill_amounts'];
  550. }
  551. return [$special_stat, $order_stat];
  552. }
  553. public function ajaxProviderTimeoutOp()
  554. {
  555. $base_cond['refill_order.inner_status'] = 0;
  556. $base_cond['vr_order.order_state'] = ORDER_STATE_SEND;
  557. if (!empty($card_type)) {
  558. if (in_array($card_type, ['1', '2', '4', '5', '6', '7'])) {
  559. $base_cond['refill_order.card_type'] = $card_type;
  560. }
  561. if ($card_type == 'oil') {
  562. $base_cond['refill_order.card_type'] = ['in', ['1', '2']];
  563. }
  564. if ($card_type == 'phone') {
  565. $base_cond['refill_order.card_type'] = ['in', ['4', '5', '6']];
  566. }
  567. }
  568. if (!empty($_GET['quality'])) {
  569. $base_cond['refill_order.quality'] = $_GET['quality'];
  570. }
  571. $cur_time = time();
  572. $period = 180;
  573. if(!empty($_GET['time'])) {
  574. $period = intval($_GET['time']);
  575. }
  576. $total_period = 0;
  577. if (!empty($_GET['total_time'])) {
  578. $total_period = intval($_GET['total_time']);
  579. }
  580. $time_cond = $this->notify_time($cur_time, $period, $total_period);
  581. $orders_cond = array_merge($base_cond,$time_cond);
  582. $provider_list = $this->providers();
  583. [$special_stat, $order_stat] = $this->provider_timeout_stats($orders_cond, $provider_list);
  584. echo json_encode(['special_stat' => $special_stat, 'order_stat' =>$order_stat]);
  585. }
  586. private function RefillOrderExport($cond, $method_name = '', $type='order')
  587. {
  588. $result = [];
  589. if ($type == 'order') {
  590. $result = Model('refill_order')->getAllOrders($cond);
  591. } elseif ($type == 'time_out_order') {
  592. $result = Model('refill_order')->getAllTimeOutOrders($cond);
  593. }
  594. $this->createExcel($result, $method_name);
  595. }
  596. private function createExcel($data = [], $method_name = '')
  597. {
  598. Language::read('export');
  599. import('libraries.excel');
  600. $excel_obj = new Excel();
  601. $excel_data = array();
  602. //设置样式
  603. $excel_obj->setStyle(array('id' => 's_title', 'Font' => array('FontName' => '宋体', 'Size' => '12', 'Bold' => '1')));
  604. //header
  605. $excel_data[0][] = array('styleid' => 's_title', 'data' => '商户号');
  606. $excel_data[0][] = array('styleid' => 's_title', 'data' => '客户订单号');
  607. $excel_data[0][] = array('styleid' => 's_title', 'data' => '平台单号');
  608. $excel_data[0][] = array('styleid' => 's_title', 'data' => '面额');
  609. $excel_data[0][] = array('styleid' => 's_title', 'data' => '充值卡号');
  610. $excel_data[0][] = array('styleid' => 's_title', 'data' => '充值卡类型');
  611. $excel_data[0][] = array('styleid' => 's_title', 'data' => '下单日期');
  612. $excel_data[0][] = array('styleid' => 's_title', 'data' => '完成日期');
  613. $excel_data[0][] = array('styleid' => 's_title', 'data' => '官方流水号');
  614. $excel_data[0][] = array('styleid' => 's_title', 'data' => '订单状态');
  615. //data
  616. foreach ((array)$data as $v) {
  617. $tmp = array();
  618. $tmp[] = array('data' => $v['mchid']);
  619. $tmp[] = array('data' => $v['mch_order']);
  620. $tmp[] = array('data' => $v['order_sn']);
  621. $tmp[] = array('data' => $v['refill_amount']);
  622. $tmp[] = array('data' => $v['card_no']);
  623. $tmp[] = array('data' => $this->scard_type($v['card_type']));
  624. $tmp[] = array('data' => date('Y-m-d H:i:s', $v['order_time']));
  625. if (empty($v['notify_time'])) {
  626. $tmp[] = array('data' => '');
  627. } else {
  628. $tmp[] = array('data' => date('Y-m-d H:i:s', $v['notify_time']));
  629. }
  630. $tmp[] = array('data' => $v['official_sn']);
  631. $tmp[] = array('data' => orderState($v));
  632. $excel_data[] = $tmp;
  633. }
  634. $excel_data = $excel_obj->charset($excel_data, CHARSET);
  635. $excel_obj->addArray($excel_data);
  636. $excel_obj->addWorksheet($excel_obj->charset(L('exp_od_order'), CHARSET));
  637. $excel_obj->generateXML($method_name . date('Y-m-d-H', time()));
  638. }
  639. public function neterr_orderOp()
  640. {
  641. $model_refill_order = Model('refill_order');
  642. if (!empty($_GET['store_id'])) {
  643. $condition['vr_order.store_id'] = $_GET['store_id'];
  644. }
  645. $condition['refill_order.inner_status'] = 0;
  646. $condition['refill_order.neterr'] = 1;
  647. $condition['vr_order.order_state'] = ORDER_STATE_PAY;
  648. $cur_time = time();
  649. $start_day = strtotime("-5 days",$cur_time);
  650. $condition['vr_order.add_time&vr_order.add_time'] = ['_multi' => true,
  651. ['egt', $start_day],
  652. ['lt', $cur_time]];
  653. $condition['refill_order.order_time&refill_order.order_time'] = ['_multi' => true,
  654. ['egt', $start_day],
  655. ['lt', $cur_time]];
  656. if (!empty($_GET['order_query'])) {
  657. $this->updateOrderSend($condition);
  658. return;
  659. }
  660. if (!empty($_GET['export'])) {
  661. $this->RefillOrderExport($condition, '网络错误订单导出');
  662. return;
  663. }
  664. $merchant_list = $this->merchants();
  665. $provider_list = $this->providers();
  666. //耗时
  667. $fields = "refill_order.*,vr_order.order_state";
  668. $order_by = "refill_order.commit_time asc";
  669. [$special_stat, $order_stat] = $this->provider_timeout_stats($condition, $provider_list);
  670. $order_list = $model_refill_order->getMerchantOrderList($condition, 200, $order_stat['order_count'],$fields, $order_by);
  671. $order_list = $this->orderFormat($order_list, $merchant_list);
  672. Tpl::output('stat', $order_stat);
  673. Tpl::output('special_stat', $special_stat);
  674. Tpl::output('order_list', $order_list);
  675. Tpl::output('show_page', $model_refill_order->showpage());
  676. Tpl::showpage('refill.order.neterr.index');
  677. }
  678. public function neterr_order_manualOp()
  679. {
  680. $type = $_GET['type'];
  681. $official_sn = $_GET['official_sn'] ?? '';
  682. if ($type != 'success' && $type != 'cancel') {
  683. showMessage('手动操作类型错误');
  684. }
  685. $order_ids = $_GET['order_ids'];
  686. $model_refill_order = Model('refill_order');
  687. $condition['refill_order.order_id'] = ['in', $order_ids];
  688. $condition['refill_order.inner_status'] = 0;
  689. $condition['refill_order.neterr'] = 1;
  690. $condition['vr_order.order_state'] = ORDER_STATE_PAY;
  691. $order_list = $model_refill_order->getMerchantOrderList($condition);
  692. if (empty($order_list)) {
  693. showMessage('暂无数据');
  694. }
  695. foreach ($order_list as $order)
  696. {
  697. $order_id = $order['order_id'];
  698. if ($type == 'success') {
  699. if (!empty($official_sn)) {
  700. $logic_vr_order = Logic("vr_order");
  701. $logic_vr_order->changeOrderStateSuccess($order_id, true);
  702. $model_refill_order->edit($order_id, ['official_sn' => $official_sn,'notify_state' => 1, 'notify_time' => time()]);
  703. util::pop_queue_order($order['mchid'], $order['mch_order']);
  704. QueueClient::push("NotifyMerchantComplete", ['order_id' => $order_id, 'manual' => true]);
  705. }
  706. else {
  707. refill\util::manual_success($order_id);
  708. }
  709. } elseif ($type == 'cancel') {
  710. refill\util::manual_cancel($order_id);
  711. }
  712. }
  713. $this->log("手动强制处理", 1);
  714. showMessage('操作成功');
  715. }
  716. public function orderFormat($order_list, $merchant_list): array
  717. {
  718. $merchants = [];
  719. foreach ($merchant_list as $value) {
  720. $merchants[$value['mchid']] = $value;
  721. }
  722. $cur_time = time();
  723. foreach ($order_list as $order_id => $order_info) {
  724. $order_list[$order_id]['card_type_text'] = $this->scard_type($order_info['card_type']);
  725. $order_list[$order_id]['mch_name'] = $merchants[$order_info['mchid']]['company_name'];
  726. if ($order_info['notify_time'] > 0) {
  727. $total_diff_time = $order_info['notify_time'] - $order_info['order_time'];
  728. $diff_time = $order_info['notify_time'] - $order_info['commit_time'];
  729. } else {
  730. $total_diff_time = $cur_time - $order_info['order_time'];
  731. $diff_time = $cur_time - $order_info['commit_time'];
  732. }
  733. if($order_info['mtime_out'] > 0) {
  734. $order_list[$order_id]['mtime_out_text'] = $this->elapse_time($order_info['mtime_out']);
  735. }
  736. $order_list[$order_id]['diff_time'] = $diff_time;
  737. $order_list[$order_id]['diff_time_text'] = $this->elapse_time($diff_time);
  738. $order_list[$order_id]['total_diff_time'] = $total_diff_time;
  739. $order_list[$order_id]['total_diff_time_text'] = $this->elapse_time($total_diff_time);
  740. $order_list[$order_id]['quality_text'] = $this->quality_format($order_info['quality'], $order_info['card_type']);
  741. if ($total_diff_time > $merchants[$order_info['mchid']]['time_out'] && $order_info['order_state'] == ORDER_STATE_SEND) {
  742. $order_list[$order_id]['time_out_state'] = 0;
  743. if (in_array($order_info['card_type'], [mtopcard\PetroChinaCard, mtopcard\SinopecCard])) {
  744. $order_list[$order_id]['time_out_state'] = 1;
  745. }
  746. if (in_array($order_info['card_type'], [mtopcard\ChinaMobileCard, mtopcard\ChinaUnicomCard, mtopcard\ChinaTelecomCard])) {
  747. if (in_array($order_info['quality'], [
  748. refill\Quality::SlowTwentyFour,
  749. refill\Quality::SlowSix,
  750. refill\Quality::SlowTwo,
  751. refill\Quality::SlowFortyEight,
  752. refill\Quality::SlowSeventyTwo])) {
  753. $order_list[$order_id]['time_out_state'] = 2;
  754. } elseif (in_array($order_info['mchid'], [10132])) {
  755. //重点机构
  756. $order_list[$order_id]['time_out_state'] = 3;
  757. } else {
  758. $order_list[$order_id]['time_out_state'] = 4;
  759. }
  760. }
  761. } else {
  762. $order_list[$order_id]['time_out_state'] = 0;
  763. }
  764. }
  765. return $order_list;
  766. }
  767. public function notify_err_orderOp()
  768. {
  769. $model_refill_order = Model('refill_order');
  770. $order_state_cancel = ORDER_STATE_CANCEL;
  771. $order_state_success = ORDER_STATE_SUCCESS;
  772. $condition['refill_order.inner_status'] = 0;
  773. $condition['refill_order.is_retrying'] = 0;
  774. $condition['vr_order.order_state'] = ['in', "{$order_state_cancel},{$order_state_success}"];
  775. $condition['refill_order.mch_notify_state'] = ['in', "0,2"];
  776. $condition['refill_order.mch_notify_times'] = ['gt', 0];
  777. if (empty($_GET['time'])) {
  778. $_GET['time'] = 1;
  779. }
  780. if (empty($_GET['notify_time'])) {
  781. $_GET['notify_time'] = 180;
  782. }
  783. $cur_time = time();
  784. $time = $_GET['time'] * 3600;
  785. $condition['refill_order.order_time'] = [['egt', ($cur_time - $time)], ['lt', $cur_time], 'and'];
  786. $condition['vr_order.add_time'] = [['egt', ($cur_time - $time)], ['lt', $cur_time], 'and'];
  787. $notify_time = $_GET['notify_time'];
  788. if($notify_time > 0) {
  789. $start_day = strtotime("-5 days",$cur_time);
  790. $condition['refill_order.notify_time'] = [['egt', $start_day], ['lt', ($cur_time - $notify_time)], 'and'];
  791. }
  792. $order_list = $model_refill_order->getMerchantOrderList($condition, 200, 1000,'refill_order.*,vr_order.order_state', '', 1000);
  793. $merchant_list = $this->merchants();
  794. $order_list = $this->orderFormat($order_list, $merchant_list);
  795. Tpl::output('order_list', $order_list);
  796. Tpl::output('show_page', $model_refill_order->showpage());
  797. Tpl::showpage('refill.order.notify.err.index');
  798. }
  799. public function notifyerr_all_notifyOp()
  800. {
  801. if (empty($_GET['time']) || empty($_GET['notify_time'])) {
  802. showMessage('日期条件错误');
  803. }
  804. $model_refill_order = Model('refill_order');
  805. $order_state_cancel = ORDER_STATE_CANCEL;
  806. $order_state_success = ORDER_STATE_SUCCESS;
  807. $condition['refill_order.inner_status'] = 0;
  808. $condition['vr_order.order_state'] = ['in', "{$order_state_cancel},{$order_state_success}"];
  809. $condition['refill_order.mch_notify_state'] = ['in', "0,2"];
  810. $condition['refill_order.is_retrying'] = 0;
  811. $time = $_GET['time'] * 3600;
  812. $condition['refill_order.order_time'] = ['gt', (time() - $time)];
  813. $notify_time = $_GET['notify_time'];
  814. $condition['refill_order.notify_time'] = ['lt', (time() - $notify_time)];
  815. $order_list = $model_refill_order->getMerchantOrderList($condition, '', 0,'refill_order.*,vr_order.order_state', 'refill_order.notify_time asc', 1000);
  816. foreach ($order_list as $order) {
  817. QueueClient::push("NotifyMerchantComplete", ['order_id' => $order['order_id'], 'manual' => true]);
  818. }
  819. showMessage('操作成功');
  820. }
  821. private function updateOrderSend($condition)
  822. {
  823. $condition['order_state'] = ORDER_STATE_SEND;
  824. $orders = $this->getAllTimeOutOrders($condition);
  825. if (!empty($orders)) {
  826. foreach ($orders as $order) {
  827. $order_id = $order['order_id'];
  828. QueueClient::push("QueryRefillState", ['order_id' => $order_id]);
  829. }
  830. }
  831. showMessage('操作成功');
  832. }
  833. private function getAllTimeOutOrders($condition): array
  834. {
  835. $len = 1000;
  836. $i = 0;
  837. $orders = [];
  838. while (true) {
  839. $start = $i * $len;
  840. $items = Model('')->table('refill_order,vr_order,merchant')
  841. ->field('refill_order.*,vr_order.order_state')
  842. ->join('inner,inner')
  843. ->on('refill_order.order_id=vr_order.order_id,refill_order.mchid=merchant.mchid')
  844. ->where($condition)
  845. ->order('refill_order.order_time desc')
  846. ->limit("{$start},{$len}")->select();
  847. $orders = array_merge($orders,$items);
  848. if (empty($items) || count($items) < $len) {
  849. break;
  850. }
  851. $i++;
  852. }
  853. return $orders;
  854. }
  855. public function order_exceptionOp()
  856. {
  857. $mod_except = Model('refill_exception');
  858. $_GET['except_state'] = $_GET['except_state'] ?? 0;
  859. $cond = [];
  860. if (!empty($_GET['order_sns'])) {
  861. $order_sns = rtrim($_GET['order_sns'],',');
  862. $cond['refill_exception.order_sn'] = ['in', $order_sns];
  863. }
  864. if(isset($_GET['except_type']) && $_GET['except_type'] !== '') {
  865. $_GET['except_type'] = intval($_GET['except_type']);
  866. }
  867. if(in_array($_GET['except_type'], [refill_exception_type::EUnKnown, refill_exception_type::EOfficialSN, refill_exception_type::ERefundOrder, refill_exception_type::EqualOfficialSN], true)) {
  868. $cond['except_type'] = $_GET['except_type'];
  869. }
  870. if(in_array($_GET['except_state'], ['0', '1'])) {
  871. $cond['except_state'] = $_GET['except_state'];
  872. }
  873. $start_unixtime = intval(strtotime($_GET['query_start_time']));
  874. $end_unixtime = intval(strtotime($_GET['query_end_time']));
  875. if ($start_unixtime > 0 && $end_unixtime > $start_unixtime) {
  876. $cond['order_time'] = [['egt', $start_unixtime], ['lt', $end_unixtime], 'and'];
  877. } elseif ($start_unixtime > 0) {
  878. $cond['order_time'] = ['egt', $start_unixtime];
  879. } elseif ($end_unixtime > 0) {
  880. $cond['order_time'] = ['lt', $end_unixtime];
  881. }
  882. if (!empty($_GET['export'])) {
  883. $this->exception_order_export($cond);
  884. return;
  885. }
  886. $list = $mod_except->getExceptionList($cond, 200, 0, 'refill_exception.*,refill_order.order_time,refill_order.card_no');
  887. $merchant_list = $this->merchants();
  888. foreach ($merchant_list as $value) {
  889. $merchants[$value['mchid']] = $value;
  890. }
  891. Tpl::output('merchant_list', $merchants);
  892. Tpl::output('list', $list);
  893. Tpl::output('except_stat', $this->except_stat());
  894. Tpl::output('show_page', $mod_except->showpage());
  895. Tpl::showpage('refill.order.exception');
  896. }
  897. public function order_exception_handledOp()
  898. {
  899. $except_ids = $_GET['except_ids'];
  900. $except_ids = explode(',', $except_ids);
  901. $cond['except_id'] = ['in',$except_ids];
  902. $cond['except_state'] = 0;
  903. $mod_except = Model('refill_exception');
  904. $excepts = $mod_except->getExceptionList($cond);
  905. if(empty($excepts)) {
  906. showMessage('操作完成');
  907. }
  908. $admininfo = $this->getAdminInfo();
  909. $update['admin_id'] = $admininfo['id'];
  910. $update['admin_name'] = $admininfo['name'];
  911. $update['oper_time'] = time();
  912. foreach ($excepts as $except) {
  913. $exc_id = $except['except_id'];
  914. $mod_except->setHandled($exc_id, $update);
  915. }
  916. showMessage('操作完成');
  917. }
  918. private function except_stat()
  919. {
  920. $mod_except = Model('refill_exception');
  921. $cond['except_state'] = 0;
  922. $except_stat = $mod_except->where($cond)->count();
  923. return intval($except_stat);
  924. }
  925. public function refill_detail_monitorOp()
  926. {
  927. $mod_detail = Model('refill_detail');
  928. $cond['order_state'] = ['neq', ORDER_STATE_HANDLED];
  929. $merchant_list = $this->merchants();
  930. foreach ($merchant_list as $value) {
  931. $merchants[$value['mchid']] = $value;
  932. }
  933. $list = $mod_detail->getRefillDetailList($cond, 30, 30, '*', 'order_time asc');
  934. foreach ($list as $key => $value) {
  935. $params = json_decode($value['params'],true);
  936. $list[$key]['company_name'] = $merchants[$value['mchid']]['company_name'];
  937. $list[$key]['params'] = $params;
  938. if($value['order_state'] == ORDER_STATE_SEND) {
  939. $list[$key]['order_state_text'] = '待收货';
  940. } elseif ($value['order_state'] == ORDER_STATE_QUEUE) {
  941. $list[$key]['order_state_text'] = '队列中';
  942. } elseif ($value['order_state'] == ORDER_STATE_HANDLED) {
  943. $list[$key]['order_state_text'] = '已处理';
  944. } else {
  945. $list[$key]['order_state_text'] = '/';
  946. }
  947. }
  948. Tpl::output('list', $list);
  949. Tpl::output('show_page', $mod_detail->showpage());
  950. Tpl::showpage('refill.detail.monitor');
  951. }
  952. public function query_errOp()
  953. {
  954. $mod = Model('refill_query_err');
  955. $condition = [];
  956. $_GET['query_start_time'] = $_GET['query_start_time'] ?? date("Y-m-d 00:00:00");
  957. if(!empty($_GET['mchid'])) {
  958. $condition['mchid'] = $_GET['mchid'];
  959. }
  960. if (!empty($_GET['mch_orders'])) {
  961. $mch_orders = rtrim($_GET['mch_orders'],',');
  962. $condition['mch_order'] = ['in', $mch_orders];
  963. }
  964. $start_unixtime = intval(strtotime($_GET['query_start_time']));
  965. $end_unixtime = intval(strtotime($_GET['query_end_time']));
  966. if ($start_unixtime > 0 && $end_unixtime > $start_unixtime) {
  967. $condition['query_time'] = [['egt', $start_unixtime], ['lt', $end_unixtime], 'and'];
  968. } elseif ($start_unixtime > 0) {
  969. $condition['query_time'] = ['egt', $start_unixtime];
  970. } elseif ($end_unixtime > 0) {
  971. $condition['query_time'] = ['lt', $end_unixtime];
  972. } else {
  973. $start = strtotime(date('Y-m-d', time()));
  974. $condition['query_time'] = ['egt', $start];
  975. }
  976. if (!empty($_GET['export'])) {
  977. $this->RefillQueryAsyncExport($condition, 'refill_query_err_export');
  978. return;
  979. }
  980. $merchants = [];
  981. $merchant_list = $this->merchants();
  982. foreach ($merchant_list as $value) {
  983. $merchants[$value['mchid']] = $value;
  984. }
  985. $list = $mod->getRefillQueryErrList($condition, 200, 1000);
  986. Tpl::output('merchant_list', $merchant_list);
  987. Tpl::output('merchants', $merchants);
  988. Tpl::output('list', $list);
  989. Tpl::output('show_page', $mod->showpage());
  990. Tpl::showpage('refill.query.err');
  991. }
  992. private function exception_order_export($cond)
  993. {
  994. $data = Model('refill_exception')->getAllExceptionOrders($cond);
  995. $merchants = [];
  996. $merchant_list = $this->merchants();
  997. foreach ($merchant_list as $value) {
  998. $merchants[$value['mchid']] = $value;
  999. }
  1000. Language::read('export');
  1001. import('libraries.excel');
  1002. $excel_obj = new Excel();
  1003. $excel_data = array();
  1004. //设置样式
  1005. $excel_obj->setStyle(array('id' => 's_title', 'Font' => array('FontName' => '宋体', 'Size' => '12', 'Bold' => '1')));
  1006. //header
  1007. $excel_data[0][] = array('styleid' => 's_title', 'data' => '机构编号');
  1008. $excel_data[0][] = array('styleid' => 's_title', 'data' => '机构名称');
  1009. $excel_data[0][] = array('styleid' => 's_title', 'data' => '通道名称');
  1010. $excel_data[0][] = array('styleid' => 's_title', 'data' => '订单号');
  1011. $excel_data[0][] = array('styleid' => 's_title', 'data' => '异常事件');
  1012. $excel_data[0][] = array('styleid' => 's_title', 'data' => '异常信息');
  1013. $excel_data[0][] = array('styleid' => 's_title', 'data' => '异常记录日期');
  1014. $excel_data[0][] = array('styleid' => 's_title', 'data' => '异常状态');
  1015. $excel_data[0][] = array('styleid' => 's_title', 'data' => '处理人');
  1016. //data
  1017. foreach ((array)$data as $v) {
  1018. $tmp = array();
  1019. $tmp[] = array('data' => $v['mchid']);
  1020. $tmp[] = array('data' => $merchants[$v['mchid']]['company_name']);
  1021. $tmp[] = array('data' => $v['store_name']);
  1022. $tmp[] = array('data' => $v['order_sn']);
  1023. $tmp[] = array('data' => $v['title']);
  1024. $tmp[] = array('data' => $v['except_desc']);
  1025. $tmp[] = array('data' => date('Y-m-d H:i:s', $v['add_time']));
  1026. if (empty($v['except_state'])) {
  1027. $tmp[] = array('data' => '未处理');
  1028. } else {
  1029. $tmp[] = array('data' => '已处理');
  1030. }
  1031. $tmp[] = array('data' => $v['admin_name']);
  1032. $excel_data[] = $tmp;
  1033. }
  1034. $excel_data = $excel_obj->charset($excel_data, CHARSET);
  1035. $excel_obj->addArray($excel_data);
  1036. $excel_obj->addWorksheet($excel_obj->charset(L('exp_od_order'), CHARSET));
  1037. $excel_obj->generateXML('异常订单导出-' . date('Y-m-d-H', time()));
  1038. }
  1039. private function RefillQueryAsyncExport($condition, $type)
  1040. {
  1041. if (empty($condition)) {
  1042. showMessage('请选择导出条件后重新操作', '', '', 'error');
  1043. }
  1044. $title = $_GET['task_title'] ?? '';
  1045. $manager = new task\manager();
  1046. $task = $manager->add_task($type, $condition, 1, -1, $title);
  1047. if ($task->completed() && $task->success()) {
  1048. $file_name = $task->result();
  1049. $file_path = UPLOAD_SITE_URL . '/' . ATTACH_TASK . DS . $file_name;
  1050. header("Content-Disposition: attachment; filename={$file_name}");
  1051. readfile($file_path);
  1052. } else {
  1053. $task_id = $task->task_id();
  1054. showMessage("录入成功,任务ID:{$task_id},请稍后以相同条件再次导出,或在任务列表直接下载。","index.php?act=task&op=index&task_id={$task_id}");
  1055. }
  1056. }
  1057. private function monitor_transfer_export($cond, &$merchants_getter, $all_mchids)
  1058. {
  1059. $order_list = Model('refill_order')->getAllMonitorTransferOrders($cond);
  1060. $merchant_list = $merchants_getter($all_mchids);
  1061. if(!empty($order_list)) {
  1062. $order_list = $this->orderFormat($order_list, $merchant_list);
  1063. }
  1064. Language::read('export');
  1065. import('libraries.excel');
  1066. $excel_obj = new Excel();
  1067. $excel_data = array();
  1068. //设置样式
  1069. $excel_obj->setStyle(array('id' => 's_title', 'Font' => array('FontName' => '宋体', 'Size' => '12', 'Bold' => '1')));
  1070. //header
  1071. $excel_data[0][] = array('styleid' => 's_title', 'data' => '机构编号');
  1072. $excel_data[0][] = array('styleid' => 's_title', 'data' => '机构名称');
  1073. $excel_data[0][] = array('styleid' => 's_title', 'data' => '订单号');
  1074. $excel_data[0][] = array('styleid' => 's_title', 'data' => '充值卡号');
  1075. $excel_data[0][] = array('styleid' => 's_title', 'data' => '充值卡类型');
  1076. $excel_data[0][] = array('styleid' => 's_title', 'data' => '充值额度');
  1077. $excel_data[0][] = array('styleid' => 's_title', 'data' => '下单日期');
  1078. $excel_data[0][] = array('styleid' => 's_title', 'data' => '超时');
  1079. $excel_data[0][] = array('styleid' => 's_title', 'data' => '当前耗时');
  1080. $excel_data[0][] = array('styleid' => 's_title', 'data' => '总耗时');
  1081. $excel_data[0][] = array('styleid' => 's_title', 'data' => '订单状态');
  1082. $excel_data[0][] = array('styleid' => 's_title', 'data' => '通道质量');
  1083. $excel_data[0][] = array('styleid' => 's_title', 'data' => '失败原因');
  1084. $excel_data[0][] = array('styleid' => 's_title', 'data' => '商家单号');
  1085. $excel_data[0][] = array('styleid' => 's_title', 'data' => '扣款金额');
  1086. $excel_data[0][] = array('styleid' => 's_title', 'data' => '渠道单号');
  1087. $excel_data[0][] = array('styleid' => 's_title', 'data' => '渠道名称');
  1088. //data
  1089. foreach ($order_list as $order) {
  1090. $tmp = array();
  1091. $tmp[] = array('data' => $order['mchid']);
  1092. $tmp[] = array('data' => $order['mch_name']);
  1093. $tmp[] = array('data' => $order['order_sn']);
  1094. $tmp[] = array('data' => $order['card_no']);
  1095. $tmp[] = array('data' => $order['card_type_text']);
  1096. $tmp[] = array('data' => $order['refill_amount']);
  1097. $tmp[] = array('data' => date('Y-m-d H:i:s', $order['order_time']));
  1098. $tmp[] = array('data' => $order['mtime_out_text']);
  1099. $tmp[] = array('data' => $order['diff_time_text']);
  1100. $tmp[] = array('data' => $order['total_diff_time_text']);
  1101. $tmp[] = array('data' => orderState($order));
  1102. $tmp[] = array('data' => $order['quality_text']);
  1103. $tmp[] = array('data' => $order['err_msg']);
  1104. $tmp[] = array('data' => $order['mch_order']);
  1105. $tmp[] = array('data' => $order['mch_amount']);
  1106. $tmp[] = array('data' => $order['ch_trade_no']);
  1107. $tmp[] = array('data' => $order['channel_name']);
  1108. $excel_data[] = $tmp;
  1109. }
  1110. $excel_data = $excel_obj->charset($excel_data, CHARSET);
  1111. $excel_obj->addArray($excel_data);
  1112. $excel_obj->addWorksheet($excel_obj->charset(L('exp_od_order'), CHARSET));
  1113. $excel_obj->generateXML('补单导出-' . date('Y-m-d-H', time()));
  1114. }
  1115. }