This commit is contained in:
Jay 2018-12-06 10:20:07 +08:00
commit 1584aacb04
2 changed files with 14 additions and 3 deletions

View File

@ -57,7 +57,10 @@ func GetLineMessageLogCount(where ...interface{}) (c int, err error) {
} }
// GetLineMessageLogList - // GetLineMessageLogList -
func GetLineMessageLogList(g, u string, offset, limit int) (logs []*LineMessageLogWithUG, err error) { func GetLineMessageLogList(g, u string, offset, limit int, orderArg string) (logs []*LineMessageLogWithUG, err error) {
if orderArg != "asc" && orderArg != "desc" {
orderArg = "desc"
}
params := struct { params := struct {
Group string `db:"group"` Group string `db:"group"`
User string `db:"user"` User string `db:"user"`
@ -81,7 +84,7 @@ func GetLineMessageLogList(g, u string, offset, limit int) (logs []*LineMessageL
} }
params.User = u params.User = u
} }
order := `order by m.ctime desc` order := fmt.Sprintf(`order by m.ctime %s`, orderArg)
pager := fmt.Sprintf("offset %d limit %d", offset, limit) pager := fmt.Sprintf("offset %d limit %d", offset, limit)
stmt, err := x.PrepareNamed(fmt.Sprintf("%s %s %s %s", query, where, order, pager)) stmt, err := x.PrepareNamed(fmt.Sprintf("%s %s %s %s", query, where, order, pager))

View File

@ -49,6 +49,10 @@ func GetLineMessageLog(c *context.Context) {
g := c.DefaultQuery("group", "") g := c.DefaultQuery("group", "")
u := c.DefaultQuery("user", "") u := c.DefaultQuery("user", "")
order := c.DefaultQuery("order", "desc")
if order != "asc" && order != "desc" {
order = "desc"
}
where := make(map[string]string) where := make(map[string]string)
if len(g) > 0 { if len(g) > 0 {
@ -66,8 +70,12 @@ func GetLineMessageLog(c *context.Context) {
} }
page := utils.CalcPage(count, numP, numMax) page := utils.CalcPage(count, numP, numMax)
if numP == -1 {
numP = page.Total
}
page = utils.CalcPage(count, numP, numMax)
logs, err := model.GetLineMessageLogList(g, u, page.Offset, page.Limit) logs, err := model.GetLineMessageLogList(g, u, page.Offset, page.Limit, order)
if err != nil { if err != nil {
c.ServerError(nil) c.ServerError(nil)
return return