12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- --失败书籍
- local M = {}
- local mysqldbx = require "mysqldbx"
- local tools = require "tools"
- local skynet = require "skynet"
- local cjson = require "cjson"
- function M.delete_other_book(msg_body)
- local isok ,key = tools.checkData({"id_list"},msg_body)
- if not isok then
- return false,string.format("缺少字段: %s.", key)
- end
- for i = 1, #msg_body.id_list, 1 do
- local id = msg_body.id_list[i]
- local sql = string.format("DELETE FROM other_book WHERE id = %d ",id)
- mysqldbx.query(sql)
- end
- return true, {}
- end
- function M.search_other_book(msg_body)
- local isok ,key = tools.checkData({"page_size","page_number","tg_platform_id","product_id"},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 product_id_param = ""
- if msg_body.product_id~="" then
- product_id_param = string.format(" AND product_id = '%s' " ,msg_body.product_id )
- end
-
- local tg_platform_id_param = ""
- if msg_body.tg_platform_id~="" then
- tg_platform_id_param = " AND tg_platform_id = "..msg_body.tg_platform_id.." "
- end
- local param = product_id_param..tg_platform_id_param
- local sql = "SELECT * FROM other_book where 1=1 "..param..string.format(" LIMIT %d OFFSET %d ",page_size, offset)
- local list = mysqldbx.query(sql)
- sql = "SELECT COUNT(*) AS total FROM other_book where 1=1 "..param
- local total = mysqldbx.query(sql)
- return true,list,total[1].total
- end
- return M
|