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