Files

594 lines
18 KiB
JavaScript
Raw Permalink Normal View History

2026-05-23 22:10:14 +08:00
// --------------------------------------------------------------------
// @author: xxx@syg.com(必填, 创建模块的人员)
// @description:
// 这里填写详细说明,主要填写该模块的功能简要
// <br/>Create: 2019-02-26 21:07:32
// --------------------------------------------------------------------
const BridgeController = require( "bridge.controller" );
var RoleController = require( "role_controller" );
var VipEvent = require( "vip_event" );
const Payment = require( "payment.mod" );
var VipController = cc.Class( {
extends: BridgeController,
ctor: function() {
},
// 初始化配置数据
initConfig: function() {
var VipModel = require( "vip_model" );
this.model = new VipModel();
this.model.initConfig();
this.vip_redpoint_status = {};
this.vip_privilege_redpoint = {};//vip特权 item 红点
this.is_first = true;
this.giftInfos = [];
this.giftInfo = [];
},
// 返回当前的model
getModel: function() {
return this.model;
},
// 注册监听事件
registerEvents: function() {
if( this.login_event_success == null ) {
this.login_event_success = gcore.GlobalEvent.bind( EventId.EVT_ROLE_CREATE_SUCCESS, function() {
gcore.GlobalEvent.unbind( this.login_event_success );
this.login_event_success = null;
this.role_vo = RoleController.getInstance().getRoleVo();
if( this.role_vo ) {
if( this.role_assets_event == null ) {
this.role_assets_event = this.role_vo.bind( EventId.UPDATE_ROLE_ATTRIBUTE, function( key, value ) {
if( key == "vip_lev" ) {
this.setIsFirst( true );
var get_list = this.model.getGetGiftList();
var item_status = ( get_list[ this.role_vo.vip_lev ] == null ) && this.getIsFirst();
// this.setTipsVIPStstus(VIPREDPOINT.VIP_TAB, item_status);
gcore.GlobalEvent.fire( VipEvent.UPDATA_ITEM_REDPOINT )
}
}.bind( this ) )
}
}
}, this )
}
if( this.re_link_game_event == null ) {
this.re_link_game_event = gcore.GlobalEvent.bind( EventId.EVT_RE_LINK_GAME, function() {
// this.sender21006();
}, this )
}
},
// 注册协议接受事件
registerProtocals: function() {
this.RegisterProtocal( 16710, this.handle16710 ) //VIP礼包领取信息
this.RegisterProtocal( 16711, this.handle16711 ) //VIP等级奖励领取
this.RegisterProtocal( 16712, this.handle16712 ) //获取永久累充信息
this.RegisterProtocal( 16713, this.handle16713 ) //领取累充奖励
this.RegisterProtocal( 16714, this.handle16714 ) //不處理返回
this.RegisterProtocal( 21005, this.handle21005 ) //三倍返利信息
this.RegisterProtocal( 21006, this.handle21006 ) //每日礼包数据
this.RegisterProtocal( 21007, this.handle21007.bind( this ) );
this.RegisterProtocal( 24501, this.handle24501 ) //购买VIP特权礼包
this.RegisterProtocal( 24502, this.handle24502 ) //VIP特权礼包数据
this.RegisterProtocal( 16707, this.handle16707 ) // 月卡额外奖励领取状态
this.RegisterProtocal( 16708, this.handle16708 ) // 月卡额外奖励领取
this.RegisterProtocal( 16730, this.handle16730 );
this.RegisterProtocal( 16731, this.handle16731 );
// this.RegisterProtocal( 21020, this.handle21020 );//每日一元红点
this.RegisterProtocal( 21023, this.getMonthlyGift );//每日一元红点
this.RegisterProtocal( 21041, this.handle21041 ); // 每日特惠禮包
this.RegisterProtocal( 21042, this.handle21042 ); // 領取每日特惠禮包
this.RegisterProtocal( 21043, this.handle21043 ); // 領取每日特惠達成禮包
},
// 从服务器初始化数据
reqBaseFromServer: function( _cb ) {
// 配置加载
let cfgs = [
"charge_data", // 支付点
"daily_charge_data", //
"privilege_data", // 特权
"vip_data", // VIP
"misc_data", // 周、月禮包
];
this.loadConfigs( cfgs, ( _ret, _data ) => {
// nx.dt.fnInvoke( _cb, true );
this.reqVipData( _cb );
} );
},
// 功能解锁检查
checkLockState: function() {
const DATA = game.configs.charge_data.data_constant.open_lv;
let conds = [];
conds.push( [ DATA.key, DATA.val ] );
let ret = nx.bridge.checkConditions( conds );
nx.bridge.vset( "ShopLocked", ret );
},
reqVipData( _cb ) {
this.SendProtocal( 16714, {}, _cb ); // 特权礼包
this.SendProtocal( 24700, {} );
this.SendProtocal( 21006, {} ); // 每日礼包
this.SendProtocal( 16707, {} ); // 月卡奖励
this.SendProtocal( 16710, {} ); // vip红点
this.SendProtocal( 16712, {} ); // 累充红点
this.SendProtocal( 24502, {} ); // 特权礼包
// this.SendProtocal( 21020, {} ); // 每日1元
// this.reqDailySpGift(); // 每日特惠禮包相關
this.reqMonthlyGiftData( 1 );
this.reqMonthlyGiftData();
},
setPrivilegeRedpoint: function( index, status ) {
this.vip_privilege_redpoint[ index ] = status;
},
getPrivilegeRedpoint: function( index ) {
var status = this.vip_privilege_redpoint[ index ];
return status
},
getIsFirst: function() {
return this.is_first
},
setIsFirst: function( status ) {
this.is_first = status
},
//三倍返利信息
sender21005: function() {
this.SendProtocal( 21005, {} )
},
handle21005: function( data ) {
gcore.GlobalEvent.fire( VipEvent.THREE_RECHARGE, data );
},
//请求每次礼包数据
sender21006: function() {
this.SendProtocal( 21006, {} )
},
handle21006: function( data ) {
if( data ) {
this.model.setDailyGiftData( data.first_gift );
gcore.GlobalEvent.fire( VipEvent.DAILY_GIFT_INFO );
}
},
// 请求每日首次充值數據
reqMonthlyGiftData: function( _type ) {
let type = _type ? _type : 2;
this.SendProtocal( 21007, {
type: type
} );
},
handle21007: function( _data ){
let wfg = game.configs.misc_data.data_cycle_gift_info[_data.type];
let rfg = game.configs.misc_data.data_cycle_gift_reward;
let gifts = _data.first_gift;
if( _data.type == 2 ){
this.giftInfos = [];
let reg_day = _data.reg_day;
for (let i in wfg ) {
let gift = wfg[i];
let reward = rfg[i];
let num = 0;
gifts.forEach( _gift=>{
if( _gift && _gift.id == gift.charge_id ){
num = _gift.count;
}
} )
if( gift ){
let info = {
gift: gift,
count : num,
rewards : {},
cb: ( gift.val == 0 ? ()=>{
this.reqGetMonthlyFreeGift( gift.charge_id );
} : ()=>{
Payment.getInstance().reqPayment( gift.charge_id );
}),
}
for (let r in reward ) {
let rinfo = reward[r];
if( rinfo.reg_min == 0 ){
if( rinfo.min <= reg_day && reg_day <= rinfo.max ){
let msg = "pay " + gift.charge_id;
info.rewards = rinfo;
// if( !nx.dt.arrMember( this.giftInfos, info ) ){
// this.giftInfos.push( info );
// }
}
}
}
if( nx.dt.objNEmpty( info.rewards ) ){
this.giftInfos.push( info );
}
}
}
nx.bridge.vset( "monthlygift", _data );
let get = true;
let first_gift = _data.first_gift;
if( nx.dt.arrEmpty( first_gift ) ){
get = true;
}else{
first_gift.forEach( _f => {
if( _f && wfg[_f.id] && wfg[_f.id].val == 0 ){
get = false;
}
} )
}
nx.mTip.openTip( "payment.monthly", false );
}else{
this.giftInfo = [];
let reg_day = _data.reg_day;
for (let i in wfg ) {
let gift = wfg[i];
let reward = rfg[i];
let num = 0;
gifts.forEach( _gift=>{
if( _gift && _gift.id == gift.charge_id ){
num = _gift.count;
}
} )
let info = {
gift: gift,
count : num,
rewards : {},
cb: ( ()=>{
Payment.getInstance().reqPayment( gift.charge_id );
}),
}
for (let r in reward ) {
let rinfo = reward[r];
if( rinfo.reg_min == 0 ){
if( rinfo.min <= reg_day && reg_day <= rinfo.max ){
let msg = "pay " + gift.charge_id;
info.rewards = rinfo;
// if( !nx.dt.arrMember( this.giftInfo, info ) ){
// this.giftInfo.push( info );
// }
}
}
}
if( nx.dt.objNEmpty( info.rewards ) ){
this.giftInfo.push( info );
}
}
// _data.award_list.sort( ( a,b ) => {
// return a.id - b.id;
// } )
nx.bridge.vset( "weeklygift", _data );
let get = true;
let first_gift = _data.first_gift;
if( nx.dt.arrEmpty( first_gift ) ){
get = true;
}else{
first_gift.forEach( _f => {
if( _f && wfg[_f.id] && wfg[_f.id].val == 0 ){
get = false;
}
} )
}
nx.mTip.openTip( "payment.weekly", false );
}
},
//请求領取每次礼包数据
reqGetMonthlyFreeGift: function( _id ) {
this.SendProtocal( 21023, {
package_id: _id
} )
},
//请求每次礼包数据
reqDailySpGift: function() {
this.SendProtocal( 21041, {} )
},
//请求領取每次礼包数据
reqGetDailySpGift: function( _id ) {
this.SendProtocal( 21042, {
id: _id
} )
},
//请求領取每次礼包数据
reqGetDailyReward: function( _id ) {
this.SendProtocal( 21043, {
id: _id
} )
},
getMonthlyGift : function( _data ){
if( _data.code == 0 ){
if( nx.dt.strNEmpty( _data.msg ) ){
nx.tbox( _data.msg );
}
}
},
handle21041: function( _data ){
nx.bridge.vset( "DailySpGift", _data );
let gift = _data.gift;
let show = false;
if( gift ){
if( nx.dt.arrNEmpty( gift ) ){
gift.forEach( _gift =>{
if( _gift.id == 1 ){
show = _gift.status == 1;
}
} )
}
}
nx.mTip.openTip( "payment.daily", show );
},
handle21042: function( _data ){
},
handle21043: function( _data ){
},
//请求购买VIP特权礼包
sender24501: function( id ) {
var protocal = {};
protocal.id = id;
this.SendProtocal( 24501, protocal );
},
handle24501: function( data ) {
if( data.msg ) {
nx.tbox( data.msg );
}
},
//请求VIP特权礼包数据
sender24502: function() {
this.SendProtocal( 24502, {} );
},
handle24502: function( data ) {
if( data ) {
nx.bridge.vset( "privilege", data.list );
this.model.setPrivilegeList( data.list );
var status = this.model.getPrivilegeRedStatus();
// this.setTipsVIPStstus(VIPREDPOINT.PRIVILEGE, status);
gcore.GlobalEvent.fire( VipEvent.PRIVILEGE_INFO );
}
},
//VIP界面月卡领取
sender16707: function() {
this.SendProtocal( 16707, {} );
},
handle16707: function( data ) {
var status = false;
if( data.status == 1 ) {
status = true;
}
this.model.setMonthCard( data.status );
nx.bridge.vset( "VIPMMSp", data.status );
nx.mTip.openTip( "payment.vip.daily", data.status == 1 );
// this.setTipsVIPStstus(VIPREDPOINT.MONTH_CARD, status);
gcore.GlobalEvent.fire( VipEvent.SUPRE_CARD_GET, data.status );
},
sender16708: function() {
this.SendProtocal( 16708, {} );
},
handle16708: function( data ) {
nx.tbox( data.msg )
},
//VIP礼包领取信息
sender16710: function() {
this.SendProtocal( 16710, {} );
},
handle16710: function( data ) {
this.model.setGetGiftList( data.list );
if( this.role_vo == null ) {
this.role_vo = RoleController.getInstance().getRoleVo();
}
nx.bridge.vset( "VIPBuyGifts", data.list || [] );
var get_list = this.model.getGetGiftList();
var item_status = ( get_list[ this.role_vo.vip_lev ] == null ) && this.getIsFirst();
// this.setTipsVIPStstus(VIPREDPOINT.VIP_TAB, item_status);
gcore.GlobalEvent.fire( VipEvent.UPDATA_ITEM_REDPOINT )
},
//红点
setTipsVIPStstus: function( bid, status ) {
this.vip_redpoint_status[ bid ] = status
let redpoint = false
for( let i in this.vip_redpoint_status ) {
let v = this.vip_redpoint_status[ i ]
if( v == true ) {
redpoint = true
break
}
}
},
//VIP等级奖励领取
sender16711: function( lev ) {
var protocal = {};
protocal.lev = lev;
this.SendProtocal( 16711, protocal );
},
handle16711: function( data ) {
nx.tbox( data.msg )
},
//累充奖励信息
sender16712: function() {
this.SendProtocal( 16712, {} );
},
handle16712: function( data ) {
this.charge_sum = data.charge_sum //当前总充值数
this.model.setAccList( data.list );
gcore.GlobalEvent.fire( VipEvent.ACC_RECHARGE_INFO, data );
},
getChargeSum: function() {
return this.charge_sum || 0;
},
//领取累充奖励
sender16713: function( id ) {
var protocal = {};
protocal.id = id;
this.SendProtocal( 16713, protocal );
},
handle16713: function( data ) {
nx.tbox( data.msg );
},
handle16714: function( _data ){
},
//
sender16730: function() {
var protocal = {};
this.SendProtocal( 16730, protocal );
},
// time
// state
handle16730: function( data ) {
this.model.setGiveVipInfo( data );
this.model.setGiveVipStatus();
gcore.GlobalEvent.fire( VipEvent.GIVE_VIP_UPDATE );
},
//
sender16731: function() {
var protocal = {};
this.SendProtocal( 16731, protocal );
},
//领取vip
handle16731: function( data ) {
nx.tbox( data.msg );
if( data.code == 1 ) {
this.openVipAwardWindow();
this.sender16730();
}
},
//index是大标签页 VIPTABCONST
//sub_type是vip特权界面的 要跳哪个等级就传哪个等级
openVipMainWindow: function( status, index2, sub_type, callFunc ) {
if( status ) {
var charge_cfg = gdata( "charge_data", "data_constant", [ "open_lv" ] );
if( charge_cfg ) {
if( this.role_vo && this.role_vo.lev < charge_cfg.val ) {
nx.tbox( charge_cfg.desc );
return
}
}
let index = index2 || "recharge";
nx.bridge.createPanel( "WndPayment", index );
if( callFunc ) {
this.deleteCallFunc = callFunc
}
} else {
nx.bridge.closePanel( "WndPayment" );
if( this.deleteCallFunc ) {
this.deleteCallFunc()
this.deleteCallFunc = null;
}
}
},
// 打开奖励VIP界面
openVipAwardWindow: function( status ) {
if( status == true ) {
if( !this.vip_award_window ) {
this.vip_award_window = Utils.createClass( "vip_award_window", this );
}
this.vip_award_window.open();
} else {
if( this.vip_award_window ) {
this.vip_award_window.close();
this.vip_award_window = null;
}
}
},
//切换vip面板的标签页
changeMainWindowTab: function( index ) {
if( this.vip_window ) {
this.vip_window.changeTabView( index );
}
},
handle21020( data ) {
var status = false;
if( data.code == 1 ) {
status = true;
}
},
} );
module.exports = VipController;