Beispiel #1
0
// 保存订单
func (this *Order) saveOrderOnSubmit() (int, error) {
	cartItems := this._cart.GetValue().Items
	if this._value.Items == nil {
		this._value.Items = make([]*shopping.OrderItem, len(cartItems))
	}
	var sl sale.ISale = this._saleRep.GetSale(this._value.PartnerId)
	var item sale.IItem
	var snap *sale.GoodsSnapshot
	for i, v := range cartItems {
		snap = sl.GetGoodsSnapshot(cartItems[i].SnapshotId)
		if snap == nil {
			return 0, errors.New("商品缺少快照:" + item.GetValue().Name)
		}

		this._value.Items[i] = &shopping.OrderItem{
			Id:         0,
			SnapshotId: snap.Id,
			Quantity:   v.Num,
			Sku:        "",
			Fee:        v.SalePrice * float32(v.Num),
		}
	}

	return this._shoppingRep.SaveOrder(this._shopping.GetAggregateRootId(), this._value)
}
Beispiel #2
0
// 获取分页上架的商品
func (this *saleService) GetPagedOnShelvesGoods(partnerId, categoryId, start, end int,
	sortQuery string) (int, []*valueobject.Goods) {
	var sl sale.ISale = this._rep.GetSale(partnerId)
	var cate sale.ICategory = sl.GetCategory(categoryId)
	var ids []int = cate.GetChildId()
	ids = append(ids, categoryId)
	//todo: cache

	var where string
	var orderBy string
	switch sortQuery {
	case "price_0":
		where = ""
		orderBy = "gs_item.sale_price ASC"
	case "price_1":
		where = ""
		orderBy = "gs_item.sale_price DESC"
	case "sale_0":
		where = ""
		orderBy = "gs_goods.sale_num ASC"
	case "sale_1":
		where = ""
		orderBy = "gs_goods.sale_num DESC"
	case "rate_0":
		//todo:
	case "rate_1":
		//todo:
	}

	return this._goodsRep.GetPagedOnShelvesGoods(partnerId, ids, start, end, where, orderBy)

}
Beispiel #3
0
// 获取分页上架的商品
func (this *saleService) GetPagedOnShelvesGoods(partnerId, categoryId, start, end int) (int, []*valueobject.Goods) {
	var sl sale.ISale = this._rep.GetSale(partnerId)
	var cate sale.ICategory = sl.GetCategory(categoryId)
	var ids []int = cate.GetChildId()
	ids = append(ids, categoryId)
	//todo: cache

	return this._goodsRep.GetPagedOnShelvesGoods(partnerId, ids, start, end)

}
Beispiel #4
0
// 设置附加的商品信息
func (this *Cart) setAttachGoodsInfo(items []*shopping.ValueCartItem) {
	if items != nil {
		l := len(items)
		if l == 0 {
			return
		}
		var ids []int = make([]int, l)
		for i, v := range items {
			ids[i] = v.GoodsId
		}

		// 设置附加的值
		goods, err := this._goodsRep.GetGoodsByIds(ids...)
		if err == nil {
			var goodsMap = make(map[int]*valueobject.Goods, len(goods))
			for _, v := range goods {
				goodsMap[v.GoodsId] = v
			}

			var level int
			var goods sale.IGoods
			var sl sale.ISale

			//  更新登陆后的优惠价
			if this._value.BuyerId > 0 {
				sl = this._saleRep.GetSale(this._partnerId)
				m, _ := this._memberRep.GetMember(this._value.BuyerId)
				if m != nil {
					level = m.GetValue().Level
				}
			}

			for _, v := range items {
				gv, ok := goodsMap[v.GoodsId]
				if level > 0 {
					goods = sl.CreateGoods(
						sl.CreateItem(sale.ParseToPartialValueItem(gv)),
						sale.ParseToValueGoods(gv),
					)
					if p := goods.GetPromotionPrice(level); p < gv.SalePrice {
						gv.SalePrice = p
					}
				}
				if ok {
					v.Name = gv.Name
					v.Price = gv.Price
					v.GoodsNo = gv.GoodsNo
					v.Image = gv.Image
					v.SalePrice = gv.SalePrice
				}
			}
		}
	}
}