From f082399caf9a9026a6618d69b43603851224db34 Mon Sep 17 00:00:00 2001 From: ljl Date: Tue, 19 Sep 2023 19:43:41 +0800 Subject: [PATCH] yh --- app/Controller/Payment/PaymentController.php | 21 ++++++++++++ app/Helper/Baofu/ApiList.php | 10 ++++++ app/Helper/Baofu/Baofu.php | 33 ++++++++++++++++++ app/Helper/Baofu/H5List.php | 12 +++++++ app/Service/PaymentService.php | 35 ++++++++++++++++++- app/Service/UserService.php | 36 ++++++++++++++++++++ config/routes.php | 3 ++ 7 files changed, 149 insertions(+), 1 deletion(-) diff --git a/app/Controller/Payment/PaymentController.php b/app/Controller/Payment/PaymentController.php index 3567965..0cc1912 100644 --- a/app/Controller/Payment/PaymentController.php +++ b/app/Controller/Payment/PaymentController.php @@ -178,4 +178,25 @@ class PaymentController extends AbstractController $data = $this->paymentService->withdrawApplyQuery($data, $app); return $this->success($data); } + + public function unbindWithdrawEntrust(RequestInterface $request) + { + [$app, $data, $token] = $this->parseReqest($request, RegisterRequest::class); + $url = $this->userService->unbindWithdrawEntrust($data, $app, $token); + return $this->success(['url' => $url]); + } + + public function signWithdrawEntrust(RequestInterface $request) + { + [$app, $data, $token] = $this->parseReqest($request, RegisterRequest::class); + $url = $this->userService->signWithdrawEntrust($data, $app, $token); + return $this->success(['url' => $url]); + } + + public function querySignEntrust(RequestInterface $request) + { + [$app, $data, $token] = $this->parseReqest($request, RegisterRequest::class); + $result = $this->userService->querySignEntrust($data, $app); + return $this->success(['result' => $result]); + } } diff --git a/app/Helper/Baofu/ApiList.php b/app/Helper/Baofu/ApiList.php index 70950ca..2227ce5 100644 --- a/app/Helper/Baofu/ApiList.php +++ b/app/Helper/Baofu/ApiList.php @@ -154,6 +154,16 @@ class ApiList 'description' => '企业注册-聚合交易商户报备-v3.1版本-授权目录报备', 'url' => '/api/aggregationReport/v3.1.0/authBind', 'signParams' => 'orgNo|merchantNo|terminalNo|simId|authType|authContent' + ], + 'entrust-withdraw' => [ + 'description' => '委托提现交易', + 'url' => '/api/order/v3.0.0/entrustWithdraw', + 'signParams' => 'orgNo|merchantNo|terminalNo|loginNo|requestDate|outOrderNo|amount|agreementNo' + ], + 'find-sign-entrust-result' => [ + 'description' => '委托授权查询', + 'url' => '/api/cust/v3.0.0/findSignEntrustResult', + 'signParams' => 'orgNo|merchantNo|terminalNo|loginNo|requestDate' ] ]; diff --git a/app/Helper/Baofu/Baofu.php b/app/Helper/Baofu/Baofu.php index 39f25a5..01fe6ca 100644 --- a/app/Helper/Baofu/Baofu.php +++ b/app/Helper/Baofu/Baofu.php @@ -547,4 +547,37 @@ class Baofu throw new BusinessException($msg); } } + + public function signWithdrawEntrust($loginNo, $token) + { + $data = []; + $data['loginNo'] = $loginNo; + return $this->h5('sign-withdraw-entrust', $data, $token); + } + + public function unbindWithdrawEntrust($loginNo, $token) + { + $data = []; + $data['loginNo'] = $loginNo; + return $this->h5('unbind-withdraw-entrust', $data, $token); + } + + public function entrustWithdraw($params, $token) + { + $data = []; + $data['amount'] = $params['amount']; + $data['loginNo'] = $params['loginNo']; + $data['agreementNo'] = Rsa::encryptByCERFile($params['agreementNo'], $this->getCerFilePath()); + $data['outOrderNo'] = $params['outOrderNo']; + $data['notifyUrl'] = NotifyList::getNotifyUrl('withdraw', $token); + return $this->withReturnUrl($this->api('entrust-withdraw', $data), $token); + } + + public function findSignEntrustResult($loginNo, $agreementType = 'W_ENTRUST') + { + $data = []; + $data['loginNo'] = $loginNo; + $data['agreementType'] = $agreementType; + return $this->api('find-sign-entrust-result', $data); + } } diff --git a/app/Helper/Baofu/H5List.php b/app/Helper/Baofu/H5List.php index b0dbe2b..d729766 100644 --- a/app/Helper/Baofu/H5List.php +++ b/app/Helper/Baofu/H5List.php @@ -58,6 +58,18 @@ class H5List 'signParams' => 'orgNo|merchantNo|terminalNo|callType|loginNo|requestDate|null', 'callType' => 'BM_PWDMODIFY' ], + 'sign-withdraw-entrust' => [ + 'description' => '委托提现授权', + 'url' => '/api/wallet/v3.0.0/login', + 'signParams' => 'orgNo|merchantNo|terminalNo|callType|loginNo|requestDate|dataContent', + 'callType' => 'SIGN_WITHDRAW_ENTRUST', + ], + 'unbind-withdraw-entrust' => [ + 'description' => '委托提现解权', + 'url' => '/api/wallet/v3.0.0/login', + 'signParams' => 'orgNo|merchantNo|terminalNo|callType|loginNo|requestDate|dataContent', + 'callType' => 'UNBIND_WITHDRAW_ENTRUST', + ], ]; public static function get($h5Name) diff --git a/app/Service/PaymentService.php b/app/Service/PaymentService.php index 2a292f6..aaef169 100644 --- a/app/Service/PaymentService.php +++ b/app/Service/PaymentService.php @@ -613,6 +613,7 @@ class PaymentService extends AbstractService } public function withdraw(array $data, App $app, string $token) { + $withdrawType = $data['withdrawType'] ?? 'normal'; $user = User::where('app_id', $app->app_id)->where('user_id', $data['userId'])->first(); if (empty($user)) { throw new BusinessException('用户不存在'); @@ -624,17 +625,49 @@ class PaymentService extends AbstractService $withdraw->agreement_no = $data['agreementNo']; $withdraw->withdraw_no = StringHelper::generateOrderNo(StringHelper::ORDER_NO_TYPE_WITHDRAW_NO); $withdraw->out_withdraw_no = $data['outWithdrawNo']; + $withdraw->withdraw_type = $withdrawType; $withdraw->amount = $data['amount']; $withdraw->status = 'PREPARE'; $withdraw->applied_at = date('Y-m-d H:i:s'); $withdraw->notify_url = $data['notifyUrl']; $withdraw->save(); + if ($withdrawType == 'entrust') { + return $this->doEntrustWithdraw($data, $withdraw); + } else { + return $this->doWithdraw($data, $withdraw); + } + } + + private function doWithdraw(array $data, Withdraw $withdraw) { try { $baofu = new Baofu(); $result = $baofu->withdraw([ 'amount' => intval($data['amount']), - 'loginNo' => $user->member_id, + 'loginNo' => $withdraw->member_id, + 'agreementNo' => $data['agreementNo'], + 'outOrderNo' => $withdraw->withdraw_no, + ], $token); + + $withdraw->status = 'APPLY_SUCCESS'; + $withdraw->withdraw_url = $result; + $withdraw->save(); + return $result; + } catch (ApiException $e) { + $withdraw->status = 'APPLY_FAILED'; + $withdraw->error_code = $e->getCode(); + $withdraw->error_message = $e->getMessage(); + $withdraw->save(); + throw $e; + } + } + + private function doEntrustWithdraw(array $data, Withdraw $withdraw) { + try { + $baofu = new Baofu(); + $result = $baofu->entrustWithdraw([ + 'amount' => intval($data['amount']), + 'loginNo' => $withdraw->member_id, 'agreementNo' => $data['agreementNo'], 'outOrderNo' => $withdraw->withdraw_no, ], $token); diff --git a/app/Service/UserService.php b/app/Service/UserService.php index c8c3851..913c0ac 100644 --- a/app/Service/UserService.php +++ b/app/Service/UserService.php @@ -234,4 +234,40 @@ class UserService extends AbstractService $baofu = new Baofu(); return $baofu->getBalance($memberId); } + + public function signWithdrawEntrust(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('用户不存在'); + } + + $baofu = new Baofu(); + $url = $baofu->signWithdrawEntrust($user->member_id, $token); + return $url; + } + + public function unbindWithdrawEntrust(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('用户不存在'); + } + + $baofu = new Baofu(); + $url = $baofu->unbindWithdrawEntrust($user->member_id, $token); + return $url; + } + + public function querySignEntrust(array $data, App $app) + { + $user = User::where('app_id', $app->app_id)->where('user_id', $data['userId'])->first(); + if (empty($user)) { + throw new BusinessException('用户不存在'); + } + + $baofu = new Baofu(); + $result = $baofu->findSignEntrustResult($user->member_id); + return $result; + } } \ No newline at end of file diff --git a/config/routes.php b/config/routes.php index eab8f42..af963db 100644 --- a/config/routes.php +++ b/config/routes.php @@ -30,6 +30,9 @@ Router::addGroup('/payment',function () { Router::post('/withdraw-apply', [PaymentController::class, 'withdrawApply']); Router::post('/withdraw-apply-query', [PaymentController::class, 'withdrawApplyQuery']); Router::post('/withdraw', [PaymentController::class, 'withdraw']); + Router::post('/unbind-withdraw-entrust', [PaymentController::class, 'unbindWithdrawEntrust']); + Router::post('/sign-withdraw-entrust', [PaymentController::class, 'signWithdrawEntrust']); + Router::post('/query-sign-entrust', [PaymentController::class, 'querySignEntrust']); }, ['middleware' => [\App\Middleware\RequestLogMiddleware::class, \App\Middleware\AppAuthMiddleWare::class]]); Router::addGroup('/notify',function () {