From c3b24969e3e9f375e0d749419aee5593cb76d880 Mon Sep 17 00:00:00 2001 From: "YZ\\249929363" <249929363@qq.com> Date: Wed, 2 Jul 2025 18:21:32 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=85=E5=80=BC=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/Scene/GameScene.fire | 6 +- assets/Scene/HomeScene.fire | 2 +- assets/Script/JiaZai.ts | 14 ++--- assets/Script/NumberToImage.ts | 25 +++++++-- assets/Script/module/Pay/Utils.ts | 48 +++++++++------- assets/Script/module/Tool/GameTool.ts | 32 ++++++++++- assets/shop/prefab/shop.prefab | 74 ++++++++++++------------ assets/shop/script/shop.ts | 81 ++++++++++++++++++++++++--- 8 files changed, 200 insertions(+), 82 deletions(-) diff --git a/assets/Scene/GameScene.fire b/assets/Scene/GameScene.fire index fbc1ece..ce19193 100644 --- a/assets/Scene/GameScene.fire +++ b/assets/Scene/GameScene.fire @@ -10507,7 +10507,7 @@ "__id__": 370 } ], - "_active": true, + "_active": false, "_components": [ { "__id__": 397 @@ -11012,7 +11012,7 @@ "__id__": 298 } ], - "_active": false, + "_active": true, "_components": [], "_prefab": null, "_opacity": 255, @@ -17709,7 +17709,7 @@ "__id__": 395 } ], - "_active": true, + "_active": false, "_components": [], "_prefab": null, "_opacity": 255, diff --git a/assets/Scene/HomeScene.fire b/assets/Scene/HomeScene.fire index 5982e45..a4a42f7 100644 --- a/assets/Scene/HomeScene.fire +++ b/assets/Scene/HomeScene.fire @@ -2435,7 +2435,7 @@ "__type__": "TypedArray", "ctor": "Float64Array", "array": [ - -0.255, + 19.091, 1.584, 0, 0, diff --git a/assets/Script/JiaZai.ts b/assets/Script/JiaZai.ts index 0b69747..038d6d4 100644 --- a/assets/Script/JiaZai.ts +++ b/assets/Script/JiaZai.ts @@ -109,7 +109,11 @@ export default class NewClass extends cc.Component { } - + updateCoin(){ + console.log("主页更新金币",cc.fx.GameConfig.GM_INFO.coin); + cc.fx.GameConfig.GM_INFO.coin += 900; + NumberToImage.numberToImageNodes(cc.fx.GameConfig.GM_INFO.coin, 30, 15, "coin_", this.coin, true); + } //开始倒计时 startTimeCutDown() { @@ -216,13 +220,7 @@ export default class NewClass extends cc.Component { clickShop() { // 假设已经获取到了 userId 和 productId - Utils.buyProp((res)=>{ - console.log("获得充值结果",res); - Utils.getPayInfo((data) =>{ - console.log("获得轮训结果:",data); - console.log(data.data.pay_state) - }) - }); + } diff --git a/assets/Script/NumberToImage.ts b/assets/Script/NumberToImage.ts index fc113c6..8383afc 100644 --- a/assets/Script/NumberToImage.ts +++ b/assets/Script/NumberToImage.ts @@ -30,18 +30,33 @@ export default class NumberToImage extends cc.Component { else if (number < 10) cha = posX if (targetNode.children.length > 0) targetNode.removeAllChildren(); + + const digitNodes: cc.Node[] = []; for (let i = 0; i < numStr.length; i++) { const digit = parseInt(numStr[i], 10); const node = new cc.Node(); const sprite = node.addComponent(cc.Sprite); - // debugger; sprite.spriteFrame = this.font._spriteFrames[name + digit + ""]; - // 将节点添加到目标节点下 - node.x = i * width + cha; - node.parent = targetNode; + digitNodes.push(node); } + + // 计算总宽度 + const totalWidth = (numStr.length - 1) * width + (digitNodes[0]?.width || 0); + if (middle) { - targetNode.x = targetNode.x - targetNode.children.length * (width - 15) / 2; + // 计算居中的起始位置 + const startX = -totalWidth / 2; + for (let i = 0; i < digitNodes.length; i++) { + const node = digitNodes[i]; + node.x = startX + i * width; + node.parent = targetNode; + } + } else { + for (let i = 0; i < digitNodes.length; i++) { + const node = digitNodes[i]; + node.x = i * width + cha; + node.parent = targetNode; + } } } diff --git a/assets/Script/module/Pay/Utils.ts b/assets/Script/module/Pay/Utils.ts index 1a7a2f0..cd135c3 100644 --- a/assets/Script/module/Pay/Utils.ts +++ b/assets/Script/module/Pay/Utils.ts @@ -29,8 +29,10 @@ export default class Utils { } /**道具直购接口*/ - static buyProp(callBack){ - Utils.POST("wx/orderPaySig",{uid:Utils.uid,itemid:"10011",itemCount:1,itemPrice:100},res=>{ + static buyProp(id,count,price,callBack){ + console.log("请求uid:"+Utils.uid,"请求id:"+id,"请求数量:"+count,"请求价格:"+price); + + Utils.POST("wx/orderPaySig",{uid:Utils.uid,itemid:id,itemCount:count,itemPrice:price},res=>{ if(res.code==1){ Utils.outTradeNo=res.data.outTradeNo; //@ts-ignore @@ -45,7 +47,7 @@ export default class Utils { fail({errMsg,errCode}) { console.error('失败'); console.error(errMsg, errCode) - callBack(res); + callBack(null); } }) } @@ -54,24 +56,30 @@ export default class Utils { } - static getPayInfo(callBack){ - console.log("请求uid:"+Utils.uid); - console.log("outTradeNo:"+this.outTradeNo); - Utils.POST("wx/getPayInfo",{uid:Utils.uid,outTradeNo:Utils.outTradeNo},res=>{ - console.log("查询字符结果"); - console.log(res); - if(res.code==1){ - if(res.data.pay_state==1){ - console.log("充值取消") - callBack(res); - }else{ - console.log("充值成功") - callBack(res); - - } - } - }); + static getPayInfo(callBack) { + const delays = [1000, 10000, 30000, 60000, 60000]; // 延迟时间数组 + let attempt = 0; // 轮询次数 + const poll = () => { + if (attempt >= delays.length) { + callBack({ code: 0, data: { pay_state: -1 }, message: '轮询超时' }); + return; + } + + console.log("请求uid:", Utils.uid); + console.log("outTradeNo:", this.outTradeNo); + Utils.POST("wx/getPayInfo", { uid: Utils.uid, outTradeNo: Utils.outTradeNo }, res => { + console.log("查询字符结果:", res); + if (res.code === 1 && (res.data.pay_state === 1 || res.data.pay_state === 2)) { + callBack(res); + } else { + attempt++; + setTimeout(poll, delays[attempt - 1]); + } + }); + }; + + poll(); } /**跳转客服*/ diff --git a/assets/Script/module/Tool/GameTool.ts b/assets/Script/module/Tool/GameTool.ts index 8a642be..6fac229 100644 --- a/assets/Script/module/Tool/GameTool.ts +++ b/assets/Script/module/Tool/GameTool.ts @@ -806,7 +806,37 @@ var GameTool = { } }, - formatDate(date: Date): string { + //商城购买 + shopBuy(productId){ + switch(productId){ + case "gold_pack_1": + cc.fx.GameTool.changeCoin(1800); + MiniGameSdk.API.showToast("充值成功,获得1800金币"); + break; + case "gold_pack_2": + cc.fx.GameTool.changeCoin(8000); + MiniGameSdk.API.showToast("充值成功,获得8000金币"); + break; + case "gold_pack_3": + cc.fx.GameTool.changeCoin(16000); + MiniGameSdk.API.showToast("充值成功,获得16000金币"); + break; + case "gold_pack_4": + cc.fx.GameTool.changeCoin(32000); + MiniGameSdk.API.showToast("充值成功,获得32000金币"); + break; + case "gold_pack_5": + cc.fx.GameTool.changeCoin(100000); + MiniGameSdk.API.showToast("充值成功,获得100000金币"); + break; + case "gold_pack_6": + cc.fx.GameTool.changeCoin(240000); + MiniGameSdk.API.showToast("充值成功,获得240000金币"); + break; + } + }, + + formatDate(date: Date): string { const year = date.getFullYear(); const month = String(date.getMonth() + 1).padStart(2, '0'); const day = String(date.getDate()).padStart(2, '0'); diff --git a/assets/shop/prefab/shop.prefab b/assets/shop/prefab/shop.prefab index 871b9dc..2a68b0f 100644 --- a/assets/shop/prefab/shop.prefab +++ b/assets/shop/prefab/shop.prefab @@ -1046,7 +1046,7 @@ 1, 1, 1, - 1 + 0 ] }, "_eulerAngles": { @@ -1277,7 +1277,7 @@ "__type__": "TypedArray", "ctor": "Float64Array", "array": [ - -72.37, + 15, 150, 0, 0, @@ -1321,7 +1321,7 @@ "__id__": 25 }, "_children": [], - "_active": true, + "_active": false, "_components": [ { "__id__": 34 @@ -1576,7 +1576,7 @@ "_normalMaterial": null, "_grayMaterial": null, "duration": 0.1, - "zoomScale": 1.2, + "zoomScale": 1.1, "clickEvents": [ { "__id__": 41 @@ -1584,8 +1584,8 @@ ], "_N$interactable": true, "_N$enableAutoGrayEffect": false, - "_N$transition": 0, - "transition": 0, + "_N$transition": 3, + "transition": 3, "_N$normalColor": { "__type__": "cc.Color", "r": 255, @@ -1742,7 +1742,7 @@ 1, 1, 1, - 1 + 0 ] }, "_eulerAngles": { @@ -1973,7 +1973,7 @@ "__type__": "TypedArray", "ctor": "Float64Array", "array": [ - -72.37, + 20, 150, 0, 0, @@ -2017,7 +2017,7 @@ "__id__": 44 }, "_children": [], - "_active": true, + "_active": false, "_components": [ { "__id__": 53 @@ -2272,7 +2272,7 @@ "_normalMaterial": null, "_grayMaterial": null, "duration": 0.1, - "zoomScale": 1.2, + "zoomScale": 1.1, "clickEvents": [ { "__id__": 60 @@ -2280,8 +2280,8 @@ ], "_N$interactable": true, "_N$enableAutoGrayEffect": false, - "_N$transition": 0, - "transition": 0, + "_N$transition": 3, + "transition": 3, "_N$normalColor": { "__type__": "cc.Color", "r": 255, @@ -2438,7 +2438,7 @@ 1, 1, 1, - 1 + 0 ] }, "_eulerAngles": { @@ -2669,7 +2669,7 @@ "__type__": "TypedArray", "ctor": "Float64Array", "array": [ - -72.37, + 15, 150, 0, 0, @@ -2713,7 +2713,7 @@ "__id__": 63 }, "_children": [], - "_active": true, + "_active": false, "_components": [ { "__id__": 72 @@ -2968,7 +2968,7 @@ "_normalMaterial": null, "_grayMaterial": null, "duration": 0.1, - "zoomScale": 1.2, + "zoomScale": 1.1, "clickEvents": [ { "__id__": 79 @@ -2976,8 +2976,8 @@ ], "_N$interactable": true, "_N$enableAutoGrayEffect": false, - "_N$transition": 0, - "transition": 0, + "_N$transition": 3, + "transition": 3, "_N$normalColor": { "__type__": "cc.Color", "r": 255, @@ -3134,7 +3134,7 @@ 1, 1, 1, - 1 + 0 ] }, "_eulerAngles": { @@ -3365,7 +3365,7 @@ "__type__": "TypedArray", "ctor": "Float64Array", "array": [ - -72.37, + 10, 150, 0, 0, @@ -3409,7 +3409,7 @@ "__id__": 82 }, "_children": [], - "_active": true, + "_active": false, "_components": [ { "__id__": 91 @@ -3664,7 +3664,7 @@ "_normalMaterial": null, "_grayMaterial": null, "duration": 0.1, - "zoomScale": 1.2, + "zoomScale": 1.1, "clickEvents": [ { "__id__": 98 @@ -3672,8 +3672,8 @@ ], "_N$interactable": true, "_N$enableAutoGrayEffect": false, - "_N$transition": 0, - "transition": 0, + "_N$transition": 3, + "transition": 3, "_N$normalColor": { "__type__": "cc.Color", "r": 255, @@ -3830,7 +3830,7 @@ 1, 1, 1, - 1 + 0 ] }, "_eulerAngles": { @@ -4061,7 +4061,7 @@ "__type__": "TypedArray", "ctor": "Float64Array", "array": [ - -72.37, + 0, 150, 0, 0, @@ -4105,7 +4105,7 @@ "__id__": 101 }, "_children": [], - "_active": true, + "_active": false, "_components": [ { "__id__": 110 @@ -4360,7 +4360,7 @@ "_normalMaterial": null, "_grayMaterial": null, "duration": 0.1, - "zoomScale": 1.2, + "zoomScale": 1.1, "clickEvents": [ { "__id__": 117 @@ -4368,8 +4368,8 @@ ], "_N$interactable": true, "_N$enableAutoGrayEffect": false, - "_N$transition": 0, - "transition": 0, + "_N$transition": 3, + "transition": 3, "_N$normalColor": { "__type__": "cc.Color", "r": 255, @@ -4526,7 +4526,7 @@ 1, 1, 1, - 1 + 0 ] }, "_eulerAngles": { @@ -4757,7 +4757,7 @@ "__type__": "TypedArray", "ctor": "Float64Array", "array": [ - -72.37, + 0, 150, 0, 0, @@ -4801,7 +4801,7 @@ "__id__": 120 }, "_children": [], - "_active": true, + "_active": false, "_components": [ { "__id__": 129 @@ -5056,7 +5056,7 @@ "_normalMaterial": null, "_grayMaterial": null, "duration": 0.1, - "zoomScale": 1.2, + "zoomScale": 1.1, "clickEvents": [ { "__id__": 136 @@ -5064,8 +5064,8 @@ ], "_N$interactable": true, "_N$enableAutoGrayEffect": false, - "_N$transition": 0, - "transition": 0, + "_N$transition": 3, + "transition": 3, "_N$normalColor": { "__type__": "cc.Color", "r": 255, @@ -6942,7 +6942,7 @@ "__type__": "TypedArray", "ctor": "Float64Array", "array": [ - -0.255, + 35.399, 1.584, 0, 0, diff --git a/assets/shop/script/shop.ts b/assets/shop/script/shop.ts index 650155e..cab5302 100644 --- a/assets/shop/script/shop.ts +++ b/assets/shop/script/shop.ts @@ -1,5 +1,7 @@ +import Utils from "../../Script/module/Pay/Utils"; import List from "../../Script/module/RankList/List"; import NumberToImage from "../../Script/NumberToImage"; +import { MiniGameSdk } from "../../Script/Sdk/MiniGameSdk"; const { ccclass, property } = cc._decorator; @@ -16,19 +18,25 @@ export default class NewClass extends cc.Component { //金币数量 @property(cc.Node) coin: cc.Node = null; + + btn_Touch: boolean = true; + onLoad() { + this.btn_Touch = true; + } start() { + this.btn_Touch = true; this.openShop(); } //打开商店界面 openShop() { // 商品数据数组 const products = [ - { product_id: "gold_pack_1", name: "金币包1", price: 600, title: "3x2六档金币" }, - { product_id: "gold_pack_2", name: "金币包2", price: 3600, title: "" }, - { product_id: "gold_pack_3", name: "金币包3", price: 6800, title: "" }, - { product_id: "gold_pack_4", name: "金币包4", price: 12800, title: "" }, - { product_id: "gold_pack_5", name: "金币包5", price: 32800, title: "" }, - { product_id: "gold_pack_6", name: "金币包6", price: 64800, title: "" }, + { product_id: "gold_pack_1", name: "金币包1", price: 600, coin:1200, title: "3x2六档金币" }, + { product_id: "gold_pack_2", name: "金币包2", price: 3600, coin:8000, title: "" }, + { product_id: "gold_pack_3", name: "金币包3", price: 6800, coin:16000, title: "" }, + { product_id: "gold_pack_4", name: "金币包4", price: 12800, coin:32000, title: "" }, + { product_id: "gold_pack_5", name: "金币包5", price: 32800, coin:100000, title: "" }, + { product_id: "gold_pack_6", name: "金币包6", price: 64800, coin:240000, title: "" }, ]; for (let i = 1; i <= 6 && i < this.itemList.children.length; i++) { const spriteComp = this.itemList.children[i].children[0].getComponent(cc.Sprite); @@ -45,7 +53,7 @@ export default class NewClass extends cc.Component { NumberToImage.numberToImageNodes(product.price / 100, 25, 20, "cost_", price, false) } if (title && product) { - NumberToImage.numberToImageNodes(product.price / 100, 40, 25, "scoin_", title, false) + NumberToImage.numberToImageNodes(product.coin, 40, 25, "scoin_", title, true) } } NumberToImage.numberToImageNodes(cc.fx.GameConfig.GM_INFO.coin, 30, 15, "coin_", this.coin, true); @@ -61,7 +69,66 @@ export default class NewClass extends cc.Component { //点击充值购买 buyProduct(event, customData) { + if(!this.btn_Touch){ + return; + } + this.btn_Touch = false; const productId = customData; + let id = "10011"; + let price = 100; + let count = 1; + id = productId; + switch(productId){ + case "gold_pack_1": + price = 100; + break; + case "gold_pack_2": + price = 100; + break; + case "gold_pack_3": + price = 100; + break; + case "gold_pack_4": + price = 100; + break; + case "gold_pack_5": + price = 100; + break; + case "gold_pack_6": + price = 200; + break; + } + console.log("获得商品id:",id,count,price); + Utils.buyProp(id,count,price,(res)=>{ + console.log("获得充值结果",res); + if(res == null){ + MiniGameSdk.API.showToast("网络异常,充值失败请稍后再试"); + this.btn_Touch = true; + } + else{ + Utils.getPayInfo((data) =>{ + console.log("获得轮训结果:",data); + if(data.data.pay_state == 1){ + this.btn_Touch = true; + MiniGameSdk.API.showToast("取消充值"); + cc.fx.GameTool.shopBuy(productId); + console.log("充值取消未获得金币"); + NumberToImage.numberToImageNodes(cc.fx.GameConfig.GM_INFO.coin, 30, 15, "coin_", this.coin, true); + this.node.parent.getComponent("JiaZai").updateCoin(); + } + else if(data.data.pay_state == 2){ + this.btn_Touch = true; + MiniGameSdk.API.showToast("充值成功"); + cc.fx.GameTool.shopBuy(productId); + console.log("充值成功获得金币"); + NumberToImage.numberToImageNodes(cc.fx.GameConfig.GM_INFO.coin, 30, 15, "coin_", this.coin, true); + this.node.parent.getComponent("JiaZai").updateCoin(); + } + }) + } + + }); + } // update (dt) {} }