huangjiajun 2 ay önce
ebeveyn
işleme
33a58eed74
1 değiştirilmiş dosya ile 33 ekleme ve 32 silme
  1. +33
    -32
      rule/service_award_dividend/return.go

+ 33
- 32
rule/service_award_dividend/return.go Dosyayı Görüntüle

@@ -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
}

Yükleniyor…
İptal
Kaydet