From 6f60a6a49b2adf760ce4bae78228ce91a869f6d4 Mon Sep 17 00:00:00 2001 From: wanglei <34475144@qqcom> Date: Thu, 23 Oct 2025 17:46:02 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=94=A8=E6=88=B7=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E6=95=B0=E6=8D=AE=E5=92=8C=E6=95=B0=E6=8D=AE=E8=A1=A8?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=E7=9A=84=E5=86=85=E5=AE=B9=EF=BC=8C=E5=AF=B9?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E8=BF=9B=E8=A1=8C=E6=98=AF=E5=90=A6=E5=AD=98?= =?UTF-8?q?=E5=9C=A8=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/api.lua | 4 ++-- src/api/system/user.lua | 12 +++++++++- src/config/status.lua | 1 + src/service/system/user.lua | 44 ++++++++++++++++++++++++++++++++----- 4 files changed, 53 insertions(+), 8 deletions(-) diff --git a/src/api/api.lua b/src/api/api.lua index 27c98dc..e619b1b 100644 --- a/src/api/api.lua +++ b/src/api/api.lua @@ -42,8 +42,8 @@ local routes = { }, --账户相关路由接口 { - paths = { "/api/get-account" }, - metadata = { "metadata get-account" }, + paths = { "/api/get-accounts" }, + metadata = { "metadata get-accounts" }, methods = { "GET" }, handler = accountApi.get_allaccounts, }, diff --git a/src/api/system/user.lua b/src/api/system/user.lua index a22b39e..a17fcf0 100644 --- a/src/api/system/user.lua +++ b/src/api/system/user.lua @@ -68,7 +68,17 @@ end --根据用户id删除用户信息 function _M.update_user(m) 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) resp:send(result) end diff --git a/src/config/status.lua b/src/config/status.lua index 7c0e89d..ebc1ca4 100644 --- a/src/config/status.lua +++ b/src/config/status.lua @@ -38,4 +38,5 @@ return { [0x010009] = '重置密码失败,用户不存在', [0x01000A] = '获取用户信息失败,用户未登录', [0x01000B] = '获取用户信息失败,用户不存在', + [0x01000C] = '修改用户信息失败,用户不存在', } diff --git a/src/service/system/user.lua b/src/service/system/user.lua index efa0445..a40d2af 100644 --- a/src/service/system/user.lua +++ b/src/service/system/user.lua @@ -70,10 +70,8 @@ local function checkJson(jsonData) end --通过查询条件判断数据库中的数据记录 ---根据用户、手机号、邮箱进行验证用户是否存在 -local function checkUserExist(username, phone, email) +local function checkUserExist(where) --组装sql语句 - 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) --获取数据库连接 @@ -112,8 +110,9 @@ function _M.addUser(jsonData) if key == "phone" then phone = value end if key == "email" then email = value end end - --校验用户是否存在 - local ok, res = checkUserExist(username, phone, email) + --根据用户、手机号、邮箱进行验证用户是否存在 + local where = string.format("where username='%s' or phone='%s' or email='%s'", username, phone, email) + local ok, res = checkUserExist(where) if ok ~= 0 then return 0x000001,res end @@ -142,4 +141,39 @@ function _M.delete_user(id) return execSQL(sql) end +--更新用户信息到数据表 +function _M.update_user(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_users\" set %s where id='%s'", vals, id) + return execSQL(sql) +end + return _M