123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- --审核员用户
- 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({"account","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 account = '%s', name = '%s' , password = '%s' , Disable = %d , permissions = %d WHERE id = %d ", msg_body.account, 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, res
- 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
|