tg_platform.lua 9.5 KB

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