活动:糜家商队

This commit is contained in:
qiaoxin
2021-06-08 17:36:44 +08:00
parent c51997299c
commit cc218151e4
12 changed files with 659 additions and 361 deletions

View File

@@ -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 })
}
}