From 18cc4bb1a7ab6951b8e1c54ec37f746e993a3eaa Mon Sep 17 00:00:00 2001 From: jeff Date: Thu, 17 Oct 2019 19:26:10 +0800 Subject: [PATCH] add point to user --- models/repo_list.go | 1 + models/user.go | 1 + routers/home.go | 2 +- routers/routes/routes.go | 1 + routers/user/profile.go | 22 ++++++++++++++++++++++ templates/explore/users.tmpl | 2 +- templates/user/profile.tmpl | 17 ++++++++++++++++- 7 files changed, 43 insertions(+), 3 deletions(-) diff --git a/models/repo_list.go b/models/repo_list.go index 692d4d002f5a4..8dd882d1d7e3f 100644 --- a/models/repo_list.go +++ b/models/repo_list.go @@ -163,6 +163,7 @@ const ( SearchOrderByStarsReverse SearchOrderBy = "num_stars DESC" SearchOrderByForks SearchOrderBy = "num_forks ASC" SearchOrderByForksReverse SearchOrderBy = "num_forks DESC" + SearchOrderByPoint SearchOrderBy = "Point DESC" ) // SearchRepository returns repositories based on search options, diff --git a/models/user.go b/models/user.go index 030e23c383afb..48068c2839a5f 100644 --- a/models/user.go +++ b/models/user.go @@ -118,6 +118,7 @@ type User struct { Salt string `xorm:"VARCHAR(10)"` Language string `xorm:"VARCHAR(5)"` Description string + Point int `xorm:"NOT NULL DEFAULT 0"` CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"` UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"` diff --git a/routers/home.go b/routers/home.go index f8fb849c8e17b..baeb9c4d7413e 100644 --- a/routers/home.go +++ b/routers/home.go @@ -210,7 +210,7 @@ func RenderUserSearch(ctx *context.Context, opts *models.SearchUserOptions, tplN orderBy = models.SearchOrderByAlphabetically default: ctx.Data["SortType"] = "alphabetically" - orderBy = models.SearchOrderByAlphabetically + orderBy = models.SearchOrderByPoint } opts.Keyword = strings.Trim(ctx.Query("q"), " ") diff --git a/routers/routes/routes.go b/routers/routes/routes.go index 9572ea80390a4..6695459951ffa 100644 --- a/routers/routes/routes.go +++ b/routers/routes/routes.go @@ -520,6 +520,7 @@ func RegisterRoutes(m *macaron.Macaron) { m.Group("/:username", func() { m.Get("/action/:action", user.Action) + m.Post("/action/transfer_point", user.TransferP) }, reqSignIn) if macaron.Env == macaron.DEV { diff --git a/routers/user/profile.go b/routers/user/profile.go index 8a62ddeac026c..62db36f668ae5 100644 --- a/routers/user/profile.go +++ b/routers/user/profile.go @@ -9,6 +9,7 @@ import ( "fmt" "path" "strings" + "strconv" "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/base" @@ -270,3 +271,24 @@ func Action(ctx *context.Context) { ctx.RedirectToFirst(ctx.Query("redirect_to"), u.HomeLink()) } + +func TransferP(ctx *context.Context) { + //减少发送者点数 + //增加接收者点数 + //创建transfer记录 + u := GetUserByParams(ctx) + var err error + Qty, err := strconv.Atoi(ctx.Query("qty")) + if err != nil { + return + } + err = models.TransferPoint(ctx.User.ID, + ctx.Query("why"), + u.ID, + Qty) + if err != nil { + ctx.ServerError("Transfer", err) + return + } + ctx.RedirectToFirst(ctx.Query("redirect_to"), u.HomeLink()) +} diff --git a/templates/explore/users.tmpl b/templates/explore/users.tmpl index 32a36931c70b9..8c0f6d96edbeb 100644 --- a/templates/explore/users.tmpl +++ b/templates/explore/users.tmpl @@ -9,7 +9,7 @@
- {{.Name}} {{.FullName}} + {{.Name}} {{.FullName}} {{.Point}}
{{if .Location}} {{.Location}} diff --git a/templates/user/profile.tmpl b/templates/user/profile.tmpl index 52c6e3ec3f589..f4d9dbe78ce2c 100644 --- a/templates/user/profile.tmpl +++ b/templates/user/profile.tmpl @@ -15,7 +15,7 @@ {{end}}
{{if .Owner.FullName}}{{.Owner.FullName}}{{end}} - {{.Owner.Name}} + {{.Owner.Name}} {{.Owner.Point}}