ShopInfo.lua
9.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
cc.exports.ShopInfo = {}
local xml = require("core.utils.pl.xml")
local shopCouponsList = {}; --点券
local shopCoinList = {}; --金币
local shopItemsList = {}; --道具
local shopCoinItemsList = {}; --头像框列表
local vipList = {}; --月卡
local firstPayList = {}; --首充礼包
local dailyPayList = {}; --每日充值
local cyclePayList = {}; --周期活动
local shop_real_digital = {}; --数码产品
local shop_real_other = {}; --其他产品
--道具配置表信息
local function init()
local configStr = cc.FileUtils:getInstance():getStringFromFile("res/config/shop.txt");
local function readLineFun(lineStr)
local info;
local contents = StringUtil.split(lineStr,'\t');
if #contents > 1 then
info = {};
info.id = tonumber(contents[1]);
info.itemList = {};
local itemArr = StringUtil.split(contents[2],';');
for i,v in ipairs(itemArr) do
local itemItemArr = StringUtil.split(v,',');
local itemInfo = {id=tonumber(itemItemArr[1]),num=tonumber(itemItemArr[2])};
info.itemList[i] = itemInfo;
end
info.costList = {};
local costArr = StringUtil.split(contents[3],';');
for i,v in ipairs(costArr) do
local costItemArr = StringUtil.split(v,',');
local costInfo = {id=tonumber(costItemArr[1]),num=tonumber(costItemArr[2])};
info.costList[i] = costInfo;
end
info.des = contents[4];
info.extra = tonumber(contents[5]);
end
return info;
end
local index = 1;
local function readLine(str)
local a,b = string.find(str,"\r\n");
if a then
local lineStr = string.sub(str,1,a-1);
if index > 2 then
local info = readLineFun(lineStr);
if info then
if info.id > 100 and info.id < 200 then
shopItemsList[#shopItemsList+1] = info;
elseif info.id > 3000 and info.id < 4000 then
shopCoinItemsList[#shopCoinItemsList+1] = info;
elseif info.id > 4000 and info.id < 5000 then
shop_real_digital[#shop_real_digital+1] = info;
elseif info.id > 5000 and info.id < 6000 then
shop_real_other[#shop_real_other+1] = info;
else
shopCoinList[#shopCoinList+1] = info;
end
end
end
index = index + 1;
str = string.sub(str,b+1);
readLine(str);
else
local info = readLineFun(str);
if info then
if info.id > 100 and info.id < 200 then
shopItemsList[#shopItemsList+1] = info;
elseif info.id > 3000 and info.id < 4000 then
shopCoinItemsList[#shopCoinItemsList+1] = info;
else
shopCoinList[#shopCoinList+1] = info;
end
end
end
end
readLine(configStr);
local configStr = cc.FileUtils:getInstance():getStringFromFile("res/config/pay.xml");
local data = xml.parse(configStr, false, true);
for k,v in pairs(data) do
if k ~= "attr" and k ~= "tag" then
local info = {};
info.id = tonumber(v.attr.id);
info.name = v.attr.name;
info.rmb = tonumber(v.attr.rmb);
info.type = tonumber(v.attr.type);
info.itemList = {};
local itemArr = StringUtil.split(v.attr.item,";");
for ii,vv in ipairs(itemArr) do
local arr = StringUtil.split(vv,",");
local itemInfo = {id=tonumber(arr[1]),num=tonumber(arr[2])};
info.itemList[ii] = itemInfo;
end
local costInfo = {id=0,num=v.attr.rmb};
info.costList = {costInfo};
if CHANNEL == "putao" then
info.product = v.attr.productPuTao;
else
info.product = v.attr.product;
end
if info.product and info.product ~= "" then
if info.type == 1 then
info.extra = tonumber(v.attr.extra);
shopCouponsList[#shopCouponsList+1] = info;
elseif info.type == 2 then
info.des = v.attr.des;
info.day = v.attr.day;
local arr = StringUtil.split(v.attr.payitem,",");
info.payItemInfo = {id=tonumber(arr[1]),num=tonumber(arr[2])};
vipList[#vipList+1] = info;
elseif info.type == 3 then
info.worth = v.attr.worth;
firstPayList[#firstPayList+1] = info;
elseif info.type == 4 then
info.worth = v.attr.worth;
dailyPayList[#dailyPayList+1] = info;
elseif info.type == 5 then
info.startTime = tonumber(v.attr.startTime);
info.endTime = tonumber(v.attr.endTime);
info.cuccFlag = tonumber(v.attr.cuccFlag);
cyclePayList[#cyclePayList+1] = info;
end
end
end
end
table.sort(firstPayList,function (aa,bb)
return aa.id<bb.id;
end);
end
init();
--通过ID获取商品信息
function ShopInfo.getShopInfo(id)
local info = nil;
for i,v in ipairs(shopCoinList) do
if v.id == id then
info = v;
break;
end
end
if not info then
for i,v in ipairs(shopItemsList) do
if v.id == id then
info = v;
break;
end
end
end
if not info then
for i,v in ipairs(shopCoinItemsList) do
if v.id == id then
info = v;
break;
end
end
end
if not info then
for i,v in ipairs(shop_real_digital) do
if v.id == id then
info = v;
break;
end
end
end
if not info then
for i,v in ipairs(shop_real_other) do
if v.id == id then
info = v;
break;
end
end
end
return info;
end
function ShopInfo.getPayInfo(id)
local info = nil;
for i,v in ipairs(shopCouponsList) do
if v.id == id then
info = v;
break;
end
end
if not info then
for i,v in ipairs(firstPayList) do
if v.id == id then
info = v;
break;
end
end
end
if not info then
for i,v in ipairs(dailyPayList) do
if v.id == id then
info = v;
break;
end
end
end
if not info then
for i,v in ipairs(cyclePayList) do
if v.id == id then
info = v;
break;
end
end
end
if not info then
for i,v in ipairs(vipList) do
if v.id == id then
info = v;
break;
end
end
end
return info;
end
function ShopInfo.getShopCouponsList()
return shopCouponsList;
end
function ShopInfo.getShopItemsList()
return shopItemsList;
end
function ShopInfo.getListByType(itemType)
local _list = {};
if itemType == 1 then
for i,v in ipairs(shopCoinList) do
if v.id > 1000 and v.id < 2000 then
_list[#_list + 1] = v;
end
end
elseif itemType == 2 then
_list = shopCouponsList;
elseif itemType == 3 then
_list = shopCoinItemsList;
elseif itemType == 4 then
for i,v in ipairs(shopItemsList) do
_list[#_list + 1] = v;
end
elseif itemType == 5 then
_list = shop_real_digital;
elseif itemType == 6 then
_list = shop_real_other;
end
return _list;
end
function ShopInfo.getFirstPayList()
return firstPayList;
end
function ShopInfo.getDailyPayList()
return dailyPayList;
end
function ShopInfo.getCyclePayList()
return cyclePayList;
end
function ShopInfo.getVipList()
return vipList;
end
function ShopInfo.getPayInfoByProduct(product)
local info = nil;
for i,v in ipairs(shopCouponsList) do
if v.product == product then
info = v;
end
end
for i,v in ipairs(vipList) do
if v.product == product then
info = v;
end
end
if not info then
for i,v in ipairs(firstPayList) do
if v.product == product then
info = v;
break;
end
end
end
if not info then
for i,v in ipairs(dailyPayList) do
if v.product == product then
info = v;
break;
end
end
end
if not info then
for i,v in ipairs(cyclePayList) do
if v.product == product then
info = v;
break;
end
end
end
return info;
end
return ShopInfo