// 应用优惠券 func (this *Order) ApplyCoupon(coupon promotion.ICouponPromotion) error { if this._coupons == nil { this._coupons = []promotion.ICouponPromotion{} } this._coupons = append(this._coupons, coupon) v := this._value //v.CouponCode = val.Code //v.CouponDescribe = coupon.GetDescribe() v.CouponFee = coupon.GetCouponFee(v.Fee) v.PayFee = this.GetPaymentFee() v.DiscountFee = v.DiscountFee + v.CouponFee return nil }
func (this *OrderCoupon) Clone(coupon promotion.ICouponPromotion, orderId int, orderFee float32) *OrderCoupon { v := coupon.GetDetailsValue() 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 }
// 生成订单 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.ICouponPromotion var result bool var val = order.GetValue() cp := this._promRep.GetCouponByCode( this._partnerId, couponCode) // 如果优惠券不存在 if cp == nil { log.PrintErr(err) return order, cart, errors.New("优惠券无效") } coupon = cp.(promotion.ICouponPromotion) 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("优惠券无效") } err = order.ApplyCoupon(coupon) //应用优惠券 } } return order, cart, err }