public string CreateOrder(string remark = "", string couponId = "") { var loginUser = (UserInfo)ViewBag.User; var list = _order.GetShoppingCar(loginUser); var totalPrice = list.Sum(x => x.Count * x.Price); if (list != null && list.Count > 0 && totalPrice > 380) { var order = new OrderInfo(); var saleMan = _user.GetUserByUserId(loginUser.SaleManGuid); order.Id = Guid.NewGuid(); order.CreateTime = DateTime.Now; order.CreateUserId = loginUser.UserId; order.CreateUserName = loginUser.UserName; order.CreateUserType = loginUser.TypeName; order.CreateUserNum = loginUser.UserNum; order.StoreName = loginUser.SotreName; order.CreateUserTel = loginUser.Tel; order.CreateUserTypeId = loginUser.TypeId; order.RootUserId = loginUser.CreateUserId; order.RootUserName = loginUser.CreateUser; order.SaleManGuid = loginUser.SaleManGuid; order.SaleManName = loginUser.SaleManName; order.ReceiveAddr = loginUser.Addr; order.Province = loginUser.Province; order.ProvinceNum = loginUser.ProvinceNum; order.City = loginUser.City; order.CityNum = loginUser.CityNum; order.Area = loginUser.Area; order.AreaNum = loginUser.AreaNum; order.Stutas = (int)Common.Entities.OrderStatus.等待商家发货; order.SaleManTel = saleMan == null ? "" : saleMan.Tel; order.PayType = "货到付款"; order.Remark = remark; Guid Cid = new Guid(); if (Guid.TryParse(couponId, out Cid)) { Coupon c = _active.GetCouponById(Cid); if (c != null) { order.LessMoney += c.LessMoney; _active.SetCouponUse(Cid, order.Id); } } Manjiujian mj = _active.CheckManjiujian(loginUser, ViewBag.ManagerId); Manjiusong ms = _active.CheckManSong(loginUser, ViewBag.ManagerId); CouponActivity ca = _active.CheckCouponActivity(loginUser, ViewBag.ManagerId); if (mj != null) { order.Manjian = mj.LessMoeny; } if ((ms != null && ca == null) || (ms != null && ca != null && ms.LimitMoney > ca.SendMoney)) { var model = _manager.GetGoodsWithPrice(ms.SendGoodId, loginUser.TypeId); OrderItem item = new OrderItem(); item.IsGift = true; item.Count = ms.SendGoodCount; item.CreateUserId = loginUser.UserId; item.Id = Guid.NewGuid(); item.LessPrice = 0; item.Price = 0; item.RealPrice = 0; item.ProductId = model.Id; item.ProductTittle = model.GoodsTittle; item.TotalPrice = 0; item.ProductType = model.FirstTypeName; item.ProductTypeId = model.FirstTypeId; item.ProductId = model.Id; item.BarCode = model.BarCode; item.Spec = model.Spec; item.Unit = model.Unit; item.SupplierId = model.SupplierId; item.SupplierName = model.SupplierName; item.BrandId = model.BrandId; item.Brand = model.BrandName; item.Pic = model.pic1; var res = _order.AddOrderItem(item); } if ((ms == null && ca != null) || (ms != null && ca != null && ms.LimitMoney <= ca.SendMoney)) { Coupon coupon = new Coupon(); coupon.BrandId = ca.BrandId; coupon.BrandName = ca.BrandName; coupon.CouponType = ca.CouponType; coupon.CreateTime = DateTime.Now; coupon.CreateUserId = ca.CreateUserId; coupon.CreateUserName = ca.CreateUserName; coupon.EffectTime = ca.EffectTime; coupon.EndTime = DateTime.Now.AddDays(coupon.EffectTime); coupon.Id = Guid.NewGuid(); coupon.IsUsed = false; coupon.LessMoney = ca.LessMoney; coupon.Limit = ca.Limit; coupon.Remark = ca.Remark; coupon.StartTime = ca.StartTime; coupon.StoreId = loginUser.UserId; coupon.StoreNum = loginUser.UserNum; coupon.SupplierId = ca.SupplierId; coupon.SupplierName = ca.SupplierName; coupon.ActivityID = ca.Id; List <UserInfo> userList = new List <UserInfo>(); userList.Add(loginUser); _active.CreateCoupon(coupon, userList); } var dpses = _active.CheckDPS(list, loginUser.TypeId, loginUser.AreaNum); foreach (var dps in dpses) { var model = _manager.GetGoodsWithPrice(dps.SendGoodsId, loginUser.TypeId); OrderItem item = new OrderItem(); item.IsGift = true; item.Count = dps.SendCount; item.CreateUserId = loginUser.UserId; item.Id = Guid.NewGuid(); item.LessPrice = 0; item.Price = 0; item.RealPrice = 0; item.ProductId = model.Id; item.ProductTittle = model.GoodsTittle; item.TotalPrice = 0; item.ProductType = model.FirstTypeName; item.ProductTypeId = model.FirstTypeId; item.ProductId = model.Id; item.BarCode = model.BarCode; item.Spec = model.Spec; item.Unit = model.Unit; item.SupplierId = model.SupplierId; item.SupplierName = model.SupplierName; item.BrandId = model.BrandId; item.Brand = model.BrandName; item.Pic = model.pic1; var res = _order.AddOrderItem(item); } _response.Stutas = _order.SaveOrder(order, loginUser); //保存订单成功后 保存销售订单到erp 系统中 if (_response.Stutas) { try { var res = _order.InsertErp(order.Id); } catch (Exception ex) { LogsHelper.WriteErrorLog(ex, "导入Erp"); } } } else { _response.Msg = "总金额不足380无法下单!请继续添加商品!"; } return(Utils.SerializeObject(_response)); }