bing 1 år sedan
förälder
incheckning
704b20100f
4 ändrade filer med 534 tillägg och 430 borttagningar
  1. 501 378
      assets/pay/prefab/pay.prefab
  2. 7 23
      assets/pay/script/ItemPay.ts
  3. 24 27
      assets/pay/script/Pay.ts
  4. 2 2
      assets/scene/script/NavInfo.ts

Filskillnaden har hållts tillbaka eftersom den är för stor
+ 501 - 378
assets/pay/prefab/pay.prefab


+ 7 - 23
assets/pay/script/ItemPay.ts

@@ -3,7 +3,7 @@ import { _decorator, Component, game, Label, Node, Sprite } from 'cc';
 import { UtilsPanel } from '../../scene/script/UtilsPanel';
 import { ViewItemPro } from '../../scene/script/components/ViewItemPro';
 import { nav_info } from '../../scene/script/NavInfo';
-import { Pay, ShopData } from './Pay';
+import { Pay, RateInfo, ShopData } from './Pay';
 import { UtilsFormat } from '../../scene/script/UtilsFormat';
 const { ccclass } = _decorator;
 
@@ -13,37 +13,21 @@ export class ItemPay extends ViewItemPro {
     private sp_icon: Sprite = null;
 	private lb_count: Label = null;
 
-    private money = 0;
-    private gold = 0;
+    private data: RateInfo = null;
 
 	protected onLoad(){
 		UtilsPanel.getAllNeedCom(this, this.node, false);
         UtilsPanel.addBtnEvent(this.node, this.onClick, this);
 	}
 
-    public init(data:any, index: number, p0?: any): void {
-        let p = Pay.data_shop;
-        if(index == p.DefaultPrice.length){
-            this.money = -1;
-            this.lb_count.string = "أدخل المبلغ";
-            index = 99;
-        }
-        else{
-            this.money = p.DefaultPrice[index];
-            this.gold = Pay.clacGold(this.money);
-            this.lb_count.string = UtilsFormat.formatMoney(this.gold);
-        }
-        if(index > 4 && this.money != -1)index = 4;
-
+    public init(data:RateInfo, index: number, p0?: any): void {
+        this.data = data;
+        this.lb_count.string = UtilsFormat.formatMoney(data.Gold);
+        if(index > 4)index = 4;
         UtilsPanel.setItemIcon(nav_info.bundle, "texture/1"+index+"/spriteFrame", this.sp_icon);
     }
 
     public onClick(){
-        if(this.money == -1){
-            nav_info.scene.showByUrl("prefab/paycustom");
-        }
-        else{
-            game.emit("select_item", this.money, this.node);
-        }
+        game.emit("select_item", this.data, this.node);
     }
 }

+ 24 - 27
assets/pay/script/Pay.ts

@@ -6,40 +6,37 @@ import { Config, nav_info } from '../../scene/script/NavInfo';
 import { WebRequest } from '../../scene/script/WebRequest';
 const { ccclass, property } = _decorator;
 
-type RateInfo = {
-    Min: number
-    Max: number
-    Ratio: number
+export type RateInfo = {
+    ProductID: string
+    Gold: number,
+    PayPrice: number
 }
 //money * rate * (1 + Ratio) = gold;
 export type ShopData = {
-    MinMoney: number //最小金额
-    Rate: number //金币/钱
-    DefaultPrice: number[] //默认商品
-    RatioConfig: RateInfo[]
+    ProductConfig: RateInfo[]
 }
 
 @ccclass('Pay')
 export class Pay extends Component {
     
-    public static clacGold(money: number){
-        let config = Pay.data_shop;
-        if(!config || money < config.MinMoney)return 0;
-        let ratio_info = config.RatioConfig.find(function(info){return money >= info.Min && money <= info.Max});
-        if(!ratio_info){
-            let ratios = config.RatioConfig;
-            ratio_info = ratios[ratios.length - 1];
-        }
-        return Math.floor(money * (ratio_info.Ratio + 1) * config.Rate);
-    }
-    public static buy(price:number){
+    // public static clacGold(money: number){
+    //     let config = Pay.data_shop;
+    //     if(!config || money < config.MinMoney)return 0;
+    //     let ratio_info = config.RatioConfig.find(function(info){return money >= info.Min && money <= info.Max});
+    //     if(!ratio_info){
+    //         let ratios = config.RatioConfig;
+    //         ratio_info = ratios[ratios.length - 1];
+    //     }
+    //     return Math.floor(money * (ratio_info.Ratio + 1) * config.Rate);
+    // }
+    public static buy(prod_id:string, price:number){
         let user_id = Pay.user_id;
         if(user_id.length == 0){
             nav_info.scene.showTip("يرجى إدخال ال ID حقك");
             return;
         }
         let url = nav_info.is_test ? Config.url_pay_test : Config.url_pay;
-        let final_url = `${url}?UserID=${user_id}&Price=${price}&ProductID=0&PartnerID=110&Currency=SAR&Country=SA&T=${new Date().getTime()}`;
+        let final_url = `${url}?UserID=${user_id}&Price=${price}&ProductID=${prod_id}&PartnerID=110&Currency=SAR&Country=SA&T=${new Date().getTime()}`;
         window.open(final_url);
     }
     public static user_id = "";
@@ -52,7 +49,7 @@ export class Pay extends Component {
 	private lb_money: Label = null;
 	private edit_id: EditBox = null;
     
-    private select_data = 0;
+    private select_data: RateInfo = null;
 
 	protected start(){
 		UtilsPanel.getAllNeedCom(this, this.node, true);
@@ -65,7 +62,7 @@ export class Pay extends Component {
             if(succ){
                 let info:ShopData = Pay.data_shop = JSON.parse(content);
                 // console.log("fwef:",info);
-                this.gene_items.initData(new Array(info.DefaultPrice.length + 1));
+                this.gene_items.initData(info.ProductConfig);
                 this.node_light.setSiblingIndex(-1);
             }
         }, false);
@@ -74,18 +71,18 @@ export class Pay extends Component {
         this.node_descid.active = this.edit_id.string.length == 0;
         Pay.user_id = this.edit_id.string;
     }
-    private onSelect(money:number, node:Node){
-        this.select_data = money;
-        this.lb_money.string = money + "";
+    private onSelect(info: RateInfo, node:Node){
+        this.select_data = info;
+        this.lb_money.string = "" + info.PayPrice
         this.node_light.active = true;
         this.node_light.setPosition(node.position);
     }
     private onBuy(){
-        if(this.select_data == 0){
+        if(this.select_data == null){
             nav_info.scene.showTip("يرجى اختيار الباقة التي ترغب بشرائها");
             return;
         }
-        Pay.buy(this.select_data);
+        Pay.buy(this.select_data.ProductID, this.select_data.PayPrice);
     }
     // private test(){
     //     let info = Pay.data_shop = {"MinMoney": 450, "Rate": 10000, "DefaultPrice": [1000,3000,6000,8000,10000],

+ 2 - 2
assets/scene/script/NavInfo.ts

@@ -9,8 +9,8 @@ import { MainScene } from "./MainScene";
 class NavInfo{
     public scene: MainScene = null;
 
-    public bundle = "share";
-    public pre = "share";
+    public bundle = "pay";
+    public pre = "pay";
     public is_test = false;
     public match_id = "";
     public user_id = "";

Vissa filer visades inte eftersom för många filer har ändrats