tg_platform.lua 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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"},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. tools.dump(obj)
  55. end
  56. local id = #obj+1
  57. table.insert(obj,id,{id=id,name=msg_body.name})
  58. sql = string.format("UPDATE `tg_platform` SET huichuan = '%s' WHERE id = %d ",
  59. cjson.encode(obj),msg_body.id)
  60. mysqldbx.query(sql)
  61. skynet.send("backmgr","lua","on_recv",nil,"ws_push_msg",cjson.encode({cmd="updatePlatformConfig"}))
  62. return true, obj
  63. end
  64. --修改回传规则
  65. function M.modifyHuiChuanRule(msg_body)
  66. local isok ,key = tools.checkData({"name","id","table_id"},msg_body)
  67. if not isok then
  68. return false,string.format("缺少字段: %s.", key)
  69. end
  70. local sql = string.format("select huichuan from `tg_platform` WHERE id = %d ",msg_body.id)
  71. local res = mysqldbx.query(sql)
  72. local obj = {}
  73. if res[1].huichuan~=nil then
  74. obj = cjson.decode(res[1].huichuan)
  75. end
  76. for i = 1, #obj, 1 do
  77. if obj[i].id == msg_body.table_id then
  78. obj[i].name = msg_body.name
  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"},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. tools.dump(obj)
  100. end
  101. local id = #obj+1
  102. table.insert(obj,id,{id=id,name=msg_body.name})
  103. sql = string.format("UPDATE `tg_platform` SET kadian = '%s' WHERE id = %d ",
  104. cjson.encode(obj),msg_body.id)
  105. mysqldbx.query(sql)
  106. return true, obj
  107. end
  108. --修改收费卡点
  109. function M.modifyShouFeiKaDian(msg_body)
  110. local isok ,key = tools.checkData({"name","id","table_id"},msg_body)
  111. if not isok then
  112. return false,string.format("缺少字段: %s.", key)
  113. end
  114. local sql = string.format("select kadian from `tg_platform` WHERE id = %d ",msg_body.id)
  115. local res = mysqldbx.query(sql)
  116. local obj = {}
  117. if res[1].kadian~=nil then
  118. obj = cjson.decode(res[1].kadian)
  119. end
  120. for i = 1, #obj, 1 do
  121. if obj[i].id == msg_body.table_id then
  122. obj[i].name = msg_body.name
  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"},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})
  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"},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. break
  166. end
  167. end
  168. sql = string.format("UPDATE `tg_platform` SET chongzhi = '%s' WHERE id = %d ",
  169. cjson.encode(obj),msg_body.id)
  170. mysqldbx.query(sql)
  171. return true,obj
  172. end
  173. function M.getTotal()
  174. local sql = "SELECT COUNT(*) AS total FROM tg_platform"
  175. local res = mysqldbx.query(sql)
  176. return true,res[1]
  177. end
  178. return M