完善用户资料发放优惠卷
This commit is contained in:
parent
94d25b4ec4
commit
7285da9a79
@ -7,6 +7,7 @@ import (
|
|||||||
"hepa-calc-api/api/model"
|
"hepa-calc-api/api/model"
|
||||||
"hepa-calc-api/api/requests"
|
"hepa-calc-api/api/requests"
|
||||||
"hepa-calc-api/api/responses"
|
"hepa-calc-api/api/responses"
|
||||||
|
"hepa-calc-api/api/service"
|
||||||
"hepa-calc-api/extend/app"
|
"hepa-calc-api/extend/app"
|
||||||
"hepa-calc-api/global"
|
"hepa-calc-api/global"
|
||||||
"hepa-calc-api/utils"
|
"hepa-calc-api/utils"
|
||||||
@ -218,6 +219,15 @@ func (r *UserCase) PutUserCase(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 发放用户完善资料优惠卷
|
||||||
|
couponService := service.CouponService{}
|
||||||
|
res := couponService.GrantFillUserInfoCoupon(tx, userId)
|
||||||
|
if res != true {
|
||||||
|
tx.Rollback()
|
||||||
|
responses.FailWithMessage("操作失败", c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// app数据
|
// app数据
|
||||||
appData.PatientUuid = user.AppIden
|
appData.PatientUuid = user.AppIden
|
||||||
_, err = app.UpdateUserCase(appData)
|
_, err = app.UpdateUserCase(appData)
|
||||||
|
|||||||
@ -133,3 +133,15 @@ func (r *CouponDao) Dec(tx *gorm.DB, couponId int64, field string, numeral int)
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetFillUserInfoCouponList 发放用户完善资料优惠卷列表
|
||||||
|
func (r *CouponDao) GetFillUserInfoCouponList() (m []*model.Coupon, err error) {
|
||||||
|
err = global.Db.
|
||||||
|
Where("coupon_status = ?", 1).
|
||||||
|
Where("distribution_object in ?", []int{1, 4}).
|
||||||
|
Find(&m).Error
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return m, nil
|
||||||
|
}
|
||||||
|
|||||||
@ -12,6 +12,7 @@ type Coupon struct {
|
|||||||
CouponType int `gorm:"column:coupon_type;type:varchar(255);comment:优惠卷类型(1:无门槛 2:满减)" json:"coupon_type"`
|
CouponType int `gorm:"column:coupon_type;type:varchar(255);comment:优惠卷类型(1:无门槛 2:满减)" json:"coupon_type"`
|
||||||
CouponStatus int `gorm:"column:coupon_status;type:tinyint(1);default:1;comment:状态(1:正常 2:强制失效 3:结束 4:删除)" json:"coupon_status"`
|
CouponStatus int `gorm:"column:coupon_status;type:tinyint(1);default:1;comment:状态(1:正常 2:强制失效 3:结束 4:删除)" json:"coupon_status"`
|
||||||
ApplicationScope int `gorm:"column:application_scope;type:tinyint(1);default:1;comment:适用范围(1:全场通用 2:单项 3:会员)" json:"application_scope"`
|
ApplicationScope int `gorm:"column:application_scope;type:tinyint(1);default:1;comment:适用范围(1:全场通用 2:单项 3:会员)" json:"application_scope"`
|
||||||
|
DistributionObject int `gorm:"column:distribution_object;type:tinyint(1);default:1;comment:发放对象(1:全部用户 2:新注册用户 3:会员 4:完善资料)" json:"distribution_object"`
|
||||||
IsMutex int `gorm:"column:is_mutex;type:tinyint(1);default:1;comment:是否互斥(0:否 1:是)互斥情况下无法和其他优惠卷同时使用" json:"is_mutex"`
|
IsMutex int `gorm:"column:is_mutex;type:tinyint(1);default:1;comment:是否互斥(0:否 1:是)互斥情况下无法和其他优惠卷同时使用" json:"is_mutex"`
|
||||||
CouponCount int `gorm:"column:coupon_count;type:int(10);default:1;comment:发放数量;NOT NULL" json:"coupon_count"`
|
CouponCount int `gorm:"column:coupon_count;type:int(10);default:1;comment:发放数量;NOT NULL" json:"coupon_count"`
|
||||||
CouponTakeCount int `gorm:"column:coupon_take_count;type:int(10);comment:已领取数量" json:"coupon_take_count"`
|
CouponTakeCount int `gorm:"column:coupon_take_count;type:int(10);comment:已领取数量" json:"coupon_take_count"`
|
||||||
|
|||||||
@ -6,6 +6,7 @@ import (
|
|||||||
"hepa-calc-api/api/dao"
|
"hepa-calc-api/api/dao"
|
||||||
"hepa-calc-api/api/model"
|
"hepa-calc-api/api/model"
|
||||||
"hepa-calc-api/extend/rabbitMq"
|
"hepa-calc-api/extend/rabbitMq"
|
||||||
|
"hepa-calc-api/utils"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -13,6 +14,7 @@ type CouponService struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GrantUserCoupon 发放优惠卷
|
// GrantUserCoupon 发放优惠卷
|
||||||
|
// grantQuantity 发放数量
|
||||||
func (r *CouponService) GrantUserCoupon(tx *gorm.DB, userId, couponId int64, grantQuantity int) bool {
|
func (r *CouponService) GrantUserCoupon(tx *gorm.DB, userId, couponId int64, grantQuantity int) bool {
|
||||||
// 获取优惠卷数据
|
// 获取优惠卷数据
|
||||||
couponDao := dao.CouponDao{}
|
couponDao := dao.CouponDao{}
|
||||||
@ -31,7 +33,7 @@ func (r *CouponService) GrantUserCoupon(tx *gorm.DB, userId, couponId int64, gra
|
|||||||
now := time.Now().Add(10 * 60 * time.Second)
|
now := time.Now().Add(10 * 60 * time.Second)
|
||||||
validEndTime := time.Time(*coupon.ValidEndTime)
|
validEndTime := time.Time(*coupon.ValidEndTime)
|
||||||
if validEndTime.Before(now) {
|
if validEndTime.Before(now) {
|
||||||
return false
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,8 +48,18 @@ func (r *CouponService) GrantUserCoupon(tx *gorm.DB, userId, couponId int64, gra
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 检测用户是否已有该优惠卷
|
||||||
|
userCouponDao := dao.UserCouponDao{}
|
||||||
|
maps := make(map[string]interface{})
|
||||||
|
maps["user_id"] = userId
|
||||||
|
maps["coupon_id"] = coupon.CouponId
|
||||||
|
userCoupon, _ := userCouponDao.GetUserCoupon(maps)
|
||||||
|
if userCoupon != nil {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
// 添加用户优惠卷表
|
// 添加用户优惠卷表
|
||||||
userCoupon := &model.UserCoupon{
|
userCoupon = &model.UserCoupon{
|
||||||
UserId: userId,
|
UserId: userId,
|
||||||
CouponId: couponId,
|
CouponId: couponId,
|
||||||
UserCouponStatus: 0,
|
UserCouponStatus: 0,
|
||||||
@ -67,7 +79,6 @@ func (r *CouponService) GrantUserCoupon(tx *gorm.DB, userId, couponId int64, gra
|
|||||||
userCoupon.ValidEndTime = &validEndTime
|
userCoupon.ValidEndTime = &validEndTime
|
||||||
}
|
}
|
||||||
|
|
||||||
userCouponDao := dao.UserCouponDao{}
|
|
||||||
userCoupon, err = userCouponDao.AddUserCoupon(tx, userCoupon)
|
userCoupon, err = userCouponDao.AddUserCoupon(tx, userCoupon)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false
|
return false
|
||||||
@ -114,3 +125,23 @@ func (r *CouponService) GrantUserCoupon(tx *gorm.DB, userId, couponId int64, gra
|
|||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GrantFillUserInfoCoupon 发放用户完善资料优惠卷
|
||||||
|
func (r *CouponService) GrantFillUserInfoCoupon(tx *gorm.DB, userId int64) bool {
|
||||||
|
// 发放用户完善资料优惠卷
|
||||||
|
couponDao := dao.CouponDao{}
|
||||||
|
coupons, _ := couponDao.GetFillUserInfoCouponList()
|
||||||
|
if len(coupons) == 0 {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// 发放优惠卷
|
||||||
|
for _, coupon := range coupons {
|
||||||
|
res := r.GrantUserCoupon(tx, userId, coupon.CouponId, 1)
|
||||||
|
if res == false {
|
||||||
|
utils.LogJsonErr("发放用户完善资料优惠卷失败:", nil)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user