chore: stabilize lint and verify builds

This commit is contained in:
2026-02-06 11:51:32 +08:00
parent edede17880
commit 1782f64417
114 changed files with 3032 additions and 1345 deletions

View File

@@ -77,6 +77,7 @@ func (s *coupon) ListUserCoupons(
res = append(res, s.composeUserCouponItem(v, c, finalStatus))
}
return res, nil
}
@@ -126,6 +127,7 @@ func (s *coupon) ListAvailable(
return nil, err
}
}
continue
}
@@ -165,6 +167,7 @@ func (s *coupon) Receive(
if errors.Is(err, gorm.ErrRecordNotFound) {
return errorx.ErrRecordNotFound.WithMsg("优惠券不存在")
}
return errorx.ErrDatabaseError.WithCause(err)
}
if tenantID > 0 && coupon.TenantID != tenantID {
@@ -185,6 +188,7 @@ func (s *coupon) Receive(
if err == nil {
item := s.composeUserCouponItem(existing, coupon, existing.Status)
result = &item
return nil
}
if !errors.Is(err, gorm.ErrRecordNotFound) {
@@ -214,11 +218,13 @@ func (s *coupon) Receive(
item := s.composeUserCouponItem(uc, coupon, consts.UserCouponStatusUnused)
result = &item
return nil
})
if err != nil {
return nil, err
}
return result, nil
}
@@ -286,6 +292,7 @@ func (s *coupon) Create(
}
item := s.composeCouponItem(coupon)
return &item, nil
}
@@ -313,6 +320,7 @@ func (s *coupon) Update(
if errors.Is(err, gorm.ErrRecordNotFound) {
return errorx.ErrRecordNotFound.WithMsg("优惠券不存在")
}
return errorx.ErrDatabaseError.WithCause(err)
}
@@ -402,6 +410,7 @@ func (s *coupon) Update(
if len(updates) == 0 {
resultItem := s.composeCouponItem(coupon)
result = &resultItem
return nil
}
@@ -415,11 +424,13 @@ func (s *coupon) Update(
}
resultItem := s.composeCouponItem(updated)
result = &resultItem
return nil
})
if err != nil {
return nil, err
}
return result, nil
}
@@ -440,9 +451,11 @@ func (s *coupon) Get(
if errors.Is(err, gorm.ErrRecordNotFound) {
return nil, errorx.ErrRecordNotFound.WithMsg("优惠券不存在")
}
return nil, errorx.ErrDatabaseError.WithCause(err)
}
item := s.composeCouponItem(coupon)
return &item, nil
}
@@ -557,6 +570,7 @@ func (s *coupon) Grant(
if errors.Is(err, gorm.ErrRecordNotFound) {
return errorx.ErrRecordNotFound.WithMsg("优惠券不存在")
}
return errorx.ErrDatabaseError.WithCause(err)
}
@@ -613,11 +627,13 @@ func (s *coupon) Grant(
}
granted++
}
return nil
})
if err != nil {
return 0, err
}
return granted, nil
}
@@ -650,6 +666,7 @@ func (s *coupon) Validate(ctx context.Context, tenantID, userID, userCouponID, a
if err := s.markUserCouponExpired(ctx, uc.ID); err != nil {
return 0, err
}
return 0, errorx.ErrBusinessLogic.WithMsg("优惠券已过期")
}
@@ -685,6 +702,7 @@ func (s *coupon) MarkUsed(ctx context.Context, tx *models.Query, tenantID, userC
if errors.Is(err, gorm.ErrRecordNotFound) {
return errorx.ErrRecordNotFound.WithMsg("优惠券不存在")
}
return errorx.ErrDatabaseError.WithCause(err)
}
if uc.Status != consts.UserCouponStatusUnused {
@@ -696,6 +714,7 @@ func (s *coupon) MarkUsed(ctx context.Context, tx *models.Query, tenantID, userC
if errors.Is(err, gorm.ErrRecordNotFound) {
return errorx.ErrRecordNotFound.WithMsg("优惠券信息缺失")
}
return errorx.ErrDatabaseError.WithCause(err)
}
if tenantID > 0 && c.TenantID != tenantID {
@@ -752,6 +771,7 @@ func (s *coupon) fetchCouponMap(ctx context.Context, tenantID int64, list []*mod
for _, c := range coupons {
couponMap[c.ID] = c
}
return couponMap, nil
}
@@ -770,6 +790,7 @@ func (s *coupon) composeUserCouponItem(uc *models.UserCoupon, c *models.Coupon,
item.StartAt = s.formatTime(c.StartAt)
item.EndAt = s.formatTime(c.EndAt)
}
return item
}
@@ -801,6 +822,7 @@ func (s *coupon) markUserCouponExpired(ctx context.Context, userCouponID int64)
if err != nil {
return errorx.ErrDatabaseError.WithCause(err)
}
return nil
}
@@ -815,6 +837,7 @@ func (s *coupon) isCouponActive(c *models.Coupon, now time.Time) bool {
if !c.EndAt.IsZero() && now.After(c.EndAt) {
return false
}
return true
}
@@ -827,6 +850,7 @@ func (s *coupon) parseTime(val string) (time.Time, error) {
if err != nil {
return time.Time{}, errorx.ErrInvalidFormat.WithMsg("时间格式无效")
}
return tm, nil
}
@@ -839,6 +863,7 @@ func (s *coupon) parseCouponType(val string) (consts.CouponType, error) {
if err != nil {
return "", errorx.ErrInvalidParameter.WithMsg("优惠券类型无效")
}
return couponType, nil
}
@@ -858,6 +883,7 @@ func (s *coupon) validateCouponValue(typ consts.CouponType, value, maxDiscount i
default:
return errorx.ErrInvalidParameter.WithMsg("优惠券类型无效")
}
return nil
}
@@ -865,5 +891,6 @@ func (s *coupon) formatTime(t time.Time) string {
if t.IsZero() {
return ""
}
return t.Format(time.RFC3339)
}