|
|
@@ -11,6 +11,7 @@ namespace app\controller\merchant\store\order;
|
|
11
|
11
|
|
|
12
|
12
|
use app\common\repositories\store\order\MerchantReconciliationRepository;
|
|
13
|
13
|
use app\common\repositories\store\order\StoreRefundStatusRepository;
|
|
|
14
|
+use app\services\ThirdParty\AlibabaAgent\OrderService;
|
|
14
|
15
|
use think\App;
|
|
15
|
16
|
use crmeb\basic\BaseController;
|
|
16
|
17
|
use app\common\repositories\store\order\StoreRefundOrderRepository as repository;
|
|
|
@@ -481,4 +482,102 @@ class RefundOrder extends BaseController
|
|
481
|
482
|
// return app('json')->fail('订单信息或状态错误');
|
|
482
|
483
|
return app('json')->success($this->repository->express($id));
|
|
483
|
484
|
}
|
|
|
485
|
+
|
|
|
486
|
+ public function refundReasonList()
|
|
|
487
|
+ {
|
|
|
488
|
+ $orderId = request()->param('alibaba_order_id');
|
|
|
489
|
+
|
|
|
490
|
+ if (empty($orderId)) {
|
|
|
491
|
+ return app('json')->fail('订单号不能为空');
|
|
|
492
|
+ }
|
|
|
493
|
+
|
|
|
494
|
+ $orderService = new OrderService();
|
|
|
495
|
+ $params = ['orderId' => $orderId];
|
|
|
496
|
+ $result = $orderService->getRefundReasonList($params);
|
|
|
497
|
+ if ($result === false) {
|
|
|
498
|
+ return app('json')->fail('获取退款原因失败');
|
|
|
499
|
+ }
|
|
|
500
|
+
|
|
|
501
|
+ return app('json')->success($result);
|
|
|
502
|
+ }
|
|
|
503
|
+
|
|
|
504
|
+ public function submitAli()
|
|
|
505
|
+ {
|
|
|
506
|
+ $data = $this->request->params([
|
|
|
507
|
+ 'orderId',
|
|
|
508
|
+ 'orderEntryIds',
|
|
|
509
|
+ 'disputeRequest',
|
|
|
510
|
+ 'description',
|
|
|
511
|
+ 'applyPayment',
|
|
|
512
|
+ 'applyCarriage',
|
|
|
513
|
+ 'applyReasonId',
|
|
|
514
|
+ 'goodsStatus',
|
|
|
515
|
+ 'refund_order_id',
|
|
|
516
|
+ ]);
|
|
|
517
|
+
|
|
|
518
|
+ // 参数校验(所有参数均为必填)
|
|
|
519
|
+ $requiredFields = ['orderId', 'orderEntryIds', 'disputeRequest', 'description', 'applyPayment', 'applyCarriage', 'applyReasonId', 'goodsStatus'];
|
|
|
520
|
+ foreach ($requiredFields as $field) {
|
|
|
521
|
+ if (!isset($data[$field])) {
|
|
|
522
|
+ return app('json')->fail('缺少必填参数: ' . $field);
|
|
|
523
|
+ }
|
|
|
524
|
+ }
|
|
|
525
|
+
|
|
|
526
|
+ $orderService = new OrderService();
|
|
|
527
|
+
|
|
|
528
|
+ // 构建1688接口参数(前端 disputeRequest 映射为 1688 接口的 disputeReasonId)
|
|
|
529
|
+ $params = [
|
|
|
530
|
+ 'orderId' => (string)$data['orderId'],
|
|
|
531
|
+ 'orderEntryIds' => $data['orderEntryIds'],
|
|
|
532
|
+ 'disputeReasonId' => (string)$data['disputeRequest'],
|
|
|
533
|
+ 'description' => (string)$data['description'],
|
|
|
534
|
+ 'applyPayment' => (string)$data['applyPayment'] * 100,
|
|
|
535
|
+ 'applyCarriage' => (string)$data['applyCarriage'] * 100,
|
|
|
536
|
+ 'applyReasonId' => (string)$data['applyReasonId'],
|
|
|
537
|
+ 'goodsStatus' => (string)$data['goodsStatus'],
|
|
|
538
|
+ ];
|
|
|
539
|
+
|
|
|
540
|
+ // 调用1688 API提交售后申请
|
|
|
541
|
+ $result = $orderService->createRefund($params);
|
|
|
542
|
+
|
|
|
543
|
+ // 记录到 store_refund_alibaba 表(不管成功与否都保存原始数据)
|
|
|
544
|
+ $insertData = [
|
|
|
545
|
+ 'refund_order_id' => (int)($data['refund_order_id'] ?? 0),
|
|
|
546
|
+ 'alibaba_order_id' => (string)$data['orderId'],
|
|
|
547
|
+ 'order_entry_ids' => $data['orderEntryIds'],
|
|
|
548
|
+ 'dispute_reason_id' => (string)$data['disputeRequest'],
|
|
|
549
|
+ 'description' => (string)$data['description'],
|
|
|
550
|
+ 'goods_status' => (string)$data['goodsStatus'],
|
|
|
551
|
+ 'apply_payment' => (string)$data['applyPayment'],
|
|
|
552
|
+ 'apply_carriage' => (string)$data['applyCarriage'],
|
|
|
553
|
+ 'result_data' => json_encode($result['rawData'] ?? [], JSON_UNESCAPED_UNICODE),
|
|
|
554
|
+ ];
|
|
|
555
|
+
|
|
|
556
|
+ if ($result['success']) {
|
|
|
557
|
+ // 提交成功
|
|
|
558
|
+ $insertData['status'] = 1;
|
|
|
559
|
+ $insertData['alibaba_refund_id'] = $result['refundId'] ?? '';
|
|
|
560
|
+ $insertData['alibaba_status'] = $result['status'] ?? '';
|
|
|
561
|
+ Db::name('store_refund_alibaba')->insert($insertData);
|
|
|
562
|
+
|
|
|
563
|
+ // 更新退款单的 after_sn 字段为1688售后单ID
|
|
|
564
|
+ if (!empty($data['refund_order_id']) && !empty($result['refundId'])) {
|
|
|
565
|
+ Db::name('store_refund_order')
|
|
|
566
|
+ ->where('refund_order_id', (int)$data['refund_order_id'])
|
|
|
567
|
+ ->update(['after_sn' => $result['refundId']]);
|
|
|
568
|
+ }
|
|
|
569
|
+
|
|
|
570
|
+ return app('json')->success([
|
|
|
571
|
+ 'alibaba_refund_id' => $result['refundId'] ?? '',
|
|
|
572
|
+ 'alibaba_status' => $result['status'] ?? '',
|
|
|
573
|
+ ], '提交1688售后申请成功');
|
|
|
574
|
+ } else {
|
|
|
575
|
+ // 提交失败
|
|
|
576
|
+ $insertData['status'] = 2;
|
|
|
577
|
+ $insertData['fail_message'] = $result['status'] ?? '1688接口调用失败';
|
|
|
578
|
+ Db::name('store_refund_alibaba')->insert($insertData);
|
|
|
579
|
+ return app('json')->fail($result['status'] ?? '提交1688售后申请失败');
|
|
|
580
|
+ }
|
|
|
581
|
+ }
|
|
|
582
|
+
|
|
484
|
583
|
}
|