pull/1/head
wanghousheng 1 year ago
parent 7e4e3817fc
commit 2dd563da7e
  1. 46
      app/api/controller/Identity.php
  2. 21
      app/api/model/user/Identity.php
  3. 66
      app/api/model/user/IdentityOrder.php
  4. 119
      app/api/service/Identity.php
  5. 16
      app/api/service/Server/PaySuccess.php
  6. 336
      app/api/service/identity/PaySuccess.php
  7. 321
      app/api/service/identity/Payment.php
  8. 22
      app/common/model/user/Identity.php
  9. 20
      app/common/model/user/IdentityOrder.php
  10. 19
      app/store/model/user/Identity.php

@ -0,0 +1,46 @@
<?php
declare (strict_types=1);
namespace app\api\controller;
use app\common\enum\user\IdentityEnum;
use cores\exception\BaseException;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\response\Json;
class Identity extends Controller
{
/**
* @notes:会员身份价格列表
* @return Json
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException|BaseException
* @author: wanghousheng
*/
public function userPriceList(): Json
{
$client = $this->request->post('client');
$model = new \app\api\service\Identity();
$list = $model->center($client, ['type' => IdentityEnum::MEMBER]);
return $this->renderSuccess(compact('list'));
}
/**
* @notes:分销身份价格列表
* @return Json
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException|BaseException
* @author: wanghousheng
*/
public function dealerPriceList(): Json
{
$client = $this->request->post('client');
$model = new \app\api\service\Identity();
$list = $model->center($client, ['type' => IdentityEnum::MEMBER]);
return $this->renderSuccess(compact('list'));
}
}

@ -0,0 +1,21 @@
<?php
declare (strict_types=1);
namespace app\api\model\user;
use app\common\model\user\Identity as BaseIdentity;
class Identity extends BaseIdentity
{
/**
* 隐藏字段
* @var array
*/
protected $hidden = [
'type',
'create_time',
'update_time',
'store_id',
];
}

@ -0,0 +1,66 @@
<?php
namespace app\api\model\user;
use app\api\service\User as UserService;
use app\common\model\user\IdentityOrder as BaseIdentityOrder;
use app\common\service\Order as OrderService;
use cores\exception\BaseException;
use function getPlatform;
class IdentityOrder extends BaseIdentityOrder
{
/**
* 隐藏字段
* @var array
*/
protected $hidden = [
'order_type',
'create_time',
'update_time',
'store_id',
];
/**
* @notes:创建订单
* @param array $identityInfo
* @return bool
* @throws BaseException
* @author: wanghousheng
*/
public function createOrder(array $identityInfo): bool
{
$data = [
'user_id' => UserService::getCurrentLoginUserId(),
'order_no' => OrderService::createOrderNo(),
'identity_id' => $identityInfo['identity_id'],
'order_type' => $identityInfo['type'],
'pay_price' => $identityInfo['price'],
'month' => $identityInfo['month'],
'platform' => getPlatform(),
'store_id' => self::$storeId,
];
return $this->save($data);
}
/**
* 获取订单详情 (待付款状态)
* @param string $orderNo 订单号
* @return array|null|static
*/
public static function getPayDetail(string $orderNo)
{
return self::detail(['order_no' => $orderNo]);
}
/**
* @notes:编辑
* @param $data
* @return bool
* @author: wanghousheng
*/
public function edit($data): bool
{
return $this->save($data) !== false;
}
}

