// 保存订单 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) }
// 保存产品 func (this *saleService) SaveItem(partnerId int, v *sale.ValueItem) (int, error) { sl := this._rep.GetSale(partnerId) var pro sale.IItem if v.Id > 0 { pro = sl.GetItem(v.Id) if pro == nil { return 0, errors.New("产品不存在") } if err := pro.SetValue(v); err != nil { return 0, err } } else { pro = sl.CreateItem(v) } return pro.Save() }