From d69dcdb6acdac4f764187c99f86c8c3543b88e38 Mon Sep 17 00:00:00 2001 From: ljl Date: Wed, 30 Aug 2023 21:11:06 +0800 Subject: [PATCH] yh --- app/Controller/Payment/NotifyController.php | 6 +++ app/Controller/Payment/PaymentController.php | 24 +++++++++ app/Helper/Baofu/Baofu.php | 2 +- app/Helper/StringHelper.php | 3 ++ app/Model/Withdraw.php | 15 ++++++ app/Model/WithdrawApply.php | 15 ++++++ app/Service/PaymentService.php | 52 ++++++++++++++++++++ config/routes.php | 3 ++ 8 files changed, 119 insertions(+), 1 deletion(-) create mode 100644 app/Model/Withdraw.php create mode 100644 app/Model/WithdrawApply.php diff --git a/app/Controller/Payment/NotifyController.php b/app/Controller/Payment/NotifyController.php index 74ef4bd..79b34ce 100644 --- a/app/Controller/Payment/NotifyController.php +++ b/app/Controller/Payment/NotifyController.php @@ -244,4 +244,10 @@ class NotifyController extends AbstractController public function testNotify(RequestInterface $request) { return $this->success(['params' => $request->all()]); } + + public function transferWithdraw(RequestInterface $request) + { + $params = $request->all(); + Log::info('NOTIFY_DATA: ' . $request->getUri() . ':', $params); + } } diff --git a/app/Controller/Payment/PaymentController.php b/app/Controller/Payment/PaymentController.php index 240723a..63b4f2c 100644 --- a/app/Controller/Payment/PaymentController.php +++ b/app/Controller/Payment/PaymentController.php @@ -157,4 +157,28 @@ class PaymentController extends AbstractController ]; return $this->success($result); } + + public function withdraw(RequestInterface $request) + { + [$app, $data, $token] = $this->parseReqest($request, UnbindCardRequest::class); + $order = $this->paymentService->queryOrder($data, $app); + $result = [ + 'finishTime' => $order->finished_at, + 'amount' => $order->amount, + 'status' => $order->status, + ]; + return $this->success($result); + } + + public function withdrawApply(RequestInterface $request) + { + [$app, $data, $token] = $this->parseReqest($request, UnbindCardRequest::class); + $order = $this->paymentService->queryOrder($data, $app); + $result = [ + 'finishTime' => $order->finished_at, + 'amount' => $order->amount, + 'status' => $order->status, + ]; + return $this->success($result); + } } diff --git a/app/Helper/Baofu/Baofu.php b/app/Helper/Baofu/Baofu.php index 2816ab9..01069aa 100644 --- a/app/Helper/Baofu/Baofu.php +++ b/app/Helper/Baofu/Baofu.php @@ -527,6 +527,6 @@ class Baofu echo $result; echo PHP_EOL; $result = base64_decode($result); - return json_encode($result, true); + return json_decode($result, true); } } diff --git a/app/Helper/StringHelper.php b/app/Helper/StringHelper.php index b881ac0..86a48d6 100644 --- a/app/Helper/StringHelper.php +++ b/app/Helper/StringHelper.php @@ -13,6 +13,9 @@ class StringHelper 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'; + const ORDER_NO_TYPE_WITHDRAW_APPLY_BATCH_NUM = 'withdraw_apply_batch_num'; + const ORDER_NO_TYPE_WITHDRAW_APPLY_NO = 'withdraw_apply_no'; + const ORDER_NO_TYPE_WITHDRAW_NO = 'withdraw_no'; public static function getRandomString($length, $withSpecialChar = false) { diff --git a/app/Model/Withdraw.php b/app/Model/Withdraw.php new file mode 100644 index 0000000..e1184dc --- /dev/null +++ b/app/Model/Withdraw.php @@ -0,0 +1,15 @@ +belongsTo(App::class, 'app_id', 'app_id'); + } +} \ No newline at end of file diff --git a/app/Model/WithdrawApply.php b/app/Model/WithdrawApply.php new file mode 100644 index 0000000..50525f9 --- /dev/null +++ b/app/Model/WithdrawApply.php @@ -0,0 +1,15 @@ +belongsTo(App::class, 'app_id', 'app_id'); + } +} \ No newline at end of file diff --git a/app/Service/PaymentService.php b/app/Service/PaymentService.php index 024d6a3..659e867 100644 --- a/app/Service/PaymentService.php +++ b/app/Service/PaymentService.php @@ -15,6 +15,7 @@ use App\Model\OrderSplitInfo; use App\Model\Refund; use App\Model\RefundSplitInfo; use App\Model\User; +use App\Model\WithdrawApply; class PaymentService extends AbstractService { @@ -505,4 +506,55 @@ class PaymentService extends AbstractService return $this->updateOrder($info); } + + public function withdrawApply(array $data, App $app) { + $user = User::where('app_id', $app->app_id)->where('user_id', $data['userId'])->first(); + if (empty($user)) { + throw new BusinessException('用户不存在'); + } + $apply = new WithdrawApply(); + $apply->app_id = $app->app_id; + $apply->user_id = $user->user_id; + $apply->member_id = $user->member_id; + $apply->account_name = $data['accountName']; + $apply->batch_num = StringHelper::generateOrderNo(StringHelper::ORDER_NO_TYPE_WITHDRAW_APPLY_BATCH_NUM); + $apply->apply_no = StringHelper::generateOrderNo(StringHelper::ORDER_NO_TYPE_WITHDRAW_APPLY_NO); + $apply->out_apply_no = $params['outApplyNo']; + $apply->amount = $params['amount']; + $apply->status = 'PREPARE'; + $apply->summary = $data['summary'] ?? '转账'; + $apply->save(); + + $baofu = new Baofu(); + $data = [ + 'transContent' => [ + [ + 'transNo' => $apply->apply_no, + 'transMoney' => round($apply->amount / 100, 2), + 'transType' => 2, + 'transAccNo' => $user->contract_no, + 'transAccName' => $apply->account_name, + 'transSummary' => $apply->summary, + ] + ] + ]; + $result = $baofu->transferWithdraw($data); + if ($result['header']['sysRespCode'] == 'S_0000' && $result['body']['transHeader']['returnCode'] == '0000') { + $apply->status = 'APPLY_SUCCESS'; + } else { + $apply->status = 'APPLY_FAILED'; + } + $apply->save(); + } + + public function withdraw(array $data, App $app, string $token) { + + $baofu = new Baofu(); + return $baofu->withdraw([ + 'amount' => $data['amount'], + 'loginNo' => $data['amount'], + 'agreementNo' => $data['agreementNo'], + 'outOrderNo' => $data['outOrderNo'], + ], $token); + } } diff --git a/config/routes.php b/config/routes.php index 4b8c73f..d92f7a9 100644 --- a/config/routes.php +++ b/config/routes.php @@ -27,6 +27,8 @@ Router::addGroup('/payment',function () { Router::post('/refund-apply', [PaymentController::class, 'refundApply']); Router::post('/refund-confirm', [PaymentController::class, 'refundConfirm']); Router::post('/refund-cancel', [PaymentController::class, 'refundCancel']); + Router::post('/withdraw-apply', [PaymentController::class, 'withdrawApply']); + Router::post('/withdraw', [PaymentController::class, 'withdraw']); }, ['middleware' => [\App\Middleware\RequestLogMiddleware::class, \App\Middleware\AppAuthMiddleWare::class]]); Router::addGroup('/notify',function () { @@ -34,6 +36,7 @@ Router::addGroup('/notify',function () { Router::addRoute(['GET', 'POST'], '/bind-card/{token}', [NotifyController::class, 'bindCard']); Router::addRoute(['GET', 'POST'], '/payment/{token}', [NotifyController::class, 'payment']); Router::addRoute(['GET', 'POST'], '/refund/{token}', [NotifyController::class, 'refund']); + Router::addRoute(['GET', 'POST'], '/transfer-withdraw', [NotifyController::class, 'transferWithdraw']); Router::addRoute(['POST'], '/test-notify', [NotifyController::class, 'testNotify']); Router::addRoute(['GET', 'POST'], '/confirm-assure-portfolio-pay/{token}', [NotifyController::class, 'confirmAssurePortfolioPay']); });