修改用户是否注册和返回结果处理的问题
This commit is contained in:
parent
896b001a2c
commit
89c57ccd97
|
|
@ -36,12 +36,16 @@ local function getUuid()
|
|||
end
|
||||
|
||||
--数据库执行sql语句
|
||||
function _M.execSQL(sql)
|
||||
local function execSQL(sql)
|
||||
local res = nil
|
||||
if sql == '' or sql == nil then
|
||||
return 0x000003,res
|
||||
end
|
||||
--获取数据库连接
|
||||
local code,conn = get_con(dbconf.postgres)
|
||||
if code ~= 0 then
|
||||
return 0x000003,res
|
||||
end
|
||||
--执行数据库操作
|
||||
res = conn:query(sql)
|
||||
if not res then
|
||||
|
|
@ -58,16 +62,20 @@ local function checkJson(jsonData)
|
|||
local success, result = pcall(function()
|
||||
return cjson.decode(jsonData)
|
||||
end)
|
||||
if success == true then
|
||||
return true, result
|
||||
end
|
||||
local res = nil
|
||||
return success,res
|
||||
return false,res
|
||||
end
|
||||
|
||||
--通过查询条件判断数据库中的数据记录
|
||||
--根据用户、手机号、邮箱进行验证用户是否存在
|
||||
local function checkUserExist(username, phone, email)
|
||||
--组装sql语句
|
||||
local where = string.format("where username=\'%s\' or phone=\'%s\' or email=\'%s\'", username, phone, email)
|
||||
local sql = string.format("select count(*) from \"T_Users\" %s", where)
|
||||
local where = string.format("where username='%s' or phone='%s' or email='%s'", username, phone, email)
|
||||
local sql = string.format("select count(*) as count from \"T_Users\" %s", where)
|
||||
print("check sql: "..sql)
|
||||
--获取数据库连接
|
||||
return execSQL(sql)
|
||||
end
|
||||
|
|
@ -82,7 +90,7 @@ end
|
|||
--根据用户id获取用户信息
|
||||
function _M.getUser(uuid)
|
||||
--组装sql语句
|
||||
local sql = "select * from \"T_Users\" where uuid="..uuid
|
||||
local sql = "select * from \"T_Users\" where uuid='"..uuid.."'"
|
||||
return execSQL(sql)
|
||||
end
|
||||
|
||||
|
|
@ -94,30 +102,34 @@ function _M.addUser(jsonData)
|
|||
return 0x000001,result
|
||||
end
|
||||
--解析json中的键和数据值
|
||||
local keys, values
|
||||
local keys = ""
|
||||
local values = ""
|
||||
local username, phone, email
|
||||
for key, value in pairs(result) do
|
||||
keys = keys..key..","
|
||||
values = values..((type(value) == "string") and "\'"..value.."\'" or value)..","
|
||||
values = values..((type(value) == "string") and "'"..value.."'" or value)..","
|
||||
if key == "username" then username = value end
|
||||
if key == "phone" then phone = value end
|
||||
if key == "email" then email = value end
|
||||
end
|
||||
--校验用户是否存在
|
||||
local ok, res = checkUserExist(username, phone, email)
|
||||
if ok == false then
|
||||
if ok ~= 0 then
|
||||
return 0x000001,res
|
||||
end
|
||||
local count = 0
|
||||
for _k, _v in pairs(res) do
|
||||
count = _v
|
||||
local num = 0
|
||||
for _, row in ipairs(res) do
|
||||
for key, value in pairs(row) do
|
||||
num = value
|
||||
end
|
||||
end
|
||||
if count > 0 then
|
||||
print("exec result:", num)
|
||||
if num > 0 then
|
||||
return 0x010000,nil
|
||||
end
|
||||
--自己增加对应的uuid数据值
|
||||
local newKeys = keys.."uuid"
|
||||
local newValues = values.."\'"..getUuid().."\'"
|
||||
local newValues = values.."'"..getUuid().."'"
|
||||
--组装sql语句
|
||||
local sql = string.format("insert into \"T_Users\"(%s)values(%s)", newKeys, newValues)
|
||||
return execSQL(sql)
|
||||
|
|
@ -126,7 +138,7 @@ end
|
|||
--增加用户信息到数据表
|
||||
function _M.delete_user(uuid)
|
||||
--组装sql语句
|
||||
local sql = "delete from \"T_Users\" where uuid="..uuid
|
||||
local sql = "delete from \"T_Users\" where uuid='"..uuid.."'"
|
||||
return execSQL(sql)
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user