✨ feat(活动): 微信公众号口令
This commit is contained in:
@@ -6,8 +6,10 @@ import { DailyItem } from '../../../domain/activityField/dailyChallengesField';
|
||||
import { addReward, stringToRewardParam } from '../../../services/activity/giftPackageService';
|
||||
import { RewardParam } from '../../../domain/activityField/rewardField';
|
||||
import { ActivityDailyChallengesModel } from '../../../db/ActivityDailyChallenges';
|
||||
import { getBindPhoneData, getBindPhoneDataShow } from '../../../services/activity/bindPhoneService';
|
||||
import { getBindPhoneData, getAllSnsLinkDataShow, getPublicAccountData } from '../../../services/activity/bindPhoneService';
|
||||
import { ActivityBindPhoneRewardModel } from '../../../db/ActivityBindPhoneReward';
|
||||
import { ActivityPublicAccountCodeModel } from '../../../db/ActivityPublicAccountCode';
|
||||
import { UserModel } from '../../../db/User';
|
||||
|
||||
|
||||
export default function (app: Application) {
|
||||
@@ -25,7 +27,7 @@ export class BindPhoneHandler {
|
||||
const serverId = session.get('serverId');
|
||||
const uid = session.get('userid');
|
||||
|
||||
let playerData = await getBindPhoneDataShow(activityId, roleId, serverId, uid);
|
||||
let playerData = await getAllSnsLinkDataShow(activityId, roleId, serverId, uid);
|
||||
return resResult(STATUS.SUCCESS, {
|
||||
playerData
|
||||
})
|
||||
@@ -98,9 +100,30 @@ export class BindPhoneHandler {
|
||||
* @memberof BindPhoneHandler
|
||||
*/
|
||||
async receiveGiftCode(msg: { activityId: number }, session: BackendSession) {
|
||||
return resResult(STATUS.SUCCESS);
|
||||
}
|
||||
const { activityId } = msg;
|
||||
const roleId = session.get('roleId');
|
||||
const serverId = session.get('serverId');
|
||||
const sid = session.get('sid');
|
||||
const roleName = session.get('roleName');
|
||||
const uid = session.get('userid');
|
||||
|
||||
let user = await UserModel.findUserByUid(uid);
|
||||
let playerData = await getPublicAccountData(activityId, roleId, serverId, user);
|
||||
let data = playerData?.wxPublicAccount;
|
||||
if(!data) return resResult(STATUS.ACTIVITY_ID_ERROR);
|
||||
if(data.status == BIND_PHONE_STATUS.WAIT_BIND) return resResult(STATUS.ACTIVITY_PUBLIC_ACCOUNT_WAIT);
|
||||
if(data.status == BIND_PHONE_STATUS.RECEIVED) return resResult(STATUS.ACTIVITY_PUBLIC_ACCOUNT_RECEIVED);
|
||||
|
||||
await ActivityPublicAccountCodeModel.receive(activityId, user.channelId);
|
||||
let rewardArray = stringToRewardParam(data.rewards)
|
||||
let { goods, addHeros } = await addReward(roleId, roleName, sid, serverId, rewardArray, ITEM_CHANGE_REASON.ACT_BIND_PHONE);
|
||||
|
||||
return resResult(STATUS.SUCCESS, {
|
||||
activityId,
|
||||
status: BIND_PHONE_STATUS.RECEIVED,
|
||||
goods, addHeros
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 前往论坛,用于前往论坛任务
|
||||
|
||||
@@ -12,6 +12,7 @@ import { saveActivityMemory } from '../../../services/log/memoryLogService';
|
||||
import { setApiIsClose } from '../../../services/chatService';
|
||||
import { setHiddenData } from '../../../services/dataService';
|
||||
import { setKvToMemory } from '../../../services/pushService';
|
||||
import { sendPublicAccountGift } from '../../../services/activity/bindPhoneService';
|
||||
|
||||
export default function (app: Application) {
|
||||
new HandlerService(app, {});
|
||||
@@ -174,4 +175,12 @@ export class ActivityRemote {
|
||||
errlogger.error(`remote ${__filename} \n ${e.stack}`);
|
||||
}
|
||||
}
|
||||
|
||||
public async sendPublicAccountGift(message: string) {
|
||||
try {
|
||||
await sendPublicAccountGift(message);
|
||||
} catch(e) {
|
||||
errlogger.error(`remote ${__filename} \n ${e.stack}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@ import { Application, ChannelService, HandlerService, } from 'pinus';
|
||||
import { reloadResources } from '../../../pubUtils/data';
|
||||
import { RankFirstModel, RankFirstType } from '../../../db/RankFirst';
|
||||
import { PVPConfigModel, PVPConfigType } from '../../../db/PvpConfig';
|
||||
import { treatRoleName, taflush, sendSurveyMail } from '../../../services/sdkService';
|
||||
import { treatRoleName, taflush, sendSurveyMail, sendGiftCodeMail } from '../../../services/sdkService';
|
||||
import { getServerMainten, setServerMainten, stopServerMainten } from '../../../services/gmService';
|
||||
import { errlogger } from '../../../util/logger';
|
||||
import { setApiIsClose } from '../../../services/chatService';
|
||||
@@ -136,6 +136,15 @@ export class RoleRemote {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public async sendGiftCodeMail(message: string) {
|
||||
try {
|
||||
await sendGiftCodeMail(message);
|
||||
} catch(e) {
|
||||
errlogger.error(`remote ${__filename} \n ${e.stack}`);
|
||||
}
|
||||
}
|
||||
|
||||
public async setApiIsClose(isClose: boolean) {
|
||||
try {
|
||||
setApiIsClose(isClose);
|
||||
|
||||
@@ -40,7 +40,7 @@ import { getGuideGachaData } from './gachaService';
|
||||
import { getPopNoticeData } from './popNoticeService';
|
||||
import { _getActivities, _getActivitiesByServerId, _getActivitiesByType, _getActivityById } from './activityRemoteService';
|
||||
import { getGroupShopDataShow } from './groupShopService';
|
||||
import { getBindPhoneDataShow } from './bindPhoneService';
|
||||
import { getAllSnsLinkDataShow } from './bindPhoneService';
|
||||
import { getPlayerForgeDataShow } from './forgeService';
|
||||
import { getPlayerMiniGameDataShow } from './miniGameService';
|
||||
import { getWeeklyFundDataShow } from './weeklyFundService';
|
||||
@@ -233,7 +233,7 @@ export async function getActivity(serverId: number, roleId: string, uid: number,
|
||||
}
|
||||
case ACTIVITY_TYPE.BIND_PHONE:
|
||||
{
|
||||
activityData = await getBindPhoneDataShow(activityId, roleId, serverId, uid);
|
||||
activityData = await getAllSnsLinkDataShow(activityId, roleId, serverId, uid);
|
||||
break
|
||||
}
|
||||
case ACTIVITY_TYPE.FORGE:
|
||||
@@ -266,7 +266,7 @@ export async function getActivity(serverId: number, roleId: string, uid: number,
|
||||
}
|
||||
return activityData;
|
||||
} catch(e) {
|
||||
console.log('activity error', activityId, activityType);
|
||||
console.log('activity error', e, activityId, activityType);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,57 @@
|
||||
import { ACTIVITY_TYPE } from '../../consts';
|
||||
import { ActivityModel, ActivityModelType } from '../../db/Activity';
|
||||
import { isNumber } from 'underscore';
|
||||
import { ACTIVITY_TYPE, BIND_PHONE_STATUS, PUBLIC_ACCOUNT_GIFT, PUSH_ROUTE, SDK_37_CONST, SNS_LINK_TYPE } from '../../consts';
|
||||
import { ActivityModelType } from '../../db/Activity';
|
||||
import { ActivityBindPhoneRewardModel } from '../../db/ActivityBindPhoneReward';
|
||||
import { ActivityDailyChallengesModel, ActivityDailyChallengesModelType } from '../../db/ActivityDailyChallenges';
|
||||
import { ActivityPublicAccountCodeModel } from '../../db/ActivityPublicAccountCode';
|
||||
import { LinkModel } from '../../db/Link';
|
||||
import { RoleModel } from '../../db/Role';
|
||||
import { ServerlistModel } from '../../db/Serverlist';
|
||||
import { UserModel } from '../../db/User';
|
||||
import { UserModel, UserType } from '../../db/User';
|
||||
import { BindPhoneData } from '../../domain/activityField/bindPhoneField';
|
||||
import { DailyChallengesData } from '../../domain/activityField/dailyChallengesField';
|
||||
import { getRoleCreateTime, getServerCreateTime } from '../redisService';
|
||||
import { getActivitiesByType, getActivityById } from './activityService';
|
||||
import { aes128Encrypt } from '../../pubUtils/util';
|
||||
import { getOnlineRoleByUserCode, getRedis, getRoleCreateTime, getServerCreateTime } from '../redisService';
|
||||
import { getActivityById } from './activityService';
|
||||
import { sendMessageToUserWithSuc } from '../pushService';
|
||||
|
||||
|
||||
/**
|
||||
* 获取活动数据
|
||||
* 绑定手机相关数据
|
||||
*
|
||||
* @param {number} serverId 区Id
|
||||
* @param {number} activityId 活动Id
|
||||
* @param {string} roleId 角色Id
|
||||
*
|
||||
*/
|
||||
export async function getAllSnsLinkData(activityId: number, roleId: string, serverId: number, uid: number) {
|
||||
|
||||
let activityData: ActivityModelType = await getActivityById(activityId);
|
||||
if(!activityData || activityData.type != ACTIVITY_TYPE.BIND_PHONE) return null;
|
||||
|
||||
let createTime = await getRoleCreateTime(roleId);
|
||||
let serverTime = await getServerCreateTime(serverId);
|
||||
let playerData = new BindPhoneData(activityData, createTime, serverTime);
|
||||
|
||||
let links = await LinkModel.findByServerId(serverId);
|
||||
playerData.setLinks(links);
|
||||
|
||||
let user: UserType;
|
||||
if(playerData.bindPhone) {
|
||||
if(!user) user = await UserModel.findUserByUid(uid);
|
||||
let receiveRec = await ActivityBindPhoneRewardModel.findByUid(activityId, uid);
|
||||
playerData.bindPhone.setBindPhoneStatus(user, receiveRec);
|
||||
}
|
||||
if(playerData.wxPublicAccount) {
|
||||
if(!user) user = await UserModel.findUserByUid(uid);
|
||||
if(!user.channelInfo) return null;
|
||||
let giftCode = encodeGiftCode(roleId, serverId, user.channelInfo.uid, user.channelInfo.platformAppid, user.channelInfo.childGameId, activityId);
|
||||
playerData.wxPublicAccount.setEncodeGiftCode(giftCode);
|
||||
let playerRecord = await ActivityPublicAccountCodeModel.findByChannel(activityId, user.channelId);
|
||||
if(playerRecord) playerData.wxPublicAccount.setPlayerRecord(playerRecord);
|
||||
}
|
||||
|
||||
return playerData;
|
||||
}
|
||||
|
||||
/**
|
||||
* 绑定手机相关数据
|
||||
*
|
||||
* @param {number} serverId 区Id
|
||||
* @param {number} activityId 活动Id
|
||||
@@ -32,10 +70,42 @@ export async function getBindPhoneData(activityId: number, roleId: string, serve
|
||||
let links = await LinkModel.findByServerId(serverId);
|
||||
playerData.setLinks(links);
|
||||
|
||||
let user: UserType;
|
||||
if(playerData.bindPhone) {
|
||||
let user = await UserModel.findUserByUid(uid);
|
||||
if(!user) user = await UserModel.findUserByUid(uid);
|
||||
let receiveRec = await ActivityBindPhoneRewardModel.findByUid(activityId, uid);
|
||||
playerData.setBindPhoneStatus(user, receiveRec);
|
||||
playerData.bindPhone.setBindPhoneStatus(user, receiveRec);
|
||||
}
|
||||
|
||||
return playerData;
|
||||
}
|
||||
|
||||
/**
|
||||
* 微信公众号
|
||||
*
|
||||
* @param {number} serverId 区Id
|
||||
* @param {number} activityId 活动Id
|
||||
* @param {string} roleId 角色Id
|
||||
*
|
||||
*/
|
||||
export async function getPublicAccountData(activityId: number, roleId: string, serverId: number, user: UserType) {
|
||||
|
||||
let activityData: ActivityModelType = await getActivityById(activityId);
|
||||
if(!activityData || activityData.type != ACTIVITY_TYPE.BIND_PHONE) return null;
|
||||
|
||||
let createTime = await getRoleCreateTime(roleId);
|
||||
let serverTime = await getServerCreateTime(serverId);
|
||||
let playerData = new BindPhoneData(activityData, createTime, serverTime);
|
||||
|
||||
let links = await LinkModel.findByServerId(serverId);
|
||||
playerData.setLinks(links);
|
||||
|
||||
if(playerData.wxPublicAccount) {
|
||||
if(!user.channelInfo) return null;
|
||||
let giftCode = encodeGiftCode(roleId, serverId, user.channelInfo.uid, user.channelInfo.platformAppid, user.channelInfo.childGameId, activityId);
|
||||
playerData.wxPublicAccount.setEncodeGiftCode(giftCode);
|
||||
let playerRecord = await ActivityPublicAccountCodeModel.findByChannel(activityId, user.channelId);
|
||||
if(playerRecord) playerData.wxPublicAccount.setPlayerRecord(playerRecord);
|
||||
}
|
||||
|
||||
return playerData;
|
||||
@@ -50,12 +120,28 @@ export async function getBindPhoneData(activityId: number, roleId: string, serve
|
||||
* @param {string} roleId 角色Id
|
||||
*
|
||||
*/
|
||||
export async function getBindPhoneDataShow(activityId: number, roleId: string, serverId: number, uid: number) {
|
||||
let playerData = await getBindPhoneData(activityId, roleId, serverId, uid);
|
||||
export async function getAllSnsLinkDataShow(activityId: number, roleId: string, serverId: number, uid: number) {
|
||||
let playerData = await getAllSnsLinkData(activityId, roleId, serverId, uid);
|
||||
if(playerData && playerData.canShow && playerData.canShow()) {
|
||||
return playerData.getShowResult();
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
function encodeGiftCode(roleId: string, serverId: number, uid: number, pid: string, gid: string, activityId: number) {
|
||||
let encodeResult = aes128Encrypt(`${roleId}|${serverId}|${uid}|${pid}|${gid}|${PUBLIC_ACCOUNT_GIFT}${activityId}|${SDK_37_CONST.GIFT_GAME_ID}`, SDK_37_CONST.PUBLIC_GIFT_KEY);
|
||||
return `FS${encodeResult}`;
|
||||
}
|
||||
|
||||
export async function sendPublicAccountGift(message: string) {
|
||||
let [_activityId, userCode, channelId] = message?.split('|')||[];
|
||||
let activityId = parseInt(_activityId);
|
||||
if(!isNumber(activityId) || !userCode || !channelId) return;
|
||||
|
||||
let onlineRoleId = await getOnlineRoleByUserCode(userCode);
|
||||
console.log('##### sendPublicAccountGift', message, userCode, onlineRoleId);
|
||||
if (!!onlineRoleId) { // 在线,推送消息
|
||||
let playerRecord = await ActivityPublicAccountCodeModel.findByChannel(activityId, channelId);
|
||||
await sendMessageToUserWithSuc(onlineRoleId, PUSH_ROUTE.PUBLIC_ACCOUNT_GIFT, { activityId, type: SNS_LINK_TYPE.WX_PUBLIC_ACCOUNT, status: playerRecord.hasReceived? BIND_PHONE_STATUS.HAS_BIND: BIND_PHONE_STATUS.RECEIVED });
|
||||
}
|
||||
}
|
||||
@@ -659,7 +659,9 @@ export async function redisSubScribe() {
|
||||
let treatGuildChannel = getRedisSubChannel(REDIS_KEY.TREAT_GUILD_CHANNEL, env);
|
||||
let surveyChannel = getRedisSubChannel(REDIS_KEY.SURVEY_CHANNEL, env);
|
||||
let userChannel = getRedisSubChannel(REDIS_KEY.USER_CHANNEL, env);
|
||||
await redisClientPub().subscribeAsync(payChannel, treatRoleChannel, treatGuildChannel, refundChannel, surveyChannel, userChannel);
|
||||
let publicAccountChannel = getRedisSubChannel(REDIS_KEY.PUBLIC_ACCOUNT_GIFT, env);
|
||||
let sendGiftCodeChannel = getRedisSubChannel(REDIS_KEY.SEND_GIFT_CODE, env);
|
||||
await redisClientPub().subscribeAsync(payChannel, treatRoleChannel, treatGuildChannel, refundChannel, surveyChannel, userChannel, publicAccountChannel, sendGiftCodeChannel);
|
||||
redisClientPub().on('message', (channel, message) => {
|
||||
console.log('**********redisSubScribe*******')
|
||||
console.log('channel: ', channel, payChannel);
|
||||
@@ -687,6 +689,15 @@ export async function redisSubScribe() {
|
||||
} else if(channel == userChannel) {
|
||||
let [sid, roleId] = (message||'').split('|');
|
||||
if(!!sid && !!roleId) pinus.app.rpc.connector.connectorRemote.remoteLogin.toServer(sid, roleId);
|
||||
} else if (channel == publicAccountChannel) {
|
||||
let servers = pinus.app.getServersByType('activity');
|
||||
let server = getRandSingleEelm(servers);
|
||||
pinus.app.rpc.activity.activityRemote.sendPublicAccountGift.toServer(server.id, message);
|
||||
} else if (channel == sendGiftCodeChannel) {
|
||||
let servers = pinus.app.getServersByType('role');
|
||||
let server = getRandSingleEelm(servers);
|
||||
pinus.app.rpc.role.roleRemote.sendGiftCodeMail.toServer(server.id, message);
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -22,6 +22,8 @@ import { sendMessageToUserWithSuc } from "./pushService";
|
||||
import { GuildLeader } from "../domain/rank";
|
||||
import { initTaLoggingMode } from "./sdk/ta";
|
||||
import { DicPushMessage } from "../pubUtils/dictionary/DicPushMessage";
|
||||
import { GiftCodeModel } from "../db/GiftCode";
|
||||
import { GiftCodeDetailModel } from "../db/GiftCodeDetail";
|
||||
|
||||
// 检查私聊是否合法
|
||||
|
||||
@@ -319,4 +321,18 @@ export async function sendSurveyMail(code: string) {
|
||||
await sendMailByContent(MAIL_TYPE.SEND_MAIL, rec.roleId, { goods: survey.reward, params: [survey.mailContent] });
|
||||
await sendMessageToUserWithSuc(rec.roleId, PUSH_ROUTE.DELETE_SURVEY, { code: survey.code });
|
||||
rec = await SurveyRecModel.send(rec.code);
|
||||
}
|
||||
|
||||
export async function sendGiftCodeMail(message: string) {
|
||||
console.log('***** sendSurveyMail', message);
|
||||
let [roleId, _giftId] = message.split('|');
|
||||
let giftId = parseInt(_giftId);
|
||||
if(isNaN(giftId) || !roleId) return false;
|
||||
let giftCode = await GiftCodeModel.findByGiftId(giftId);
|
||||
if(!giftCode) {
|
||||
console.log('***** sendSurveyMail giftId not found', giftId);
|
||||
return false;
|
||||
}
|
||||
|
||||
await sendMailByContent(MAIL_TYPE.SEND_MAIL, roleId, { goods: giftCode.goods, params: [''] });
|
||||
}
|
||||
Reference in New Issue
Block a user