Example #1
0
func (this *Order) ApplyCoupon(coupon promotion.ICoupon) error {
	if this._coupons == nil {
		this._coupons = []promotion.ICoupon{}
	}
	this._coupons = append(this._coupons, coupon)

	//val := coupon.GetValue()
	v := this._value
	//v.CouponCode = val.Code
	//v.CouponDescribe = coupon.GetDescribe()
	v.CouponFee = coupon.GetCouponFee(v.Fee)
	v.PayFee = v.Fee - v.CouponFee
	v.DiscountFee = v.DiscountFee + v.CouponFee
	return nil
}
Example #2
0
func (this *promotionService) SaveCoupon(partnerId int, e *promotion.ValueCoupon) (int, error) {
	prom := this._rep.GetPromotion(partnerId)
	var coupon promotion.ICoupon
	if e.Id > 0 {
		coupon = prom.GetCoupon(e.Id)
		if coupon == nil {
			return 0, errors.New("优惠券不存在")
		}
		err := coupon.SetValue(e)
		if err != nil {
			return 0, err
		}
	} else {
		coupon = prom.CreateCoupon(e)
	}
	return coupon.Save()
}
Example #3
0
func (this *OrderCoupon) Clone(coupon promotion.ICoupon,
	orderId int, orderFee float32) *OrderCoupon {
	v := coupon.GetValue()
	this.CouponCode = v.Code
	this.CouponId = v.Id
	this.OrderId = orderId
	this.Fee = coupon.GetCouponFee(orderFee)
	this.Describe = coupon.GetDescribe()
	this.SendIntegral = v.Integral
	return this
}
Example #4
0
// 生成订单
func (this *Shopping) BuildOrder(memberId int, couponCode string) (shopping.IOrder, shopping.ICart, error) {
	order, m, cart, err := this.ParseShoppingCart(memberId)
	if err != nil {
		return order, cart, err
	}

	if len(couponCode) != 0 {
		var coupon promotion.ICoupon
		var result bool
		var val = order.GetValue()
		coupon, err = this._promRep.GetCouponByCode(
			this._partnerId, couponCode)

		// 如果优惠券不存在
		if err != nil || coupon == nil {
			log.PrintErr(err)
			return order, cart, errors.New("优惠券无效")
		}

		result, err = coupon.CanUse(m, val.Fee)
		if result {
			if coupon.CanTake() {
				_, err = coupon.GetTake(memberId)
				//如果未占用,则占用
				if err != nil {
					err = coupon.Take(memberId)
				}
			} else {
				_, err = coupon.GetBind(memberId)
			}
			if err != nil {
				log.PrintErr(err)
				return order, cart, errors.New("优惠券无效")
			}
			order.ApplyCoupon(coupon) //应用优惠券
		}
	}

	return order, cart, err
}