user.lua 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. local code = require("code")
  2. local util_player = require("utils.util_player")
  3. local util_global = require("utils.util_global")
  4. local playerData = require("data.player")
  5. local root = class("user", require("base.baseModule"))
  6. function root:ctor(uid)
  7. root.super.ctor(self, uid, "user", "uid", true)
  8. self.uid = uid
  9. end
  10. function root:mysql_get_init_columns()
  11. return {
  12. uid = "int(11) unsigned NOT NULL",
  13. nickname = "varchar(50)",
  14. password = "varchar(45) DEFAULT NULL",
  15. uuid = "varchar(200) DEFAULT NULL",
  16. udid = "varchar(200) DEFAULT NULL",
  17. channel = "int(11) DEFAULT NULL",
  18. device = "varchar(45) DEFAULT NULL",
  19. loginTime = "int(11) DEFAULT 0",
  20. sysVer = "varchar(1024) DEFAULT NULL",
  21. version = "varchar(45) DEFAULT NULL",
  22. appVersion = "varchar(45) DEFAULT NULL",
  23. deviceId = "varchar(200) DEFAULT NULL",
  24. headUrl = "varchar(500) DEFAULT NULL",
  25. sex = "int(11) DEFAULT NULL",
  26. token = "varchar(255)",
  27. lastLoginTime = "int(11) DEFAULT 0",
  28. logoutTime = "int(11) DEFAULT 0",
  29. registerTime = "int(11) DEFAULT 0 COMMENT '注册时间'",
  30. registerVersion = "varchar(45) DEFAULT NULL COMMENT '注册版本'",
  31. ip = "varchar(45) DEFAULT NULL COMMENT 'IP'",
  32. status = "int(11) DEFAULT 0 COMMENT '账号状态 0:正常 1:封号 2:注销'",
  33. phone = "varchar(45) DEFAULT NULL COMMENT '绑定手机号'",
  34. bandShareCode = "varchar(45) DEFAULT NULL COMMENT '绑定推广码'",
  35. shareCode = "varchar(45) DEFAULT NULL COMMENT '我的推广码'",
  36. steamLink = "varchar(45) DEFAULT NULL COMMENT 'steam交易链接'"
  37. }
  38. end
  39. ----------------------------------------
  40. -- 接口
  41. ----------------------------------------
  42. -- 获取自己的信息
  43. function root:itf_get_info(role, msg)
  44. local info = util_player:get_player_info(self.uid)
  45. return code.OK, {playerInfo = info}
  46. end
  47. -- 获取验证码
  48. function root:itf_get_verify_code(role, msg)
  49. local vcode = playerData:update_verify_code(self.uid)
  50. local ret = {}
  51. if IS_TEST then
  52. ret.vcode = vcode
  53. else
  54. -- 发短信
  55. end
  56. return code.OK, ret
  57. end
  58. -- 更新主播邀请码
  59. function root:itf_update_band_share_code(role, msg)
  60. local shareCode = msg.shareCode
  61. if is_empty(shareCode) then
  62. return code.PARAMTER_ERROR
  63. end
  64. if not util_global:is_sharecode_active(shareCode) then
  65. -- 邀请码不存在
  66. return code.SHARE_CODE.NOT_FOUND
  67. end
  68. self:redis_update_key_info("bandShareCode", shareCode)
  69. return code.OK
  70. end
  71. -- 更新自己邀请码
  72. function root:itf_update_share_code(role, msg)
  73. local shareCode = msg.shareCode
  74. if is_empty(shareCode) then
  75. shareCode = util_global:gen_share_code()
  76. end
  77. if not util_global:is_sharecode_active(shareCode) then
  78. -- 邀请码已存在
  79. return code.SHARE_CODE.EXIST
  80. end
  81. self:redis_update_key_info("shareCode", shareCode)
  82. return code.OK
  83. end
  84. -- 更新steam交易链接
  85. function root:itf_update_steam_link(role, msg)
  86. local link = msg.link
  87. local vcode = msg.vcode
  88. if is_empty(link) or is_empty(vcode) then
  89. return code.PARAMTER_ERROR
  90. end
  91. local errcode, _vcode = playerData:get_verify_code(self.uid)
  92. if code.is_not_ok(errcode) then
  93. return errcode
  94. end
  95. if vcode ~= _vcode then
  96. return code.VERIFY_CODE.NOT_MATCH
  97. end
  98. self:redis_update_key_info("steamLink", link)
  99. return code.OK
  100. end
  101. -- 更新头像
  102. function root:itf_update_icon(role, msg)
  103. local icon = msg.icon
  104. if is_empty(icon) then
  105. return code.PARAMTER_ERROR
  106. end
  107. self:redis_update_key_info("headUrl", icon)
  108. return code.OK
  109. end
  110. -- 更新昵称
  111. function root:itf_update_nickname(role, msg)
  112. local nickname = msg.nickname
  113. if is_empty(nickname) then
  114. return code.PARAMTER_ERROR
  115. end
  116. self:redis_update_key_info("nickname", nickname)
  117. return code.OK
  118. end
  119. -- 更新密码
  120. function root:itf_update_password(role, msg)
  121. local oldPassword = msg.oldPassword
  122. local newPassword = msg.newPassword
  123. if is_empty(oldPassword) or is_empty(newPassword) then
  124. return code.PARAMTER_ERROR
  125. end
  126. local password = self:redis_get_key_info("password")
  127. if oldPassword ~= password then
  128. return code.USR.PASSWORD_NOT_MATCH
  129. end
  130. self:redis_update_key_info("password", newPassword)
  131. return code.OK
  132. end
  133. -- 注销
  134. function root:itf_cancel_account(role, msg)
  135. return code.OK
  136. end
  137. -- 实名认证 - 更新信息
  138. function root:itf_identity(role, msg)
  139. return code.OK
  140. end
  141. return root