Compare commits

...

4 Commits

3 changed files with 91 additions and 53 deletions

View File

@ -3,16 +3,21 @@ import { ReqUpdateHbzbCrossUser, ResUpdateHbzbCrossUser } from "../../cross/prot
/**更新跨服数据库里,黑帮争霸的玩家数据 */ /**更新跨服数据库里,黑帮争霸的玩家数据 */
export default async function (call: ApiCall<ReqUpdateHbzbCrossUser, ResUpdateHbzbCrossUser>) { export default async function (call: ApiCall<ReqUpdateHbzbCrossUser, ResUpdateHbzbCrossUser>) {
let setData = { let setData: any = {
"data": { "data": {
player: call.req.user.player, player: call.req.user.player,
roles: call.req.user.roles, roles: call.req.user.roles,
uid: call.req.uid uid: call.req.uid
}, },
};
if (call.req.isNew) {
setData = {
...setData,
"jifen": -999999, "jifen": -999999,
"rank": -999999, "rank": -999999,
"zbsgroup": "" "zbsgroup": ""
}; }
}
G.mongodb.collection('hbzb_user_cross').updateOne({uid: setData.data.uid}, {$set: setData}, {upsert: true}); G.mongodb.collection('hbzb_user_cross').updateOne({uid: setData.data.uid}, {$set: setData}, {upsert: true});
call.succ({}); call.succ({});
} }

View File

@ -9,10 +9,8 @@ export default async function (call: ApiCall<ReqOpen, ResOpen>) {
let dbData = await getHbzbData(call.uid); let dbData = await getHbzbData(call.uid);
let data: typeof dbData.data = dbData?.data || {} as any; let data: typeof dbData.data = dbData?.data || {} as any;
if (dbData == null) {
//如果没有,则同步到跨服 //如果没有,则同步到跨服
await updateHbzbCrossUser(await call.conn.getDefaultFightData(), true); await updateHbzbCrossUser(await call.conn.getDefaultFightData(), dbData == null);
}
if (!data.refreshTime || data.refreshTime < PublicShared.getToDayZeroTime()) { if (!data.refreshTime || data.refreshTime < PublicShared.getToDayZeroTime()) {
data.winNum = 0; data.winNum = 0;
@ -32,7 +30,9 @@ export default async function (call: ApiCall<ReqOpen, ResOpen>) {
return call.errorCode(-4) return call.errorCode(-4)
} }
if (callRes.res.enemy.length) if (callRes.res.enemy.length)
data.enemy = callRes.res.enemy.map(e => { return { ...e, result: null }; }); data.enemy = callRes.res.enemy.map(e => {
return {...e, result: null};
});
} }
G.mongodb.cPlayerInfo('hbzb').updateOne( G.mongodb.cPlayerInfo('hbzb').updateOne(

View File

@ -21,34 +21,7 @@ export default async function (call: ApiCall<ReqGetList, ResGetList>) {
color[heroCon[v.heroId].colour] += 1; color[heroCon[v.heroId].colour] += 1;
}); });
// 修复配件数据 await checkDataAndFix(call, list)
let peijianids = [];
Object.values(list).map(hero => {
hero.peijian && Object.values(hero.peijian).map(
i => peijianids.push(G.mongodb.conversionId(PeijianShared.fmt(i)._id))
)
});
let peijians = (await G.mongodb.collection("peijian").find(
{uid: call.uid, _id: {$in: peijianids}}, {projection: {_id: 1}}
).toArray()).map(temp => G.mongodb.conversionId(temp._id));
let changes = {};
Object.values(list).map(hero => {
for (let pos in hero.peijian) {
if (!peijians.includes(PeijianShared.fmt(hero.peijian[pos])._id)) {
hero.peijian[pos] = "";
changes[hero._id] = hero.peijian;
}
}
})
for (let oid in changes) {
// 修复数据
G.mongodb.collection("hero").updateOne(
G.mongodb.conversionIdObj({_id: oid}), {$set: {peijian: changes[oid]}}
)
}
// 记录玩家最大等级,颜色相关数据 注册任务用 // 记录玩家最大等级,颜色相关数据 注册任务用
await G.mongodb.collection('playerInfo', 'usertasklog').updateOne({uid: call.conn.uid, type: 'usertasklog'}, await G.mongodb.collection('playerInfo', 'usertasklog').updateOne({uid: call.conn.uid, type: 'usertasklog'},
@ -69,3 +42,63 @@ export default async function (call: ApiCall<ReqGetList, ResGetList>) {
gbzj: (await G.mongodb.cPlayerInfo('gbzj').findOne({uid: call.uid, type: 'gbzj'}))?.rec || {} gbzj: (await G.mongodb.cPlayerInfo('gbzj').findOne({uid: call.uid, type: 'gbzj'}))?.rec || {}
}); });
} }
/**
*
* @param call
* @param list
*/
async function checkDataAndFix(call: ApiCall, list: ResGetList['list']) {
try {
// 修复配件数据
let peijianids = [];
Object.values(list).map(hero => {
hero.peijian && Object.values(hero.peijian).map(
i => peijianids.push(G.mongodb.conversionId(PeijianShared.fmt(i)._id))
)
});
let peijians = (await G.mongodb.collection("peijian").find(
{uid: call.uid, _id: {$in: peijianids}}, {projection: {_id: 1}}
).toArray()).map(temp => G.mongodb.conversionId(temp._id));
let shiwuIds = R.flatten(R.values(list).map(hero => R.values(hero.shiwu).map(i => G.mongodb.conversionId(i._id))))
let shiwus = (await G.mongodb.collection("shiwu").find(
{uid: call.uid, _id: {$in: shiwuIds}}, {projection: {_id: 1}}
).toArray()).map(i => G.mongodb.conversionId(i._id));
let peijianChanges = {};
let shiwuChanges = {};
Object.values(list).map(hero => {
for (let pos in hero.peijian) {
if (!peijians.includes(PeijianShared.fmt(hero.peijian[pos])._id)) {
hero.peijian[pos] = "";
peijianChanges[hero._id] = hero.peijian;
}
}
for (let pos in hero.shiwu) {
if (!shiwus.includes(hero.shiwu[pos]._id)) {
hero.shiwu = R.omit([pos], hero.shiwu)
shiwuChanges[hero._id] = hero.shiwu;
}
}
})
for (let oid in peijianChanges) {
// 修复数据
G.mongodb.collection("hero").updateOne(
G.mongodb.conversionIdObj({_id: oid}), {$set: {peijian: peijianChanges[oid]}}
)
}
for (let oid in shiwuChanges) {
// 修复数据
G.mongodb.collection("hero").updateOne(
G.mongodb.conversionIdObj({_id: oid}), {$set: {shiwu: shiwuChanges[oid]}}
)
}
} catch (e) {
console.log('======修复英雄配件和饰物报错====',e)
}
}