diff --git a/laf-cloud/functions/login.ts b/laf-cloud/functions/login.ts index 580b76a..1802361 100644 --- a/laf-cloud/functions/login.ts +++ b/laf-cloud/functions/login.ts @@ -96,6 +96,7 @@ export default async function (ctx: FunctionContext) { userPowerTime: migratedUser?.userPowerTime ?? 0, monthCardReward: migratedUser?.monthCardReward ?? 0, monthCardTime: migratedUser?.monthCardTime ?? 0, + miniProgramWelfare: { favorite: false, desktop: false }, rebornGiftCount: 0, rebornGiftTime: 0, useravatar: Math.floor(Math.random() * 4) + "", @@ -303,6 +304,11 @@ export default async function (ctx: FunctionContext) { userData.shareLv = []; } userData.careerAmount = userData.careerAmount || 0; + // 老用户缺少字段或某一项时按未领取返回,不写回整对象,避免覆盖并发领取。 + userData.miniProgramWelfare = { + favorite: userData.miniProgramWelfare?.favorite === true, + desktop: userData.miniProgramWelfare?.desktop === true, + }; if (dbname === "users") { userData.abTests = abTests; } @@ -453,6 +459,10 @@ async function getIosOrder(openid, ctx) { await db.collection("users").where({ _id: res1.data._id }).update({ pay_user: true }); break; case "reborn_Gift": + case "reborn_Gift_2": + case "reborn_Gift_3": + case "reborn_Gift_4": + case "reborn_Gift_5": db.collection("users").where({ _id: res1.data._id }).update({ rebornGiftTime: Date.now(), rebornGiftCount: 0, pay_user: true }); break; case "starter_pack": @@ -463,7 +473,8 @@ async function getIosOrder(openid, ctx) { break; } // 月卡补单确认成功后进入待客户端补发状态。 - if (res.data[i].itemid === "month_Card" || jungleTier || /^battlepass(?:_30|_12)?$/.test(res.data[i].itemid)) { + if (res.data[i].itemid === "month_Card" || jungleTier || /^battlepass(?:_30|_12)?$/.test(res.data[i].itemid) + || /^reborn_Gift(?:_[2-5])?$/.test(res.data[i].itemid)) { await db.collection("order").where({ outTradeNo: res.data[i].outTradeNo }).update({ state: 1 }); } } else { diff --git a/laf-cloud/functions/wx/KeFuInfo.ts b/laf-cloud/functions/wx/KeFuInfo.ts index 6eacb0d..baa6d9c 100644 --- a/laf-cloud/functions/wx/KeFuInfo.ts +++ b/laf-cloud/functions/wx/KeFuInfo.ts @@ -1,7 +1,5 @@ import * as StarterPackModule from "@/limitedTimeEvent"; const StarterPack: any = StarterPackModule as any; -import * as StarterPackModule from "@/limitedTimeEvent"; -const StarterPack: any = StarterPackModule as any; import cloud from '@lafjs/cloud' import { passOrderFields, PASS_PRICES } from '@/passCheckUpgrade'; // const token = "nika123"; @@ -104,6 +102,8 @@ async function frontsign(data) { return signature } const propName = { + reborn_Gift: "复活礼包6元", reborn_Gift_2: "复活礼包8元", reborn_Gift_3: "复活礼包10元", + reborn_Gift_4: "复活礼包12元", reborn_Gift_5: "复活礼包15元", battlepass: '基础战令', battlepass_30: '高级战令', battlepass_12: '战令升级', gold_1: "金币包1", gold_2: "金币包2", @@ -153,6 +153,11 @@ async function PostMsg(OpenId, msg) { return "ok" } async function PostImg(OpenId, outTradeNo, name, count, price, passInput: any = {}) { + const rebornPrice = { reborn_Gift: 600, reborn_Gift_2: 800, reborn_Gift_3: 1000, reborn_Gift_4: 1200, reborn_Gift_5: 1500 }; + if (/^reborn_Gift(?:_[2-5])?$/.test(name)) { + count = 1; + price = rebornPrice[name]; + } let passFields: any = {}; if (Object.prototype.hasOwnProperty.call(PASS_PRICES, name)) { const owner = await db.collection('users').where({ openid: OpenId }).getOne(); diff --git a/laf-cloud/functions/wx/getOrderReward.ts b/laf-cloud/functions/wx/getOrderReward.ts index 089d55c..ead204f 100644 --- a/laf-cloud/functions/wx/getOrderReward.ts +++ b/laf-cloud/functions/wx/getOrderReward.ts @@ -15,5 +15,14 @@ export default async function (ctx: FunctionContext) { if (order.data.itemid !== "month_Card") { await db.collection("order").where({ outTradeNo: outTradeNo }).update({ state: 2, getTime: new Date(Date.now() + 8 * 3600000) }); } + if (/^reborn_Gift(?:_[2-5])?$/.test(order.data.itemid)) { + const user = await db.collection("users").where({ _id: ctx.body.uid }).getOne(); + if (!user.data || user.data.openid !== order.data.openid) { + return { code: 0, data: null, msg: "充值订单不属于当前玩家" }; + } + if (order.data.state !== 1 && order.data.state !== 2) { + return { code: 0, data: null, msg: "充值尚未成功" }; + } + } return { code: 1, data: "ok", msg: "成功" }; } diff --git a/laf-cloud/functions/wx/iosgetPayInfo.ts b/laf-cloud/functions/wx/iosgetPayInfo.ts index 5cfab3c..56d81f9 100644 --- a/laf-cloud/functions/wx/iosgetPayInfo.ts +++ b/laf-cloud/functions/wx/iosgetPayInfo.ts @@ -24,6 +24,9 @@ export default async function (ctx: FunctionContext) { return { code: 0, data: null, msg: "未获取到充值信息" }; } let payment_name = ret.data?.itemid; + const rebornGift = /^reborn_Gift(?:_[2-5])?$/.test(payment_name); + const rebornPending = rebornGift && Number(ctx.body.rebornGiftVersion) === 1; + if (rebornGift && !uid) return { code: 0, data: null, msg: "未获取到玩家数据" }; if (isUpgradeOrder(ret.data) && ret.data.state === 2) return { code: 1, data: { payment_name, goodsPrice: ret.data.goodsPrice } }; if (res && payment_name === "starter_pack") { try { @@ -45,6 +48,9 @@ export default async function (ctx: FunctionContext) { if (!res1.data) { return { code: 0, data: null, msg: "未获取到玩家数据" }; } + if (rebornGift && ret.data.openid !== res1.data.openid) { + return { code: 0, data: null, msg: "充值订单不属于当前玩家" }; + } paidUser = res1.data; if (!iosOrder) { iosOrder = {}; @@ -65,6 +71,10 @@ export default async function (ctx: FunctionContext) { await db.collection("users").where({ _id: uid }).update({ pay_user: true }); break; case "reborn_Gift": + case "reborn_Gift_2": + case "reborn_Gift_3": + case "reborn_Gift_4": + case "reborn_Gift_5": db.collection("users").where({ _id: uid }).update({ rebornGiftTime: Date.now(), rebornGiftCount: 0, pay_user: true }); break; case "starter_pack": @@ -75,11 +85,11 @@ export default async function (ctx: FunctionContext) { break; } } - // 月卡等待 monthlyCard 完成加时后再进入 state=2,其他商品保持原逻辑。 + // 新版复活礼包等待客户端去重发奖后确认;旧客户端保持直接完成订单。 await db.collection("order").where({ outTradeNo: outTradeNo, ...(isUpgradeOrder(ret.data) ? { state: ret.data.state } : {}) }).update({ - state: payment_name === "month_Card" || isUpgradeOrder(ret.data) ? 1 : 2, + state: payment_name === "month_Card" || isUpgradeOrder(ret.data) || rebornPending ? 1 : 2, chargeTime: new Date(Date.now() + 8 * 3600000), - ...(payment_name === "month_Card" || isUpgradeOrder(ret.data) ? {} : { getTime: new Date(Date.now() + 8 * 3600000) }), + ...(payment_name === "month_Card" || isUpgradeOrder(ret.data) || rebornPending ? {} : { getTime: new Date(Date.now() + 8 * 3600000) }), }); diff --git a/laf-cloud/functions/wx/iosorderPaySig.ts b/laf-cloud/functions/wx/iosorderPaySig.ts index d2ac1d9..989336d 100644 --- a/laf-cloud/functions/wx/iosorderPaySig.ts +++ b/laf-cloud/functions/wx/iosorderPaySig.ts @@ -17,6 +17,11 @@ export default async function (ctx: FunctionContext) { let itemid = ctx.body.itemid; let itemCount = ctx.body.itemCount; let itemPrice = ctx.body.itemPrice; + const rebornPrice = { reborn_Gift: 600, reborn_Gift_2: 800, reborn_Gift_3: 1000, reborn_Gift_4: 1200, reborn_Gift_5: 1500 }; + if (/^reborn_Gift(?:_[2-5])?$/.test(itemid)) { + itemCount = 1; + itemPrice = rebornPrice[itemid]; + } let user = await db.collection("users").where({ _id: uid }).getOne(); if (user.data == null) { return { code: 0, data: null, msg: "未获取到玩家数据" }; diff --git a/laf-cloud/functions/wx/orderPaySig.ts b/laf-cloud/functions/wx/orderPaySig.ts index 9e9d505..b056a6a 100644 --- a/laf-cloud/functions/wx/orderPaySig.ts +++ b/laf-cloud/functions/wx/orderPaySig.ts @@ -17,6 +17,11 @@ export default async function (ctx: FunctionContext) { let itemid = ctx.body.itemid; let itemCount = ctx.body.itemCount; let itemPrice = ctx.body.itemPrice; + const rebornPrice = { reborn_Gift: 600, reborn_Gift_2: 800, reborn_Gift_3: 1000, reborn_Gift_4: 1200, reborn_Gift_5: 1500 }; + if (/^reborn_Gift(?:_[2-5])?$/.test(itemid)) { + itemCount = 1; + itemPrice = rebornPrice[itemid]; + } let user = await db.collection("users").where({ _id: uid }).getOne(); if (user.data == null) { return { code: 0, data: null, msg: "未获取到玩家数据" };