feat: 好友邀请
This commit is contained in:
31
src/service/models/promotionRecord.ts
Normal file
31
src/service/models/promotionRecord.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import { Schema, model, models, Model } from 'mongoose';
|
||||
import { PromotionRecordSchema as PromotionRecordType } from '@/types/mongoSchema';
|
||||
|
||||
const PromotionRecordSchema = new Schema({
|
||||
userId: {
|
||||
type: Schema.Types.ObjectId,
|
||||
ref: 'user',
|
||||
required: true
|
||||
},
|
||||
objUId: {
|
||||
type: Schema.Types.ObjectId,
|
||||
ref: 'user',
|
||||
required: false
|
||||
},
|
||||
createTime: {
|
||||
type: Date,
|
||||
default: () => new Date()
|
||||
},
|
||||
type: {
|
||||
type: String,
|
||||
required: true,
|
||||
enum: ['invite', 'shareModel', 'withdraw']
|
||||
},
|
||||
amount: {
|
||||
type: Number,
|
||||
required: true
|
||||
}
|
||||
});
|
||||
|
||||
export const promotionRecord: Model<PromotionRecordType> =
|
||||
models['promotionRecord'] || model('promotionRecord', PromotionRecordSchema);
|
||||
@@ -31,11 +31,6 @@ const UserSchema = new Schema({
|
||||
// 返现比例
|
||||
type: Number,
|
||||
default: 15
|
||||
},
|
||||
amount: {
|
||||
// 推广金额
|
||||
type: Number,
|
||||
default: 0
|
||||
}
|
||||
},
|
||||
openaiKey: {
|
||||
|
||||
@@ -62,3 +62,4 @@ export * from './models/data';
|
||||
export * from './models/dataItem';
|
||||
export * from './models/splitData';
|
||||
export * from './models/openapi';
|
||||
export * from './models/promotionRecord';
|
||||
|
||||
36
src/service/utils/promotion.ts
Normal file
36
src/service/utils/promotion.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import { promotionRecord } from '../mongo';
|
||||
|
||||
export const pushPromotionRecord = async ({
|
||||
userId,
|
||||
objUId,
|
||||
type,
|
||||
amount
|
||||
}: {
|
||||
userId: string;
|
||||
objUId: string;
|
||||
type: 'invite' | 'shareModel';
|
||||
amount: number;
|
||||
}) => {
|
||||
try {
|
||||
await promotionRecord.create({
|
||||
userId,
|
||||
objUId,
|
||||
type,
|
||||
amount
|
||||
});
|
||||
} catch (error) {
|
||||
console.log('创建推广记录异常', error);
|
||||
}
|
||||
};
|
||||
|
||||
export const withdrawRecord = async ({ userId, amount }: { userId: string; amount: number }) => {
|
||||
try {
|
||||
await promotionRecord.create({
|
||||
userId,
|
||||
type: 'withdraw',
|
||||
amount
|
||||
});
|
||||
} catch (error) {
|
||||
console.log('提现记录异常', error);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user