Ver Fonte

修改部分支付逻辑

slambb há 3 anos atrás
pai
commit
f56143ec3e

+ 9 - 5
assets/Script/Lease/LeaseInfo.js

@@ -155,21 +155,25 @@ cc.Class({
         }
         let _self = this;
         //cntAmount,payType,itemType,callback
-        Global.game.payCNT(this.totalPriceValue, 1, this.toggleInputValue, (data) => {
+        GlobalD.GameData.payCNT(this.totalPriceValue, 1, this.toggleInputValue, (data) => {
             console.log("土地支付", this.totalPriceValue, "==", 1, "==", this.toggleInputValue);
             console.log("支付data:", data);
-            gameToast.getInstance().show(this.ToastParent, "支付成功!", 3, () => {
-                console.log("finish toast!");
-            }, this);
+            const [err, tx] = data;
+       
             if (err === null) {
                 // TODO 成功, 支付为链上操作,需要提供回调接口给这边服务端确认交易成功后修改购买订单结果
                 console.log(tx) // 交易hash,唯一标识符
-
+                gameToast.getInstance().show(this.ToastParent, "支付成功!", 3, () => {
+                    console.log("finish toast!");
+                }, this);
                 //解锁土地操作
                 this.leaseFarmlandInfoNode.getComponent("LeaseFarmlandInfo").onUnlockLand();
 
             } else {
                 console.log(err)
+                gameToast.getInstance().show(this.ToastParent, err, 3, () => {
+                    console.log("finish toast!");
+                }, this);
             }
         });
         // GlobalD.dapp.bindParent(_self.inputInviteValue).then((data) => {

+ 9 - 9
assets/Script/Network/dapp.js

@@ -10,11 +10,11 @@ cc.Class({
     // LIFE-CYCLE CALLBACKS:
 
     onLoad() {
-        cc.view.enableAutoFullScreen(false);
+        // cc.view.enableAutoFullScreen(false);
         cc.game.addPersistRootNode(this.node);
-        let _self = this;
-
+    
         async function dappInit() {
+            console.log("初始化 dappInit");
             let dapp = GlobalD.dapp = new Dapp()
             // gameToast.getInstance().show("loding...",5,()=>{
             //     console.log("finish toast!");
@@ -100,21 +100,21 @@ cc.Class({
                             })
                             //需要提前拉取一下土地配置,用于初始化地图土地
                             utils.get(utils.api.landConfig, {}, (res, value) => {
-                                if(0 === value.code){
+                                if (0 === value.code) {
                                     GlobalD.ConfigLand = value.data;
-                                }else{
+                                } else {
                                     console.warn("未能读取到config土地?");
                                 }
                             })
-                         
+
                             utils.get(utils.api.userLandList, {}, (res, value) => {
-                                if(0 === value.code){
+                                if (0 === value.code) {
                                     GlobalD.UserLeaseLand = value.data;
-                                }else{
+                                } else {
                                     console.warn("读取到用户的土地错误?");
                                 }
                             })
-                            
+
 
                         } else {
                             console.log(res, value);

+ 6 - 7
assets/Script/UI/ManageBuildings.js

@@ -495,11 +495,11 @@ cc.Class({
             housingTemp_farmland.parent = this.BuildingsParent;
             var endPos = GlobalD.TiledMap._getTheMiddleLocationFromtilePos(cc.v2(_configLand[i].posX, _configLand[i].posY));
             housingTemp_farmland.setPosition(endPos.x, endPos.y);
-
+            let leaseFarmlandInfoScript = housingTemp_farmland.getComponent("LeaseFarmlandInfo");
+            //记录config的土地信息
+            leaseFarmlandInfoScript.setConfigLandInfo(_configLand[i]);
             for (let j = 0; j < _userLeaseLand.length; j++) {
-                let leaseFarmlandInfoScript = housingTemp_farmland.getComponent("LeaseFarmlandInfo");
-                //记录config的土地信息
-                leaseFarmlandInfoScript.setConfigLandInfo(_configLand[i]);
+              
                 //记录已经租赁的信息(租赁里面包含了seedInfo,如果有种植的话,对应的种植信息会有)
                 if (_userLeaseLand[j].configLandId == _configLand[i].id) {
                     let _leaseLandInfo = _userLeaseLand[j];
@@ -886,8 +886,7 @@ cc.Class({
     Sale() {
 
     },
-    Exchange()
-    {
-        
+    Exchange() {
+
     }
 });

+ 1 - 1
assets/Script/adpp/villageAndMayor.js

@@ -38,7 +38,7 @@ cc.Class({
         this.callback = callback;
         //this.title.string = title;
         this.content.string = content;
-        this.confirmLabel.string = confirmText;
+        // this.confirmLabel.string = confirmText;
     },
 
     onConfirm(e) {

+ 37 - 28
assets/Script/public/GameData.js

@@ -3,6 +3,7 @@ var AConfig = require('../Config');
 
 import utils from "../Network/netUtils";
 import GameNet from "../Network/GameNet"
+import gameToast from "../Network/gameToast"
 
 //全局数据类
 cc.Class({
@@ -1035,32 +1036,32 @@ cc.Class({
         // "data": {
         //     "seed": [
         //         {
-                        // amount: 0
-                        // createTime: "2022-01-10 16:45:18"
-                        // harvestCount: 2500
-                        // harvestName: "大白菜"
-                        // harvestQuantity: 2500
-                        // id: 1
-                        // mallType: "0"
-                        // maturity: 100
-                        // name: "白菜种子"
-                        // picture: null
-                        // planting: 100
-                        // priceCnt: 99.99
-                        // priceSnb: 495.99
-                        // updateTime: "2022-01-10 16:45:26"
-                        // withered: 200
+        // amount: 0
+        // createTime: "2022-01-10 16:45:18"
+        // harvestCount: 2500
+        // harvestName: "大白菜"
+        // harvestQuantity: 2500
+        // id: 1
+        // mallType: "0"
+        // maturity: 100
+        // name: "白菜种子"
+        // picture: null
+        // planting: 100
+        // priceCnt: 99.99
+        // priceSnb: 495.99
+        // updateTime: "2022-01-10 16:45:26"
+        // withered: 200
         //         }
         //     ],
         //     "fruit": [
         //         {
-                        // createTime: "2022-01-10 16:45:18"
-                        // id: 1
-                        // name: "白菜"
-                        // picture: null
-                        // priceCnt: 9.99
-                        // priceSnb: 99
-                        // updateTime: "2022-01-10 16:45:26"
+        // createTime: "2022-01-10 16:45:18"
+        // id: 1
+        // name: "白菜"
+        // picture: null
+        // priceCnt: 9.99
+        // priceSnb: 99
+        // updateTime: "2022-01-10 16:45:26"
         //         }
         //     ]
         // },
@@ -1070,14 +1071,14 @@ cc.Class({
     },
     //种植种子
     // data:{landId:1,seedId:1}
-    onPlant(data,callback) {
+    onPlant(data, callback) {
         utils.get(utils.api.plant, data, (res, vaule) => {
             callback(res, vaule);
         })
     },
 
     //收取果实
-    onAddFruit(data,callback) {
+    onAddFruit(data, callback) {
         utils.post(utils.api.addFruit, data, (res, vaule) => {
             callback(res, vaule);
         })
@@ -1090,12 +1091,20 @@ cc.Class({
      * @param {*} payType 支付类型,1购买土地租凭, 2自然灾害防护,3野兽防护
      * @param {*} itemType 操作物品的id
      */
-    payCNT(cntAmount,payType,itemType,callback) {
-        if(!GlobalD.dapp){
+    payCNT(cntAmount, payType, itemType, callback) {
+        if (!GlobalD.dapp) {
             console.warn("GlobalD.dapp未初始化,不能payCNT!");
             return;
         }
-        GlobalD.dapp.payCnt(cntAmount, payType,itemType).then((data) => {
+        //
+        if (GlobalD.GameData.GetCNT() < cntAmount) {
+            console.log("cnt 不足,GetCNT:", GlobalD.GameData.GetCNT(), "消费的cntAmount", cntAmount);
+            gameToast.getInstance().show(cc.find("Canvas/UICamera"), "CNT不足!", 2, () => {
+                console.log("finish toast!");
+            }, this);
+            return;
+        }
+        GlobalD.dapp.payCnt(cntAmount, payType, itemType).then((data) => {
             const [err, tx] = data;
             if (err === null) {
                 // TODO 成功, 支付为链上操作,需要提供回调接口给这边服务端确认交易成功后修改购买订单结果
@@ -1104,7 +1113,7 @@ cc.Class({
                 console.log(err)
             }
 
-            if(callback){
+            if (callback) {
                 callback(data);
             }
         });