@ -0,0 +1,119 @@
<?php
namespace app\api\service;
use app\api\model\Payment as PaymentModel;
use app\api\service\identity\Payment;
use app\api\service\User as UserService;
use app\common\service\BaseService;
use cores\exception\BaseException;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
class Identity extends BaseService
{
// 提示信息
private string $message = '';
// 支付方式 (微信支付、支付宝、余额)
private string $method;
// 下单的客户端
private string $client;
/**
* 设置当前支付方式
* @param string $method 支付方式
* @return $this
*/
public function setMethod(string $method): Identity
{
$this->method = $method;
return $this;
}
/**
* 设置下单的客户端
* @param string $client 客户端
* @return $this
*/
public function setClient(string $client): Identity
{
$this->client = $client;
return $this;
}
/**
* 开通会员/分销页面数据
* @param string $client 当前客户端
* @param array $where
* @return array
* @throws BaseException
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public function center(string $client, array $where): array
{
// 当期用户信息
$userInfo = UserService::getCurrentLoginUser(true);
// 获取充值方案列表
$model = new \app\api\model\user\Identity();
$planList = $model->getList($where);
// 根据指定客户端获取可用的支付方式
$PaymentModel = new PaymentModel;
$methods = $PaymentModel->getMethodsByClient($client);
// 返回数据
return [
'personal' => $userInfo,
'list' => $planList,
'paymentMethods' => $methods
];
}
/**
* 确认订单支付事件
* @param int $identityId
* @param array $extra 附加数据
* @return array[]
* @throws BaseException
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public function orderPay(int $identityId, array $extra = []): array
{
$PaymentService = new Payment();
$result = $PaymentService->setMethod($this->method)
->setClient($this->client)
->orderPay($identityId, $extra);
$this->message = $PaymentService->getMessage();
return $result;
}
/**
* 交易查询
* 查询第三方支付订单是否付款成功
* @param string $outTradeNo 商户订单号
* @return bool
* @throws BaseException
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public function tradeQuery(string $outTradeNo): bool
{
$PaymentService = new PaymentService;
return $PaymentService->setMethod($this->method)->setClient($this->client)->tradeQuery($outTradeNo);
}
/**
* 返回消息提示
* @return string
*/
public function getMessage(): string
{
return $this->message;
}
}

