活动:糜家商队
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 }));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -349,9 +349,7 @@ export class HeroHandler {
|
||||
await checkTask(roleId, sid, funcs, TASK_TYPE.HERO_WAKE_UP, 1, true, {});
|
||||
await checkActivityTask(serverId, sid, funcs, roleId, TASK_TYPE.HERO_QUALITY_WAKE_UP_COUNT, 1, { quality: hero.quality });
|
||||
await checkActivityTask(serverId, sid, funcs, roleId, TASK_TYPE.HERO_WAKE_UP_COUNT, 1, { hid: hid });
|
||||
if (isWakeUp) {//觉醒升星
|
||||
await checkActivityTask(serverId, sid, funcs, roleId, TASK_TYPE.HERO_WAKE_UP_STAR_UP_COUNT, 1, { quality: dicHero.quality, colorStar: update.colorStar });
|
||||
}
|
||||
await checkActivityTask(serverId, sid, funcs, roleId, TASK_TYPE.HERO_WAKE_UP_STAR_UP_COUNT, 1, { quality: dicHero.quality, colorStar: update.colorStar });
|
||||
}
|
||||
const curHero = {
|
||||
hid,
|
||||
|
||||
@@ -15,6 +15,7 @@ import { ServerlistModel } from '../db/Serverlist';
|
||||
import { makeGrowthFund } from './growthFundService';
|
||||
import { makeLimitPackageReward } from './limitPackageService';
|
||||
import { makeShop } from './treasureHuntService';
|
||||
import { makeSelfServerShop } from './selfServiceShopActivityService';
|
||||
|
||||
|
||||
|
||||
@@ -109,6 +110,11 @@ export async function makeOrder(localOrderID: string, sid: string, orderInfo: Us
|
||||
rewardResult = await makeShop(roleId, roleInfo.roleName, sid, orderInfo.serverId, roleInfo.funcs, orderInfo.activityId, orderInfo.productID)
|
||||
break;
|
||||
}
|
||||
case ACTIVITY_TYPE.SELF_SERVICE_SHOP://自选商店-购买礼包
|
||||
{
|
||||
rewardResult = await makeSelfServerShop(roleId, roleInfo.roleName, sid, orderInfo.serverId, roleInfo.funcs, orderInfo.activityId, orderInfo.productID)
|
||||
break;
|
||||
}
|
||||
default:
|
||||
rewardResult = STATUS.ERROR_TYPE;
|
||||
break;
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { ACTIVITY_RESOURCES_TYPE, ACTIVITY_TYPE } from '../consts';
|
||||
import { ACTIVITY_RESOURCES_TYPE, ACTIVITY_TYPE, STATUS } from '../consts';
|
||||
import { ActivityModel, ActivityModelType } from '../db/Activity';
|
||||
import { ActivitySelfServiceGoodsModel, ActivitySelfServiceGoodsModelType } from '../db/ActivitySelfServiceGoods';
|
||||
import { ActivitySelfServiceShopModel, ActivitySelfServiceShopModelType } from '../db/ActivitySelfServiceShop';
|
||||
import { ActivitySelfServiceModel, ActivitySelfServiceModelType } from '../db/ActivitySelfService';
|
||||
import { ServerlistModel } from '../db/Serverlist';
|
||||
import { RewardParam } from '../domain/activityField/rewardField';
|
||||
import { SelfServiceShopData, SelfServiceShopItem } from '../domain/activityField/selfServiceShopField';
|
||||
@@ -42,9 +43,12 @@ export async function getPlayerActivityData(activityId: number, serverId: number
|
||||
let activityData: ActivityModelType = await ActivityModel.findActivity(activityId);
|
||||
let playerData = new SelfServiceShopData(activityData);
|
||||
|
||||
let playerRecords: ActivitySelfServiceShopModelType[] = await ActivitySelfServiceShopModel.findDataByPriceType(serverId, activityId, roleId, playerData.roundIndex, ACTIVITY_RESOURCES_TYPE.RMB);
|
||||
let playerRecords: ActivitySelfServiceShopModelType[] = await ActivitySelfServiceShopModel.findDataByPriceType(serverId, activityId, roleId, playerData.roundIndex);
|
||||
|
||||
playerData.setPlayerRecords(playerRecords);
|
||||
let playerSelfServerData = await ActivitySelfServiceModel.findData(serverId, activityId, roleId, playerData.roundIndex);
|
||||
let buyCount = (playerSelfServerData && playerSelfServerData.unitBuyCount) ? playerSelfServerData.unitBuyCount : 0;
|
||||
playerData.unitBuyCount = buyCount;
|
||||
|
||||
return playerData;
|
||||
}
|
||||
@@ -61,7 +65,7 @@ export async function getPlayerActivityData(activityId: number, serverId: number
|
||||
* @param {number} priceType 价格类型
|
||||
*
|
||||
*/
|
||||
export async function addSelfServiceShopGiftReward(roleId: string, roleName: string, sid: string, serverId: number, funcs: number[], activityId: number, roundIndex: number, index: number, price: number, priceType: number) {
|
||||
export async function addSelfServiceShopGiftReward(roleId: string, roleName: string, sid: string, serverId: number, funcs: number[], activityId: number, roundIndex: number, index: number) {
|
||||
let playerGoods: ActivitySelfServiceGoodsModelType[] = await ActivitySelfServiceGoodsModel.findDataByIndex(activityId, roleId, roundIndex, index);
|
||||
|
||||
let rewardArray: Array<RewardParam> = [];
|
||||
@@ -78,6 +82,49 @@ export async function addSelfServiceShopGiftReward(roleId: string, roleName: str
|
||||
}
|
||||
let result = await addReward(roleId, roleName, sid, serverId, funcs, rewardArray);
|
||||
//购买记录
|
||||
await ActivitySelfServiceShopModel.addBuyRecord(serverId, activityId, roleId, roundIndex, index, price, priceType, goodsStr);
|
||||
console.log('dddddddd', rewardArray.length, serverId, activityId, roleId, roundIndex, index, goodsStr)
|
||||
await ActivitySelfServiceShopModel.addBuyRecord(serverId, activityId, roleId, roundIndex, index, goodsStr);
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 购买自选礼包
|
||||
*
|
||||
* @param {number} serverId 区Id
|
||||
* @param {number} activityId 活动Id
|
||||
* @param {string} roleId 角色Id
|
||||
* @param {string} productID 商品ID
|
||||
*
|
||||
*/
|
||||
export async function makeSelfServerShop(roleId: string, roleName: string, sid: string, serverId: number, funcs: number[],
|
||||
activityId: number, productID: string) {
|
||||
|
||||
let activityData: ActivityModelType = await ActivityModel.findActivity(activityId);
|
||||
if (!activityData) {
|
||||
return {
|
||||
code: STATUS.ACTIVITY_MISSING,
|
||||
}
|
||||
}
|
||||
let playerData = new SelfServiceShopData(activityData);
|
||||
let item: SelfServiceShopItem = playerData.getItemByProductID(productID);
|
||||
if (!item) {
|
||||
return {
|
||||
code: STATUS.ACTIVITY_DATA_ERROR,
|
||||
}
|
||||
}
|
||||
if (item.countMax > 0) {//限制购买次数
|
||||
let playerRecords: ActivitySelfServiceShopModelType[] = await ActivitySelfServiceShopModel.findDataByIndex(serverId, activityId, roleId, playerData.roundIndex, item.index);
|
||||
if (playerRecords.length >= item.countMax) {
|
||||
return {
|
||||
code: STATUS.ACTIVITY_MAX_COUNT,
|
||||
}
|
||||
}
|
||||
}
|
||||
let result = await addSelfServiceShopGiftReward(roleId, roleName, sid, serverId, funcs, activityId, playerData.roundIndex, item.index);
|
||||
item.buyCount += 1;
|
||||
return {
|
||||
code: 0,
|
||||
data: Object.assign(result, { item })
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user