refreshcoupon
This commit is contained in:
@@ -271,6 +271,10 @@ func Init() {
|
||||
ScheduleTimerFunc("RefreshUserMemberStatus", func() {
|
||||
cms.RefreshUserMemberStatus(jxcontext.AdminCtx)
|
||||
}, updateActStatusTimeList)
|
||||
//刷优惠券状态
|
||||
ScheduleTimerFunc("RefreshCouponsStatus", func() {
|
||||
localjx.RefreshCouponsStatus(jxcontext.AdminCtx)
|
||||
}, updateActStatusTimeList)
|
||||
}
|
||||
ScheduleTimerFunc("AutoSaleStoreSku", func() {
|
||||
cms.AutoSaleStoreSku(jxcontext.AdminCtx, nil, false)
|
||||
|
||||
@@ -45,7 +45,7 @@ const (
|
||||
)
|
||||
|
||||
const (
|
||||
UserCouponStatusOverdue = 1 // 已被使用
|
||||
UserCouponStatusUsed = 1 // 已被使用
|
||||
)
|
||||
|
||||
var (
|
||||
|
||||
@@ -21,6 +21,7 @@ import (
|
||||
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/ddmsg"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/netprinter"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/tasksch"
|
||||
|
||||
"git.rosy.net.cn/baseapi/platformapi/dingdingapi"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
@@ -2298,3 +2299,57 @@ func ReceiveCoupons(ctx *jxcontext.Context, couponID int) (err error) {
|
||||
err = dao.CreateEntity(db, userCoupon)
|
||||
return err
|
||||
}
|
||||
|
||||
func RefreshCouponsStatus(ctx *jxcontext.Context) (err error) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
)
|
||||
task := tasksch.NewParallelTask("RefreshCouponsStatus", tasksch.NewParallelConfig().SetParallelCount(1).SetIsContinueWhenError(true), ctx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
step := batchItemList[0].(int)
|
||||
switch step {
|
||||
case 0:
|
||||
//还没生效的弄成生效
|
||||
coupons, _ := dao.GetCoupons(db, 0, []int{model.CouponStatusRe}, nil, "", "", "")
|
||||
task := tasksch.NewParallelTask("RefreshCouponsStatusRe", tasksch.NewParallelConfig().SetParallelCount(1).SetIsContinueWhenError(true), ctx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
coupon := batchItemList[0].(*model.Coupons)
|
||||
if time.Now().Sub(coupon.BeginAt) > 0 {
|
||||
coupon.CouponStatus = model.CouponStatusNormal
|
||||
coupon.UpdatedAt = time.Now()
|
||||
dao.UpdateEntity(db, coupon, "CouponStatus", "UpdatedAt")
|
||||
}
|
||||
return retVal, err
|
||||
}, coupons)
|
||||
tasksch.HandleTask(task, nil, true).Run()
|
||||
_, err = task.GetResult(0)
|
||||
case 1:
|
||||
//过期的弄成过期
|
||||
coupons, _ := dao.GetCoupons(db, 0, []int{model.CouponStatusNormal}, nil, "", "", "")
|
||||
task := tasksch.NewParallelTask("RefreshCouponsStatusNormal", tasksch.NewParallelConfig().SetParallelCount(1).SetIsContinueWhenError(true), ctx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
coupon := batchItemList[0].(*model.Coupons)
|
||||
if time.Now().Sub(coupon.EndAt) > 0 {
|
||||
coupon.CouponStatus = model.CouponStatusOverdue
|
||||
coupon.UpdatedAt = time.Now()
|
||||
dao.UpdateEntity(db, coupon, "CouponStatus", "UpdatedAt")
|
||||
//用户手上的优惠券也要弄成过期
|
||||
if userCoupons, err := dao.GetUserCoupons(db, couponIDs, userIDs, mobiles, userStatus); err == nil {
|
||||
for _, v := range userCoupons {
|
||||
v.UserCouponStatus = model.CouponStatusOverdue
|
||||
v.UpdatedAt = time.Now()
|
||||
dao.UpdateEntity(db, v, "UserCouponStatus", "UpdatedAt")
|
||||
}
|
||||
}
|
||||
}
|
||||
return retVal, err
|
||||
}, coupons)
|
||||
tasksch.HandleTask(task, nil, true).Run()
|
||||
_, err = task.GetResult(0)
|
||||
}
|
||||
return retVal, err
|
||||
}, []int{0, 1})
|
||||
tasksch.HandleTask(task, nil, true).Run()
|
||||
task.GetID()
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user