ordersendlist.php 53 KB

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