2025-10-29 17:29:17 +08:00
|
|
|
|
---
|
|
|
|
|
|
--- Generated by EmmyLua(https://github.com/EmmyLua)
|
|
|
|
|
|
--- Created by admin.
|
|
|
|
|
|
--- DateTime: 2025/10/25 16:36
|
|
|
|
|
|
--- 数据表模型文件
|
|
|
|
|
|
|
|
|
|
|
|
local helpers = require("share.helpers")
|
|
|
|
|
|
--引用使用的库文件
|
|
|
|
|
|
local model = require("share.model")
|
|
|
|
|
|
--创建一个数据表相关的模型
|
|
|
|
|
|
local userModel = model:new('sys_user')
|
|
|
|
|
|
|
|
|
|
|
|
local _M = {}
|
|
|
|
|
|
|
|
|
|
|
|
--判断用户是否存在
|
|
|
|
|
|
local function isExistUser(id)
|
|
|
|
|
|
--根据用户id进行验证用户是否存在
|
|
|
|
|
|
local code, res = userModel:find(id)
|
|
|
|
|
|
if code ~= 0 then
|
|
|
|
|
|
return false
|
|
|
|
|
|
end
|
|
|
|
|
|
local num = 0
|
|
|
|
|
|
if res ~= nil then
|
|
|
|
|
|
num = table.getn(res)
|
|
|
|
|
|
end
|
|
|
|
|
|
--用户不存在返回错误
|
|
|
|
|
|
if num <= 0 then
|
|
|
|
|
|
return false
|
|
|
|
|
|
end
|
|
|
|
|
|
return true
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
-- 查询数据表中的所有用户信息
|
2025-10-29 23:00:17 +08:00
|
|
|
|
function _M.getSystemUsers(pageNum, pageSize)
|
2025-10-29 17:29:17 +08:00
|
|
|
|
return userModel:paginate(pageNum, pageSize)
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
--根据用户id获取用户信息
|
2025-10-29 23:00:17 +08:00
|
|
|
|
function _M.getSystemUser(id)
|
2025-10-29 17:29:17 +08:00
|
|
|
|
return userModel:find(id)
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
--增加用户信息到数据表
|
2025-10-29 23:00:17 +08:00
|
|
|
|
function _M.addSystemUser(jsonData)
|
2025-10-31 21:32:39 +08:00
|
|
|
|
if jsonData == nil or jsonData == "" then
|
|
|
|
|
|
return 0x000001, nil
|
|
|
|
|
|
end
|
2025-10-29 17:29:17 +08:00
|
|
|
|
--解析json中的键和数据值
|
|
|
|
|
|
local userName = jsonData['username']
|
|
|
|
|
|
local phone = jsonData['phone']
|
|
|
|
|
|
local email = jsonData['email']
|
|
|
|
|
|
|
|
|
|
|
|
--根据用户、手机号、邮箱进行验证用户是否存在
|
2025-10-31 21:32:39 +08:00
|
|
|
|
local code, res = userModel:where("username", "=", userName):orwhere("phone", "=", phone):orwhere("email", "=", email):get()
|
2025-10-29 17:29:17 +08:00
|
|
|
|
if code ~= 0 then
|
|
|
|
|
|
return 0x000001,res
|
|
|
|
|
|
end
|
|
|
|
|
|
local num = 0
|
|
|
|
|
|
if res ~= nil then
|
|
|
|
|
|
num = table.getn(res)
|
|
|
|
|
|
end
|
|
|
|
|
|
--用户存在时返回用户已经存在
|
|
|
|
|
|
if num > 0 then
|
|
|
|
|
|
return 0x01000C,nil
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
--键值为id产生uuid数据值,增加到json中
|
|
|
|
|
|
jsonData.id = helpers.getUuid()
|
|
|
|
|
|
-- 创建一个用户
|
2025-10-31 21:32:39 +08:00
|
|
|
|
return userModel:create(jsonData)
|
2025-10-29 17:29:17 +08:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
--删除用户信息到数据表
|
2025-10-29 23:00:17 +08:00
|
|
|
|
function _M:deleteSystemUser(id)
|
2025-10-29 17:29:17 +08:00
|
|
|
|
--根据用户id进行验证用户是否存在
|
|
|
|
|
|
local ok = isExistUser(id)
|
|
|
|
|
|
--用户不存在则返回
|
|
|
|
|
|
if ok == false then
|
|
|
|
|
|
return 0x000001,nil
|
|
|
|
|
|
end
|
|
|
|
|
|
return userModel:delete(id)
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
--更新用户信息到数据表
|
2025-10-29 23:00:17 +08:00
|
|
|
|
function _M:updateSystemUser(id, jsonData)
|
2025-10-29 17:29:17 +08:00
|
|
|
|
--根据用户id进行验证用户是否存在
|
|
|
|
|
|
local ok = isExistUser(id)
|
|
|
|
|
|
--用户不存在则返回
|
|
|
|
|
|
if ok == false then
|
|
|
|
|
|
return 0x000001,nil
|
|
|
|
|
|
end
|
|
|
|
|
|
--对数据内容进行更新
|
|
|
|
|
|
return userModel:where('id', '=', id):update(jsonData)
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
return _M
|