huangjiajun 1 vecka sedan
förälder
incheckning
33a58eed74
1 ändrade filer med 33 tillägg och 32 borttagningar
  1. +33
    -32
      rule/service_award_dividend/return.go

+ 33
- 32
rule/service_award_dividend/return.go Visa fil

@@ -245,41 +245,42 @@ func BatchInsertMallUserCoupon(engine *xorm.Engine, mallCouponScheme model.MallC
if len(tmp) == 0 {
return nil
}
tmpData := make(map[string]interface{})
for _, v := range tmp {
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
}

Laddar…
Avbryt
Spara