aa
This commit is contained in:
@@ -2153,7 +2153,7 @@ func GetCoupons(ctx *jxcontext.Context, couponType int, couponStatuss, storeIDs
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
)
|
||||
coupons, err = dao.GetCoupons(db, couponType, couponStatuss, storeIDs, keyword)
|
||||
coupons, err = dao.GetCoupons(db, couponType, couponStatuss, storeIDs, "", "", keyword)
|
||||
return coupons, err
|
||||
}
|
||||
|
||||
@@ -2265,3 +2265,36 @@ func UpdateCoupons(ctx *jxcontext.Context, payload map[string]interface{}, store
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func ReceiveCoupons(ctx *jxcontext.Context, couponID int) (err error) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
userID = ctx.GetUserID()
|
||||
coupons = &model.Coupons{}
|
||||
)
|
||||
coupons.ID = int64(couponID)
|
||||
dao.GetEntity(db, coupons)
|
||||
if coupons == nil {
|
||||
return fmt.Errorf("领取优惠券失败!")
|
||||
}
|
||||
if coupons.CouponStatus != model.CouponStatusNormal {
|
||||
return fmt.Errorf("优惠券状态有误,领取失败!")
|
||||
}
|
||||
if time.Now().Sub(coupons.EndAt) > 0 {
|
||||
return fmt.Errorf("优惠券已过期,领取失败!")
|
||||
}
|
||||
if time.Now().Sub(coupons.BeginAt) < 0 {
|
||||
return fmt.Errorf("优惠券未生效,领取失败!")
|
||||
}
|
||||
userCoupons, _ := dao.GetUserCoupons(db, []int{couponID}, []string{userID}, nil, model.CouponStatusNormal)
|
||||
if len(userCoupons) > 0 {
|
||||
return fmt.Errorf("您已经领取过该优惠券了,请使用后再领取!")
|
||||
}
|
||||
userCoupon := &model.UserCoupons{
|
||||
CouponID: couponID,
|
||||
UserID: userID,
|
||||
}
|
||||
dao.WrapAddIDCULEntity(userCoupon, ctx.GetUserName())
|
||||
err = dao.CreateEntity(db, userCoupon)
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user