mirror of
https://github.com/labring/FastGPT.git
synced 2026-05-02 01:02:05 +08:00
update coupon type (#6623)
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
export const COUPON_PREFIX = 'coupon-';
|
||||
export const BANK_PREFIX = 'bank-';
|
||||
|
||||
export enum CouponTypeEnum {
|
||||
bank = 'bank',
|
||||
|
||||
@@ -1,36 +1,44 @@
|
||||
import type { SubTypeEnum, StandardSubLevelEnum } from '../constants';
|
||||
import type { CouponTypeEnum } from './constants';
|
||||
import z from 'zod';
|
||||
import { SubTypeEnum, StandardSubLevelEnum } from '../constants';
|
||||
import { CouponTypeEnum } from './constants';
|
||||
|
||||
export type CustomSubConfig = {
|
||||
requestsPerMinute: number;
|
||||
maxTeamMember: number;
|
||||
maxAppAmount: number;
|
||||
maxDatasetAmount: number;
|
||||
chatHistoryStoreDuration: number;
|
||||
maxDatasetSize: number;
|
||||
websiteSyncPerDataset: number;
|
||||
appRegistrationCount: number;
|
||||
auditLogStoreDuration: number;
|
||||
ticketResponseTime: number;
|
||||
customDomain: number;
|
||||
};
|
||||
const CustomSubConfigSchema = z.object({
|
||||
requestsPerMinute: z.number(),
|
||||
maxTeamMember: z.number(),
|
||||
maxAppAmount: z.number(),
|
||||
maxDatasetAmount: z.number(),
|
||||
chatHistoryStoreDuration: z.number(),
|
||||
maxDatasetSize: z.number(),
|
||||
websiteSyncPerDataset: z.number(),
|
||||
appRegistrationCount: z.number(),
|
||||
auditLogStoreDuration: z.number(),
|
||||
ticketResponseTime: z.number(),
|
||||
customDomain: z.number(),
|
||||
enableSandbox: z.boolean().optional()
|
||||
});
|
||||
export type CustomSubConfig = z.infer<typeof CustomSubConfigSchema>;
|
||||
|
||||
export type TeamCouponSub = {
|
||||
type: `${SubTypeEnum}`; // Sub type
|
||||
durationDay: number; // Duration day
|
||||
level?: `${StandardSubLevelEnum}`; // Standard sub level
|
||||
extraDatasetSize?: number; // Extra dataset size
|
||||
totalPoints?: number; // Total points(Extrapoints or Standard sub)
|
||||
customConfig?: CustomSubConfig; // Custom config for custom level (only required when level=custom)
|
||||
};
|
||||
const TeamCouponSubSchema = z.object({
|
||||
type: z.enum(SubTypeEnum).meta({ description: '套餐类型' }),
|
||||
durationDay: z.number().meta({ description: '套餐时长' }),
|
||||
level: z.enum(StandardSubLevelEnum).optional().meta({ description: '套餐等级' }),
|
||||
extraDatasetSize: z.number().optional().meta({ description: '额外数据集大小' }),
|
||||
totalPoints: z.number().optional().meta({ description: '总积分' }),
|
||||
customConfig: CustomSubConfigSchema.optional().meta({ description: '自定义配置' })
|
||||
});
|
||||
export type TeamCouponSub = z.infer<typeof TeamCouponSubSchema>;
|
||||
|
||||
export type TeamCouponSchema = {
|
||||
key: string;
|
||||
subscriptions: TeamCouponSub[];
|
||||
redeemedAt?: Date;
|
||||
expiredAt?: Date;
|
||||
redeemedTeamId?: string;
|
||||
type: CouponTypeEnum;
|
||||
price?: number;
|
||||
description?: string;
|
||||
};
|
||||
const TeamCouponSchema = z.object({
|
||||
key: z.string(),
|
||||
subscriptions: z.array(TeamCouponSubSchema).meta({ description: '套餐列表' }),
|
||||
redeemedAt: z.date().optional().meta({ description: '使用时间' }),
|
||||
expiredAt: z.date().optional().meta({ description: '过期时间' }),
|
||||
redeemedTeamId: z.string().optional().meta({ description: '使用团队 ID' }),
|
||||
type: z.enum(CouponTypeEnum).meta({ description: '优惠券类型' }),
|
||||
price: z.number().optional().meta({ description: '价格' }),
|
||||
paidAmount: z.number().optional().meta({ description: '实付金额' }),
|
||||
transactionId: z.string().optional().meta({ description: '交易 ID' }),
|
||||
description: z.string().optional().meta({ description: '描述' }),
|
||||
createdAt: z.date().meta({ description: '创建时间' })
|
||||
});
|
||||
export type TeamCouponSchemaType = z.infer<typeof TeamCouponSchema>;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { addDays } from 'date-fns';
|
||||
import { connectionMongo, getMongoModel } from '../../../common/mongo';
|
||||
const { Schema } = connectionMongo;
|
||||
import type { TeamCouponSchema } from '@fastgpt/global/support/wallet/sub/coupon/type';
|
||||
import type { TeamCouponSchemaType } from '@fastgpt/global/support/wallet/sub/coupon/type';
|
||||
import { TeamCollectionName } from '@fastgpt/global/support/user/team/constant';
|
||||
import { CouponTypeEnum } from '@fastgpt/global/support/wallet/sub/coupon/constants';
|
||||
import { getLogger, LogCategories } from '../../../common/logger';
|
||||
@@ -18,11 +18,17 @@ const CouponSchema = new Schema({
|
||||
enum: Object.values(CouponTypeEnum)
|
||||
},
|
||||
price: Number,
|
||||
paidAmount: Number,
|
||||
transactionId: String,
|
||||
description: String,
|
||||
subscriptions: {
|
||||
type: [Object],
|
||||
required: true
|
||||
},
|
||||
createdAt: {
|
||||
type: Date,
|
||||
default: () => new Date()
|
||||
},
|
||||
redeemedAt: {
|
||||
type: Date,
|
||||
default: undefined
|
||||
@@ -44,4 +50,7 @@ try {
|
||||
logger.error('Failed to build coupon indexes', { error });
|
||||
}
|
||||
|
||||
export const MongoTeamCoupon = getMongoModel<TeamCouponSchema>(couponCollectionName, CouponSchema);
|
||||
export const MongoTeamCoupon = getMongoModel<TeamCouponSchemaType>(
|
||||
couponCollectionName,
|
||||
CouponSchema
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user