Skip to content

Commit

Permalink
reseet free plan
Browse files Browse the repository at this point in the history
  • Loading branch information
c121914yu committed Feb 27, 2024
1 parent 2de74f9 commit 82b6e8d
Show file tree
Hide file tree
Showing 13 changed files with 17 additions and 125 deletions.
1 change: 1 addition & 0 deletions packages/global/common/string/time.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ import dayjs from 'dayjs';

export const formatTime2YMDHM = (time?: Date) =>
time ? dayjs(time).format('YYYY-MM-DD HH:mm') : '';
export const formatTime2YMD = (time?: Date) => (time ? dayjs(time).format('YYYY-MM-DD') : '');
1 change: 0 additions & 1 deletion packages/service/common/vectorStore/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ const getVectorObj = () => {
export const initVectorStore = getVectorObj().init;
export const deleteDatasetDataVector = getVectorObj().delete;
export const recallFromVectorStore = getVectorObj().recall;
export const checkVectorDataExist = getVectorObj().checkDataExist;
export const getVectorDataByTime = getVectorObj().getVectorDataByTime;
export const getVectorCountByTeamId = getVectorObj().getVectorCountByTeamId;

Expand Down
4 changes: 1 addition & 3 deletions packages/service/common/vectorStore/pg/class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import {
deleteDatasetDataVector,
embeddingRecall,
getVectorDataByTime,
getVectorCountByTeamId,
checkDataExist
getVectorCountByTeamId
} from './controller';

export class PgVector {
Expand All @@ -14,7 +13,6 @@ export class PgVector {
insert = insertDatasetDataVector;
delete = deleteDatasetDataVector;
recall = embeddingRecall;
checkDataExist = checkDataExist;
getVectorCountByTeamId = getVectorCountByTeamId;
getVectorDataByTime = getVectorDataByTime;
}
5 changes: 0 additions & 5 deletions packages/service/common/vectorStore/pg/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,6 @@ export const embeddingRecall = async (
}
};

export const checkDataExist = async (id: string) => {
const { rows } = await PgClient.query(`SELECT id FROM ${PgDatasetTableName} WHERE id=${id};`);

return rows.length > 0;
};
export const getVectorCountByTeamId = async (teamId: string) => {
const total = await PgClient.count(PgDatasetTableName, {
where: [['team_id', String(teamId)]]
Expand Down
4 changes: 1 addition & 3 deletions packages/service/support/wallet/sub/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,7 @@ try {
SubSchema.index({ teamId: 1, type: 1, expiredTime: -1 });

// timer task. check expired plan; update standard plan;
SubSchema.index({ type: 1, expiredTime: -1 });
// timer task. clear dead team
SubSchema.index({ type: 1, currentSubLevel: 1, nextSubLevel: 1 });
SubSchema.index({ type: 1, currentSubLevel: 1, expiredTime: -1 });
} catch (error) {
console.log(error);
}
Expand Down
52 changes: 1 addition & 51 deletions packages/service/support/wallet/sub/utils.ts
Original file line number Diff line number Diff line change
@@ -1,57 +1,7 @@
import { SubTypeEnum } from '@fastgpt/global/support/wallet/sub/constants';
import { MongoTeamSub } from './schema';
import {
FeTeamPlanStatusType,
StandSubPlanLevelMapType
} from '@fastgpt/global/support/wallet/sub/type.d';
import { getVectorCountByTeamId } from '../../../common/vectorStore/controller';
import { StandSubPlanLevelMapType } from '@fastgpt/global/support/wallet/sub/type.d';

export const getTeamSubPlans = async ({
teamId,
standardPlans
}: {
teamId: string;
standardPlans?: StandSubPlanLevelMapType;
}): Promise<FeTeamPlanStatusType> => {
const [plans, usedDatasetSize] = await Promise.all([
MongoTeamSub.find({ teamId }).lean(),
getVectorCountByTeamId(teamId)
]);

const standard = plans.find((plan) => plan.type === SubTypeEnum.standard);
const extraDatasetSize = plans.filter((plan) => plan.type === SubTypeEnum.extraDatasetSize);
const extraPoints = plans.filter((plan) => plan.type === SubTypeEnum.extraPoints);

const totalPoints = standardPlans
? (standard?.totalPoints || 0) +
extraPoints.reduce((acc, cur) => acc + (cur.totalPoints || 0), 0)
: Infinity;
const surplusPoints =
(standard?.surplusPoints || 0) +
extraPoints.reduce((acc, cur) => acc + (cur.surplusPoints || 0), 0);

const standardMaxDatasetSize =
standard?.currentSubLevel && standardPlans
? standardPlans[standard.currentSubLevel]?.maxDatasetSize || Infinity
: Infinity;
const totalDatasetSize =
standardMaxDatasetSize +
extraDatasetSize.reduce((acc, cur) => acc + (cur.currentExtraDatasetSize || 0), 0);

return {
[SubTypeEnum.standard]: standard,
standardConstants:
standard?.currentSubLevel && standardPlans
? standardPlans[standard.currentSubLevel]
: undefined,

totalPoints,
usedPoints: totalPoints - surplusPoints,

datasetMaxSize: totalDatasetSize,
usedDatasetSize
};
};
export const getUserStandDardList = async (teamId: string) => {
return MongoTeamSub.find({ teamId });
};
Expand Down
4 changes: 2 additions & 2 deletions projects/app/src/pages/account/components/Info.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { putUpdateMemberName } from '@/web/support/user/team/api';
import { getDocPath } from '@/web/common/system/doc';
import { MongoImageTypeEnum } from '@fastgpt/global/common/file/image/constants';
import { standardSubLevelMap } from '@fastgpt/global/support/wallet/sub/constants';
import { formatTime2YMDHM } from '@fastgpt/global/common/string/time';
import { formatTime2YMD } from '@fastgpt/global/common/string/time';
import { AI_POINT_USAGE_CARD_ROUTE } from '@/web/support/wallet/sub/constants';

import StandardPlanContentList from '@/components/support/wallet/StandardPlanContentList';
Expand Down Expand Up @@ -386,7 +386,7 @@ const PlanUsage = () => {
</Box>
<Flex mt="3" color={'#485264'} fontSize="sm">
<Box>{t('common.Expired Time')}:</Box>
<Box ml={2}>{formatTime2YMDHM(standardPlan?.expiredTime)}</Box>
<Box ml={2}>{formatTime2YMD(standardPlan?.expiredTime)}</Box>
</Flex>
</Box>
<Button onClick={() => router.push('/price')}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { useTranslation } from 'next-i18next';
import { useQuery } from '@tanstack/react-query';
import { useLoading } from '@/web/common/hooks/useLoading';
import MyIcon from '@fastgpt/web/components/common/Icon';
import { getTeamPlans } from '@/web/support/wallet/sub/api';
import { getTeamPlans } from '@/web/support/user/team/api';
import { subTypeMap, standardSubLevelMap } from '@fastgpt/global/support/wallet/sub/constants';
import { TeamSubSchema } from '@fastgpt/global/support/wallet/sub/type';
import { formatTime2YMDHM } from '@fastgpt/global/common/string/time';
Expand Down
24 changes: 0 additions & 24 deletions projects/app/src/pages/api/support/wallet/sub/getTeamPlans.ts

This file was deleted.

30 changes: 0 additions & 30 deletions projects/app/src/pages/api/support/wallet/sub/getTeamSubStatus.ts

This file was deleted.

7 changes: 7 additions & 0 deletions projects/app/src/web/support/user/team/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
TeamMemberItemType,
TeamMemberSchema
} from '@fastgpt/global/support/user/team/type.d';
import { FeTeamPlanStatusType, TeamSubSchema } from '@fastgpt/global/support/wallet/sub/type';

/* --------------- team ---------------- */
export const getTeamList = (status: `${TeamMemberSchema['status']}`) =>
Expand Down Expand Up @@ -55,3 +56,9 @@ export const checkTeamExportDatasetLimit = (datasetId: string) =>
export const checkTeamWebSyncLimit = () => GET(`/support/user/team/limit/webSyncLimit`);
export const checkTeamDatasetSizeLimit = (size: number) =>
GET(`/support/user/team/limit/datasetSizeLimit`, { size });

/* plans */
export const getTeamPlanStatus = () =>
GET<FeTeamPlanStatusType>(`/proApi/support/user/team/plan/getTeamSubStatus`, { maxQuantity: 1 });
export const getTeamPlans = () =>
GET<TeamSubSchema[]>(`/proApi/support/user/team/plan/getTeamPlans`);
4 changes: 3 additions & 1 deletion projects/app/src/web/support/user/useUserStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import type { UserUpdateParams } from '@/types/user';
import type { UserType } from '@fastgpt/global/support/user/type.d';
import { getTokenLogin, putUserInfo } from '@/web/support/user/api';
import { FeTeamPlanStatusType } from '@fastgpt/global/support/wallet/sub/type';
import { getTeamPlanStatus } from '@/web/support/wallet/sub/api';
import { getTeamPlanStatus } from './team/api';
import { useSystemStore } from '@/web/common/system/useSystemStore';

type State = {
userInfo: UserType | null;
Expand Down Expand Up @@ -60,6 +61,7 @@ export const useUserStore = create<State>()(
},
teamPlanStatus: null,
initTeamPlanStatus() {
if (!useSystemStore.getState()?.feConfigs?.isPlus) return Promise.resolve();
return getTeamPlanStatus().then((res) => {
set((state) => {
state.teamPlanStatus = res;
Expand Down
4 changes: 0 additions & 4 deletions projects/app/src/web/support/wallet/sub/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,12 @@ import {
StandardSubPlanUpdateResponse
} from '@fastgpt/global/support/wallet/sub/api';
import { SubStatusEnum, SubTypeEnum } from '@fastgpt/global/support/wallet/sub/constants';
import { FeTeamPlanStatusType, TeamSubSchema } from '@fastgpt/global/support/wallet/sub/type';

export const putTeamDatasetSubStatus = (data: {
status: `${SubStatusEnum}`;
type: `${SubTypeEnum}`;
}) => POST('/proApi/support/wallet/sub/updateStatus', data);

export const getTeamPlanStatus = () =>
GET<FeTeamPlanStatusType>(`/support/wallet/sub/getTeamSubStatus`);
export const getTeamPlans = () => GET<TeamSubSchema[]>(`/support/wallet/sub/getTeamPlans`);
export const postCheckStandardSub = (data: StandardSubPlanParams) =>
POST<StandardSubPlanUpdateResponse>('/proApi/support/wallet/sub/standard/preCheck', data);
export const postUpdateStandardSub = (data: StandardSubPlanParams) =>
Expand Down

0 comments on commit 82b6e8d

Please sign in to comment.