Beispiel #1
0
// 获取商品值
func (this *saleService) GetValueGoods(partnerId, goodsId int) *valueobject.Goods {
	sl := this._rep.GetSale(partnerId)
	var goods sale.IGoods = sl.GetGoods(goodsId)
	if goods != nil {
		return goods.GetPackedValue()
	}
	return nil
}
Beispiel #2
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
				}
			}
		}
	}
}
Beispiel #3
0
// 添加商品销售数量
func (this *Order) addGoodsSaleNum(snapshotId int, quantity int) error {
	snapshot := this._saleRep.GetGoodsSnapshot(snapshotId)
	if snapshot == nil {
		return sale.ErrNoSuchSnapshot
	}
	var goods sale.IGoods = this._saleRep.GetSale(this._value.PartnerId).
		GetGoods(snapshot.GoodsId)

	if goods == nil {
		return sale.ErrNoSuchGoods
	}
	return goods.AddSaleNum(quantity)
}
Beispiel #4
0
// 取消商品
func (this *Order) cancelGoods() error {
	for _, v := range this._value.Items {
		snapshot := this._saleRep.GetGoodsSnapshot(v.SnapshotId)
		if snapshot == nil {
			return sale.ErrNoSuchSnapshot
		}
		var goods sale.IGoods = this._saleRep.GetSale(this._value.PartnerId).
			GetGoods(snapshot.GoodsId)
		if goods != nil {
			goods.CancelSale(v.Quantity, this.GetOrderNo())
		}
	}
	return nil
}
Beispiel #5
0
func (this *saleService) SaveGoods(partnerId int, v *sale.ValueGoods) (int, error) {
	sl := this._rep.GetSale(partnerId)
	var pro sale.IGoods
	if v.Id > 0 {
		pro = sl.GetGoods(v.Id)
		if pro == nil {
			return 0, errors.New("产品不存在")
		}
		if err := pro.SetValue(v); err != nil {
			return 0, err
		}
	} else {
		pro = sl.CreateGoods(v)
	}
	return pro.Save()
}
Beispiel #6
0
// 获取商品详情
func (this *saleService) GetGoodsDetails(partnerId, goodsId, mLevel int) (*valueobject.Goods, map[string]string) {
	sl := this._rep.GetSale(partnerId)
	var goods sale.IGoods = sl.GetGoods(goodsId)
	gv := goods.GetPackedValue()
	proMap := goods.GetPromotionDescribe()
	if b, price := goods.GetLevelPrice(mLevel); b {
		gv.PromPrice = price
		proMap["会员专享"] = fmt.Sprintf("会员优惠,仅需<b>¥%s</b>",
			format.FormatFloat(price))
	}
	return gv, proMap
}
Beispiel #7
0
// 根据SKU获取商品
func (this *saleService) GetGoodsBySku(partnerId int, itemId int, sku int) *valueobject.Goods {
	sl := this._rep.GetSale(partnerId)
	var goods sale.IGoods = sl.GetGoodsBySku(itemId, sku)
	return goods.GetPackedValue()
}
Beispiel #8
0
// 获取货品描述
func (this *saleService) GetItemDescriptionByGoodsId(partnerId, goodsId int) string {
	sl := this._rep.GetSale(partnerId)
	var goods sale.IGoods = sl.GetGoods(goodsId)
	return goods.GetItem().GetValue().Description
}