pull/1/head
wanghousheng 1 year ago
parent f999ce8bc2
commit d84eb3b046
  1. 2
      app/api/service/User.php
  2. 14
      app/api/service/identity/PaySuccess.php
  3. 23
      app/api/service/identity/Payment.php
  4. 17
      app/common/enum/user/balanceLog/Scene.php
  5. 3
      app/common/model/UserCoupon.php
  6. 2
      app/common/model/user/IdentityOrder.php

@ -162,7 +162,7 @@ class User extends UserService
* @throws BaseException * @throws BaseException
* @author: wanghousheng * @author: wanghousheng
*/ */
private function checkEffectiveTime(): bool private static function checkEffectiveTime(): bool
{ {
$userInfo = static::getCurrentLoginUser(); $userInfo = static::getCurrentLoginUser();
if (!empty($userInfo) && !empty($userInfo['effective_time'])) { if (!empty($userInfo) && !empty($userInfo['effective_time'])) {

@ -57,6 +57,8 @@ class PaySuccess extends BaseService
// 第三方支付成功返回的数据 // 第三方支付成功返回的数据
private array $paymentData = []; private array $paymentData = [];
private int $type;
/** /**
* 设置支付的订单ID * 设置支付的订单ID
* @param int $orderId 订单ID * @param int $orderId 订单ID
@ -67,6 +69,12 @@ class PaySuccess extends BaseService
return $this; return $this;
} }
public function setType($type): PaySuccess
{
$this->type = $type;
return $this;
}
/** /**
* 设置当前的订单号 * 设置当前的订单号
* @param string $orderNo * @param string $orderNo
@ -203,7 +211,11 @@ class PaySuccess extends BaseService
// 更新用户余额 // 更新用户余额
UserModel::setDecBalance((int)$orderInfo['user_id'], (float)$orderInfo['pay_price']); UserModel::setDecBalance((int)$orderInfo['user_id'], (float)$orderInfo['pay_price']);
// 新增余额变动记录 // 新增余额变动记录
BalanceLogModel::add(SceneEnum::CONSUME, [ $type = SceneEnum::MEMBER;
if ($this->type == IdentityEnum::DEALER) {
$type = SceneEnum::DEALER;
}
BalanceLogModel::add($type, [
'user_id' => (int)$orderInfo['user_id'], 'user_id' => (int)$orderInfo['user_id'],
'money' => -$orderInfo['pay_price'], 'money' => -$orderInfo['pay_price'],
], ['order_no' => $orderInfo['order_no']]); ], ['order_no' => $orderInfo['order_no']]);

@ -49,6 +49,8 @@ class Payment extends BaseService
// 下单的客户端 // 下单的客户端
private string $client = ''; private string $client = '';
private int $type;
/** /**
* 设置当前支付方式 * 设置当前支付方式
* @param string $method 支付方式 * @param string $method 支付方式
@ -60,6 +62,12 @@ class Payment extends BaseService
return $this; return $this;
} }
public function setType($type): Payment
{
$this->type = $type;
return $this;
}
/** /**
* 设置下单的客户端 * 设置下单的客户端
* @param string $client 客户端 * @param string $client 客户端
@ -83,6 +91,7 @@ class Payment extends BaseService
*/ */
public function orderPay(int $identityId, array $extra = []): array public function orderPay(int $identityId, array $extra = []): array
{ {
// 创建订单信息 // 创建订单信息
$this->orderInfo = $this->createOrder($identityId); $this->orderInfo = $this->createOrder($identityId);
// 订单支付事件 // 订单支付事件
@ -109,7 +118,7 @@ class Payment extends BaseService
{ {
// 余额支付 // 余额支付
if ($this->method == PaymentMethodEnum::BALANCE) { if ($this->method == PaymentMethodEnum::BALANCE) {
$this->orderPaySuccess($this->orderInfo['order_no']); $this->setType($this->orderInfo['order_type'])->orderPaySuccess($this->orderInfo['order_no']);
} }
} }
@ -126,7 +135,11 @@ class Payment extends BaseService
{ {
$service = new IdentityPaySuccessService(); $service = new IdentityPaySuccessService();
// 订单支付成功业务处理 // 订单支付成功业务处理
$service->setOrderNo($orderNo)->setMethod($this->method)->setTradeId($tradeId)->setPaymentData($paymentData); $service->setOrderNo($orderNo)
->setMethod($this->method)
->setTradeId($tradeId)
->setType($this->type)
->setPaymentData($paymentData);
if (!$service->handle()) { if (!$service->handle()) {
throwError($service->getError() ?: '订单支付失败'); throwError($service->getError() ?: '订单支付失败');
} }
@ -146,7 +159,7 @@ class Payment extends BaseService
if ($info->isEmpty()) { if ($info->isEmpty()) {
throwError('记录不存在'); throwError('记录不存在');
} }
if (UserService::isDealerMember() && $info['type'] == IdentityEnum::DEALER) { if (UserService::isDealerMember() && $info['type'] != IdentityEnum::DEALER) {
throwError('非法操作'); throwError('非法操作');
} }
if (!$model->createOrder($info->toArray())) { if (!$model->createOrder($info->toArray())) {
@ -225,6 +238,10 @@ class Payment extends BaseService
*/ */
private function unifiedorder(array $extra = []): array private function unifiedorder(array $extra = []): array
{ {
// 判断支付方式是否合法
if (!in_array($this->method, [PaymentMethodEnum::WECHAT, PaymentMethodEnum::ALIPAY])) {
return [];
}
// 生成第三方交易订单号 (并非主订单号) // 生成第三方交易订单号 (并非主订单号)
$outTradeNo = OrderService::createOrderNo(); $outTradeNo = OrderService::createOrderNo();
// 获取支付方式的配置信息 // 获取支付方式的配置信息

@ -33,6 +33,12 @@ class Scene extends EnumBasics
// 订单退款 // 订单退款
const REFUND = 40; const REFUND = 40;
//开通分销商
const DEALER = 70;
//开通会员
const MEMBER = 80;
/** /**
* 获取订单类型值 * 获取订单类型值
* @return array * @return array
@ -59,7 +65,18 @@ class Scene extends EnumBasics
'name' => '订单退款', 'name' => '订单退款',
'value' => self::REFUND, 'value' => self::REFUND,
'describe' => '订单退款:%s', 'describe' => '订单退款:%s',
],
self::DEALER => [
'name' => '开通分销商',
'value' => self::DEALER,
'describe' => '开通分销商:%s',
],
self::MEMBER => [
'name' => '开通会员',
'value' => self::MEMBER,
'describe' => '开通会员:%s',
] ]
]; ];
} }
} }

@ -13,7 +13,6 @@ declare (strict_types=1);
namespace app\common\model; namespace app\common\model;
use app\common\enum\coupon\ExpireType as ExpireTypeEnum; use app\common\enum\coupon\ExpireType as ExpireTypeEnum;
use app\common\enum\coupon\TypeCase;
use app\common\library\helper; use app\common\library\helper;
use app\common\model\Coupon as CouponModel; use app\common\model\Coupon as CouponModel;
use cores\BaseModel; use cores\BaseModel;
@ -177,7 +176,7 @@ class UserCoupon extends BaseModel
// 整理领取记录 // 整理领取记录
$data = [ $data = [
'coupon_id' => $couponInfo['coupon_id'], 'coupon_id' => $couponInfo['coupon_id'],
'coupon_case' => !empty($couponInfo['coupon_case']) ?: TypeCase::SHOP, 'coupon_case' => $couponInfo['coupon_case'],
'name' => $couponInfo['name'], 'name' => $couponInfo['name'],
'coupon_type' => $couponInfo['coupon_type'], 'coupon_type' => $couponInfo['coupon_type'],
'reduce_price' => $couponInfo['reduce_price'], 'reduce_price' => $couponInfo['reduce_price'],

@ -14,7 +14,7 @@ class IdentityOrder extends BaseModel
public static function detail($where) public static function detail($where)
{ {
return self::detail($where); return self::get($where);
} }
} }
Loading…
Cancel
Save