Skip to content

Commit

Permalink
add point to user
Browse files Browse the repository at this point in the history
  • Loading branch information
GoodERPJeff committed Oct 17, 2019
1 parent ae13263 commit 18cc4bb
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 3 deletions.
1 change: 1 addition & 0 deletions models/repo_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions models/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
2 changes: 1 addition & 1 deletion routers/home.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"), " ")
Expand Down
1 change: 1 addition & 0 deletions routers/routes/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
22 changes: 22 additions & 0 deletions routers/user/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"fmt"
"path"
"strings"
"strconv"

"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/base"
Expand Down Expand Up @@ -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())
}
2 changes: 1 addition & 1 deletion templates/explore/users.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<div class="item">
<img class="ui avatar image" src="{{.RelAvatarLink}}">
<div class="content">
<span class="header"><a href="{{.HomeLink}}">{{.Name}}</a> {{.FullName}}</span>
<span class="header"><a href="{{.HomeLink}}">{{.Name}}</a> {{.FullName}} {{.Point}}</span>
<div class="description">
{{if .Location}}
<i class="octicon octicon-location"></i> {{.Location}}
Expand Down
17 changes: 16 additions & 1 deletion templates/user/profile.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
{{end}}
<div class="content wrap">
{{if .Owner.FullName}}<span class="header text center">{{.Owner.FullName}}</span>{{end}}
<span class="username text center">{{.Owner.Name}}</span>
<span class="username text center">{{.Owner.Name}} {{.Owner.Point}}</span>
</div>
<div class="extra content wrap">
<ul class="text black">
Expand Down Expand Up @@ -88,6 +88,21 @@
<a class="ui basic green button" href="{{.Link}}/action/follow?redirect_to={{$.Link}}"><i class="octicon octicon-person"></i> {{.i18n.Tr "user.follow"}}</a>
{{end}}
</li>
<li>
<form class="ui form" id="transfer-point-form" action="{{.Link}}/action/transfer_point" method="post">
{{.CsrfTokenHtml}}
<input type="hidden" name="uid" value="{{.SignedUser.ID}}">
<input type="hidden" name="toid" value="{{ .Owner.ID }}">
<div class="inline field ui left">
<div class="ui input">
<input name="why" placeholder="为什么" autocomplete="off" required>
发送
<input name="qty" placeholder="多少个赞" autocomplete="off" required>
</div>
</div>
<button class="ui green button"><i class="octicon octicon-thumbsup"/></button>
</form>
</li>
{{end}}
</ul>
</div>
Expand Down

0 comments on commit 18cc4bb

Please sign in to comment.