--微信小程序产品表 local M = {} local mysqldbx = require "mysqldbx" local tools = require "tools" local skynet = require "skynet" local cjson = require "cjson" function M.set_sweight(msg_body) local isok ,key = tools.checkData({"sweight","id_list"},msg_body) if not isok then return false,string.format("缺少字段: %s.", key) end local idString = table.concat(msg_body.id_list, ",") local sql = string.format("UPDATE wechat_miniapp_product SET sweight = %d WHERE id IN (%s) ",msg_body.sweight,idString) mysqldbx.query(sql) return true, {} end function M.search(msg_body) local isok ,key = tools.checkData({ "start_publish_time", "end_publish_time", "main_id", "start_create_time", "end_create_time", "audit_status", "ldy_audit_status", "product_name", "product_id", "create_status", "share_status", "ldy_create_status", "ldy_share_status", "page_size", "page_number" },msg_body) if not isok then return false,string.format("缺少字段: %s.", key) end local page_size = msg_body.page_size local page_number = msg_body.page_number local offset = (page_number - 1) * page_size local date_param = "" if msg_body.start_publish_time~="" and msg_body.end_publish_time~="" then 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) .. ")) " end local main_param = "" if msg_body.main_id~="" then main_param = string.format(" AND main_id = %d ",tonumber(msg_body.main_id)) end local create_date_param = "" if msg_body.start_create_time~="" and msg_body.end_create_time~="" then 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) .. "))" end local audit_status_param = "" if msg_body.audit_status~="" then audit_status_param = string.format(" AND audit_status = %d ",tonumber(msg_body.audit_status)) end local ldy_audit_status_param = "" if msg_body.ldy_audit_status~="" then ldy_audit_status_param = string.format(" AND ldy_audit_status = %d ",tonumber(msg_body.ldy_audit_status)) end local product_param = "" if msg_body.product_id~="" then product_param = string.format(" AND product_id = '%s' ",msg_body.product_id) end local product_name_param = "" if msg_body.product_name~="" then product_name_param = string.format(" AND ( product_name LIKE CONCAT( '%%%s%%')) ",msg_body.product_name) end local create_status_param = "" if msg_body.create_status~="" then create_status_param = string.format(" AND create_status = %d ",msg_body.create_status) end local share_status_param = "" if msg_body.share_status~="" then share_status_param = string.format(" AND share_status = %d ",msg_body.share_status) end local ldy_create_status_param = "" if msg_body.ldy_create_status~="" then ldy_create_status_param = string.format(" AND ldy_create_status = %d ",msg_body.ldy_create_status) end local ldy_share_status_param = "" if msg_body.ldy_share_status~="" then ldy_share_status_param = string.format(" AND ldy_share_status = %d ",msg_body.ldy_share_status) end 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 local sql = "SELECT * FROM wechat_miniapp_product WHERE 1=1 "..param.."ORDER BY sweight DESC"..string.format(" LIMIT %d OFFSET %d ",page_size, offset) local list = mysqldbx.query(sql) sql = "SELECT COUNT(*) AS total FROM wechat_miniapp_product WHERE 1=1 "..param local total = mysqldbx.query(sql) return true,list,total[1].total end return M