/// <summary> /// 将订单保存到数据库 /// </summary> /// <param name="tenantID"></param> /// <param name="db"></param> /// <param name="oid"></param> public void Save(Guid tenantID, Zippy.Data.IDalProvider db, long?oid) { long orderID = 0; Z10Order.Total = Items.Sum(s => s.Total); Z10Order.TenantID = tenantID; try { // 此处应该加入事务 db.BeginTransaction(); if (Z10Order.OrderID.HasValue && Z10Order.OrderID > 0) { orderID = Z10Order.OrderID.Value; db.Update(Z10Order); } else { orderID = db.Insert(Z10Order); Z10Order zorder = new Z10Order(); if (!oid.HasValue) { zorder.OrderID = orderID; zorder.OriID = orderID; } else { zorder.OriID = oid; } //zorder.FeeShould = this.CalFeeShould(); db.Update(zorder); } foreach (Z10OrderItem item in Items) { item.ItemStatus = 1; item.TenantID = tenantID; item.Total = (item.Price ?? 0) * (item.CountShould ?? 0); if (item.ItemID.HasValue && item.ItemID > 0 && item.OrderID == orderID) { db.Update(item); } else { item.OrderID = orderID; var itemID = db.Insert(item); item.ItemID = itemID; } } Z10Order.OrderID = orderID; db.Commit(); } catch (Exception ex) { db.RollbackTransaction(); throw ex; } }