123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192 |
- --小程序
- 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"},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)
- tools.dump(obj)
- end
- local id = #obj+1
- table.insert(obj,id,{id=id,name=msg_body.name})
- 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","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
- 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"},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)
- tools.dump(obj)
- end
- local id = #obj+1
- table.insert(obj,id,{id=id,name=msg_body.name})
- 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"},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
- 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"},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})
- 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"},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
- 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.getTotal()
- local sql = "SELECT COUNT(*) AS total FROM tg_platform"
- local res = mysqldbx.query(sql)
- return true,res[1]
- end
- return M
|