tg_app.lua 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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.getAppList()
  9. local sql = string.format("select * from `tg_app` ")
  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. --所属账户ID advertiser_id
  18. --资产ID instance_id
  19. --小程序ID app_id
  20. --小程序名称 name
  21. --添加小程序
  22. function M.addApp(msg_body)
  23. local isok ,key = tools.checkData({"tg_platform_id","app_id","instance_id","name","advertiser_id","landing_page","titles"},msg_body)
  24. if not isok then
  25. return false,string.format("缺少字段: %s.", key)
  26. end
  27. local current_time = os.date("%Y-%m-%d %H:%M:%S")
  28. msg_body.create_time = current_time
  29. local sql = string.format("INSERT INTO `tg_app` (tg_platform_id,app_id, instance_id, name,advertiser_id,landing_page,titles) VALUES (%d,'%s','%s','%s','%s','%s','%s')",
  30. msg_body.tg_platform_id,
  31. msg_body.app_id,
  32. msg_body.instance_id,msg_body.name,msg_body.advertiser_id,msg_body.landing_page,msg_body.titles)
  33. mysqldbx.query(sql)
  34. skynet.send("backmgr","lua","on_recv",nil,"push_msg","updateAppConfig")
  35. return true
  36. end
  37. --修改小程序
  38. function M.modifyApp(msg_body)
  39. local isok ,key = tools.checkData({"id","tg_platform_id","app_id","instance_id","name","advertiser_id","landing_page","titles"},msg_body)
  40. if not isok then
  41. return false,string.format("缺少字段: %s.", key)
  42. end
  43. local current_time = os.date("%Y-%m-%d %H:%M:%S")
  44. msg_body.update_time = current_time
  45. local sql = string.format("UPDATE `tg_app` SET tg_platform_id =%d ,app_id ='%s' , instance_id ='%s' , name ='%s' , advertiser_id ='%s' , update_time ='%s' , landing_page ='%s' , titles ='%s' WHERE id = %d ",
  46. msg_body.tg_platform_id,msg_body.app_id,msg_body.instance_id,msg_body.name,msg_body.advertiser_id,msg_body.update_time,msg_body.landing_page,msg_body.titles,msg_body.id)
  47. mysqldbx.query(sql)
  48. skynet.send("backmgr","lua","on_recv",nil,"ws_push_msg",cjson.encode({cmd="updateAppConfig"}))
  49. return true
  50. end
  51. return M