2025-09-27 15:19:58 +08:00
|
|
|
---
|
|
|
|
|
--- Generated by EmmyLua(https://github.com/EmmyLua)
|
|
|
|
|
--- Created by admin.
|
|
|
|
|
--- DateTime: 2025/9/25 08:19
|
|
|
|
|
---
|
|
|
|
|
|
2025-10-15 17:05:35 +08:00
|
|
|
local _M = {}
|
2025-09-27 15:19:58 +08:00
|
|
|
|
2025-10-16 16:47:24 +08:00
|
|
|
local dao = require("service.system.user")
|
2025-10-16 21:02:10 +08:00
|
|
|
local resp = require("util.response")
|
2025-10-24 11:11:57 +08:00
|
|
|
local validator = require("util.validator")
|
2025-10-20 16:52:40 +08:00
|
|
|
|
2025-10-15 17:05:35 +08:00
|
|
|
--获取所有用户信息
|
2025-10-23 20:25:17 +08:00
|
|
|
function _M.get_alluser()
|
2025-10-24 15:15:45 +08:00
|
|
|
--获取页码和请求的数据量
|
|
|
|
|
local page = 0
|
|
|
|
|
local pagesize = 0
|
|
|
|
|
local payloads = ngx.req.get_uri_args()
|
|
|
|
|
for k,v in pairs(payloads) do
|
|
|
|
|
if k == "page" then page = v end
|
|
|
|
|
if k == "pagesize" then pagesize = v end
|
|
|
|
|
end
|
|
|
|
|
--ngx.say("page:", page, " pagesize:", pagesize)
|
2025-10-20 16:52:40 +08:00
|
|
|
local code,ret = dao.getAllUser()
|
|
|
|
|
local result = resp:json(code, ret)
|
2025-10-16 21:32:04 +08:00
|
|
|
resp:send(result)
|
2025-10-15 17:05:35 +08:00
|
|
|
end
|
|
|
|
|
|
2025-10-16 16:47:24 +08:00
|
|
|
--根据用户id获取用户信息
|
|
|
|
|
function _M.get_user(m)
|
|
|
|
|
local id = m.id
|
2025-10-20 16:52:40 +08:00
|
|
|
local code,ret = dao.getUser(id)
|
|
|
|
|
local result = resp:json(code, ret)
|
|
|
|
|
resp:send(result)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--根据用户id获取用户信息
|
|
|
|
|
function _M.add_user()
|
|
|
|
|
--获取请求头并进行校验
|
2025-10-24 11:11:57 +08:00
|
|
|
if validator.checkReqHeader() == false then
|
|
|
|
|
local result = resp:json(0x000001)
|
|
|
|
|
resp:send(result)
|
2025-10-20 16:52:40 +08:00
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
--读取请求体的数据
|
|
|
|
|
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
|
|
|
|
|
--ngx.say(body_data)
|
|
|
|
|
local code, ret = dao.addUser(body_data)
|
|
|
|
|
local result = resp:json(code, ret)
|
|
|
|
|
resp:send(result)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--根据用户id删除用户信息
|
|
|
|
|
function _M.delete_user(m)
|
|
|
|
|
local id = m.id
|
2025-10-25 16:27:52 +08:00
|
|
|
local code, ret = dao.deleteUser(id)
|
2025-10-20 16:52:40 +08:00
|
|
|
local result = resp:json(code, ret)
|
|
|
|
|
resp:send(result)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--根据用户id删除用户信息
|
|
|
|
|
function _M.update_user(m)
|
|
|
|
|
local id = m.id
|
2025-10-23 17:46:02 +08:00
|
|
|
--读取请求体的数据
|
|
|
|
|
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
|
2025-10-25 16:27:52 +08:00
|
|
|
local code, ret = dao.updateUser(id, body_data)
|
2025-10-20 16:52:40 +08:00
|
|
|
local result = resp:json(code, ret)
|
2025-10-16 21:32:04 +08:00
|
|
|
resp:send(result)
|
2025-10-15 17:22:04 +08:00
|
|
|
end
|
|
|
|
|
|
2025-10-15 17:05:35 +08:00
|
|
|
return _M
|