tg_app.lua 2.3 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({"butler_id","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` (butler_id,tg_platform_id,app_id, instance_id, name,advertiser_id,landing_page,titles) VALUES (%d,%d,'%s','%s','%s','%s','%s','%s')",
  30. msg_body.butler_id,
  31. msg_body.tg_platform_id,
  32. msg_body.app_id,
  33. msg_body.instance_id,msg_body.name,msg_body.advertiser_id,msg_body.landing_page,msg_body.titles)
  34. mysqldbx.query(sql)
  35. skynet.send("backmgr","lua","on_recv",nil,"ws_push_msg",cjson.encode({cmd="updateAppConfig"}))
  36. return true
  37. end
  38. --修改小程序
  39. function M.modifyApp(msg_body)
  40. local isok ,key = tools.checkData({"butler_id","id","tg_platform_id","app_id","instance_id","name","advertiser_id","landing_page","titles"},msg_body)
  41. if not isok then
  42. return false,string.format("缺少字段: %s.", key)
  43. end
  44. local current_time = os.date("%Y-%m-%d %H:%M:%S")
  45. msg_body.update_time = current_time
  46. local sql = string.format("UPDATE `tg_app` SET butler_id = %d , 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 ",
  47. msg_body.butler_id,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)
  48. mysqldbx.query(sql)
  49. skynet.send("backmgr","lua","on_recv",nil,"ws_push_msg",cjson.encode({cmd="updateAppConfig"}))
  50. return true
  51. end
  52. return M