feat: update

This commit is contained in:
Rogee
2025-05-23 20:07:34 +08:00
parent 9b38699764
commit 57cb0a750b
53 changed files with 741 additions and 982 deletions

View File

@@ -5,7 +5,7 @@ import (
"fmt"
"time"
"quyun/app/models"
"quyun/app/model"
"quyun/database/fields"
"github.com/pkg/errors"
@@ -45,7 +45,7 @@ func (w *BalancePayNotifyWorker) Work(ctx context.Context, job *Job[BalancePayNo
log.Infof("[Start] Working on job with strings: %+v", job.Args)
defer log.Infof("[End] Finished %s", job.Args.Kind())
order, err := models.Orders.GetByOrderNo(context.Background(), job.Args.OrderNo)
order, err := model.OrdersModel.GetByOrderNo(context.Background(), job.Args.OrderNo)
if err != nil {
log.Errorf("GetByOrderNo error:%v", err)
return err
@@ -56,7 +56,7 @@ func (w *BalancePayNotifyWorker) Work(ctx context.Context, job *Job[BalancePayNo
return JobCancel(fmt.Errorf("Order already paid, currently status: %d", order.Status))
}
user, err := models.Users.GetByID(context.Background(), order.UserID)
user, err := model.UsersModel.GetByID(context.Background(), order.UserID)
if err != nil {
log.Errorf("GetByID error:%v", err)
return errors.Wrap(err, "get user error")
@@ -75,25 +75,25 @@ func (w *BalancePayNotifyWorker) Work(ctx context.Context, job *Job[BalancePayNo
}
log.Infof("Updated order details: %+v", order)
tx, err := models.Transaction(ctx)
tx, err := model.Transaction(ctx)
if err != nil {
return errors.Wrap(err, "Transaction error")
}
defer tx.Rollback()
// update user balance
err = models.Users.SetBalance(ctx, user.ID, user.Balance-payPrice)
err = model.UsersModel.SetBalance(ctx, user.ID, user.Balance-payPrice)
if err != nil {
log.WithError(err).Error("SetBalance error")
return JobCancel(errors.Wrap(err, "set user balance failed"))
}
if err := models.Users.BuyPosts(context.Background(), order.UserID, order.PostID, order.Price); err != nil {
if err := model.UsersModel.BuyPosts(context.Background(), order.UserID, order.PostID, order.Price); err != nil {
log.Errorf("BuyPosts error:%v", err)
return errors.Wrap(err, "BuyPosts error")
}
if err := models.Orders.Update(context.Background(), order); err != nil {
if err := model.OrdersModel.Update(context.Background(), order); err != nil {
log.Errorf("Update order error:%v", err)
return errors.Wrap(err, "Update order error")
}