419 lines
14 KiB
JavaScript
419 lines
14 KiB
JavaScript
"use strict";
|
|
cc._RF.push(module, 'a9944mV1I5PI7Oa6YqWCaXh', 'mall_controller');
|
|
// Scripts/mod/shop/mall/mall_controller.js
|
|
|
|
"use strict";
|
|
|
|
// --------------------------------------------------------------------
|
|
// @author: xxx@syg.com(必填, 创建模块的人员)
|
|
// @description:
|
|
// 商城的逻辑控制层
|
|
// <br/>Create: 2018-12-18 17:12:27
|
|
// --------------------------------------------------------------------
|
|
var BridgeController = require("bridge.controller");
|
|
var MallEvent = require("mall_event");
|
|
var MallConst = require("mall_const");
|
|
var TDefine = require("trace.define");
|
|
var TTT = TDefine.TraceType;
|
|
var MallController = cc.Class({
|
|
"extends": BridgeController,
|
|
ctor: function ctor() {},
|
|
// 初始化配置数据
|
|
initConfig: function initConfig() {
|
|
var MallModel = require("mall_model");
|
|
this.model = new MallModel();
|
|
this.model.initConfig();
|
|
this.is_first_login = true;
|
|
this.temp_data = null;
|
|
},
|
|
// 返回当前的model
|
|
getModel: function getModel() {
|
|
return this.model;
|
|
},
|
|
setFirstLogin: function setFirstLogin(status) {
|
|
this.is_first_login = status;
|
|
},
|
|
setExchangeBuyData: function setExchangeBuyData(data) {
|
|
this.temp_data = data;
|
|
},
|
|
// 注册监听事件
|
|
registerEvents: function registerEvents() {},
|
|
// 注册协议接受事件
|
|
registerProtocals: function registerProtocals() {
|
|
this.RegisterProtocal(13401, this.handle13401); //商城进入数据请求
|
|
this.RegisterProtocal(13402, this.handle13402); //普通商店购买
|
|
this.RegisterProtocal(13403, this.handle13403); //神秘商店请求
|
|
this.RegisterProtocal(13404, this.handle13404); //服务端推送神秘商店可以刷新
|
|
this.RegisterProtocal(13405, this.handle13405); //神秘商城刷新列表
|
|
|
|
this.RegisterProtocal(13407, this.handle13407); //神秘商店购买
|
|
this.RegisterProtocal(13419, this.handle13419);
|
|
this.RegisterProtocal(13420, this.handle13420); //商店刷新状态
|
|
|
|
//活动商城 协议
|
|
this.RegisterProtocal(16660, this.handle16660); //商店刷新状态
|
|
this.RegisterProtocal(16661, this.handle16661); //购买道具协议
|
|
|
|
//成长自选礼包
|
|
this.RegisterProtocal(27800, this.handle27800);
|
|
this.RegisterProtocal(27801, this.handle27801);
|
|
},
|
|
// 从服务器初始化数据
|
|
reqBaseFromServer: function reqBaseFromServer(_cb) {
|
|
// 配置加载
|
|
var cfgs = ["exchange_data" // 商店
|
|
];
|
|
|
|
this.loadConfigs(cfgs, function (_ret, _data) {
|
|
nx.dt.fnInvoke(_cb, true);
|
|
});
|
|
},
|
|
// 打开商城主界面
|
|
//bid 需求的物品bid 通过页签组 来判断当前需要打开的相关的商城页面 mall_const中对应的编号 [ ( 1,2,3,9 ),( 8,6 ,17, 54, 55, 56 ) ]
|
|
openMallPanel: function openMallPanel(bool, _fromOthers) {
|
|
if (bool == true) {
|
|
nx.bridge.createPanel("WndShopMain", {
|
|
fromOther: _fromOthers
|
|
});
|
|
} else {
|
|
nx.bridge.closePanel("WndShopMain");
|
|
}
|
|
},
|
|
//引导需要
|
|
getMallRoot: function getMallRoot() {
|
|
if (this.mall_panel) return this.mall_panel.root_wnd;
|
|
},
|
|
getMallView: function getMallView() {
|
|
if (this.mall_panel) {
|
|
return this.mall_panel;
|
|
}
|
|
},
|
|
getNeedBid: function getNeedBid() {
|
|
return this.need_bid;
|
|
},
|
|
//设置需求的物品bid (给不在商城建筑里的商城类型设置
|
|
setNeedBid: function setNeedBid(bid) {
|
|
this.need_bid = bid;
|
|
},
|
|
//打开商城批量购买界面
|
|
openMallBuyWindow: function openMallBuyWindow(bool, data) {
|
|
if (bool == true) {
|
|
if (data != null) {
|
|
if (data.shop_type == MallConst.MallType.Recovery || data.shop_type == MallConst.MallType.ActionShop) {
|
|
if (this.mall_buy_win == null) {
|
|
var MallBuyWindow = require("mall_buy_window");
|
|
this.mall_buy_win = new MallBuyWindow();
|
|
}
|
|
this.mall_buy_win.open(data);
|
|
// this.mall_buy_win.setData(data);
|
|
} else {
|
|
var price_val = 0;
|
|
if (data.discount != null && data.discount > 0) {
|
|
price_val = data.discount;
|
|
} else {
|
|
price_val = data.price;
|
|
}
|
|
var is_can_buy_num = this.model.checkMoenyByType(data.pay_type, price_val);
|
|
if (is_can_buy_num <= 0) {
|
|
var pay_config = null;
|
|
if (typeof data.pay_type == "number") {
|
|
pay_config = Utils.getItemConfig(data.pay_type);
|
|
} else {
|
|
pay_config = Utils.getItemConfig(gdata("item_data", "data_assets_label2id", [data.pay_type]));
|
|
}
|
|
if (pay_config != null) {
|
|
if (pay_config.id == gdata("item_data", "data_assets_label2id", "gold") || pay_config.id == gdata("item_data", "data_assets_label2id", "red_gold_or_gold")) {
|
|
// if(IS_SHOW_CHARGE == false){
|
|
// nx.tbox(nx.text.getKey("lab_role_controller_tip_1"));
|
|
// }else{
|
|
// var fun = function(){
|
|
// nx.bridge.createPanel( "WndPayment", { key: "recharge" } );
|
|
// }
|
|
// var str = cc.js.formatStr(nx.text.getKey("lab_role_controller_tip_2"),pay_config.name);
|
|
|
|
// }
|
|
} else {
|
|
require("backpack_controller").getInstance().openTipsSource(true, pay_config.id);
|
|
}
|
|
}
|
|
} else {
|
|
if (this.mall_buy_win == null) {
|
|
var MallBuyWindow = require("mall_buy_window");
|
|
this.mall_buy_win = new MallBuyWindow();
|
|
}
|
|
// this.mall_buy_win.setData(data);
|
|
this.mall_buy_win.open(data);
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
if (this.mall_buy_win != null) {
|
|
this.mall_buy_win.close();
|
|
this.mall_buy_win = null;
|
|
}
|
|
}
|
|
},
|
|
//热卖商城的礼包查看界面
|
|
openMallGiftPanel: function openMallGiftPanel(bool, data) {
|
|
if (bool == true) {
|
|
if (this.mall_gift_panel == null) {
|
|
this.mall_gift_panel = new MallGiftPanel();
|
|
}
|
|
this.mall_gift_panel.open(data);
|
|
} else {
|
|
if (this.mall_gift_panel) {
|
|
this.mall_gift_panel.close();
|
|
this.mall_gift_panel = null;
|
|
}
|
|
}
|
|
},
|
|
//----------------协议处理--------------
|
|
//
|
|
sender13401: function sender13401(type) {
|
|
var protocal = {};
|
|
protocal.type = type;
|
|
this.SendProtocal(13401, protocal);
|
|
},
|
|
handle13401: function handle13401(data) {
|
|
// [13401]:{"type":8}
|
|
var status = false;
|
|
var index = 0;
|
|
if (data.type == 1) {
|
|
this.model.setLimitInfo(data);
|
|
}
|
|
if (data.type == 8 || data.type == 5 || data.type == 6 || data.type == 17 || data.type == 54 || data.type == 55 || data.type == 56 || data.type == 57 || data.type == 30 || data.type == 36 || data.type == 28 || data.type == 31 || data.type == 61 || data.type == 58 || data.type == 59 || data.type == 62 || data.type == 71) {
|
|
this.model.setLimitInfoD(data);
|
|
if (data.type == 28) {
|
|
this.holy = nx.dt.objClone(data);
|
|
}
|
|
}
|
|
if (data.code == 1 && data.type == 1) {
|
|
//钻石商城
|
|
var config = gdata("exchange_data", "data_shop_list", [1]);
|
|
if (config != null && config.login_red != null && Utils.next(config.login_red) != null) {
|
|
var len = config.login_red.length;
|
|
for (var k in config.login_red) {
|
|
var v = config.login_red[k];
|
|
var id = v[0];
|
|
var num = v[1];
|
|
if (data.item_list != null && Utils.next(data.item_list) != null) {
|
|
for (var a in data.item_list) {
|
|
var j = data.item_list[a];
|
|
if (id == j.item_id && j.ext[0].val < num) {
|
|
status = true;
|
|
break;
|
|
} else if (id == j.item_id && j.ext[0].val >= nul) {
|
|
index = index + 1;
|
|
}
|
|
}
|
|
} else {
|
|
//都没有买
|
|
status = true;
|
|
}
|
|
}
|
|
if (index == len) status = false;else status = true;
|
|
}
|
|
}
|
|
gcore.GlobalEvent.fire(MallEvent.Open_View_Event, data);
|
|
},
|
|
sender13402: function sender13402(eid, num) {
|
|
var protocal = {};
|
|
protocal.eid = eid;
|
|
protocal.num = num;
|
|
this.SendProtocal(13402, protocal);
|
|
},
|
|
//
|
|
handle13402: function handle13402(data) {
|
|
if (nx.dt.strNEmpty(data.msg)) {
|
|
nx.tbox(data.msg);
|
|
}
|
|
|
|
/***
|
|
* {"code":1,"msg":"","type":28,"is_half":0,"item_list":[{"item_id":10030,"ext":[{"key":1,"val":8}]}]}
|
|
*/
|
|
if (data.type == 28 && data.code == 1) {
|
|
if (nx.dt.arrEmpty(this.holy.item_list)) {
|
|
this.holy.item_list.push({
|
|
item_id: data.eid,
|
|
ext: data.ext
|
|
});
|
|
} else {
|
|
this.holy.item_list.forEach(function (_item) {
|
|
if (_item.item_id == data.eid) {
|
|
_item.ext = data.ext;
|
|
}
|
|
});
|
|
}
|
|
this.model.setLimitInfoD(this.holy);
|
|
}
|
|
nx.mTrace.trace(TTT.buyResult, data.eid, data.code == 1 ? 1 : 2);
|
|
// 处理显示
|
|
if (data.code == 1) {
|
|
gcore.GlobalEvent.fire(MallEvent.Buy_Success_Event, data);
|
|
}
|
|
},
|
|
//神秘商店请求
|
|
sender13403: function sender13403(type) {
|
|
var protocal = {};
|
|
protocal.type = type;
|
|
this.SendProtocal(13403, protocal);
|
|
},
|
|
//
|
|
handle13403: function handle13403(data) {
|
|
if (data.code == 1) {
|
|
gcore.GlobalEvent.fire(MallEvent.Get_Buy_list, data);
|
|
} else {
|
|
//nx.tbox(data.msg);
|
|
}
|
|
},
|
|
//服务端推送神秘商店可以刷新
|
|
handle13404: function handle13404(data) {
|
|
gcore.GlobalEvent.fire(MallEvent.Frash_tips_event);
|
|
},
|
|
//刷新列表
|
|
sender13405: function sender13405(type) {
|
|
var protocal = {};
|
|
protocal.type = type;
|
|
this.SendProtocal(13405, protocal);
|
|
},
|
|
//
|
|
handle13405: function handle13405(data) {
|
|
// if( nx.dt.strNEmpty( data.msg ) ){
|
|
// nx.tbox( data.msg );
|
|
// }
|
|
|
|
if (data.code == 1) {
|
|
gcore.GlobalEvent.fire(MallEvent.Get_Buy_list, data);
|
|
}
|
|
},
|
|
//神秘商店购买
|
|
sender13407: function sender13407(order, type, buy_type, nu, data) {
|
|
var protocal = {};
|
|
protocal.order = order;
|
|
protocal.type = type;
|
|
protocal.buy_type = buy_type;
|
|
protocal.num = nu;
|
|
this.SendProtocal(13407, protocal);
|
|
this.order = data;
|
|
},
|
|
handle13407: function handle13407(data) {
|
|
//nx.tbox(data.msg)
|
|
if (data.code == 1) {
|
|
gcore.GlobalEvent.fire(MallEvent.Buy_One_Success, data, this.order);
|
|
} else {
|
|
if (this.order) {
|
|
require("backpack_controller").getInstance().openTipsSource(true, this.order.item_id);
|
|
}
|
|
}
|
|
},
|
|
send13419: function send13419(num) {
|
|
var protocal = {};
|
|
protocal.num = num;
|
|
this.SendProtocal(13419, protocal);
|
|
},
|
|
handle13419: function handle13419(data) {
|
|
//nx.tbox(data.msg)
|
|
if (data.code == 1) {
|
|
if (this.temp_data != null) {
|
|
this.sender13407(this.temp_data.order, this.temp_data.shop_type, 1);
|
|
this.temp_data = null;
|
|
}
|
|
}
|
|
},
|
|
handle13420: function handle13420(data) {
|
|
gcore.GlobalEvent.fire(MallEvent.Free_Refresh_Data, data);
|
|
},
|
|
// ----------------------------杂货店相关----------------------------
|
|
// 打开杂货店界面
|
|
openVarietyStoreWindows: function openVarietyStoreWindows(status, _data) {
|
|
if (status == true) {
|
|
nx.bridge.createPanel("WndBlackMarket", _data);
|
|
} else {
|
|
nx.bridge.closePanel("WndBlackMarket");
|
|
}
|
|
},
|
|
// --打开活动商城
|
|
// --@ bid 活动对应的bid 不传默认打开 第一个
|
|
openMallActionWindow: function openMallActionWindow(bool, bid) {
|
|
if (bool == true) {
|
|
if (!this.mall_action_window) {
|
|
var MallActionWindow = require("mall_action_window");
|
|
this.mall_action_window = new MallActionWindow();
|
|
}
|
|
this.mall_action_window.open(bid);
|
|
} else {
|
|
if (this.mall_action_window) {
|
|
this.mall_action_window.close();
|
|
this.mall_action_window = null;
|
|
}
|
|
}
|
|
},
|
|
// ----------------------------------活动商城协议------------------------------------------
|
|
send16660: function send16660() {
|
|
var protocal = {};
|
|
this.SendProtocal(16660, protocal);
|
|
},
|
|
handle16660: function handle16660(data) {
|
|
//nx.tbox(data.msg)
|
|
gcore.GlobalEvent.fire(MallEvent.Update_Action_event, data);
|
|
},
|
|
handle16661: function handle16661(data) {
|
|
//nx.tbox(data.msg)
|
|
if (data.code == 1) {
|
|
gcore.GlobalEvent.fire(MallEvent.Buy_Action_Shop_Success_event, data);
|
|
}
|
|
},
|
|
// --{uint32, aim, "商品id"},
|
|
// --{uint32, num, "购买数量"}
|
|
send16661: function send16661(bid, aim, num) {
|
|
var protocal = {};
|
|
protocal.bid = bid;
|
|
protocal.aim = aim;
|
|
protocal.num = num;
|
|
this.SendProtocal(16661, protocal);
|
|
},
|
|
__delete: function __delete() {
|
|
if (this.model != null) {
|
|
this.model.DeleteMe();
|
|
this.model = null;
|
|
}
|
|
},
|
|
// -----------------------@ 聖羽商店
|
|
openPlumeShopWindow: function openPlumeShopWindow(status) {
|
|
if (status) {
|
|
if (!this.plume_shop_wnd) {
|
|
var PlumeShopWindow = require("plume_shop_window");
|
|
this.plume_shop_wnd = new PlumeShopWindow();
|
|
}
|
|
this.plume_shop_wnd.open();
|
|
} else {
|
|
if (this.plume_shop_wnd) {
|
|
this.plume_shop_wnd.close();
|
|
this.plume_shop_wnd = null;
|
|
}
|
|
}
|
|
},
|
|
//------------------------自选礼包----------------------------
|
|
// 自選禮包(觸發式禮包)
|
|
sender27800: function sender27800() {
|
|
var protocal = {};
|
|
this.SendProtocal(27800, protocal);
|
|
},
|
|
handle27800: function handle27800(data) {
|
|
gcore.GlobalEvent.fire(MallEvent.Get_Chose_Shop_Data_Event, data);
|
|
},
|
|
// 請求0元購買自選禮包
|
|
sender27801: function sender27801(package_id) {
|
|
var protocal = {};
|
|
protocal.package_id = package_id;
|
|
this.SendProtocal(27801, protocal);
|
|
},
|
|
handle27801: function handle27801(data) {
|
|
if (data.msg) {
|
|
//nx.tbox(data.msg)
|
|
}
|
|
}
|
|
});
|
|
module.exports = MallController;
|
|
|
|
cc._RF.pop(); |