4.6.7 first pr (#726)

This commit is contained in:
Archer
2024-01-10 23:35:04 +08:00
committed by GitHub
parent 414b693303
commit 006ad17c6a
186 changed files with 2996 additions and 1838 deletions

View File

@@ -54,6 +54,7 @@ const BillSchema = new Schema({
try {
BillSchema.index({ teamId: 1 });
BillSchema.index({ tmbId: 1 });
BillSchema.index({ tmbId: 1, time: 1 });
BillSchema.index({ time: 1 }, { expireAfterSeconds: 90 * 24 * 60 * 60 });
} catch (error) {
console.log(error);

View File

@@ -0,0 +1,55 @@
import { connectionMongo, type Model } from '../../../common/mongo';
const { Schema, model, models } = connectionMongo;
import { TeamCollectionName } from '@fastgpt/global/support/user/team/constant';
import { subModeMap, subStatusMap, subTypeMap } from '@fastgpt/global/support/wallet/sub/constants';
import type { TeamSubSchema } from '@fastgpt/global/support/wallet/sub/type';
export const subCollectionName = 'team.subscription';
const SubSchema = new Schema({
teamId: {
type: Schema.Types.ObjectId,
ref: TeamCollectionName,
required: true
},
type: {
type: String,
enum: Object.keys(subTypeMap),
required: true
},
mode: {
type: String,
enum: Object.keys(subModeMap),
required: true
},
status: {
type: String,
enum: Object.keys(subStatusMap),
required: true
},
renew: {
type: Boolean,
default: true
},
startTime: {
type: Date
},
expiredTime: {
type: Date
},
datasetStoreAmount: {
type: Number
}
});
try {
SubSchema.index({ teamId: 1 });
SubSchema.index({ status: 1 });
SubSchema.index({ type: 1 });
SubSchema.index({ expiredTime: -1 });
} catch (error) {
console.log(error);
}
export const MongoTeamSub: Model<TeamSubSchema> =
models[subCollectionName] || model(subCollectionName, SubSchema);

View File

@@ -0,0 +1,31 @@
import { SubStatusEnum } from '@fastgpt/global/support/wallet/sub/constants';
import { MongoTeamSub } from './schema';
/* get team dataset size */
export const getTeamDatasetValidSub = async ({
teamId,
freeSize = Infinity
}: {
teamId: string;
freeSize?: number;
}) => {
const sub = await MongoTeamSub.findOne({
teamId,
status: SubStatusEnum.active
})
.sort({
expiredTime: -1
})
.lean();
const maxSize = (() => {
if (!sub || !sub.datasetStoreAmount) return freeSize;
return sub.datasetStoreAmount + freeSize;
})();
return {
maxSize,
sub
};
};