Exemplo n.º 1
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
}
Exemplo n.º 2
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
}