--小程序 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({"tg_platform_name"},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` (tg_platform_id,tg_platform_name) VALUES (%d,'%s')",id,msg_body.tg_platform_name) 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({"tg_platform_name","id"},msg_body) if not isok then return false,string.format("缺少字段: %s.", key) end local sql = string.format("UPDATE `tg_platform` SET tg_platform_name = '%s' WHERE id = %d ", 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].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 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].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 f_chongzhi = '%s' WHERE id = %d ", cjson.encode(obj),msg_body.id) mysqldbx.query(sql) return true,obj 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