@ -2,20 +2,17 @@
namespace app\api\service\Server;
use app\api\model\Order as OrderModel;
use app\api\model\PaymentTrade as PaymentTradeModel;
use app\api\model\Server\ServerOrder;
use app\api\model\User as UserModel;
use app\api\model\user\BalanceLog as BalanceLogModel;
use app\common\enum\order\PayStatus as PayStatusEnum;
use app\common\enum\OrderType as OrderTypeEnum;
use app\common\enum\payment\Method as PaymentMethodEnum;
use app\common\enum\user\balanceLog\Scene as SceneEnum;
use app\common\library\Lock;
use app\common\library\Log;
use app\common\service\BaseService;
use cores\exception\BaseException;
use think\facade\Event;
class PaySuccess extends BaseService
{
@ -109,11 +106,6 @@ class PaySuccess extends BaseService
if ($this->checkOrderStatusOnPay()) {
// 更新订单状态为已付款
$this->updatePayStatus();
// 订单支付成功事件 (处理订单来源相关业务)
Event::trigger('OrderPaySuccess', [
'order' => $this->getOrderInfo(),
'orderType' => OrderTypeEnum::SERVER
]);
}
// 当前订单解除并发锁
$this->unLock();
@ -145,10 +137,10 @@ class PaySuccess extends BaseService
/**
* 订单模型
* @return OrderModel|null
* @return ServerOrder|null
* @throws BaseException
*/
private function orderModel(): ?OrderModel
private function orderModel(): ?ServerOrder
{
return $this->getOrderInfo();
}
@ -288,10 +280,10 @@ class PaySuccess extends BaseService
/**
* 获取当前订单的详情信息
* @return OrderModel|null
* @return ServerOrder|null
* @throws BaseException
*/
private function getOrderInfo(): ?OrderModel
private function getOrderInfo(): ?ServerOrder
{
// 获取订单详情 (待支付状态)
if (empty($this->orderInfo)) {

@ -0,0 +1,336 @@
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\api\service\identity;
use app\api\model\PaymentTrade as PaymentTradeModel;
use app\api\model\recharge\Order as OrderModel;
use app\api\model\Server\ServerOrder;
use app\api\model\User as UserModel;
use app\api\model\user\BalanceLog as BalanceLogModel;
use app\api\model\user\IdentityOrder;
use app\common\enum\order\PayStatus;
use app\common\enum\payment\Method as PaymentMethodEnum;
use app\common\enum\recharge\order\PayStatus as PayStatusEnum;
use app\common\enum\user\balanceLog\Scene as SceneEnum;
use app\common\library\Lock;
use app\common\library\Log;
use app\common\service\BaseService;
use cores\exception\BaseException;
/**
* 余额充值订单支付成功服务类
* Class PaySuccess
* @package app\api\service\order
*/
class PaySuccess extends BaseService
{
// 当前订单信息
public ServerOrder $orderInfo;
// 当前用户信息
private UserModel $userInfo;
// 当前订单号
private string $orderNo;
// 当前订单ID
private string $orderId;
// 订单支付方式
private string $method;
// 第三方交易记录ID
private ?int $tradeId = null;
// 第三方支付成功返回的数据
private array $paymentData = [];
/**
* 设置支付的订单ID
* @param int $orderId 订单ID
*/
public function setOrderId(int $orderId): \app\api\service\Server\PaySuccess
{
$this->orderId = $orderId;
return $this;
}
/**
* 设置当前的订单号
* @param string $orderNo
* @return $this
*/
public function setOrderNo(string $orderNo): PaySuccess
{
$this->orderNo = $orderNo;
return $this;
}
/**
* 设置订单支付方式
* @param string $method
* @return $this
*/
public function setMethod(string $method): PaySuccess
{
$this->method = $method;
return $this;
}
/**
* 第三方支付交易记录ID
* @param int|null $tradeId
* @return $this
*/
public function setTradeId(?int $tradeId = null): PaySuccess
{
$this->tradeId = $tradeId;
return $this;
}
/**
* 第三方支付成功返回的数据
* @param array $paymentData
* @return $this
*/
public function setPaymentData(array $paymentData): PaySuccess
{
$this->paymentData = $paymentData;
return $this;
}
/**
* 订单支付成功业务处理
* @return bool
* @throws BaseException
*/
public function handle(): bool
{
// 验证当前参数是否合法
$this->verifyParameters();
// 当前订单开启并发锁
$this->lockUp();
// 验证当前订单是否允许支付
if ($this->checkOrderStatusOnPay()) {
// 更新订单状态为已付款
$this->updatePayStatus();
}
// 当前订单解除并发锁
$this->unLock();
return true;
}
/**
* 验证当前参数是否合法
* @throws BaseException
*/
private function verifyParameters()
{
if (empty($this->orderNo)) {
throwError('orderNo not found');
}
if (empty($this->method)) {
throwError('method not found');
}
if ($this->tradeId) {
empty($this->paymentData) && throwError('PaymentData not found');
!isset($this->paymentData['tradeNo']) && throwError('PaymentData not found');
}
// 记录日志
Log::append('PaySuccess', [
'orderNo' => $this->orderNo, 'method' => $this->method,
'tradeId' => $this->tradeId, 'paymentData' => $this->paymentData
]);
}
/**
* 订单模型
* @return IdentityOrder|null
* @throws BaseException
*/
private function orderModel(): ?IdentityOrder
{
return $this->getOrderInfo();
}
/**
* 订单已付款事件
* @return void
* @throws BaseException
*/
private function updatePayStatus(): void
{
// 记录日志
Log::append('PaySuccess --updatePayStatus', ['title' => '订单已付款事件']);
// 当前订单信息
$orderInfo = $this->getOrderInfo();
// 事务处理
$this->orderModel()->transaction(function () use ($orderInfo) {
// 更新订单状态
$this->updateOrderStatus();
// 累积用户总消费金额
UserModel::setIncPayMoney($orderInfo['user_id'], (float)$orderInfo['pay_price']);
// 记录订单支付信息
$this->updatePayInfo();
});
}
/**
* 记录订单支付的信息
* @throws BaseException
*/
private function updatePayInfo()
{
// 当前订单信息
$orderInfo = $this->getOrderInfo();
// 余额支付
if ($this->method == PaymentMethodEnum::BALANCE) {
// 更新用户余额
UserModel::setDecBalance((int)$orderInfo['user_id'], (float)$orderInfo['pay_price']);
// 新增余额变动记录
BalanceLogModel::add(SceneEnum::CONSUME, [
'user_id' => (int)$orderInfo['user_id'],
'money' => -$orderInfo['pay_price'],
], ['order_no' => $orderInfo['order_no']]);
}
// 将第三方交易记录更新为已支付状态
if (in_array($this->method, [PaymentMethodEnum::WECHAT, PaymentMethodEnum::ALIPAY])) {
$this->updateTradeRecord();
}
}
/**
* 将第三方交易记录更新为已支付状态
*/
private function updateTradeRecord()
{
if ($this->tradeId && !empty($this->paymentData)) {
PaymentTradeModel::updateToPaySuccess($this->tradeId, $this->paymentData['tradeNo']);
}
}
/**
* 更新订单状态
* @throws BaseException
*/
private function updateOrderStatus(): void
{
// 更新订单状态
$this->orderModel()->save([
'pay_method' => $this->method,
'pay_status' => PayStatus::SUCCESS,
'pay_time' => time(),
'trade_id' => $this->tradeId ?: 0,
]);
}
/**
* 获取买家用户信息
* @return UserModel|array|null
* @throws BaseException
*/
private function getUserInfo()
{
if (empty($this->userInfo)) {
$this->userInfo = UserModel::detail($this->getOrderInfo()['user_id']);
}
if (empty($this->userInfo)) {
throwError('未找到买家用户信息');
}
return $this->userInfo;
}
/**
* 验证当前订单是否允许支付
* @return bool
* @throws BaseException
*/
private function checkOrderStatusOnPay(): bool
{
// 当前订单信息
$orderInfo = $this->getOrderInfo();
// 验证余额支付时用户余额是否满足
if ($this->method == PaymentMethodEnum::BALANCE) {
if ($this->getUserInfo()['balance'] < $orderInfo['pay_price']) {
throwError('账户余额不足,无法使用余额支付');
}
}
// 检查订单状态是否为已支付
if ($orderInfo['pay_status'] == PayStatusEnum::SUCCESS) {
$this->onOrderPaid();
return false;
}
return true;
}
/**
* 处理订单已支付的情况
* @throws BaseException
*/
private function onOrderPaid()
{
// 记录日志
Log::append('PaySuccess --onOrderPaid', ['title' => '处理订单已支付的情况']);
// 当前订单信息
$orderInfo = $this->getOrderInfo();
// 余额支付直接返回错误信息
if ($this->method == PaymentMethodEnum::BALANCE) {
throwError('当前订单已支付,无需重复支付');
}
// 第三方支付判断是否为重复下单 (因异步回调可能存在网络延迟的原因,在并发的情况下会出现同时付款两次,这里需要容错)
// 如果订单记录中已存在tradeId并且和当前支付的tradeId不一致, 那么判断为重复的订单, 需进行退款处理
if ($this->tradeId > 0 && $orderInfo['trade_id'] != $this->tradeId) {
// 执行原路退款
throwError('当前订单异常');
}
}
/**
* 获取当前订单的详情信息
* @return OrderModel|null
* @throws BaseException
*/
private function getOrderInfo(): ?IdentityOrder
{
// 获取订单详情 (待支付状态)
if (empty($this->orderInfo)) {
$this->orderInfo = IdentityOrder::getPayDetail($this->orderNo);
}
// 判断订单是否存在
if (empty($this->orderInfo)) {
throwError('未找到该订单信息');
}
return $this->orderInfo;
}
/**
* 订单锁:防止并发导致重复支付
* @throws BaseException
*/
private function lockUp()
{
$orderInfo = $this->getOrderInfo();
Lock::lockUp("OrderPaySuccess_{$orderInfo['order_id']}");
}
/**
* 订单锁:防止并发导致重复支付
* @throws BaseException
*/
private function unLock()
{
$orderInfo = $this->getOrderInfo();
Lock::unLock("OrderPaySuccess_{$orderInfo['order_id']}");
}
}

@ -0,0 +1,321 @@
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\api\service\identity;
use app\api\model\Payment as PaymentModel;
use app\api\model\PaymentTrade as PaymentTradeModel;
use app\api\model\user\Identity;
use app\api\model\user\IdentityOrder;
use app\api\service\identity\PaySuccess as IdentityPaySuccessService;
use app\api\service\Order as OrderService;
use app\api\service\User as UserService;
use app\common\enum\Client as ClientEnum;
use app\common\enum\OrderType as OrderTypeEnum;
use app\common\enum\payment\Method as PaymentMethodEnum;
use app\common\enum\user\IdentityEnum;
use app\common\library\payment\Facade as PaymentFacade;
use app\common\service\BaseService;
use cores\exception\BaseException;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
/**
* 开通会员/分销商订单付款服务类
* Class Payment
* @package app\api\controller
*/
class Payment extends BaseService
{
// 提示信息
private string $message = '';
// 订单信息
private IdentityOrder $orderInfo;
// 支付方式 (微信支付、支付宝,余额)
private string $method = '';
// 下单的客户端
private string $client = '';
/**
* 设置当前支付方式
* @param string $method 支付方式
* @return $this
*/
public function setMethod(string $method): Payment
{
$this->method = $method;
return $this;
}
/**
* 设置下单的客户端
* @param string $client 客户端
* @return $this
*/
public function setClient(string $client): Payment
{
$this->client = $client;
return $this;
}
/**
* 确认订单支付事件
* @param int $identityId
* @param array $extra 附加数据
* @return array[]
* @throws BaseException
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public function orderPay(int $identityId, array $extra = []): array
{
// 创建订单信息
$this->orderInfo = $this->createOrder($identityId);
// 订单支付事件
$this->orderPayEvent();
// 构建第三方支付请求的参数
$payment = $this->unifiedorder($extra);
// 记录第三方交易信息
$order_type = OrderTypeEnum::MEMBER;//开通会员
if ($this->orderInfo['order_type'] == IdentityEnum::DEALER) {
$order_type = OrderTypeEnum::DEALER;//开通分销商
}
$this->recordPaymentTrade($payment, $order_type);
// 返回结果
return compact('payment');
}
/**
* 订单支付事件
* @return void
* @throws BaseException
* @author: wanghousheng
*/
private function orderPayEvent(): void
{
// 余额支付
if ($this->method == PaymentMethodEnum::BALANCE) {
$this->orderPaySuccess($this->orderInfo['order_no']);
}
}
/**
* 订单支付成功事件
* @param string $orderNo 当前订单号
* @return void
* @throws BaseException
* @author: wanghousheng
*/
private function orderPaySuccess(string $orderNo): void
{
$paymentData = [];// 获取订单详情
$service = new IdentityPaySuccessService();
// 订单支付成功业务处理
$service->setOrderNo($orderNo)->setMethod($this->method)->setTradeId()->setPaymentData($paymentData);
if (!$service->handle()) {
throwError($service->getError() ?: '订单支付失败');
}
$this->message = '恭喜您,订单支付成功';
}
/**
* 创建订单
* @param int $identityId
* @return IdentityOrder
* @throws BaseException
*/
private function createOrder(int $identityId): IdentityOrder
{
$model = new IdentityOrder();
$info = Identity::detail(['identity_id' => $identityId]);
if ($info->isEmpty()) {
throwError('记录不存在');
}
if (!$model->createOrder($info->toArray())) {
throwError($model->getError() ?: '创建订单失败');
}
$model['order_id'] = (int)$model['order_id'];
return $model;
}
/**
* 查询订单是否支付成功 (仅限第三方支付订单)
* @param string $outTradeNo 商户订单号
* @return bool
* @throws BaseException
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public function tradeQuery(string $outTradeNo): bool
{
// 获取支付方式的配置信息
$options = $this->getPaymentConfig();
// 构建支付模块
$Payment = PaymentFacade::store($this->method)->setOptions($options, $this->client);
// 执行第三方支付查询API
$result = $Payment->tradeQuery($outTradeNo);
// 订单支付成功事件
if (!empty($result) && $result['paySuccess']) {
// 获取第三方交易记录信息
$tradeInfo = PaymentTradeModel::detailByOutTradeNo($outTradeNo);
// 订单支付成功事件
$this->orderPaySucces($tradeInfo['order_no'], $tradeInfo['trade_id'], $result);
}
// 返回订单状态
return $result ? $result['paySuccess'] : false;
}
/**
* 记录第三方交易信息
* @param array $payment 第三方支付数据
* @throws BaseException
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
private function recordPaymentTrade(array $payment, int $orderType): void
{
if ($this->method != PaymentMethodEnum::BALANCE) {
PaymentTradeModel::record(
$this->orderInfo,
$this->method,
$this->client,
$orderType,
$payment
);
}
}
/**
* 返回消息提示
* @return string
*/
public function getMessage(): string
{
return $this->message;
}
/**
* 构建第三方支付请求的参数
* @param array $extra 附加数据
* @return array
* @throws BaseException
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
private function unifiedorder(array $extra = []): array
{
// 判断支付方式是否合法
if (!in_array($this->method, [PaymentMethodEnum::WECHAT, PaymentMethodEnum::ALIPAY])) {
return [];
}
// 生成第三方交易订单号 (并非主订单号)
$outTradeNo = OrderService::createOrderNo();
// 获取支付方式的配置信息
$options = $this->getPaymentConfig();
// 整理下单接口所需的附加数据
$extra = $this->extraAsUnify($extra);
// 构建支付模块
$Payment = PaymentFacade::store($this->method)->setOptions($options, $this->client);
// 执行第三方支付下单API
if (!$Payment->unify($outTradeNo, (string)$this->orderInfo['pay_price'], $extra)) {
throwError('第三方支付下单API调用失败');
}
// 返回客户端需要的支付参数
return $Payment->getUnifyResult();
}
/**
* 获取支付方式的配置信息
* @return mixed
* @throws BaseException
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
private function getPaymentConfig()
{
$PaymentModel = new PaymentModel;
$templateInfo = $PaymentModel->getPaymentInfo($this->method, $this->client, $this->getStoreId());
return $templateInfo['template']['config'][$this->method];
}
/**
* 整理下单接口所需的附加数据
* @param array $extra
* @return array
* @throws BaseException
*/
private function extraAsUnify(array $extra = []): array
{
// 微信支付时需要的附加数据
if ($this->method === PaymentMethodEnum::WECHAT) {
// 微信小程序端和微信公众号端需要openid
if (in_array($this->client, [ClientEnum::WXOFFICIAL, ClientEnum::MP_WEIXIN])) {
$extra['openid'] = $this->getWechatOpenid();
}
}
// 支付宝支付时需要的附加数据
if ($this->method === PaymentMethodEnum::ALIPAY) {
// 支付宝小程序端需要buyerId
if ($this->client == ClientEnum::MP_ALIPAY) {
$extra['buyerId'] = $this->getAlipayBuyerId();
}
}
return $extra;
}
/**
* 获取微信端的用户openid(仅微信小程序和微信公众号)
* @return null
* @throws BaseException
*/
private function getWechatOpenid()
{
if (in_array($this->client, [ClientEnum::MP_WEIXIN, ClientEnum::WXOFFICIAL])) {
// 当前登录用户信息
$useInfo = UserService::getCurrentLoginUser(true);
if (!$useInfo['currentOauth'] || empty($useInfo['currentOauth']['oauth_id'])) {
throwError('很抱歉,您当前不存在openid 无法发起微信支付');
}
// 当前第三方用户标识
return $useInfo['currentOauth']['oauth_id'];
}
return null;
}
/**
* 获取支付宝端的用户buyerId(仅支付宝小程序端)
* @return null
* @throws BaseException
*/
private function getAlipayBuyerId()
{
if ($this->client == ClientEnum::MP_ALIPAY) {
// 当前登录用户信息
$useInfo = UserService::getCurrentLoginUser(true);
if (!$useInfo['currentOauth'] || empty($useInfo['currentOauth']['oauth_id'])) {
throwError('很抱歉,您当前不存在buyerId 无法发起支付宝支付');
}
// 当前第三方用户标识
return $useInfo['currentOauth']['oauth_id'];
}
return null;
}
}

@ -4,6 +4,10 @@ namespace app\common\model\user;
use app\common\enum\user\IdentityEnum;
use cores\BaseModel;
use think\Collection;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
class Identity extends BaseModel
{
@ -12,8 +16,7 @@ class Identity extends BaseModel
// 定义主键
protected $pk = 'identity_id';
protected $updateTime = false;
/**
* 追加字段
@ -39,6 +42,20 @@ class Identity extends BaseModel
return '未知';
}
/**
* @notes:获取全部记录
* @param array $where
* @return \app\store\model\user\Identity[]|array|Collection
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
* @author: wanghousheng
*/
public function getList(array $where)
{
return $this->where($where)->select();
}
/**
* @notes:详情
* @param $where
@ -51,4 +68,5 @@ class Identity extends BaseModel
return static::get($where, $with);
}
}

@ -0,0 +1,20 @@
<?php
namespace app\common\model\user;
use cores\BaseModel;
class IdentityOrder extends BaseModel
{
// 定义表名
protected $name = 'user_identity_order';
// 定义主键
protected $pk = 'order_id';
public static function detail($where)
{
return self::detail($where);
}
}

@ -1,29 +1,12 @@
<?php
declare (strict_types=1);
namespace app\store\model\user;
use app\common\model\user\Identity as BaseIdentity;
use think\Collection;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
class Identity extends BaseIdentity
{
/**
* @notes:获取全部记录
* @param array $where
* @return Identity[]|array|Collection
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
* @author: wanghousheng
*/
public function getList(array $where)
{
return $this->where($where)->select();
}
/**
* @notes:新增
* @param $data

Loading…
Cancel
Save