neo il y a 1 an
Parent
commit
b6eed5934f

+ 48 - 0
dev/data/player.lua

@@ -0,0 +1,48 @@
1
+--[[
2
+Descripttion:玩家信息
3
+version:
4
+Author: Neo,Huang
5
+Date: 2021-09-15 19:47:54
6
+LastEditors: Neo,Huang
7
+LastEditTime: 2021-09-15 19:47:55
8
+--]]
9
+local code = require("code")
10
+local timeUtil = require("utils.timeUtil")
11
+local moduleData = require("data.module")
12
+
13
+local MODULE_NAME = "player"
14
+
15
+local root = {}
16
+
17
+-- 更新验证码
18
+function root:update_verify_code(uid)
19
+    if is_empty(uid) or is_robot(uid) then
20
+        return
21
+    end
22
+    local r = {}
23
+    for i = 1, 6 do
24
+        table.insert(r, string.char(math.random(48, 57)))
25
+    end
26
+    local vcode = table.concat(r)
27
+    local vcodeInfo = {vcode = vcode, timeout = timeUtil.now(uid) + 60}
28
+    moduleData:hset(uid, MODULE_NAME, "vcodeInfo", vcodeInfo)
29
+    return vcode
30
+end
31
+
32
+-- 获取验证码
33
+function root:get_verify_code(uid)
34
+    if is_empty(uid) or is_robot(uid) then
35
+        return
36
+    end
37
+    local vcodeInfo = moduleData:hget_json(uid, MODULE_NAME, "vcodeInfo")
38
+    if is_empty(vcodeInfo) or is_empty(vcodeInfo.vcode) then
39
+        return code.VERIFY_CODE.VERIFY_CODE
40
+    end
41
+    local currTime = timeUtil.now(uid)
42
+    if currTime > (vcodeInfo.timeout or 0) then
43
+        return code.VERIFY_CODE.TIME_OUT
44
+    end
45
+    return code.OK, vcodeInfo.vcode
46
+end
47
+
48
+return root

+ 20 - 0
dev/data/user.lua

@@ -29,6 +29,9 @@ function root:user_init_register_info(uid, info)
29 29
     moduleData:hset(uid, MODULE_NAME, "deviceId", info.deviceId or "")
30 30
     moduleData:hset(uid, MODULE_NAME, "channel", info.channel)
31 31
 
32
+    moduleData:hset(uid, MODULE_NAME, "phone", info.phone)
33
+    moduleData:hset(uid, MODULE_NAME, "shareCode", info.shareCode)
34
+
32 35
     moduleData:hset(uid, MODULE_NAME, "nickname", info.nickname or string.format("玩家%06d", uid))
33 36
     -- 非测试环境随机密码
34 37
     local password = info.password
@@ -69,4 +72,21 @@ function root:get_status(uid)
69 72
     return moduleData:hget(uid, MODULE_NAME, "status")
70 73
 end
71 74
 
75
+-- 获取当前邀请码
76
+function root:get_share_code(uid)
77
+    if is_empty(uid) then
78
+        return
79
+    end
80
+    return moduleData:hget(uid, MODULE_NAME, "shareCode")
81
+end
82
+
83
+-- 绑定邀请码
84
+function root:band_share_code(uid, sharecode)
85
+    if is_empty(uid) then
86
+        return false
87
+    end
88
+    moduleData:hset(uid, MODULE_NAME, "bandShareCode", sharecode)
89
+    return true
90
+end
91
+
72 92
 return root

+ 16 - 0
dev/modules/sharecode.lua

@@ -0,0 +1,16 @@
1
+-- 要求码
2
+local root = class("sharecode", require("base.baseModule"))
3
+
4
+function root:ctor(sharecode)
5
+    root.super.ctor(self, sharecode, "sharecode", "sharecode", true, false)
6
+    self.sharecode = sharecode
7
+end
8
+
9
+function root:mysql_get_init_columns()
10
+    return {
11
+        sharecode = "varchar(20) NOT NULL COMMENT '邀请码'",
12
+        uid = "bigint(20) unsigned NOT NULL COMMENT '用户ID'"
13
+    }
14
+end
15
+
16
+return root

+ 67 - 2
dev/modules/user.lua

@@ -1,5 +1,8 @@
1 1
 local code = require("code")
2 2
 local util_player = require("utils.util_player")
3
+local util_global = require("utils.util_global")
4
+
5
+local playerData = require("data.player")
3 6
 
4 7
 local root = class("user", require("base.baseModule"))
5 8
 
@@ -30,7 +33,11 @@ function root:mysql_get_init_columns()
30 33
         registerTime = "int(11) DEFAULT 0 COMMENT '注册时间'",
31 34
         registerVersion = "varchar(45) DEFAULT NULL COMMENT '注册版本'",
32 35
         ip = "varchar(45) DEFAULT NULL COMMENT 'IP'",
