diff --git a/src/api_s2c/event/zixuanlibao/ApiBuy.ts b/src/api_s2c/event/zixuanlibao/ApiBuy.ts index 910e00e..53541b6 100644 --- a/src/api_s2c/event/zixuanlibao/ApiBuy.ts +++ b/src/api_s2c/event/zixuanlibao/ApiBuy.ts @@ -15,10 +15,21 @@ export default async function (call: ApiCall) { let conf = _hdinfo.data.gift[call.req.index]; if (!conf || conf.payId) return call.errorCode(-1); - let selectPrize = conf.prize.map((v, i) => v[call.req.prizeIndex[i]]).filter(p => !!p); - if (selectPrize.length < conf.prize.length) return call.errorCode(-2); + let data = await G.mongodb.cEvent(_dbType).findOne({uid: call.uid, type: _dbType}) + 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 (conf.need.length > 0) { @@ -26,15 +37,15 @@ export default async function (call: ApiCall) { await PlayerFun.cutNeed(call, conf.need); } - await PlayerFun.sendPrize(call, selectPrize); + let prize = [...conf.prize,...call.req.dlz] - G.mongodb.cEvent(_dbType).updateOne( - { uid: call.uid, type: _dbType }, - { $inc: G.mongodb.createTreeObj({ key: `record.${call.req.index}`, val: 1 }) }, - { upsert: true } - ); + await PlayerFun.sendPrize(call, prize); + + await G.mongodb.cEvent(_dbType).updateOne({uid: call.uid, type: _dbType}, { + $set: {[`rec.${call.req.index}`]: prize}, + }, {upsert: true}) call.succ({ - prize: selectPrize + prize: prize }); } \ No newline at end of file diff --git a/src/api_s2c/event/zixuanlibao/ApiOpen.ts b/src/api_s2c/event/zixuanlibao/ApiOpen.ts index 2b1016f..a742dc7 100644 --- a/src/api_s2c/event/zixuanlibao/ApiOpen.ts +++ b/src/api_s2c/event/zixuanlibao/ApiOpen.ts @@ -13,7 +13,7 @@ export default async function (call: ApiCall) { let db = await G.mongodb.cEvent(_dbType).findOne({ uid: call.uid, type: _dbType }); call.succ({ - record: db?.record || {}, + rec: db?.rec || {}, hdinfo: _hdinfo }); } \ No newline at end of file diff --git a/src/shared/protocols/event/zixuanlibao/PtlBuy.ts b/src/shared/protocols/event/zixuanlibao/PtlBuy.ts index d998f3d..2a64a6d 100644 --- a/src/shared/protocols/event/zixuanlibao/PtlBuy.ts +++ b/src/shared/protocols/event/zixuanlibao/PtlBuy.ts @@ -1,4 +1,4 @@ -import { prizeType } from '../../type'; +import {prizeType} from '../../type'; /** * 购买自选礼包 @@ -7,7 +7,7 @@ export type ReqBuy = { /**礼包index */ index: number; /**礼包的每个奖励index */ - prizeIndex: number[]; + dlz: prizeType[] hdid: number }; diff --git a/src/shared/protocols/event/zixuanlibao/PtlOpen.ts b/src/shared/protocols/event/zixuanlibao/PtlOpen.ts index 8b7cf23..92eabf0 100644 --- a/src/shared/protocols/event/zixuanlibao/PtlOpen.ts +++ b/src/shared/protocols/event/zixuanlibao/PtlOpen.ts @@ -10,8 +10,8 @@ export type ReqOpen = { export type ResOpen = { /**购买记录 */ - record: { - [k: string]: number; + rec: { + [k: string]: any; }; hdinfo: ReqAddHuoDong }; \ No newline at end of file diff --git a/src/shared/protocols/serviceProto.ts b/src/shared/protocols/serviceProto.ts index fc065a0..d3a6cd6 100644 --- a/src/shared/protocols/serviceProto.ts +++ b/src/shared/protocols/serviceProto.ts @@ -11957,11 +11957,12 @@ export const serviceProto: ServiceProto = { }, { "id": 1, - "name": "prizeIndex", + "name": "dlz", "type": { "type": "Array", "elementType": { - "type": "Number" + "type": "Reference", + "target": "type/prizeType" } } }, @@ -12007,13 +12008,13 @@ export const serviceProto: ServiceProto = { "properties": [ { "id": 0, - "name": "record", + "name": "rec", "type": { "type": "Interface", "indexSignature": { "keyType": "String", "type": { - "type": "Number" + "type": "Any" } } }