浏览代码

添加snb支付

slambb 3 年之前
父节点
当前提交
b565ad592c

+ 1 - 0
assets/Prefabs/NBuildings/Labour/Labour_205_Holy_Farmland.prefab

@@ -3747,6 +3747,7 @@
     "harvestNode": {
       "__id__": 95
     },
+    "isHarvest": false,
     "_id": ""
   },
   {

文件差异内容过多而无法显示
+ 2969 - 197
assets/Prefabs/UI/store/StoreContainer.prefab


+ 1 - 1
assets/Scene/Login.fire

@@ -159,7 +159,7 @@
       "__type__": "cc.Vec3",
       "x": 0,
       "y": 0,
-      "z": 525.6774200971543
+      "z": 523.079343885801
     },
     "_scale": {
       "__type__": "cc.Vec3",

文件差异内容过多而无法显示
+ 411 - 257
assets/Scene/MyCityScene - 004.fire


+ 1 - 0
assets/Script/Network/netUtils.ts

@@ -25,6 +25,7 @@ var utils = {
         loginTokenAndVerification: 'comUsers/loginTokenAndVerification',
         //平台账户相关信息
         userInfo: 'comUsers/getUserInfo',
+        userSnbInfo: 'comUsers/getUserSnb',
         //角色的信息和属性
         playerInfo: 'comPlayers/getPlayerAndBattleAttribute',
         playerPushInfo:'comPlayers/playerPushInfo',

+ 124 - 26
assets/Script/UI/StoreView.js

@@ -81,6 +81,26 @@ cc.Class({
             default: null,
             type: cc.Node,
         },
+
+        //购买种类数值
+        toggleInputValue: {
+            default: '1',
+            visible: false
+        },
+        PayCNTPopViewNameLabel: {
+            default: null,
+            type: cc.Label,
+        },
+        PayCNTPopViewPriceLabel: {
+            default: null,
+            type: cc.Label,
+        },
+        PayCNTPopViewMutureDurLabel: {
+            default: null,
+            type: cc.Label,
+        },
+
+        isPlaying: false,
     },
     HiddenAll() {
         if (this.Seed.active)
@@ -214,8 +234,17 @@ cc.Class({
             node.setSiblingIndex(dst);
         }
     },
+    OpentSNBExchangeToCNT() {
+        //更新数据
+        this.snbAmountLabel.string = GlobalD.GameData.SNB;
+        this.ExchangePopView.active = true;
+    },
     SNBExchangeToCNT() {
         GlobalD.GameData.onSnbToCnt(this.snbAmount, (data) => {
+
+            //更新数据
+            this.snbAmountLabel.string = GlobalD.GameData.SNB;
+
             this.ExchangePopView.active = false;
             console.log('data=', data)
             // console.log('res=', res)
@@ -225,9 +254,14 @@ cc.Class({
         this.buySeedIndex = myIndex;
         this.PayCNTPopView.active = true;
         // console.log('this.mySeedList[this.buySeedIndex] =',this.mySeedList[this.buySeedIndex])
-        this.PayCNTPopView.getChildByName("BG").getChildByName("BG1_sprite_splash").getChildByName("NameLabel").getChildByName("label").getComponent(cc.Label).string = this.mySeedList[this.buySeedIndex].name;
-        this.PayCNTPopView.getChildByName("BG").getChildByName("BG1_sprite_splash").getChildByName("PriceLabel").getChildByName("label").getComponent(cc.Label).string = this.mySeedList[this.buySeedIndex].priceCnt + ' CNT';
-        this.PayCNTPopView.getChildByName("BG").getChildByName("BG1_sprite_splash").getChildByName("MutureDurLabel").getChildByName("label").getComponent(cc.Label).string = this.mySeedList[this.buySeedIndex].maturity;
+        // this.PayCNTPopView.getChildByName("BG").getChildByName("BG1_sprite_splash").getChildByName("NameLabel").getChildByName("label").getComponent(cc.Label).string = this.mySeedList[this.buySeedIndex].name;
+        // this.PayCNTPopView.getChildByName("BG").getChildByName("BG1_sprite_splash").getChildByName("PriceLabel").getChildByName("label").getComponent(cc.Label).string = this.mySeedList[this.buySeedIndex].priceCnt + ' CNT';
+        // this.PayCNTPopView.getChildByName("BG").getChildByName("BG1_sprite_splash").getChildByName("MutureDurLabel").getChildByName("label").getComponent(cc.Label).string = this.mySeedList[this.buySeedIndex].maturity;
+        this._updatePrice();
+        // this.PayCNTPopViewNameLabel.string = this.mySeedList[this.buySeedIndex].name;
+        // this.PayCNTPopViewPriceLabel.string = this.mySeedList[this.buySeedIndex].priceCnt + ' CNT';
+        // this.PayCNTPopViewMutureDurLabel.string = this.mySeedList[this.buySeedIndex].maturity;
+
     },
     onPaySNBPopView(myIndex) {
         this.buySeedIndex = myIndex;
@@ -236,6 +270,7 @@ cc.Class({
         this.PaySNBPopView.getChildByName("BG").getChildByName("BG1_sprite_splash").getChildByName("NameLabel").getChildByName("label").getComponent(cc.Label).string = this.mySeedList[this.buySeedIndex].name;
         this.PaySNBPopView.getChildByName("BG").getChildByName("BG1_sprite_splash").getChildByName("PriceLabel").getChildByName("label").getComponent(cc.Label).string = this.mySeedList[this.buySeedIndex].priceCnt + ' SNB';
         this.PaySNBPopView.getChildByName("BG").getChildByName("BG1_sprite_splash").getChildByName("MutureDurLabel").getChildByName("label").getComponent(cc.Label).string = this.mySeedList[this.buySeedIndex].maturity;
+
     },
     PayCNT() {
         console.log('this.cntAmount=', this.cntAmount)
@@ -255,9 +290,20 @@ cc.Class({
             seedId: this.mySeedList[this.buySeedIndex].id,
             currentAmount: currentAmount //把当前背包的数据传进去
         });
-
-        GlobalD.GameData.payCNT(this.cntAmount * parseInt(this.mySeedList[this.buySeedIndex].priceCnt), 4, this.mySeedList[this.buySeedIndex].id + "", (data) => {
+        let playAmount = this.cntAmount * parseInt(this.mySeedList[this.buySeedIndex].priceCnt);
+        if (0 === playAmount) {
+            GlobalD.GameData.showToast(cc.find("Canvas/UICamera"), "请输入购买数量", 1);
+            return;
+        }
+        // if (this.isPlaying) {
+        //     GlobalD.GameData.showToast(cc.find("Canvas/UICamera"), "购买过快!", 1);
+        //     return;
+        // }
+        // this.isPlaying = true;
+        // GlobalD.GameData.showToast(cc.find("Canvas/UICamera"), "区块确认中,请耐心等待!", 120);
+        GlobalD.GameData.payCNT(playAmount, 4, this.mySeedList[this.buySeedIndex].id + "", (data) => {
             const [err, tx] = data;
+            // this.isPlaying = false;
             if (err === null) {
                 // TODO 成功, 支付为链上操作,需要提供回调接口给这边服务端确认交易成功后修改购买订单结果
                 console.log(tx) // 交易hash,唯一标识符
@@ -278,9 +324,9 @@ cc.Class({
                             if (0 === value.code) {
                                 this.unschedule(this.AutoGetSeedsData);
                                 console.log("轮询种子购买成功");
-                                GlobalD.GameData.showToast(cc.find("Canvas/UICamera"), "种子购买成功!", 5);
+                                GlobalD.GameData.showToast(cc.find("Canvas/UICamera"), "种子购买成功!", 1);
 
-                                this.PayCNTPopView.active = false;
+                                // this.PayCNTPopView.active = false;
 
                                 //直接重新初始化一下列表,
                                 this.buildingViewScript.onUpdateList();
@@ -290,7 +336,7 @@ cc.Class({
                 this.schedule(this.AutoGetSeedsData, 5);
             } else {
                 console.log(err)
-                GlobalD.GameData.showToast(cc.find("Canvas/UICamera"), err, 5);
+                GlobalD.GameData.showToast(cc.find("Canvas/UICamera"), err, 2);
             }
 
         });
@@ -299,29 +345,38 @@ cc.Class({
         console.log('this.snbAmount=', this.cntAmount)
         console.log('priceSnb price=', this.mySeedList[this.buySeedIndex].priceSnb)
         console.log('this.snbAmount price=', this.cntAmount * parseInt(this.mySeedList[this.buySeedIndex].priceSnb))
-        // let currentAmount = 0;
-        // for (let i = 0; i < this.myWareHouseSeedList.length; i++) {
-        //     if (this.myWareHouseSeedList[i].id == this.mySeedList[this.buySeedIndex].id) {
-        //         currentAmount = this.myWareHouseSeedList[i].amount;
-        //     }
-        // }
-        //当前背包的数量
-        // console.log("currentAmount:", {
-        //     seedId: this.mySeedList[this.buySeedIndex].id,
-        //     currentAmount: currentAmount //把当前背包的数据传进去
-        // });
-        console.log("支付价格:"+this.cntAmount * parseInt(this.mySeedList[this.buySeedIndex].priceCnt*5));
-        GlobalD.GameData.onBuySeedsWithSNB(this.cntAmount * parseInt(this.mySeedList[this.buySeedIndex].priceCnt*5), this.mySeedList[this.buySeedIndex].id, (res, value) => {
-            console.log('snb res =====', res) // 交易hash,唯一标识符
-            console.log('snb value =====', value) // 交易hash,唯一标识符
+        console.log("支付价格:" + this.cntAmount * parseInt(this.mySeedList[this.buySeedIndex].priceSnb));
+        let playAmount = this.cntAmount * parseInt(this.mySeedList[this.buySeedIndex].priceSnb);
+        if (0 === playAmount) {
+            GlobalD.GameData.showToast(cc.find("Canvas/UICamera"), "请输入购买数量", 1);
+            return;
+        }
+
+        if (this.isPlaying) {
+            GlobalD.GameData.showToast(cc.find("Canvas/UICamera"), "购买过快!", 1);
+            return;
+        }
+        GlobalD.GameData.showToast(cc.find("Canvas/UICamera"), "支付处理中...", 10);
+
+        this.isPlaying = true;
+        GlobalD.GameData.onBuySeedsWithSNB(playAmount, this.mySeedList[this.buySeedIndex].id, (res, value) => {
+            // console.log("SNB购买后", value);
+            this.isPlaying = false;
             if (0 === value.code) {
                 //todo 种子
-                GlobalD.GameData.showToast(cc.find("Canvas/UICamera"), "种子购买成功!", 5);
-                this.PaySNBPopView.active = false;
+                GlobalD.GameData.showToast(cc.find("Canvas/UICamera"), "种子购买成功!", 1);
+                // this.PayCNTPopView.active = false;
+
+                //重新获取一下snb,会自动更新到面板
+                GlobalD.GameData.onGetUserSnb();
+
                 //直接重新初始化一下列表,
                 this.buildingViewScript.onUpdateList();
+
+                //更新日志数据
+                cc.find("GameNode/ManageDapp").getComponent("ManageDapp").onUpdateSnbList();
             } else {
-                GlobalD.GameData.showToast(cc.find("Canvas/UICamera"), value.msg, 5);
+                GlobalD.GameData.showToast(cc.find("Canvas/UICamera"), value.msg, 2);
             }
         });
     },
@@ -338,4 +393,47 @@ cc.Class({
         // 这里的 customEventData 参数就等于你之前设置的 "foobar"
         this.snbAmount = parseInt(text);
     },
+
+    onToggleInput(value, evnentData) {
+        this.toggleInputValue = evnentData;
+        this._updatePrice();
+    },
+
+    _updatePrice() {
+        switch (this.toggleInputValue) {
+            case "1":
+                // this.totalPriceValue = 700 * this.inputInviteValue;
+                // this.totalPriceLabel.string = this.totalPriceValue + "CNT";
+                this.PayCNTPopViewNameLabel.string = this.mySeedList[this.buySeedIndex].name;
+                this.PayCNTPopViewPriceLabel.string = this.mySeedList[this.buySeedIndex].priceCnt + ' CNT';
+                this.PayCNTPopViewMutureDurLabel.string = this.mySeedList[this.buySeedIndex].maturity;
+                break;
+            case "2":
+                // this.totalPriceValue = 2500 * this.inputInviteValue;
+                // this.totalPriceLabel.string = this.totalPriceValue + "CNT";
+                this.PayCNTPopViewNameLabel.string = this.mySeedList[this.buySeedIndex].name;
+                this.PayCNTPopViewPriceLabel.string = this.mySeedList[this.buySeedIndex].priceSnb + ' SNB';
+                this.PayCNTPopViewMutureDurLabel.string = this.mySeedList[this.buySeedIndex].maturity;
+                break;
+            default:
+                console.error("this.toggleInputValue 不是1 2 3!", this.toggleInputValue);
+                break;
+        }
+
+    },
+    //根据状态吊起不同支付
+    onSwitchPlayType() {
+        switch (this.toggleInputValue) {
+            case "1"://cnt 支付
+                this.PayCNT();
+                break;
+            case "2": //snb 支付
+                this.PaySNB();
+                break;
+            default:
+                console.error("状态吊起错误", this.toggleInputValue);
+                GlobalD.GameData.showToast(cc.find("Canvas/UICamera"), "请先选择支付方式", 1);
+                break;
+        }
+    }
 });

+ 12 - 12
assets/Script/adpp/ManageDapp.js

@@ -154,39 +154,39 @@ cc.Class({
             this.cntData = res.data;
         });
         this.cntShowNode.on(cc.Node.EventType.TOUCH_END, function (event) {
-            let agent_level = GlobalD.Dapp.UserInfo.agent_level;
-            if(0 === agent_level){
-                GlobalD.GameData.showToast(cc.find("Canvas/UICamera"), "请先升级村长!", 120);
-                return;
-            }
-            this.ListInfoNode.getComponent("dappListInfo").onShowList("cntList", this.cntData);
+            // let agent_level = GlobalD.Dapp.UserInfo.agent_level;
+            // if(0 === agent_level){
+            //     GlobalD.GameData.showToast(cc.find("Canvas/UICamera"), "请先升级村长!", 120);
+            //     return;
+            // }
+            this.ListInfoNode.getComponent("dappListInfo").onShowList("cntList", this.cntData, true);
         }, this);
         //snb数据
         GlobalD.GameData.onGetSnbInfoList(this.snbPage, this.snbLimit, (data) => {
-            console.log("==========",data);
+            // console.log("==========",data);
             this.snbData = data.content;
         });
 
         this.snbShowNode.on(cc.Node.EventType.TOUCH_END, function (event) {
-            this.ListInfoNode.getComponent("dappListInfo").onShowList("snbList", this.snbData);
+            this.ListInfoNode.getComponent("dappListInfo").onShowList("snbList", this.snbData, true);
         }, this);
 
 
     },
 
-    onUpdateCntList(){
+    onUpdateCntList() {
         GlobalD.GameData.onCntLog(this.cntPage, this.cntLimit, (data) => {
             const { err, res } = data;
             this.cntData = res.data;
-            this.ListInfoNode.getComponent("dappListInfo").onShowList("cntList", this.cntData);
+            this.ListInfoNode.getComponent("dappListInfo").onShowList("cntList", this.cntData, false);
         });
 
     },
-    onUpdateSnbList(){
+    onUpdateSnbList() {
         GlobalD.GameData.onGetSnbInfoList(this.snbPage, this.snbLimit, (data) => {
             // console.log("==========",data);
             this.snbData = data.content;
-            this.ListInfoNode.getComponent("dappListInfo").onShowList("snbList", this.snbData);
+            this.ListInfoNode.getComponent("dappListInfo").onShowList("snbList", this.snbData, false);
         });
     },
 

+ 2 - 2
assets/Script/adpp/dappListInfo.js

@@ -115,14 +115,14 @@ cc.Class({
         this.cntData = list;
     },
     //切换数据
-    onShowList(type, list) {
+    onShowList(type, list, isActive) {
         // console.log("onShowList:", type, list);
         //获取余额
         GlobalD.GameData.onCntCanWithdrawBalance((data) => {
             // console.log("站内收益余额:", GlobalD.GameData.CNTDrawBalance);
             this.outCNTValue.string = "CNT余额:" + Math.floor(GlobalD.GameData.CNTDrawBalance * 100) / 100;
         });
-        this.node.active = true;
+        this.node.active = isActive;
         if (type == "snbList") {
             this.snbData = list;
             this.cntIndex = this.start_index;

+ 8 - 3
assets/Script/build/LeaseFarmlandInfo.js

@@ -141,7 +141,9 @@ cc.Class({
             default: null,
             type: cc.Node,
             serializable: true,
-        }
+        },
+
+        isHarvest: false
     },
 
     // LIFE-CYCLE CALLBACKS:
@@ -302,9 +304,11 @@ cc.Class({
 
         this.harvestNode.on(cc.Node.EventType.TOUCH_START, () => {
             console.log("点击收获");
+            //限制点击多次
+            if (this.isHarvest) return;
+            this.isHarvest = true;
 
             let data = { landId: this.leaseLandInfo.configLandId };
-
             //果实收入仓库,重置土地种植信息
             GlobalD.GameData.onAddFruit(data, (res, value) => {
                 // console.log(value);
@@ -314,7 +318,6 @@ cc.Class({
                     this.midSliderNode.active = false
                     let _workingBuilding = this.node.getComponent("WorkingBuilding");
                     _workingBuilding.onSetGrow(0, null);
-
                     //更新仓库列表
                     let BuildingView = cc.find("Canvas/UICamera/BuildingContainer/BuildingView").getComponent("BuildingView");
                     BuildingView.onUpdateList();
@@ -327,6 +330,8 @@ cc.Class({
                         console.log("finish toast!");
                     });
                 }
+                //处理信息后开放
+                this.isHarvest = false;
             });
         })
 

+ 39 - 22
assets/Script/public/GameData.js

@@ -71,10 +71,12 @@ cc.Class({
         },
 
 
+
         toast: null,
         scheduleObj: null,
         toastCallback: null,
         isStart: true,
+        isInit: false,
 
         /**
          * 限制重复触发支付, 正在支付中转态,
@@ -98,6 +100,16 @@ cc.Class({
         }
     },
     start() {
+        cc.loader.loadRes("prefab/gameToast", function (err, texture) {
+            this.toast = cc.instantiate(texture);
+            this.toast.parent = cc.find("Canvas/UICamera");
+            this.toast.zIndex = 999;
+            this.toast.active = false;
+            this.scheduleObj = this.schedule(() => {
+                this.updateToast();
+            }, 1);
+        }.bind(this));
+
         this._tiledMap = GlobalD.TiledMap._tiledMap;
         //调用初始化dapp
         this.isDebugMode(GlobalD.dapp);
@@ -1130,6 +1142,15 @@ cc.Class({
         })
     },
 
+    //获取用户的snb
+    onGetUserSnb(callback) {
+        utils.get(utils.api.userSnbInfo, {}, (res, value) => {
+            GlobalD.GameData.SetSNB(value.data.SNB);
+            if (callback)
+                callback(res, value);
+        })
+    },
+
     /**
      * 支付cnt操作
      * @param {*} amount // 需支付金额
@@ -1155,7 +1176,7 @@ cc.Class({
             return;
         }
         this.isPlayingCnt = true;
-        GlobalD.GameData.showToast(cc.find("Canvas/UICamera"), "支付处理中...", 20, () => {
+        GlobalD.GameData.showToast(cc.find("Canvas/UICamera"), "支付处理中...", 5, () => {
             console.log("finish toast!支付处理中...");
         });
 
@@ -1338,7 +1359,7 @@ cc.Class({
     onGetSnbInfoList(page, limit, callback) {
 
         utils.get(utils.api.snbList, { page: page, limit: limit }, (res, value) => {
-            console.log("snb操作日志", value);
+            // console.log("snb操作日志", value);
             if (0 === value.code) {
                 if (callback)
                     callback(value.data);
@@ -1354,40 +1375,36 @@ cc.Class({
 
 
     updateToast() {
-        if (this.toastEndTime <= 0 && this.isStart) {
+        if (this.toastEndTime <= 0) {
             this.toast.active = false
-            if (this.toastCallback != null && this.toastCallback != undefined) {
-                this.toastCallback();
-                // console.log(this.toastCallback);
+            if (this.isStart) {
+                if (this.toastCallback != null && this.toastCallback != undefined) {
+                    this.toastCallback();
+                    // console.log(this.toastCallback);
+                }
+                this.isStart = false;
             }
-            this.isStart = false;
-        } else {
-            this.toastEndTime--;
+            // console.log("this.toast.active:" + this.toast.active);
         }
+        this.toastEndTime--;
     },
 
     showToast(parent, content, time, callback) {
-        this.toastCallback = callback;
+        if (callback) {
+            this.toastCallback = callback;
+        } else {
+            this.toastCallback = null;
+        }
+
         this.isStart = true;
         if (this.toast) {
+            // console.log(this.toast.active);
             this.toast.active = true;
             this.toast.parent = parent;
             this.toast.zIndex = 999;
             let DetailLabel = this.toast.getChildByName('DetailLabel');
             DetailLabel.getComponent(cc.Label).string = content;
             this.toastEndTime = time;
-        } else {
-            cc.loader.loadRes("prefab/gameToast", function (err, texture) {
-                this.toast = cc.instantiate(texture);
-                this.toast.parent = parent;
-                this.toast.zIndex = 999;
-                let DetailLabel = this.toast.getChildByName('DetailLabel');
-                DetailLabel.getComponent(cc.Label).string = content;
-                this.toastEndTime = time;
-                this.scheduleObj = this.schedule(() => {
-                    this.updateToast();
-                }, 1);
-            }.bind(this));
         }
     }
 

+ 2 - 2
assets/UI/NPublic/BuySeedBG.png.meta

@@ -24,8 +24,8 @@
       "height": 596,
       "rawWidth": 599,
       "rawHeight": 601,
-      "borderTop": 0,
-      "borderBottom": 0,
+      "borderTop": 227,
+      "borderBottom": 255,
       "borderLeft": 0,
       "borderRight": 0,
       "subMetas": {}

部分文件因为文件数量过多而无法显示