33
-        status = "int(11) DEFAULT 0 COMMENT '账号状态 0:正常 1:封号 2:注销'"
36
+        status = "int(11) DEFAULT 0 COMMENT '账号状态 0:正常 1:封号 2:注销'",
37
+        phone = "varchar(45) DEFAULT NULL COMMENT '绑定手机号'",
38
+        bandShareCode = "varchar(45) DEFAULT NULL COMMENT '绑定推广码'",
39
+        shareCode = "varchar(45) DEFAULT NULL COMMENT '我的推广码'",
40
+        steamLink = "varchar(45) DEFAULT NULL COMMENT 'steam交易链接'"
34 41
     }
35 42
 end
36 43
 
@@ -40,7 +47,65 @@ end
40 47
 -- 获取自己的信息
41 48
 function root:itf_get_info(role, msg)
42 49
     local info = util_player:get_player_info(self.uid)
43
-    return code.OK, {baseInfo = info}
50
+    return code.OK, {playerInfo = info}
51
+end
52
+
53
+-- 获取验证码
54
+function root:itf_get_verify_code(role, msg)
55
+    local vcode = playerData:update_verify_code(self.uid)
56
+    local ret = {}
57
+    if IS_TEST then
58
+        ret.vcode = vcode
59
+    else
60
+        -- 发短信
61
+    end
62
+    return code.OK, ret
63
+end
64
+
65
+-- 更新主播邀请码
66
+function root:itf_update_band_share_code(role, msg)
67
+    local shareCode = msg.shareCode
68
+    if is_empty(shareCode) then
69
+        return code.PARAMTER_ERROR
70
+    end
71
+    if not util_global:is_sharecode_active(shareCode) then
72
+        -- 邀请码不存在
73
+        return code.SHARE_CODE.NOT_FOUND
74
+    end
75
+    self:redis_update_key_info("bandShareCode", shareCode)
76
+    return code.OK
77
+end
78
+
79
+-- 更新自己邀请码
80
+function root:itf_update_share_code(role, msg)
81
+    local shareCode = msg.shareCode
82
+    if is_empty(shareCode) then
83
+        shareCode = util_global:gen_share_code()
84
+    end
85
+    if not util_global:is_sharecode_active(shareCode) then
86
+        -- 邀请码已存在
87
+        return code.SHARE_CODE.EXIST
88
+    end
89
+    self:redis_update_key_info("shareCode", shareCode)
90
+    return code.OK
91
+end
92
+
93
+-- 更新steam交易链接
94
+function root:itf_update_steam_link(role, msg)
95
+    local link = msg.link
96
+    local vcode = msg.vcode
97
+    if is_empty(link) or is_empty(vcode) then
98
+        return code.PARAMTER_ERROR
99
+    end
100
+    local errcode, _vcode = playerData:get_verify_code(self.uid)
101
+    if code.is_not_ok(errcode) then
102
+        return errcode
103
+    end
104
+    if vcode ~= _vcode then
105
+        return code.VERIFY_CODE.NOT_MATCH
106
+    end
107
+    self:redis_update_key_info("steamLink", link)
108
+    return code.OK
44 109
 end
45 110
 
46 111
 return root

+ 56 - 1
dev/utils/util_global.lua

@@ -1,5 +1,5 @@
1 1
 --[[
2
-Descripttion:玩家事件
2
+Descripttion:全局
3 3
 version:
4 4
 Author: Neo,Huang
5 5
 Date: 2022-07-05 19:59:16
@@ -7,6 +7,9 @@ LastEditors: Neo,Huang
7 7
 LastEditTime: 2022-07-05 20:08:31
8 8
 --]]
9 9
 local lib_game_redis = require("lib_game_redis")
10
+local lib_game_mysql = require("lib_game_mysql")
11
+
12
+local userData = require("data.user")
10 13
 
11 14
 local MODULE_NAME = "global"
12 15
 
@@ -30,4 +33,56 @@ function root:gen_mail_id()
30 33
     return id
31 34
 end
32 35
 
36
+-- 创建邀请码
37
+function root:gen_share_code()
38
+    local function _gen_code()
39
+        local r = {}
40
+        for i = 1, 5 do
41
+            table.insert(r, string.char(math.random(65, 90)))
42
+        end
43
+        return table.concat(r)
44
+    end
45
+    local sharecode = _gen_code()
46
+    while self:is_sharecode_active(sharecode) do
47
+        sharecode = _gen_code()
48
+    end
49
+    -- 绑定
50
+    lib_game_redis:sadd("sharecode", sharecode)
51
+
52
+    return sharecode
53
+end
54
+
55
+-- 邀请码是否使用
56
+function root:is_sharecode_active(sharecode)
57
+    if is_empty(sharecode) then
58
+        return false
59
+    end
60
+    local ret = lib_game_redis:sismerber("sharecode", sharecode)
61
+    return ret == 1
62
+end
63
+-- 删除邀请码
64
+function root:del_sharecode(sharecode)
65
+    local sql = string.format("delete from `mdl_sharecode` where `sharecode` = '%s'", tostring(sharecode))
66
+    lib_game_mysql:query(sql)
67
+    lib_game_redis:srem("sharecode", sharecode)
68
+end
69
+-- 更新邀请码
70
+function root:update_sharecode(uid, sharecode)
71
+    if is_empty(uid) or is_empty(sharecode) then
72
+        return false
73
+    end
74
+    -- 删除旧邀请码
75
+    local shareCode = userData:get_share_code(uid)
76
+    if not is_empty(shareCode) then
77
+        self:del_sharecode(shareCode)
78
+    end
79
+    -- 更新
80
+    lib_game_redis:sadd("sharecode", sharecode)
81
+
82
+    local values = string.format("sharecode='%s', uid=%s", tostring(sharecode), tostring(uid))
83
+    local sql = string.format("insert into mdl_sharecode set %s;", tostring(values))
84
+    lib_game_mysql:query(sql)
85
+    return true
86
+end
87
+
33 88
 return root

