904118851 4 months ago
parent
commit
08f2d3c5d2
2 changed files with 115 additions and 1 deletions
  1. 2 1
      service/backmgr/init.lua
  2. 113 0
      service/backmgr/review_user.lua

+ 2 - 1
service/backmgr/init.lua

@@ -51,7 +51,7 @@ local material_platform = require "material_platform"
 local xs_origin_data = require "xs_origin_data"
 local statistics_platform = require "statistics_platform"
 local data_manager = require "data_manager"
-
+local review_user = require "review_user"
 local status_200 = 200
 local CMD = {
     
@@ -101,6 +101,7 @@ CMD["material_platform"] = material_platform;
 CMD["xs_origin_data"] = xs_origin_data;
 CMD["statistics_platform"] = statistics_platform;
 CMD["data_manager"] = data_manager;
+CMD["review_user"] = review_user;
 function run(target,fun,msg_body,fd)
     if target~=nil and fun~=nil and target[fun]~=nil then
         local isok,data,total = target[fun](msg_body)

+ 113 - 0
service/backmgr/review_user.lua

@@ -0,0 +1,113 @@
+--审核员用户
+local M = {}
+local mysqldbx = require "mysqldbx"
+local tools = require "tools"
+local skynet = require "skynet"
+local mysql = require "skynet.db.mysql"
+local config = require "run_config"
+local mysqldtaskbx = {}
+local db
+function M.Register(msg_body)
+    local isok ,key =  tools.checkData({"name","account","password","Disable","permissions"},msg_body)
+    if not isok then
+        return false,string.format("缺少字段: %s.", key)
+    end
+    local sql = string.format("SELECT * FROM review_user WHERE account = '%s' and password = '%s' ", msg_body.account, msg_body.password)
+    local isok,res;
+    res = mysqldtaskbx.Singleton().query(sql)
+    if #res > 0 then
+        return false ,"用户已存在"
+    end
+    sql = string.format("insert into review_user ( name, account,  password, Disable,permissions) values ('%s','%s','%s',%d,%d)",msg_body.name,msg_body.account,msg_body.password,msg_body.Disable,msg_body.permissions)
+    res = mysqldtaskbx.Singleton().query(sql)
+    tools.dump(res)
+    return true, {}
+end
+
+function M.Modify(msg_body)
+    local isok ,key =  tools.checkData({"id","name","password","Disable","permissions"},msg_body)
+    if not isok then
+        return false,string.format("缺少字段: %s.", key)
+    end
+
+    local sql = string.format("SELECT * FROM review_user WHERE id = %d ", msg_body.id)
+    local isok,res;
+    res = mysqldtaskbx.Singleton().query(sql)
+    if #res < 0 then
+        return false ,"用户不存在"
+    end
+
+    local sql = string.format("UPDATE review_user set name = '%s' , password = '%s' , Disable = %d , permissions = %d WHERE id = %d ", msg_body.name,msg_body.password,msg_body.Disable,msg_body.permissions,msg_body.id)
+    local isok,res;
+    res = mysqldtaskbx.Singleton().query(sql)
+    return true, {}
+end
+
+function M.Login(msg_body)
+    local isok ,key =  tools.checkData({"account","password"},msg_body)
+    if not isok then
+        return false,string.format("缺少字段: %s.", key)
+    end
+    local sql = string.format("SELECT * FROM review_user WHERE account = '%s' and password = '%s' ", msg_body.account, msg_body.password)
+    local isok,res;
+    res = mysqldtaskbx.Singleton().query(sql)
+    if #res <= 0 then
+        return false ,"账号或密码错误!"
+    end
+    return true, {}
+end
+
+
+function M.Search(msg_body)
+    local isok ,key =  tools.checkData({"page_size","page_number"},msg_body)
+    if not isok then
+        return false,string.format("缺少字段: %s.", key)
+    end
+    local page_size = msg_body.page_size
+    local page_number = msg_body.page_number
+    local offset = (page_number - 1) * page_size
+    
+    local sql = "SELECT * FROM review_user WHERE 1=1 "..string.format(" LIMIT %d OFFSET %d ",page_size, offset)
+    local list = mysqldtaskbx.Singleton().query(sql)
+    sql = "SELECT   COUNT(*) AS total  FROM review_user "
+    local total = mysqldtaskbx.Singleton().query(sql)
+    return true,list,total[1].total
+end
+
+
+function mysqldtaskbx.start()
+    local function on_connect(db)
+        db:query("set charset utf8mb4");
+    end
+    local conf = {
+        ip = 'n8-mr-dsq824ev2pqxbr6rhw.rwlb.rds.aliyuncs.com',
+        port = 3306,
+        user = "zdroot",
+        password = "p0LTZh&CjMl2023",
+        db = "ml_oceanengine"
+    }
+    db = mysql.connect{
+        host=conf.ip,
+        port=conf.port,
+        database=conf.db,
+        user=conf.user,
+        password=conf.password,
+        charset="utf8mb4",
+        max_packet_size = 1024 * 1024,
+        on_connect = on_connect
+    }
+    if not db then
+       skynet.error("mysql connect fail")
+    end
+end
+
+function mysqldtaskbx.Singleton()
+    if db == nil then
+        mysqldtaskbx.start()
+    end
+    return mysqldtaskbx
+end
+function mysqldtaskbx.query(sql)
+    return db:query(sql)
+end
+return M