Compare commits
No commits in common. "8b69d78c3b88269540434e75a09e7968a667cb29" and "a3a7ee26ea3436e3cf760135be18bc2291303680" have entirely different histories.
8b69d78c3b
...
a3a7ee26ea
|
|
@ -11,10 +11,10 @@ local accountApi = require("api.system.account")
|
||||||
local routes = {
|
local routes = {
|
||||||
--用户相关路由接口
|
--用户相关路由接口
|
||||||
{
|
{
|
||||||
paths = { "/api/get-user" },
|
paths = { "/api/get-users" },
|
||||||
metadata = { "metadata get-user" },
|
metadata = { "metadata get-users" },
|
||||||
methods = { "GET" },
|
methods = { "GET" },
|
||||||
handler = userApi.get_alluser,
|
handler = userApi.get_allusers,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
paths = { "/api/get-user/:id" },
|
paths = { "/api/get-user/:id" },
|
||||||
|
|
@ -45,7 +45,7 @@ local routes = {
|
||||||
paths = { "/api/get-account" },
|
paths = { "/api/get-account" },
|
||||||
metadata = { "metadata get-account" },
|
metadata = { "metadata get-account" },
|
||||||
methods = { "GET" },
|
methods = { "GET" },
|
||||||
handler = accountApi.get_allaccount,
|
handler = accountApi.get_allaccounts,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
paths = { "/api/get-account/:id" },
|
paths = { "/api/get-account/:id" },
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
local _M = {}
|
local _M = {}
|
||||||
|
|
||||||
local dao = require("service.system.account")
|
local dao = require("service.system.user")
|
||||||
local resp = require("util.response")
|
local resp = require("util.response")
|
||||||
|
|
||||||
--验证请求头是否正确
|
--验证请求头是否正确
|
||||||
|
|
@ -20,14 +20,14 @@ local function checkReqHeader()
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
--获取所有账号信息
|
--获取所有用户信息
|
||||||
function _M.get_allaccount()
|
function _M.get_allaccount(uuid)
|
||||||
local code,ret = dao.getAllAccount()
|
local code,ret = dao.getAllAccount(uuid)
|
||||||
local result = resp:json(code, ret)
|
local result = resp:json(code, ret)
|
||||||
resp:send(result)
|
resp:send(result)
|
||||||
end
|
end
|
||||||
|
|
||||||
--根据账号id获取账号信息
|
--根据用户id获取用户信息
|
||||||
function _M.get_account(m)
|
function _M.get_account(m)
|
||||||
local id = m.id
|
local id = m.id
|
||||||
local code,ret = dao.getAccount(id)
|
local code,ret = dao.getAccount(id)
|
||||||
|
|
@ -35,10 +35,12 @@ function _M.get_account(m)
|
||||||
resp:send(result)
|
resp:send(result)
|
||||||
end
|
end
|
||||||
|
|
||||||
--根据账号id获取账号信息
|
--根据用户id获取用户信息
|
||||||
function _M.add_account()
|
function _M.add_account()
|
||||||
--获取请求头并进行校验
|
--获取请求头并进行校验
|
||||||
if checkReqHeader() == false then return end
|
if checkReqHeader() == false then
|
||||||
|
return
|
||||||
|
end
|
||||||
--读取请求体的数据
|
--读取请求体的数据
|
||||||
ngx.req.read_body()
|
ngx.req.read_body()
|
||||||
--获取请求数据
|
--获取请求数据
|
||||||
|
|
@ -55,7 +57,7 @@ function _M.add_account()
|
||||||
resp:send(result)
|
resp:send(result)
|
||||||
end
|
end
|
||||||
|
|
||||||
--根据账号id删除账号信息
|
--根据用户id删除用户信息
|
||||||
function _M.delete_account(m)
|
function _M.delete_account(m)
|
||||||
local id = m.id
|
local id = m.id
|
||||||
local code, ret = dao.deleteAccount(id)
|
local code, ret = dao.deleteAccount(id)
|
||||||
|
|
@ -63,20 +65,10 @@ function _M.delete_account(m)
|
||||||
resp:send(result)
|
resp:send(result)
|
||||||
end
|
end
|
||||||
|
|
||||||
--根据账号id删除账号信息
|
--根据用户id删除用户信息
|
||||||
function _M.update_account(m)
|
function _M.update_account(m)
|
||||||
local id = m.id
|
local id = m.id
|
||||||
--读取请求体的数据
|
local code, ret = dao.updateAccount(id)
|
||||||
ngx.req.read_body()
|
|
||||||
--获取请求数据
|
|
||||||
local body_data = ngx.req.get_body_data()
|
|
||||||
--判断请求体数据是否为空
|
|
||||||
if body_data == nil then
|
|
||||||
local result = resp:json(0x000001)
|
|
||||||
resp:send(result)
|
|
||||||
return
|
|
||||||
end
|
|
||||||
local code, ret = dao.updateAccount(id, body_data)
|
|
||||||
local result = resp:json(code, ret)
|
local result = resp:json(code, ret)
|
||||||
resp:send(result)
|
resp:send(result)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -8,10 +8,20 @@ local _M = {}
|
||||||
|
|
||||||
local dao = require("service.system.user")
|
local dao = require("service.system.user")
|
||||||
local resp = require("util.response")
|
local resp = require("util.response")
|
||||||
local validator = require("util.validator")
|
|
||||||
|
--验证请求头是否正确
|
||||||
|
local function checkReqHeader()
|
||||||
|
local headers = ngx.req.get_headers()
|
||||||
|
if headers["content-type"] ~= "application/json" then
|
||||||
|
local result = resp:json(0x000001)
|
||||||
|
resp:send(result)
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
--获取所有用户信息
|
--获取所有用户信息
|
||||||
function _M.get_alluser()
|
function _M.get_allusers()
|
||||||
local code,ret = dao.getAllUser()
|
local code,ret = dao.getAllUser()
|
||||||
local result = resp:json(code, ret)
|
local result = resp:json(code, ret)
|
||||||
resp:send(result)
|
resp:send(result)
|
||||||
|
|
@ -28,9 +38,7 @@ end
|
||||||
--根据用户id获取用户信息
|
--根据用户id获取用户信息
|
||||||
function _M.add_user()
|
function _M.add_user()
|
||||||
--获取请求头并进行校验
|
--获取请求头并进行校验
|
||||||
if validator.checkReqHeader() == false then
|
if checkReqHeader() == false then
|
||||||
local result = resp:json(0x000001)
|
|
||||||
resp:send(result)
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
--读取请求体的数据
|
--读取请求体的数据
|
||||||
|
|
@ -60,17 +68,7 @@ end
|
||||||
--根据用户id删除用户信息
|
--根据用户id删除用户信息
|
||||||
function _M.update_user(m)
|
function _M.update_user(m)
|
||||||
local id = m.id
|
local id = m.id
|
||||||
--读取请求体的数据
|
local code, ret = dao.update_user(id)
|
||||||
ngx.req.read_body()
|
|
||||||
--获取请求数据
|
|
||||||
local body_data = ngx.req.get_body_data()
|
|
||||||
--判断请求体数据是否为空
|
|
||||||
if body_data == nil then
|
|
||||||
local result = resp:json(0x000001)
|
|
||||||
resp:send(result)
|
|
||||||
return
|
|
||||||
end
|
|
||||||
local code, ret = dao.update_user(id, body_data)
|
|
||||||
local result = resp:json(code, ret)
|
local result = resp:json(code, ret)
|
||||||
resp:send(result)
|
resp:send(result)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -38,5 +38,4 @@ return {
|
||||||
[0x010009] = '重置密码失败,用户不存在',
|
[0x010009] = '重置密码失败,用户不存在',
|
||||||
[0x01000A] = '获取用户信息失败,用户未登录',
|
[0x01000A] = '获取用户信息失败,用户未登录',
|
||||||
[0x01000B] = '获取用户信息失败,用户不存在',
|
[0x01000B] = '获取用户信息失败,用户不存在',
|
||||||
[0x01000C] = '修改用户信息失败,用户不存在',
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,6 @@ local pgmoon = require('pgmoon')
|
||||||
local dbconf = require("config.database")
|
local dbconf = require("config.database")
|
||||||
local status = require("config.status")
|
local status = require("config.status")
|
||||||
local snowflake = require("util.snowflake")
|
local snowflake = require("util.snowflake")
|
||||||
local validator = require("util.validator")
|
|
||||||
|
|
||||||
local _M = {}
|
local _M = {}
|
||||||
|
|
||||||
|
|
@ -58,33 +57,47 @@ local function execSQL(sql)
|
||||||
return code,res
|
return code,res
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--校验json数据的正确性,并返回json解析后的数据
|
||||||
|
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 false,res
|
||||||
|
end
|
||||||
|
|
||||||
--通过查询条件判断数据库中的数据记录
|
--通过查询条件判断数据库中的数据记录
|
||||||
local function checkAccountExist(where)
|
--根据用户、手机号、邮箱进行验证用户是否存在
|
||||||
|
local function checkAccountExist(username, phone, email)
|
||||||
--组装sql语句
|
--组装sql语句
|
||||||
local sql = string.format("select count(*) as count from \"tbl_account\" %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)
|
print("check sql: "..sql)
|
||||||
--获取数据库连接
|
--获取数据库连接
|
||||||
return execSQL(sql)
|
return execSQL(sql)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- 查询数据表中的所有账号信息
|
-- 查询数据表中的所有账户根据用户的uuid
|
||||||
function _M.getAllAccount()
|
function _M.getAllAccount(uuid)
|
||||||
--组装sql语句
|
--组装sql语句
|
||||||
local sql = "select * from \"tbl_account\""
|
local sql = "select * from \"T_Users\""
|
||||||
return execSQL(sql)
|
return execSQL(sql)
|
||||||
end
|
end
|
||||||
|
|
||||||
--根据用户id获取账号信息
|
--根据用户id获取用户信息
|
||||||
function _M.getAccount(id)
|
function _M.getAccount(uuid)
|
||||||
--组装sql语句
|
--组装sql语句
|
||||||
local sql = "select * from \"tbl_account\" where id='"..id.."'"
|
local sql = "select * from \"T_Users\" where uuid='"..uuid.."'"
|
||||||
return execSQL(sql)
|
return execSQL(sql)
|
||||||
end
|
end
|
||||||
|
|
||||||
--增加账号信息到数据表
|
--增加用户信息到数据表
|
||||||
function _M.addAccount(jsonData)
|
function _M.addAccount(jsonData)
|
||||||
--验证数据的正确性,错误时返回
|
--验证数据的正确性,错误时返回
|
||||||
local success, result = validator.checkJson(jsonData)
|
local success, result = checkJson(jsonData)
|
||||||
if success == false then
|
if success == false then
|
||||||
return 0x000001,result
|
return 0x000001,result
|
||||||
end
|
end
|
||||||
|
|
@ -99,9 +112,8 @@ function _M.addAccount(jsonData)
|
||||||
if key == "phone" then phone = value end
|
if key == "phone" then phone = value end
|
||||||
if key == "email" then email = value end
|
if key == "email" then email = value end
|
||||||
end
|
end
|
||||||
--根据用户、手机号、邮箱进行验证用户是否存在
|
--校验用户是否存在
|
||||||
local where = string.format("where username='%s' or phone='%s' or email='%s'", username, phone, email)
|
local ok, res = checkAccountExist(username, phone, email)
|
||||||
local ok, res = checkAccountExist(where)
|
|
||||||
if ok ~= 0 then
|
if ok ~= 0 then
|
||||||
return 0x000001,res
|
return 0x000001,res
|
||||||
end
|
end
|
||||||
|
|
@ -116,52 +128,17 @@ function _M.addAccount(jsonData)
|
||||||
return 0x010000,nil
|
return 0x010000,nil
|
||||||
end
|
end
|
||||||
--自己增加对应的uuid数据值
|
--自己增加对应的uuid数据值
|
||||||
local newKeys = keys.."id"
|
local newKeys = keys.."uuid"
|
||||||
local newValues = values.."'"..getUuid().."'"
|
local newValues = values.."'"..getUuid().."'"
|
||||||
--组装sql语句
|
--组装sql语句
|
||||||
local sql = string.format("insert into \"tbl_account\"(%s)values(%s)", newKeys, newValues)
|
local sql = string.format("insert into \"T_Users\"(%s)values(%s)", newKeys, newValues)
|
||||||
return execSQL(sql)
|
return execSQL(sql)
|
||||||
end
|
end
|
||||||
|
|
||||||
--增加账号信息到数据表
|
--增加用户信息到数据表
|
||||||
function _M.deleteAccount(id)
|
function _M.deleteAccount(uuid)
|
||||||
--组装sql语句
|
--组装sql语句
|
||||||
local sql = "delete from \"tbl_account\" where id='"..id.."'"
|
local sql = "delete from \"T_Users\" where uuid='"..uuid.."'"
|
||||||
return execSQL(sql)
|
|
||||||
end
|
|
||||||
|
|
||||||
--更新账号信息到数据表
|
|
||||||
function _M.updateAccount(id, jsonData)
|
|
||||||
--根据用户id进行验证用户是否存在
|
|
||||||
local where = string.format("where id='%s'", id)
|
|
||||||
local ok, res = checkAccountExist(where)
|
|
||||||
if ok ~= 0 then
|
|
||||||
return 0x000001,res
|
|
||||||
end
|
|
||||||
local num = 0
|
|
||||||
for _, row in ipairs(res) do
|
|
||||||
for key, value in pairs(row) do
|
|
||||||
num = value
|
|
||||||
end
|
|
||||||
end
|
|
||||||
print("exec result:", num)
|
|
||||||
if num <= 0 then
|
|
||||||
return 0x01000C,nil
|
|
||||||
end
|
|
||||||
--验证数据的正确性,错误时返回
|
|
||||||
local success, result = checkJson(jsonData)
|
|
||||||
if success == false then
|
|
||||||
return 0x000001,result
|
|
||||||
end
|
|
||||||
--解析json中的键和数据值
|
|
||||||
local tmp = ""
|
|
||||||
for key, value in pairs(result) do
|
|
||||||
local val = (type(value) == "string") and "'"..value.."'" or value
|
|
||||||
tmp = string.format("%s=%s,", key, val)
|
|
||||||
end
|
|
||||||
local vals = tmp:sub(1, #tmp - 1)
|
|
||||||
--组装sql语句
|
|
||||||
local sql = string.format("update \"tbl_account\" set %s where id='%s'", vals, id)
|
|
||||||
return execSQL(sql)
|
return execSQL(sql)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -70,9 +70,11 @@ local function checkJson(jsonData)
|
||||||
end
|
end
|
||||||
|
|
||||||
--通过查询条件判断数据库中的数据记录
|
--通过查询条件判断数据库中的数据记录
|
||||||
local function checkUserExist(where)
|
--根据用户、手机号、邮箱进行验证用户是否存在
|
||||||
|
local function checkUserExist(username, phone, email)
|
||||||
--组装sql语句
|
--组装sql语句
|
||||||
local sql = string.format("select count(*) as count from \"tbl_user\" %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 \"tbl_users\" %s", where)
|
||||||
print("check sql: "..sql)
|
print("check sql: "..sql)
|
||||||
--获取数据库连接
|
--获取数据库连接
|
||||||
return execSQL(sql)
|
return execSQL(sql)
|
||||||
|
|
@ -81,14 +83,14 @@ end
|
||||||
-- 查询数据表中的所有用户信息
|
-- 查询数据表中的所有用户信息
|
||||||
function _M.getAllUser()
|
function _M.getAllUser()
|
||||||
--组装sql语句
|
--组装sql语句
|
||||||
local sql = "select * from \"tbl_user\""
|
local sql = "select * from \"tbl_users\""
|
||||||
return execSQL(sql)
|
return execSQL(sql)
|
||||||
end
|
end
|
||||||
|
|
||||||
--根据用户id获取用户信息
|
--根据用户id获取用户信息
|
||||||
function _M.getUser(id)
|
function _M.getUser(id)
|
||||||
--组装sql语句
|
--组装sql语句
|
||||||
local sql = "select * from \"tbl_user\" where id='"..id.."'"
|
local sql = "select * from \"tbl_users\" where id='"..id.."'"
|
||||||
return execSQL(sql)
|
return execSQL(sql)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -110,9 +112,8 @@ function _M.addUser(jsonData)
|
||||||
if key == "phone" then phone = value end
|
if key == "phone" then phone = value end
|
||||||
if key == "email" then email = value end
|
if key == "email" then email = value end
|
||||||
end
|
end
|
||||||
--根据用户、手机号、邮箱进行验证用户是否存在
|
--校验用户是否存在
|
||||||
local where = string.format("where username='%s' or phone='%s' or email='%s'", username, phone, email)
|
local ok, res = checkUserExist(username, phone, email)
|
||||||
local ok, res = checkUserExist(where)
|
|
||||||
if ok ~= 0 then
|
if ok ~= 0 then
|
||||||
return 0x000001,res
|
return 0x000001,res
|
||||||
end
|
end
|
||||||
|
|
@ -130,49 +131,14 @@ function _M.addUser(jsonData)
|
||||||
local newKeys = keys.."id"
|
local newKeys = keys.."id"
|
||||||
local newValues = values.."'"..getUuid().."'"
|
local newValues = values.."'"..getUuid().."'"
|
||||||
--组装sql语句
|
--组装sql语句
|
||||||
local sql = string.format("insert into \"tbl_user\"(%s)values(%s)", newKeys, newValues)
|
local sql = string.format("insert into \"tbl_users\"(%s)values(%s)", newKeys, newValues)
|
||||||
return execSQL(sql)
|
return execSQL(sql)
|
||||||
end
|
end
|
||||||
|
|
||||||
--增加用户信息到数据表
|
--增加用户信息到数据表
|
||||||
function _M.deleteUser(id)
|
function _M.delete_user(id)
|
||||||
--组装sql语句
|
--组装sql语句
|
||||||
local sql = "delete from \"tbl_user\" where id='"..id.."'"
|
local sql = "delete from \"tbl_users\" where id='"..id.."'"
|
||||||
return execSQL(sql)
|
|
||||||
end
|
|
||||||
|
|
||||||
--更新用户信息到数据表
|
|
||||||
function _M.updateUser(id, jsonData)
|
|
||||||
--根据用户id进行验证用户是否存在
|
|
||||||
local where = string.format("where id='%s'", id)
|
|
||||||
local ok, res = checkUserExist(where)
|
|
||||||
if ok ~= 0 then
|
|
||||||
return 0x000001,res
|
|
||||||
end
|
|
||||||
local num = 0
|
|
||||||
for _, row in ipairs(res) do
|
|
||||||
for key, value in pairs(row) do
|
|
||||||
num = value
|
|
||||||
end
|
|
||||||
end
|
|
||||||
print("exec result:", num)
|
|
||||||
if num <= 0 then
|
|
||||||
return 0x01000C,nil
|
|
||||||
end
|
|
||||||
--验证数据的正确性,错误时返回
|
|
||||||
local success, result = checkJson(jsonData)
|
|
||||||
if success == false then
|
|
||||||
return 0x000001,result
|
|
||||||
end
|
|
||||||
--解析json中的键和数据值
|
|
||||||
local tmp = ""
|
|
||||||
for key, value in pairs(result) do
|
|
||||||
local val = (type(value) == "string") and "'"..value.."'" or value
|
|
||||||
tmp = string.format("%s=%s,", key, val)
|
|
||||||
end
|
|
||||||
local vals = tmp:sub(1, #tmp - 1)
|
|
||||||
--组装sql语句
|
|
||||||
local sql = string.format("update \"tbl_user\" set %s where id='%s'", vals, id)
|
|
||||||
return execSQL(sql)
|
return execSQL(sql)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,32 +0,0 @@
|
||||||
---
|
|
||||||
--- Generated by EmmyLua(https://github.com/EmmyLua)
|
|
||||||
--- Created by admin.
|
|
||||||
--- DateTime: 2025/10/24 11:01
|
|
||||||
--- 提供公共需要的验证接口等功能
|
|
||||||
|
|
||||||
local cjson = require('cjson')
|
|
||||||
|
|
||||||
local _M = {}
|
|
||||||
|
|
||||||
--验证请求头是否正确
|
|
||||||
function _M:checkReqHeader()
|
|
||||||
local headers = ngx.req.get_headers()
|
|
||||||
if headers["content-type"] ~= "application/json" then
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
--校验json数据的正确性,并返回json解析后的数据
|
|
||||||
function _M:checkJson(jsonData)
|
|
||||||
local success, result = pcall(function()
|
|
||||||
return cjson.decode(jsonData)
|
|
||||||
end)
|
|
||||||
if success == true then
|
|
||||||
return true, result
|
|
||||||
end
|
|
||||||
local res = nil
|
|
||||||
return false,res
|
|
||||||
end
|
|
||||||
|
|
||||||
return _M
|
|
||||||
Loading…
Reference in New Issue
Block a user