|
|
@ -1,6 +1,7 @@ |
|
|
|
package coupon |
|
|
|
|
|
|
|
import ( |
|
|
|
"CouponBackendGo/api/v1/coupon" |
|
|
|
"CouponBackendGo/internal/dao" |
|
|
|
"CouponBackendGo/internal/model/do" |
|
|
|
"CouponBackendGo/internal/model/dto" |
|
|
@ -112,6 +113,9 @@ func (s *sCoupon) DeleteCoupon(ctx context.Context, id int) (err error) { |
|
|
|
_, err = dao.Coupon.Ctx(ctx).Data(do.Coupon{ |
|
|
|
Deleted: 1, |
|
|
|
}).WherePri(id).Update() |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
|
|
|
|
// 软删除数据后,删除所有缓存
|
|
|
|
keys, err := g.Redis().Keys(ctx, "*-* couponlist") |
|
|
@ -121,3 +125,24 @@ func (s *sCoupon) DeleteCoupon(ctx context.Context, id int) (err error) { |
|
|
|
|
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
func (s *sCoupon) InsertCoupon(ctx context.Context, req *coupon.InsertCouponReq) (err error) { |
|
|
|
_, err = dao.Coupon.Ctx(ctx).Data(do.Coupon{ |
|
|
|
Title: req.Title, |
|
|
|
Cover: req.Image, |
|
|
|
ImgUrl: req.Image, |
|
|
|
StartTime: req.StartTime.Unix(), |
|
|
|
EndTime: req.EndTime.Unix(), |
|
|
|
}).Insert() |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
|
|
|
|
// 新增数据后,删除所有缓存
|
|
|
|
keys, err := g.Redis().Keys(ctx, "*-* couponlist") |
|
|
|
if len(keys) > 0 { |
|
|
|
_, err = g.Redis().Del(ctx, keys...) |
|
|
|
} |
|
|
|
|
|
|
|
return |
|
|
|
} |