--书籍平台 local M = {} local skynet = require "skynet" local mysqldbx = require "mysqldbx" local tools = require "tools" local cjson = require "cjson" --获取所有平台 function M.getPlatformList() local sql = string.format("select * from `tg_platform` ") local isok,res; res = mysqldbx.query(sql) if #res <= 0 then return true , {} end return true, res end --添加平台 function M.addPlatform(msg_body) local isok ,key ,id= tools.checkData({"filter_guajian_logic_list","platform_shared_id","mini_program_platform_id","tg_platform_name","filter_guajian_logic"},msg_body) if not isok then return false,string.format("缺少字段: %s.", key) end local _,data = M.getTotal() local id = data.total + 1 local sql = string.format("INSERT INTO `tg_platform` (filter_guajian_logic_list,platform_shared_id,mini_program_platform_id,tg_platform_id,tg_platform_name,filter_guajian_logic) VALUES ('%s',%d,%d,%d,'%s','%s')", cjson.encode(msg_body.filter_guajian_logic_list),msg_body.platform_shared_id,msg_body.mini_program_platform_id,id,msg_body.tg_platform_name,msg_body.filter_guajian_logic) skynet.error(sql) mysqldbx.query(sql) skynet.send("backmgr","lua","on_recv",nil,"ws_push_msg",cjson.encode({cmd="updatePlatformConfig"})) return true end --修改平台 function M.modifyPlatform(msg_body) local isok ,key = tools.checkData({"filter_guajian_logic_list","platform_shared_id","mini_program_platform_id","tg_platform_name","id","filter_guajian_logic"},msg_body) if not isok then return false,string.format("缺少字段: %s.", key) end local sql = string.format("UPDATE `tg_platform` SET filter_guajian_logic_list = '%s' , platform_shared_id = %d , mini_program_platform_id = %d , filter_guajian_logic = '%s' , tg_platform_name = '%s' WHERE id = %d ", cjson.encode(msg_body.filter_guajian_logic_list), msg_body.platform_shared_id, msg_body.mini_program_platform_id, msg_body.filter_guajian_logic, msg_body.tg_platform_name,msg_body.id) mysqldbx.query(sql) skynet.send("backmgr","lua","on_recv",nil,"ws_push_msg",cjson.encode({cmd="updatePlatformConfig"})) return true end --添加回传规则 function M.addHuiChuanRule(msg_body) local isok ,key = tools.checkData({"name","id","value"},msg_body) if not isok then return false,string.format("缺少字段: %s.", key) end local sql = string.format("select huichuan from `tg_platform` WHERE id = %d ",msg_body.id) local res = mysqldbx.query(sql) local obj = {} if res[1].huichuan~=nil then obj = cjson.decode(res[1].huichuan) end local id = #obj+1 table.insert(obj,id,{id=id,name=msg_body.name,value=msg_body.value}) sql = string.format("UPDATE `tg_platform` SET huichuan = '%s' WHERE id = %d ", cjson.encode(obj),msg_body.id) mysqldbx.query(sql) skynet.send("backmgr","lua","on_recv",nil,"ws_push_msg",cjson.encode({cmd="updatePlatformConfig"})) return true, obj end --修改回传规则 function M.modifyHuiChuanRule(msg_body) local isok ,key = tools.checkData({"name","id","value","table_id"},msg_body) if not isok then return false,string.format("缺少字段: %s.", key) end local sql = string.format("select huichuan from `tg_platform` WHERE id = %d ",msg_body.id) local res = mysqldbx.query(sql) local obj = {} if res[1].huichuan~=nil then obj = cjson.decode(res[1].huichuan) end for i = 1, #obj, 1 do if obj[i].id == msg_body.table_id then obj[i].name = msg_body.name obj[i].value = msg_body.value break end end sql = string.format("UPDATE `tg_platform` SET huichuan = '%s' WHERE id = %d ", cjson.encode(obj),msg_body.id) mysqldbx.query(sql) skynet.send("backmgr","lua","on_recv",nil,"ws_push_msg",cjson.encode({cmd="updatePlatformConfig"})) return true,obj end --添加收费卡点 function M.addShouFeiKaDian(msg_body) local isok ,key = tools.checkData({"name","id","value"},msg_body) if not isok then return false,string.format("缺少字段: %s.", key) end local sql = string.format("select kadian from `tg_platform` WHERE id = %d ",msg_body.id) local res = mysqldbx.query(sql) local obj = {} if res[1].kadian~=nil then obj = cjson.decode(res[1].kadian) end local id = #obj+1 table.insert(obj,id,{id=id,name=msg_body.name,value=msg_body.value}) sql = string.format("UPDATE `tg_platform` SET kadian = '%s' WHERE id = %d ", cjson.encode(obj),msg_body.id) mysqldbx.query(sql) return true, obj end --修改收费卡点 function M.modifyShouFeiKaDian(msg_body) local isok ,key = tools.checkData({"name","id","table_id","value"},msg_body) if not isok then return false,string.format("缺少字段: %s.", key) end local sql = string.format("select kadian from `tg_platform` WHERE id = %d ",msg_body.id) local res = mysqldbx.query(sql) local obj = {} if res[1].kadian~=nil then obj = cjson.decode(res[1].kadian) end for i = 1, #obj, 1 do if obj[i].id == msg_body.table_id then obj[i].name = msg_body.name obj[i].value = msg_body.value break end end sql = string.format("UPDATE `tg_platform` SET kadian = '%s' WHERE id = %d ", cjson.encode(obj),msg_body.id) mysqldbx.query(sql) return true,obj end --添加充值模板 function M.addChongZhiTemplate(msg_body) local isok ,key = tools.checkData({"name","id","value"},msg_body) if not isok then return false,string.format("缺少字段: %s.", key) end local sql = string.format("select chongzhi from `tg_platform` WHERE id = %d ",msg_body.id) local res = mysqldbx.query(sql) local obj = {} if res[1].chongzhi~=nil then obj = cjson.decode(res[1].chongzhi) end local id = #obj+1 table.insert(obj,id,{id=id,name=msg_body.name,value=msg_body.value}) sql = string.format("UPDATE `tg_platform` SET chongzhi = '%s' WHERE id = %d ", cjson.encode(obj),msg_body.id) mysqldbx.query(sql) return true, obj end --修改充值模板 function M.modifyChongZhiTemplate(msg_body) local isok ,key = tools.checkData({"name","id","table_id","value"},msg_body) if not isok then return false,string.format("缺少字段: %s.", key) end local sql = string.format("select chongzhi from `tg_platform` WHERE id = %d ",msg_body.id) local res = mysqldbx.query(sql) local obj = {} if res[1].chongzhi ~=nil then obj = cjson.decode(res[1].chongzhi) end for i = 1, #obj, 1 do if obj[i].id == msg_body.table_id then obj[i].name = msg_body.name obj[i].value = msg_body.value break end end sql = string.format("UPDATE `tg_platform` SET chongzhi = '%s' WHERE id = %d ", cjson.encode(obj),msg_body.id) mysqldbx.query(sql) return true,obj end --添加复充值模板 function M.addFChongZhiTemplate(msg_body) local isok ,key = tools.checkData({"name","id","value"},msg_body) if not isok then return false,string.format("缺少字段: %s.", key) end local sql = string.format("select f_chongzhi from `tg_platform` WHERE id = %d ",msg_body.id) local res = mysqldbx.query(sql) local obj = {} if res[1].f_chongzhi~=nil then obj = cjson.decode(res[1].f_chongzhi) end local id = #obj+1 table.insert(obj,id,{id=id,name=msg_body.name,value=msg_body.value}) sql = string.format("UPDATE `tg_platform` SET f_chongzhi = '%s' WHERE id = %d ", cjson.encode(obj),msg_body.id) mysqldbx.query(sql) return true, obj end --修改复充值模板 function M.modifyFChongZhiTemplate(msg_body) local isok ,key = tools.checkData({"name","id","table_id","value"},msg_body) if not isok then return false,string.format("缺少字段: %s.", key) end local sql = string.format("select f_chongzhi from `tg_platform` WHERE id = %d ",msg_body.id) local res = mysqldbx.query(sql) local obj = {} if res[1].f_chongzhi ~=nil then obj = cjson.decode(res[1].f_chongzhi) end for i = 1, #obj, 1 do if obj[i].id == msg_body.table_id then obj[i].name = msg_body.name obj[i].value = msg_body.value break end end sql = string.format("UPDATE `tg_platform` SET f_chongzhi = '%s' WHERE id = %d ", cjson.encode(obj),msg_body.id) mysqldbx.query(sql) return true,obj end --添加推广小程序平台 function M.addMiniProgramPlatform(msg_body) local isok ,key = tools.checkData({"name","id","value"},msg_body) if not isok then return false,string.format("缺少字段: %s.", key) end local sql = string.format("select m_p_platform from `tg_platform` WHERE id = %d ",msg_body.id) local res = mysqldbx.query(sql) local obj = {} if res[1].m_p_platform~=nil then obj = cjson.decode(res[1].m_p_platform) end local id = #obj+1 table.insert(obj,id,{id=id,name=msg_body.name,value=msg_body.value}) sql = string.format("UPDATE `tg_platform` SET m_p_platform = '%s' WHERE id = %d ", cjson.encode(obj),msg_body.id) mysqldbx.query(sql) return true, obj end --修改推广小程序平台 function M.modifyMiniProgramPlatform(msg_body) local isok ,key = tools.checkData({"name","id","table_id","value"},msg_body) if not isok then return false,string.format("缺少字段: %s.", key) end local sql = string.format("select m_p_platform from `tg_platform` WHERE id = %d ",msg_body.id) local res = mysqldbx.query(sql) local obj = {} if res[1].m_p_platform~=nil then obj = cjson.decode(res[1].m_p_platform) end for i = 1, #obj, 1 do if obj[i].id == msg_body.table_id then obj[i].name = msg_body.name obj[i].value = msg_body.value break end end sql = string.format("UPDATE `tg_platform` SET m_p_platform = '%s' WHERE id = %d ", cjson.encode(obj),msg_body.id) mysqldbx.query(sql) return true,obj end function M.set_filter_guajian_logic(msg_body) local isok ,key = tools.checkData({"id","filter_guajian_logic"},msg_body) if not isok then return false,string.format("缺少字段: %s.", key) end local sql = string.format("UPDATE `tg_platform` SET filter_guajian_logic = '%s' WHERE id = %d ",msg_body.filter_guajian_logic,msg_body.id) mysqldbx.query(sql) return true,{} end function M.getTotal() local sql = "SELECT COUNT(*) AS total FROM tg_platform" local res = mysqldbx.query(sql) return true,res[1] end return M