Ejemplo n.º 1
0
// 将购物车转换为订单
func (this *Shopping) ParseShoppingCart(memberId int) (shopping.IOrder,
	member.IMember, shopping.ICart, error) {
	var order shopping.IOrder
	var val shopping.ValueOrder
	var cart shopping.ICart
	var m member.IMember
	var err error

	m = this._memberRep.GetMember(memberId)
	if m == nil {
		return nil, m, nil, member.ErrSessionTimeout
	}

	cart, err = this.GetCurrentCart(memberId)

	if err != nil || cart == nil || len(cart.GetValue().Items) == 0 {
		return nil, m, cart, shopping.ErrEmptyShoppingCart
	}

	val.MemberId = memberId
	val.PartnerId = this._partnerId

	tf, of := cart.GetFee()
	val.TotalFee = tf //总金额
	val.Fee = of      //实际金额
	val.PayFee = of
	val.DiscountFee = tf - of //优惠金额
	val.PartnerId = this._partnerId
	val.Status = 1

	order = this.CreateOrder(&val, cart)
	return order, m, cart, nil
}
Ejemplo n.º 2
0
Archivo: cart.go Proyecto: honj51/go2o
// 合并购物车,并返回新的购物车
func (this *Cart) Combine(c shopping.ICart) (shopping.ICart, error) {
	if c.GetDomainId() != this.GetDomainId() {
		for _, v := range c.GetValue().Items {
			this.AddItem(v.GoodsId, v.Num)
		}
	}
	return this, nil
}
Ejemplo n.º 3
0
//  获取购物车
func (this *shoppingService) getShoppingCart(partnerId int, memberId int, cartKey string) shopping.ICart {
	sp := this._rep.GetShopping(partnerId)
	var c shopping.ICart
	var mc shopping.ICart

	var skIsNil = len(cartKey) == 0
	var mmNotNil = memberId != 0

	if mmNotNil {
		mc, _ = sp.GetNotBoughtCart(memberId)
		if mc != nil && (skIsNil || mc.GetValue().CartKey == cartKey) {
			return mc
		}
	}

	if !skIsNil {
		// 根据Key获取购物车
		c, _ = sp.GetCart(cartKey)
		if c == nil {
			// 新的购物车不存在,直接返回会员的购物车
			if mc != nil {
				return mc
			}
		} else {

			cv := c.GetValue()
			//合并购物车
			if cv.BuyerId <= 0 {
				// 设置购买者
				if mmNotNil {
					c.SetBuyer(memberId)
				}
			} else if mc != nil {
				// 合并购物车
				nc, err := mc.Combine(c)
				if err == nil {
					nc.Save()
					return nc
				}
				return mc
			}

			// 如果没有购买,则返回
			if cv.IsBought == 0 {
				return c
			}
		}
	}

	// 返回一个新的购物车
	return sp.NewCart(memberId)
}
Ejemplo n.º 4
0
func (this *shoppingService) parseDtoCart(c shopping.ICart) *dto.ShoppingCart {
	var cart = new(dto.ShoppingCart)
	v := c.GetValue()
	cart.Id = c.GetDomainId()
	cart.BuyerId = v.BuyerId
	cart.CartKey = v.CartKey
	cart.UpdateTime = v.UpdateTime
	t, f := c.GetFee()
	cart.TotalFee = t
	cart.OrderFee = f
	cart.Summary = c.GetSummary()
	cart.IsBought = v.IsBought

	if v.Items != nil {
		if l := len(v.Items); l != 0 {
			cart.Items = make([]*dto.CartItem, l)
			for i, v := range v.Items {
				cart.Items[i] = &dto.CartItem{
					GoodsId:    v.GoodsId,
					GoodsName:  v.Name,
					GoodsNo:    v.GoodsNo,
					SmallTitle: v.SmallTitle,
					GoodsImage: v.Image,
					Num:        v.Num,
					Price:      v.Price,
					SalePrice:  v.SalePrice,
				}
			}
		}
	}

	return cart
}
Ejemplo n.º 5
0
// 应用购物车内商品的促销
func (this *Order) applyCartPromotionObSubmit(vo *shopping.ValueOrder, cart shopping.ICart) ([]promotion.IPromotion, int) {
	var proms []promotion.IPromotion = make([]promotion.IPromotion, 0)
	var prom promotion.IPromotion
	var saveFee int
	var totalSaveFee int
	var intOrderFee = int(vo.Fee)
	var rightBack bool

	for _, v := range cart.GetCartGoods() {
		prom = nil
		saveFee = 0
		rightBack = false

		// 判断商品的最省促销
		for _, v1 := range v.GetPromotions() {

			// 返现
			if v1.Type() == promotion.TypeFlagCashBack {
				vc := v1.GetRelationValue().(*promotion.ValueCashBack)
				if vc.MinFee < intOrderFee {
					if vc.BackFee > saveFee {
						prom = v1
						saveFee = vc.BackFee
						rightBack = vc.BackType == promotion.BackUseForOrder // 是否立即抵扣
					}
				}
			}

			//todo: 其他促销
		}

		if prom != nil {
			proms = append(proms, prom)
			if rightBack {
				totalSaveFee += saveFee
			}
		}
	}

	return proms, totalSaveFee
}
Ejemplo n.º 6
0
// 检查购物车
func (this *Shopping) CheckCart(cart shopping.ICart) error {
	if cart == nil || len(cart.GetValue().Items) == 0 {
		return shopping.ErrEmptyShoppingCart
	}

	sl := this._saleRep.GetSale(this._partnerId)
	for _, v := range cart.GetValue().Items {
		goods := sl.GetGoods(v.GoodsId)
		if goods == nil {
			return sale.ErrNoSuchGoods // 没有商品
		}
		stockNum := goods.GetValue().StockNum
		if stockNum == 0 {
			return sale.ErrFullOfStock // 已经卖完了
		}
		if stockNum < v.Quantity {
			return sale.ErrOutOfStock // 超出库存
		}
	}
	return nil
}
Ejemplo n.º 7
0
func (this *Shopping) GetShoppingCart(buyerId int, cartKey string) shopping.ICart {

	var hasOutCart = len(cartKey) != 0
	var hasBuyer = buyerId != 0

	var memCart shopping.ICart = nil // 消费者的购物车
	var outCart shopping.ICart = nil // 通过cartKey传入的购物车

	if hasBuyer {
		// 如果没有传递cartKey ,或者传递的cart和会员绑定的购物车相同,直接返回
		if memCart, _ = this.GetCurrentCart(buyerId); memCart != nil {
			if !hasOutCart || memCart.GetValue().CartKey == cartKey {
				return memCart
			}
		} else {
			memCart = this.NewCart(buyerId)
		}
	}

	if hasOutCart {
		outCart, _ = this.GetCartByKey(cartKey)
	}

	// 合并购物车
	if outCart != nil && hasBuyer {
		if bid := outCart.GetValue().BuyerId; bid <= 0 || bid == buyerId {
			memCart, _ = memCart.Combine(outCart)
			outCart.Destroy()
			memCart.Save()
		}
	}

	if memCart != nil {
		return memCart
	}

	if outCart != nil {
		return outCart
	}

	return this.NewCart(buyerId)

	//	if !hasOutCart {
	//		if c == nil {
	//			// 新的购物车不存在,直接返回会员的购物车
	//			if mc != nil {
	//				return mc
	//			}
	//		} else {
	//			cv := c.GetValue()
	//			//合并购物车
	//			if cv.BuyerId <= 0 {
	//				// 设置购买者
	//				if hasBuyer {
	//					c.SetBuyer(buyerId)
	//				}
	//			} else if mc != nil && cv.BuyerId == buyerId {
	//				// 合并购物车
	//				nc, err := mc.Combine(c)
	//				if err == nil {
	//					nc.Save()
	//					return nc
	//				}
	//				return mc
	//			}
	//
	//			// 如果没有购买,则返回
	//			return c
	//		}
	//	}

	// 返回一个新的购物车
	//	return this.NewCart(buyerId)
}
Ejemplo n.º 8
0
//创建购物车
// @buyerId 为购买会员ID,0表示匿名购物车
func (this *Shopping) NewCart(buyerId int) shopping.ICart {
	var cart shopping.ICart = newCart(this._partnerRep, this._memberRep, this._saleRep,
		this._goodsRep, this._rep, this._partnerId, buyerId)
	cart.Save()
	return cart
}