|
--[[@------------------------------------------------------------------
|
|
@description:市场
|
|
@author:wyb
|
|
----------------------------------------------------------------------]]
|
|
require("game.proto.155.Require155")
|
|
require("game.market.MarketModel")
|
|
require("game.market.MarketConst")
|
|
require("game.market.MarketView")--主界面
|
|
require("game.market.MarketBuyHallView")--交易大厅
|
|
require("game.market.MarketVerTabItem")--左边树状标签栏
|
|
require("game.market.MarketHorTabItem")--水平tap按钮
|
|
require("game.market.MarketGoodsItem")--交易物品item
|
|
require("game.market.MarketSalesHallView")--上架界面
|
|
require("game.market.MarketSalesHallItem")--上架界面
|
|
require("game.market.MarketBagItem")--背包物品
|
|
require("game.market.MarketBuyView")--购买界面
|
|
require("game.market.MarketFocusView")--关注界面
|
|
require("game.market.MarketFocusItem")--关注界面item
|
|
require("game.market.MarketRecordView")--记录界面
|
|
require("game.market.MarketRecordItem")--记录界面item
|
|
require("game.market.MarketAttentionView")--提醒界面
|
|
require("game.market.MarketAttentionItem")--提醒界面item
|
|
require("game.market.MarketUpShelvesView")--上架界面
|
|
|
|
MarketController = MarketController or BaseClass(BaseController)
|
|
function MarketController:__init()
|
|
MarketController.Instance = self
|
|
|
|
self.model = MarketModel:getInstance()
|
|
self.is_first_login = true
|
|
self:InitEvent()
|
|
self:registerAllProtocals()
|
|
end
|
|
|
|
function MarketController:getInstance()
|
|
if MarketController.Instance == nil then
|
|
MarketController.New()
|
|
end
|
|
return MarketController.Instance
|
|
end
|
|
|
|
function MarketController:InitEvent()
|
|
local function onRequestHandler(...)
|
|
local args = {...}
|
|
if args[1] == 15501 then
|
|
self:SendFmtToGame(args[1], "ccchcchhcc", args[2],args[3],args[4],args[5],args[6],args[7],args[8],args[9],args[10],args[11])
|
|
elseif args[1] == 15504 then
|
|
self:SendFmtToGame(args[1], "h", args[2])
|
|
elseif args[1] == 15506 then
|
|
self:SendFmtToGame(args[1], "liicc", args[2],args[3],args[4],args[5],args[6])
|
|
elseif args[1] == 15507 then
|
|
self:SendFmtToGame(args[1], "li", args[2],args[3])
|
|
elseif args[1] == 15508 or args[1] == 15510 or args[1] == 15511 then
|
|
self:SendFmtToGame(args[1], "l", args[2])
|
|
elseif args[1] == 15509 then
|
|
self:SendFmtToGame(args[1], "lcc", args[2],args[3],args[4])
|
|
elseif args[1] == 15513 or args[1] == 15514 then
|
|
self:SendFmtToGame(args[1], "i", args[2])
|
|
elseif args[1] == 15516 then
|
|
self:SendFmtToGame(args[1], "cc", args[2], args[3])
|
|
else
|
|
self:SendFmtToGame(args[1])
|
|
end
|
|
end
|
|
self.model:Bind(MarketModel.REQUEST_CCMD_EVENT, onRequestHandler)
|
|
|
|
local onOpenMarketView = function (index, sub_index, param_list)
|
|
if self.market_view == nil then
|
|
self.market_view = MarketView.New()
|
|
end
|
|
if self.market_view:HasOpen() then
|
|
self.market_view:ReOpen(index, sub_index, param_list)
|
|
else
|
|
self.market_view:Open(index, sub_index, param_list)
|
|
end
|
|
end
|
|
GlobalEventSystem:Bind(EventName.OPEN_MARKET_VIEW, onOpenMarketView)
|
|
|
|
local onGameStartHandler = function ()
|
|
--顶号重连数据未刷新处理
|
|
self.model:Fire(MarketModel.REQUEST_CCMD_EVENT, 15503)
|
|
self.model:Fire(MarketModel.REQUEST_CCMD_EVENT, 15512)
|
|
if UserMsgAdapter:getInstance().reconnect_times > 0 then
|
|
|
|
end
|
|
end
|
|
self:Bind(EventName.GAME_START, onGameStartHandler)
|
|
|
|
local function on_buy_view_open( data,type )
|
|
if self.market_buy_view == nil then
|
|
self.market_buy_view = MarketBuyView.New()
|
|
end
|
|
self.market_buy_view:Open(data,type)
|
|
end
|
|
self.model:Bind(MarketModel.OPEN_MARKET_BUY_VIEW, on_buy_view_open)
|
|
|
|
local function on_update_red_dot( )
|
|
self:UpdateMarketRed()
|
|
end
|
|
self.model:Bind(MarketModel.UPDATE_MARKET_TAB_RED_DOT, on_update_red_dot)
|
|
GlobalEventSystem:Bind(EventName.BAG_LIST_INIT_EVENT, on_update_red_dot)
|
|
end
|
|
|
|
|
|
function MarketController:UpdateMarketRed( )
|
|
local function call_back( ... )
|
|
local bool = self.model:CheckMarketRedDot()
|
|
GlobalEventSystem:Fire(ActivityIconManager.UPDATE_ICON_TIPS, 11, bool)
|
|
end
|
|
TimeManager.GetInstance():StartTime("MarketController:on_update_red", 0.5, call_back)
|
|
end
|
|
|
|
function MarketController:registerAllProtocals()
|
|
self:RegisterProtocal(15501,"handle15501")--市场商品一级列表
|
|
self:RegisterProtocal(15502,"handle15502")--玩家正在竞价的商品列表
|
|
self:RegisterProtocal(15503,"handle15503")--玩家已上架物品列表
|
|
self:RegisterProtocal(15504,"handle15504")--成交记录
|
|
self:RegisterProtocal(15505,"handle15505")--已添加的入库提醒
|
|
self:RegisterProtocal(15506,"handle15506")--商品上架
|
|
self:RegisterProtocal(15507,"handle15507")--竞拍物品
|
|
self:RegisterProtocal(15508,"handle15508")--商品下架
|
|
self:RegisterProtocal(15509,"handle15509")--玩家已下架物品列表
|
|
self:RegisterProtocal(15510,"handle15510")--关注商品
|
|
self:RegisterProtocal(15511,"handle15511")--取消关注商品
|
|
self:RegisterProtocal(15512,"handle15512")--玩家关注的商品列表
|
|
self:RegisterProtocal(15513,"handle15513")--添加上架提醒
|
|
self:RegisterProtocal(15514,"handle15514")--取消上架提醒
|
|
self:RegisterProtocal(15515,"handle15515")--主推上架提醒
|
|
self:RegisterProtocal(15516,"handle15516")--一键取消上架提醒
|
|
self:RegisterProtocal(15517,"handle15517")--竞价被超越
|
|
self:RegisterProtocal(15518,"handle15518")--竞拍价格变化
|
|
self:RegisterProtocal(15519,"handle15519")--一键上架
|
|
end
|
|
|
|
function MarketController:handle15501()
|
|
local vo = SCMD15501.New(true)
|
|
if vo.sell_type == 1 then--世界拍卖
|
|
if TableSize(vo.goods_list) == 0 then
|
|
self.model:SetGoodsListLastPageType(vo.type, vo.subtype, 1)
|
|
else
|
|
self.model:SetGoodsListLastPageType(vo.type, vo.subtype, 0)
|
|
end
|
|
self.model:SetWorldMarketGoodsInfo(vo.type, vo.subtype, vo.page_no, vo.goods_list)
|
|
elseif vo.sell_type == 2 then--社团拍卖
|
|
if TableSize(vo.goods_list) == 0 then
|
|
self.model:SetGuildGoodsListLastPageType(vo.type, vo.subtype, 1)
|
|
else
|
|
self.model:SetGuildGoodsListLastPageType(vo.type, vo.subtype, 0)
|
|
end
|
|
self.model:SetGuildMarketGoodsInfo(vo.type, vo.subtype, vo.page_no, vo.goods_list)
|
|
end
|
|
end
|
|
--玩家正在竞价的商品列表
|
|
function MarketController:handle15502()
|
|
local vo = SCMD15502.New(true)
|
|
self.model:SetAuctionList(vo.goods_list)
|
|
end
|
|
|
|
--玩家已上架物品列表
|
|
function MarketController:handle15503()
|
|
local vo = SCMD15503.New(true)
|
|
self.model:SetOnShelvesList(vo.goods_list)
|
|
self.model:Fire(MarketModel.UPDATE_MARKET_TAB_RED_DOT)
|
|
end
|
|
|
|
--成交记录
|
|
function MarketController:handle15504()
|
|
local vo = SCMD15504.New(true)
|
|
self.model:SetMarketRecordInfo(vo.type, vo.log_list)
|
|
end
|
|
|
|
--上架提醒列表
|
|
function MarketController:handle15505()
|
|
local vo = SCMD15505.New(true)
|
|
self.model:SetMarketAttentionList(vo.good_list)
|
|
end
|
|
|
|
--商品上架
|
|
function MarketController:handle15506()
|
|
local vo = SCMD15506.New(true)
|
|
if vo.result_code == 1 then
|
|
Message.show("上架成功")
|
|
self.model:Fire(MarketModel.REQUEST_CCMD_EVENT, 15503)
|
|
else
|
|
ErrorCodeShow(vo.result_code)
|
|
end
|
|
end
|
|
|
|
--竞拍物品
|
|
function MarketController:handle15507()
|
|
local vo = SCMD15507.New(true)
|
|
if vo.errcode == 1 then
|
|
Message.show("竞拍成功")
|
|
self.model:Fire(MarketModel.MARKET_BUY_SUCCESS)
|
|
self.model:Fire(MarketModel.REQUEST_CCMD_EVENT, 15512)
|
|
elseif vo.errcode == 1550018 then
|
|
Message.show("竞价有变化,请重新出价")
|
|
self.model:Fire(MarketModel.MARKET_BUY_SUCCESS)
|
|
self.model:Fire(MarketModel.REQUEST_CCMD_EVENT, 15512)
|
|
else
|
|
ErrorCodeShow(vo.errcode)
|
|
end
|
|
end
|
|
|
|
function MarketController:handle15508()
|
|
local vo = SCMD15508.New(true)
|
|
if vo.errcode == 1 then
|
|
Message.show("取回商品成功")
|
|
self.model:Fire(MarketModel.REQUEST_CCMD_EVENT, 15503)
|
|
else
|
|
ErrorCodeShow(vo.errcode)
|
|
end
|
|
end
|
|
|
|
function MarketController:handle15509()
|
|
local vo = SCMD15509.New(true)
|
|
if vo.result_code == 1 then
|
|
Message.show("重新上架成功")
|
|
self.model:Fire(MarketModel.REQUEST_CCMD_EVENT, 15503)
|
|
else
|
|
ErrorCodeShow(vo.result_code)
|
|
end
|
|
end
|
|
|
|
function MarketController:handle15510( )
|
|
local vo = SCMD15510.New(true)
|
|
if vo.errcode == 1 then
|
|
Message.show("关注商品成功")
|
|
self.model:Fire(MarketModel.MARKET_BUY_SUCCESS)
|
|
self.model:Fire(MarketModel.REQUEST_CCMD_EVENT, 15512)
|
|
else
|
|
ErrorCodeShow(vo.errcode)
|
|
end
|
|
end
|
|
|
|
function MarketController:handle15511()
|
|
local vo = SCMD15511.New(true)
|
|
if vo.errcode == 1 then
|
|
Message.show("取消关注成功")
|
|
self.model:Fire(MarketModel.MARKET_BUY_SUCCESS)
|
|
self.model:Fire(MarketModel.REQUEST_CCMD_EVENT, 15512)
|
|
else
|
|
ErrorCodeShow(vo.errcode)
|
|
end
|
|
end
|
|
|
|
function MarketController:handle15512()
|
|
local vo = SCMD15512.New(true)
|
|
self.model:SetMarketFocusList(vo.goods_list)
|
|
if self.is_first_login then
|
|
self.model:SetMarketAuctionRed(self.model:IsAuctionNeedRed())
|
|
self.is_first_login = false
|
|
end
|
|
end
|
|
|
|
function MarketController:handle15513()
|
|
local vo = SCMD15513.New(true)
|
|
if vo.errcode == 1 then
|
|
Message.show("成功添加上架提醒")
|
|
self.model:Fire(MarketModel.REQUEST_CCMD_EVENT, 15505)
|
|
else
|
|
ErrorCodeShow(vo.errcode)
|
|
end
|
|
end
|
|
|
|
function MarketController:handle15514()
|
|
local vo = SCMD15514.New(true)
|
|
if vo.errcode == 1 then
|
|
Message.show("已取消该商品上架提醒")
|
|
self.model:Fire(MarketModel.REQUEST_CCMD_EVENT, 15505)
|
|
else
|
|
ErrorCodeShow(vo.errcode)
|
|
end
|
|
end
|
|
|
|
function MarketController:handle15515()
|
|
local vo = SCMD15515.New(true)
|
|
local goods_name = GoodsModel:getInstance():getGoodsName(vo.type_id, true)
|
|
local market_name = self.model:GetMarketTypeName(vo.sell_type)
|
|
local str = string.format("您关注的商品%s已经有人正在%s出售,请赶快前往购买。", goods_name, market_name)
|
|
Message.show(str)
|
|
end
|
|
|
|
function MarketController:handle15516()
|
|
local vo = SCMD15516.New(true)
|
|
if vo.errcode == 1 then
|
|
Message.show("已取消该分类下所有商品上架提醒")
|
|
self.model:Fire(MarketModel.REQUEST_CCMD_EVENT, 15505)
|
|
else
|
|
ErrorCodeShow(vo.errcode)
|
|
end
|
|
end
|
|
|
|
-- ########### 竞价被超越 ##############
|
|
-- protocol=15517
|
|
-- {
|
|
-- s2c{
|
|
-- goods_id :int32 // 物品id
|
|
-- other_data:array{
|
|
-- // 物品信息,一般不同的物品 包含的信息不同
|
|
-- // 服务端见def_goods.hrl #goods.extra_data
|
|
-- type:int8
|
|
-- info:string
|
|
-- }
|
|
-- }
|
|
-- }
|
|
function MarketController:handle15517( )
|
|
local vo = SCMD15517.New(true)
|
|
local goods_vo = GoodsModel:getInstance():GetGoodsBasicByTypeId(vo.goods_id)
|
|
if goods_vo then
|
|
GlobalEventSystem:Fire(EventName.OPEN_COMMON_AUCTION_VIEW, vo)
|
|
self.model:SetMarketAuctionRed(true)
|
|
end
|
|
end
|
|
|
|
function MarketController:handle15518( )
|
|
local vo = SCMD15518.New(true)
|
|
self.model:Fire(MarketModel.UPDATE_ONE_GOODS_BY_PRICE_UP, vo.id, vo.price)
|
|
end
|
|
|
|
function MarketController:handle15519( )
|
|
local vo = SCMD15519.New(true)
|
|
if vo.result_code == 1 then
|
|
Message.show("一键重新上架成功")
|
|
self.model:Fire(MarketModel.REQUEST_CCMD_EVENT, 15503)
|
|
else
|
|
ErrorCodeShow(vo.result_code)
|
|
end
|
|
end
|