From e17eb1da6aaf11d0d880809799628603b0680fb1 Mon Sep 17 00:00:00 2001 From: ljl Date: Tue, 15 Aug 2023 21:19:02 +0800 Subject: [PATCH] yh --- app/Controller/Payment/PaymentController.php | 6 ++ app/Helper/Baofu/ApiList.php | 5 ++ app/Helper/Baofu/Baofu.php | 28 ++++++++- app/Model/Order.php | 1 + app/Service/PaymentService.php | 64 +++++++++++++++++--- payment.sql | 11 +++- 6 files changed, 106 insertions(+), 9 deletions(-) diff --git a/app/Controller/Payment/PaymentController.php b/app/Controller/Payment/PaymentController.php index ae95101..8097e70 100644 --- a/app/Controller/Payment/PaymentController.php +++ b/app/Controller/Payment/PaymentController.php @@ -81,6 +81,12 @@ class PaymentController extends AbstractController return $this->success(['url' => $url]); } + public function transferPay(RequestInterface $request) { + [$app, $data, $token] = $this->parseReqest($request, UnbindCardRequest::class); + $acsNo = $this->paymentService->transferPay($data, $app, $token); + return $this->success(['acsNo' => $acsNo]); + } + public function refundApply(RequestInterface $request) { [$app, $data, $token] = $this->parseReqest($request, UnbindCardRequest::class); diff --git a/app/Helper/Baofu/ApiList.php b/app/Helper/Baofu/ApiList.php index 3b964c7..967afae 100644 --- a/app/Helper/Baofu/ApiList.php +++ b/app/Helper/Baofu/ApiList.php @@ -45,6 +45,11 @@ class ApiList 'url' => '/api/order/v3.0.0/paymentSplitApi', 'signParams' => 'orgNo|merchantNo|terminalNo|loginNo|requestDate|outOrderNo|amount|paidType|splitInfoList', ], + 'transfer-split-pay' => [ + 'description' => '担保支付-转账支付', + 'url' => '/api/transfer/v3.0.0/transferSplitPay', + 'signParams' => 'orgNo|merchantNo|loginNo|terminalNo|requestDate|dataContent', + ], 'payment' => [ 'description' => '个人担保支付-聚合支付', 'url' => '/api/wallet/v3.0.0/payment', diff --git a/app/Helper/Baofu/Baofu.php b/app/Helper/Baofu/Baofu.php index 1103dfe..f4e398f 100644 --- a/app/Helper/Baofu/Baofu.php +++ b/app/Helper/Baofu/Baofu.php @@ -102,7 +102,33 @@ class Baofu return $this->withReturnUrl($this->api('payment-split', $data), $token); } - public function unifyPay($params){ + public function transferSplitPay($params, $token) + { + $dataContent = [ + 'goodsName' => $params['goodsName'], + 'amount' => $params['amount'], + 'outOrderNo' => $params['outOrderNo'], + 'agreementNo' => $params['agreementNo'], + 'notifyUrl' => NotifyList::getNotifyUrl('payment', $token), + 'expireDate' => $params['expireDate'], + 'validDate' => $params['validDate'], + 'splitInfoList' => $params['splitInfoList'], + 'marketInfo' => [ + 'marketAmount' => $params['marketInfo']['amount'], + 'remark' => $params['marketInfo']['remark'], + ], + ]; + + $data = []; + $data['loginNo'] = $params['loginNo']; + $data['callType'] = 'TRANSFER_ASSURE_PORTFOLIO_PAYMENT'; + $data['dataContent'] = json_encode($dataContent); + $data['isDeductMarketAmount'] = '0'; + return $this->api('transfer-split-pay', $data); + } + + public function unifyPay($params) + { $dataContent = [ 'goodsName' => $params['goodsName'], 'amount' => $params['amount'], diff --git a/app/Model/Order.php b/app/Model/Order.php index 909be51..8b703dd 100644 --- a/app/Model/Order.php +++ b/app/Model/Order.php @@ -18,6 +18,7 @@ class Order extends Model protected $casts = [ 'org_split_info_list' => 'array', + 'market_info' => 'array', ]; public function getExpiresIn() { diff --git a/app/Service/PaymentService.php b/app/Service/PaymentService.php index f28e444..e15c9b7 100644 --- a/app/Service/PaymentService.php +++ b/app/Service/PaymentService.php @@ -36,7 +36,25 @@ class PaymentService extends AbstractService throw new BusinessException('订单号重复'); } - [$order, $orderSplitInfos] = $this->createOrder($app, $data, $user); + [$order, $orderSplitInfos] = $this->createOrder($app, $data, $user, 'paymentSplit'); + + $splitInfoList = $this->buildSplitInfoList($orderSplitInfos); + + return $this->paymentSplit($order, $user, $splitInfoList, $token); + } + + public function transferPay() + { + $user = User::where('app_id', $app->app_id)->where('user_id', $data['userId'])->first(); + if (empty($user)) { + throw new BusinessException('用户不存在'); + } + $order = Order::where('app_id', $app->app_id)->where('out_order_no', $data['outOrderNo'])->first(); + if ($order) { + throw new BusinessException('订单号重复'); + } + + [$order, $orderSplitInfos] = $this->createOrder($app, $data, $user, 'transferSplitPay'); $splitInfoList = $this->buildSplitInfoList($orderSplitInfos); @@ -67,7 +85,7 @@ class PaymentService extends AbstractService 'amount' => $order->amount, 'paidType' => 'CARD', 'agreementNo' => $order->agreement_no, - 'pwdPayExpTime' => strtotime($order->expired_at), + 'pwdPayExpTime' => strtotime($order->expires_in), 'splitInfoList' => $splitInfoList, ], $token); $order->status = 'APPLY_SUCCESS'; @@ -85,7 +103,36 @@ class PaymentService extends AbstractService } } - public function createOrder(App $app, array $params, User $user) { + private function transferSplitPay(Order $order, User $user, array $splitInfoList, string $token) + { + try { + $baofu = new Baofu(); + $result = $baofu->transferSplitPay([ + 'loginNo' => $user->member_id, + 'outOrderNo' => $order->order_no, + 'amount' => $order->amount, + 'agreementNo' => $order->agreement_no, + 'expireDate' => date('YmdHis', time() + $order->expires_in), + 'validDate' => $order->valid_date, + 'splitInfoList' => $splitInfoList, + 'marketInfo' => $order->market_info, + ], $token); + $order->status = 'APPLY_SUCCESS'; + $order->applied_at = date('Y-m-d H:i:s'); + $order->acs_no = $result['acsNo']; + $order->save(); + return $result['acsNo']; + } catch (ApiException $e) { + $order->status = 'APPLY_FAILED'; + $order->applied_at = date('Y-m-d H:i:s'); + $order->error_code = $e->getErrorCode(); + $order->error_message = $e->getMessage(); + $order->save(); + throw $e; + } + } + + public function createOrder(App $app, array $params, User $user, string $payMethod) { $expiresIn = $params['expiresIn'] ?? 10 * 60; $order = new Order(); $order->app_id = $app->app_id; @@ -95,13 +142,16 @@ class PaymentService extends AbstractService $order->out_order_no = $params['outOrderNo']; $order->amount = $params['amount']; $order->notify_url = $params['notifyUrl']; - $order->return_url = $params['returnUrl']; - $order->agreement_no = $params['agreementNo'] ?: ''; + $order->return_url = $params['returnUrl'] ?? ''; + $order->agreement_no = $params['agreementNo'] ?? ''; $order->status = 'PREPARE'; $order->pay_channel = 'BAOFU'; - $order->pay_method = 'paymentSplit'; + $order->pay_method = $payMethod; $order->pay_type = 'CARD'; - $order->expired_at = date('Y-m-d H:i:s', $expiresIn); + $order->valid_date = $params['valid_date'] ?? null; + $order->expires_in = $expiresIn, + $order->expired_at = date('Y-m-d H:i:s', time() + $expiresIn); + $order->market_info = $params['marketInfo'] ?? []; $order->org_split_info_list = $params['splitInfoList']; $order->save(); diff --git a/payment.sql b/payment.sql index 8cb5c4a..7d40078 100644 --- a/payment.sql +++ b/payment.sql @@ -115,11 +115,15 @@ CREATE TABLE `orders` ( `pay_type` varchar(20) NOT NULL, `agreement_no` varchar(32) NOT NULL DEFAULT '', `expired_at` datetime DEFAULT NULL, + `expires_in` int(11) NOT NULL DEFAULT 0, + `valid_date` date DEFAULT NULL, + `market_info` varchar(255) NOT NULL DEFAULT '', `applied_at` datetime DEFAULT NULL, `notify_url` varchar(255) NOT NULL DEFAULT '', `return_url` varchar(255) NOT NULL DEFAULT '', `org_split_info_list` varchar(512) NOT NULL DEFAULT '', `pay_url` varchar(255) NOT NULL DEFAULT '', + `acs_no` varchar(32) NOT NULL DEFAULT '', `status` varchar(16) NOT NULL DEFAULT '', `error_code` varchar(64) NOT NULL DEFAULT '', `error_message` varchar(120) NOT NULL DEFAULT '', @@ -211,4 +215,9 @@ CREATE TABLE `refund_split_infos` ( KEY `idx_appid` (`app_id`) USING BTREE, KEY `idx_memberid` (`member_id`) USING BTREE, KEY `idx_createdat` (`created_at`) USING BTREE -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 ROW_FORMAT=DYNAMIC; \ No newline at end of file +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 ROW_FORMAT=DYNAMIC; + +-- `expires_in` int(11) NOT NULL DEFAULT 0, +-- `valid_date` date DEFAULT NULL, +-- `market_info` varchar(255) NOT NULL DEFAULT '', +-- `acs_no` varchar(32) NOT NULL DEFAULT '', \ No newline at end of file