修改 一些代码

This commit is contained in:
YZ\249929363 2025-07-03 16:40:06 +08:00
parent 3127af522f
commit a7edab0b6e
13 changed files with 1437 additions and 1223 deletions

File diff suppressed because it is too large Load Diff

View File

@ -300,7 +300,10 @@ export default class Block extends cc.Component {
let spriteFrame = this.ice_SpriteFrame._spriteFrames[name]; let spriteFrame = this.ice_SpriteFrame._spriteFrames[name];
freeze.getChildByName("icon").getComponent(cc.Sprite).spriteFrame = spriteFrame; freeze.getChildByName("icon").getComponent(cc.Sprite).spriteFrame = spriteFrame;
let freezeX = posConfig.pos6.x-(this.node.width*(this.node.anchorX-0.5)); let freezeY = posConfig.pos6.y + this.node.height/2; let freezeX = posConfig.pos6.x-(this.node.width*(this.node.anchorX-0.5)); let freezeY = posConfig.pos6.y + this.node.height/2;
freeze.setPosition(freezeX,freezeY); if(this.block_Info.block == 2){
freeze.setPosition(freezeX+4,freezeY-10);
}
else freeze.setPosition(freezeX,freezeY);
freeze.getComponent("Freeze").init(this.block_Info.freezeTime); freeze.getComponent("Freeze").init(this.block_Info.freezeTime);
freeze.getChildByName("time").setPosition(posConfig.pos5.x-10-freezeX,posConfig.pos5.y-2-freezeY); freeze.getChildByName("time").setPosition(posConfig.pos5.x-10-freezeX,posConfig.pos5.y-2-freezeY);
break; break;

View File

@ -13,7 +13,12 @@ import Utils from "./module/Pay/Utils";
const { ccclass, property } = cc._decorator; const { ccclass, property } = cc._decorator;
@ccclass @ccclass
export default class NewClass extends cc.Component { export default class JiaZai extends cc.Component {
// 缓存 shop 预制体
private static cachedShopPrefab: cc.Prefab | null = null;
// 缓存 shop 节点
private shopNode: cc.Node | null = null;
@property(cc.Node) @property(cc.Node)
node1: cc.Node = null; node1: cc.Node = null;
@ -58,6 +63,25 @@ export default class NewClass extends cc.Component {
// console.log("加载关卡配置2"); // console.log("加载关卡配置2");
// window.initMgr(); // window.initMgr();
GameManager._instance.Block_Color = this.Block_Color; GameManager._instance.Block_Color = this.Block_Color;
// 预加载 shop 预制体
if (!JiaZai.cachedShopPrefab) {
cc.assetManager.loadBundle('shop', (err: Error, bundle: cc.AssetManager.Bundle) => {
if (err) {
cc.error(err.message || err);
return;
}
bundle.load('prefab/shop', cc.Prefab, (err: Error, prefab: cc.Prefab) => {
if (err) {
cc.error(err.message || err);
return;
}
JiaZai.cachedShopPrefab = prefab;
});
});
}
if (cc.fx.GameConfig.GM_INFO.first) { if (cc.fx.GameConfig.GM_INFO.first) {
console.log("————————准备注册事件", cc.fx.GameConfig.GM_INFO.openid); console.log("————————准备注册事件", cc.fx.GameConfig.GM_INFO.openid);
if (cc.fx.GameConfig.GM_INFO.openid != "") { if (cc.fx.GameConfig.GM_INFO.openid != "") {
@ -111,7 +135,6 @@ export default class NewClass extends cc.Component {
} }
//打开heath弹窗,创建预制体 //打开heath弹窗,创建预制体
openHeath() { openHeath() {
let health = cc.instantiate(this.health); let health = cc.instantiate(this.health);
@ -203,20 +226,27 @@ export default class NewClass extends cc.Component {
//打开商店 //打开商店
openShop() { openShop() {
// 加载 shop bundle if (!JiaZai.cachedShopPrefab) {
cc.assetManager.loadBundle('shop', (err: Error, bundle: cc.AssetManager.Bundle) => { cc.error('Shop prefab is not loaded yet.');
bundle.load('prefab/shop', cc.Prefab, (err: Error, prefab: cc.Prefab) => {
if (err) {
cc.error(err.message || err);
return; return;
} }
if (prefab) {
const shopNode = cc.instantiate(prefab); if (!this.shopNode) {
this.node.addChild(shopNode); // 第一次使用,创建节点
console.log("shopNode parent:", shopNode.parent); this.shopNode = cc.instantiate(JiaZai.cachedShopPrefab);
this.node.addChild(this.shopNode);
} else {
// 非第一次使用,直接激活节点
this.shopNode.active = true;
}
// console.log("shopNode parent:", this.shopNode.parent);
}
// 关闭商店
closeShop() {
if (this.shopNode) {
this.shopNode.active = false;
} }
});
});
} }
closeRank() { closeRank() {

View File

@ -193,13 +193,14 @@ export default class MapConroler extends cc.Component {
// this.node.getChildByName("Wall").zIndex = 10; // this.node.getChildByName("Wall").zIndex = 10;
this.timeLabel = this.node.parent.getChildByName("Top").getChildByName("time"); this.timeLabel = this.node.parent.getChildByName("Top").getChildByName("time");
this.levelLabel = this.node.parent.getChildByName("Top").getChildByName("level"); this.levelLabel = this.node.parent.getChildByName("Top").getChildByName("level");
this.coin = this.node.parent.getChildByName("Top").getChildByName("coin"); this.coin = this.node.parent.getChildByName("Top").getChildByName("shop").getChildByName("coin");
this.timeNumber = cc.fx.GameConfig.LEVEL_INFO[0].time; this.timeNumber = cc.fx.GameConfig.LEVEL_INFO[0].time;
console.log("当前关卡时间", this.timeNumber); console.log("当前关卡时间", this.timeNumber);
this.count_Time = 0; this.count_Time = 0;
this.add_Time = 0; this.add_Time = 0;
NumberToImage.getTimeMargin(this.timeNumber, 50, "time_", this.timeLabel) NumberToImage.getTimeMargin(this.timeNumber, 50, "time_", this.timeLabel)
NumberToImage.numberToImageNodes(cc.fx.GameConfig.GM_INFO.coin, 30, 15, "coin_", this.coin, true); NumberToImage.numberToImageNodes(cc.fx.GameConfig.GM_INFO.coin, 30, 15, "coin_", this.coin, true);
// var timeTemp = cc.fx.GameTool.getTimeMargin(this.timeNumber); // var timeTemp = cc.fx.GameTool.getTimeMargin(this.timeNumber);
// this.timeLabel.string = timeTemp.toString(); // this.timeLabel.string = timeTemp.toString();
@ -1647,7 +1648,7 @@ export default class MapConroler extends cc.Component {
this.pause = true; this.pause = true;
this.node.parent.getChildByName("Ice").active = true; this.node.parent.getChildByName("Ice").active = true;
this.node.parent.getChildByName("Top").getChildByName("Ice").active = true; // this.node.parent.getChildByName("Top").getChildByName("Ice").active = true;
cc.fx.GameConfig.GM_INFO.freezeAmount -= 1; cc.fx.GameConfig.GM_INFO.freezeAmount -= 1;
if (cc.fx.GameConfig.GM_INFO.freezeAmount < 0) if (cc.fx.GameConfig.GM_INFO.freezeAmount < 0)
@ -1679,7 +1680,7 @@ export default class MapConroler extends cc.Component {
let freezeBtn = this.node.parent.getChildByName("Bottom").getChildByName("timeBtn"); let freezeBtn = this.node.parent.getChildByName("Bottom").getChildByName("timeBtn");
freezeBtn.getComponent("btnControl").setTouch(true); freezeBtn.getComponent("btnControl").setTouch(true);
this.node.parent.getChildByName("Ice").active = false; this.node.parent.getChildByName("Ice").active = false;
this.node.parent.getChildByName("Top").getChildByName("Ice").active = false; // this.node.parent.getChildByName("Top").getChildByName("Ice").active = false;
this.pause = false; this.pause = false;
// this.startTimeCutDown(); // this.startTimeCutDown();
} }

View File

@ -14,6 +14,11 @@ const { ccclass, property } = cc._decorator;
@ccclass @ccclass
export default class SceneManager extends cc.Component { export default class SceneManager extends cc.Component {
// 缓存 shop 预制体
private static cachedShopPrefab: cc.Prefab | null = null;
// 缓存 shop 节点
private shopNode: cc.Node | null = null;
@property(cc.Label) @property(cc.Label)
label: cc.Label = null; label: cc.Label = null;
@ -64,7 +69,22 @@ export default class SceneManager extends cc.Component {
onLoad() { onLoad() {
cc.game.setFrameRate(63); cc.game.setFrameRate(63);
this.changeBg(); this.changeBg();
// 预加载 shop 预制体
if (!SceneManager.cachedShopPrefab) {
cc.assetManager.loadBundle('shop', (err: Error, bundle: cc.AssetManager.Bundle) => {
if (err) {
cc.error(err.message || err);
return;
}
bundle.load('prefab/shop', cc.Prefab, (err: Error, prefab: cc.Prefab) => {
if (err) {
cc.error(err.message || err);
return;
}
SceneManager.cachedShopPrefab = prefab;
});
});
}
setTimeout(() => { setTimeout(() => {
cc.director.preloadScene("HomeScene", (err) => { cc.director.preloadScene("HomeScene", (err) => {
if (err) { if (err) {
@ -243,7 +263,12 @@ export default class SceneManager extends cc.Component {
this.node.getChildByName("Pause").active = true; this.node.getChildByName("Pause").active = true;
MapConroler._instance.pause = true; MapConroler._instance.pause = true;
} }
}
closeShop(){
if (this.shopNode) {
this.shopNode.active = false;
}
} }
closePause() { closePause() {
@ -282,20 +307,20 @@ export default class SceneManager extends cc.Component {
} }
//打开商店 //打开商店
openShop() { openShop() {
// 加载 shop bundle if (!SceneManager.cachedShopPrefab) {
cc.assetManager.loadBundle('shop', (err: Error, bundle: cc.AssetManager.Bundle) => { cc.error('Shop prefab is not loaded yet.');
bundle.load('prefab/shop', cc.Prefab, (err: Error, prefab: cc.Prefab) => {
if (err) {
cc.error(err.message || err);
return; return;
} }
if (prefab) {
const shopNode = cc.instantiate(prefab); if (!this.shopNode) {
this.node.addChild(shopNode); // 第一次使用,创建节点
console.log("shopNode parent:", shopNode.parent); this.shopNode = cc.instantiate(SceneManager.cachedShopPrefab);
this.node.addChild(this.shopNode);
} else {
// 非第一次使用,直接激活节点
this.shopNode.active = true;
} }
}); // console.log("shopNode parent:", this.shopNode.parent);
});
} }

View File

@ -251,7 +251,7 @@ export class GameConfig {
cc.fx.GameConfig.GM_INFO.level = 204; cc.fx.GameConfig.GM_INFO.level = 204;
} }
let name = "Json/level" + (cc.fx.GameConfig.GM_INFO.level+1); let name = "Json/level" + (cc.fx.GameConfig.GM_INFO.level+1);
debugger;
// //console.log("关卡名称:",name); // //console.log("关卡名称:",name);
// name = "Json/level" + 68; // name = "Json/level" + 68;
// cc.fx.StorageMessage.setStorage("level",cc.fx.GameConfig.GM_INFO.level.toString()); // cc.fx.StorageMessage.setStorage("level",cc.fx.GameConfig.GM_INFO.level.toString());

View File

@ -14,7 +14,7 @@ export default class Utils {
console.log(res); console.log(res);
if (res.code) { if (res.code) {
Utils.POST("login",{code:res.code},ret=>{ Utils.POST("login",{code:res.code},ret=>{
console.log("请求结果:"); console.log("请求结果:",res);
console.log(ret); console.log(ret);
Utils.openid=ret.data.openid; Utils.openid=ret.data.openid;
Utils.session_key=ret.data.session_key; Utils.session_key=ret.data.session_key;
@ -131,133 +131,133 @@ export default class Utils {
//#endregion //#endregion
//#region 微信云 //#region 微信云
static initServer(){ // static initServer(){
if(cc.sys.platform!=cc.sys.WECHAT_GAME)return; // if(cc.sys.platform!=cc.sys.WECHAT_GAME)return;
//@ts-ignore // //@ts-ignore
wx.cloud.init({ // wx.cloud.init({
env: 'cloudbase-1gl7iex89268f11e' // env: 'cloudbase-1gl7iex89268f11e'
}) // })
} // }
static getUserCode(){ // static getUserCode(){
//@ts-ignore // //@ts-ignore
wx.login({ // wx.login({
success (res) { // success (res) {
console.log("登录成功"); // console.log("登录成功");
console.log(res); // console.log(res);
if (res.code) { // if (res.code) {
//@ts-ignore // //@ts-ignore
wx.cloud.callFunction({ // wx.cloud.callFunction({
// 云函数名称 // // 云函数名称
name: 'login', // name: 'login',
// 传给云函数的参数 // // 传给云函数的参数
data: { // data: {
code:res.code, // code:res.code,
}, // },
success: function(ret) { // success: function(ret) {
console.log("请求成功"); // console.log("请求成功");
console.log("请求结果:"); // console.log("请求结果:");
console.log(ret); // console.log(ret);
Utils.openid=ret.data.openid; // Utils.openid=ret.data.openid;
Utils.session_key=ret.data.session_key; // Utils.session_key=ret.data.session_key;
Utils.uid=ret.data._id; // Utils.uid=ret.data._id;
}, // },
fail:function(res){ // fail:function(res){
console.log("请求失败"); // console.log("请求失败");
console.log(res); // console.log(res);
} // }
}) // })
} else { // } else {
console.log('登录失败!' + res.errMsg) // console.log('登录失败!' + res.errMsg)
} // }
} // }
}) // })
} // }
static PayOder(){ // static PayOder(){
if(cc.sys.platform!=cc.sys.WECHAT_GAME)return; // if(cc.sys.platform!=cc.sys.WECHAT_GAME)return;
//@ts-ignore // //@ts-ignore
wx.cloud.callFunction({ // wx.cloud.callFunction({
// 云函数名称 // // 云函数名称
name: 'userPayOrder', // name: 'userPayOrder',
// 传给云函数的参数 // // 传给云函数的参数
data: { // data: {
itemid:"10011", // itemid:"10011",
itemCount:1, // itemCount:1,
itemPrice:100 // itemPrice:100
}, // },
success: function(res) { // success: function(res) {
console.log("请求成功"); // console.log("请求成功");
console.log(res) // console.log(res)
if(res.result.code==1){ // if(res.result.code==1){
Utils.outTradeNo=res.result.data.outTradeNo; // Utils.outTradeNo=res.result.data.outTradeNo;
console.log("订单号:"+Utils.outTradeNo); // console.log("订单号:"+Utils.outTradeNo);
//@ts-ignore // //@ts-ignore
wx.requestMidasPaymentGameItem({ // wx.requestMidasPaymentGameItem({
signData:res.result.data.signData, // signData:res.result.data.signData,
paySig: res.result.data.paySig, // paySig: res.result.data.paySig,
signature: res.result.data.signature, // signature: res.result.data.signature,
success(res, errCode) { // success(res, errCode) {
console.log('成功', res, errCode); // console.log('成功', res, errCode);
}, // },
fail({errMsg,errCode}) { // fail({errMsg,errCode}) {
console.error('失败'); // console.error('失败');
console.error(errMsg, errCode) // console.error(errMsg, errCode)
} // }
}) // })
} // }
}, // },
fail:function(res){ // fail:function(res){
console.log("请求失败"); // console.log("请求失败");
console.log(res); // console.log(res);
} // }
}) // })
} // }
static getPayInfo1(callBack){ // static getPayInfo1(callBack){
if(cc.sys.platform!=cc.sys.WECHAT_GAME)return; // if(cc.sys.platform!=cc.sys.WECHAT_GAME)return;
//@ts-ignore // //@ts-ignore
wx.cloud.callFunction({ // wx.cloud.callFunction({
// 云函数名称 // // 云函数名称
name: 'userGetPayState', // name: 'userGetPayState',
// 传给云函数的参数 // // 传给云函数的参数
data: { // data: {
outTradeNo:Utils.outTradeNo // outTradeNo:Utils.outTradeNo
}, // },
success: function(res) { // success: function(res) {
console.log("请求成功"); // console.log("请求成功");
console.log(res) // console.log(res)
callBack("成功"); // callBack("成功");
}, // },
fail:function(res){ // fail:function(res){
console.log("请求失败"); // console.log("请求失败");
console.log(res); // console.log(res);
callBack("失败"); // callBack("失败");
} // }
}) // })
} // }
static toke(){ // static toke(){
if(cc.sys.platform!=cc.sys.WECHAT_GAME)return; // if(cc.sys.platform!=cc.sys.WECHAT_GAME)return;
//@ts-ignore // //@ts-ignore
wx.cloud.callFunction({ // wx.cloud.callFunction({
// 云函数名称 // // 云函数名称
name: 'uerToken', // name: 'uerToken',
// 传给云函数的参数 // // 传给云函数的参数
data: { // data: {
}, // },
success: function(res) { // success: function(res) {
console.log("请求成功"); // console.log("请求成功");
console.log(res) // console.log(res)
}, // },
fail:function(res){ // fail:function(res){
console.log("请求失败"); // console.log("请求失败");
console.log(res); // console.log(res);
} // }
}) // })
} // }
//#endregion //#endregion

View File

@ -1,6 +1,7 @@
import SceneManager from "../../SceneManager"; import SceneManager from "../../SceneManager";
import { MiniGameSdk } from "../../Sdk/MiniGameSdk"; import { MiniGameSdk } from "../../Sdk/MiniGameSdk";
import Utils from "../Pay/Utils";
//@ts-ignore //@ts-ignore
//最大工具类 各种公共方法,以及处理上传,获取后端接口数据 //最大工具类 各种公共方法,以及处理上传,获取后端接口数据
var GameTool = { var GameTool = {
@ -643,7 +644,7 @@ var GameTool = {
const buyData = { const buyData = {
item_id:_id, item_id:_id,
item_num:1, item_num:3,
item_price:1500, item_price:1500,
cost_type:"gold" cost_type:"gold"
} }
@ -809,32 +810,53 @@ var GameTool = {
//商城购买 //商城购买
shopBuy(productId){ shopBuy(productId){
let coin = 0;
let price = 0;
switch(productId){ switch(productId){
case "gold_1": case "gold_1":
cc.fx.GameTool.changeCoin(1200); cc.fx.GameTool.changeCoin(1200);
coin = 1200;
price = 600;
MiniGameSdk.API.showToast("充值成功获得1200金币"); MiniGameSdk.API.showToast("充值成功获得1200金币");
break; break;
case "gold_2": case "gold_2":
cc.fx.GameTool.changeCoin(8000); cc.fx.GameTool.changeCoin(8000);
coin = 8000;
price = 3600;
MiniGameSdk.API.showToast("充值成功获得8000金币"); MiniGameSdk.API.showToast("充值成功获得8000金币");
break; break;
case "gold_3": case "gold_3":
cc.fx.GameTool.changeCoin(16000); cc.fx.GameTool.changeCoin(16000);
coin = 16000;
price = 6800;
MiniGameSdk.API.showToast("充值成功获得16000金币"); MiniGameSdk.API.showToast("充值成功获得16000金币");
break; break;
case "gold_4": case "gold_4":
cc.fx.GameTool.changeCoin(32000); cc.fx.GameTool.changeCoin(32000);
coin = 32000;
price = 12800;
MiniGameSdk.API.showToast("充值成功获得32000金币"); MiniGameSdk.API.showToast("充值成功获得32000金币");
break; break;
case "gold_5": case "gold_5":
cc.fx.GameTool.changeCoin(100000); cc.fx.GameTool.changeCoin(100000);
coin = 100000;
price = 32800;
MiniGameSdk.API.showToast("充值成功获得100000金币"); MiniGameSdk.API.showToast("充值成功获得100000金币");
break; break;
case "gold_6": case "gold_6":
cc.fx.GameTool.changeCoin(240000); cc.fx.GameTool.changeCoin(240000);
coin = 240000;
price = 64800;
MiniGameSdk.API.showToast("充值成功获得240000金币"); MiniGameSdk.API.showToast("充值成功获得240000金币");
break; break;
} }
const buyData = {
item_id:productId,
item_num:coin,
item_price:price,
cost_type:"cash"
}
cc.fx.GameTool.shushu_Track("shop_buy",buyData);
}, },
formatDate(date: Date): string { formatDate(date: Date): string {
@ -900,7 +922,34 @@ var GameTool = {
item_price: data.item_price, item_price: data.item_price,
cost_type: data.cost_type, cost_type: data.cost_type,
} }
console.log("数据:",eventData); break;
case "init_order": //发起充值时
eventData = {
order_id: data.outTradeNo,
pay_amount: data.price,
payment_name: data.payment_name,
payment_num: data.payment_num,
payment_type: data.type,
}
break;
case "payment": //发起充值时
eventData = {
order_id: data.outTradeNo,
pay_amount: data.price,
payment_name: data.payment_name,
payment_num: data.payment_num,
payment_type: data.type,
}
break;
case "payment_fail": //发起充值时
eventData = {
order_id: data.outTradeNo,
pay_amount: data.price,
payment_name: data.payment_name,
payment_num: data.payment_num,
payment_type: data.type,
fail_reason: data.fail_reason,
}
break; break;
} }
// MiniGameSdk.API.shushu_Track(name,eventData); // MiniGameSdk.API.shushu_Track(name,eventData);

Binary file not shown.

Before

Width:  |  Height:  |  Size: 94 KiB

View File

@ -1,38 +0,0 @@
{
"ver": "2.3.7",
"uuid": "707d9e1d-7462-4b68-abd1-ae01b980fde2",
"importer": "texture",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 1057,
"height": 361,
"platformSettings": {},
"subMetas": {
"ice2": {
"ver": "1.0.6",
"uuid": "097fb6b3-a8de-49fd-8da8-5a65561d8fc2",
"importer": "sprite-frame",
"rawTextureUuid": "707d9e1d-7462-4b68-abd1-ae01b980fde2",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 1057,
"height": 361,
"rawWidth": 1057,
"rawHeight": 361,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"subMetas": {}
}
}
}

View File

@ -262,7 +262,9 @@
], ],
"_srcBlendFactor": 770, "_srcBlendFactor": 770,
"_dstBlendFactor": 771, "_dstBlendFactor": 771,
"_spriteFrame": null, "_spriteFrame": {
"__uuid__": "11ca11bf-c649-466a-aa87-a88c13ef46ca"
},
"_type": 0, "_type": 0,
"_sizeMode": 1, "_sizeMode": 1,
"_fillType": 0, "_fillType": 0,
@ -274,7 +276,9 @@
"_fillStart": 0, "_fillStart": 0,
"_fillRange": 0, "_fillRange": 0,
"_isTrimmedMode": true, "_isTrimmedMode": true,
"_atlas": null, "_atlas": {
"__uuid__": "f2c494b7-b6df-488f-b194-358235b0f180"
},
"_id": "" "_id": ""
}, },
{ {

View File

@ -1647,7 +1647,7 @@
"component": "", "component": "",
"_componentId": "48bfeZuYFZE2qmgxbW2IigB", "_componentId": "48bfeZuYFZE2qmgxbW2IigB",
"handler": "buyProduct", "handler": "buyProduct",
"customEventData": "gold_pack_1" "customEventData": "gold_1"
}, },
{ {
"__type__": "de906iE/HVHpI6VO7IMvKaI", "__type__": "de906iE/HVHpI6VO7IMvKaI",
@ -2343,7 +2343,7 @@
"component": "", "component": "",
"_componentId": "48bfeZuYFZE2qmgxbW2IigB", "_componentId": "48bfeZuYFZE2qmgxbW2IigB",
"handler": "buyProduct", "handler": "buyProduct",
"customEventData": "gold_pack_2" "customEventData": "gold_2"
}, },
{ {
"__type__": "de906iE/HVHpI6VO7IMvKaI", "__type__": "de906iE/HVHpI6VO7IMvKaI",
@ -3039,7 +3039,7 @@
"component": "", "component": "",
"_componentId": "48bfeZuYFZE2qmgxbW2IigB", "_componentId": "48bfeZuYFZE2qmgxbW2IigB",
"handler": "buyProduct", "handler": "buyProduct",
"customEventData": "gold_pack_3" "customEventData": "gold_3"
}, },
{ {
"__type__": "de906iE/HVHpI6VO7IMvKaI", "__type__": "de906iE/HVHpI6VO7IMvKaI",
@ -3735,7 +3735,7 @@
"component": "", "component": "",
"_componentId": "48bfeZuYFZE2qmgxbW2IigB", "_componentId": "48bfeZuYFZE2qmgxbW2IigB",
"handler": "buyProduct", "handler": "buyProduct",
"customEventData": "gold_pack_4" "customEventData": "gold_4"
}, },
{ {
"__type__": "de906iE/HVHpI6VO7IMvKaI", "__type__": "de906iE/HVHpI6VO7IMvKaI",
@ -4431,7 +4431,7 @@
"component": "", "component": "",
"_componentId": "48bfeZuYFZE2qmgxbW2IigB", "_componentId": "48bfeZuYFZE2qmgxbW2IigB",
"handler": "buyProduct", "handler": "buyProduct",
"customEventData": "gold_pack_5" "customEventData": "gold_5"
}, },
{ {
"__type__": "de906iE/HVHpI6VO7IMvKaI", "__type__": "de906iE/HVHpI6VO7IMvKaI",
@ -5127,7 +5127,7 @@
"component": "", "component": "",
"_componentId": "48bfeZuYFZE2qmgxbW2IigB", "_componentId": "48bfeZuYFZE2qmgxbW2IigB",
"handler": "buyProduct", "handler": "buyProduct",
"customEventData": "gold_pack_6" "customEventData": "gold_6"
}, },
{ {
"__type__": "de906iE/HVHpI6VO7IMvKaI", "__type__": "de906iE/HVHpI6VO7IMvKaI",

View File

@ -31,12 +31,12 @@ export default class NewClass extends cc.Component {
openShop() { openShop() {
// 商品数据数组 // 商品数据数组
const products = [ const products = [
{ product_id: "gold_pack_1", name: "金币包1", price: 600, coin:1200, title: "3x2六档金币" }, { product_id: "gold_1", name: "金币包1", price: 600, coin:1200, title: "3x2六档金币" },
{ product_id: "gold_pack_2", name: "金币包2", price: 3600, coin:8000, title: "" }, { product_id: "gold_2", name: "金币包2", price: 3600, coin:8000, title: "" },
{ product_id: "gold_pack_3", name: "金币包3", price: 6800, coin:16000, title: "" }, { product_id: "gold_3", name: "金币包3", price: 6800, coin:16000, title: "" },
{ product_id: "gold_pack_4", name: "金币包4", price: 12800, coin:32000, title: "" }, { product_id: "gold_4", name: "金币包4", price: 12800, coin:32000, title: "" },
{ product_id: "gold_pack_5", name: "金币包5", price: 32800, coin:100000, title: "" }, { product_id: "gold_5", name: "金币包5", price: 32800, coin:100000, title: "" },
{ product_id: "gold_pack_6", name: "金币包6", price: 64800, coin:240000, title: "" }, { product_id: "gold_6", name: "金币包6", price: 64800, coin:240000, title: "" },
]; ];
for (let i = 1; i <= 6 && i < this.itemList.children.length; i++) { for (let i = 1; i <= 6 && i < this.itemList.children.length; i++) {
const spriteComp = this.itemList.children[i].children[0].getComponent(cc.Sprite); const spriteComp = this.itemList.children[i].children[0].getComponent(cc.Sprite);
@ -63,7 +63,13 @@ export default class NewClass extends cc.Component {
//关闭商店界面 //关闭商店界面
closeShop() { closeShop() {
//销毁预制体 //销毁预制体
this.shop.destroy(); if(this.node.parent.getComponent("JiaZai")){
this.node.parent.getComponent("JiaZai").closeShop();
}
else if(this.node.parent.getComponent("SceneManager")){
this.node.parent.getComponent("SceneManager").closeShop();
}
// this.shop.destroy();
} }
//点击充值购买 //点击充值购买
@ -99,11 +105,40 @@ export default class NewClass extends cc.Component {
break; break;
} }
console.log("获得商品id:",id,count,price); console.log("获得商品id:",id,count,price);
// 判断设备系统
let systemType = "Android";
try {
const systemInfo = wx.getSystemInfoSync();
if (systemInfo.platform === 'ios') {
systemType = "iOS";
}
} catch (e) {
console.error('获取系统信息失败', e);
}
const data = {
outTradeNo:Utils.outTradeNo,
price:price,
payment_name:productId,
payment_num:1,
type:systemType,
}
cc.fx.GameTool.shushu_Track("init_order",data);
Utils.buyProp(id,count,price,(res)=>{ Utils.buyProp(id,count,price,(res)=>{
console.log("获得充值结果",res); console.log("获得充值结果",res);
if(res == null){ if(res == null){
MiniGameSdk.API.showToast("网络异常,充值失败请稍后再试"); MiniGameSdk.API.showToast("网络异常,充值失败请稍后再试");
this.btn_Touch = true; this.btn_Touch = true;
const dataFail = {
outTradeNo:Utils.outTradeNo,
price:price,
payment_name:productId,
payment_num:1,
type:systemType,
fail_reason:"网络异常,没有拉起支付",
}
cc.fx.GameTool.shushu_Track("payment_fail",dataFail);
return; return;
} }
else{ else{
@ -112,22 +147,61 @@ export default class NewClass extends cc.Component {
if(data.data.pay_state == 1){ if(data.data.pay_state == 1){
this.btn_Touch = true; this.btn_Touch = true;
MiniGameSdk.API.showToast("取消充值"); MiniGameSdk.API.showToast("取消充值");
const dataFail2 = {
outTradeNo:Utils.outTradeNo,
price:price,
payment_name:productId,
payment_num:1,
type:systemType,
fail_reason:"用户取消支付",
}
cc.fx.GameTool.shushu_Track("payment_fail",dataFail2);
} }
else if(data.data.pay_state == 2){ else if(data.data.pay_state == 2){
this.btn_Touch = true; this.btn_Touch = true;
Utils.setPayInfo((data) => { Utils.setPayInfo((data) => {
console.log("设置轮训结果:",data); console.log("设置轮训结果:",data);
if(data.code === 1){
})
MiniGameSdk.API.showToast("充值成功"); MiniGameSdk.API.showToast("充值成功");
cc.fx.GameTool.shopBuy(productId); cc.fx.GameTool.shopBuy(productId);
console.log("充值成功获得金币"); console.log("充值成功获得金币");
const dataSuccess = {
outTradeNo:Utils.outTradeNo,
price:price,
payment_name:productId,
payment_num:1,
type:systemType,
}
cc.fx.GameTool.shushu_Track("payment_fail",dataSuccess);
}
else{
MiniGameSdk.API.showToast("网络异常,充值奖励将在登录后再次发放");
const dataFail4 = {
outTradeNo:Utils.outTradeNo,
price:price,
payment_name:productId,
payment_num:1,
type:systemType,
fail_reason:"成功付款,但是发货时请求服务器失败,充值成功未发货",
}
cc.fx.GameTool.shushu_Track("payment_fail",dataFail4);
}
NumberToImage.numberToImageNodes(cc.fx.GameConfig.GM_INFO.coin, 30, 15, "coin_", this.coin, true); NumberToImage.numberToImageNodes(cc.fx.GameConfig.GM_INFO.coin, 30, 15, "coin_", this.coin, true);
this.node.parent.getComponent("JiaZai").updateCoin(); this.node.parent.getComponent("JiaZai").updateCoin();
})
} }
else{ else{
NumberToImage.numberToImageNodes(cc.fx.GameConfig.GM_INFO.coin, 30, 15, "coin_", this.coin, true); NumberToImage.numberToImageNodes(cc.fx.GameConfig.GM_INFO.coin, 30, 15, "coin_", this.coin, true);
this.node.parent.getComponent("JiaZai").updateCoin(); this.node.parent.getComponent("JiaZai").updateCoin();
const dataFail3 = {
outTradeNo:Utils.outTradeNo,
price:price,
payment_name:productId,
payment_num:1,
type:systemType,
fail_reason:"拉起支付后,付款时网络异常付款失败",
}
cc.fx.GameTool.shushu_Track("payment_fail",dataFail3);
} }
}) })
} }