tg_platform.lua 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. --书籍平台
  2. local M = {}
  3. local skynet = require "skynet"
  4. local mysqldbx = require "mysqldbx"
  5. local tools = require "tools"
  6. local cjson = require "cjson"
  7. --获取所有平台
  8. function M.getPlatformList()
  9. local sql = string.format("select * from `tg_platform` ")
  10. local isok,res;
  11. res = mysqldbx.query(sql)
  12. if #res <= 0 then
  13. return true , {}
  14. end
  15. return true, res
  16. end
  17. --添加平台
  18. function M.addPlatform(msg_body)
  19. local isok ,key ,id= tools.checkData({"tg_platform_name","filter_guajian_logic"},msg_body)
  20. if not isok then
  21. return false,string.format("缺少字段: %s.", key)
  22. end
  23. local _,data = M.getTotal()
  24. local id = data.total + 1
  25. local sql = string.format("INSERT INTO `tg_platform` (tg_platform_id,tg_platform_name,filter_guajian_logic) VALUES (%d,'%s','%s')",id,msg_body.tg_platform_name,msg_body.filter_guajian_logic)
  26. skynet.error(sql)
  27. mysqldbx.query(sql)
  28. skynet.send("backmgr","lua","on_recv",nil,"ws_push_msg",cjson.encode({cmd="updatePlatformConfig"}))
  29. return true
  30. end
  31. --修改平台
  32. function M.modifyPlatform(msg_body)
  33. local isok ,key = tools.checkData({"tg_platform_name","id","filter_guajian_logic"},msg_body)
  34. if not isok then
  35. return false,string.format("缺少字段: %s.", key)
  36. end
  37. local sql = string.format("UPDATE `tg_platform` SET filter_guajian_logic = '%s' , tg_platform_name = '%s' WHERE id = %d ",
  38. msg_body.filter_guajian_logic,
  39. msg_body.tg_platform_name,msg_body.id)
  40. mysqldbx.query(sql)
  41. skynet.send("backmgr","lua","on_recv",nil,"ws_push_msg",cjson.encode({cmd="updatePlatformConfig"}))
  42. return true
  43. end
  44. --添加回传规则
  45. function M.addHuiChuanRule(msg_body)
  46. local isok ,key = tools.checkData({"name","id","value"},msg_body)
  47. if not isok then
  48. return false,string.format("缺少字段: %s.", key)
  49. end
  50. local sql = string.format("select huichuan from `tg_platform` WHERE id = %d ",msg_body.id)
  51. local res = mysqldbx.query(sql)
  52. local obj = {}
  53. if res[1].huichuan~=nil then
  54. obj = cjson.decode(res[1].huichuan)
  55. end
  56. local id = #obj+1
  57. table.insert(obj,id,{id=id,name=msg_body.name,value=msg_body.value})
  58. sql = string.format("UPDATE `tg_platform` SET huichuan = '%s' WHERE id = %d ",
  59. cjson.encode(obj),msg_body.id)
  60. mysqldbx.query(sql)
  61. skynet.send("backmgr","lua","on_recv",nil,"ws_push_msg",cjson.encode({cmd="updatePlatformConfig"}))
  62. return true, obj
  63. end
  64. --修改回传规则
  65. function M.modifyHuiChuanRule(msg_body)
  66. local isok ,key = tools.checkData({"name","id","value","table_id"},msg_body)
  67. if not isok then
  68. return false,string.format("缺少字段: %s.", key)
  69. end
  70. local sql = string.format("select huichuan from `tg_platform` WHERE id = %d ",msg_body.id)
  71. local res = mysqldbx.query(sql)
  72. local obj = {}
  73. if res[1].huichuan~=nil then
  74. obj = cjson.decode(res[1].huichuan)
  75. end
  76. for i = 1, #obj, 1 do
  77. if obj[i].id == msg_body.table_id then
  78. obj[i].name = msg_body.name
  79. obj[i].value = msg_body.value
  80. break
  81. end
  82. end
  83. sql = string.format("UPDATE `tg_platform` SET huichuan = '%s' WHERE id = %d ",
  84. cjson.encode(obj),msg_body.id)
  85. mysqldbx.query(sql)
  86. skynet.send("backmgr","lua","on_recv",nil,"ws_push_msg",cjson.encode({cmd="updatePlatformConfig"}))
  87. return true,obj
  88. end
  89. --添加收费卡点
  90. function M.addShouFeiKaDian(msg_body)
  91. local isok ,key = tools.checkData({"name","id","value"},msg_body)
  92. if not isok then
  93. return false,string.format("缺少字段: %s.", key)
  94. end
  95. local sql = string.format("select kadian from `tg_platform` WHERE id = %d ",msg_body.id)
  96. local res = mysqldbx.query(sql)
  97. local obj = {}
  98. if res[1].kadian~=nil then
  99. obj = cjson.decode(res[1].kadian)
  100. end
  101. local id = #obj+1
  102. table.insert(obj,id,{id=id,name=msg_body.name,value=msg_body.value})
  103. sql = string.format("UPDATE `tg_platform` SET kadian = '%s' WHERE id = %d ",
  104. cjson.encode(obj),msg_body.id)
  105. mysqldbx.query(sql)
  106. return true, obj
  107. end
  108. --修改收费卡点
  109. function M.modifyShouFeiKaDian(msg_body)
  110. local isok ,key = tools.checkData({"name","id","table_id","value"},msg_body)
  111. if not isok then
  112. return false,string.format("缺少字段: %s.", key)
  113. end
  114. local sql = string.format("select kadian from `tg_platform` WHERE id = %d ",msg_body.id)
  115. local res = mysqldbx.query(sql)
  116. local obj = {}
  117. if res[1].kadian~=nil then
  118. obj = cjson.decode(res[1].kadian)
  119. end
  120. for i = 1, #obj, 1 do
  121. if obj[i].id == msg_body.table_id then
  122. obj[i].name = msg_body.name
  123. obj[i].value = msg_body.value
  124. break
  125. end
  126. end
  127. sql = string.format("UPDATE `tg_platform` SET kadian = '%s' WHERE id = %d ",
  128. cjson.encode(obj),msg_body.id)
  129. mysqldbx.query(sql)
  130. return true,obj
  131. end
  132. --添加充值模板
  133. function M.addChongZhiTemplate(msg_body)
  134. local isok ,key = tools.checkData({"name","id","value"},msg_body)
  135. if not isok then
  136. return false,string.format("缺少字段: %s.", key)
  137. end
  138. local sql = string.format("select chongzhi from `tg_platform` WHERE id = %d ",msg_body.id)
  139. local res = mysqldbx.query(sql)
  140. local obj = {}
  141. if res[1].chongzhi~=nil then
  142. obj = cjson.decode(res[1].chongzhi)
  143. end
  144. local id = #obj+1
  145. table.insert(obj,id,{id=id,name=msg_body.name,value=msg_body.value})
  146. sql = string.format("UPDATE `tg_platform` SET chongzhi = '%s' WHERE id = %d ",
  147. cjson.encode(obj),msg_body.id)
  148. mysqldbx.query(sql)
  149. return true, obj
  150. end
  151. --修改充值模板
  152. function M.modifyChongZhiTemplate(msg_body)
  153. local isok ,key = tools.checkData({"name","id","table_id","value"},msg_body)
  154. if not isok then
  155. return false,string.format("缺少字段: %s.", key)
  156. end
  157. local sql = string.format("select chongzhi from `tg_platform` WHERE id = %d ",msg_body.id)
  158. local res = mysqldbx.query(sql)
  159. local obj = {}
  160. if res[1].chongzhi ~=nil then
  161. obj = cjson.decode(res[1].chongzhi)
  162. end
  163. for i = 1, #obj, 1 do
  164. if obj[i].id == msg_body.table_id then
  165. obj[i].name = msg_body.name
  166. obj[i].value = msg_body.value
  167. break
  168. end
  169. end
  170. sql = string.format("UPDATE `tg_platform` SET chongzhi = '%s' WHERE id = %d ",
  171. cjson.encode(obj),msg_body.id)
  172. mysqldbx.query(sql)
  173. return true,obj
  174. end
  175. --添加复充值模板
  176. function M.addFChongZhiTemplate(msg_body)
  177. local isok ,key = tools.checkData({"name","id","value"},msg_body)
  178. if not isok then
  179. return false,string.format("缺少字段: %s.", key)
  180. end
  181. local sql = string.format("select f_chongzhi from `tg_platform` WHERE id = %d ",msg_body.id)
  182. local res = mysqldbx.query(sql)
  183. local obj = {}
  184. if res[1].f_chongzhi~=nil then
  185. obj = cjson.decode(res[1].f_chongzhi)
  186. end
  187. local id = #obj+1
  188. table.insert(obj,id,{id=id,name=msg_body.name,value=msg_body.value})
  189. sql = string.format("UPDATE `tg_platform` SET f_chongzhi = '%s' WHERE id = %d ",
  190. cjson.encode(obj),msg_body.id)
  191. mysqldbx.query(sql)
  192. return true, obj
  193. end
  194. --修改复充值模板
  195. function M.modifyFChongZhiTemplate(msg_body)
  196. local isok ,key = tools.checkData({"name","id","table_id","value"},msg_body)
  197. if not isok then
  198. return false,string.format("缺少字段: %s.", key)
  199. end
  200. local sql = string.format("select f_chongzhi from `tg_platform` WHERE id = %d ",msg_body.id)
  201. local res = mysqldbx.query(sql)
  202. local obj = {}
  203. if res[1].f_chongzhi ~=nil then
  204. obj = cjson.decode(res[1].f_chongzhi)
  205. end
  206. for i = 1, #obj, 1 do
  207. if obj[i].id == msg_body.table_id then
  208. obj[i].name = msg_body.name
  209. obj[i].value = msg_body.value
  210. break
  211. end
  212. end
  213. sql = string.format("UPDATE `tg_platform` SET f_chongzhi = '%s' WHERE id = %d ",
  214. cjson.encode(obj),msg_body.id)
  215. mysqldbx.query(sql)
  216. return true,obj
  217. end
  218. --添加推广小程序平台
  219. function M.addMiniProgramPlatform(msg_body)
  220. local isok ,key = tools.checkData({"name","id","value"},msg_body)
  221. if not isok then
  222. return false,string.format("缺少字段: %s.", key)
  223. end
  224. local sql = string.format("select m_p_platform from `tg_platform` WHERE id = %d ",msg_body.id)
  225. local res = mysqldbx.query(sql)
  226. local obj = {}
  227. if res[1].m_p_platform~=nil then
  228. obj = cjson.decode(res[1].m_p_platform)
  229. end
  230. local id = #obj+1
  231. table.insert(obj,id,{id=id,name=msg_body.name,value=msg_body.value})
  232. sql = string.format("UPDATE `tg_platform` SET m_p_platform = '%s' WHERE id = %d ",
  233. cjson.encode(obj),msg_body.id)
  234. mysqldbx.query(sql)
  235. return true, obj
  236. end
  237. --修改推广小程序平台
  238. function M.modifyMiniProgramPlatform(msg_body)
  239. local isok ,key = tools.checkData({"name","id","table_id","value"},msg_body)
  240. if not isok then
  241. return false,string.format("缺少字段: %s.", key)
  242. end
  243. local sql = string.format("select m_p_platform from `tg_platform` WHERE id = %d ",msg_body.id)
  244. local res = mysqldbx.query(sql)
  245. local obj = {}
  246. if res[1].m_p_platform~=nil then
  247. obj = cjson.decode(res[1].m_p_platform)
  248. end
  249. for i = 1, #obj, 1 do
  250. if obj[i].id == msg_body.table_id then
  251. obj[i].name = msg_body.name
  252. obj[i].value = msg_body.value
  253. break
  254. end
  255. end
  256. sql = string.format("UPDATE `tg_platform` SET m_p_platform = '%s' WHERE id = %d ",
  257. cjson.encode(obj),msg_body.id)
  258. mysqldbx.query(sql)
  259. return true,obj
  260. end
  261. function M.set_filter_guajian_logic(msg_body)
  262. local isok ,key = tools.checkData({"id","filter_guajian_logic"},msg_body)
  263. if not isok then
  264. return false,string.format("缺少字段: %s.", key)
  265. end
  266. local sql = string.format("UPDATE `tg_platform` SET filter_guajian_logic = '%s' WHERE id = %d ",msg_body.filter_guajian_logic,msg_body.id)
  267. mysqldbx.query(sql)
  268. return true,{}
  269. end
  270. function M.getTotal()
  271. local sql = "SELECT COUNT(*) AS total FROM tg_platform"
  272. local res = mysqldbx.query(sql)
  273. return true,res[1]
  274. end
  275. return M