1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- --[[
- Descripttion:全局
- version:
- Author: Neo,Huang
- Date: 2022-07-05 19:59:16
- LastEditors: Neo,Huang
- LastEditTime: 2022-07-05 20:08:31
- --]]
- local lib_game_redis = require("lib_game_redis")
- local lib_game_mysql = require("lib_game_mysql")
- local userData = require("data.user")
- local MODULE_NAME = "global"
- local root = {}
- -- 创建玩家id
- function root:gen_user_id()
- local uid = lib_game_redis:hincrby(MODULE_NAME, "user:max:id", 1)
- if uid < 1000000 then
- uid = uid + 1000000
- lib_game_redis:set("user:max:id", uid)
- end
- return uid
- end
- -- 创建邮件id
- function root:gen_mail_id()
- local id = lib_game_redis:hincrby(MODULE_NAME, "mail:max:id", 1)
- return id
- end
- -- 创建邀请码
- function root:gen_share_code()
- local function _gen_code()
- local r = {}
- for i = 1, 5 do
- table.insert(r, string.char(math.random(65, 90)))
- end
- return table.concat(r)
- end
- local sharecode = _gen_code()
- while self:is_sharecode_active(sharecode) do
- sharecode = _gen_code()
- end
- -- 绑定
- lib_game_redis:sadd("sharecode", sharecode)
- return sharecode
- end
- -- 邀请码是否使用
- function root:is_sharecode_active(sharecode)
- if is_empty(sharecode) then
- return false
- end
- local ret = lib_game_redis:sismerber("sharecode", sharecode)
- return ret == 1
- end
- -- 删除邀请码
- function root:del_sharecode(sharecode)
- local sql = string.format("delete from `mdl_sharecode` where `sharecode` = '%s'", tostring(sharecode))
- lib_game_mysql:query(sql)
- lib_game_redis:srem("sharecode", sharecode)
- end
- -- 更新邀请码
- function root:update_sharecode(uid, sharecode)
- if is_empty(uid) or is_empty(sharecode) then
- return false
- end
- -- 删除旧邀请码
- local shareCode = userData:get_share_code(uid)
- if not is_empty(shareCode) then
- self:del_sharecode(shareCode)
- end
- -- 更新
- lib_game_redis:sadd("sharecode", sharecode)
- local values = string.format("sharecode='%s', uid=%s", tostring(sharecode), tostring(uid))
- local sql = string.format("insert into mdl_sharecode set %s;", tostring(values))
- lib_game_mysql:query(sql)
- return true
- end
- return root
|