feat(db): 修改对item表的数据库操作方式

This commit is contained in:
liangtongchuan
2023-05-06 17:44:56 +08:00
parent df35bee3b5
commit 76877348ba
7 changed files with 23 additions and 23 deletions

View File

@@ -12,7 +12,7 @@ import { STATUS } from '../../../consts/statusCode';
import { Application, BackendSession } from 'pinus';
import { resResult, getRandSingleEelm, cal } from '../../../pubUtils/util';
import { RoleStatus, ComBattleTeamModel, ComBattleTeamType, BossHp, ComRoleStatusHero } from '../../../db/ComBattleTeam';
import { ItemModel, ItemType } from '../../../db/Item';
import Item, { ItemType } from '../../../db/Item';
import { addItems, handleCost } from '../../../services/role/rewardService';
import { checkRoleInQueue, getServerName, redisClient, rmCreatedTeamFromRedis, rmRoleFromQueue, setTeamSearchReq } from '../../../services/redisService';
import { getRandBlueprtId, getFrd, updateRobotHurtByTime, comBtlLvInvalid, clearRobotHurtTimer, setDismissTimer, dismissTeam, handleComBtlProgress, getComBattleFriendAdd, teammateInBlackList, blueprtIdValid, hasEnoughBlueprt, addRoleToTeam, addRoleStToTeam, addValidSearchingRoles, validToJoin, addRobotsToTeam, addRobotsLater, teamIsFullToStart, oneTeamNotInBlack, getAllAssistCnt, checkHasMyTeam, checkTeamStatusAndSend, getComBtlLvByPlayerLv, addToSearchingTeams, getCapFrd, getCapExtraCnt, startTeam } from '../../../services/battle/comBattleService';
@@ -631,9 +631,9 @@ export class ComBattleHandler {
let { ids } = msg;
let blueprts: ItemType[];
if (ids && ids.length) {
blueprts = await ItemModel.findbyRoleAndIds(roleId, ids);
blueprts = await Item.findbyRoleAndIds(roleId, ids);
} else {
blueprts = await ItemModel.findByRoleAndType(roleId, CONSUME_TYPE.BLUEPRT);
blueprts = await Item.findByRoleAndType(roleId, CONSUME_TYPE.BLUEPRT);
}
return resResult(STATUS.SUCCESS, { blueprts });
}
@@ -660,7 +660,7 @@ export class ComBattleHandler {
async getComBtlCnt(msg: {}, session: BackendSession) {
let roleId = session.get('roleId');
let cnt = await getAllAssistCnt(roleId);
const blueprts = await ItemModel.findByRoleAndType(roleId, CONSUME_TYPE.BLUEPRT);
const blueprts = await Item.findByRoleAndType(roleId, CONSUME_TYPE.BLUEPRT);
let capExtraCnt = await getCapExtraCnt(roleId);
return resResult(STATUS.SUCCESS, { blueprts, assistCnt: cnt, capExtraCnt });
}

View File

@@ -5,7 +5,7 @@ import { STATUS } from '../../../consts/statusCode';
import Hero, { Connect, HeroSkin, HeroUpdate, EPlace, Talent } from '../../../db/Hero';
import { CURRENCY_BY_TYPE, CURRENCY_TYPE, CONSUME_TYPE, HERO_GROW_MAX, HERO_SYSTEM_TYPE, ABI_STAGE, DEBUG_MAGIC_WORD, HERO_INITIAL_QUALITY, REDIS_KEY, TASK_TYPE, ITEM_CHANGE_REASON, CHECK_HERO_CONSUME } from '../../../consts';
import Role from '../../../db/Role';
import { ItemModel } from '../../../db/Item';
import Item from '../../../db/Item';
import { gameData, getHeroExpByLv, getHeroStarByQuality, getHeroWakeByQuality, getHeroLvByExp, getMaxGradeByjobClass, getJobByGradeAndClass, getConnectLvByExp, getEquipByJobClassAndEPlace, getScollByStar, getExpByLv, getConnectMaxLv, getFriendShipByIdAndLv } from '../../../pubUtils/data';
import { ItemInter, RewardInter } from '../../../pubUtils/interface';
import { getDropItems, FIGURE_UNLOCK_CONDITION, ITID } from '../../../consts/constModules/itemConst'
@@ -100,7 +100,7 @@ export class HeroHandler {
let newExp = oldExp;
// 计算得材料可转换的经验
let originalConsumes = await ItemModel.findByRoleAndType(roleId, CONSUME_TYPE.EXP);
let originalConsumes = await Item.findByRoleAndType(roleId, CONSUME_TYPE.EXP);
let material = new Array<RewardInter>();
for (let { id, count } of originalConsumes) {
let dicGoods = gameData.goods.get(id);
@@ -473,7 +473,7 @@ export class HeroHandler {
let newExp = oldExp;
// 计算得材料可转换的经验
let originalConsumes = await ItemModel.findByRoleAndType(roleId, CONSUME_TYPE.FAVOUR);
let originalConsumes = await Item.findByRoleAndType(roleId, CONSUME_TYPE.FAVOUR);
let material = new Array<RewardInter>();
for (let { id, count } of originalConsumes) {
let dicGoods = gameData.goods.get(id);

View File

@@ -1,5 +1,5 @@
import { MemComBtlTeam } from '../../domain/battleField/ComBattleTeamField';
import { ItemModel } from '../../db/Item';
import Item from '../../db/Item';
import { BATTLE_REWARD_TYPE, ITEM_CHANGE_REASON, IT_TYPE, PUSH_ROUTE } from '../../consts';
import { FriendRelationModel } from '../../db/FriendRelation';
import Role, { RoleType } from '../../db/Role';
@@ -505,7 +505,7 @@ export function blueprtIdValid(id: number) {
* @returns
*/
export async function hasEnoughBlueprt(roleId: string, sid: string, blueprtId: number) {
let blueprt = await ItemModel.findbyRoleAndGidAndCount(roleId, blueprtId, 1);
let blueprt = await Item.findbyRoleAndGidAndCount(roleId, blueprtId, 1);
if (!blueprt || blueprt.count <= 0) return false;
// 检查是否有已创建未结束的寻宝,预先占用一张藏宝图
// // 背包中占用的藏宝图不显示,所以这里就扣掉,结束再加回去

View File

@@ -31,7 +31,7 @@ import { GuildModel, GuildType } from '../db/Guild';
import UserGuild, { UserGuildType } from '../db/UserGuild';
import { getAllGuildActivityStatus } from './guildActivity/guildActivityService';
import { getAllOnlineRoles, getAllServers, incConnectorNum, redisClient } from './redisService';
import Item, { ItemModel } from '../db/Item';
import Item from '../db/Item';
import { PvpDefenseModel } from '../db/PvpDefense';
import { getDonation } from './donateService';
import { refChallengeCnt, sendLastSeasonRewardIfNotSent } from './pvpService';
@@ -123,7 +123,7 @@ export async function getModuleData(type: string, data: { role: RoleType, sessio
case 'role':
let heros = await Hero.findByRole(role.roleId, [], HERO_SELECT.ENTRY, true);
let jewels = await JewelModel.findbyRole(role.roleId, JEWEL_SELECT.ENTRY);
let items = await ItemModel.findbyRole(role.roleId, ITEM_SELECT.ENTRY);
let items = await Item.findbyRole(role.roleId, ITEM_SELECT.ENTRY);
let skins = await SkinModel.findbyRole(role.roleId, SKIN_SELECT.ENTRY);
let artifacts = await ArtifactModel.findbyRole(role.roleId, ARTIFACT_SELECT.ENTRY);
let activityItems = await ActivityItemModel.findbyRole(role.roleId, ACTIVITYITEM_SELECT.ENTRY);

View File

@@ -1,6 +1,6 @@
import { CURRENCY_TYPE, HANDLE_REWARD_TYPE, CURRENCY_BY_TYPE } from '../../consts';
import Role, { RoleType } from '../../db/Role';
import { ItemModel, ItemType } from '../../db/Item';
import Item, { ItemType } from '../../db/Item';
import { ItemInter, RewardInter, } from '../../pubUtils/interface';
import { gameData } from '../../pubUtils/data';
import { sortItems } from './util';
@@ -81,7 +81,7 @@ export class CheckMeterial {
private async decreaseItem(id: number, count: number) {
console.log('#### decreaseItem 1', id, count);
if(!this.itemsIndb.has(id)) {
let item = await ItemModel.findbyRoleAndGid(this.roleId, id);
let item = await Item.findbyRoleAndGid(this.roleId, id);
console.log('#### decreaseItem', item);
if(!item) {
this.pushToNotEnoughItems(id, count);

View File

@@ -2,7 +2,7 @@ import { ITID, CONSUME_TYPE, ITEM_TABLE, CURRENCY_TYPE, MAIL_TYPE, HANDLE_REWARD
import { getDecimalCnt, getRandEelm, getRandEelmWithWeight, getRandValueByMinMax, } from '../../pubUtils/util';
import Role, { RoleType } from '../../db/Role';
import { setAp } from '../actionPointService';
import { ItemModel, } from '../../db/Item';
import Item from '../../db/Item';
import { ItemInter, } from '../../pubUtils/interface';
import { gameData, getDefArtifactByGid } from '../../pubUtils/data';
import { uniq } from 'underscore';
@@ -59,7 +59,7 @@ export async function handleCost(roleId: string, sid: string, goods: Array<ItemI
}
//检查并修改道具
if (items.length > 0) {
let { hasError, result } = await ItemModel.decreaseItems(roleId, items);
let { hasError, result } = await Item.decreaseItems(roleId, items);
if (hasError) return false;
sendMessageToUserWithSuc(roleId, PUSH_ROUTE.ITEM_UPDATE, { goods: result.map(cur => ({...cur, reason })) }, sid);
saveItemChangeLog(roleId, result, reason);
@@ -340,7 +340,7 @@ export async function checkGoods(roleId: string, goodIds: Array<number>) {
}
//检查并修改道具
if (itemIds.length > 0) {
let items = await ItemModel.findbyRoleAndIds(roleId, itemIds);
let items = await Item.findbyRoleAndIds(roleId, itemIds);
if (items.length < itemIds.length)
return false;
}
@@ -460,7 +460,7 @@ export async function addBag(roleId: string, roleName: string, data: { id: numbe
let { name: itemName, itid, hid } = gameData.goods.get(id);
let { type } = ITID.get(itid);
let item = await ItemModel.increaseItem(roleId, id, count, { roleId, roleName, itemName, id, type, hid });
let item = await Item.increaseItem(roleId, id, count, { roleId, roleName, itemName, id, type, hid });
return { id: item.id, count: item.count, inc: count, reason };
}

View File

@@ -4,7 +4,7 @@ import Hero from '@db/Hero';
import { Service } from 'egg';
import { STATUS, REDIS_KEY, WAR_TYPE } from '@consts';
import { ItemModel } from '@db/Item';
import Item from '@db/Item';
import { gameData } from '@pubUtils/data';
import { smsModel } from '@db/Sms';
import { isString } from 'underscore';
@@ -139,7 +139,7 @@ export default class GMUsers extends Service {
let list = [];
for (let role of roles) {
let heroCount = await Hero.countByCondition({ roleId: role.roleId });
let itemCount = await ItemModel.count({ roleId: role.roleId }).lean();
let itemCount = await Item.countByCondition({ roleId: role.roleId });
let { roleId, roleName, serverId, lv, gold, coin, ce, blockType = 0, blockReason = '', fixedIpLocation, ip, ipLocation, totalPay } = role;
let { uid, tel } = role.userInfo;
@@ -368,7 +368,7 @@ export default class GMUsers extends Service {
}
for (let [roleId, ids] of map) {
await ItemModel.deletebyRoleAndIds(roleId, ids);
await Item.deletebyRoleAndIds(roleId, ids);
}
return ctx.service.utils.resResult(STATUS.SUCCESS);
@@ -393,7 +393,7 @@ export default class GMUsers extends Service {
// }
// for (let [roleId, ids] of map) {
// await ItemModel.updateCountByRoleAndIds(roleId, ids, count);
// await Item.updateCountByRoleAndIds(roleId, ids, count);
// }
// return ctx.service.utils.resResult(STATUS.SUCCESS);
@@ -478,8 +478,8 @@ export default class GMUsers extends Service {
public async getItemList(page: number, pageSize: number, sortField: string, sortOrder: string, form: SearchItemParam) {
const { ctx } = this;
const items = await ItemModel.findByCondition(page, pageSize, sortField, sortOrder, form);
const total = await ItemModel.countByCondition( form )
const items = await Item.findByCondition(page, pageSize, sortField, sortOrder, form);
const total = await Item.countByCondition( form )
let list = items.map(cur => {
return {...cur, env: ctx.app.config.realEnv}