feat(后台gm): 新增后台宝物查询功能
This commit is contained in:
@@ -2,6 +2,7 @@ import BaseModel from './BaseModel';
|
||||
import { index, getModelForClass, prop, DocumentType, modelOptions } from '@typegoose/typegoose';
|
||||
import { RoleModel } from './Role';
|
||||
import { genCode } from '../pubUtils/util';
|
||||
import { SearchArtifactParam } from '../domain/backEndField/search';
|
||||
|
||||
/**
|
||||
* 宝物
|
||||
@@ -16,7 +17,7 @@ export default class Artifact extends BaseModel {
|
||||
|
||||
// 主键: artifact,不同形态的宝物分开词条
|
||||
@prop({ required: true })
|
||||
seqId: number|string; // 唯一id
|
||||
seqId: number | string; // 唯一id
|
||||
|
||||
@prop({ required: true })
|
||||
roleId: string; // 玩家id
|
||||
@@ -48,12 +49,12 @@ export default class Artifact extends BaseModel {
|
||||
@prop({ required: true, default: 1 })
|
||||
status: number; // 装备 1-生成 0-被合成删除
|
||||
|
||||
public static async findbySeqIds(roleId: string, seqIds: (number|string)[], select?: string) {
|
||||
public static async findbySeqIds(roleId: string, seqIds: (number | string)[], select?: string) {
|
||||
const result: ArtifactModelType[] = await ArtifactModel.find({ roleId, seqId: { $in: seqIds }, status: 1 }).select(select).lean();
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async findbySeqId(roleId: string, seqId: number|string, select?: string) {
|
||||
public static async findbySeqId(roleId: string, seqId: number | string, select?: string) {
|
||||
const result: ArtifactModelType = await ArtifactModel.findOne({ roleId, seqId, status: 1 }).select(select).lean();
|
||||
return result;
|
||||
}
|
||||
@@ -72,7 +73,7 @@ export default class Artifact extends BaseModel {
|
||||
const seqId = genCode(10);
|
||||
|
||||
const doc = new ArtifactModel();
|
||||
const artifact = Object.assign(doc.toJSON(), {seqId}, artifactInfo);
|
||||
const artifact = Object.assign(doc.toJSON(), { seqId }, artifactInfo);
|
||||
return artifact;
|
||||
}
|
||||
|
||||
@@ -87,21 +88,21 @@ export default class Artifact extends BaseModel {
|
||||
return insertInfo;
|
||||
}
|
||||
|
||||
public static async putOnOrOff(roleId: string, seqId: number|string, hid: number, lv?: number) {
|
||||
public static async putOnOrOff(roleId: string, seqId: number | string, hid: number, lv?: number) {
|
||||
let update: ArtifactModelUpdate = { hid };
|
||||
if(lv != undefined) update.lv = lv;
|
||||
if (lv != undefined) update.lv = lv;
|
||||
let rec: ArtifactModelType = await ArtifactModel.findOneAndUpdate({ roleId, seqId }, { $set: update }, { new: true }).lean();
|
||||
return rec;
|
||||
}
|
||||
|
||||
public static async deleteBySeqIds(roleId: string, seqIds: (number|string)[]) {
|
||||
public static async deleteBySeqIds(roleId: string, seqIds: (number | string)[]) {
|
||||
let result: ArtifactModelType[] = await ArtifactModel.findbySeqIds(roleId, seqIds);
|
||||
let delResult: { n: number, nModified: number, ok: number } = await ArtifactModel.updateMany({ roleId, seqId: { $in: seqIds } }, { $set: { status: 0 } });
|
||||
await RoleModel.increaseArtifact(roleId, -1 * delResult.nModified);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async updateInfoBySeqId(roleId: string, seqId: number|string, update: ArtifactModelUpdate) {
|
||||
public static async updateInfoBySeqId(roleId: string, seqId: number | string, update: ArtifactModelUpdate) {
|
||||
let rec: ArtifactModelType = await ArtifactModel.findOneAndUpdate({ roleId, seqId }, { $set: update }, { new: true }).lean();
|
||||
return rec;
|
||||
}
|
||||
@@ -115,9 +116,35 @@ export default class Artifact extends BaseModel {
|
||||
let result: ArtifactModelType[] = await ArtifactModel.find({ batchCode, status: 1 }).lean();
|
||||
return result;
|
||||
}
|
||||
|
||||
private static getSearchObj(form: SearchArtifactParam) {
|
||||
let { roleId, isShowDel } = form
|
||||
let searchObj = {};
|
||||
if (form.roleId) searchObj['roleId'] = roleId;
|
||||
if (isShowDel && isShowDel == 1) {
|
||||
searchObj['status'] = 1
|
||||
}
|
||||
return searchObj
|
||||
}
|
||||
|
||||
public static async countByCondition(form: SearchArtifactParam = {}) {
|
||||
let searchObj = this.getSearchObj(form);
|
||||
const result = await ArtifactModel.count(searchObj);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async findByRoleIdAndIsShowDel(form) {
|
||||
let searchObj = this.getSearchObj(form);
|
||||
//.select("roleId roleName id artifactId artifactName lv quality qualityStage status")
|
||||
const result: ArtifactModelType[] = await ArtifactModel.find(searchObj).lean();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export const ArtifactModel = getModelForClass(Artifact);
|
||||
|
||||
export interface ArtifactModelType extends Pick<DocumentType<Artifact>, keyof Artifact> { }
|
||||
export interface ArtifactModelType extends Pick<DocumentType<Artifact>, keyof Artifact> {
|
||||
artifactName: string;
|
||||
}
|
||||
export type ArtifactModelUpdate = Partial<ArtifactModelType>; // 将所有字段变成可选项
|
||||
Reference in New Issue
Block a user