|
@@ -9,6 +9,8 @@ LastEditTime: 2023-11-15 22:41:18
|
9
|
9
|
local timeUtil = require("utils.timeUtil")
|
10
|
10
|
local redisUtil = require("utils.redisUtil")
|
11
|
11
|
local util_player = require("utils.util_player")
|
|
12
|
+local mysqlUtil = require("utils.mysqlUtil")
|
|
13
|
+local lib_game_redis = require("lib_game_redis")
|
12
|
14
|
|
13
|
15
|
local baseAdapt = require("base.baseAdapt")
|
14
|
16
|
local boxAdapt = require("adapt.boxAdapt")
|
|
@@ -18,6 +20,9 @@ local MODULE_NAME = "box"
|
18
|
20
|
|
19
|
21
|
local root = {}
|
20
|
22
|
|
|
23
|
+----------------------------------------
|
|
24
|
+-- 盲盒
|
|
25
|
+----------------------------------------
|
21
|
26
|
local function _get_box_key(boxId)
|
22
|
27
|
return string.format("%s:%s", MODULE_NAME, tostring(boxId))
|
23
|
28
|
end
|
|
@@ -92,5 +97,149 @@ function root:pack_box_info_list(boxId)
|
92
|
97
|
end
|
93
|
98
|
return boxInfoList
|
94
|
99
|
end
|
|
100
|
+----------------------------------------
|
|
101
|
+-- 追梦
|
|
102
|
+----------------------------------------
|
|
103
|
+local function _get_dream_key()
|
|
104
|
+ return "box:dream"
|
|
105
|
+end
|
|
106
|
+local function _get_dream_odds_tims_key(ti)
|
|
107
|
+ return string.format("box:dream:odds-times:%s", timeUtil.toDate(ti))
|
|
108
|
+end
|
|
109
|
+-- 新增记录
|
|
110
|
+function root:dream_add_record(uid, itemId, odds, dropItem, isWin)
|
|
111
|
+ if is_empty(uid) or is_empty(itemId) or is_empty(odds) or is_empty(dropItem) then
|
|
112
|
+ return false
|
|
113
|
+ end
|
|
114
|
+ local price = resAdapt:get_item_price(itemId)
|
|
115
|
+ if is_empty(price) then
|
|
116
|
+ return false
|
|
117
|
+ end
|
|
118
|
+
|
|
119
|
+ local dropTime = timeUtil.now()
|
|
120
|
+ local expireTime = dropItem + timeUtil.SEC_PER_DAY * 365
|
|
121
|
+ local sql =
|
|
122
|
+ string.format(
|
|
123
|
+ "INSERT INTO `mdl_dream` (`uid`,`itemId`,`dropItem`,`price`,`odds`,`isWin`,`dropTime`,`expireTime`)" ..
|
|
124
|
+ " VALUES (%s,%s,'%s',%s,%s,%s,%s,%s); ",
|
|
125
|
+ tostring(uid),
|
|
126
|
+ tostring(itemId),
|
|
127
|
+ cjson_encode(dropItem),
|
|
128
|
+ tostring(price),
|
|
129
|
+ tostring(odds),
|
|
130
|
+ tostring(isWin and 1 or 0),
|
|
131
|
+ tostring(dropTime),
|
|
132
|
+ tostring(expireTime)
|
|
133
|
+ )
|
|
134
|
+
|
|
135
|
+ return mysqlUtil:insert(sql)
|
|
136
|
+end
|
|
137
|
+-- 新增概率次数
|
|
138
|
+function root:dream_add_odds_times(odds, isWin)
|
|
139
|
+ if is_empty(odds) then
|
|
140
|
+ return false
|
|
141
|
+ end
|
|
142
|
+ local key = _get_dream_odds_tims_key()
|
|
143
|
+ local subKey = string.format("odds:%s:%s", tostring(odds), tostring(isWin and 1 or 0))
|
|
144
|
+ local times = redisUtil.hget_int(key, subKey)
|
|
145
|
+ times = times + 1
|
|
146
|
+ redisUtil.hset(key, subKey, times)
|
|
147
|
+end
|
|
148
|
+
|
|
149
|
+-- 获取精彩瞬间记录
|
|
150
|
+function root:dream_get_brilliants()
|
|
151
|
+ local minPrice = 100000
|
|
152
|
+ local count = 20
|
|
153
|
+ local sql =
|
|
154
|
+ string.format(
|
|
155
|
+ "SELECT * FROM `mdl_dream` WHERE `price`>=%s AND `isWin`=1 ORDER BY dropTime DESC limit %s",
|
|
156
|
+ tostring(minPrice),
|
|
157
|
+ tostring(count)
|
|
158
|
+ )
|
|
159
|
+ local ok, ret = mysqlUtil:select(sql)
|
|
160
|
+ if not ok or is_empty(ret) then
|
|
161
|
+ return
|
|
162
|
+ end
|
|
163
|
+ local list = {}
|
|
164
|
+ for _, v in ipairs(ret) do
|
|
165
|
+ local uid = tonumber(v.uid)
|
|
166
|
+ local info = {
|
|
167
|
+ playerInfo = util_player:get_base_info(uid),
|
|
168
|
+ itemId = tonumber(v.itemId),
|
|
169
|
+ dropItem = cjson_decode(v.dropItem),
|
|
170
|
+ price = tonumber(v.price),
|
|
171
|
+ odds = tonumber(v.odds),
|
|
172
|
+ dropTime = tonumber(v.dropTime)
|
|
173
|
+ }
|
|
174
|
+ table.insert(list, info)
|
|
175
|
+ end
|
|
176
|
+ return list
|
|
177
|
+end
|
|
178
|
+
|
|
179
|
+-- 掉落记录
|
|
180
|
+function root:dream_get_records()
|
|
181
|
+ local count = 20
|
|
182
|
+ local sql = string.format("SELECT * FROM `mdl_dream` ORDER BY dropTime DESC limit %s", tostring(count))
|
|
183
|
+ local ok, ret = mysqlUtil:select(sql)
|
|
184
|
+ if not ok or is_empty(ret) then
|
|
185
|
+ return
|
|
186
|
+ end
|
|
187
|
+ local list = {}
|
|
188
|
+ for _, v in ipairs(ret) do
|
|
189
|
+ local uid = tonumber(v.uid)
|
|
190
|
+ local info = {
|
|
191
|
+ playerInfo = util_player:get_base_info(uid),
|
|
192
|
+ itemId = tonumber(v.itemId),
|
|
193
|
+ dropItem = cjson_decode(v.dropItem),
|
|
194
|
+ price = tonumber(v.price),
|
|
195
|
+ odds = tonumber(v.odds),
|
|
196
|
+ dropTime = tonumber(v.dropTime)
|
|
197
|
+ }
|
|
198
|
+ table.insert(list, info)
|
|
199
|
+ end
|
|
200
|
+ return list
|
|
201
|
+end
|
|
202
|
+
|
|
203
|
+-- 次数统计
|
|
204
|
+function root:dream_get_statement()
|
|
205
|
+ local days = 3
|
|
206
|
+ local mapOddsWinTims = {}
|
|
207
|
+ local mapOddsLoseTims = {}
|
|
208
|
+ local currTime = timeUtil.now()
|
|
209
|
+ for i = 0, days - 2 do
|
|
210
|
+ local ti = currTime - timeUtil.SEC_PER_DAY * i
|
|
211
|
+ local key = _get_dream_odds_tims_key(ti)
|
|
212
|
+ for odds = 5, 85 do
|
|
213
|
+ -- 中奖
|
|
214
|
+ local subKey = string.format("odds:%s:1", tostring(odds))
|
|
215
|
+ local times = redisUtil.hget_int(key, subKey)
|
|
216
|
+ mapOddsWinTims[odds] = (mapOddsWinTims[odds] or 0) + times
|
|
217
|
+ -- 不中奖
|
|
218
|
+ subKey = string.format("odds:%s:0", tostring(odds))
|
|
219
|
+ times = redisUtil.hget_int(key, subKey)
|
|
220
|
+ mapOddsLoseTims[odds] = (mapOddsLoseTims[odds] or 0) + times
|
|
221
|
+ end
|
|
222
|
+ end
|
|
223
|
+ local oddsTimesList = {}
|
|
224
|
+ for odds = 5, 85 do
|
|
225
|
+ if not is_empty(mapOddsWinTims[odds]) or not is_empty(mapOddsLoseTims[odds]) then
|
|
226
|
+ local info = {
|
|
227
|
+ odds = odds,
|
|
228
|
+ winTimes = mapOddsWinTims[odds] or 0,
|
|
229
|
+ loseTimes = mapOddsLoseTims[odds] or 0
|
|
230
|
+ }
|
|
231
|
+ table.insert(oddsTimesList, info)
|
|
232
|
+ end
|
|
233
|
+ end
|
|
234
|
+ return oddsTimesList
|
|
235
|
+end
|
|
236
|
+-- 删除天统计
|
|
237
|
+function root:dream_del_day_statement(ti)
|
|
238
|
+ if is_empty(ti) then
|
|
239
|
+ return
|
|
240
|
+ end
|
|
241
|
+ local key = _get_dream_odds_tims_key(ti)
|
|
242
|
+ lib_game_redis:del(key)
|
|
243
|
+end
|
95
|
244
|
|
96
|
245
|
return root
|