+ 19 - 0
dev/utils/util_player.lua

@@ -24,4 +24,23 @@ function root:get_player_info(uid)
24 24
     return info
25 25
 end
26 26
 
27
+-- 玩家基础信息
28
+function root:get_base_info(uid)
29
+    local info = {
30
+        uid = uid,
31
+        nickname = moduleData:hget(uid, "user", "nickname"),
32
+        icon = moduleData:hget(uid, "user", "headUrl"),
33
+        level = moduleData:hget_int(uid, "player", "level"),
34
+        vipLevel = moduleData:hget_int(uid, "player", "vipLevel"),
35
+        registerVersion = moduleData:hget(uid, "user", "registerVersion"),
36
+        activeDays = moduleData:hget(uid, "player", "activeDays"),
37
+        phone = moduleData:hget(uid, "user", "phone"),
38
+        bandShareCode = moduleData:hget(uid, "user", "bandShareCode"),
39
+        shareCode = moduleData:hget(uid, "user", "shareCode"),
40
+        steamLink = moduleData:hget(uid, "user", "steamLink"),
41
+        isRealname = false
42
+    }
43
+    return info
44
+end
45
+
27 46
 return root

+ 24 - 0
nodes/game/interface/user.lua

@@ -9,6 +9,10 @@ LastEditTime: 2022-07-05 20:29:29
9 9
 local code = require "code"
10 10
 local timeUtil = require("utils.timeUtil")
11 11
 local util_user = require("utils.util_user")
12
+local util_global = require("utils.util_global")
13
+
14
+local playerData = require("data.player")
15
+local userData = require("data.user")
12 16
 
13 17
 local root = {}
14 18
 
@@ -26,4 +30,24 @@ function root:after_user_self_info(role, msg)
26 30
     util_user:user_proto_notify(role.uid, "on_user_system_info", msg)
27 31
 end
28 32
 
33
+-- 获取验证码
34
+function root:user_get_verify_code(role, msg)
35
+    return role.user:itf_get_verify_code(role, msg)
36
+end
37
+
38
+-- 更新主播邀请码
39
+function root:user_update_band_share_code(role, msg)
40
+    return role.user:itf_update_band_share_code(role, msg)
41
+end
42
+
43
+-- 更新自己邀请码
44
+function root:user_update_share_code(role, msg)
45
+    return role.user:itf_update_share_code(role, msg)
46
+end
47
+
48
+-- 更新steam交易链接
49
+function root:user_update_steam_link(role, msg)
50
+    return role.user:itf_update_steam_link(role, msg)
51
+end
52
+
29 53
 return root

+ 15 - 4
nodes/login/controllers/usr.lua

@@ -1,12 +1,13 @@
1
-local code = require "code"
2
-local tokenUtil = require "utils.tokenUtil"
1
+local code = require("code")
2
+local tokenUtil = require("utils.tokenUtil")
3 3
 local serverLogUtil = require("utils.serverLogUtil")
4 4
 local util_user = require("utils.util_user")
5
-local accountModule = require("modules.account")
6 5
 local util_global = require("utils.util_global")
7
-
8 6
 local lib_game_mysql = require("lib_game_mysql")
9 7
 local lib_game_redis = require("lib_game_redis")
8
+
9
+local accountModule = require("modules.account")
10
+
10 11
 local moduleData = require("data.module")
11 12
 local userData = require("data.user")
12 13
 
@@ -159,8 +160,18 @@ function root.usr_register_by_phone(msg)
159 160
     err = moduleData:hset(account, "account", "uid", uid)
160 161
     err = accountObj:backup_to_db()
161 162
 
163
+    -- 生产推广码
164
+    msg.shareCode = util_global:gen_share_code()
165
+    local values = string.format("sharecode='%s', uid=%s", tostring(msg.shareCode), tostring(uid))
166
+    local sql = string.format("insert into mdl_sharecode set %s;", tostring(values))
167
+    lib_game_mysql:query(sql)
168
+
162 169
     -- 正常注册
163 170
     userData:user_init_register_info(uid, msg)
171
+    -- 绑定主播邀请码
172
+    if not is_empty(msg.sharecode) and util_global:is_sharecode_active(msg.sharecode) then
173
+        userData:band_share_code(uid, msg.sharecode)
174
+    end
164 175
     -- 注册埋点
165 176
     serverLogUtil.logRegister(uid, msg.channel, msg.version, msg.sysVer or "", msg.uuid, msg.udid, msg.ip)
166 177