|
|
@@ -22,6 +22,7 @@ import { PaginationResponse } from '../dto/common.dto'
|
|
|
import { MemberService } from './member.service'
|
|
|
import { UserService } from './user.service'
|
|
|
import { TeamService } from './team.service'
|
|
|
+import { SysConfigService } from './sys-config.service'
|
|
|
import { VipLevel } from '../entities/member.entity'
|
|
|
|
|
|
export class PaymentService {
|
|
|
@@ -33,6 +34,7 @@ export class PaymentService {
|
|
|
private memberService: MemberService
|
|
|
private userService: UserService
|
|
|
private teamService: TeamService
|
|
|
+ private sysConfigService: SysConfigService
|
|
|
|
|
|
private static readonly ORDER_TYPE_TO_VIP_LEVEL_MAP: Record<OrderType, VipLevel> = {
|
|
|
[OrderType.SINGLE_TIP]: VipLevel.FREE,
|
|
|
@@ -65,6 +67,7 @@ export class PaymentService {
|
|
|
this.memberService = new MemberService(app)
|
|
|
this.userService = new UserService(app)
|
|
|
this.teamService = new TeamService(app)
|
|
|
+ this.sysConfigService = new SysConfigService(app)
|
|
|
}
|
|
|
|
|
|
private generateSign(params: Record<string, any>, key: string): string {
|
|
|
@@ -156,22 +159,16 @@ export class PaymentService {
|
|
|
if (!user) {
|
|
|
throw new Error('用户不存在')
|
|
|
}
|
|
|
- const vipPrices: Record<string, string> = {
|
|
|
- single: '0.10',
|
|
|
- hourly: '1.00',
|
|
|
- daily: '5.00',
|
|
|
- weekly: '20.00',
|
|
|
- monthly: '50.00',
|
|
|
- quarterly: '120.00',
|
|
|
- yearly: '400.00',
|
|
|
- lifetime: '1000.00'
|
|
|
- }
|
|
|
+ // 从团队配置中获取价格
|
|
|
+ const configs = await this.sysConfigService.getUserTeamConfigs(params.userId)
|
|
|
+ const config = configs.find((c: any) => c.name === params.type)
|
|
|
|
|
|
- const price = vipPrices[params.type]
|
|
|
- if (!price) {
|
|
|
- throw new Error('不支持的订单类型')
|
|
|
+ if (!config) {
|
|
|
+ throw new Error(`价格错误`)
|
|
|
}
|
|
|
|
|
|
+ const price = config.value
|
|
|
+
|
|
|
const out_trade_no = `${Date.now()}${params.userId}${randomInt(0, 1e4).toString().padStart(4, '0')}`
|
|
|
|
|
|
const paymentParams: CreatePaymentParams = {
|
|
|
@@ -184,10 +181,7 @@ export class PaymentService {
|
|
|
money: price,
|
|
|
client_ip: params.ip
|
|
|
}
|
|
|
- console.log('paymentParams:', paymentParams)
|
|
|
-
|
|
|
const result = await this.createOrder(paymentParams)
|
|
|
- console.log('result:', result)
|
|
|
|
|
|
// 创建收入记录
|
|
|
try {
|
|
|
@@ -248,8 +242,15 @@ export class PaymentService {
|
|
|
throw new Error('用户不存在')
|
|
|
}
|
|
|
|
|
|
- // 单片购买固定价格
|
|
|
- const price = '10.00'
|
|
|
+ // 从团队配置中获取单片购买价格
|
|
|
+ const configs = await this.sysConfigService.getUserTeamConfigs(params.userId)
|
|
|
+ const config = configs.find((c: any) => c.name === 'single')
|
|
|
+
|
|
|
+ if (!config) {
|
|
|
+ throw new Error('价格错误')
|
|
|
+ }
|
|
|
+
|
|
|
+ const price = config.value
|
|
|
const out_trade_no = `${Date.now()}${params.userId}${params.resourceId}${randomInt(0, 1e4)
|
|
|
.toString()
|
|
|
.padStart(4, '0')}`
|