tg_platform.lua 13 KB

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