wechat_miniapp_product.lua 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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.set_sweight(msg_body)
  8. local isok ,key = tools.checkData({"sweight","id_list"},msg_body)
  9. if not isok then
  10. return false,string.format("缺少字段: %s.", key)
  11. end
  12. local idString = table.concat(msg_body.id_list, ",")
  13. local sql = string.format("UPDATE wechat_miniapp_product SET sweight = %d WHERE id IN (%s) ",msg_body.sweight,idString)
  14. mysqldbx.query(sql)
  15. return true, {}
  16. end
  17. function M.search(msg_body)
  18. local isok ,key = tools.checkData({
  19. "start_publish_time",
  20. "end_publish_time",
  21. "main_id",
  22. "start_create_time",
  23. "end_create_time",
  24. "audit_status",
  25. "ldy_audit_status",
  26. "product_name",
  27. "product_id",
  28. "create_status",
  29. "share_status",
  30. "ldy_create_status",
  31. "ldy_share_status",
  32. "page_size",
  33. "page_number"
  34. },msg_body)
  35. if not isok then
  36. return false,string.format("缺少字段: %s.", key)
  37. end
  38. local page_size = msg_body.page_size
  39. local page_number = msg_body.page_number
  40. local offset = (page_number - 1) * page_size
  41. local date_param = ""
  42. if msg_body.start_publish_time~="" and msg_body.end_publish_time~="" then
  43. date_param = " AND DATE(publish_time) >= DATE(FROM_UNIXTIME(" .. (msg_body.start_publish_time / 1000) .. ")) AND DATE(publish_time) <= DATE(FROM_UNIXTIME(" .. (msg_body.end_publish_time / 1000) .. ")) "
  44. end
  45. local main_param = ""
  46. if msg_body.main_id~="" then
  47. main_param = string.format(" AND main_id = %d ",tonumber(msg_body.main_id))
  48. end
  49. local create_date_param = ""
  50. if msg_body.start_create_time~="" and msg_body.end_create_time~="" then
  51. create_date_param = " AND DATE(create_time) >= DATE(FROM_UNIXTIME(" .. (msg_body.start_create_time / 1000) .. ")) AND DATE(create_time) <= DATE(FROM_UNIXTIME(" .. (msg_body.end_create_time / 1000) .. "))"
  52. end
  53. local audit_status_param = ""
  54. if msg_body.audit_status~="" then
  55. audit_status_param = string.format(" AND audit_status = %d ",tonumber(msg_body.audit_status))
  56. end
  57. local ldy_audit_status_param = ""
  58. if msg_body.ldy_audit_status~="" then
  59. ldy_audit_status_param = string.format(" AND ldy_audit_status = %d ",tonumber(msg_body.ldy_audit_status))
  60. end
  61. local product_param = ""
  62. if msg_body.product_id~="" then
  63. product_param = string.format(" AND product_id = '%s' ",msg_body.product_id)
  64. end
  65. local product_name_param = ""
  66. if msg_body.product_name~="" then
  67. product_name_param = string.format(" AND ( product_name LIKE CONCAT( '%%%s%%')) ",msg_body.product_name)
  68. end
  69. local create_status_param = ""
  70. if msg_body.create_status~="" then
  71. create_status_param = string.format(" AND create_status = %d ",msg_body.create_status)
  72. end
  73. local share_status_param = ""
  74. if msg_body.share_status~="" then
  75. share_status_param = string.format(" AND share_status = %d ",msg_body.share_status)
  76. end
  77. local ldy_create_status_param = ""
  78. if msg_body.ldy_create_status~="" then
  79. ldy_create_status_param = string.format(" AND ldy_create_status = %d ",msg_body.ldy_create_status)
  80. end
  81. local ldy_share_status_param = ""
  82. if msg_body.ldy_share_status~="" then
  83. ldy_share_status_param = string.format(" AND ldy_share_status = %d ",msg_body.ldy_share_status)
  84. end
  85. local param = date_param..product_param..product_name_param..ldy_share_status_param..ldy_create_status_param..share_status_param..create_status_param..ldy_audit_status_param..audit_status_param..create_date_param..main_param
  86. local sql = "SELECT * FROM wechat_miniapp_product WHERE 1=1 "..param.."ORDER BY sweight DESC"..string.format(" LIMIT %d OFFSET %d ",page_size, offset)
  87. local list = mysqldbx.query(sql)
  88. sql = "SELECT COUNT(*) AS total FROM wechat_miniapp_product WHERE 1=1 "..param
  89. local total = mysqldbx.query(sql)
  90. return true,list,total[1].total
  91. end
  92. return M