feat(后台gm): 新增后台宝物查询功能
This commit is contained in:
@@ -4,7 +4,7 @@ export default class UserController extends Controller {
|
||||
|
||||
public async getuserlist() {
|
||||
const { ctx } = this;
|
||||
const { page, pageSize, sortField, sortOrder, form } = ctx.request.body;
|
||||
const { page, pageSize, sortField, sortOrder, form } = ctx.request.body;
|
||||
ctx.body = await ctx.service.users.getuserlist(page, pageSize, sortField, sortOrder, form);
|
||||
}
|
||||
|
||||
@@ -13,19 +13,19 @@ export default class UserController extends Controller {
|
||||
// const { uid, roleName, serverId } = ctx.request.body;
|
||||
// ctx.body = await ctx.service.users.createRole(uid, serverId, roleName);
|
||||
// }
|
||||
|
||||
|
||||
// public async addAuth() {
|
||||
// const { ctx } = this;
|
||||
// const { uid, auth } = ctx.request.body;
|
||||
// ctx.body = await ctx.service.users.addAuth(uid, auth);
|
||||
// }
|
||||
|
||||
|
||||
public async fixSms() {
|
||||
const { ctx } = this;
|
||||
const { tel } = ctx.request.body;
|
||||
ctx.body = await ctx.service.users.fixSms(tel);
|
||||
}
|
||||
|
||||
|
||||
public async deleteRole() {
|
||||
const { ctx } = this;
|
||||
const { roleId } = ctx.request.body;
|
||||
@@ -34,13 +34,13 @@ export default class UserController extends Controller {
|
||||
|
||||
public async getrolelist() {
|
||||
const { ctx } = this;
|
||||
const { page, pageSize, sortField, sortOrder, form } = ctx.request.body;
|
||||
const { page, pageSize, sortField, sortOrder, form } = ctx.request.body;
|
||||
ctx.body = await ctx.service.users.getrolelist(page, pageSize, sortField, sortOrder, form);
|
||||
}
|
||||
|
||||
public async getpaystatic() {
|
||||
const { ctx } = this;
|
||||
const { page = 1, pageSize = 10, form } = ctx.request.body;
|
||||
const { page = 1, pageSize = 10, form } = ctx.request.body;
|
||||
ctx.body = await ctx.service.users.getpaystatic(page, pageSize, form);
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ export default class UserController extends Controller {
|
||||
|
||||
public async getHeroList() {
|
||||
const { ctx } = this;
|
||||
const { page, pageSize, sortField, sortOrder, form } = ctx.request.body;
|
||||
const { page, pageSize, sortField, sortOrder, form } = ctx.request.body;
|
||||
ctx.body = await ctx.service.users.getHeroList(page, pageSize, sortField, sortOrder, form);
|
||||
}
|
||||
|
||||
@@ -82,19 +82,25 @@ export default class UserController extends Controller {
|
||||
|
||||
public async getItemList() {
|
||||
const { ctx } = this;
|
||||
const { page, pageSize, sortField, sortOrder, form } = ctx.request.body;
|
||||
const { page, pageSize, sortField, sortOrder, form } = ctx.request.body;
|
||||
ctx.body = await ctx.service.users.getItemList(page, pageSize, sortField, sortOrder, form);
|
||||
}
|
||||
|
||||
public async getArtifactList() {
|
||||
const { ctx } = this;
|
||||
const { form } = ctx.request.body;
|
||||
ctx.body = await ctx.service.users.getArtifactList(form);
|
||||
}
|
||||
|
||||
public async getGuildList() {
|
||||
const { ctx } = this;
|
||||
const { page, pageSize, sortField, sortOrder, form } = ctx.request.body;
|
||||
const { page, pageSize, sortField, sortOrder, form } = ctx.request.body;
|
||||
ctx.body = await ctx.service.users.getGuildList(page, pageSize, sortField, sortOrder, form);
|
||||
}
|
||||
|
||||
public async getMembersByGuildCode() {
|
||||
const { ctx } = this;
|
||||
const { code } = ctx.request.body;
|
||||
const { code } = ctx.request.body;
|
||||
ctx.body = await ctx.service.users.getMembersByGuildCode(code);
|
||||
}
|
||||
|
||||
@@ -103,7 +109,7 @@ export default class UserController extends Controller {
|
||||
const { selectedRowKeys: roleIdAndIds } = ctx.request.body;
|
||||
ctx.body = await ctx.service.users.deleteItem(roleIdAndIds);
|
||||
}
|
||||
|
||||
|
||||
// public async setItemCount() {
|
||||
// const { ctx } = this;
|
||||
// const { selectedRowKeys: roleIdAndIds, count } = ctx.request.body;
|
||||
|
||||
@@ -34,6 +34,8 @@ export default (app: Application) => {
|
||||
router.post('/api/users/setcreatetime', tokenParser, controller.users.setCreateTime);
|
||||
router.post('/api/users/getherolist', tokenParser,controller.users.getHeroList);
|
||||
router.post('/api/users/getitemlist', tokenParser, controller.users.getItemList);
|
||||
router.post('/api/users/getartifactlist', tokenParser, controller.users.getArtifactList);
|
||||
|
||||
router.post('/api/users/getguildlist', tokenParser, controller.users.getGuildList);
|
||||
router.post('/api/users/getmembersbyguildcode', tokenParser, controller.users.getMembersByGuildCode);
|
||||
router.post('/api/users/deleteitem', tokenParser, controller.users.deleteItem);
|
||||
|
||||
@@ -13,7 +13,7 @@ import GiftCodeDetail, { GiftCodeDetailModel } from '@db/GiftCodeDetail';
|
||||
import { deletRole } from '@pubUtils/roleUtil';
|
||||
import { RScriptRecordModel } from '@db/RScriptRecord';
|
||||
import { DicWar } from '@pubUtils/dictionary/DicWar';
|
||||
import { SearchHeroParam, SearchUserParam, SearchGiftCodeParam, SearchGiftCodeDetailParam, SearchItemParam, SearchGuildParam, SearchRoleParam } from '@domain/backEndField/search';
|
||||
import { SearchHeroParam, SearchUserParam, SearchGiftCodeParam, SearchGiftCodeDetailParam, SearchItemParam, SearchGuildParam, SearchRoleParam, SearchArtifactParam } from '@domain/backEndField/search';
|
||||
import { CreateGiftCode, UpdateGiftCode } from '@domain/backEndField/params';
|
||||
import { isNumber } from 'util';
|
||||
import { GuildModel } from '@db/Guild';
|
||||
@@ -24,6 +24,7 @@ import { nowSeconds } from '@pubUtils/timeUtil';
|
||||
import { RoleCeModel, RoleCeType } from '@db/RoleCe';
|
||||
import { HangUpRecordModel } from '@db/HangUpRecord';
|
||||
import { UserOrderModel } from '@db/UserOrder';
|
||||
import { ArtifactModel } from '@db/Artifact';
|
||||
const Excel = require('exceljs');
|
||||
|
||||
// import { resResult } from '@pubUtils/util';
|
||||
@@ -42,7 +43,7 @@ export default class GMUsers extends Service {
|
||||
const { ctx } = this;
|
||||
|
||||
const users = await UserModel.findByCondition(page, pageSize, sortField, sortOrder, form);
|
||||
const total = await UserModel.countByCondition( form )
|
||||
const total = await UserModel.countByCondition(form)
|
||||
|
||||
let list = [];
|
||||
for (let user of users) {
|
||||
@@ -115,7 +116,7 @@ export default class GMUsers extends Service {
|
||||
console.log('enter Auth deleteRole');
|
||||
const ctx = this.ctx;
|
||||
let result = await deletRole(roleId);
|
||||
if(!result) return ctx.service.utils.resResult(STATUS.WRONG_PARMS);
|
||||
if (!result) return ctx.service.utils.resResult(STATUS.WRONG_PARMS);
|
||||
return ctx.service.utils.resResult(STATUS.SUCCESS);
|
||||
}
|
||||
|
||||
@@ -125,16 +126,16 @@ export default class GMUsers extends Service {
|
||||
public async getrolelist(page: number, pageSize: number, sortField: string, sortOrder: string, form: SearchRoleParam) {
|
||||
const { ctx } = this;
|
||||
|
||||
if(!!form.channelId) {
|
||||
if (!!form.channelId) {
|
||||
let user = await UserModel.findUserByChannelRegex(form.channelId);
|
||||
if(!user) {
|
||||
if (!user) {
|
||||
return ctx.service.utils.resResult(STATUS.SUCCESS, { list: [], total: 0 });
|
||||
}
|
||||
form.uid = user.uid;
|
||||
}
|
||||
|
||||
const roles = await RoleModel.findByCondition(page, pageSize, sortField, sortOrder, form);
|
||||
const total = await RoleModel.countByCondition( form )
|
||||
const total = await RoleModel.countByCondition(form)
|
||||
|
||||
let list = [];
|
||||
for (let role of roles) {
|
||||
@@ -157,20 +158,20 @@ export default class GMUsers extends Service {
|
||||
public async getpaystatic(page: number, pageSize: number, form: { beginTime: number, endTime: number, serverId: number }) {
|
||||
const { ctx } = this;
|
||||
let match = { state: 1 };
|
||||
if(form.beginTime && form.endTime) {
|
||||
if (form.beginTime && form.endTime) {
|
||||
match['beginTime'] = { $gt: new Date(form.beginTime) };
|
||||
match['endTime'] = { $lt: new Date(form.endTime) };
|
||||
}
|
||||
if(form.serverId) {
|
||||
if (form.serverId) {
|
||||
match['serverId'] = form.serverId;
|
||||
}
|
||||
console.log(match)
|
||||
let list = await UserOrderModel.aggregate([
|
||||
{ $match: match },
|
||||
{ $group: { '_id': '$roleId', sum: { '$sum': '$price' }, count: { '$sum': 1 }, max: { $max:'$price'}, lastTime: { $max: '$updatedAt' } } },
|
||||
{ $group: { '_id': '$roleId', sum: { '$sum': '$price' }, count: { '$sum': 1 }, max: { $max: '$price' }, lastTime: { $max: '$updatedAt' } } },
|
||||
{ $lookup: { from: 'roles', localField: '_id', foreignField: 'roleId', as: 'role' } },
|
||||
{ $unwind: '$role' },
|
||||
{ $project: { _id: 0, roleId: '$_id', roleName: '$role.roleName', guildName: '$role.guildName', serverId: '$role.serverId', lv: '$role.lv', sum: 1, count: 1, max: 1, lastTime: {$dateToString: {format: '%Y-%m-%d %H:%M:%S', date:{$add:['$lastTime',28800000]}}}, env: ctx.app.config.realEnv } },
|
||||
{ $project: { _id: 0, roleId: '$_id', roleName: '$role.roleName', guildName: '$role.guildName', serverId: '$role.serverId', lv: '$role.lv', sum: 1, count: 1, max: 1, lastTime: { $dateToString: { format: '%Y-%m-%d %H:%M:%S', date: { $add: ['$lastTime', 28800000] } } }, env: ctx.app.config.realEnv } },
|
||||
{ $sort: { 'sum': -1 } },
|
||||
{ $skip: (page - 1) * pageSize },
|
||||
{ $limit: pageSize },
|
||||
@@ -331,11 +332,11 @@ export default class GMUsers extends Service {
|
||||
const { ctx } = this;
|
||||
|
||||
const heroes = await HeroModel.findByCondition(page, pageSize, sortField, sortOrder, form);
|
||||
const total = await HeroModel.countByCondition( form )
|
||||
|
||||
const total = await HeroModel.countByCondition(form)
|
||||
|
||||
let roleMap = new Map<string, RoleCeType>();
|
||||
for(let { roleId } of heroes) {
|
||||
if(!roleMap.has(roleId)) {
|
||||
for (let { roleId } of heroes) {
|
||||
if (!roleMap.has(roleId)) {
|
||||
let roleCe = await RoleCeModel.findByRoleId(roleId);
|
||||
roleMap.set(roleId, roleCe);
|
||||
}
|
||||
@@ -343,7 +344,7 @@ export default class GMUsers extends Service {
|
||||
let list = heroes.map(cur => {
|
||||
let roleCe = roleMap.get(cur.roleId);
|
||||
let obj = roleCe?.attributes?.find(ccur => ccur.hid == cur.hid);
|
||||
return {...cur, calculatedAttr: obj?.attrs||[], env: ctx.app.config.realEnv}
|
||||
return { ...cur, calculatedAttr: obj?.attrs || [], env: ctx.app.config.realEnv }
|
||||
})
|
||||
|
||||
return ctx.service.utils.resResult(STATUS.SUCCESS, { list, total })
|
||||
@@ -479,10 +480,30 @@ export default class GMUsers extends Service {
|
||||
const { ctx } = this;
|
||||
|
||||
const items = await ItemModel.findByCondition(page, pageSize, sortField, sortOrder, form);
|
||||
const total = await ItemModel.countByCondition( form )
|
||||
const total = await ItemModel.countByCondition(form)
|
||||
|
||||
let list = items.map(cur => {
|
||||
return {...cur, env: ctx.app.config.realEnv}
|
||||
return { ...cur, env: ctx.app.config.realEnv }
|
||||
})
|
||||
|
||||
return ctx.service.utils.resResult(STATUS.SUCCESS, { list, total })
|
||||
}
|
||||
|
||||
|
||||
public async getArtifactList(form: SearchArtifactParam) {
|
||||
const { ctx } = this;
|
||||
|
||||
let artifact = await ArtifactModel.findByRoleIdAndIsShowDel(form)
|
||||
if (artifact && artifact.length > 0) {
|
||||
artifact.forEach((ele) => {
|
||||
let dicArtifact = gameData.artifact.get(ele.artifactId);
|
||||
ele.artifactName = dicArtifact.name;
|
||||
});
|
||||
}
|
||||
const total = await ArtifactModel.countByCondition(form)
|
||||
|
||||
let list = artifact.map(cur => {
|
||||
return { ...cur, env: ctx.app.config.realEnv }
|
||||
})
|
||||
|
||||
return ctx.service.utils.resResult(STATUS.SUCCESS, { list, total })
|
||||
@@ -493,13 +514,13 @@ export default class GMUsers extends Service {
|
||||
let redisClient: RedisClient = ctx.app.context.redisClient;
|
||||
|
||||
const guilds = await GuildModel.findByCondition(page, pageSize, sortField, sortOrder, form);
|
||||
const total = await GuildModel.countByCondition( form )
|
||||
const total = await GuildModel.countByCondition(form)
|
||||
|
||||
let list = [];
|
||||
for(let guild of guilds) {
|
||||
for (let guild of guilds) {
|
||||
let rank = await redisClient.zrevrankAsync(`${REDIS_KEY.GUILD_LV_RANK}:${guild.serverId}`, guild.code);
|
||||
|
||||
list.push({ ...guild, rank: rank == undefined? '未上榜': rank + 1, env: ctx.app.config.realEnv })
|
||||
list.push({ ...guild, rank: rank == undefined ? '未上榜' : rank + 1, env: ctx.app.config.realEnv })
|
||||
}
|
||||
|
||||
return ctx.service.utils.resResult(STATUS.SUCCESS, { list, total })
|
||||
@@ -508,7 +529,7 @@ export default class GMUsers extends Service {
|
||||
public async getMembersByGuildCode(code: string) {
|
||||
const { ctx } = this;
|
||||
let guild = await GuildModel.findByCode(code);
|
||||
if(!guild) return ctx.service.utils.resResult(STATUS.GUILD_NOT_FOUND);
|
||||
if (!guild) return ctx.service.utils.resResult(STATUS.GUILD_NOT_FOUND);
|
||||
|
||||
let userGuilds = await UserGuildModel.getListByGuild(code);
|
||||
let list = userGuilds.map(userGuild => ({ ...userGuild, env: ctx.app.config.realEnv }))
|
||||
@@ -520,16 +541,16 @@ export default class GMUsers extends Service {
|
||||
const { ctx } = this;
|
||||
|
||||
const list = await GiftCodeModel.findByCondition(page, pageSize, sortField, sortOrder, form);
|
||||
const total = await GiftCodeModel.countByCondition( form )
|
||||
const total = await GiftCodeModel.countByCondition(form)
|
||||
return ctx.service.utils.resResult(STATUS.SUCCESS, {
|
||||
list: list.map(cur => ({...cur, env: ctx.app.config.realEnv })), total
|
||||
list: list.map(cur => ({ ...cur, env: ctx.app.config.realEnv })), total
|
||||
});
|
||||
}
|
||||
|
||||
public async createAndGenerateGift(obj: any, count: number = 1) {
|
||||
const { ctx } = this;
|
||||
let params = new CreateGiftCode(obj);
|
||||
if(!isNumber(count) || !params.checkParams()) return ctx.service.utils.resResult(STATUS.WRONG_PARMS);
|
||||
if (!isNumber(count) || !params.checkParams()) return ctx.service.utils.resResult(STATUS.WRONG_PARMS);
|
||||
|
||||
let giftCode = await GiftCodeModel.createData(params);
|
||||
await GiftCodeDetailModel.generateMany(giftCode, count, ctx.user?.uid);
|
||||
@@ -539,50 +560,50 @@ export default class GMUsers extends Service {
|
||||
public async updateGiftCode(id: number, obj: any) {
|
||||
const { ctx } = this;
|
||||
let params = new UpdateGiftCode(id, obj);
|
||||
if(!params.checkParams()) return ctx.service.utils.resResult(STATUS.WRONG_PARMS);
|
||||
if (!params.checkParams()) return ctx.service.utils.resResult(STATUS.WRONG_PARMS);
|
||||
|
||||
const result = await GiftCodeModel.updateData(id, params, ctx.user?.uid);
|
||||
if(!result) return ctx.service.utils.resResult(STATUS.INTERNAL_ERR);
|
||||
if (!result) return ctx.service.utils.resResult(STATUS.INTERNAL_ERR);
|
||||
return ctx.service.utils.resResult(STATUS.SUCCESS);
|
||||
}
|
||||
|
||||
public async generateGiftCode(id: number, count: number) {
|
||||
const { ctx } = this;
|
||||
if(!isNumber(id) || !isNumber(count)) return ctx.service.utils.resResult(STATUS.WRONG_PARMS);
|
||||
if (!isNumber(id) || !isNumber(count)) return ctx.service.utils.resResult(STATUS.WRONG_PARMS);
|
||||
|
||||
let giftCode = await GiftCodeModel.findByGiftId(id);
|
||||
if(!giftCode) return ctx.service.utils.resResult(STATUS.DB_DATA_NOT_FOUND);
|
||||
if (!giftCode) return ctx.service.utils.resResult(STATUS.DB_DATA_NOT_FOUND);
|
||||
await GiftCodeDetailModel.generateMany(giftCode, count, ctx.user?.uid);
|
||||
return ctx.service.utils.resResult(STATUS.SUCCESS, giftCode);
|
||||
}
|
||||
|
||||
public async cancelGiftCode(id: number, isEnable: boolean) {
|
||||
const { ctx } = this;
|
||||
if(!isNumber(id)) return ctx.service.utils.resResult(STATUS.WRONG_PARMS);
|
||||
if (!isNumber(id)) return ctx.service.utils.resResult(STATUS.WRONG_PARMS);
|
||||
|
||||
let giftCode = await GiftCodeModel.findByGiftId(id);
|
||||
if(!giftCode) return ctx.service.utils.resResult(STATUS.DB_DATA_NOT_FOUND);
|
||||
if (!giftCode) return ctx.service.utils.resResult(STATUS.DB_DATA_NOT_FOUND);
|
||||
await GiftCodeModel.updateData(id, { isEnable }, ctx.user?.uid);
|
||||
return ctx.service.utils.resResult(STATUS.SUCCESS, giftCode);
|
||||
}
|
||||
|
||||
public async getGiftCodeDetailFile(id: number, fileType: string) {
|
||||
const { ctx } = this;
|
||||
|
||||
|
||||
let giftCode = await GiftCodeModel.findByGiftId(id);
|
||||
if(!giftCode) return ctx.service.utils.resResult(STATUS.WRONG_PARMS);
|
||||
if (!giftCode) return ctx.service.utils.resResult(STATUS.WRONG_PARMS);
|
||||
let giftCodeDetails = await GiftCodeDetailModel.findAllCodeByGiftId(giftCode.id);
|
||||
|
||||
if(fileType == 'txt') {
|
||||
if (fileType == 'txt') {
|
||||
let codes: string[] = [];
|
||||
for(let {code} of giftCodeDetails) {
|
||||
for (let { code } of giftCodeDetails) {
|
||||
codes.push(code);
|
||||
}
|
||||
console.log(id, codes.join())
|
||||
|
||||
ctx.set('Content-Type', 'application/octet-stream');
|
||||
return Buffer.from(codes.join('\n'));
|
||||
} else if(fileType == 'xls'){
|
||||
} else if (fileType == 'xls') {
|
||||
ctx.set('Content-Type', 'application/vnd.openxmlformats');
|
||||
return await this.generateExcelFromGiftCode(giftCodeDetails);
|
||||
}
|
||||
@@ -596,32 +617,32 @@ export default class GMUsers extends Service {
|
||||
name: 'table1',
|
||||
ref: 'A1',
|
||||
columns: [
|
||||
{name: '礼包码', filterButton: false},
|
||||
{ name: '礼包码', filterButton: false },
|
||||
],
|
||||
rows,
|
||||
});
|
||||
return await workBook.xlsx.writeBuffer();
|
||||
});
|
||||
return await workBook.xlsx.writeBuffer();
|
||||
}
|
||||
|
||||
public async getGiftCodeDetailList(page: number, pageSize: number, sortField: string, sortOrder: string, form: SearchGiftCodeDetailParam = {}) {
|
||||
const { ctx } = this;
|
||||
|
||||
const list = await GiftCodeDetailModel.findByCondition(page, pageSize, sortField, sortOrder, form);
|
||||
const total = await GiftCodeDetailModel.countByCondition( form )
|
||||
const total = await GiftCodeDetailModel.countByCondition(form)
|
||||
return ctx.service.utils.resResult(STATUS.SUCCESS, {
|
||||
list: list.map(cur => ({...cur, env: ctx.app.config.realEnv })), total
|
||||
list: list.map(cur => ({ ...cur, env: ctx.app.config.realEnv })), total
|
||||
});
|
||||
}
|
||||
|
||||
public async setWarRecord(roleId: string, warId: number) {
|
||||
const { ctx } = this;
|
||||
if(!isNumber(warId)) return ctx.service.utils.resResult(STATUS.WRONG_PARMS);
|
||||
if(warId < 104) return ctx.service.utils.resResult(STATUS.WRONG_PARMS, '不可以跳到序章以前')
|
||||
if (!isNumber(warId)) return ctx.service.utils.resResult(STATUS.WRONG_PARMS);
|
||||
if (warId < 104) return ctx.service.utils.resResult(STATUS.WRONG_PARMS, '不可以跳到序章以前')
|
||||
let dicWar = gameData.war.get(warId);
|
||||
if(!dicWar) return ctx.service.utils.resResult(STATUS.WRONG_PARMS);
|
||||
if (!dicWar) return ctx.service.utils.resResult(STATUS.WRONG_PARMS);
|
||||
|
||||
await this.setWarStarAndScript(roleId, dicWar);
|
||||
if(dicWar.warType == WAR_TYPE.TOWER) {
|
||||
if (dicWar.warType == WAR_TYPE.TOWER) {
|
||||
await this.setTowerWar(roleId, dicWar);
|
||||
}
|
||||
return ctx.service.utils.resResult(STATUS.SUCCESS);
|
||||
@@ -629,8 +650,8 @@ export default class GMUsers extends Service {
|
||||
|
||||
private async setTowerWar(roleId: string, dicWar: DicWar) {
|
||||
let towerLv = 1;
|
||||
for(let [lv, dicTower] of gameData.tower) {
|
||||
if(dicTower.warArray.indexOf(dicWar.war_id) != -1) {
|
||||
for (let [lv, dicTower] of gameData.tower) {
|
||||
if (dicTower.warArray.indexOf(dicWar.war_id) != -1) {
|
||||
towerLv = lv; break;
|
||||
}
|
||||
}
|
||||
@@ -643,26 +664,26 @@ export default class GMUsers extends Service {
|
||||
|
||||
public async setCreateTime(roleId: string, day: number) {
|
||||
const { ctx } = this;
|
||||
if(!isNumber(day) || day < 0) return ctx.service.utils.resResult(STATUS.WRONG_PARMS);
|
||||
if (!isNumber(day) || day < 0) return ctx.service.utils.resResult(STATUS.WRONG_PARMS);
|
||||
|
||||
let createTime = nowSeconds() - (day - 1) * 86400;
|
||||
|
||||
let role = await RoleModel.updateRoleInfo(roleId, { createTime });
|
||||
if(!role) return ctx.service.utils.resResult(STATUS.WRONG_PARMS);
|
||||
|
||||
if (!role) return ctx.service.utils.resResult(STATUS.WRONG_PARMS);
|
||||
|
||||
return ctx.service.utils.resResult(STATUS.SUCCESS);
|
||||
}
|
||||
|
||||
private async setWarStarAndScript(roleId: string, dicWar: DicWar) {
|
||||
let { warStar } = await RoleModel.findByRoleId(roleId);
|
||||
let deleteIds: number[] = [], myMaxWarId = 0;
|
||||
for(let i = 0; i < warStar.length; i++) {
|
||||
for (let i = 0; i < warStar.length; i++) {
|
||||
let { id, warType } = warStar[i];
|
||||
if(warType == dicWar.warType) {
|
||||
if(id >= dicWar.war_id) {
|
||||
if (warType == dicWar.warType) {
|
||||
if (id >= dicWar.war_id) {
|
||||
deleteIds.push(id);
|
||||
}
|
||||
if(id > myMaxWarId) {
|
||||
if (id > myMaxWarId) {
|
||||
myMaxWarId = id;
|
||||
}
|
||||
}
|
||||
@@ -670,31 +691,31 @@ export default class GMUsers extends Service {
|
||||
let newWarStar = warStar.filter(cur => {
|
||||
return deleteIds.indexOf(cur.id) == -1;
|
||||
});
|
||||
if(myMaxWarId < dicWar.war_id) {
|
||||
for(let id = myMaxWarId + 1; id < dicWar.war_id; id++) {
|
||||
if (myMaxWarId < dicWar.war_id) {
|
||||
for (let id = myMaxWarId + 1; id < dicWar.war_id; id++) {
|
||||
let _dicWar = gameData.war.get(id)
|
||||
if(_dicWar && _dicWar.warType == dicWar.warType) {
|
||||
if (_dicWar && _dicWar.warType == dicWar.warType) {
|
||||
newWarStar.push({ id, warType: _dicWar.warType, star: 0, stars: [] });
|
||||
}
|
||||
}
|
||||
}
|
||||
let preGkIndex = newWarStar.findIndex(cur => cur.id == dicWar.previousGk);
|
||||
console.log(dicWar.previousGk)
|
||||
if(dicWar.previousGk && preGkIndex == -1) {
|
||||
if (dicWar.previousGk && preGkIndex == -1) {
|
||||
let _dicWar = gameData.war.get(dicWar.previousGk);
|
||||
if(_dicWar) {
|
||||
if (_dicWar) {
|
||||
newWarStar.push({ id: _dicWar.war_id, warType: _dicWar.warType, star: 0, stars: [] });
|
||||
}
|
||||
}
|
||||
await RScriptRecordModel.deleteByWarType(roleId, dicWar.warType);
|
||||
let insertParams: DicWar[] = [];
|
||||
for(let [_, obj] of gameData.war) {
|
||||
if(dicWar.warType == obj.warType && obj.war_id < dicWar.war_id) {
|
||||
for (let [_, obj] of gameData.war) {
|
||||
if (dicWar.warType == obj.warType && obj.war_id < dicWar.war_id) {
|
||||
insertParams.push(obj);
|
||||
}
|
||||
}
|
||||
|
||||
if(insertParams.length > 0) {
|
||||
if (insertParams.length > 0) {
|
||||
await RScriptRecordModel.insertScripts(roleId, insertParams);
|
||||
}
|
||||
let role = await RoleModel.updateRoleInfo(roleId, { warStar: newWarStar });
|
||||
|
||||
@@ -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>; // 将所有字段变成可选项
|
||||
@@ -38,6 +38,11 @@ export interface SearchItemParam {
|
||||
id?: number;
|
||||
}
|
||||
|
||||
export interface SearchArtifactParam {
|
||||
roleId?: string;
|
||||
isShowDel?: number;
|
||||
}
|
||||
|
||||
export interface SearchGuildParam {
|
||||
serverId?: number;
|
||||
name?: string;
|
||||
|
||||
@@ -1006,5 +1006,12 @@
|
||||
"name": "上传excel",
|
||||
"module": "server",
|
||||
"type": "update"
|
||||
},
|
||||
{
|
||||
"id": 145,
|
||||
"api": "/api/users/getartifactlist",
|
||||
"name": "宝物查询",
|
||||
"module": "user",
|
||||
"type": "find"
|
||||
}
|
||||
]
|
||||
Reference in New Issue
Block a user