Skip to content

Commit e4deaf3

Browse files
committed
generate table, add error but fail
1 parent 9618629 commit e4deaf3

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

models/models.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ func init() {
113113
new(OAuth2AuthorizationCode),
114114
new(OAuth2Grant),
115115
new(Task),
116+
new(Transfer),
116117
)
117118

118119
gonicNames := []string{"SSL", "UID"}

models/transfer_point.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ func TransferPoint(FromID int64, Why string, ToID int64, Qty int) (err error) {
2626
return err
2727
}
2828

29-
// if _, err = sess.Insert(&Transfer{FromID: FromID, ToID: ToID, Why: Why, Qty: Qty}); err != nil {
30-
// return err
31-
// }
29+
if _, err = sess.Insert(&Transfer{FromID: FromID, ToID: ToID, Why: Why, Qty: Qty}); err != nil {
30+
return err
31+
}
3232

3333
if _, err = sess.Exec("UPDATE `user` SET point = point + ? WHERE id = ?", Qty, ToID); err != nil {
3434
return err

routers/user/profile.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,11 @@ func TransferP(ctx *context.Context) {
280280
var err error
281281
Qty, err := strconv.Atoi(ctx.Query("qty"))
282282
if err != nil {
283+
ctx.Flash.Error("请输入数字")
284+
return
285+
}
286+
if ctx.User.Point < Qty {
287+
ctx.Flash.Error("余额不足!")
283288
return
284289
}
285290
err = models.TransferPoint(ctx.User.ID,

0 commit comments

Comments
 (0)