ordersendlist.php 53 KB

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