From dfb21ea4ea1b5d2f4344a53a349a233b9f5b3373 Mon Sep 17 00:00:00 2001 From: elf <360197197@qq.com> Date: Wed, 16 Aug 2023 00:26:20 +0800 Subject: [PATCH] yh --- app/Command/MineCommand.php | 36 ++++++++++++++++++-- app/Helper/Baofu/ApiList.php | 5 +++ app/Helper/Baofu/Baofu.php | 18 +++++++++- app/Helper/StringHelper.php | 1 + app/Service/PaymentService.php | 62 ++++++++++++++++++++++++++++++---- payment.sql | 12 ++++--- 6 files changed, 121 insertions(+), 13 deletions(-) diff --git a/app/Command/MineCommand.php b/app/Command/MineCommand.php index 6a6c308..a80c022 100644 --- a/app/Command/MineCommand.php +++ b/app/Command/MineCommand.php @@ -45,7 +45,7 @@ class MineCommand extends HyperfCommand public function handle(): void { - $this->payment(); + $this->transferPay(); return; // $this->notify('http://ceshi-shop.hkcpex.com/index.php/pay/notify/baofu_f_register', $this->getApp(), ['userId' => '30684']); $this->notify('http://ceshi-shop.hkcpex.com/index.php/pay/notify/baofu_f_bind_card', $this->getApp(), ['userId' => '23121', 'bindCardFlag' => true]); @@ -89,7 +89,7 @@ class MineCommand extends HyperfCommand return $requestService->createRequestLog('/', $params); } - protected function getApp($appId = '202308070000001') { + protected function getApp($appId = '202308040000002') { return App::where('app_id', $appId)->first(); } @@ -293,4 +293,36 @@ class MineCommand extends HyperfCommand Log::info('notifyToOut response:' . $result, [], 'platform'); var_dump($result); } + + protected function transferPay() + { + /** + * @var PaymentService $paymentService + */ + $paymentService = $this->container->make(PaymentService::class); + $data = [ + 'userId' => 'ELF1990', + 'goodsName' => '测试商品', + 'agreementNo' => '312023081200002052866', + 'notifyUrl' => 'http://www.baidu.com', + 'returnUrl' => 'http://www.baidu.com', + 'amount' => 100, + 'outOrderNo' => time() . rand(1000, 9999), + 'validDate' => '2023-08-15', + 'marketInfo' => [ + 'amount' => 1, + 'remark' => 'test', + ], + 'splitInfoList' => [ + [ + 'splitUserId' => 'RLX1990', + 'sellerFlag' => 1, + 'splitAmount' => 100, + 'subOutOrderNo' => time() . rand(1000, 9999), + ] + ] + ]; + $result = $paymentService->transferPay($data, $this->getApp(), $this->getToken()); + var_dump($result); + } } \ No newline at end of file diff --git a/app/Helper/Baofu/ApiList.php b/app/Helper/Baofu/ApiList.php index 967afae..8beedb6 100644 --- a/app/Helper/Baofu/ApiList.php +++ b/app/Helper/Baofu/ApiList.php @@ -95,6 +95,11 @@ class ApiList 'url' => '/api/wallet/v3.0.0/confirmAssurePay', 'signParams' => 'orgNo|merchantNo|loginNo|terminalNo|requestDate|dataContent', ], + 'confirm-assure-portfoli-pay' => [ + 'description' => '营销支付-确认分账', + 'url' => '/api/wallet/v3.0.0/confirmAssurePortfolioPay', + 'signParams' => 'orgNo|merchantNo|loginNo|terminalNo|requestDate|dataContent', + ], 'refund-request' => [ 'description' => '担保支付-分账前退款', 'url' => '/api/trade/v3.0.0/refundRequest', diff --git a/app/Helper/Baofu/Baofu.php b/app/Helper/Baofu/Baofu.php index f4e398f..9a2e35f 100644 --- a/app/Helper/Baofu/Baofu.php +++ b/app/Helper/Baofu/Baofu.php @@ -122,7 +122,7 @@ class Baofu $data = []; $data['loginNo'] = $params['loginNo']; $data['callType'] = 'TRANSFER_ASSURE_PORTFOLIO_PAYMENT'; - $data['dataContent'] = json_encode($dataContent); + $data['dataContent'] = json_encode($dataContent, JSON_UNESCAPED_UNICODE); $data['isDeductMarketAmount'] = '0'; return $this->api('transfer-split-pay', $data); } @@ -255,6 +255,22 @@ class Baofu return $this->api('confirm-assure-pay', $data); } + public function confirmAssurePortfolioPay($params) + { + $dataContent = [ + 'amount' => $params['amount'], + 'outOrderNo' => $params['outOrderNo'], + 'assureConfirmSplitInfoList' => $params['assureConfirmSplitInfoList'], + 'oldOutOrderNo' => $params['oldOutOrderNo'], + ]; + + $data = []; + $data['loginNo'] = $params['loginNo']; + $data['dataContent'] = json_encode($dataContent); + $data['notifyUrl'] = $params['notifyUrl']; + return $this->api('confirm-assure-portfoli-pay', $data); + } + public function findBindBankCards($params) { $data = []; diff --git a/app/Helper/StringHelper.php b/app/Helper/StringHelper.php index b82a36a..b881ac0 100644 --- a/app/Helper/StringHelper.php +++ b/app/Helper/StringHelper.php @@ -9,6 +9,7 @@ class StringHelper const ORDER_NO_TYPE_PAY = 'pay'; const ORDER_NO_TYPE_PAY_SPLIT = 'pay_split'; const ORDER_NO_TYPE_REFUND= 'refund'; + const ORDER_NO_TYPE_CONFIRM_PAY= 'confirm_pay'; const ORDER_NO_TYPE_UNBIND_CARD = 'unbind_card'; const ORDER_NO_TYPE_QUERY_CUSTOMER_INFO = 'query_customer_info'; const ORDER_NO_TYPE_REQUEST_ID = 'request_id'; diff --git a/app/Service/PaymentService.php b/app/Service/PaymentService.php index e15c9b7..9cca938 100644 --- a/app/Service/PaymentService.php +++ b/app/Service/PaymentService.php @@ -43,7 +43,7 @@ class PaymentService extends AbstractService return $this->paymentSplit($order, $user, $splitInfoList, $token); } - public function transferPay() + public function transferPay(array $data, App $app, string $token) { $user = User::where('app_id', $app->app_id)->where('user_id', $data['userId'])->first(); if (empty($user)) { @@ -58,7 +58,7 @@ class PaymentService extends AbstractService $splitInfoList = $this->buildSplitInfoList($orderSplitInfos); - return $this->paymentSplit($order, $user, $splitInfoList, $token); + return $this->transferSplitPay($order, $user, $splitInfoList, $token); } private function buildSplitInfoList($orderSplitInfos) { @@ -110,10 +110,11 @@ class PaymentService extends AbstractService $result = $baofu->transferSplitPay([ 'loginNo' => $user->member_id, 'outOrderNo' => $order->order_no, + 'goodsName' => $order->goods_name, 'amount' => $order->amount, 'agreementNo' => $order->agreement_no, 'expireDate' => date('YmdHis', time() + $order->expires_in), - 'validDate' => $order->valid_date, + 'validDate' => date('Ymd', strtotime($order->valid_date)), 'splitInfoList' => $splitInfoList, 'marketInfo' => $order->market_info, ], $token); @@ -141,6 +142,7 @@ class PaymentService extends AbstractService $order->order_no = StringHelper::generateOrderNo(StringHelper::ORDER_NO_TYPE_PAY); $order->out_order_no = $params['outOrderNo']; $order->amount = $params['amount']; + $order->goods_name = $params['goodsName'] ?? ''; $order->notify_url = $params['notifyUrl']; $order->return_url = $params['returnUrl'] ?? ''; $order->agreement_no = $params['agreementNo'] ?? ''; @@ -148,8 +150,8 @@ class PaymentService extends AbstractService $order->pay_channel = 'BAOFU'; $order->pay_method = $payMethod; $order->pay_type = 'CARD'; - $order->valid_date = $params['valid_date'] ?? null; - $order->expires_in = $expiresIn, + $order->valid_date = $params['validDate'] ?? 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']; @@ -161,7 +163,10 @@ class PaymentService extends AbstractService $splitUserIds = array_column($params['splitInfoList'], 'splitUserId'); $users = User::where('app_id', $app->app_id)->whereIn('user_id', $splitUserIds)->get()->keyBy('user_id'); foreach ($params['splitInfoList'] as $splitInfo) { - $splitUser = $users[$splitInfo['splitUserId']]; + $splitUser = $users[$splitInfo['splitUserId']] ?? null; + if (empty($splitUser)) { + throw new BusinessException('分账用户不存在'); + } $splitAmount = $splitInfo['sellerFlag'] == 1 ? ($splitInfo['splitAmount'] - $fee): $splitInfo['splitAmount']; $orderSplitInfos[] = [ 'app_id' => $app->app_id, @@ -367,4 +372,49 @@ class PaymentService extends AbstractService $refund->save(); return $refund; } + + public function confirmPay(array $data, App $app, string $token) + { + $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 (empty($order)) { + throw new BusinessException('订单不存在'); + } + + if ($order->status != Order::STATUS_APPLY_SUCCESS) { + throw new BusinessException('订单状态异常'); + } + + $confirmSplitInfoList = []; + foreach ($order->orderSplitInfos as $orderSplitInfo) { + $confirmSplitInfoList[] = [ + 'oldSubOutOrderNo' => $orderSplitInfo->sub_order_no, + 'splitAmount' => $orderSplitInfo->split_amount, + ]; + } + + try { + $baofu = new Baofu(); + $result = $baofu->confirmAssurePortfolioPay([ + 'loginNo' => $user->member_id, + 'oldOutOrderNo' => $order->order_no, + 'assureConfirmSplitInfoList' => $confirmSplitInfoList, + 'outOrderNo' => StringHelper::generateOrderNo(StringHelper::ORDER_NO_TYPE_CONFIRM_PAY), + 'amount' => $data['amount'], + 'notifyUrl' => $data['notifyUrl'], + ], $token); + $order->status = 'CONFIRM_SUCCESS'; + $order->save(); + return $result; + } catch (ApiException $e) { + $order->status = 'CONFIRM_FAILED'; + $order->error_code = $e->getCode(); + $order->error_message = $e->getMessage(); + $order->save(); + throw $e; + } + } } diff --git a/payment.sql b/payment.sql index 7d40078..49ddd66 100644 --- a/payment.sql +++ b/payment.sql @@ -217,7 +217,11 @@ CREATE TABLE `refund_split_infos` ( KEY `idx_createdat` (`created_at`) USING BTREE ) 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 +alter table orders +add column `expires_in` int(11) NOT NULL DEFAULT 0 after expired_at, +add column `valid_date` date DEFAULT NULL after expires_in, +add column `market_info` varchar(255) NOT NULL DEFAULT '' after valid_date, +add column `acs_no` varchar(32) NOT NULL DEFAULT '' after market_info; + +alter table orders +add column `goods_name` varchar(125) NOT NULL DEFAULT '' after amount; \ No newline at end of file