aa
This commit is contained in:
@@ -41,6 +41,7 @@ const (
|
||||
CouponStatusRe = -2 //优惠券状态还没生效
|
||||
CouponStatusOverdue = -1 //已过期
|
||||
CouponStatusNormal = 0 //正常
|
||||
CouponStatusDeleted = -4 //被删了
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -67,6 +68,7 @@ var (
|
||||
CouponStatusOverdue: "已过期",
|
||||
CouponStatusNormal: "正常",
|
||||
UserCouponStatusOverdue: "已被使用",
|
||||
CouponStatusDeleted: "已删除",
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@@ -2211,6 +2211,57 @@ func AddCoupons(ctx *jxcontext.Context, coupons *model.Coupons, count int, store
|
||||
return err
|
||||
}
|
||||
|
||||
func UpdateCoupons(ctx *jxcontext.Context, payload map[string]interface{}, storeIDs []int) (err error) {
|
||||
func UpdateCoupons(ctx *jxcontext.Context, payload map[string]interface{}, storeIDs []int, isDel bool) (err error) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
coupons = &model.Coupons{}
|
||||
)
|
||||
coupons.ID = utils.MustInterface2Int64(payload["id"])
|
||||
dao.GetEntity(db, coupons)
|
||||
if isDel {
|
||||
coupons.CouponStatus = model.CouponStatusDeleted
|
||||
coupons.UpdatedAt = time.Now()
|
||||
coupons.LastOperator = ctx.GetUserName()
|
||||
dao.UpdateEntity(db, coupons, "CouponStatus", "UpdatedAt", "LastOperator")
|
||||
} else {
|
||||
valid := dao.StrictMakeMapByStructObject(payload, coupons, ctx.GetUserName())
|
||||
if len(valid) > 0 {
|
||||
dao.Begin(db)
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
dao.Rollback(db)
|
||||
panic(r)
|
||||
}
|
||||
}()
|
||||
if valid["isAll"] != nil {
|
||||
if utils.MustInterface2Int64(valid["isAll"]) == model.NO && len(storeIDs) == 0 {
|
||||
return fmt.Errorf("改成全国不生效要选门店!")
|
||||
}
|
||||
}
|
||||
if _, err = dao.UpdateEntityByKV(db, coupons, valid, nil); err != nil {
|
||||
dao.Rollback(db)
|
||||
return err
|
||||
}
|
||||
if valid["isAll"] != nil {
|
||||
storeCouponss, _ := dao.GetStoreCoupons(db, []int{int(coupons.ID)}, nil)
|
||||
for _, v := range storeCouponss {
|
||||
v.DeletedAt = time.Now()
|
||||
v.LastOperator = ctx.GetUserName()
|
||||
dao.UpdateEntity(db, v, "DeletoedAt", "LastOperator")
|
||||
}
|
||||
if utils.MustInterface2Int64(valid["isAll"]) == model.NO {
|
||||
for _, v := range storeIDs {
|
||||
storeCoupons := &model.StoreCoupons{
|
||||
StoreID: v,
|
||||
CouponID: int(coupons.ID),
|
||||
}
|
||||
dao.WrapAddIDCULEntity(storeCoupons, ctx.GetUserName())
|
||||
dao.CreateEntity(db, storeCoupons)
|
||||
}
|
||||
}
|
||||
}
|
||||
dao.Commit(db)
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user