tg_app.lua 2.4 KB

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