tg_platform.lua 13 KB

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