tg_platform.lua 13 KB

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