public void MakeTestOrder(LiveEntities dbEntity) { // 建一个测试订单(真实订单,运单号) OrderInformation oNewOrder = new OrderInformation { Organization = (from o in dbEntity.MemberOrganizations where o.Code == "Zhuchao" && o.Otype == (byte)ModelEnum.OrganizationType.CORPORATION select o).FirstOrDefault(), Channel = (from c in dbEntity.MemberChannels where c.Code == "Taobao01" && c.Otype == (byte)ModelEnum.OrganizationType.CHANNEL select c).FirstOrDefault(), Warehouse = (from w in dbEntity.WarehouseInformations where w.Code == "ZCWH01" && w.Otype == (byte)ModelEnum.OrganizationType.WAREHOUSE select w).FirstOrDefault(), User = (from u in dbEntity.MemberUsers where u.LoginName == "test" select u).FirstOrDefault(), LinkCode = "92781947684462", Ostatus = (byte)ModelEnum.OrderStatus.DELIVERIED, PayStatus = (byte)ModelEnum.PayStatus.PAID, TransType = (byte)ModelEnum.TransType.SECURED, Currency = (from u in dbEntity.GeneralMeasureUnits where u.Code == "¥" && u.Utype == (byte)ModelEnum.MeasureUnit.CURRENCY select u).FirstOrDefault(), Location = (from r in dbEntity.GeneralRegions where r.Code == "110105" select r).FirstOrDefault(), }; OrderShipping oShipping = new OrderShipping { Order = oNewOrder, Shipper = (from s in dbEntity.ShippingInformations where s.Code == "EMS" && s.Otype == (byte)ModelEnum.OrganizationType.SHIPPER select s).FirstOrDefault(), Ostatus = (byte)ModelEnum.ShippingCheck.PASSED, Candidate = true }; dbEntity.OrderShippings.Add(oShipping); dbEntity.SaveChanges(); ExTaobaoDeliveryPending oPending = new ExTaobaoDeliveryPending { Order = oNewOrder, Dstatus = (byte)ModelEnum.TaobaoDeliveryStatus.WAIT_FOR_SEND, ShipID = oShipping.Gid, tid = oNewOrder.LinkCode, logistics = oShipping.Shipper.Code, out_sid = "EM812010333CS" }; dbEntity.ExTaobaoDeliveryPendings.Add(oPending); dbEntity.SaveChanges(); }
public ActionResult ConfirmDelivery(string data, Guid outID) { if (!base.CheckPrivilege("EnableApprove"))//是否允许确认(扫描/发货) RedirectToAction("ErrorPage", "Home", new { message = "Sorry you have no privilege to visit the Page" }); WarehouseStockOut stockOut = dbEntity.WarehouseStockOuts.Find(outID); if (stockOut == null || stockOut.Deleted) { return Error("记录不存在", Url.Action("StockOut")); } else if (stockOut.Ostatus != (byte)ModelEnum.StockOutStatus.NONE) { return Error("已确认,不能再次确认", Url.Action("StockOut")); } JavaScriptSerializer jss = new JavaScriptSerializer(); IEnumerable<WarehouseOutDelivery> models = jss.Deserialize<IEnumerable<WarehouseOutDelivery>>(data); foreach (WarehouseOutDelivery model in models) { WarehouseOutDelivery delivery = new WarehouseOutDelivery { OutID = outID, Envelope = model.Envelope, PackWeight = model.PackWeight, ShipID = model.ShipID }; dbEntity.WarehouseOutDeliveries.Add(delivery); } Guid shipper = models.ElementAt(0).ShipID;//最终承运商 #region 修改出库单的最终信息 stockOut.ShipID = models.ElementAt(0).ShipID;//设置出库单的最终承运商 stockOut.Ostatus = (byte)ModelEnum.StockOutStatus.DELIVERIED;//设置出库单的状态 stockOut.SendMan = CurrentSession.UserID; #endregion 修改出库单的最终信息 #region 设置订单的最终承运商 OrderShipping os = (from i in dbEntity.OrderShippings where i.OrderID == stockOut.RefID && i.ShipID == shipper && i.Deleted == false select i).FirstOrDefault(); //如果订单对应的运输信还没有,新建 if (os == null) { os = new OrderShipping { ShipID = shipper, OrderID = stockOut.RefID.Value, Candidate = true }; dbEntity.OrderShippings.Add(os); } else { os.Candidate = true; } #endregion 设置订单的最终承运商 #region 修改订单最终信息 OrderInformation order = dbEntity.OrderInformations.Find(stockOut.RefID); order.Ostatus = (byte)ModelEnum.OrderStatus.DELIVERIED; //若是淘宝订单,需要另外做的修改 if (order.Channel.ExtendType.Ctype == (byte)ModelEnum.StandardCategoryType.CHANNEL && order.Channel.Code == "Taobao") { ExTaobaoDeliveryPending TDelivery = (from t in dbEntity.ExTaobaoDeliveryPendings where t.OrderID == stockOut.RefID && !t.Deleted select t).SingleOrDefault(); if (TDelivery != null) { TDelivery.ShipID = shipper; TDelivery.tid = order.LinkCode; TDelivery.out_sid = stockOut.Shipper.Code; } else { TDelivery = new ExTaobaoDeliveryPending { OrderID = order.Gid, ShipID = shipper, tid = order.LinkCode, out_sid = stockOut.Shipper.Code }; dbEntity.ExTaobaoDeliveryPendings.Add(TDelivery); } } #endregion 修改订单最终信息 dbEntity.SaveChanges(); return RedirectToAction("StockOut"); }