diff --git a/http/controller/balance.go b/http/controller/balance.go index be514bc3..5277943a 100644 --- a/http/controller/balance.go +++ b/http/controller/balance.go @@ -7,6 +7,7 @@ package controller import ( + "github.com/polaris1119/goutils" "github.com/studygolang/studygolang/context" "github.com/studygolang/studygolang/http/middleware" "github.com/studygolang/studygolang/logic" @@ -24,18 +25,23 @@ func (self UserRichController) RegisterRoute(g *echo.Group) { } func (UserRichController) MyBalance(ctx echo.Context) error { + p := goutils.MustInt(ctx.QueryParam("p"), 1) me := ctx.Get("user").(*model.Me) - balanceDetails := logic.DefaultUserRich.FindBalanceDetail(context.EchoContext(ctx), me) + balanceDetails := logic.DefaultUserRich.FindBalanceDetail(context.EchoContext(ctx), me, p) + total := logic.DefaultUserRich.Total(context.EchoContext(ctx), me.Uid) data := map[string]interface{}{ "details": balanceDetails, + "total": int(total), + "cur_p": p, } return render(ctx, "rich/balance.html", data) } func (UserRichController) Add(ctx echo.Context) error { + p := goutils.MustInt(ctx.QueryParam("p"), 1) me := ctx.Get("user").(*model.Me) - balanceDetails := logic.DefaultUserRich.FindBalanceDetail(context.EchoContext(ctx), me, model.MissionTypeAdd) + balanceDetails := logic.DefaultUserRich.FindBalanceDetail(context.EchoContext(ctx), me, p, model.MissionTypeAdd) rechargeAmount := logic.DefaultUserRich.FindRecharge(context.EchoContext(ctx), me) diff --git a/logic/user_rich.go b/logic/user_rich.go index 855aefb6..4960837f 100644 --- a/logic/user_rich.go +++ b/logic/user_rich.go @@ -9,11 +9,12 @@ package logic import ( "errors" "fmt" - "github.com/studygolang/studygolang/model" - "github.com/studygolang/studygolang/util" "net/url" "time" + "github.com/studygolang/studygolang/model" + "github.com/studygolang/studygolang/util" + . "github.com/studygolang/studygolang/db" "github.com/garyburd/redigo/redis" @@ -152,7 +153,7 @@ func (self UserRichLogic) IncrUserRich(user *model.User, typ, award int, desc st session.Commit() } -func (UserRichLogic) FindBalanceDetail(ctx context.Context, me *model.Me, types ...int) []*model.UserBalanceDetail { +func (UserRichLogic) FindBalanceDetail(ctx context.Context, me *model.Me, p int, types ...int) []*model.UserBalanceDetail { objLog := GetLogger(ctx) balanceDetails := make([]*model.UserBalanceDetail, 0) @@ -161,7 +162,7 @@ func (UserRichLogic) FindBalanceDetail(ctx context.Context, me *model.Me, types session.And("type=?", types[0]) } - err := session.Desc("id").Find(&balanceDetails) + err := session.Desc("id").Limit(CommentPerNum, (p-1)*CommentPerNum).Find(&balanceDetails) if err != nil { objLog.Errorln("UserRichLogic FindBalanceDetail error:", err) return nil diff --git a/template/rich/balance.html b/template/rich/balance.html index 8f825ce4..2b9f5803 100644 --- a/template/rich/balance.html +++ b/template/rich/balance.html @@ -31,6 +31,34 @@ {{.me.Copper}} + {{if gt .total .cmt_per_num}} +
+ + + + {{with $pageMax := divide .total .cmt_per_num}} + + + {{end}} + + +
+ {{range $i, $v := genList $.total $.cmt_per_num}} + {{$v}} + {{end}} + + + + + + + + + +
+
+
+ {{end}}
@@ -94,9 +122,54 @@

获得初始资本

{{define "css"}} {{end}} {{define "js"}} + {{end}}