日志:添加玩家日志
This commit is contained in:
@@ -7,7 +7,7 @@ import { Application, HandlerService, pinus, } from 'pinus';
|
||||
import { FrontendSession } from 'pinus';
|
||||
import { HeroModel } from './../../../db/Hero';
|
||||
import { genCode, generateStr, resResult } from '../../../pubUtils/util';
|
||||
import { COM_BTL_QUALITY, HERO_SELECT, DEBUG_MAGIC_WORD, REDIS_KEY, TASK_TYPE, ENTERY_ROLE_PICK, COUNTER, DEFAULT_LV, TA_USERSET_TYPE } from '../../../consts';
|
||||
import { COM_BTL_QUALITY, HERO_SELECT, DEBUG_MAGIC_WORD, REDIS_KEY, TASK_TYPE, ENTERY_ROLE_PICK, COUNTER, DEFAULT_LV, TA_USERSET_TYPE, LOG_TYPE } from '../../../consts';
|
||||
import { getAp } from '../../../services/actionPointService';
|
||||
import { ItemModel } from '../../../db/Item';
|
||||
import { SkinModel } from '../../../db/Skin';
|
||||
@@ -25,6 +25,7 @@ import { setComBtlOnUserLeave } from '../../../services/comBattleService';
|
||||
import Counter from '../../../db/Counter';
|
||||
import { getExpByLv } from '../../../pubUtils/data';
|
||||
import { reportTAUserSet } from '../../../services/sdkService';
|
||||
import { saveLoginAndOutLog } from '../../../pubUtils/logUtil';
|
||||
|
||||
export default function (app: Application) {
|
||||
new HandlerService(app, {});
|
||||
@@ -69,6 +70,7 @@ export class EntryHandler {
|
||||
let serverName = this.app.getServerId();
|
||||
await roleLogin(role.roleId, user.userCode, serverName, user.pkgName); // 保存在线用户
|
||||
await this.addSession(role, session);
|
||||
saveLoginAndOutLog(LOG_TYPE.LOGIN, session);
|
||||
|
||||
// put user into channel
|
||||
// console.log(JSON.stringify(self.app.rpc.battle))
|
||||
@@ -224,6 +226,7 @@ export class EntryHandler {
|
||||
if(teamCode) { // 如果有寻宝中的队伍,那么等于战败
|
||||
setComBtlOnUserLeave(roleId, teamCode)
|
||||
}
|
||||
saveLoginAndOutLog(LOG_TYPE.LOGINOUT, session);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -342,10 +342,10 @@ function randomQuestion(num: number) {
|
||||
let rid:Array<number> = [], result = [];
|
||||
while(num > 0) {
|
||||
let dicQuestion = getRandSingleEelm(questions);
|
||||
let {id, question, answer, correct} = dicQuestion;
|
||||
let {id, question, answer } = dicQuestion;
|
||||
if(rid.includes(id)) continue;
|
||||
rid.push(id);
|
||||
result.push({id, question, answer, correct});
|
||||
result.push({id, question, answer});
|
||||
num--;
|
||||
}
|
||||
return result;
|
||||
|
||||
@@ -27,6 +27,7 @@ import { checkOrderALI } from './pay/aliPay';
|
||||
import { getRoleOnlineInfo } from './redisService';
|
||||
import { PayCallback37Data } from '../domain/sdk';
|
||||
import { reportTAEvent, reportTAUserSet } from './sdkService';
|
||||
import { savePayLog } from '../pubUtils/logUtil';
|
||||
|
||||
|
||||
/**
|
||||
@@ -160,6 +161,7 @@ export async function settleOrder(order: UserOrderModelType, serverId: number, s
|
||||
if (result.code !== 0) {//结算失败
|
||||
console.log(`支付失败..... ${JSON.stringify(result)}`)
|
||||
reportTAEvent(order.roleId, TA_EVENT.RECHARGE_FAIL, { pay_id: order.localOrderID, charge_id: order.productID, pay_name: order.message, pay_amount: order.price, pay_channel: order.payType })
|
||||
savePayLog(order);
|
||||
return resResult(result);
|
||||
}
|
||||
//推送
|
||||
@@ -181,7 +183,7 @@ export async function settleOrder(order: UserOrderModelType, serverId: number, s
|
||||
reportTAUserSet(TA_USERSET_TYPE.SET_ONCE, order.roleId, { first_pay_time: new Date() });
|
||||
reportTAUserSet(TA_USERSET_TYPE.SET, order.roleId, { last_pay_time: new Date() });
|
||||
reportTAUserSet(TA_USERSET_TYPE.ADD, order.roleId, { total_revenue: order.price });
|
||||
|
||||
savePayLog(order);
|
||||
return result.data;
|
||||
}
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ import { SkinUpdate } from '../db/Skin';
|
||||
import { getInitHeroById } from './roleService';
|
||||
import { getActivities } from './activity/activityService';
|
||||
import { reportTAEvent, reportTAUserSet } from './sdkService';
|
||||
import { saveCoinChangeLog, saveFigureInfoLog, saveGoldChangeLog, saveItemChangeLog } from '../pubUtils/logUtil';
|
||||
|
||||
export class CheckMeterial {
|
||||
private roleId: string;
|
||||
@@ -120,6 +121,7 @@ export async function handleCost(roleId: string, sid: string, goods: Array<ItemI
|
||||
let { hasError, result } = await ItemModel.decreaseItems(roleId, items);
|
||||
if (hasError) return false;
|
||||
pinus.app.get('channelService').pushMessageByUids('onItemUpdate', resResult(STATUS.SUCCESS, { goods: result.map(cur => ({...cur, reason })) }), uids);
|
||||
saveItemChangeLog(roleId, result, reason);
|
||||
}
|
||||
|
||||
//删除装备
|
||||
@@ -146,6 +148,7 @@ export async function handleCost(roleId: string, sid: string, goods: Array<ItemI
|
||||
|
||||
|
||||
let equips = await EquipModel.deleteEquips(roleId, equipSeqIds);
|
||||
saveItemChangeLog(roleId, equips.map(equip => ({ id: equip.id, count: equip.count, inc: -1 })), reason);
|
||||
pinus.app.get('channelService').pushMessageByUids('onEquipDel', resResult(STATUS.SUCCESS, { equips: equips.map(equip => ({ seqId: equip.seqId, id: equip.id, inc: -1, reason })) }), uids);
|
||||
}
|
||||
|
||||
@@ -161,10 +164,12 @@ export async function handleCost(roleId: string, sid: string, goods: Array<ItemI
|
||||
if(costGold > 0) {
|
||||
reportTAEvent(roleId, TA_EVENT.ITEM_CONSUME, getGoldEventProperties(costGold, role.gold, reason));
|
||||
reportTAUserSet(TA_USERSET_TYPE.SET, roleId, { current_gold: role.gold });
|
||||
saveGoldChangeLog(roleId, role.gold, -1 * costGold, reason);
|
||||
}
|
||||
if(costCoin > 0) {
|
||||
reportTAEvent(roleId, TA_EVENT.ITEM_CONSUME, getCoinEventProperties(costCoin, role.coin, reason));
|
||||
reportTAUserSet(TA_USERSET_TYPE.SET, roleId, { current_coin: role.coin });
|
||||
saveCoinChangeLog(roleId, role.coin, -1 * costCoin, reason);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -205,6 +210,7 @@ export async function addItems(roleId: string, roleName: string, sid: string, go
|
||||
if (equipInfos.length > 0) {
|
||||
let { serverId } = await RoleModel.findByRoleId(roleId);
|
||||
await checkActivityTask(serverId, sid, roleId, TASK_TYPE.EQUIP_QUALITY_COUNT, equipInfos.length, { equips: equipInfos.map(obj => { return { quality: obj.quality } }) })
|
||||
saveItemChangeLog(roleId, equipInfos, reason);
|
||||
}
|
||||
// 发邮件的
|
||||
if(mailEquips.length > 0) {
|
||||
@@ -219,8 +225,10 @@ export async function addItems(roleId: string, roleName: string, sid: string, go
|
||||
showItems.push({ id: item.id, count: item.count });
|
||||
}
|
||||
//背包除去装备推送
|
||||
if (!!itemInfos.length)
|
||||
if (!!itemInfos.length) {
|
||||
pinus.app.get('channelService').pushMessageByUids('onItemUpdate', resResult(STATUS.SUCCESS, { goods: itemInfos }), uids);
|
||||
saveItemChangeLog(roleId, itemInfos, reason);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -239,6 +247,7 @@ export async function addItems(roleId: string, roleName: string, sid: string, go
|
||||
});
|
||||
reportTAEvent(roleId, TA_EVENT.ITEM_GET, getGoldEventProperties(incGold, role.gold, reason));
|
||||
reportTAUserSet(TA_USERSET_TYPE.SET, roleId, { current_gold: role.gold });
|
||||
saveGoldChangeLog(roleId, role.gold, incGold, reason );
|
||||
}
|
||||
if(coin.length > 0) {
|
||||
coin.forEach(count => {
|
||||
@@ -246,6 +255,7 @@ export async function addItems(roleId: string, roleName: string, sid: string, go
|
||||
});
|
||||
reportTAEvent(roleId, TA_EVENT.ITEM_GET, getCoinEventProperties(incCoin, role.coin, reason));
|
||||
reportTAUserSet(TA_USERSET_TYPE.SET, roleId, { current_coin: role.coin });
|
||||
saveCoinChangeLog(roleId, role.coin, incCoin, reason);
|
||||
}
|
||||
if(ap > 0) {
|
||||
showItems.push(getApObject(ap));
|
||||
@@ -256,7 +266,7 @@ export async function addItems(roleId: string, roleName: string, sid: string, go
|
||||
let figureInfos:{ heads: Figure[], frames: Figure[], spines: Figure[] }[] = []; // 头像变化推送信息
|
||||
if(skins.length > 0) {
|
||||
let heroskins: {skins: HeroSkin[], hid: number}[] = []; // 皮肤推送信息
|
||||
let skinInfos: {id: number, hid: number, inc: number, reason: number }[] = [];
|
||||
let skinInfos: {id: number, hid: number, count: number, inc: number, reason: number }[] = [];
|
||||
let calAllHeroResult = undefined; // 全局战力变化推送
|
||||
|
||||
for (let skinId of skins) {//皮肤推送
|
||||
@@ -268,11 +278,12 @@ export async function addItems(roleId: string, roleName: string, sid: string, go
|
||||
heroskins.push({ skins: result.hero.skins, hid: result.hero.hid });
|
||||
if(result.calAllHeroResult) calAllHeroResult = result.calAllHeroResult;
|
||||
}
|
||||
skinInfos.push({ id: skinId, hid: result.hero?.hid||0, inc: 1, reason })
|
||||
skinInfos.push({ id: skinId, hid: result.hero?.hid||0, count: 1, inc: 1, reason })
|
||||
}
|
||||
}
|
||||
if (!!skinInfos.length) {
|
||||
pushHeroSkinMsg(heroskins, skinInfos, uids); // 推送onHeroSkinChange
|
||||
saveItemChangeLog(roleId, skinInfos, reason);
|
||||
}
|
||||
// 推送全局加成信息
|
||||
if(calAllHeroResult) await pushCalAllHeroCe(roleId, sid, calAllHeroResult);
|
||||
@@ -291,6 +302,7 @@ export async function addItems(roleId: string, roleName: string, sid: string, go
|
||||
if(!!figureInfos && figureInfos.length > 0) {
|
||||
for(let figureInfo of figureInfos) {
|
||||
pinus.app.get('channelService').pushMessageByUids('onHeadChange', resResult(STATUS.SUCCESS, { ...figureInfo }), uids);
|
||||
saveFigureInfoLog(roleId, figureInfo, reason)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,9 @@ export default class UserLog extends BaseModel {
|
||||
@prop({ required: true })
|
||||
uid: number; // uid
|
||||
|
||||
@prop({ required: true })
|
||||
serverId: number; // 小区id
|
||||
|
||||
@prop({ required: true })
|
||||
roleId: string; // 角色id
|
||||
|
||||
@@ -40,12 +43,12 @@ export default class UserLog extends BaseModel {
|
||||
@prop({ required: false })
|
||||
ceChangeReason: number; // 战力变化原因
|
||||
|
||||
@prop({ required: false })
|
||||
ceChangeReasonInfo: string; // 战力变化原因信息,如武将id等
|
||||
@prop({ required: false, type: Number })
|
||||
ceChangeIds: number[]; // 战力变化原因信息,如武将id等
|
||||
|
||||
// 充值相关
|
||||
@prop({ required: false })
|
||||
productId: string; // 商品id
|
||||
productID: string; // 商品id
|
||||
|
||||
@prop({ required: false })
|
||||
productName: string; // 商品名字
|
||||
@@ -57,7 +60,10 @@ export default class UserLog extends BaseModel {
|
||||
isYuanbao: boolean; // 是否为代币
|
||||
|
||||
@prop({ required: false })
|
||||
localOrderId: string; // 订单id
|
||||
orderID: string; // 平台订单id
|
||||
|
||||
@prop({ required: false })
|
||||
localOrderID: string; // 订单id
|
||||
|
||||
@prop({ required: false })
|
||||
totalPay: number; // 总充值金额
|
||||
@@ -75,9 +81,6 @@ export default class UserLog extends BaseModel {
|
||||
@prop({ required: false })
|
||||
itid: number; // 道具类型
|
||||
|
||||
@prop({ required: false })
|
||||
itemChangeModule: string; // 道具变更模块
|
||||
|
||||
@prop({ required: false })
|
||||
itemChangeReason: number; // 道具变更来源
|
||||
|
||||
@@ -96,9 +99,15 @@ export default class UserLog extends BaseModel {
|
||||
|
||||
@prop({ required: false })
|
||||
mailSendName: string; // 邮件发件人
|
||||
|
||||
|
||||
public static async createRecord(params: UserLogModelTypeParam) {
|
||||
const r = await UserLogModel.insertMany(params);
|
||||
return r;
|
||||
}
|
||||
}
|
||||
|
||||
export const UserLogModel = getModelForClass(UserLog);
|
||||
export let UserLogModel = getModelForClass(UserLog);
|
||||
|
||||
export interface UserLogModelType extends Pick<DocumentType<UserLog>, keyof UserLog> { }
|
||||
export type UserLogModelTypeParam = Partial<UserLogModelType>; // 将所有字段变成可选项
|
||||
@@ -224,7 +224,8 @@ export class Figure {
|
||||
unlocked: boolean = false; // 是否已解锁
|
||||
|
||||
// 埋点用
|
||||
inc?: number;
|
||||
count = 1;
|
||||
inc = 1;
|
||||
reason?: number;
|
||||
|
||||
public get status () { // 虚拟字段status,当前头像是否已经解锁
|
||||
|
||||
@@ -62,7 +62,7 @@ export async function addSkin(roleId: string, roleName: string, skinId: number,
|
||||
}
|
||||
|
||||
export async function addBags(roleId: string, roleName: string, datas: { id: number, count: number }[], reason: number) {
|
||||
let items: { id: number, count: number }[] = [];
|
||||
let items: { id: number, count: number, inc: number }[] = [];
|
||||
for(let data of datas) {
|
||||
let item = await addBag(roleId, roleName, data, reason);
|
||||
items.push(item)
|
||||
|
||||
@@ -1,3 +1,107 @@
|
||||
export function saveUserLog() {
|
||||
import { ACTIVITY_TYPE, CURRENCY_BY_TYPE, CURRENCY_TYPE, HERO_SYSTEM_TYPE, LOG_TYPE } from "../consts";
|
||||
import { RoleModel, RoleType, RoleUpdate } from "../db/Role";
|
||||
import { UserLogModel } from "../db/UserLog";
|
||||
import { UserOrderModelType } from "../db/UserOrder";
|
||||
import { Figure } from "../domain/dbGeneral";
|
||||
import { MailParam } from "../domain/roleField/mail";
|
||||
import { gameData } from "./data";
|
||||
|
||||
function getParamBySession(session: any) {
|
||||
let uid = session.get('userid');
|
||||
let roleId = session.get('roleId');
|
||||
let roleName = session.get('roleName');
|
||||
let ip = session.get('ip');
|
||||
let serverId = session.get('serverId');
|
||||
return { uid, roleId, roleName, ip, serverId };
|
||||
}
|
||||
|
||||
function getParamByRole(role: RoleType) {
|
||||
let uid = role.userInfo.uid;
|
||||
let roleId = role.roleId;
|
||||
let roleName = role.roleName;
|
||||
let serverId = role.serverId;
|
||||
return { uid, roleId, roleName, serverId };
|
||||
}
|
||||
|
||||
export async function saveLoginAndOutLog(type: LOG_TYPE, session: any) {
|
||||
try {
|
||||
let params = getParamBySession(session);
|
||||
await UserLogModel.createRecord({ type, ...params });
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
export async function saveCeChangeLog(role: RoleType, inc: number, count: number, type: number, ids: number[]) {
|
||||
try {
|
||||
let params = getParamByRole(role);
|
||||
await UserLogModel.createRecord({ type: LOG_TYPE.CE_CHANGE, ...params, inc, count, ceChangeReason: type, ceChangeIds: ids });
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
export function getReCalRoleAttrIds(type: number, update: RoleUpdate, args: number[]) {
|
||||
if (type == HERO_SYSTEM_TYPE.TITLE) {
|
||||
return [update.title];
|
||||
} else {
|
||||
return args;
|
||||
}
|
||||
}
|
||||
|
||||
export async function savePayLog(order: UserOrderModelType) {
|
||||
try {
|
||||
let role = await RoleModel.findByRoleId(order.roleId, 'userInfo roleId roleName serverId');
|
||||
let params = getParamByRole(role);
|
||||
let { productID, message: productName, price, localOrderID, orderID, state } = order;
|
||||
let dicRmb = gameData.rmb.get(productID);
|
||||
let isYuanbao = dicRmb.type == ACTIVITY_TYPE.YUAN_BAO_SHOP;
|
||||
await UserLogModel.createRecord({ type: LOG_TYPE.PAY, ...params, productID, productName, price, isYuanbao, localOrderID, orderID, totalPay: role.totalPay, orderStatus: state });
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
export async function saveItemChangeLog(roleId: string, goods: { id: number, count: number, inc: number }[], reason: number) {
|
||||
try {
|
||||
let role = await RoleModel.findByRoleId(roleId, 'userInfo roleId roleName serverId');
|
||||
let params = getParamByRole(role);
|
||||
for (let { id, count, inc } of goods) {
|
||||
let dicGoods = gameData.goods.get(id);
|
||||
await UserLogModel.createRecord({ type: LOG_TYPE.ITEM_CHANGE, ...params, itemId: id, itemName: dicGoods.name, itid: dicGoods.itid, inc, count, itemChangeReason: reason })
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
export async function saveGoldChangeLog(roleId: string, count: number, inc: number, reason: number) {
|
||||
let id = CURRENCY_BY_TYPE.get(CURRENCY_TYPE.GOLD);
|
||||
return await saveItemChangeLog(roleId, [{ id, count, inc }], reason);
|
||||
}
|
||||
|
||||
export async function saveCoinChangeLog(roleId: string, count: number, inc: number, reason: number) {
|
||||
let id = CURRENCY_BY_TYPE.get(CURRENCY_TYPE.COIN);
|
||||
return await saveItemChangeLog(roleId, [{ id, count, inc }], reason);
|
||||
}
|
||||
|
||||
export async function saveFigureInfoLog(roleId: string, figureInfo: { heads: Figure[], frames: Figure[], spines: Figure[] }, reason: number) {
|
||||
try {
|
||||
await saveItemChangeLog(roleId, figureInfo.frames, reason);
|
||||
await saveItemChangeLog(roleId, figureInfo.heads, reason);
|
||||
await saveItemChangeLog(roleId, figureInfo.spines, reason);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
export async function saveMailLog(session: any, mails: MailParam[]) {
|
||||
try {
|
||||
let params = getParamBySession(session);
|
||||
for(let { id, sendName, title, content, goods } of mails) {
|
||||
await UserLogModel.createRecord({ type: LOG_TYPE.RECEIVE_MAIL, ...params, mailId: id, goods: goods, mailContent: content, mailSendName: sendName, mailTitle: title });
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,7 @@ import { findIndex } from 'underscore';
|
||||
import { GuildModel } from '../db/Guild';
|
||||
import { DicJob } from './dictionary/DicJob';
|
||||
import { DicSuit } from './dictionary/DicSuit';
|
||||
import { saveCeChangeLog } from './logUtil';
|
||||
|
||||
// 修改并下发战力
|
||||
export async function calPlayerCeAndSave(type: number, roleId: string, originHero: HeroType, update: HeroUpdate, args?: Array<number>) {
|
||||
@@ -54,6 +55,9 @@ export async function calPlayerCeAndSave(type: number, roleId: string, originHer
|
||||
ce: reduceCe(heroCe),
|
||||
incHeroCe: reduceCe(incCe),
|
||||
});
|
||||
|
||||
saveCeChangeLog(role, incCe, role.ce, type, [originHero.hid]);
|
||||
|
||||
return { pushHeros, role, topLineupCe, hero, guild, serverId }
|
||||
}
|
||||
|
||||
@@ -96,6 +100,8 @@ export async function reCalAllHeroCe(type: number, roleId: string, update: RoleU
|
||||
role = await RoleModel.updateRoleInfo(roleId, update);
|
||||
|
||||
let guild = await GuildModel.updateCe(roleId, allIncCe); // 公会更新战力
|
||||
|
||||
saveCeChangeLog(role, allIncCe, role.ce, type, args);
|
||||
return { role, pushHeros, ce: role.ce, topLineupCe: role.topLineupCe, guild, serverId: role.serverId, heros }
|
||||
|
||||
}
|
||||
|
||||
@@ -99,6 +99,7 @@ import { UserTaskRecModel } from '../db/UserTaskRec';
|
||||
import { WishPoolReportModel } from '../db/WishPoolReport';
|
||||
import { pick } from "underscore";
|
||||
import { HeroShowParam } from '../domain/roleField/hero';
|
||||
import { saveCeChangeLog } from "./logUtil";
|
||||
|
||||
// 储存在内存中的初始数据
|
||||
export function getInitRoleInfo() {
|
||||
@@ -208,6 +209,7 @@ export class UpdateHeroes {
|
||||
for(let { hid, incHeroCe } of this.pushHeroes) {
|
||||
await PvpDefenseModel.updateCe(this.roleId, hid, incHeroCe); // 更新pvp防守阵战力
|
||||
}
|
||||
saveCeChangeLog(this.role, this.incRoleCe, this.role.ce, HERO_SYSTEM_TYPE.INIT, this.pushHeroes.map(cur => cur.hid));
|
||||
}
|
||||
|
||||
public async updateRedisRank(Rank: any) {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user