Skip to content

Commit 9618629

Browse files
committed
add transfer table
1 parent 18cc4bb commit 9618629

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

models/transfer_point.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright 2017 The Gitea Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
package models
6+
7+
import (
8+
"code.gitea.io/gitea/modules/timeutil"
9+
)
10+
11+
type Transfer struct {
12+
ID int64 `xorm:"pk autoincr"`
13+
FromID int64
14+
ToID int64
15+
Why string
16+
Qty int
17+
CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"`
18+
}
19+
20+
func TransferPoint(FromID int64, Why string, ToID int64, Qty int) (err error) {
21+
22+
sess := x.NewSession()
23+
//判断是否足够转
24+
defer sess.Close()
25+
if err = sess.Begin(); err != nil {
26+
return err
27+
}
28+
29+
// if _, err = sess.Insert(&Transfer{FromID: FromID, ToID: ToID, Why: Why, Qty: Qty}); err != nil {
30+
// return err
31+
// }
32+
33+
if _, err = sess.Exec("UPDATE `user` SET point = point + ? WHERE id = ?", Qty, ToID); err != nil {
34+
return err
35+
}
36+
37+
if _, err = sess.Exec("UPDATE `user` SET point = point - ? WHERE id = ?", Qty, FromID); err != nil {
38+
return err
39+
}
40+
return sess.Commit()
41+
}

0 commit comments

Comments
 (0)