Пример #1
0
// 保存促销
func (this *promotionService) SavePromotion(v *promotion.PromotionInfo) (int, error) {
	var prom promotion.IPromotion
	if v.Id > 0 {
		prom = this._rep.GetPromotion(v.Id)
		err := prom.SetValue(v)
		if err != nil {
			return v.Id, err
		}
	} else {
		prom = this._rep.CreatePromotion(v)
	}
	return prom.Save()
}
Пример #2
0
/**************   Coupon ************/
func (this *promotionService) SaveCoupon(merchantId int, v *promotion.PromotionInfo, v1 *promotion.ValueCoupon) (int, error) {
	var prom promotion.IPromotion
	var err error
	if v.Id > 0 {
		prom = this._rep.GetPromotion(v.Id)
		if prom.GetValue().MerchantId != merchantId {
			return -1, merchant.ErrMerchantNotMatch
		}
	} else {
		prom = this._rep.CreatePromotion(v)
	}

	if err = prom.SetValue(v); err == nil {
		cb := prom.(promotion.ICouponPromotion)
		err = cb.SetDetailsValue(v1)
	}

	if err != nil {
		return v.Id, err
	}

	return prom.Save()
}