| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338 |
- local RemoteProxy = requireProxy("remote/RemoteProxy")
- local PurchaseProxy = class("PurchaseProxy", RemoteProxy)
- PurchaseProxy.NAME = global.ProxyTable.PurchaseProxy
- local socket = require("socket")
- local cjson = require("cjson")
- -- guid 标识
- -- userid 归属者ID
- -- itemid 道具ID
- -- stdmode 道具类型stdmode
- -- currency 货币ID
- -- totalqty 总数量
- -- minqty 最小数量
- -- remainqty 剩余数量
- -- waitrecqty 待提取数量
- -- recedqty 已提取数量
- -- price 单价
- -- qty 数量
- -- amount 金额
- -- starttime 上架时间
- -- endtime 下架时间(为0不限制下架时间)
- -- pageindex 页码
- -- pagemax 总共页数
- local function getUnitNumber(n)
- if n >= 100000000 then
- return string.format("%.1f%s", n / 100000000, GET_STRING(1045))
- end
- if n >= 10000 then
- return string.format("%.1f%s", n / 10000, GET_STRING(1005))
- end
- return tostring(n)
- end
- local function parseItem(item)
- if not item then
- return nil
- end
- local titem = ChangeItemServersSendDatas(item.useritem)
- setmetatable( item, { __index = titem })
- return item
- end
- function fixPurchasePrice(price, unit)
- return unit and getUnitNumber(price) or price
- end
- function PurchaseProxy:ctor()
- PurchaseProxy.super.ctor(self)
- self._config_type = {}
- self._currencies = {} -- 可求购货币
- self._currencyMap = {}
- self._receivelist = {} -- 我的 - 已收列表
- self._putlist = {} -- 我的 - 求购列表
- self._src = 0 -- 请求来源 0.世界求购 1.我的求购 2.我的已收
- self._sort = 0 -- 排序 0.默认 1.单价正序 2.单价倒序 3.总价正序 4.总价倒序
- self._page = 0
- self._complete = false
- self._itemConfig = {}
- self._requestMinTime = 600 -- 拍卖行数据请求最小时间间隔(毫秒)
- self._lastRequestTime = nil
- self._filter1Item = nil -- 分类一级数据
- self._itemListByType = {} -- 按类分物品列表
- self:Init()
- end
- function PurchaseProxy:Init()
- self._config_type = clone(requireGameConfig("cfg_auction_type"))
- end
- function PurchaseProxy:InitItemConfig(...)
- local ItemConfigProxy = global.Facade:retrieveProxy(global.ProxyTable.ItemConfigProxy)
- self._itemConfig = ItemConfigProxy:GetItemConfigData()
- end
- function PurchaseProxy:Clear()
- self._page = 0
- self._complete = false
- end
- function PurchaseProxy:IsComplete()
- return self._complete
- end
- function PurchaseProxy:getCurrencies()
- return self._currencies
- end
- -- #分隔
- function PurchaseProxy:SetCurrencies(str)
- if str and string.len(str) > 0 then
- local data = string.split(str, "#")
- for k, v in ipairs(data) do
- local id = tonumber(v)
- if id and not self._currencyMap[id] then
- self._currencyMap[id] = true
- table.insert(self._currencies, {id = id})
- end
- end
- end
- end
- function PurchaseProxy:SetTypeItemList(list)
- self._itemListByType = list or {}
- end
- function PurchaseProxy:GetItemListByType(key)
- return self._itemListByType and self._itemListByType[key] or {}
- end
- function PurchaseProxy:clearData()
- self._itemListByType = {}
- end
- function PurchaseProxy:SetSortType(type)
- self._sort = type
- end
- function PurchaseProxy:GetSortType()
- return self._sort
- end
- function PurchaseProxy:GetCTypeByID(id)
- return self._config_type[id]
- end
- function PurchaseProxy:GetStdModeByID(id)
- local config = self:GetCTypeByID(id)
- if not config then
- return {}
- end
- local slices = string.split(tostring(config.stdmode), "#")
- local stdmode = {}
- for key, value in ipairs(slices) do
- table.insert(stdmode, tonumber(value))
- end
- return stdmode
- end
- -- 一级页签
- function PurchaseProxy:GetFirstFilterItem()
- if not self._filter1Item then
- local items = {}
- for i, v in pairs(self._config_type) do
- if not items[v.firstlevel] then
- items[v.firstlevel] = {}
- end
- table.insert(items[v.firstlevel], v)
- end
- for i, v in pairs(items) do
- table.sort(v, function(a, b) return a.id < b.id end)
- end
- self._filter1Item = items
- end
- return self._filter1Item
- end
- -- 二级页签
- function PurchaseProxy:GetSecondFilterItem(g)
- local items = self:GetFirstFilterItem()[g] or {}
- -- table.sort(items, function(a, b) return a.id < b.id end)
- return items
- end
- function PurchaseProxy:GetItemConfig()
- return self._itemConfig
- end
- function PurchaseProxy:SetRequestMinTime(time)
- self._requestMinTime = time
- end
- ----------------------------------------------------------------------------------
- -- 拉取求购数据:发送消息号:1510, recog 世界=0, 我的求购=1, 我的已收=2
- function PurchaseProxy:RequestItemList(data)
- local curTime = socket.gettime()
- local needDelay = false
- -- if self._lastRequestTime and self._requestMinTime then
- -- if (curTime - self._lastRequestTime) * 1000 < self._requestMinTime then
- -- needDelay = true
- -- SL:ShowSystemTips("<font color = '#00FF00'>正在读取数据中...</font>")
- -- end
- -- end
- local function callback()
- local sendData = data
- self._lastRequestTime = socket.gettime()
- local jsonStr = cjson.encode(sendData)
- LuaSendMsg(global.MsgType.MSG_CS_PURCHASE_ITEM_LIST, 0, 0, 0, data.type or 0, jsonStr, string.len(jsonStr))
- end
- PerformWithDelayGlobal(callback, needDelay and (self._requestMinTime / 1000) or 0)
- end
- function PurchaseProxy:RespItemList(msg)
- HideLoadingBar()
- local header = msg:GetHeader()
- local len = msg:GetDataLength()
- if len <= 0 then
- return false
- end
- local jsonData = ParseRawMsgToJson(msg)
- local type = header.recog -- 0 1 2
- -- complete
- dump(jsonData, "_______________itemList")
- local data = jsonData and jsonData.data
- if #data == 0 then
- self._complete = true
- global.Facade:sendNotification(global.NoticeTable.PurchaseItemListComplete, {type = type})
- SLBridge:onLUAEvent(LUA_EVENT_PURCHASE_ITEM_LIST_COMPLETE, {type = type})
- return
- end
- SLBridge:onLUAEvent(LUA_EVENT_PURCHASE_ITEM_LIST_PULL, {type = type, items = data, pageIndex = jsonData.pageindex})
- end
- function PurchaseProxy:RequestPutIn(data)
- SendTableToServer(global.MsgType.MSG_CS_PURCHASE_PUT_IN, data)
- end
- function PurchaseProxy:RequestPutOut(guid)
- if not guid then -- 全部取消
- LuaSendMsg(global.MsgType.MSG_CS_PURCHASE_PUT_OUT, 0, 0, 0, 1)
- else
- LuaSendMsg(global.MsgType.MSG_CS_PURCHASE_PUT_OUT, 0, 0, 0, 0, guid, string.len(guid))
- end
- end
- function PurchaseProxy:RequestTakeOut(guid)
- if not guid then -- 全部取出
- LuaSendMsg(global.MsgType.MSG_CS_PURCHASE_TAKE_OUT, 0, 0, 0, 1)
- else
- LuaSendMsg(global.MsgType.MSG_CS_PURCHASE_TAKE_OUT, 0, 0, 0, 0, guid, string.len(guid))
- end
- end
- function PurchaseProxy:RequestSell(data)
- SendTableToServer(global.MsgType.MSG_CS_PURCHASE_SELL, data)
- end
- function PurchaseProxy:NotifyClosePurchase()
- LuaSendMsg(global.MsgType.MSG_CS_PURCHASE_CLOSE)
- end
- -- 操作返回 recog=类型 1=上架 2=取出 3=出售 4=下架, nparam 0 成功 小于0 失败
- function PurchaseProxy:RespOperaBack(msg)
- local header = msg:GetHeader()
- local type = header.recog
- local errorcode = header.param1
- if errorcode == 0 then
- ShowSystemTips("成功")
- elseif errorcode == -1 then
- ShowSystemTips("道具不合法")
- elseif errorcode == -2 then
- ShowSystemTips("单价不合法")
- elseif errorcode == -3 then
- ShowSystemTips("最小数量不合法")
- elseif errorcode == -4 then
- ShowSystemTips("货币类型不合法")
- elseif errorcode == -5 then
- ShowSystemTips("数量不合法")
- elseif errorcode == -6 then
- ShowSystemTips("金额不合法")
- elseif errorcode == -7 then
- ShowSystemTips("玩家货币不足")
- elseif errorcode == -8 then
- ShowSystemTips("有未提取道具不允许下架")
- end
- global.Facade:sendNotification(global.NoticeTable.PurchaseOperaResp, {errorcode = errorcode})
- end
- -- recog 类型 1=上架 2=取出 3=出售 4=下架
- function PurchaseProxy:RespItemUpdate(msg)
- local header = msg:GetHeader()
- local action = header.recog
- local jsonData = ParseRawMsgToJson(msg)
- print("==================RespItemUpdate===============", action)
- dump(jsonData)
- local PlayerProperty = global.Facade:retrieveProxy(global.ProxyTable.PlayerProperty)
- local myUid = PlayerProperty:GetRoleUID()
- local isMy = jsonData.userid == myUid
- -- 已收列表 待提取数量 > 0
- local isReceive = jsonData.waitrecqty > 0
- -- type: 1 新增
- local TYPE = {
- ADD = 1,
- REMOVE = 2,
- UPDATE = 3,
- }
- if action == 1 then -- 上架
- if isMy then
- SLBridge:onLUAEvent(LUA_EVENT_PURCHASE_MYITEM_UPDATE, {isReceive = isReceive, type = TYPE.ADD, item = jsonData})
- else
- SLBridge:onLUAEvent(LUA_EVENT_PURCHASE_WORLDITEM_UPDATE, {type = TYPE.ADD, item = jsonData})
- end
- elseif action == 2 then -- 取出
- if isMy then -- 已收列表
- SLBridge:onLUAEvent(LUA_EVENT_PURCHASE_MYITEM_UPDATE, {isReceive = true, type = TYPE.REMOVE, item = jsonData})
- end
- elseif action == 3 then -- 出售 / 已收列表新增
- if isMy then
- SLBridge:onLUAEvent(LUA_EVENT_PURCHASE_MYITEM_UPDATE, {isReceive = isReceive, type = TYPE.UPDATE, item = jsonData})
- else
- SLBridge:onLUAEvent(LUA_EVENT_PURCHASE_WORLDITEM_UPDATE, {type = TYPE.UPDATE, item = jsonData})
- end
- elseif action == 4 then -- 下架
- if isMy then
- SLBridge:onLUAEvent(LUA_EVENT_PURCHASE_MYITEM_UPDATE, {type = TYPE.REMOVE, item = jsonData})
- else
- SLBridge:onLUAEvent(LUA_EVENT_PURCHASE_WORLDITEM_UPDATE, {type = TYPE.REMOVE, item = jsonData})
- end
- end
- end
- function PurchaseProxy:RegisterMsgHandler()
- PurchaseProxy.super.RegisterMsgHandler(self)
- local msgType = global.MsgType
-
- LuaRegisterMsgHandler(msgType.MSG_SC_PURCHASE_ITEM_LIST, handler(self, self.RespItemList))
- LuaRegisterMsgHandler(msgType.MSG_SC_PURCHASE_OPERA, handler(self, self.RespOperaBack))
- LuaRegisterMsgHandler(msgType.MSG_SC_PURCHASE_UPDATE, handler(self, self.RespItemUpdate))
- end
- return PurchaseProxy
|