pull/1/head
wanghousheng 10 months 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
* @author: wanghousheng
*/
private function checkEffectiveTime(): bool
private static function checkEffectiveTime(): bool
{
$userInfo = static::getCurrentLoginUser();
if (!empty($userInfo) && !empty($userInfo['effective_time'])) {

@ -57,6 +57,8 @@ class PaySuccess extends BaseService
// 第三方支付成功返回的数据
private array $paymentData = [];
private int $type;
/**
* 设置支付的订单ID
* @param int $orderId 订单ID
@ -67,6 +69,12 @@ class PaySuccess extends BaseService
return $this;
}
public function setType($type): PaySuccess
{
$this->type = $type;
return $this;
}
/**
* 设置当前的订单号
* @param string $orderNo
@ -203,7 +211,11 @@ class PaySuccess extends BaseService
// 更新用户余额
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'],
'money' => -$orderInfo['pay_price'],
], ['order_no' => $orderInfo['order_no']]);

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

@ -33,6 +33,12 @@ class Scene extends EnumBasics
// 订单退款
const REFUND = 40;
//开通分销商
const DEALER = 70;
//开通会员
const MEMBER = 80;
/**
* 获取订单类型值
* @return array
@ -59,7 +65,18 @@ class Scene extends EnumBasics
'name' => '订单退款',
'value' => self::REFUND,
'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;
use app\common\enum\coupon\ExpireType as ExpireTypeEnum;
use app\common\enum\coupon\TypeCase;
use app\common\library\helper;
use app\common\model\Coupon as CouponModel;
use cores\BaseModel;
@ -177,7 +176,7 @@ class UserCoupon extends BaseModel
// 整理领取记录
$data = [
'coupon_id' => $couponInfo['coupon_id'],
'coupon_case' => !empty($couponInfo['coupon_case']) ?: TypeCase::SHOP,
'coupon_case' => $couponInfo['coupon_case'],
'name' => $couponInfo['name'],
'coupon_type' => $couponInfo['coupon_type'],
'reduce_price' => $couponInfo['reduce_price'],

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