refill_order_manual.php 32 KB

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