feat: update models
This commit is contained in:
@@ -41,17 +41,22 @@ func (ctl *orders) Refund(ctx fiber.Ctx, id int64) error {
|
||||
return err
|
||||
}
|
||||
|
||||
user, err := model.UsersModel.GetByID(ctx.Context(), order.UserID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
post, err := model.PostsModel.GetByID(ctx.Context(), order.PostID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if order.PaymentMethod == "balance" {
|
||||
if err := model.UsersModel.AddBalance(ctx.Context(), order.UserID, order.Meta.Data.CostBalance); err != nil {
|
||||
if err := user.AddBalance(ctx.Context(), order.Meta.Data.CostBalance); err != nil {
|
||||
return errors.Wrap(err, "add balance failed")
|
||||
}
|
||||
|
||||
if err := model.UsersModel.RevokePosts(ctx.Context(), order.UserID, order.PostID); err != nil {
|
||||
if err := user.RevokePosts(ctx.Context(), order.PostID); err != nil {
|
||||
return errors.Wrap(err, "revoke posts failed")
|
||||
}
|
||||
|
||||
|
||||
@@ -51,5 +51,9 @@ type UserBalance struct {
|
||||
// @Bind id path
|
||||
// @Bind balance body
|
||||
func (ctl *users) Balance(ctx fiber.Ctx, id int64, balance *UserBalance) error {
|
||||
return model.UsersModel.AddBalance(ctx.Context(), id, balance.Balance)
|
||||
user, err := model.UsersModel.GetByID(ctx.Context(), id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return user.SetBalance(ctx.Context(), balance.Balance)
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ func (ctl *posts) List(ctx fiber.Ctx, pagination *requests.Pagination, query *Li
|
||||
|
||||
postIds := lo.Map(pager.Items.([]model.Posts), func(item model.Posts, _ int) int64 { return item.ID })
|
||||
if len(postIds) > 0 {
|
||||
userBoughtIds, err := model.UsersModel.BatchCheckHasBought(ctx.Context(), user.ID, postIds)
|
||||
userBoughtIds, err := user.BatchCheckHasBought(ctx.Context(), postIds)
|
||||
if err != nil {
|
||||
log.WithError(err).Errorf("BatchCheckHasBought err: %v", err)
|
||||
}
|
||||
@@ -124,7 +124,7 @@ func (ctl *posts) Show(ctx fiber.Ctx, id int64, user *model.Users) (*PostItem, e
|
||||
return nil, err
|
||||
}
|
||||
|
||||
bought, err := model.UsersModel.HasBought(ctx.Context(), user.ID, post.ID)
|
||||
bought, err := user.HasBought(ctx.Context(), post.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -173,7 +173,7 @@ func (ctl *posts) Play(ctx fiber.Ctx, id int64, user *model.Users) (*PlayUrl, er
|
||||
// }, nil
|
||||
|
||||
preview := false
|
||||
bought, err := model.UsersModel.HasBought(ctx.Context(), user.ID, id)
|
||||
bought, err := user.HasBought(ctx.Context(), id)
|
||||
if !bought || err != nil {
|
||||
preview = true
|
||||
}
|
||||
@@ -270,7 +270,7 @@ func (ctl *posts) Mine(ctx fiber.Ctx, pagination *requests.Pagination, query *Li
|
||||
// @Bind id path
|
||||
// @Bind user local
|
||||
func (ctl *posts) Buy(ctx fiber.Ctx, id int64, user *model.Users) (*wechat.JSAPIPayParams, error) {
|
||||
bought, err := model.UsersModel.HasBought(ctx.Context(), user.ID, id)
|
||||
bought, err := user.HasBought(ctx.Context(), id)
|
||||
if err != nil {
|
||||
return nil, errors.New("查询购买失败")
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ func (ctl *users) Update(ctx fiber.Ctx, user *model.Users, form *ProfileForm) er
|
||||
return fiber.NewError(fiber.StatusBadRequest, "Username cannot be empty")
|
||||
}
|
||||
|
||||
if err := model.UsersModel.UpdateUsername(ctx.Context(), user.ID, username); err != nil {
|
||||
if err := user.SetUsername(ctx.Context(), username); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -40,7 +40,7 @@ func (ctl *wechats) GetJsSDK(ctx fiber.Ctx, url string, user *model.Users) (*wec
|
||||
oldToken.StableAccessToken = stableToken.AccessToken
|
||||
oldToken.StableExpiresAt = time.Now().Add(time.Second * time.Duration(stableToken.ExpiresIn))
|
||||
|
||||
if err := model.UsersModel.UpdateUserToken(ctx.Context(), user.ID, oldToken); err != nil {
|
||||
if err := user.UpdateUserToken(ctx.Context(), oldToken); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
user.AuthToken.Data = oldToken
|
||||
|
||||
Reference in New Issue
Block a user