feat: update
This commit is contained in:
@@ -5,7 +5,7 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"quyun/app/models"
|
||||
"quyun/app/model"
|
||||
"quyun/database/fields"
|
||||
|
||||
"github.com/go-pay/gopay/wechat/v3"
|
||||
@@ -53,7 +53,7 @@ func (w *WechatPayNotifyWorker) Work(ctx context.Context, job *Job[WechatPayNoti
|
||||
return JobCancel(errors.New("TradeState is not SUCCESS"))
|
||||
}
|
||||
|
||||
order, err := models.Orders.GetByOrderNo(context.Background(), notify.OutTradeNo)
|
||||
order, err := model.OrdersModel.GetByOrderNo(context.Background(), notify.OutTradeNo)
|
||||
if err != nil {
|
||||
log.Errorf("GetByOrderNo error:%v", err)
|
||||
return err
|
||||
@@ -64,7 +64,7 @@ func (w *WechatPayNotifyWorker) Work(ctx context.Context, job *Job[WechatPayNoti
|
||||
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 {
|
||||
return errors.Wrapf(err, "get user by id(%d) failed", order.UserID)
|
||||
}
|
||||
@@ -85,25 +85,25 @@ func (w *WechatPayNotifyWorker) Work(ctx context.Context, job *Job[WechatPayNoti
|
||||
order.Meta = fields.ToJson(meta)
|
||||
|
||||
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-meta.CostBalance)
|
||||
err = model.UsersModel.SetBalance(ctx, user.ID, user.Balance-meta.CostBalance)
|
||||
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")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user