|
@@ -245,41 +245,42 @@ func BatchInsertMallUserCoupon(engine *xorm.Engine, mallCouponScheme model.MallC |
|
|
if len(tmp) == 0 { |
|
|
if len(tmp) == 0 { |
|
|
return nil |
|
|
return nil |
|
|
} |
|
|
} |
|
|
tmpData := make(map[string]interface{}) |
|
|
|
|
|
for _, v := range tmp { |
|
|
for _, v := range tmp { |
|
|
if zhios_order_relate_utils.AnyToString(v["id"]) == zhios_order_relate_utils.IntToStr(user.Level) { |
|
|
if zhios_order_relate_utils.AnyToString(v["id"]) == zhios_order_relate_utils.IntToStr(user.Level) { |
|
|
tmpData = v |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
perUserNum := zhios_order_relate_utils.StrToInt(zhios_order_relate_utils.AnyToString(tmpData["count"])) |
|
|
|
|
|
leftNum := mallCouponScheme.LeftNum - perUserNum |
|
|
|
|
|
if leftNum < 0 { |
|
|
|
|
|
perUserNum = mallCouponScheme.LeftNum |
|
|
|
|
|
} |
|
|
|
|
|
for i := 0; i < perUserNum; i++ { |
|
|
|
|
|
var userCoupon = &model.MallUserCoupon{ |
|
|
|
|
|
Uid: uid, |
|
|
|
|
|
SchemeId: mallCouponScheme.Id, |
|
|
|
|
|
IsUse: 0, |
|
|
|
|
|
Kind: zhios_order_relate_utils.StrToInt(zhios_order_relate_utils.AnyToString(tmpData["kind"])), |
|
|
|
|
|
Cal: zhios_order_relate_utils.SerializeStr(tmpData["cal"]), |
|
|
|
|
|
ValidTimeStart: startTime, |
|
|
|
|
|
ValidTimeEnd: endTime, |
|
|
|
|
|
UseRule: mallCouponScheme.UseRule, |
|
|
|
|
|
UseActivityType: mallCouponScheme.UseActivityType, |
|
|
|
|
|
CreateTime: now, |
|
|
|
|
|
UpdateTime: now, |
|
|
|
|
|
|
|
|
tmpData := v |
|
|
|
|
|
perUserNum := zhios_order_relate_utils.StrToInt(zhios_order_relate_utils.AnyToString(tmpData["count"])) |
|
|
|
|
|
leftNum := mallCouponScheme.LeftNum - perUserNum |
|
|
|
|
|
if leftNum < 0 { |
|
|
|
|
|
perUserNum = mallCouponScheme.LeftNum |
|
|
|
|
|
leftNum = 0 |
|
|
|
|
|
} |
|
|
|
|
|
for i := 0; i < perUserNum; i++ { |
|
|
|
|
|
var userCoupon = &model.MallUserCoupon{ |
|
|
|
|
|
Uid: uid, |
|
|
|
|
|
SchemeId: mallCouponScheme.Id, |
|
|
|
|
|
IsUse: 0, |
|
|
|
|
|
Kind: zhios_order_relate_utils.StrToInt(zhios_order_relate_utils.AnyToString(tmpData["kind"])), |
|
|
|
|
|
Cal: zhios_order_relate_utils.SerializeStr(tmpData["cal"]), |
|
|
|
|
|
ValidTimeStart: startTime, |
|
|
|
|
|
ValidTimeEnd: endTime, |
|
|
|
|
|
UseRule: mallCouponScheme.UseRule, |
|
|
|
|
|
UseActivityType: mallCouponScheme.UseActivityType, |
|
|
|
|
|
CreateTime: now, |
|
|
|
|
|
UpdateTime: now, |
|
|
|
|
|
} |
|
|
|
|
|
userCoupons = append(userCoupons, userCoupon) |
|
|
|
|
|
} |
|
|
|
|
|
if len(userCoupons) == 0 { |
|
|
|
|
|
continue |
|
|
|
|
|
} |
|
|
|
|
|
_, err := engine.Table("mall_user_coupon").Insert(&userCoupons) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return err |
|
|
|
|
|
} |
|
|
|
|
|
mallCouponScheme.LeftNum = leftNum |
|
|
|
|
|
engine.Where("id=?", mallCouponScheme.Id).Cols("left_num").Update(&mallCouponScheme) |
|
|
} |
|
|
} |
|
|
userCoupons = append(userCoupons, userCoupon) |
|
|
|
|
|
} |
|
|
|
|
|
if len(userCoupons) == 0 { |
|
|
|
|
|
return nil |
|
|
|
|
|
} |
|
|
|
|
|
_, err := engine.Table("mall_user_coupon").Insert(&userCoupons) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return err |
|
|
|
|
|
} |
|
|
} |
|
|
mallCouponScheme.LeftNum = leftNum |
|
|
|
|
|
engine.Where("id=?", mallCouponScheme.Id).Cols("left_num").Update(&mallCouponScheme) |
|
|
|
|
|
|
|
|
|
|
|
return nil |
|
|
return nil |
|
|
} |
|
|
} |