123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356 |
- --书籍平台
- 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({"material_platform_id","pay_type","parent_platform_id","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
- tools.dump(data)
- local sql = string.format("INSERT INTO `tg_platform` (material_platform_id,pay_type,parent_platform_id,filter_guajian_logic_list,platform_shared_id,mini_program_platform_id,tg_platform_id,tg_platform_name,filter_guajian_logic) VALUES (%d,%d,%d,'%s',%d,%d,%d,'%s','%s')",
- msg_body.material_platform_id,
- msg_body.pay_type,
- msg_body.parent_platform_id,
- 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.set_huichuan(msg_body)
- local isok ,key = tools.checkData({"huichuan","id"},msg_body)
- if not isok then
- return false,string.format("缺少字段: %s.", key)
- end
- local sql = string.format("UPDATE `tg_platform` SET huichuan = '%s' WHERE id = %d ",
- cjson.encode(msg_body.huichuan),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.set_chongzhi(msg_body)
- local isok ,key = tools.checkData({"chongzhi","id"},msg_body)
- if not isok then
- return false,string.format("缺少字段: %s.", key)
- end
- local sql = string.format("UPDATE `tg_platform` SET chongzhi = '%s' WHERE id = %d ",
- cjson.encode(msg_body.chongzhi),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.set_kadian(msg_body)
- local isok ,key = tools.checkData({"kadian","id"},msg_body)
- if not isok then
- return false,string.format("缺少字段: %s.", key)
- end
- local sql = string.format("UPDATE `tg_platform` SET kadian = '%s' WHERE id = %d ",
- cjson.encode(msg_body.kadian),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.set_f_chongzhi(msg_body)
- local isok ,key = tools.checkData({"f_chongzhi","id"},msg_body)
- if not isok then
- return false,string.format("缺少字段: %s.", key)
- end
- local sql = string.format("UPDATE `tg_platform` SET f_chongzhi = '%s' WHERE id = %d ",
- cjson.encode(msg_body.f_chongzhi),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.modifyPlatform(msg_body)
- local isok ,key = tools.checkData({"material_platform_id","pay_type","parent_platform_id","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 material_platform_id = %d , pay_type = %d , parent_platform_id = %d , 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 ",
- msg_body.material_platform_id,
- msg_body.pay_type,
- msg_body.parent_platform_id,
- 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
|