This commit is contained in:
@@ -60,6 +60,65 @@ func New(
|
||||
}
|
||||
}
|
||||
|
||||
// AdminList 后台分页查询充值订单列表
|
||||
func (s *Service) AdminList(ctx context.Context, params *postgres.ListRechargeOrderParams) ([]*model.RechargeOrder, int64, error) {
|
||||
orders, total, err := s.rechargeOrderStore.List(ctx, params)
|
||||
if err != nil {
|
||||
return nil, 0, errors.Wrap(errors.CodeDatabaseError, err, "查询充值订单列表失败")
|
||||
}
|
||||
return orders, total, nil
|
||||
}
|
||||
|
||||
// AdminGet 后台查询充值订单详情(含支付记录)
|
||||
func (s *Service) AdminGet(ctx context.Context, id uint) (*model.RechargeOrder, []*model.Payment, error) {
|
||||
order, err := s.rechargeOrderStore.GetByID(ctx, id)
|
||||
if err != nil {
|
||||
if err == gorm.ErrRecordNotFound {
|
||||
return nil, nil, errors.New(errors.CodeNotFound, "充值订单不存在")
|
||||
}
|
||||
return nil, nil, errors.Wrap(errors.CodeDatabaseError, err, "查询充值订单失败")
|
||||
}
|
||||
payments, err := s.paymentStore.ListByOrderID(ctx, id, model.PaymentOrderTypeRecharge)
|
||||
if err != nil {
|
||||
return nil, nil, errors.Wrap(errors.CodeDatabaseError, err, "查询支付记录失败")
|
||||
}
|
||||
return order, payments, nil
|
||||
}
|
||||
|
||||
// Reject 驳回充值订单
|
||||
// 仅待支付订单可驳回,驳回后状态变为已驳回(终态)
|
||||
func (s *Service) Reject(ctx context.Context, id uint, rejectionReason string) error {
|
||||
order, err := s.rechargeOrderStore.GetByID(ctx, id)
|
||||
if err != nil {
|
||||
if err == gorm.ErrRecordNotFound {
|
||||
return errors.New(errors.CodeNotFound, "充值订单不存在")
|
||||
}
|
||||
return errors.Wrap(errors.CodeDatabaseError, err, "查询充值订单失败")
|
||||
}
|
||||
|
||||
if order.Status != model.RechargeOrderStatusPending {
|
||||
return errors.New(errors.CodeInvalidStatus, "仅待支付订单可驳回")
|
||||
}
|
||||
|
||||
if err := s.rechargeOrderStore.UpdateStatusWithRejection(ctx, id, rejectionReason); err != nil {
|
||||
if err == gorm.ErrRecordNotFound {
|
||||
// 并发驳回:重查状态给出明确错误
|
||||
latest, queryErr := s.rechargeOrderStore.GetByID(ctx, id)
|
||||
if queryErr == nil && latest.Status != model.RechargeOrderStatusPending {
|
||||
return errors.New(errors.CodeInvalidStatus, "仅待支付订单可驳回")
|
||||
}
|
||||
return errors.New(errors.CodeInvalidStatus, "仅待支付订单可驳回")
|
||||
}
|
||||
return errors.Wrap(errors.CodeDatabaseError, err, "驳回充值订单失败")
|
||||
}
|
||||
|
||||
s.logger.Info("充值订单驳回成功",
|
||||
zap.Uint("order_id", id),
|
||||
zap.String("rejection_reason", rejectionReason),
|
||||
)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Service) HandlePaymentCallback(ctx context.Context, paymentNo string, paymentMethod string, transactionID string) error {
|
||||
payment, err := s.paymentStore.GetByPaymentNo(ctx, paymentNo)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user