tg_platform.lua 11 KB

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