团购:基础接口
This commit is contained in:
@@ -39,6 +39,7 @@ import { isArray } from 'underscore';
|
||||
import { getGuideGachaData } from './gachaService';
|
||||
import { getPopNoticeData } from './popNoticeService';
|
||||
import { _getActivities, _getActivitiesByServerId, _getActivitiesByType, _getActivityById } from './activityRemoteService';
|
||||
import { getGroupShopDataShow } from './groupShopService';
|
||||
|
||||
/**
|
||||
* 获取活动数据
|
||||
@@ -222,6 +223,11 @@ export async function getActivity(serverId: number, roleId: string, guildCode: s
|
||||
activityData = await getPopNoticeData(serverId, activityId, roleId);
|
||||
break
|
||||
}
|
||||
case ACTIVITY_TYPE.GROUP_SHOP:
|
||||
{
|
||||
activityData = await getGroupShopDataShow(activityId, roleId);
|
||||
break
|
||||
}
|
||||
default: {
|
||||
console.log('未知活动类型.........', activityType)
|
||||
break;
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
import { GROUP_SHOP_PRICE_STATUS } from "../../consts";
|
||||
import { ActivityGroupShopRecModel } from "../../db/ActivityGroupShopRec";
|
||||
import { ActivityGroupShopUserRecModel } from "../../db/ActivityGroupShopUserRec";
|
||||
import { GroupShopData } from "../../domain/activityField/groupShopField";
|
||||
import { getRoleCreateTime, getServerCreateTime } from "../redisService";
|
||||
import { getActivityById } from "./activityService";
|
||||
|
||||
/**
|
||||
* 玩家活动数据
|
||||
*
|
||||
* @param {number} serverId 区Id
|
||||
* @param {number} activityId 活动Id
|
||||
* @param {string} roleId 角色Id
|
||||
*
|
||||
*/
|
||||
export async function getGroupShopData(activityId: number, roleId: string) {
|
||||
let activityData = await getActivityById(activityId);
|
||||
let createTime = await getRoleCreateTime(roleId);
|
||||
|
||||
let playerData = new GroupShopData(activityData, createTime, 0);
|
||||
let serverRecords = await ActivityGroupShopRecModel.findByActivity(activityId);
|
||||
playerData.setRecords(serverRecords);
|
||||
let playerRecords = await ActivityGroupShopUserRecModel.findByActivityAndRoleId(activityId, roleId);
|
||||
playerData.setPlayerRecord(playerRecords);
|
||||
|
||||
return playerData;
|
||||
}
|
||||
|
||||
export async function getGroupShopDataShow(activityId: number, roleId: string) {
|
||||
let playerData = await getGroupShopData(activityId, roleId);
|
||||
if(playerData && playerData.canShow && playerData.canShow()) {
|
||||
return playerData.getShowResult();
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
export function getGroupShopPriceStatus(clientPrice: number, price: number) {
|
||||
if(clientPrice == price) return GROUP_SHOP_PRICE_STATUS.NORMAL;
|
||||
if(clientPrice < price) return GROUP_SHOP_PRICE_STATUS.NOT_ENOUGH;
|
||||
return GROUP_SHOP_PRICE_STATUS.OVER;
|
||||
}
|
||||
@@ -56,6 +56,11 @@ export async function addRoleToWorldAuctionChannel(roleId: string, sid: string,
|
||||
await addRoleToChannel(roomId, roleId, sid);
|
||||
}
|
||||
|
||||
export async function addRoleToGroupShopChannel(roleId: string, sid: string) {
|
||||
const roomId = groupRoomId(CHANNEL_PREFIX.GROUP_SHOP);
|
||||
await addRoleToChannel(roomId, roleId, sid);
|
||||
}
|
||||
|
||||
async function leaveChannel(roomId: string, roleId: string, sid: string) {
|
||||
const channelSid = await channelServer(roomId);
|
||||
await pinus.app.rpc.chat.chatRemote.leaveChannel.toServer(channelSid, roomId, roleId, sid);
|
||||
@@ -86,6 +91,11 @@ export async function leaveWorldAuctionChannel(roleId: string, sid: string, serv
|
||||
await leaveChannel(roomId, roleId, sid);
|
||||
}
|
||||
|
||||
export async function leaveGroupShopChannel(roleId: string, sid: string) {
|
||||
const roomId = groupRoomId(CHANNEL_PREFIX.GROUP_SHOP);
|
||||
await leaveChannel(roomId, roleId, sid);
|
||||
}
|
||||
|
||||
export async function leaveGuildChannel(roleId: string, sid: string, guildCode: string) {
|
||||
if (!guildCode) return;
|
||||
const roomId = groupRoomId(CHANNEL_PREFIX.GUILD, guildCode);
|
||||
@@ -122,6 +132,12 @@ export async function getWorldAuctionChannelSid(serverId: number) {
|
||||
return channelSid;
|
||||
}
|
||||
|
||||
export async function getGroupShopSid() {
|
||||
const roomId = groupRoomId(CHANNEL_PREFIX.GROUP_SHOP);
|
||||
const channelSid = await channelServer(roomId);
|
||||
return channelSid;
|
||||
}
|
||||
|
||||
async function delChannel(roomId: string) {
|
||||
const channelSid = await channelServer(roomId);
|
||||
await pinus.app.rpc.chat.chatRemote.deleteChannel.toServer(channelSid, roomId);
|
||||
|
||||
@@ -38,8 +38,8 @@ export function privateRoomId(roleId: string, targetRoleId: string) {
|
||||
* @param {string} channelId
|
||||
* @returns
|
||||
*/
|
||||
export function groupRoomId(channel: string, channelId: string | number) {
|
||||
return `${channel}_${channelId}`;
|
||||
export function groupRoomId(channel: string, channelId?: string | number) {
|
||||
return channelId?`${channel}_${channelId}`: `${channel}`;
|
||||
}
|
||||
|
||||
function msgCounterName(roomId: string) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Channel, pinus } from "pinus";
|
||||
import { CHANNEL_PREFIX, PUSH_BATCH, PUSH_INTERVAL, PUSH_ROUTE, STATUS } from "../consts";
|
||||
import { genCode, resResult } from "../pubUtils/util";
|
||||
import { getCityChannelSid, getGuildChannelSid, getWorldChannelSid, groupRoomId } from "./chatService";
|
||||
import { getCityChannelSid, getGuildChannelSid, getWorldChannelSid, groupRoomId, getGroupShopSid } from "./chatService";
|
||||
import { getAllOnlineRoles, getRoleOnlineInfo } from "./redisService";
|
||||
import { errlogger, infologger } from '../util/logger';
|
||||
import { MsgEncrypt } from "../pubUtils/sysUtil";
|
||||
@@ -64,6 +64,12 @@ export async function sendMessageToCity(cityId: number, route: string, data: any
|
||||
await pinus.app.rpc.chat.chatRemote.pushMessage.toServer(channelSid, roomId, route, data);
|
||||
}
|
||||
|
||||
export async function sendMessageToGroupShopWithSuc(route: string, data: any) {
|
||||
let channelSid = await getGroupShopSid();
|
||||
let roomId = groupRoomId(CHANNEL_PREFIX.GROUP_SHOP);
|
||||
await pinus.app.rpc.chat.chatRemote.pushMessage.toServer(channelSid, roomId, route, resResult(STATUS.SUCCESS, data));
|
||||
}
|
||||
|
||||
export async function sendMessageToUserWithSuc(roleId: string, route: string, data: any, sid?: string) {
|
||||
await sendMessageToUser(roleId, route, resResult(STATUS.SUCCESS, data), sid);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user