RefundController.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621
  1. <?php
  2. namespace app\admin\controller\order;
  3. use app\admin\validate\order\ReturnValidate;
  4. use app\controller\Curd;
  5. use app\model\GoodsComponent;
  6. use app\model\MemberAccount;
  7. use app\model\Order;
  8. use app\model\OrderExpress;
  9. use app\model\OrderReturn;
  10. use app\model\OrderSheet;
  11. use app\model\PayDetail;
  12. use app\model\SysUser;
  13. use Payment\Common\PayException;
  14. use support\Db;
  15. use support\exception\BusinessException;
  16. use support\Log;
  17. use support\Request;
  18. use support\Response;
  19. use Tinywan\Jwt\JwtToken;
  20. use Yansongda\Pay\Pay;
  21. class RefundController extends Curd
  22. {
  23. public function __construct()
  24. {
  25. $this->model = new OrderReturn();
  26. $this->validate = true;
  27. $this->validateClass = new ReturnValidate();
  28. }
  29. public function select(Request $request): Response
  30. {
  31. [$where, $format, $limit, $field, $order] = $this->selectInput($request);
  32. $order = $request->get('order', 'desc');
  33. $type = $request->get('type', '');
  34. $field = $field ?? 'order_return_addtimes';
  35. $where['order_return_category'] = '退款';
  36. if (!empty($where['order_return_addtimes'])){
  37. $where['order_return_addtimes'][0] = strtotime($where['order_return_addtimes'][0]);
  38. $where['order_return_addtimes'][1] = strtotime($where['order_return_addtimes'][1]);
  39. }
  40. if ($type == 'today') {
  41. $where['order_return_addtimes'] = [
  42. strtotime(date('Y-m-d') . ' 00:00:00'),
  43. strtotime(date('Y-m-d') . ' 23:59:59')
  44. ];
  45. }
  46. $query = $this->doSelect($where, $field, $order);
  47. return $this->doFormat($query, $format, $limit);
  48. }
  49. protected function doSelect(array $where, string $field = null, string $order = 'desc')
  50. {
  51. $model = $this->model->with([
  52. 'member' => function ($query) {
  53. $query->select('member_id', 'member_mobile');
  54. },
  55. 'cert' => function ($query) {
  56. $query->select('join_cert_member_id', 'member_cert_name');
  57. },
  58. 'order' => function ($query) {
  59. $query->select('order_id', 'order_name');
  60. }
  61. ]);
  62. foreach ($where as $column => $value) {
  63. if (is_array($value)) {
  64. if ($value[0] === 'like' || $value[0] === 'not like') {
  65. $model = $model->where($column, $value[0], "%$value[1]%");
  66. } elseif (in_array($value[0], ['>', '=', '<', '<>'])) {
  67. $model = $model->where($column, $value[0], $value[1]);
  68. } elseif ($value[0] == 'in' && !empty($value[1])) {
  69. $valArr = $value[1];
  70. if (is_string($value[1])) {
  71. $valArr = explode(",", trim($value[1]));
  72. }
  73. $model = $model->whereIn($column, $valArr);
  74. } elseif ($value[0] == 'not in' && !empty($value[1])) {
  75. $valArr = $value[1];
  76. if (is_string($value[1])) {
  77. $valArr = explode(",", trim($value[1]));
  78. }
  79. $model = $model->whereNotIn($column, $valArr);
  80. } elseif ($value[0] == 'null') {
  81. $model = $model->whereNull($column);
  82. } elseif ($value[0] == 'not null') {
  83. $model = $model->whereNotNull($column);
  84. } elseif ($value[0] !== '' || $value[1] !== '') {
  85. $model = $model->whereBetween($column, $value);
  86. }
  87. } else {
  88. $model = $model->where($column, $value);
  89. }
  90. }
  91. if ($field) {
  92. $model = $model->orderBy($field, $order);
  93. }
  94. return $model;
  95. }
  96. public function afterQuery($items)
  97. {
  98. foreach ($items as &$item) {
  99. if (!empty($item['order'])) {
  100. $orderSheet = OrderSheet::with([
  101. 'goods' => function ($query) {
  102. $query->select('goods_id', 'goods_name');
  103. }
  104. ])->select('join_sheet_order_id','join_sheet_goods_id')
  105. ->where('join_sheet_order_id',$item['order']->order_id)
  106. ->get()
  107. ->toArray();
  108. $goodsName = !empty($orderSheet) ? $orderSheet[0]['goods']['goods_name'] : '';
  109. if (count($orderSheet) > 1){
  110. $goodsName.= ' 等';
  111. }
  112. $item['goods_name'] = $goodsName;
  113. }
  114. if (!empty($item['order_return_apply_json']) && is_json($item['order_return_apply_json'])) {
  115. $json = json_decode($item['order_return_apply_json'], true);
  116. $item['order_return_apply_json'] = $json['apply'] ?? '';
  117. }
  118. if (!empty($item['order_return_recharge_json']) && is_json($item['order_return_recharge_json'])) {
  119. $json = json_decode($item['order_return_recharge_json'], true);
  120. $item['order_return_recharge_json'] = $json['change'] ?? '';
  121. }
  122. if (!empty($item['order_return_refund_json']) && is_json($item['order_return_refund_json'])) {
  123. $returnRefundJson = json_decode($item['order_return_refund_json'], true);
  124. if (!empty($returnRefundJson['user_id'])){
  125. $item['userName'] = SysUser::where('user_id',$returnRefundJson['user_id'])->value('user_name');
  126. }
  127. }
  128. }
  129. return $items;
  130. }
  131. protected function updateInput(Request $request): array
  132. {
  133. $primary_key = $this->model->getKeyName();
  134. $id = $request->post($primary_key);
  135. $data = $this->inputFilter($request->post());
  136. $model = $this->model->find($id);
  137. if (!$model) {
  138. throw new BusinessException('记录不存在', 2);
  139. }
  140. if (empty($model->order_return_accept_datetimes) && $model->order_return_status == 'PENDING' && $data['order_return_status'] == 'DOING') {
  141. $data['order_return_accept_datetimes'] = date('Y-m-d H:i:s');
  142. }
  143. if (!empty($data['order_return_apply_json'])) {
  144. $data['order_return_apply_json'] = json_encode(['apply' => $data['order_return_apply_json']]);
  145. }
  146. if (!empty($data['order_return_recharge_json'])) {
  147. $data['order_return_recharge_json'] = json_encode(['change' => $data['order_return_recharge_json']]);
  148. }
  149. unset($data[$primary_key]);
  150. return [$id, $data];
  151. }
  152. /**
  153. * @Desc 订单商品详情
  154. * @Author Gorden
  155. * @Date 2024/3/29 8:50
  156. *
  157. * @param Request $request
  158. * @return Response
  159. */
  160. public function sheet(Request $request)
  161. {
  162. $orderId = $request->get('order_id');
  163. $orderSheet = OrderSheet::with([
  164. 'member' => function ($query) {
  165. $query->select('member_id', 'member_mobile');
  166. },
  167. 'goods' => function ($query) {
  168. $query->select('goods_id', 'goods_name', 'goods_cover', 'goods_market_price', 'goods_sales_price', 'goods_classify');
  169. },
  170. 'sku' => function ($query) {
  171. $query->select('goods_sku_id', 'join_sku_goods_id', 'goods_sku_specs_json', 'goods_sku_sales_price');
  172. },
  173. 'memberInfo',
  174. 'cert',
  175. 'refund'
  176. ])->where('join_sheet_order_id', $orderId)
  177. ->get()
  178. ->toArray();
  179. $member = [];
  180. $cert = [];
  181. $memberInfo = [];
  182. foreach ($orderSheet as &$item) {
  183. if (isset($item['member']) && empty($member)) {
  184. $member = $item['member'];
  185. }
  186. if (isset($item['cert']) && empty($cert)) {
  187. $cert = $item['cert'];
  188. }
  189. if (isset($item['member_info']) && empty($memberInfo)) {
  190. $memberInfo = $item['member_info'];
  191. }
  192. $item['goods']['goods_cover'] = getenv('STORAGE_DOMAIN') . $item['goods']['goods_cover'];
  193. if (!empty($item['goods']) && $item['goods']['goods_classify'] == 'PACKAGE') {
  194. $components = GoodsComponent::with('goods')
  195. ->where('join_component_master_goods_id', $item['goods']['goods_id'])
  196. ->select('join_component_master_goods_id', 'join_component_goods_id', 'goods_component_price',
  197. 'goods_component_price')
  198. ->get()
  199. ->toArray();
  200. $goodsArr = [];
  201. foreach ($components as $component) {
  202. $configJson = !empty($component['goods_component_config_json']) ? json_decode($component['goods_component_config_json'], true) : [];
  203. if (!empty($component['goods'])) {
  204. $goodsArr[] = [
  205. 'goods_name' => $component['goods']['goods_name'],
  206. 'goods_cover' => getenv('STORAGE_DOMAIN') . $component['goods']['goods_cover'],
  207. 'nbr' => $configJson['nbr'] ?? 0,
  208. ];
  209. }
  210. }
  211. $item['goods']['components'] = $goodsArr;
  212. }
  213. if (!empty($item['sku'])) {
  214. if (!empty($item['sku']['goods_sku_specs_json'])) {
  215. $specsJson = json_decode($item['sku']['goods_sku_specs_json'], true);
  216. $skuName = '';
  217. foreach ($specsJson as $specsKey => $skuSpecs) {
  218. if (is_array($skuSpecs)) {
  219. $skuName = $skuName . ' ' . implode(' ', $skuSpecs) . ';';
  220. } else {
  221. $skuName = $skuName . ' ' . $skuSpecs . ';';
  222. }
  223. }
  224. $item['sku']['goods_sku_title'] = rtrim($skuName, ';');
  225. }
  226. }
  227. if (!empty($item['refund'])) {
  228. if (!empty($item['refund']['order_return_apply_json']) && is_json($item['refund']['order_return_apply_json'])) {
  229. $json = json_decode($item['refund']['order_return_apply_json'], true);
  230. $item['refund']['order_return_apply_json'] = $json['reason'] ?? '';
  231. }
  232. if (!empty($item['refund']['order_return_recharge_json']) && is_json($item['refund']['order_return_recharge_json'])) {
  233. $json = json_decode($item['refund']['order_return_recharge_json'], true);
  234. $item['refund']['order_return_recharge_json'] = $json['change'] ?? '';
  235. }
  236. }
  237. }
  238. $order = Order::where('order_id', $orderId)->first();
  239. $return = OrderReturn::where('join_return_order_id', $orderId)->first();
  240. if (!empty($return->order_return_refund_json)) {
  241. $returnRefundJson = json_decode($return->order_return_refund_json, true);
  242. if (!empty($returnRefundJson['user_id'])){
  243. $return->userName = SysUser::where('user_id',$returnRefundJson['user_id'])->value('user_name');
  244. }
  245. }
  246. $express = OrderExpress::where('join_express_order_id', $orderId)->first();
  247. $data = [
  248. 'member' => $member,
  249. 'cert' => $cert,
  250. 'member_info' => $memberInfo,
  251. 'order' => $order,
  252. 'refund' => $return,
  253. 'sheet' => $orderSheet,
  254. 'express' => $express
  255. ];
  256. return json_success('', $data);
  257. }
  258. public function customRefund(Request $request)
  259. {
  260. $orderId = $request->post('order_id', '');
  261. $amount = $request->post('refund_amount', 0);
  262. $password = $request->post('refund_password', '');
  263. $remark = $request->post('refund_remark', '');
  264. if (!$orderId || !$amount || !$password) {
  265. return json_fail('参数异常');
  266. }
  267. if ($password != '123456') {
  268. return json_fail('支付密码错误');
  269. }
  270. $order = Order::where('order_id', $orderId)->where('order_status_payment', 'SUCCESS')->first();
  271. if (!$order) {
  272. return json_fail("订单异常");
  273. }
  274. if ($amount > $order->order_amount_pay) {
  275. return json_fail("退款金额不能超过支付金额");
  276. }
  277. $payDetail = PayDetail::where('join_pay_order_id', $order->order_groupby)
  278. ->where('pay_status', 'SUCCESS')
  279. ->whereIn('pay_category', ['GOODS', 'SERVICE', 'CHNMED', 'CHNNCD', 'MEALS', 'DISHES', 'VIP', 'PACKAGE'])
  280. ->get()
  281. ->toArray();
  282. if (empty($payDetail)) {
  283. return json_fail("支付状态异常");
  284. }
  285. $refundPayIds = array_column($payDetail, 'pay_id');
  286. $response = [];
  287. Db::beginTransaction();
  288. try {
  289. // 主订单,退款作为优惠入库
  290. $this->updateMainOrderByRefund($order, $amount, $remark);
  291. // return 表记录
  292. $return = OrderReturn::where('join_return_order_id', $orderId)->first();
  293. if (empty($return)) {
  294. $returnId = $this->createReturnRecord($order, $amount, $remark);
  295. } else {
  296. $returnId = $return->orders_return_id;
  297. //['amount' => $amount, 'user_id' => JwtToken::getCurrentId(), 'datetime' => date('Y-m-d H:i:s'), 'remark' => $remark ?? '']
  298. OrderReturn::where('join_return_order_id', $orderId)->update([
  299. 'order_return_status' => 'DONE',
  300. 'order_return_refund_json' => json_encode([
  301. 'amount' => $amount,
  302. 'user_id' => JwtToken::getCurrentId(),
  303. 'datetime' => date('Y-m-d H:i:s'),
  304. 'remark' => $remark ?? ''
  305. ])
  306. ]);
  307. }
  308. // 组合支付,退到余额账户
  309. $prepayid = '';
  310. if (count($payDetail) > 1) {
  311. $prepayid = $order->join_order_member_id . '-CASH';
  312. $this->refundToCash($order->join_order_member_id, $amount);
  313. $response = ['order_id' => $order->order_id, 'member_id' => $order->join_order_member_id];
  314. } else if (count($payDetail) == 1) {
  315. $payDetail0 = $payDetail[0];
  316. $payWay = explode('-', $payDetail0['pay_prepayid']);
  317. if ($payWay[0] == 'WXPAY') {
  318. $prepayid = 'WXPAY';
  319. $response = $this->refundToWx($payDetail0, $returnId, $amount);
  320. } elseif ($payWay[0] == 'ALIPAY') {
  321. $prepayid = 'ALIPAY';
  322. $response = $this->refundToAlipay($payDetail0, $amount);
  323. } elseif ($payWay[0] == 'MONEY') {
  324. $prepayid = 'MONEY';
  325. $response = $this->refundToCash($payDetail0, $amount);
  326. } elseif (isset($payWay[1]) && $payWay[1] == 'CASH') {
  327. $prepayid = $order->join_order_member_id . '-CASH';
  328. $this->refundToCash($order->join_order_member_id, $amount);
  329. $response = ['order_id' => $order->order_id, 'member_id' => $order->join_order_member_id];
  330. } elseif (isset($payWay[1]) && $payWay[1] == 'WELFARE') {
  331. $prepayid = $order->join_order_member_id . '-WELFARE';
  332. $this->refundToWelfare($order->join_order_member_id, $amount);
  333. $response = ['order_id' => $order->order_id, 'member_id' => $order->join_order_member_id];
  334. } elseif (isset($payWay[1]) && $payWay[1] == 'VIP') {
  335. $prepayid = $order->join_order_member_id . '-VIP';
  336. $this->refundToVIP($order->join_order_member_id, $amount);
  337. $response = ['order_id' => $order->order_id, 'member_id' => $order->join_order_member_id];
  338. } elseif (isset($payWay['1']) && $payWay[1] == 'CARD') {
  339. $prepayid = $order->join_order_member_id . '-CARD';
  340. $this->refundToCard($order->join_order_member_id, $amount);
  341. $response = ['order_id' => $order->order_id, 'member_id' => $order->join_order_member_id];
  342. } elseif ($payWay[0] == 'OFFLINE') {
  343. $prepayid = 'OFFLINE';
  344. $response = [];
  345. } elseif ($payWay[0] == 'OFFLINE_ALIPAY') {
  346. $prepayid = 'OFFLINE_ALIPAY';
  347. $response = [];
  348. } elseif ($payWay[0] == 'OFFLINE_WXPAY') {
  349. $prepayid = 'OFFLINE_WXPAY';
  350. $response = [];
  351. }
  352. }
  353. // payDetail 表记录
  354. $this->createReturnPayDetail($order, $refundPayIds, $prepayid, $amount, $response);
  355. Db::commit();
  356. return json_success('success');
  357. } catch (BusinessException $e) {
  358. Db::rollBack();
  359. dump($e->getMessage());
  360. return json_fail($e->getMessage());
  361. } catch (\Exception $e) {
  362. Db::rollBack();
  363. dump($e->getMessage());
  364. return json_fail("退款失败");
  365. }
  366. }
  367. /**
  368. * @Desc 退款到余额
  369. * @Author Gorden
  370. * @Date 2024/8/20 11:54
  371. *
  372. * @param $memberId
  373. * @param $amount
  374. * @return void
  375. * @throws BusinessException
  376. */
  377. private function refundToCash($memberId, $amount)
  378. {
  379. $account = MemberAccount::where('join_account_member_id', $memberId)->where('member_account_classify', 'CASH')->first();
  380. if (!$account) {
  381. throw new BusinessException("余额账户异常");
  382. }
  383. $account->member_account_surplus = $account->member_account_surplus + $amount;
  384. $account->save();
  385. }
  386. /**
  387. * @Desc 退款到福利账户
  388. * @Author Gorden
  389. * @Date 2024/9/20 17:09
  390. *
  391. * @param $memberId
  392. * @param $amount
  393. * @return void
  394. * @throws BusinessException
  395. */
  396. private function refundToWelfare($memberId, $amount)
  397. {
  398. $account = MemberAccount::where('join_account_member_id', $memberId)->where('member_account_classify', 'WELFARE')->first();
  399. if (!$account) {
  400. throw new BusinessException("余额账户异常");
  401. }
  402. $account->member_account_surplus = $account->member_account_surplus + $amount;
  403. $account->save();
  404. }
  405. /**
  406. * @Desc 退款到VIP账户
  407. * @Author Gorden
  408. * @Date 2024/9/20 17:12
  409. *
  410. * @param $memberId
  411. * @param $amount
  412. * @return void
  413. * @throws BusinessException
  414. */
  415. private function refundToVIP($memberId, $amount)
  416. {
  417. $account = MemberAccount::where('join_account_member_id', $memberId)->where('member_account_classify', 'VIP')->first();
  418. if (!$account) {
  419. throw new BusinessException("余额账户异常");
  420. }
  421. $account->member_account_surplus = $account->member_account_surplus + $amount;
  422. $account->save();
  423. }
  424. /**
  425. * @Desc 退款到储蓄卡
  426. * @Author Gorden
  427. * @Date 2024/8/20 14:47
  428. *
  429. * @param $memberId
  430. * @param $amount
  431. * @return void
  432. * @throws BusinessException
  433. */
  434. private function refundToCard($cardNbr, $amount)
  435. {
  436. $account = MemberAccount::where('member_account_nbr', $cardNbr)->where('member_account_classify', 'CARD')->first();
  437. if (!$account) {
  438. throw new BusinessException("储值卡账户异常");
  439. }
  440. $account->member_account_surplus = $account->member_account_surplus + $amount;
  441. $account->save();
  442. }
  443. /**
  444. * @Desc
  445. * @Author Gorden
  446. * @Date 2024/8/20 14:17
  447. *
  448. * @param $params
  449. * @param $returnId
  450. * @param $amount
  451. * @return mixed
  452. * @throws BusinessException
  453. * @throws \Yansongda\Pay\Exceptions\GatewayException
  454. * @throws \Yansongda\Pay\Exceptions\InvalidArgumentException
  455. * @throws \Yansongda\Pay\Exceptions\InvalidSignException
  456. */
  457. private function refundToWx($params, $returnId, $amount)
  458. {
  459. try {
  460. $data = [
  461. 'type' => 'app',
  462. 'out_trade_no' => $params['join_pay_order_id'],
  463. 'out_refund_no' => $returnId,
  464. 'total_fee' => $params['pay_amount'] * 100,
  465. 'refund_fee' => $amount * 100,
  466. 'refund_desc' => '退款',
  467. ];
  468. $res = Pay::wechat(config('payment.wxpay'))->refund($data);
  469. $resArray = json_decode($res, true);
  470. if (!$resArray['result_code'] == 'SUCCESS' || !$resArray['return_code'] == 'SUCCESS') {
  471. Log::channel('pay')->error('WXPAY_REFUND_FAIL', $resArray);
  472. throw new BusinessException("退款失败");
  473. }
  474. return $resArray;
  475. } catch (\Exception $e) {
  476. throw new BusinessException("退款失败");
  477. }
  478. }
  479. /**
  480. * @Desc 支付宝退款
  481. * @Author Gorden
  482. * @Date 2024/8/20 14:40
  483. *
  484. * @param $params
  485. * @param $amount
  486. * @return mixed
  487. * @throws BusinessException
  488. */
  489. private function refundToAlipay($params, $amount)
  490. {
  491. $data = [
  492. 'out_trade_no' => $params['join_pay_order_id'],
  493. 'refund_amount' => $amount,
  494. ];
  495. try {
  496. $res = Pay::alipay(config('payment.alipay'))->refund($data);
  497. $resArray = json_decode($res, true);
  498. if ($resArray['fund_change'] != 'Y' || $resArray['msg'] != 'Success') {
  499. Log::channel('pay')->error('ALIPAY_REFUND_FAIL', $resArray);
  500. throw new BusinessException("退款失败");
  501. }
  502. return $resArray;
  503. } catch (\Exception $e) {
  504. throw new BusinessException("退款失败");
  505. }
  506. }
  507. /**
  508. * @Desc 更新主订单
  509. * @Author Gorden
  510. * @Date 2024/8/20 14:56
  511. *
  512. * @param $order
  513. * @param $amount
  514. * @param $remark
  515. * @return void
  516. * @throws BusinessException
  517. */
  518. private function updateMainOrderByRefund($order, $amount, $remark)
  519. {
  520. $orderDiscountJson = [];
  521. if (!empty($order->order_discount_json)) {
  522. $orderDiscountJson = json_decode($order->order_discount_json, true);
  523. }
  524. try {
  525. $orderDiscountJson[date('YH:i:s H:i:s')] = [
  526. 'coupon_id' => null,
  527. 'coupon_value' => $amount,
  528. 'coupon_classify' => '退款',
  529. 'coupon_detail_id' => [$remark]
  530. ];
  531. $order->order_discount_json = json_encode($orderDiscountJson, JSON_UNESCAPED_UNICODE);
  532. $order->order_is_complete = 'R';
  533. // $order->order_amount_pay = $order->order_amount_pay - $amount;
  534. $order->save();
  535. } catch (\Exception $e) {
  536. throw new BusinessException("退款失败");
  537. }
  538. }
  539. /**
  540. * @Desc
  541. * @Author Gorden
  542. * @Date 2024/8/20 13:51
  543. *
  544. * @param $order
  545. * @return int
  546. * @throws BusinessException
  547. */
  548. private function createReturnRecord($order, $amount, $remark)
  549. {
  550. try {
  551. return OrderReturn::insertGetId([
  552. 'join_order_return_user_id' => JwtToken::getCurrentId(),
  553. 'join_return_member_id' => $order->join_order_member_id,
  554. 'join_return_order_id' => $order->order_id,
  555. 'order_return_status' => 'DONE',
  556. 'order_return_category' => '退款',
  557. 'order_return_apply_datetime' => date('Y-m-d H:i:s'),
  558. 'order_return_apply_json' => json_encode(['reason' => '后台自定义退款']),
  559. 'order_return_accept_datetime' => date('Y-m-d H:i:s'),
  560. 'order_return_refund_json' => json_encode(['amount' => $amount, 'user_id' => JwtToken::getCurrentId(), 'datetime' => date('Y-m-d H:i:s'), 'remark' => $remark ?? '']),
  561. 'order_return_addtimes' => time()
  562. ]);
  563. } catch (\Exception $e) {
  564. throw new BusinessException("创建退款信息失败");
  565. }
  566. }
  567. private function createReturnPayDetail($order, $refundPayIds, $prepayid, $amount, $response = [])
  568. {
  569. try {
  570. return PayDetail::insert([
  571. 'join_pay_member_id' => $order->join_order_member_id,
  572. 'join_pay_order_id' => $order->order_groupby,
  573. 'pay_status' => 'SUCCESS',
  574. 'pay_category' => 'REFUND',
  575. 'pay_amount' => $amount,
  576. 'pay_paytimes' => date('Y-m-d H:i:s'),
  577. 'pay_prepayid' => $prepayid,
  578. 'join_pay_object_json' => json_encode(['order_id' => $order->order_id, 'refund_pay_ids' => $refundPayIds]),
  579. 'pay_json_request' => json_encode(['order_id' => $order->order_id]),
  580. 'pay_json_response' => json_encode($response),
  581. 'pay_addtimes' => time()
  582. ]);
  583. } catch (\Exception $e) {
  584. }
  585. }
  586. }