Merge branch 'bugfix' into dev

This commit is contained in:
dy 2023-12-27 10:20:00 +08:00
commit 058529ea6a
5 changed files with 31 additions and 19 deletions

View File

@ -15,10 +15,21 @@ export default async function (call: ApiCall<ReqBuy, ResBuy>) {
let conf = _hdinfo.data.gift[call.req.index]; let conf = _hdinfo.data.gift[call.req.index];
if (!conf || conf.payId) return call.errorCode(-1); if (!conf || conf.payId) return call.errorCode(-1);
let selectPrize = conf.prize.map((v, i) => v[call.req.prizeIndex[i]]).filter(p => !!p); let data = await G.mongodb.cEvent(_dbType).findOne({uid: call.uid, type: _dbType})
if (selectPrize.length < conf.prize.length) return call.errorCode(-2); let rec = data?.rec?.[call.req.index]
if (rec) return call.errorCode(-3)
// 奖励不符合,严格判断
let dlzList = R.flatten(conf.dlz.map(i => R.values(i)))
call.req.dlz.map(i => {
let item = dlzList.find(v => i.a == v.a && i.t == v.t && i.n == v.n)
if (!item) call.errorCode(-4)
})
let event = (await G.mongodb.cEvent(_dbType).findOne({ uid: call.uid, type: _dbType }));
let buyNum = R.values(event?.rec)?.length || 0
let buyNum = (await G.mongodb.cEvent(_dbType).findOne({ uid: call.uid, type: _dbType }))?.record?.[call.req.index] || 0;
if (buyNum >= conf.buyNum) return call.errorCode(-3); if (buyNum >= conf.buyNum) return call.errorCode(-3);
if (conf.need.length > 0) { if (conf.need.length > 0) {
@ -26,15 +37,15 @@ export default async function (call: ApiCall<ReqBuy, ResBuy>) {
await PlayerFun.cutNeed(call, conf.need); await PlayerFun.cutNeed(call, conf.need);
} }
await PlayerFun.sendPrize(call, selectPrize); let prize = [...conf.prize,...call.req.dlz]
G.mongodb.cEvent(_dbType).updateOne( await PlayerFun.sendPrize(call, prize);
{ uid: call.uid, type: _dbType },
{ $inc: G.mongodb.createTreeObj({ key: `record.${call.req.index}`, val: 1 }) }, await G.mongodb.cEvent(_dbType).updateOne({uid: call.uid, type: _dbType}, {
{ upsert: true } $set: {[`rec.${call.req.index}`]: prize},
); }, {upsert: true})
call.succ({ call.succ({
prize: selectPrize prize: prize
}); });
} }

View File

@ -13,7 +13,7 @@ export default async function (call: ApiCall<ReqOpen, ResOpen>) {
let db = await G.mongodb.cEvent(_dbType).findOne({ uid: call.uid, type: _dbType }); let db = await G.mongodb.cEvent(_dbType).findOne({ uid: call.uid, type: _dbType });
call.succ({ call.succ({
record: db?.record || {}, rec: db?.rec || {},
hdinfo: _hdinfo hdinfo: _hdinfo
}); });
} }

View File

@ -1,4 +1,4 @@
import { prizeType } from '../../type'; import {prizeType} from '../../type';
/** /**
* *
@ -7,7 +7,7 @@ export type ReqBuy = {
/**礼包index */ /**礼包index */
index: number; index: number;
/**礼包的每个奖励index */ /**礼包的每个奖励index */
prizeIndex: number[]; dlz: prizeType[]
hdid: number hdid: number
}; };

View File

@ -10,8 +10,8 @@ export type ReqOpen = {
export type ResOpen = { export type ResOpen = {
/**购买记录 */ /**购买记录 */
record: { rec: {
[k: string]: number; [k: string]: any;
}; };
hdinfo: ReqAddHuoDong hdinfo: ReqAddHuoDong
}; };

View File

@ -11957,11 +11957,12 @@ export const serviceProto: ServiceProto<ServiceType> = {
}, },
{ {
"id": 1, "id": 1,
"name": "prizeIndex", "name": "dlz",
"type": { "type": {
"type": "Array", "type": "Array",
"elementType": { "elementType": {
"type": "Number" "type": "Reference",
"target": "type/prizeType"
} }
} }
}, },
@ -12007,13 +12008,13 @@ export const serviceProto: ServiceProto<ServiceType> = {
"properties": [ "properties": [
{ {
"id": 0, "id": 0,
"name": "record", "name": "rec",
"type": { "type": {
"type": "Interface", "type": "Interface",
"indexSignature": { "indexSignature": {
"keyType": "String", "keyType": "String",
"type": { "type": {
"type": "Number" "type": "Any"
} }
} }
} }