好友:赠送礼物

This commit is contained in:
luying
2021-02-03 20:17:55 +08:00
parent fe85f0e247
commit 41bf3d96b5
10 changed files with 725 additions and 624 deletions

View File

@@ -31,14 +31,14 @@ export default class FriendPoint extends BaseModel {
public static async updatePointToday(roleId: string, roleName: string, cntInc: number, maxPerDay: number, type: number, lean = true) {
const curTime = new Date((new Date()).setHours(0, 0, 0, 0));
// 当 oldCnt + cntInc > maxPerDay 时需计算实际可以获得的点数cntInc - (newCnt - maxPerDay)
const rec: FriendPointType = await FriendPointModel.findOneAndUpdate({roleId, roleName, createdAt: {$gte: curTime}, cnt: {$lt: maxPerDay}, type}, {$inc: {cnt: cntInc}}, {upsert: true, new: true}).lean(lean);
const rec: FriendPointType = await FriendPointModel.findOneAndUpdate({roleId, roleName, createdAt: {$gte: curTime}, cnt: {$lt: maxPerDay}, type}, {$inc: {cnt: cntInc, sendCnt: 0}}, {upsert: true, new: true}).lean(lean);
return rec;
}
public static async updateSendCntToday(roleId: string, roleName: string, cntInc: number, maxPerDay: number, type: number, lean = true) {
const curTime = new Date((new Date()).setHours(0, 0, 0, 0));
// 当 oldCnt + cntInc > maxPerDay 时需计算实际可以获得的点数cntInc - (newCnt - maxPerDay)
const rec: FriendPointType = await FriendPointModel.findOneAndUpdate({roleId, roleName, createdAt: {$gte: curTime}, sendCnt: {$lt: maxPerDay}, type}, {$inc: {sendCnt: cntInc}}, {upsert: true, new: true}).lean(lean);
const rec: FriendPointType = await FriendPointModel.findOneAndUpdate({roleId, roleName, createdAt: {$gte: curTime}, sendCnt: {$lt: maxPerDay}, type}, {$inc: {sendCnt: cntInc, cnt: 0}}, {upsert: true, new: true}).lean(lean);
return rec;
}

View File

@@ -0,0 +1,31 @@
import BaseModel from './BaseModel';
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
import { ItemReward } from './generalField';
/**
* GM用户组接口
*/
@index({ uid: 1 })
@index({ api: 1 })
export default class FriendPresentLog extends BaseModel {
@prop({ required: true })
roleId: string;
@prop({ required: true })
hisRoleId: string;
@prop({ required: true, type: ItemReward, default: [] })
items: ItemReward[];
public static async createRecord(roleId: string, hisRoleId: string, items: ItemReward[]) {
const r = await FriendPresentLogModel.insertMany({roleId, hisRoleId, items});
return r;
}
}
export const FriendPresentLogModel = getModelForClass(FriendPresentLog);
export interface FriendPresentLogType extends Pick<DocumentType<FriendPresentLog>, keyof FriendPresentLog>{};

View File

@@ -3,6 +3,7 @@ import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoos
import { getFriendLvByExp } from '../pubUtils/data';
import * as util from '../pubUtils/friendUtil';
import { nowSeconds } from '../pubUtils/timeUtil';
import { FRIEND } from '../consts';
/**
* 好友直接的亲密值
@@ -144,6 +145,15 @@ export default class FriendShip extends BaseModel {
return result;
}
// 增加亲密度
public static async addFriendValue(roleId: string, hisRoleId: string, inc: number) {
let { roleIds } = util.getRoleIds([roleId, hisRoleId]);
let result: FriendShipType = await FriendShipModel.findOneAndUpdate({ roleIds }, { $inc: { friendValue: inc } }, { new: true })
.select(FRIEND.SEND_PRESENT)
.lean({ virtuals: true });
return result;
}
}
export const FriendShipModel = getModelForClass(FriendShip);

View File

@@ -255,4 +255,11 @@ export class PvpOtherHeroes extends PvpHeroInfo {
super();
this.score = score;
}
}
export class ItemReward {
@prop({ required: true })
id: number;
@prop({ required: true })
count: number;
}