refill_order_manual.php 32 KB

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