From 4022901c65d3131cc28effeda6d7abe9de7d71ce Mon Sep 17 00:00:00 2001 From: elf <360197197@qq.com> Date: Thu, 17 Aug 2023 00:45:37 +0800 Subject: [PATCH] yh --- app/Controller/Payment/PaymentController.php | 2 +- app/Helper/Baofu/Baofu.php | 10 ++--- app/Service/PaymentService.php | 46 +++++++++++++++++++- payment.sql | 11 ++++- 4 files changed, 60 insertions(+), 9 deletions(-) diff --git a/app/Controller/Payment/PaymentController.php b/app/Controller/Payment/PaymentController.php index 06de001..66747d6 100644 --- a/app/Controller/Payment/PaymentController.php +++ b/app/Controller/Payment/PaymentController.php @@ -127,7 +127,7 @@ class PaymentController extends AbstractController if (empty($user)) { throw new BusinessException('用户不存在'); } - $user = $this->userService->rsyncUser($user->member_id); + $user = $this->userService->rsyncUser($user->member_id, $app->app_id, $data['userId']); $result = [ 'realnameFlag' => $user->realname_flag, 'bindCardFlag' => $user->bind_bard_flag, diff --git a/app/Helper/Baofu/Baofu.php b/app/Helper/Baofu/Baofu.php index ed407d4..ba19d8c 100644 --- a/app/Helper/Baofu/Baofu.php +++ b/app/Helper/Baofu/Baofu.php @@ -181,14 +181,14 @@ class Baofu return $this->api('cloud-b2c-assure-recharge', $data); } - public function payment($params, $type = 'ASSURE_PAYMENT') + public function payment($params, $type, $token) { $dataContent = [ 'goodsName' => $params['goodsName'], 'amount' => $params['amount'], 'outOrderNo' => $params['outOrderNo'], - 'expireDate' => date('YmdHis', time() + 15*60), - 'notifyUrl' => $params['notifyUrl'], + 'expireDate' => $params['expireDate'], + 'notifyUrl' => NotifyList::getNotifyUrl('payment', $token), 'splitInfoList' => $params['splitInfoList'], 'paidType' => $params['paidType'], 'validDate' => date('Ymd'), @@ -199,14 +199,14 @@ class Baofu // 1.微信支付(公众号、小程序)需填公众号授权获取微信用户openid // 2.支付宝支付(生活号、小程序)需填生活号授权获取支付宝用户userid // 其余时间不传 - $data['chanalId'] = $params['chanalId'] ?: ''; + $data['chanalId'] = $params['chanalId'] ?? ''; $data['dataContent'] = json_encode($dataContent); // 1.微信支付(公众号、小程序)需填公众号授权获取微信的appid // 2.支付宝支付(生活号、小程序)需填生活号授权获取支付宝的appid // 支付宝主扫 不需要 $data['appId'] = $params['appId'] ?: ''; $data['isRaw'] = 0; - $data['callType'] = $type; + $data['callType'] = $params['callType']; $res = base64_decode($this->api('payment', $data)); if(self::PEYMENT_PAID_TYPE[$params['paidType']]){ diff --git a/app/Service/PaymentService.php b/app/Service/PaymentService.php index 0314c91..b6c8c5d 100644 --- a/app/Service/PaymentService.php +++ b/app/Service/PaymentService.php @@ -36,6 +36,7 @@ class PaymentService extends AbstractService throw new BusinessException('订单号重复'); } + $data['payType'] = $data['payType'] ?? 'CARD'; [$order, $orderSplitInfos] = $this->createOrder($app, $data, $user, 'paymentSplit'); $splitInfoList = $this->buildSplitInfoList($orderSplitInfos); @@ -83,7 +84,7 @@ class PaymentService extends AbstractService 'loginNo' => $user->member_id, 'outOrderNo' => $order->order_no, 'amount' => $order->amount, - 'paidType' => 'CARD', + 'paidType' => $order->pay_type, 'agreementNo' => $order->agreement_no, 'pwdPayExpTime' => $order->expires_in, 'splitInfoList' => $splitInfoList, @@ -133,6 +134,43 @@ class PaymentService extends AbstractService } } + private function unionPay(Order $order, User $user, array $splitInfoList, string $token) + { + // ASSURE_SHARE + // ASSURE_PAYMENT + // ASSURE_PORTFOLIO_PAY + // PAYMENT_SPLIT + try { + $baofu = new Baofu(); + $result = $baofu->payment([ + 'loginNo' => $user->member_id, + 'outOrderNo' => $order->order_no, + 'goodsName' => $order->goods_name, + 'amount' => $order->amount, + 'paidType' => $order->pay_type, + 'agreementNo' => $order->agreement_no, + 'expireDate' => date('YmdHis', time() + $order->expires_in), + 'validDate' => date('Ymd', strtotime($order->valid_date)), + 'splitInfoList' => $splitInfoList, + 'chanalId' => $order->channel_id, + 'appId' => $order->channel_app_id, + 'callType' => 'PAYMENT_SPLIT', + ], $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) { if ($params['amount'] < 10) { throw new BusinessException('金额不能小于10'); @@ -150,14 +188,18 @@ class PaymentService extends AbstractService $order->return_url = $params['returnUrl'] ?? ''; $order->agreement_no = $params['agreementNo'] ?? ''; $order->status = 'PREPARE'; + $order->pay_mode = 'BAOFU'; + $order->channel_id = $params['channelId'] ?? ''; + $order->channel_app_id = $params['appId'] ?? ''; $order->pay_channel = 'BAOFU'; $order->pay_method = $payMethod; - $order->pay_type = 'CARD'; + $order->pay_type = $params['payType'] ?? ''; $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']; + $order->remark = $params['remark'] ?? ''; $order->save(); $platformAccount = User::getPlatformAccount(); diff --git a/payment.sql b/payment.sql index 49ddd66..9d86a5a 100644 --- a/payment.sql +++ b/payment.sql @@ -224,4 +224,13 @@ 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 +add column `goods_name` varchar(125) NOT NULL DEFAULT '' after amount; + + +alter table orders +add column `pay_mode` varchar(20) NOT NULL DEFAULT '' after market_info, +add column `remark` varchar(255) NOT NULL DEFAULT '' after return_url; + +alter table orders +add column `channel_id` varchar(32) NOT NULL DEFAULT '' after market_info, +add column `channel_app_id` varchar(32) NOT NULL DEFAULT '' after market_info; \ No newline at end of file