fix(log): rename OrderId to OrderNo for consistency in balance logging
This commit is contained in:
parent
d0d03e724e
commit
1d878592ed
@ -758,7 +758,7 @@ type (
|
||||
Type uint16 `json:"type"`
|
||||
UserId int64 `json:"user_id"`
|
||||
Amount int64 `json:"amount"`
|
||||
OrderId int64 `json:"order_id,omitempty"`
|
||||
OrderNo string `json:"order_no,omitempty"`
|
||||
Balance int64 `json:"balance"`
|
||||
Timestamp int64 `json:"timestamp"`
|
||||
}
|
||||
|
||||
@ -51,7 +51,7 @@ func (l *FilterBalanceLogLogic) FilterBalanceLog(req *types.FilterBalanceLogRequ
|
||||
UserId: datum.ObjectID,
|
||||
Amount: content.Amount,
|
||||
Type: content.Type,
|
||||
OrderId: content.OrderId,
|
||||
OrderNo: content.OrderNo,
|
||||
Balance: content.Balance,
|
||||
Timestamp: content.Timestamp,
|
||||
})
|
||||
|
||||
@ -413,7 +413,7 @@ func (l *PurchaseCheckoutLogic) balancePayment(u *user.User, o *order.Order) err
|
||||
balanceLog := &log.Balance{
|
||||
Amount: balanceUsed,
|
||||
Type: log.BalanceTypePayment, // Type 3 represents payment deduction
|
||||
OrderId: o.Id,
|
||||
OrderNo: o.OrderNo,
|
||||
Balance: userInfo.Balance,
|
||||
Timestamp: time.Now().UnixMilli(),
|
||||
}
|
||||
|
||||
@ -62,7 +62,7 @@ func (l *QueryUserBalanceLogLogic) QueryUserBalanceLog() (resp *types.QueryUserB
|
||||
UserId: datum.ObjectID,
|
||||
Amount: content.Amount,
|
||||
Type: content.Type,
|
||||
OrderId: content.OrderId,
|
||||
OrderNo: content.OrderNo,
|
||||
Balance: content.Balance,
|
||||
Timestamp: content.Timestamp,
|
||||
})
|
||||
|
||||
@ -6,6 +6,7 @@ import (
|
||||
|
||||
"github.com/perfect-panel/server/internal/model/log"
|
||||
"github.com/perfect-panel/server/pkg/constant"
|
||||
"github.com/perfect-panel/server/pkg/tool"
|
||||
"github.com/perfect-panel/server/pkg/xerr"
|
||||
"github.com/pkg/errors"
|
||||
|
||||
@ -48,6 +49,14 @@ func (l *UnsubscribeLogic) Unsubscribe(req *types.UnsubscribeRequest) error {
|
||||
return errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "FindOneSubscribe failed: %v", err.Error())
|
||||
}
|
||||
|
||||
activate := []uint8{0, 1, 2}
|
||||
|
||||
if !tool.Contains(activate, userSub.Status) {
|
||||
// Only active (2) or paused (5) subscriptions can be cancelled
|
||||
l.Errorw("Subscription status invalid for cancellation", logger.Field("userSubscribeId", userSub.Id), logger.Field("status", userSub.Status))
|
||||
return errors.Wrapf(xerr.NewErrCode(xerr.ERROR), "Subscription status invalid for cancellation")
|
||||
}
|
||||
|
||||
// Calculate the remaining amount to refund based on unused subscription time/traffic
|
||||
remainingAmount, err := CalculateRemainingAmount(l.ctx, l.svcCtx, req.Id)
|
||||
if err != nil {
|
||||
@ -57,12 +66,8 @@ func (l *UnsubscribeLogic) Unsubscribe(req *types.UnsubscribeRequest) error {
|
||||
// Process unsubscription in a database transaction to ensure data consistency
|
||||
err = l.svcCtx.UserModel.Transaction(l.ctx, func(db *gorm.DB) error {
|
||||
// Find and update subscription status to cancelled (status = 4)
|
||||
var userSub user.Subscribe
|
||||
if err = db.Model(&user.Subscribe{}).Where("id = ?", req.Id).First(&userSub).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
userSub.Status = 4 // Set status to cancelled
|
||||
if err = l.svcCtx.UserModel.UpdateSubscribe(l.ctx, &userSub); err != nil {
|
||||
if err = l.svcCtx.UserModel.UpdateSubscribe(l.ctx, userSub); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -94,7 +99,7 @@ func (l *UnsubscribeLogic) Unsubscribe(req *types.UnsubscribeRequest) error {
|
||||
balanceRefundAmount := balance - u.Balance
|
||||
if balanceRefundAmount > 0 {
|
||||
balanceLog := log.Balance{
|
||||
OrderId: userSub.OrderId,
|
||||
OrderNo: orderInfo.OrderNo,
|
||||
Amount: balanceRefundAmount,
|
||||
Type: log.BalanceTypeRefund, // Type 4 represents refund transaction
|
||||
Balance: balance,
|
||||
|
||||
@ -225,7 +225,7 @@ func (r *ResetSubscribe) Unmarshal(data []byte) error {
|
||||
type Balance struct {
|
||||
Type uint16 `json:"type"`
|
||||
Amount int64 `json:"amount"`
|
||||
OrderId int64 `json:"order_id,omitempty"`
|
||||
OrderNo string `json:"order_no,omitempty"`
|
||||
Balance int64 `json:"balance"`
|
||||
Timestamp int64 `json:"timestamp"`
|
||||
}
|
||||
|
||||
@ -60,7 +60,13 @@ func (m *defaultUserModel) FindOneSubscribe(ctx context.Context, id int64) (*Sub
|
||||
func (m *defaultUserModel) FindUsersSubscribeBySubscribeId(ctx context.Context, subscribeId int64) ([]*Subscribe, error) {
|
||||
var data []*Subscribe
|
||||
err := m.QueryNoCacheCtx(ctx, &data, func(conn *gorm.DB, v interface{}) error {
|
||||
return conn.Model(&Subscribe{}).Where("subscribe_id = ? AND `status` IN ?", subscribeId, []int64{1, 0}).Find(&data).Error
|
||||
err := conn.Model(&Subscribe{}).Where("subscribe_id = ? AND `status` IN ?", subscribeId, []int64{1, 0}).Find(v).Error
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// update user subscribe status
|
||||
return conn.Model(&Subscribe{}).Where("subscribe_id = ? AND `status` = ?", subscribeId, 0).Update("status", 1).Error
|
||||
})
|
||||
return data, err
|
||||
}
|
||||
|
||||
@ -132,7 +132,7 @@ type BalanceLog struct {
|
||||
Type uint16 `json:"type"`
|
||||
UserId int64 `json:"user_id"`
|
||||
Amount int64 `json:"amount"`
|
||||
OrderId int64 `json:"order_id,omitempty"`
|
||||
OrderNo string `json:"order_no,omitempty"`
|
||||
Balance int64 `json:"balance"`
|
||||
Timestamp int64 `json:"timestamp"`
|
||||
}
|
||||
|
||||
@ -624,7 +624,7 @@ func (l *ActivateOrderLogic) Recharge(ctx context.Context, orderInfo *order.Orde
|
||||
balanceLog := &log.Balance{
|
||||
Amount: orderInfo.Price,
|
||||
Type: CommissionTypeRecharge,
|
||||
OrderId: orderInfo.Id,
|
||||
OrderNo: orderInfo.OrderNo,
|
||||
Balance: userInfo.Balance,
|
||||
Timestamp: time.Now().UnixMilli(),
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user