refill_order_manual.php 32 KB

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