Compare commits

..

No commits in common. "3450796bb732e2e469556acad85988f2c2713a6e" and "4ebe8ae338d24441af5b318cdc99c646ec6590a5" have entirely different histories.

View File

@ -1,31 +1,32 @@
import {ApiCall} from 'tsrpc'; import { ApiCall } from 'tsrpc';
import {ResOpen} from '../shared/protocols/tanxian/PtlOpen'; import { ResOpen } from '../shared/protocols/tanxian/PtlOpen';
import {TeQuanFun} from './tequan'; import { TeQuanFun } from './tequan';
type dataChange = Partial<ResOpen>; type dataChange = Partial<ResOpen>;
export class TanXianFun { export class TanXianFun {
/**修改探险数据 */ /**修改探险数据 */
static async changeData(call: ApiCall, change: dataChange) { static async changeData(call: ApiCall, change: dataChange) {
G.mongodb.collection('tanxian').updateOne({uid: call.uid}, {$set: {...change}});
G.mongodb.collection('tanxian').updateOne({ uid: call.uid }, { $set: { ...change } });
let data = await this.getData(call); let data = await this.getData(call);
Object.assign(data, change); Object.assign(data, change);
G.ioredis.setex(`tanxian:${call.uid}`, 600, JSON.stringify(data)); G.ioredis.set(`tanxian:${call.uid}`, JSON.stringify(data));
} }
/**获取探险数据 */ /**获取探险数据 */
static async getData(call: ApiCall, cache = true) { static async getData(call: ApiCall, cache = true) {
let cacheData = await G.ioredis.get(`tanxian:${call.uid}`); if(cache){
if (cacheData && cache) return JSON.parse(cacheData); let data = await G.ioredis.get(`tanxian:${call.uid}`);
let {_id, uid, ...data} = await G.mongodb.collection('tanxian').findOne({uid: call.uid}); if (data) return JSON.parse(data);
}
let { _id, uid, ...data } = await G.mongodb.collection('tanxian').findOne({ uid: call.uid });
if (!data.eventTime) { if (!data.eventTime) {
data.eventTime = G.time; data.eventTime = G.time;
G.mongodb.collection('tanxian').updateOne({uid: call.uid}, {$set: {eventTime: G.time}}); G.mongodb.collection('tanxian').updateOne({ uid: call.uid }, { $set: { eventTime: G.time } });
} }
G.ioredis.setex(`tanxian:${call.uid}`, 600, JSON.stringify(data)); await G.ioredis.set(`tanxian:${call.uid}`, JSON.stringify(data));
return data; return data;
} }
/**获取快速探险次数 */ /**获取快速探险次数 */
static async getFastGuaJiNum(call: ApiCall) { static async getFastGuaJiNum(call: ApiCall) {
let num = G.gc.tanxian_com.fastGuaJiNum + await TeQuanFun.getTxFreeNum(call); let num = G.gc.tanxian_com.fastGuaJiNum + await TeQuanFun.getTxFreeNum(call);
@ -37,10 +38,9 @@ export class TanXianFun {
} }
return num; return num;
} }
/**获取最后领取奖励的id与sort后的数组*/ /**获取最后领取奖励的id与sort后的数组*/
static getLastMapId(receivePrizeConfId: string[]) { static getLastMapId(receivePrizeConfId: string[]) {
if (!receivePrizeConfId) receivePrizeConfId = [] if(!receivePrizeConfId) receivePrizeConfId = []
receivePrizeConfId = receivePrizeConfId.sort((a, b) => ~~a - ~~b); receivePrizeConfId = receivePrizeConfId.sort((a, b) => ~~a - ~~b);
let receiveLastId = receivePrizeConfId.length > 0 ? receivePrizeConfId[receivePrizeConfId.length - 1] : '0';// 获取当前的领取进度 let receiveLastId = receivePrizeConfId.length > 0 ? receivePrizeConfId[receivePrizeConfId.length - 1] : '0';// 获取当前的领取进度
return {receiveLastId, receivePrizeConfId} return {receiveLastId, receivePrizeConfId}