tg_platform.lua 13 KB

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