商店:rmb购买

This commit is contained in:
luying
2022-07-25 20:55:26 +08:00
parent 57283c6b20
commit 528a862d1c
9 changed files with 326 additions and 134 deletions
@@ -2,15 +2,13 @@ import { Application, BackendSession } from "pinus";
import { gameData, hasShopType } from "../../../pubUtils/data";
import { parseGoodStr, resResult } from "../../../pubUtils/util";
import { STATUS, GUILD_STRUCTURE, ITID, CONSUME_TYPE, HERO_QUALITY_TYPE, HERO_GROW_MAX, ITEM_CHANGE_REASON } from "../../../consts";
import { DicShopListModel } from "../../../db/DicShopList";
import { UserShopModel } from "../../../db/UserShop";
import { handleCost, addItems } from "../../../services/role/rewardService";
import { GuildModel } from "../../../db/Guild";
import { SHOP } from "../../../pubUtils/dicParam";
import { HeroModel } from "../../../db/Hero";
import { getShopDicById, getShopListByType, getShopPrice } from "../../../services/shopService";
import { checkShopInPurchase, getShopDicById, getShopListByType, getShopPrice } from "../../../services/shopService";
import { RewardInter } from "../../../pubUtils/interface";
import { RoleModel } from "../../../db/Role";
import { UserShopTypeModel } from "../../../db/UserShopType";
export default function(app: Application) {
return new ShopHandler(app);
@@ -34,43 +32,38 @@ export class ShopHandler {
return resResult(STATUS.SUCCESS, result);
}
// 读取红点
async readShop(msg: { shop: number, type: number }, session: BackendSession) {
let roleId = session.get('roleId');
let { shop, type } = msg;
if(!hasShopType(shop, type)) {
return resResult(STATUS.WRONG_PARMS);
}
await UserShopTypeModel.read(roleId, shop, type);
return resResult(STATUS.SUCCESS);
}
// 购买商品
async purchase(msg: { activityId: number, shopItemId: number, count: number }, session: BackendSession) {
let roleId = session.get('roleId');
let roleName = session.get('roleName');
let sid = session.get('sid');
let guildCode = session.get('guildCode');
let serverId = session.get('serverId');
let vipStartTime: number = session.get('vipStartTime');
let { activityId, shopItemId, count } = msg;
if( count < 0) return resResult(STATUS.WRONG_PARMS);
let dicShopItem = await getShopDicById(activityId, shopItemId, roleId, serverId);
if(!dicShopItem) return resResult(STATUS.DIC_DATA_NOT_FOUND);
if(dicShopItem.guildLvLimit) {
let myGuild = await GuildModel.findByCode(guildCode, serverId);
if(!myGuild || myGuild.lv < dicShopItem.guildLvLimit) return resResult(STATUS.GUILD_LV_LIMIT);
}
if(dicShopItem.lvLimit) {
let role = await RoleModel.findByRoleId(roleId, 'lv');
if(role.lv < dicShopItem.lvLimit) {
return resResult(STATUS.LV_LIMIT);
}
}
if(!dicShopItem) return STATUS.DIC_DATA_NOT_FOUND;
if(dicShopItem['productID']) return resResult(STATUS.CAN_NOT_PURCHASE);
let userShop = await UserShopModel.findByRoleAndItem(roleId, activityId, dicShopItem);
if(dicShopItem.purchaseLimit != -1) {
if(vipStartTime > 0 && dicShopItem.purchaseLimit != -1) {
if(userShop && userShop.count + count > dicShopItem.purchaseLimit + dicShopItem.vipPurchaseLimit) {
return resResult(STATUS.BUY_COUNT_OVER);
}
} else {
if(userShop && userShop.count + count > dicShopItem.purchaseLimit) {
return resResult(STATUS.BUY_COUNT_OVER);
}
}
let checkResult = await checkShopInPurchase(session, activityId, count, userShop?.count||0, dicShopItem);
if(checkResult.code != STATUS.SUCCESS.code) {
return resResult(checkResult);
}
// 消耗