refill_order_manual.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601
  1. <?php
  2. require_once(BASE_HELPER_PATH . '/refill/util.php');
  3. require_once(BASE_HELPER_PATH . '/algorithm.php');
  4. use refill\util;
  5. class refill_order_manualControl extends SystemControl
  6. {
  7. public function __construct()
  8. {
  9. parent::__construct();
  10. }
  11. public function indexOp()
  12. {
  13. $model_refill_order = Model('refill_order');
  14. $condition['inner_status'] = 0;
  15. $order_list = [];
  16. if (!empty($_GET['order_sn'])) {
  17. $condition['refill_order.order_sn'] = $_GET['order_sn'];
  18. $merchant_list = $this->merchants();
  19. $order_list = $model_refill_order->getMerchantOrderList($condition, 50,0, 'refill_order.*,vr_order.order_state', 'refill_order.order_time desc','',true);
  20. $order_list = $this->OrderDataFormat($order_list, $merchant_list);
  21. }
  22. Tpl::output('order_list', $order_list);
  23. Tpl::showpage('refill.order.manual.index');
  24. }
  25. public function notify_manual_merchantOp()
  26. {
  27. $order_id = $_GET['order_id'];
  28. $type = $_GET['type'];
  29. $mod_order = Model('vr_order');
  30. $order_info = $mod_order->getOrderInfo(['order_id' => $order_id]);
  31. $mod_refill = Model('refill_order');
  32. $refill_info = Model('refill_order')->getOrderInfo(['order_id' => $order_id,'inner_status' => 0,'is_retrying' => 0]);
  33. if(empty($refill_info) || empty($order_info)) {
  34. showMessage('订单不存在,或不符合条件', '');
  35. }
  36. $fetch_order_ids = $this->check_fetch_order($order_id);
  37. if (in_array($order_id, $fetch_order_ids)) {
  38. showMessage('此订单不可手动操作,请联系抢单人员操作!');
  39. }
  40. $logic_vr_order = Logic("vr_order");
  41. if ($type == 'success') {
  42. $logic_vr_order->changeOrderStateSuccess($order_id,true);
  43. } elseif ($type == 'cancel') {
  44. $logic_vr_order->changeOrderStateCancel($order_info, '', "充值失败", true, true);
  45. } else {
  46. showMessage('手动操作类型错误', 'index.php?act=refill_order&op=index');
  47. }
  48. $this->manual_record([$refill_info], $type, $order_id, '手动强制处理');
  49. $this->log("手动强制处理,订单号:{$order_info['order_sn']}", 1);
  50. if($refill_info['notify_time'] == 0) {
  51. $mod_refill->edit($order_id, ['notify_state' =>1, 'notify_time' => time()]);
  52. }
  53. util::pop_queue_order($refill_info['mchid'],$refill_info['mch_order']);
  54. QueueClient::push("NotifyMerchantComplete", ['order_id' => $order_id, 'manual' => true]);
  55. showMessage('操作成功');
  56. }
  57. public function refill_order_batchOp()
  58. {
  59. $model_refill_order = Model('refill_order');
  60. $condition = [];
  61. $orders = [];
  62. $_GET['query_start_time'] = $_GET['query_start_time'] ?? date("Y-m-d 00:00:00");
  63. if (in_array($_GET['order_state'], ['0', '10', '20', '30', '40']))
  64. {
  65. $condition['vr_order.order_state'] = $_GET['order_state'];
  66. }
  67. if (!empty($_GET['mchid'])) {
  68. $condition['refill_order.mchid'] = $_GET['mchid'];
  69. }
  70. if (!empty($_GET['store_id'])) {
  71. $condition['vr_order.store_id'] = $_GET['store_id'];
  72. }
  73. //批量查询,二者都有,以卡号为主
  74. if(!empty($_GET['card_nos'])) {
  75. $card_nos = trim($_GET['card_nos'], ',');
  76. $condition['refill_order.card_no'] = ['in', $card_nos];
  77. } elseif (!empty($_GET['mch_orders'])) {
  78. $mch_orders = rtrim($_GET['mch_orders'], ',');
  79. $condition['refill_order.mch_order'] = ['in', $mch_orders];
  80. }
  81. if(!empty($_GET['order_sns'])) {
  82. $order_sns = trim($_GET['order_sns'], ',');
  83. $condition['refill_order.order_sn'] = ['in', $order_sns];
  84. }
  85. if (!empty($_GET['card_type'])) {
  86. if (in_array($_GET['card_type'], ['1', '2', '4', '5', '6', '7'])) {
  87. $condition['refill_order.card_type'] = intval($_GET['card_type']);
  88. }
  89. }
  90. $merchant_list = $this->merchants();
  91. $provider_list = $this->providers();
  92. if(!empty($condition)) {
  93. $condition['refill_order.inner_status'] = 0;
  94. $start_unixtime = intval(strtotime($_GET['query_start_time']));
  95. $end_unixtime = intval(strtotime($_GET['query_end_time']));
  96. if ($start_unixtime > 0 && $end_unixtime > $start_unixtime) {
  97. $condition['refill_order.order_time'] = [['egt', $start_unixtime], ['lt', $end_unixtime], 'and'];
  98. $condition['vr_order.add_time'] = [['egt', $start_unixtime],['lt', $end_unixtime], 'and'];
  99. } elseif ($start_unixtime > 0) {
  100. $condition['refill_order.order_time'] = ['egt', $start_unixtime];
  101. $condition['vr_order.add_time'] = ['egt', $start_unixtime];
  102. } elseif ($end_unixtime > 0) {
  103. $condition['refill_order.order_time'] = ['lt', $end_unixtime];
  104. } else {
  105. $start = strtotime(date('Y-m-d', time()));
  106. $condition['refill_order.order_time'] = ['egt', $start];
  107. $condition['vr_order.add_time'] = ['egt', $start];
  108. }
  109. $orders = $model_refill_order->getMerchantOrderList($condition, 400, 0,'refill_order.*,vr_order.order_state', 'refill_order.channel_name DESC ');
  110. $orders = $this->OrderDataFormat($orders, $merchant_list);
  111. $order_ids = array_column($orders,'order_id');
  112. $order_ids = $this->unique_array($order_ids);
  113. $refill_buyback_model = Model('refill_buyback');
  114. $buybacks = $refill_buyback_model->getBuyBackList(['order_id' => ['in',$order_ids], 'manual_type' => 'buyback']);
  115. $buyback_ids = array_column($buybacks, 'order_id');
  116. $buyback_ids = $this->int_array($buyback_ids);
  117. $buyback_ids = $this->unique_array($buyback_ids);
  118. foreach ($orders as $key => $order)
  119. {
  120. if($order['order_state'] != ORDER_STATE_SUCCESS) {
  121. $order[$key]['buyback'] = false;
  122. continue;
  123. }
  124. $order_id = intval($order['order_id']);
  125. if(algorithm::binary_search($buyback_ids,$order_id)) {
  126. $orders[$key]['buyback'] = true;
  127. }else{
  128. $orders[$key]['buyback'] = false;
  129. }
  130. }
  131. }
  132. Tpl::output('merchant_list', $merchant_list);
  133. Tpl::output('provider_list', $provider_list);
  134. Tpl::output('order_list', $orders);
  135. Tpl::output('show_page', $model_refill_order->showpage());
  136. Tpl::showpage('refill.order.batch');
  137. }
  138. public function refill_order_batch_disposeOp()
  139. {
  140. $oid_reader = function ($sids) {
  141. $sids = explode(',',$sids);
  142. $ids = $this->int_array($sids);
  143. return $this->unique_array($ids);
  144. };
  145. $oper_type = $_GET['type'];
  146. $order_ids = $oid_reader($_GET['order_id']);
  147. $cond = [];
  148. $cond['refill_order.order_id'] = ['in',$order_ids];
  149. $cond['refill_order.inner_status'] = 0;
  150. $cond['refill_order.is_retrying'] = 0;
  151. if ($oper_type == 'success' || $oper_type == 'cancel') {
  152. $cond['vr_order.order_state'] = ORDER_STATE_SEND;
  153. } elseif ($oper_type == 'buyback') {
  154. $cond['vr_order.order_state'] = ORDER_STATE_SUCCESS;
  155. }
  156. $model_refill_order = Model('refill_order');
  157. $orders = $model_refill_order->getMerchantOrderList($cond,'',0,'refill_order.*,vr_order.order_state,vr_order.buyer_id,vr_order.store_id','refill_order.order_id desc',2000);
  158. if(empty($orders)) {
  159. showMessage('操作数据为空');
  160. }
  161. if($oper_type == 'notify')
  162. {
  163. foreach ($orders as $order)
  164. {
  165. if ($order['order_state'] == ORDER_STATE_SEND) {
  166. QueueClient::push("QueryRefillState", ['order_id' => $order['order_id']]);
  167. } else {
  168. QueueClient::push("NotifyMerchantComplete", ['order_id' => $order['order_id'], 'manual' => true]);
  169. }
  170. }
  171. }
  172. elseif (in_array($oper_type, ['success', 'cancel', 'buyback'])) {
  173. $this->manual_record($orders, $oper_type, $order_ids, $_GET);
  174. }
  175. else {
  176. showMessage('手动操作类型错误');
  177. }
  178. showMessage('操作成功');
  179. }
  180. private function manual_record($orders, $oper_type, $order_ids, $input)
  181. {
  182. $admininfo = $this->getAdminInfo();
  183. $bz = empty($input['bz']) ? '' : $input['bz'];
  184. $buyback_ids = function ($order_ids, $oper_type) {
  185. $buybacks = Model('refill_buyback')->getBuyBackList(['order_id' => ['in', $order_ids], 'manual_type' => $oper_type]);
  186. $buyback_ids = array_column($buybacks, 'order_id');
  187. $buyback_ids = $this->int_array($buyback_ids);
  188. return $this->unique_array($buyback_ids);
  189. };
  190. $format_item = function ($order, $oper_type, $admininfo, $cur_time, $bz)
  191. {
  192. return ['order_id' => $order['order_id'],
  193. 'order_sn' => $order['order_sn'],
  194. 'order_time' => $order['order_time'],
  195. 'notify_time' => $order['notify_time'],
  196. 'manual_type' => $oper_type,
  197. 'admin_id' => $admininfo['id'],
  198. 'admin_name' => $admininfo['name'],
  199. 'act_time' => $cur_time,
  200. 'bz' => $bz];
  201. };
  202. if($oper_type == 'buyback')
  203. {
  204. $merge = $input['merge'];
  205. $mchids = array_column($orders, 'mchid');
  206. $mchids = $this->unique_array($mchids);
  207. if($merge > 0 && count($mchids) > 1) {
  208. showMessage('下游机构多家时,返销记录不可合并');
  209. }
  210. $merchant_list = $this->merchants(['mchid' => ['in', $mchids]]);
  211. foreach ($merchant_list as $merchant) {
  212. $merchants[$merchant['mchid']] = $merchant;
  213. }
  214. $store_ids = array_column($orders, 'store_id');
  215. $store_ids = $this->unique_array($store_ids);
  216. if($merge > 0 && count($store_ids) > 1) {
  217. showMessage('上游通道多家时,返销记录不可合并');
  218. }
  219. $provider_list = $this->providers(['refill_provider.store_id' => ['in', $store_ids]]);
  220. foreach ($provider_list as $provider) {
  221. $providers[$provider['store_id']] = $provider;
  222. }
  223. }
  224. $mod_buyback = Model('refill_buyback');
  225. $buyback_ids = $buyback_ids($order_ids, $oper_type);
  226. $fetch_order_ids = $this->check_fetch_order($order_ids);
  227. $fetch_order_ids = $this->unique_array($fetch_order_ids);
  228. $cur_time = time();
  229. if($oper_type == 'buyback')
  230. {
  231. $refill_evidence = [];
  232. $provider_amount = [];
  233. foreach ($orders as $order)
  234. {
  235. $order_id = intval($order['order_id']);
  236. if (algorithm::binary_search($buyback_ids, $order_id)) continue;
  237. $mchid = $order['mchid'];
  238. $merchant_info = $merchants[$mchid];
  239. $buyer_id = $order['buyer_id'];
  240. $store_id = $order['store_id'];
  241. $provider_info = $providers[$store_id];
  242. $account_id = $provider_info['account_id'];
  243. if (empty($mchid) || empty($buyer_id) || empty($store_id) || empty($account_id)) {
  244. Log::record("refill order manual err order_id:{$order_id}, order_sn:{$order['order_sn']}");
  245. continue;
  246. }
  247. try
  248. {
  249. $trans = new trans_wapper($mod_buyback, __METHOD__);
  250. $item = $mod_buyback->getOrder(['order_id' => $order_id, 'manual_type' => $oper_type], '*', true, true);
  251. if(!empty($item)) {
  252. $trans->commit();
  253. continue;
  254. }
  255. $insert_item = $format_item($order, $oper_type, $admininfo, $cur_time, $bz);
  256. $ret = $mod_buyback->insert($insert_item);
  257. if($ret)
  258. {
  259. $merchant_bz = "机构:{$mchid},订单号:{$order['mch_order']},卡号:{$order['card_no']},返销退款:{$order['mch_amount']}";
  260. $this->credit_save_money($order['mch_amount'], 'add', $buyer_id, $merchant_bz);
  261. if ($merge > 0) {
  262. $refill_evidence['mchid'] = $mchid;
  263. if (!array_key_exists('mch_amount', $refill_evidence)) {
  264. $refill_evidence['mch_amount'] = $order['mch_amount'];
  265. $refill_evidence['count'] = 1;
  266. } else {
  267. $refill_evidence['mch_amount'] += $order['mch_amount'];
  268. $refill_evidence['count'] += 1;
  269. }
  270. } else {
  271. $this->ct_refill_evidence(['mch_amount' => $order['mch_amount'], 'bz' => $merchant_bz], $merchant_info, $cur_time, $admininfo);
  272. }
  273. }
  274. if($ret)
  275. {
  276. $provider_bz = "通道:{$store_id},椰子单号:{$order['order_sn']},卡号:{$order['card_no']},返销退款:{$order['channel_amount']}";
  277. $this->credit_save_money($order['channel_amount'], 'add', $account_id, $provider_bz);
  278. if($merge > 0) {
  279. $provider_amount['store_id'] = $store_id;
  280. if (!array_key_exists('channel_amount', $provider_amount)) {
  281. $provider_amount['channel_amount'] = $order['channel_amount'];
  282. $provider_amount['count'] = 1;
  283. } else {
  284. $provider_amount['channel_amount'] += $order['channel_amount'];
  285. $provider_amount['count'] += 1;
  286. }
  287. }else{
  288. $this->ct_provider_amount(['channel_amount' => $order['channel_amount']], $provider_info, $cur_time, $admininfo);
  289. }
  290. }
  291. $trans->commit();
  292. }
  293. catch (Exception $e) {
  294. $trans->rollback();
  295. Log::record("manual_record err: {$e->getMessage()}", Log::ERR);
  296. }
  297. }
  298. if(!empty($refill_evidence)) {
  299. $merchant_bz = "机构:{$mchid},共返销单数:{$refill_evidence['count']},返销退款总金额:{$refill_evidence['mch_amount']}";
  300. $merchant_info = $merchants[$refill_evidence['mchid']];
  301. $this->ct_refill_evidence(['mch_amount' => $refill_evidence['mch_amount'], 'bz' => $merchant_bz], $merchant_info, $cur_time, $admininfo);
  302. }
  303. if(!empty($provider_amount)) {
  304. $provider_info = $providers[$store_id];
  305. $this->ct_provider_amount(['channel_amount' => $provider_amount['channel_amount']], $provider_info, $cur_time, $admininfo);
  306. }
  307. }
  308. else
  309. {
  310. foreach ($orders as $order)
  311. {
  312. $order_id = intval($order['order_id']);
  313. if (algorithm::binary_search($buyback_ids, $order_id)) continue;
  314. if (algorithm::binary_search($fetch_order_ids, $order_id)) continue;
  315. if ($oper_type == 'success') {
  316. refill\util::manual_success($order_id);
  317. } elseif ($oper_type == 'cancel') {
  318. refill\util::manual_cancel($order_id);
  319. } else {
  320. continue;
  321. }
  322. if (empty($bz)) {
  323. $bz = "批量处理页面,手动处理,操作人:{$admininfo['name']}";
  324. }
  325. $insert_item = $format_item($order, $oper_type, $admininfo, $cur_time, $bz);
  326. $ins[] = $insert_item;
  327. }
  328. if(!empty($ins)) {
  329. $mod_buyback->insertAll($ins);
  330. }
  331. }
  332. }
  333. public function set_cancel_orderOp()
  334. {
  335. $mod = Model('refill_order');
  336. $condition = [];
  337. $order_list = [];
  338. $mch_orderData = [];
  339. if(!empty($_GET['mchid'])) {
  340. $condition['mchid'] = $_GET['mchid'];
  341. }
  342. if (!empty($_GET['mch_orders'])) {
  343. $mch_orders = rtrim($_GET['mch_orders'],',');
  344. $condition['mch_order'] = ['in', $mch_orders];
  345. }
  346. $merchant_list = $this->merchants();
  347. if(!empty($condition)) {
  348. $condition['inner_status'] = 0;
  349. $order_list = $mod->getMerchantOrderList($condition, 200, 0,'refill_order.*,vr_order.order_state', 'refill_order.order_time desc');
  350. $order_list = $this->OrderDataFormat($order_list, $merchant_list);
  351. if(empty($mch_orders)) {
  352. $mch_orderData = [];
  353. }else{
  354. $mch_orderData = explode(',',$mch_orders);
  355. }
  356. foreach ($order_list as $order_id => $order) {
  357. $mch_order = $order['mch_order'];
  358. if(in_array($mch_order, $mch_orderData)) {
  359. $key = array_search($mch_order, $mch_orderData);
  360. unset($mch_orderData[$key]);
  361. }
  362. $order_list[$order_id]['can_cancel'] = $this->can_cancel_order($order);
  363. }
  364. }
  365. Tpl::output('noexist_mch_order', $mch_orderData);
  366. Tpl::output('merchant_list', $merchant_list);
  367. Tpl::output('list', $order_list);
  368. Tpl::output('show_page', $mod->showpage());
  369. Tpl::showpage('set.cancel.order');
  370. }
  371. public function order_cancel_disposeOp()
  372. {
  373. $order_id = $_GET['order_id'];
  374. $condition['refill_order.order_id'] = ['in',$order_id];
  375. $order_list = Model('refill_order')->getMerchantOrderList($condition,1000,0,'refill_order.*,vr_order.order_state');
  376. foreach ($order_list as $order) {
  377. if($this->can_cancel_order($order)) {
  378. $mchid = $order['mchid'];
  379. $mch_order = $order['mch_order'];
  380. refill\util::set_cancel_order($mchid,$mch_order);
  381. $this->log("拦截订单,订单号:{$order['order_sn']},商家单号:{$mch_order},机构编码:{$mchid}", 1);
  382. }
  383. }
  384. showMessage('操作成功');
  385. }
  386. private function can_cancel_order($order): bool
  387. {
  388. if($order['order_state'] == ORDER_STATE_SUCCESS) {
  389. return false;
  390. }
  391. if($order['order_state'] == ORDER_STATE_CANCEL && $order['is_retrying'] == 0) {
  392. return false;
  393. }
  394. return true;
  395. }
  396. public function refill_buybackOp()
  397. {
  398. $model_refill_order = Model('refill_order');
  399. $_GET['query_start_time'] = $_GET['query_start_time'] ?? date("Y-m-d 00:00:00");
  400. if (!empty($_GET['mchid'])) {
  401. $condition['refill_order.mchid'] = $_GET['mchid'];
  402. }
  403. if (!empty($_GET['store_id'])) {
  404. $condition['vr_order.store_id'] = $_GET['store_id'];
  405. }
  406. if(!empty($_GET['card_nos'])) {
  407. $card_nos = trim($_GET['card_nos'], ',');
  408. $condition['refill_order.card_no'] = ['in', $card_nos];
  409. }
  410. if(!empty($_GET['order_sns'])) {
  411. $order_sns = trim($_GET['order_sns'], ',');
  412. $condition['refill_order.order_sn'] = ['in', $order_sns];
  413. }
  414. if(!empty($_GET['manual_type']))
  415. {
  416. $condition['manual_type'] = $_GET['manual_type'];
  417. }
  418. $start = intval(strtotime($_GET['query_start_time']));
  419. $end = intval(strtotime($_GET['query_end_time']));
  420. if ($end <= 0) {
  421. $end = time();
  422. }
  423. $condition['refill_buyback.act_time'] = [['egt', $start], ['lt', $end], 'and'];
  424. $condition['inner_status'] = 0;
  425. if(!empty($_GET['export']))
  426. {
  427. $this->Export($condition);
  428. return;
  429. }
  430. $merchant_list = $this->merchants();
  431. $order_list = $model_refill_order->getBuyBackList($condition, 200, 'refill_buyback.*,refill_order.*,vr_order.order_state', 'refill_buyback.act_time desc','',true);
  432. $order_list = $this->OrderDataFormat($order_list, $merchant_list);
  433. $provider_list = $this->providers();
  434. Tpl::output('provider_list', $provider_list);
  435. Tpl::output('merchant_list', $merchant_list);
  436. Tpl::output('order_list', $order_list);
  437. Tpl::output('show_page', $model_refill_order->showpage());
  438. Tpl::showpage('refill.buyback.order');
  439. }
  440. private function int_array($sids): array
  441. {
  442. $result = [];
  443. foreach ($sids as $sid) {
  444. $result[] = intval($sid);
  445. }
  446. return $result;
  447. }
  448. private function unique_array($ids): array
  449. {
  450. $ids = array_unique($ids);
  451. sort($ids);
  452. return $ids;
  453. }
  454. private function ct_provider_amount($params, $provider_info, $cur_time, $admininfo)
  455. {
  456. $input['provider_id'] = $provider_info['provider_id'];
  457. $input['memeber_id'] = $provider_info['account_id'];
  458. $input['amount'] = $params['channel_amount'];
  459. $input['operation'] = $admininfo['name'];
  460. $input['add_time'] = $cur_time;
  461. return Model('provider_amount')->addAmount($input);
  462. }
  463. private function ct_refill_evidence($params, $merchant_info, $cur_time, $admininfo)
  464. {
  465. $mem_info = Model('member')->getMemberInfo(['member_id' => $merchant_info['admin_id']], '*', true);
  466. $input['mchid'] = $merchant_info['mchid'];
  467. $input['mch_name'] = $merchant_info['name'];
  468. $input['member_id'] = $merchant_info['admin_id'];
  469. $input['amount'] = $params['mch_amount'];
  470. $input['bank_username'] = '椰子';
  471. $input['bank_name'] = '椰子退款';
  472. $input['bz'] = $params['bz'];
  473. $input['voucher_name'] = '/';
  474. $input['status'] = 2;
  475. $input['is_operation'] = 2;
  476. $input['add_time'] = $input['check_time'] = $cur_time;
  477. $input['after_available'] = ncPriceFormat($mem_info['available_predeposit'] + $params['mch_amount']);
  478. $input['admin_name'] = $admininfo['name'];
  479. $input['admin_id'] = $admininfo['id'];
  480. $input['add_type'] = 3;
  481. return Model('merchant')->addRefillEvidence($input);
  482. }
  483. private function Export($cond)
  484. {
  485. $result = Model('refill_order')->getAllBuyBackOrders($cond);
  486. $this->createExcel($result);
  487. }
  488. private function createExcel($data = [])
  489. {
  490. $merchant_list = $this->merchants();
  491. foreach ($merchant_list as $value) {
  492. $merchants[$value['mchid']] = $value;
  493. }
  494. Language::read('export');
  495. import('libraries.excel');
  496. $excel_obj = new Excel();
  497. $excel_data = [];
  498. //设置样式
  499. $excel_obj->setStyle(['id' => 's_title', 'Font' => ['FontName' => '宋体', 'Size' => '12', 'Bold' => '1']]);
  500. //header
  501. $excel_data[0][] = ['styleid' => 's_title', 'data' => '编号'];
  502. $excel_data[0][] = ['styleid' => 's_title', 'data' => '操作日期'];
  503. $excel_data[0][] = ['styleid' => 's_title', 'data' => '订单号'];
  504. $excel_data[0][] = ['styleid' => 's_title', 'data' => '机构编号'];
  505. $excel_data[0][] = ['styleid' => 's_title', 'data' => '机构名称'];
  506. $excel_data[0][] = ['styleid' => 's_title', 'data' => '充值卡号'];
  507. $excel_data[0][] = ['styleid' => 's_title', 'data' => '充值卡类型'];
  508. $excel_data[0][] = ['styleid' => 's_title', 'data' => '充值额度'];
  509. $excel_data[0][] = ['styleid' => 's_title', 'data' => '折扣后金额'];
  510. $excel_data[0][] = ['styleid' => 's_title', 'data' => '下单日期'];
  511. $excel_data[0][] = ['styleid' => 's_title', 'data' => '订单状态'];
  512. $excel_data[0][] = ['styleid' => 's_title', 'data' => '渠道单号'];
  513. $excel_data[0][] = ['styleid' => 's_title', 'data' => '渠道名称'];
  514. $excel_data[0][] = ['styleid' => 's_title', 'data' => '折后金额'];
  515. $excel_data[0][] = ['styleid' => 's_title', 'data' => '操作类型'];
  516. $excel_data[0][] = ['styleid' => 's_title', 'data' => '操作人'];
  517. $excel_data[0][] = ['styleid' => 's_title', 'data' => '备注'];
  518. //data
  519. foreach ((array)$data as $k => $v) {
  520. $tmp = [];
  521. $tmp[] = ['data' => $k+1];
  522. if (empty($v['act_time'])) {
  523. $tmp[] = ['data' => ''];
  524. } else {
  525. $tmp[] = ['data' => date('Y-m-d H:i:s', $v['act_time'])];
  526. }
  527. $tmp[] = ['data' => $v['order_sn']];
  528. $tmp[] = ['data' => $v['mchid']];
  529. $tmp[] = ['data' => $merchants[$v['mchid']]['company_name']];
  530. $tmp[] = ['data' => $v['card_no']];
  531. $tmp[] = ['data' => $this->scard_type($v['card_type'])];
  532. $tmp[] = ['data' => $v['refill_amount']];
  533. $tmp[] = ['data' => $v['mch_amount']];
  534. $tmp[] = ['data' => date('Y-m-d H:i:s', $v['order_time'])];
  535. $tmp[] = ['data' => orderState($v)];
  536. $tmp[] = ['data' => $v['ch_trade_no']];
  537. $tmp[] = ['data' => $v['channel_name']];
  538. $tmp[] = ['data' => $v['channel_amount']];
  539. $tmp[] = ['data' => $v['manual_type']];
  540. $tmp[] = ['data' => $v['admin_name']];
  541. $tmp[] = ['data' => $v['bz']];
  542. $excel_data[] = $tmp;
  543. }
  544. $excel_data = $excel_obj->charset($excel_data, CHARSET);
  545. $excel_obj->addArray($excel_data);
  546. $excel_obj->addWorksheet($excel_obj->charset(L('exp_od_order'), CHARSET));
  547. $excel_obj->generateXML('返销导出' . date('Y-m-d-H', time()));
  548. }
  549. }