ordersendlist.php 46 KB

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