tg_butler.lua 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. --管家
  2. local M = {}
  3. local mysqldbx = require "mysqldbx"
  4. local tools = require "tools"
  5. local skynet = require "skynet"
  6. local cjson = require "cjson"
  7. -- function M.add_butler(msg_body)
  8. -- local isok ,key = tools.checkData({"butler_name","butler_id","mail"},msg_body)
  9. -- if not isok then
  10. -- return false,string.format("缺少字段: %s.", key)
  11. -- end
  12. -- local sql = string.format("INSERT INTO `tg_butler` (butler_name,butler_id,mail) VALUES ('%s',%d,'%s')",
  13. -- msg_body.butler_name, msg_body.butler_id, msg_body.mail)
  14. -- mysqldbx.query(sql)
  15. -- return true
  16. -- end
  17. function M.modify_butler(msg_body)
  18. local isok ,key = tools.checkData({"white_advertiser_id","advertiser_ids","oce_product_id","oce_product_platform_id","advertiser_id","butler_name","cc_account_id","mail","id","tg_platform_ids"},msg_body)
  19. if not isok then
  20. return false,string.format("缺少字段: %s.", key)
  21. end
  22. local sql = string.format("UPDATE `advertiser_butler` SET white_advertiser_id = %d , advertiser_ids = '%s' , advertiser_id = %d ,name = '%s', cc_account_id = %d ,email = '%s' , tg_platform_ids = '%s' ,oce_product_id = '%s' , oce_product_platform_id = '%s' WHERE id = %d ",
  23. msg_body.white_advertiser_id,cjson.encode(msg_body.advertiser_ids),msg_body.advertiser_id,msg_body.butler_name,msg_body.cc_account_id,msg_body.mail,msg_body.tg_platform_ids,msg_body.oce_product_id,msg_body.oce_product_platform_id,msg_body.id)
  24. skynet.error("sql:",sql)
  25. mysqldbx.query(sql)
  26. return true
  27. end
  28. function M.search_butler(msg_body)
  29. local isok ,key = tools.checkData({"page_size","page_number"},msg_body)
  30. if not isok then
  31. return false,string.format("缺少字段: %s.", key)
  32. end
  33. local page_size = msg_body.page_size
  34. local page_number = msg_body.page_number
  35. local offset = (page_number - 1) * page_size
  36. local param = ""
  37. local name_param = ""
  38. if msg_body.name~="" then
  39. name_param = string.format(" AND (name LIKE CONCAT( '%%%s%%')) ",msg_body.name)
  40. end
  41. local id_param = ""
  42. if msg_body.id~="" then
  43. id_param = string.format(" AND id = %d ",msg_body.id)
  44. end
  45. param = name_param..id_param
  46. local sql = "SELECT * FROM advertiser_butler WHERE 1=1 "..param..string.format(" LIMIT %d OFFSET %d ",page_size, offset)
  47. local list = mysqldbx.query(sql)
  48. sql = "SELECT COUNT(*) AS total FROM advertiser_butler WHERE 1=1 "..param
  49. local total = mysqldbx.query(sql)
  50. return true,list,total[1].total
  51. end
  52. return M