pull/1/head
wanghousheng 10 months ago
parent dfc96c1f67
commit a33ef7f1f8
  1. 42
      app/api/controller/Identity.php
  2. 1
      app/api/model/user/Identity.php
  3. 42
      app/api/service/Identity.php
  4. 9
      app/api/service/Notify.php
  5. 47
      app/api/service/identity/PaySuccess.php
  6. 3
      app/api/service/identity/Payment.php

@ -3,7 +3,6 @@ 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;
@ -24,7 +23,7 @@ class Identity extends Controller
{
$client = $this->request->post('client');
$model = new \app\api\service\Identity();
$list = $model->center($client, ['type' => IdentityEnum::MEMBER]);
$list = $model->userCenter($client);
return $this->renderSuccess(compact('list'));
}
@ -40,7 +39,44 @@ class Identity extends Controller
{
$client = $this->request->post('client');
$model = new \app\api\service\Identity();
$list = $model->center($client, ['type' => IdentityEnum::MEMBER]);
$list = $model->dealerCenter($client);
return $this->renderSuccess(compact('list'));
}
/**
* 确认充值订单
* @return Json
* @throws BaseException
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public function submit(): Json
{
$data = $this->postForm();
$service = new \app\api\service\Identity();
$data = $service->setMethod($data['method'])
->setClient($data['client'])
->orderPay($data['identity_id'], $data['extra']);
return $this->renderSuccess($data, $service->getMessage() ?: '下单成功');
}
/**
* 交易查询
* @param string $outTradeNo 商户订单号
* @param string $method 支付方式
* @param string $client 指定的客户端
* @return Json
* @throws BaseException
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public function tradeQuery(string $outTradeNo, string $method, string $client): Json
{
$service = new \app\api\service\Identity();
$result = $service->setMethod($method)->setClient($client)->tradeQuery($outTradeNo);
$message = $result ? '恭喜您,开通成功' : ($service->getError() ?: '很抱歉,订单未支付,请重新发起');
return $this->renderSuccess(['isPay' => $result], $message);
}
}

@ -12,7 +12,6 @@ class Identity extends BaseIdentity
* @var array
*/
protected $hidden = [
'type',
'create_time',
'update_time',
'store_id',

@ -5,6 +5,7 @@ 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\enum\user\IdentityEnum;
use app\common\service\BaseService;
use cores\exception\BaseException;
use think\db\exception\DataNotFoundException;
@ -45,22 +46,55 @@ class Identity extends BaseService
}
/**
* 开通会员/分销页面数据
* 开通会员页面数据
* @param string $client 当前客户端
* @param array $where
* @return array
* @throws BaseException
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public function center(string $client, array $where): array
public function userCenter(string $client): array
{
// 当期用户信息
$userInfo = UserService::getCurrentLoginUser(true);
//是否分销商
if (UserService::isDealerMember() || UserService::isStore()) {
throwError('非法操作');
}
// 获取充值方案列表
$model = new \app\api\model\user\Identity();
$planList = $model->getList(['type' => IdentityEnum::MEMBER]);
// 根据指定客户端获取可用的支付方式
$PaymentModel = new PaymentModel;
$methods = $PaymentModel->getMethodsByClient($client);
// 返回数据
return [
'personal' => $userInfo,
'list' => $planList,
'paymentMethods' => $methods
];
}
/**
* 开通分销页面数据
* @param string $client 当前客户端
* @return array
* @throws BaseException
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public function dealerCenter(string $client): array
{
// 当期用户信息
$userInfo = UserService::getCurrentLoginUser(true);
if (UserService::isStore()) {
throwError('非法操作');
}
// 获取充值方案列表
$model = new \app\api\model\user\Identity();
$planList = $model->getList($where);
$planList = $model->getList(['type' => IdentityEnum::DEALER]);
// 根据指定客户端获取可用的支付方式
$PaymentModel = new PaymentModel;
$methods = $PaymentModel->getMethodsByClient($client);

@ -164,6 +164,15 @@ class Notify
->setPaymentData($paymentData)
->handle();
}
// 订单支付成功业务处理 (开通会员、分销商)
if ($tradeInfo['order_type'] == OrderTypeEnum::MEMBER || $tradeInfo['order_type'] == OrderTypeEnum::DEALER) {
$service = new identity\PaySuccess();
$service->setOrderNo($tradeInfo['order_no'])
->setMethod($tradeInfo['pay_method'])
->setTradeId($tradeInfo['trade_id'])
->setPaymentData($paymentData)
->handle();
}
Log::append('Notify-orderPaySucces', ['message' => '订单支付成功']);
} catch (\Throwable $e) {
// 记录错误日志

@ -14,7 +14,6 @@ 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;
@ -22,9 +21,12 @@ 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\enum\user\IdentityEnum;
use app\common\enum\user\UserTypeEnum;
use app\common\library\Lock;
use app\common\library\Log;
use app\common\service\BaseService;
use app\store\model\dealer\User;
use cores\exception\BaseException;
/**
@ -35,7 +37,7 @@ use cores\exception\BaseException;
class PaySuccess extends BaseService
{
// 当前订单信息
public ServerOrder $orderInfo;
public IdentityOrder $orderInfo;
// 当前用户信息
private UserModel $userInfo;
@ -44,7 +46,7 @@ class PaySuccess extends BaseService
private string $orderNo;
// 当前订单ID
private string $orderId;
private int $orderId;
// 订单支付方式
private string $method;
@ -59,7 +61,7 @@ class PaySuccess extends BaseService
* 设置支付的订单ID
* @param int $orderId 订单ID
*/
public function setOrderId(int $orderId): \app\api\service\Server\PaySuccess
public function setOrderId(int $orderId): PaySuccess
{
$this->orderId = $orderId;
return $this;
@ -182,9 +184,12 @@ class PaySuccess extends BaseService
UserModel::setIncPayMoney($orderInfo['user_id'], (float)$orderInfo['pay_price']);
// 记录订单支付信息
$this->updatePayInfo();
//更改会员角色
$this->activate();
});
}
/**
* 记录订单支付的信息
* @throws BaseException
@ -333,4 +338,38 @@ class PaySuccess extends BaseService
$orderInfo = $this->getOrderInfo();
Lock::unLock("OrderPaySuccess_{$orderInfo['order_id']}");
}
private function activate(): void
{
$orderInfo = $this->orderInfo;
$userInfo = $this->userInfo;
//判断当前用户角色
$orderType = $orderInfo['type'];
$userType = $userInfo['user_type'];
if ($userType == UserTypeEnum::STORE) {
return;
}
$userModel = new UserModel();
$up = [];
$time = date('Y-m-d');
if (!empty($userInfo['effective_time']) && strtotime($userInfo['effective_time']) > strtotime(date('Y-m-d'))) {
$time = $userInfo['effective_time'];
}
//已经是会员或者未开通会员
if ($orderType == IdentityEnum::MEMBER && $userType != UserTypeEnum::DEALER) {
$up['user_type'] = UserTypeEnum::MEMBER;
} else {
//分销商
$up['user_type'] = UserTypeEnum::DEALER;
if (!User::isDealerUser($userInfo['user_id'])) {
// 新增分销商用户
User::add($userInfo['user_id'], [
'real_name' => $userInfo['mobile'],
'mobile' => $userInfo['mobile'],
]);
}
}
$up['effective_time'] = date("Y-m-d", strtotime("+{$orderInfo['month']} months", strtotime($time)));
$userModel->where(['user_id' => $userInfo['user_id']])->save($up);
}
}

@ -146,6 +146,9 @@ class Payment extends BaseService
if ($info->isEmpty()) {
throwError('记录不存在');
}
if (UserService::isDealerMember() && $info['type'] == IdentityEnum::DEALER) {
throwError('非法操作');
}
if (!$model->createOrder($info->toArray())) {
throwError($model->getError() ?: '创建订单失败');
}

Loading…
Cancel
Save