活动:糜家商队
This commit is contained in:
@@ -4,10 +4,12 @@ import { STATUS, ACTIVITY_RESOURCES_TYPE, ACTIVITY_TYPE, CURRENCY_BY_TYPE, CURRE
|
||||
import { SelfServiceShopData, SelfServiceShopItem, SelfServiceShopItemInfo } from '../../../domain/activityField/selfServiceShopField';
|
||||
import { addItems, handleCost } from '../../../services/rewardService';
|
||||
import { ActivitySelfServiceShopModel, ActivitySelfServiceShopModelType } from '../../../db/ActivitySelfServiceShop';
|
||||
import { ActivitySelfServiceModel, ActivitySelfServiceModelType } from '../../../db/ActivitySelfService';
|
||||
import { ActivitySelfServiceGoodsModel, ActivitySelfServiceGoodsModelType } from '../../../db/ActivitySelfServiceGoods';
|
||||
import moment = require('moment');
|
||||
import Activity, { ActivityModel, ActivityModelType } from '../../../db/Activity';
|
||||
import { addSelfServiceShopGiftReward, getActivityData, getPlayerActivityData } from '../../../services/selfServiceShopActivityService';
|
||||
import { addReward, stringToConsumeParam, stringToRewardParam } from '../../../services/giftPackageService';
|
||||
|
||||
export default function (app: Application) {
|
||||
return new SelfServiceShopHandler(app);
|
||||
@@ -17,7 +19,7 @@ export class SelfServiceShopHandler {
|
||||
constructor(private app: Application) {
|
||||
}
|
||||
|
||||
/************************自助商店****************************/
|
||||
/************************自助商店、糜家商队****************************/
|
||||
|
||||
/**
|
||||
* @description 获取自助商店数据
|
||||
@@ -62,17 +64,15 @@ export class SelfServiceShopHandler {
|
||||
}
|
||||
|
||||
let price = item.price;
|
||||
let priceType = item.priceType;
|
||||
|
||||
//检查资源
|
||||
if (priceType === ACTIVITY_RESOURCES_TYPE.GOODS) {//茶晶
|
||||
let result = await handleCost(roleId, sid, [{ id: CURRENCY_BY_TYPE.get(CURRENCY_TYPE.COIN), count: price }]);
|
||||
if (!result) return resResult(STATUS.ROLE_MATERIAL_NOT_ENOUGH);
|
||||
|
||||
} else if (priceType === ACTIVITY_RESOURCES_TYPE.RMB) {//RMB购买
|
||||
return resResult(STATUS.ACTIVITY_DATA_ERROR);
|
||||
if (price > 0) {//RMB购买
|
||||
return resResult(STATUS.ACTIVITY_NEED_PAY);
|
||||
}
|
||||
let result = await addSelfServiceShopGiftReward(roleId, roleName, sid, serverId, funcs, activityId, roundIndex, index, price, priceType);
|
||||
//检查资源
|
||||
let consume = stringToConsumeParam(item.consume)
|
||||
let consumeResult = await handleCost(roleId, sid, consume);
|
||||
if (!consumeResult) return resResult(STATUS.ROLE_MATERIAL_NOT_ENOUGH);
|
||||
|
||||
let result = await addSelfServiceShopGiftReward(roleId, roleName, sid, serverId, funcs, activityId, roundIndex, index);
|
||||
return resResult(STATUS.SUCCESS, Object.assign(result, {}));
|
||||
}
|
||||
|
||||
@@ -92,4 +92,43 @@ export class SelfServiceShopHandler {
|
||||
await ActivitySelfServiceGoodsModel.addGoods(activityId, roleId, roundIndex, index, cellIndex, gift, rewardIndex);
|
||||
return resResult(STATUS.SUCCESS, {});
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 购买代币资源
|
||||
* @param {{ activityId: number, roundIndex: number}} msg
|
||||
* @param {BackendSession} session
|
||||
* @memberof SelfServiceShopHandler
|
||||
*/
|
||||
async buyRecources(msg: { activityId: number, roundIndex: number }, session: BackendSession) {
|
||||
const { activityId, roundIndex } = msg;
|
||||
const roleId = session.get('roleId');
|
||||
const serverId = session.get('serverId');
|
||||
const sid = session.get('sid');
|
||||
const roleName = session.get('roleName');
|
||||
const funcs: number[] = session.get('funcs');
|
||||
|
||||
let activityData: ActivityModelType = await ActivityModel.findActivity(activityId);
|
||||
let playerData = new SelfServiceShopData(activityData);
|
||||
let unitPrice = playerData.unitPrice;//购买价格
|
||||
let unitCountMax = playerData.unitCountMax;//最大购买次数
|
||||
let unitReward = playerData.unitReward;//购买获得资源
|
||||
|
||||
let playerSelfServerData = await ActivitySelfServiceModel.findData(serverId, activityId, roleId, roundIndex);
|
||||
|
||||
let buyCount = (playerSelfServerData && playerSelfServerData.unitBuyCount) ? playerSelfServerData.unitBuyCount : 0;
|
||||
if (buyCount >= unitCountMax) {
|
||||
return resResult(STATUS.ACTIVITY_MAX_COUNT);
|
||||
}
|
||||
|
||||
//检查资源
|
||||
let consume = stringToConsumeParam(unitPrice)
|
||||
let consumeResult = await handleCost(roleId, sid, consume);
|
||||
if (!consumeResult) return resResult(STATUS.ROLE_MATERIAL_NOT_ENOUGH);
|
||||
|
||||
await ActivitySelfServiceModel.addBuyRecord(serverId, activityId, roleId, roundIndex, 1);
|
||||
let rewardArray = stringToRewardParam(unitReward)
|
||||
let result = await addReward(roleId, roleName, sid, serverId, funcs, rewardArray);
|
||||
|
||||
return resResult(STATUS.SUCCESS, Object.assign(result, { unitBuyCount: buyCount + 1 }));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user