Skip to content

Commit 18cc4bb

Browse files
committed
add point to user
1 parent ae13263 commit 18cc4bb

File tree

7 files changed

+43
-3
lines changed

7 files changed

+43
-3
lines changed

models/repo_list.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ const (
163163
SearchOrderByStarsReverse SearchOrderBy = "num_stars DESC"
164164
SearchOrderByForks SearchOrderBy = "num_forks ASC"
165165
SearchOrderByForksReverse SearchOrderBy = "num_forks DESC"
166+
SearchOrderByPoint SearchOrderBy = "Point DESC"
166167
)
167168

168169
// SearchRepository returns repositories based on search options,

models/user.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ type User struct {
118118
Salt string `xorm:"VARCHAR(10)"`
119119
Language string `xorm:"VARCHAR(5)"`
120120
Description string
121+
Point int `xorm:"NOT NULL DEFAULT 0"`
121122

122123
CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"`
123124
UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"`

routers/home.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ func RenderUserSearch(ctx *context.Context, opts *models.SearchUserOptions, tplN
210210
orderBy = models.SearchOrderByAlphabetically
211211
default:
212212
ctx.Data["SortType"] = "alphabetically"
213-
orderBy = models.SearchOrderByAlphabetically
213+
orderBy = models.SearchOrderByPoint
214214
}
215215

216216
opts.Keyword = strings.Trim(ctx.Query("q"), " ")

routers/routes/routes.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,7 @@ func RegisterRoutes(m *macaron.Macaron) {
520520

521521
m.Group("/:username", func() {
522522
m.Get("/action/:action", user.Action)
523+
m.Post("/action/transfer_point", user.TransferP)
523524
}, reqSignIn)
524525

525526
if macaron.Env == macaron.DEV {

routers/user/profile.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"fmt"
1010
"path"
1111
"strings"
12+
"strconv"
1213

1314
"code.gitea.io/gitea/models"
1415
"code.gitea.io/gitea/modules/base"
@@ -270,3 +271,24 @@ func Action(ctx *context.Context) {
270271

271272
ctx.RedirectToFirst(ctx.Query("redirect_to"), u.HomeLink())
272273
}
274+
275+
func TransferP(ctx *context.Context) {
276+
//减少发送者点数
277+
//增加接收者点数
278+
//创建transfer记录
279+
u := GetUserByParams(ctx)
280+
var err error
281+
Qty, err := strconv.Atoi(ctx.Query("qty"))
282+
if err != nil {
283+
return
284+
}
285+
err = models.TransferPoint(ctx.User.ID,
286+
ctx.Query("why"),
287+
u.ID,
288+
Qty)
289+
if err != nil {
290+
ctx.ServerError("Transfer", err)
291+
return
292+
}
293+
ctx.RedirectToFirst(ctx.Query("redirect_to"), u.HomeLink())
294+
}

templates/explore/users.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<div class="item">
1010
<img class="ui avatar image" src="{{.RelAvatarLink}}">
1111
<div class="content">
12-
<span class="header"><a href="{{.HomeLink}}">{{.Name}}</a> {{.FullName}}</span>
12+
<span class="header"><a href="{{.HomeLink}}">{{.Name}}</a> {{.FullName}} {{.Point}}</span>
1313
<div class="description">
1414
{{if .Location}}
1515
<i class="octicon octicon-location"></i> {{.Location}}

templates/user/profile.tmpl

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
{{end}}
1616
<div class="content wrap">
1717
{{if .Owner.FullName}}<span class="header text center">{{.Owner.FullName}}</span>{{end}}
18-
<span class="username text center">{{.Owner.Name}}</span>
18+
<span class="username text center">{{.Owner.Name}} {{.Owner.Point}}</span>
1919
</div>
2020
<div class="extra content wrap">
2121
<ul class="text black">
@@ -88,6 +88,21 @@
8888
<a class="ui basic green button" href="{{.Link}}/action/follow?redirect_to={{$.Link}}"><i class="octicon octicon-person"></i> {{.i18n.Tr "user.follow"}}</a>
8989
{{end}}
9090
</li>
91+
<li>
92+
<form class="ui form" id="transfer-point-form" action="{{.Link}}/action/transfer_point" method="post">
93+
{{.CsrfTokenHtml}}
94+
<input type="hidden" name="uid" value="{{.SignedUser.ID}}">
95+
<input type="hidden" name="toid" value="{{ .Owner.ID }}">
96+
<div class="inline field ui left">
97+
<div class="ui input">
98+
<input name="why" placeholder="为什么" autocomplete="off" required>
99+
发送
100+
<input name="qty" placeholder="多少个赞" autocomplete="off" required>
101+
</div>
102+
</div>
103+
<button class="ui green button"><i class="octicon octicon-thumbsup"/></button>
104+
</form>
105+
</li>
91106
{{end}}
92107
</ul>
93108
</div>

0 commit comments

Comments
 (0)