feat: 更新服务方法,显式接受用户ID参数,简化上下文调用
This commit is contained in:
@@ -7,7 +7,6 @@ import (
|
||||
"quyun/v2/app/errorx"
|
||||
coupon_dto "quyun/v2/app/http/v1/dto"
|
||||
"quyun/v2/database/models"
|
||||
"quyun/v2/pkg/consts"
|
||||
|
||||
"github.com/spf13/cast"
|
||||
)
|
||||
@@ -15,7 +14,11 @@ import (
|
||||
// @provider
|
||||
type coupon struct{}
|
||||
|
||||
func (s *coupon) ListUserCoupons(ctx context.Context, userID int64, status string) ([]coupon_dto.UserCouponItem, error) {
|
||||
func (s *coupon) ListUserCoupons(
|
||||
ctx context.Context,
|
||||
userID int64,
|
||||
status string,
|
||||
) ([]coupon_dto.UserCouponItem, error) {
|
||||
if userID == 0 {
|
||||
return nil, errorx.ErrUnauthorized
|
||||
}
|
||||
@@ -111,11 +114,13 @@ func (s *coupon) Validate(ctx context.Context, userID, userCouponID, amount int6
|
||||
func (s *coupon) MarkUsed(ctx context.Context, tx *models.Query, userCouponID, orderID int64) error {
|
||||
now := time.Now()
|
||||
// Update User Coupon
|
||||
info, err := tx.UserCoupon.WithContext(ctx).Where(tx.UserCoupon.ID.Eq(userCouponID), tx.UserCoupon.Status.Eq("unused")).Updates(&models.UserCoupon{
|
||||
Status: "used",
|
||||
OrderID: orderID,
|
||||
UsedAt: now,
|
||||
})
|
||||
info, err := tx.UserCoupon.WithContext(ctx).
|
||||
Where(tx.UserCoupon.ID.Eq(userCouponID), tx.UserCoupon.Status.Eq("unused")).
|
||||
Updates(&models.UserCoupon{
|
||||
Status: "used",
|
||||
OrderID: orderID,
|
||||
UsedAt: now,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user