// 绑定订单与优惠券 func (this *Order) bindCouponOnSubmit() { var oc *shopping.OrderCoupon = new(shopping.OrderCoupon) for _, c := range this.GetCoupons() { oc.Clone(c, this.GetDomainId(), this._value.Fee) this._shoppingRep.SaveOrderCouponBind(oc) } }
// 绑定订单与优惠券 func (this *Order) bindCouponOnSubmit(orderNo string) { var oc *shopping.OrderCoupon = new(shopping.OrderCoupon) for _, c := range this.GetCoupons() { oc.Clone(c, this.GetDomainId(), this._value.Fee) this._shoppingRep.SaveOrderCouponBind(oc) // 绑定促销 this.bindPromotionOnSubmit(orderNo, c.(promotion.IPromotion)) } }
// 提交订单,返回订单号。如有错误则返回 func (this *Order) Submit() (string, error) { if this.GetDomainId() != 0 { return "", errors.New("订单不允许重复提交!") } if this.cart == nil || len(this.cart.GetValue().Items) == 0 { return "", errors.New("购物车为空!") } v := this.value v.CreateTime = time.Now().Unix() v.UpdateTime = v.CreateTime v.ItemsInfo = this.cart.GetSummary() v.OrderNo = this._shopping.GetFreeOrderNo() // 应用优惠券 var err error var t *promotion.ValueCouponTake var b *promotion.ValueCouponBind for _, c := range this.GetCoupons() { if c.CanTake() { t, err = c.GetTake(v.MemberId) if err == nil { err = c.ApplyTake(t.Id) } } else { b, err = c.GetBind(v.MemberId) if err == nil { err = c.UseCoupon(b.Id) } } if err != nil { log.PrintErr(err) err = errors.New("Code 105:优惠券使用失败") return "", err } } // 保存订单 id, err := this.shoppingRep.SaveOrder(this._shopping.GetAggregateRootId(), v) v.Id = id if err == nil { var oc *shopping.OrderCoupon = new(shopping.OrderCoupon) for _, c := range this.GetCoupons() { oc.Clone(c, v.Id, v.Fee) // 绑定订单与优惠券 this.shoppingRep.SaveOrderCouponBind(oc) } } return v.OrderNo, err }