主要修改开发模块
This commit is contained in:
102
target/fwutils/develop/function/template.lua
Normal file
102
target/fwutils/develop/function/template.lua
Normal file
@@ -0,0 +1,102 @@
|
||||
require("fwutils.webapi")
|
||||
-- CREATE TABLE `fw_template` (
|
||||
-- `id` int NOT NULL AUTO_INCREMENT,
|
||||
-- `role_id` int DEFAULT NULL,
|
||||
-- `key` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
|
||||
-- `value` varchar(2048) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
|
||||
-- `enable` tinyint NOT NULL COMMENT '是否启用',
|
||||
-- PRIMARY KEY (`id`),
|
||||
-- UNIQUE KEY `role_id` (`role_id`,`key`)
|
||||
-- ) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Fastweb-关键词模板';
|
||||
local M = {}
|
||||
|
||||
function M.get_by_id(id,conn)
|
||||
local select = conn:select()
|
||||
select:table("fw_template LEFT JOIN fw_role ON fw_template.role_id = fw_role.id")
|
||||
select:field({
|
||||
"fw_template.id",
|
||||
"fw_template.role_id",
|
||||
"fw_template.`key`",
|
||||
"fw_template.value",
|
||||
"fw_template.enable",
|
||||
"fw_role.title as role_title",
|
||||
})
|
||||
select:where_i32("fw_template.id","=",id)
|
||||
|
||||
select:limit(0,1)
|
||||
local result = select:query()
|
||||
if result:row_count() == 0 then
|
||||
return nil
|
||||
end
|
||||
local d = result:table()[1]
|
||||
return d
|
||||
end
|
||||
function M.add(data,conn)
|
||||
local insert = conn:insert()
|
||||
insert:table("fw_template")
|
||||
|
||||
if data.role_id ~= nil and data.role_id ~= cjson.null then
|
||||
insert:set_i32("role_id",data.role_id)
|
||||
end
|
||||
if data.key ~= nil then
|
||||
insert:set_str("`key`",data.key)
|
||||
end
|
||||
if data.value ~= nil then
|
||||
insert:set_str("value",data.value)
|
||||
end
|
||||
if data.enable ~= nil then
|
||||
insert:set_i32("enable",data.enable)
|
||||
end
|
||||
local d = insert:exec()
|
||||
return d == 1
|
||||
end
|
||||
function M.update(data,conn)
|
||||
local update = conn:update()
|
||||
update:table("fw_template")
|
||||
|
||||
if data.role_id ~= nil then
|
||||
update:set_i32("role_id",data.role_id)
|
||||
end
|
||||
if data.key ~= nil then
|
||||
update:set_str("`key`",data.key)
|
||||
end
|
||||
if data.value ~= nil then
|
||||
update:set_str("value",data.value)
|
||||
end
|
||||
if data.enable ~= nil then
|
||||
update:set_i32("enable",data.enable)
|
||||
end
|
||||
update:where_i32("id","=",data.id)
|
||||
local d = update:exec()
|
||||
return d == 1
|
||||
end
|
||||
function M.delete(id,conn)
|
||||
local del = conn:delete()
|
||||
del:table("fw_template")
|
||||
del:where_i32("id","=",id)
|
||||
local d = del:exec()
|
||||
return d == 1
|
||||
end
|
||||
function M.list(search,limit,conn)
|
||||
|
||||
return query_model_ex(conn,[=[
|
||||
fw_template LEFT JOIN fw_role ON fw_template.role_id = fw_role.id
|
||||
]=],{
|
||||
"fw_template.id",
|
||||
"fw_template.role_id",
|
||||
"fw_template.`key`",
|
||||
"fw_template.value",
|
||||
"fw_template.enable",
|
||||
"fw_role.title as role_title",
|
||||
"fw_role.id as role_id",
|
||||
},limit.start,limit.length,function(sel)
|
||||
|
||||
if search.role_id ~= nil and search.role_id ~= -1 then
|
||||
sel:where_i32("fw_template.role_id","=",search.role_id)
|
||||
end
|
||||
end,function(sel_data)
|
||||
sel_data:orderby("fw_template.enable DESC")
|
||||
end)
|
||||
end
|
||||
|
||||
return M
|
||||
Reference in New Issue
Block a user