public ActionResult deleteSaleOrder(int id) { Sale_Order so = db.Sale_Order.Find(id); so.is_active = "N"; db.SaveChanges(); List<Sale_Order> list = db.Sale_Order.Where(x=>x.is_active=="Y").ToList(); return PartialView("UpdatedSaleOrderList",list); }
public ActionResult Create(int id) { try { Temporary_Orders temp = tempServices.findTempOrderById(id); int account_id = temp.Account_Id; TransactionAccount account = transactionService.findTransactionAccount(account_id); Sale_Order s_order = new Sale_Order(); s_order.bags = temp.bags; s_order.broker_name = temp.broker_name; s_order.brokers_commision = temp.brokers_commision; s_order.company_sign = temp.company_sign; s_order.created_at_ = temp.created_at_; s_order.is_active = temp.is_active; s_order.vendor_sign = temp.vendor_sign; s_order.item = temp.item; s_order.party_name = account.name; s_order.so_number = temp.order_number; s_order.terms = temp.terms; s_order.uptdated_at = temp.created_at_; s_order.weight = temp.weight; s_order.rate = temp.rate; s_order.prepared_by = temp.prepared_by; s_order.approved_by = Session["username"].ToString(); s_order.checked_by = temp.checked_by; s_order.Account_Id = account.id; service.addSO(s_order); service.save(); Temporary_Orders TO = db.Temporary_Orders.Find(id); TO.is_active = "N"; db.SaveChanges(); return RedirectToAction("listOfTempOrders"); } catch (DbEntityValidationException dbEx) { foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { Trace.TraceInformation("Class: {0}, Property: {1}, Error: {2}", validationErrors.Entry.Entity.GetType().FullName, validationError.PropertyName, validationError.ErrorMessage); } } return RedirectToAction("listOfTempOrders"); } }
/// <summary> /// 更新订单所有状态 /// </summary> /// <param name="orderInfo"></param> public void UpdateOrderAllStatus(ref Sale_Order orderInfo) { try { var orderList = new List <Sale_Order> { orderInfo }; UpdateOrderAllStatus(ref orderList); } catch (Exception) { } }
public ActionResult AddSaleVoucher(int id) { if (service.checkID() == false) { return(Content("IDS Conflict Error Occured While Procsesing Request")); } TemporaryReport temp = service.findTemporaryReport(id); int nextID = id + 1; TemporaryReport tempTo = service.findTemporaryReport(nextID); string from = temp.from_account; string to = temp.to_account; int fromID = (int)temp.tax; double rate = 0; int idForRate = 0; float unitPrice = 0; if (temp.voucher_type == "UPSV" || temp.voucher_type == "UPPV") { try { float checkingUnit = float.Parse(temp.unit_price); } catch (Exception) { if (temp.builty_no_ != null) { return(RedirectToAction("unitPriceSV", "SaleVoucher")); } else { return(RedirectToAction("unitPricePV", "SaleVoucher")); } } } try { int checking = (int)temp.builty_no_; } catch (Exception) { if (temp.voucher_type == "SV") { return(RedirectToAction("Index", "SaleVoucher")); } else { return(RedirectToAction("unitPriceSV", "SaleVoucher")); } } int builty = Convert.ToInt32(temp.builty_no_); try { String session = Session["name"].ToString(); TransactionAccount transFrom = new TransactionAccount(); TransactionAccount trans_to = new TransactionAccount(); Good good = service.findGood(fromID); if (temp.voucher_type == "UPPV" || temp.voucher_type == "PV") { transFrom = service.findJvTransaction(from); trans_to = good.TransactionAccount; idForRate = transFrom.id; } else if (temp.voucher_type == "SV" || temp.voucher_type == "UPSV") { transFrom = good.TransactionAccount; trans_to = service.findJvTransaction(to); idForRate = trans_to.id; } Transaction tr = new Transaction(); Transaction transTo = new Transaction(); if (temp.voucher_type == "UPSV" || temp.voucher_type == "UPPV") { unitPrice = float.Parse(temp.unit_price); rate = unitPrice; } else { try { rate = service.findRate(idForRate, good.good_Name); } catch (Exception) { return(Content("<script language='javascript' type='text/javascript'>alert('Invalid Rate !');</script>")); } } int amount = 0; tr.truck = temp.truck; tr.builty_no_ = temp.builty_no_; tr.weight_empty = temp.weight_empty; tr.weight_load = temp.weight_load; tr.net_weight = temp.net_weight; tr.quantity = tr.net_weight.ToString(); tr.good_ = good.good_Name; amount = Convert.ToInt32(rate * tr.net_weight); tr.bags = temp.bags; tr.created_at = temp.created_at; tr.updated_at = tr.created_at; tr.is_active = "Y"; tr.code = transFrom.id; tr.description = temp.description; tr.cr = 0; tr.dr = amount; tr.balance = (transFrom.balance - amount); tr.from_account = from; tr.to_account = to; //transFrom.dr_ = amount; if (temp.voucher_type == "SV" || temp.voucher_type == "UPSV") { if (temp.voucher_type == "SV") { tr.status = "Sale voucher added"; tr.voucher_type = "SV"; // tr.voucher_code = "SV111"; } else { tr.status = "Unit Price Sale Voucher Added"; tr.voucher_type = "UPSV"; // tr.voucher_code = "UPSV111"; } } else { if (temp.voucher_type == "PV") { tr.status = "Purchase Voucher added"; // tr.voucher_code = "PV111"; tr.voucher_type = "PV"; tr.grn = temp.grn; tr.deduction = temp.deduction; } else { tr.status = "Unit Price Purchase Voucher added"; // tr.voucher_code = "UPPV111"; tr.voucher_type = "UPPV"; tr.grn = temp.grn; tr.deduction = temp.deduction; } } tr.trans_acc_id = transFrom.id; if (session != "Admin") { string username = Session["username"].ToString(); User user = service.findUser(username); ViewBag.userName = user.name; tr.supervisor = user.name; } else { ViewBag.userName = Session["username"].ToString(); tr.supervisor = Session["username"].ToString(); } tr.user_id = temp.user_id; tr.admin_id = temp.admin_id; tr.voucher_code = temp.voucher_code; tr.unit_price = temp.unit_price; service.addTransaction(tr); transFrom.balance = tr.balance; tr.unique_key = transFrom.id; temp.is_active = "N"; transTo.truck = tempTo.truck; transTo.builty_no_ = tempTo.builty_no_; transTo.weight_empty = tempTo.weight_empty; transTo.weight_load = tempTo.weight_load; transTo.net_weight = tempTo.net_weight; transTo.bags = tempTo.bags; transTo.created_at = tempTo.created_at; transTo.updated_at = tr.created_at; transTo.is_active = "Y"; transTo.quantity = tr.quantity; transTo.good_ = good.good_Name; transTo.code = trans_to.id; transTo.description = tempTo.description; transTo.dr = 0; transTo.cr = amount; transTo.balance = (trans_to.balance + amount); transTo.from_account = from; transTo.to_account = to; if (temp.voucher_type == "SV" || temp.voucher_type == "UPSV") { if (temp.voucher_type == "SV") { transTo.status = "Sale voucher added"; transTo.voucher_type = "SV"; transTo.voucher_code = "SV111"; } else { transTo.status = "Unit Price Sale Voucher Added"; transTo.voucher_type = "UPSV"; transTo.voucher_code = "UPSV111"; } } else { if (temp.voucher_type == "PV") { transTo.status = "Purchase Voucher added"; transTo.voucher_code = "PV111"; transTo.voucher_type = "PV"; transTo.grn = tempTo.grn; transTo.deduction = tempTo.deduction; } else { transTo.status = "Unit Price Purchase Voucher added"; transTo.voucher_code = "UPPV111"; transTo.voucher_type = "UPPV"; transTo.grn = tempTo.grn; transTo.deduction = tempTo.deduction; } } transTo.trans_acc_id = trans_to.id; //trans_to.cr_ = amount; if (session != "Admin") { string username = Session["username"].ToString(); User user = service.findUser(username); ViewBag.userName = user.name; transTo.supervisor = user.name; } else { ViewBag.userName = Session["username"].ToString(); transTo.supervisor = Session["username"].ToString(); } transTo.user_id = temp.user_id; transTo.admin_id = temp.admin_id; // End // transTo.voucher_code = temp.voucher_code; transTo.unit_price = tr.unit_price; service.addTransaction(transTo); trans_to.balance = transTo.balance; transTo.unique_key = tr.unique_key; tempTo.is_active = "N"; trans_to.updated_at_ = tr.updated_at; transFrom.updated_at_ = tr.updated_at; // for Weight maintenece // //if (tr.voucher_type == "PV" || tr.voucher_type != "UPPV") // if (transFrom.WEIGHT != null) // { // int weight = Convert.ToInt32(transFrom.WEIGHT); // weight = (int)(weight - temp.net_weight); // transFrom.WEIGHT = weight.ToString(); // } // if (trans_to.WEIGHT != null) // { // int weight = Convert.ToInt32(trans_to.WEIGHT); // weight = (int)(weight + temp.net_weight); // trans_to.WEIGHT = weight.ToString(); // } ////////////////////////// tr.Last_Edit = "None"; transTo.Last_Edit = "None"; service.save(); #region Sale and Purchase order if (temp.order_number != 0 && temp.order_number != -1 && temp.order_number != null) { Database1Entities1 db = new Database1Entities1(); if (temp.order_code == "SO") { Sale_Order so = db.Sale_Order.Find(temp.order_number); so.weight = (int)(so.weight - temp.net_weight); if (so.weight <= 0) { so.is_active = "N"; } } else if (temp.order_code == "PO") { Purchase_Order po = db.Purchase_Order.Find(temp.order_number); po.weight = (int)(po.weight - temp.net_weight); if (po.weight <= 0) { po.is_active = "N"; } } db.SaveChanges(); } #endregion service.balanceUpdation(transFrom.id, trans_to.id); ////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////// if (tr.voucher_type == "SV" || tr.voucher_type == "UPSV") { Transaction transaction = new Transaction(); Transaction transactionTo = new Transaction(); TransactionAccount newTr = new TransactionAccount(); try{ newTr = service.findSaleAccount(transFrom.sale_account_id); } catch (Exception) { return(Content("<script language='javascript' type='text/javascript'>alert('Link sale Account not Found !');</script>")); } transaction.truck = tr.truck; transaction.builty_no_ = tr.builty_no_; transaction.weight_empty = tr.weight_empty; transaction.weight_load = tr.weight_load; transaction.net_weight = tr.net_weight; transaction.quantity = tr.quantity; tr.good_ = good.good_Name; amount = Convert.ToInt32(rate * tr.net_weight); transaction.bags = tr.bags; transaction.created_at = tr.created_at; transaction.updated_at = tr.created_at; transaction.is_active = "Y"; transaction.code = transFrom.id; transaction.description = tr.description; transaction.cr = 0; transaction.dr = amount; transaction.balance = (transFrom.balance - amount); transaction.from_account = transFrom.name; transaction.to_account = trans_to.name; //transFrom.dr_ = amount; transaction.status = "Sale voucher added"; transaction.voucher_type = "SV"; transaction.voucher_code = tr.voucher_code; transaction.trans_acc_id = transFrom.id; if (session != "Admin") { string username = Session["username"].ToString(); User user = service.findUser(username); ViewBag.userName = user.name; transaction.supervisor = user.name; } else { ViewBag.userName = Session["username"].ToString(); transaction.supervisor = Session["username"].ToString(); } transaction.user_id = temp.user_id; transaction.admin_id = temp.admin_id; transaction.from_account = transFrom.name; transaction.to_account = newTr.name; transaction.voucher_code = tr.voucher_code; transaction.unique_key = good.Id; transaction.Last_Edit = tr.Last_Edit; service.addTransaction(transaction); transactionTo.truck = tr.truck; transactionTo.builty_no_ = tr.builty_no_; transactionTo.weight_empty = tr.weight_empty; transactionTo.weight_load = tr.weight_load; transactionTo.net_weight = tr.net_weight; transactionTo.bags = tr.bags; transactionTo.created_at = tr.created_at; transactionTo.updated_at = tr.created_at; transactionTo.is_active = "Y"; transactionTo.quantity = tr.quantity; transactionTo.good_ = tr.good_; transactionTo.code = newTr.id; transactionTo.description = tr.description; transactionTo.dr = 0; transactionTo.cr = amount; transactionTo.balance = (trans_to.balance + amount); transactionTo.from_account = transFrom.name; transaction.to_account = newTr.name; transactionTo.status = "Sale voucher added"; transactionTo.voucher_type = "SV"; transactionTo.trans_acc_id = newTr.id; //newTr.cr_ = amount; if (session != "Admin") { string username = Session["username"].ToString(); User user = service.findUser(username); ViewBag.userName = user.name; transactionTo.supervisor = user.name; } else { ViewBag.userName = Session["username"].ToString(); transactionTo.supervisor = Session["username"].ToString(); } transactionTo.user_id = temp.user_id; transactionTo.admin_id = temp.admin_id; transactionTo.from_account = transFrom.name; transactionTo.to_account = newTr.name; transactionTo.Last_Edit = tr.Last_Edit; service.addTransaction(transactionTo); newTr.balance = newTr.balance + amount; newTr.updated_at_ = tr.updated_at; //newTr.dr_ = newTr.dr_ + amount; int weight = Convert.ToInt32(newTr.WEIGHT); int newWieght = (int)(weight + tr.net_weight); newTr.WEIGHT = newWieght.ToString(); transactionTo.voucher_code = tr.voucher_code; transaction.extra = "Sale"; // for dicriminate sale accounts // transactionTo.extra = "Sale"; service.save(); service.balanceUpdation(transFrom.id, newTr.id); } //////////////////////////////////////////////////////////////////////////// return(RedirectToAction("Supervision", "USER_CRUD")); } catch { if (temp.voucher_type == "SV" || temp.voucher_type == "UPSV") { if (unitPrice == 0) { return(RedirectToAction("Supervision", "USER_CRUD")); //return RedirectToAction("Index"); } else { return(RedirectToAction("Supervision", "USER_CRUD")); //return RedirectToAction("unitPriceSV"); } } else { if (unitPrice == 0) { return(RedirectToAction("purchaseVoucher")); } else { return(RedirectToAction("unitPricePV")); } } } }
/// <summary> /// 创建订单 /// </summary> /// <param name="guid"></param> /// <param name="channelId"></param> /// <param name="uid"></param> /// <param name="userId"></param> /// <param name="orderEntity"></param> /// <returns></returns> public static MResult <ItemOrder> CreateOrder(string guid, int channelId, string uid, int userId, OrderEntity orderEntity) { var result = new MResult <ItemOrder>(true); try { var memberDal = DALFactory.Member(); var baseDataDal = DALFactory.BaseData(); var shoppingCartDal = DALFactory.ShoppingCartDal(); var orderDal = DALFactory.Order(); var payId = MCvHelper.To <int>(orderEntity.payid, -1); #region 验证数据 #region 用户是否登录 if (userId <= 0) { result.msg = "请登录后再操作!"; result.status = MResultStatus.ParamsError; return(result); } #endregion #region 收货地址 if (orderEntity.addressid <= 0) { result.msg = "请选择收货地址!"; result.status = MResultStatus.ParamsError; return(result); } #endregion #region 支付方式 if (payId < 0) { result.msg = "请选择支付方式!"; result.status = MResultStatus.ParamsError; return(result); } #endregion #region 配送方式 if (orderEntity.logisticsid <= 0) { result.msg = "请选择配送方式!"; result.status = MResultStatus.ParamsError; return(result); } #endregion #region 发票信息是否完整 if (orderEntity.titletype == null) { result.msg = "请选择发票类型!"; result.status = MResultStatus.ParamsError; return(result); } if (orderEntity.titletype != Entity.Enum.Invoice.TitleType.NoNeed) { if (orderEntity.invoicecategory == null) { result.msg = "请选择发票分类!"; result.status = MResultStatus.ParamsError; return(result); } if (orderEntity.titletype == Entity.Enum.Invoice.TitleType.Company && string.IsNullOrEmpty(orderEntity.invoicetitle)) { result.msg = "请填写发票抬头!"; result.status = MResultStatus.ParamsError; return(result); } } #endregion #endregion var memberInfo = memberDal.GetMemberInfo(uid); #region 验证用户是否存在 if (memberInfo == null || memberInfo.membNo <= 0) { result.msg = "该用户不存在!"; result.status = MResultStatus.ParamsError; return(result); } #endregion //购物车商品数据 List <ShoppingCartEntity> norMalShoppingCartList = null; #region 判断购物车是否有商品 var shoppingCartList = shoppingCartDal.GetShoppingCartProductInfosByUserIDGuidChannelID(userId, guid, channelId); if (shoppingCartList == null || !shoppingCartList.Any()) { result.msg = "购物车没有商品!"; result.status = MResultStatus.LogicError; return(result); } norMalShoppingCartList = (from a in shoppingCartList where a.intIsDelete == 0 select a).ToList(); if (!norMalShoppingCartList.Any()) { result.msg = "购物车没有商品!"; result.status = MResultStatus.LogicError; return(result); } #endregion #region 该用户是否是黑名单 var isExistBacklist = memberDal.CheckUserIdInBackList(userId); if (isExistBacklist) { result.msg = "您的用户出现异常,请联系我们的客服人员进行解决!"; result.status = MResultStatus.LogicError; return(result); } #endregion //收货地址信息 var addressInfo = memberDal.GetMemberAddressInfo(orderEntity.addressid); #region 验证收货地址 #region 是否存在 if (addressInfo == null || addressInfo.intAddressID <= 0 || addressInfo.intCityID <= 0 && payId <= 0 && orderEntity.logisticsid <= 0) { result.msg = "收货地址信息不正确!"; result.status = MResultStatus.ParamsError; return(result); } #endregion #endregion //配送方式 var deliverInfo = baseDataDal.GetDeliverInfo(orderEntity.logisticsid); #region 验证配送方式 if (deliverInfo == null || deliverInfo.intDeliverID == 0) { result.msg = "验证配送方式信息不正确!"; result.status = MResultStatus.ParamsError; return(result); } #endregion #region 检查商品销售区域 var checkGoodsSaleAreaState = CheckGoodsSaleArea(norMalShoppingCartList, userId, MCvHelper.To <int>(addressInfo.intCityID), channelId); if (checkGoodsSaleAreaState.Any()) { result.msg = "有部分商品不在您选择的区域内销售!"; result.status = MResultStatus.LogicError; result.data = String.Join(",", checkGoodsSaleAreaState.ToArray()); return(result); } #endregion var summaryOrderInfo = SummaryOrderInfo(norMalShoppingCartList, channelId, userId, payId, orderEntity.logisticsid, MCvHelper.To <int>(addressInfo.intCityID)); #region 开始创建订单 if (summaryOrderInfo != null && summaryOrderInfo.TotalGoodsFee > 0) { var order = new Sale_Order(); #region 订单主表信息 order.dtCreateDate = DateTime.Now; order.dtSendDate = CheckDateTime(orderEntity.posttimetype, orderEntity.logisticsid); //处理送货日期 order.intChannel = channelId; order.intCreaterID = 555; order.intDeliverID = orderEntity.logisticsid; order.intLogisticsID = 21; order.intOrderState = 1; order.intOrderType = 1; order.intPayID = payId; order.intPayState = 0; order.intStockID = 100; order.intTotalStars = summaryOrderInfo.TotalScore; order.intUserID = userId; order.numAddAmount = 0; order.numCarriage = summaryOrderInfo.TotalFreight; order.numChange = 0; order.numGoodsAmount = summaryOrderInfo.TotalGoodsFee; order.numCouponAmount = summaryOrderInfo.TotalDiscountFee; order.numReceAmount = summaryOrderInfo.TotalOrderFee; order.numWeight = summaryOrderInfo.TotalWeight; order.vchSendTime = order.dtSendDate.ToShortTimeString(); order.vchUserCode = memberInfo.userCode; order.vchOrderCode = GetOrderCode(); #endregion #region 配送信息 var deliver = new Sale_Order_Deliver(); deliver.intAddressID = addressInfo.intAddressID; deliver.intCityID = MCvHelper.To <int>(addressInfo.intCityID, 0); deliver.vchCityName = addressInfo.vchCityName; deliver.vchConsignee = addressInfo.vchConsignee; deliver.intCountyID = MCvHelper.To <int>(addressInfo.intCountyID, 0); deliver.vchCountyName = addressInfo.vchCountyName; deliver.vchDetailAddr = addressInfo.vchStateName + "," + addressInfo.vchCityName + "," + addressInfo.vchCountyName + "," + addressInfo.vchDetailAddr; deliver.vchHausnummer = addressInfo.vchHausnummer; deliver.vchMobile = addressInfo.vchMobile; deliver.vchPhone = addressInfo.vchPhone; deliver.vchPostCode = addressInfo.vchPostCode; deliver.vchRoadName = addressInfo.vchRoadName; deliver.intStateID = MCvHelper.To <int>(addressInfo.intStateID, 0); deliver.vchStateName = addressInfo.vchStateName; deliver.vchUserMemo = orderEntity.remark; deliver.vchOrderCode = order.vchOrderCode; #endregion #region 发票信息 var invoice = new Sale_Order_Invoice(); if (orderEntity.titletype != null && orderEntity.titletype != Invoice.TitleType.NoNeed) { if (orderEntity.titletype == Invoice.TitleType.Personal) { invoice.vchInvoicTitile = "个人"; } else if (orderEntity.titletype == Invoice.TitleType.Company) { invoice.vchInvoicTitile = orderEntity.invoicetitle; } invoice.intInvoiceType = (int)orderEntity.invoicecategory; invoice.intInvoiceKind = 1; invoice.numAmount = order.numReceAmount; invoice.dtBillingTime = DateTime.Now; invoice.dtCreateDate = DateTime.Now; invoice.intIsBilling = 1; invoice.intIsDetail = 0; invoice.vchOrderCode = order.vchOrderCode; invoice.vchPhone = addressInfo.vchPhone; invoice.intUserID = userId; } #endregion #region 保存订单 string message; result.info.oid = orderDal.SaveWebOrder(order, invoice, deliver, null, userId, guid, channelId, MCvHelper.To <int>(memberInfo.clusterId, 0), -1, out message); if (result.info.oid > 0) { #region 清空购物车 shoppingCartDal.ClearShoppingCart(userId); #endregion #region 步订单信息到 BBHome orderDal.SyncOrderInfoToBBHome(order.vchOrderCode); #endregion result.status = MResultStatus.Success; var payType = string.Empty; if (payId == 0) { payType = "货到付款"; } else if (payId == 1) { payType = "在线支付"; } var postTimetype = string.Empty; switch (orderEntity.posttimetype) { case 1: postTimetype = "工作日送货"; break; case 2: postTimetype = "工作日、双休日均可送货"; break; case 3: postTimetype = "只双休日送货"; break; } result.info.ocode = order.vchOrderCode; result.info.paytype = payType; result.info.logisticstype = deliverInfo.vchDeliverName; result.info.total_fee = order.numGoodsAmount; result.info.total_freight = order.numCarriage; result.info.total_order = order.numReceAmount; result.info.posttimetype = postTimetype; } #endregion } #endregion } catch (Exception ex) { result.status = MResultStatus.ExecutionError; MLogManager.Error(MLogGroup.Order.创建订单, null, "", ex); } return(result); }
/// <summary> /// 创建订单 /// </summary> /// <param name="order"></param> /// <param name="invoice"></param> /// <param name="deliver"></param> /// <param name="orderProm"></param> /// <param name="userId"></param> /// <param name="guid"></param> /// <param name="channelId"></param> /// <param name="clusterId"></param> /// <param name="promID"></param> /// <param name="message"></param> /// <returns></returns> public int SaveWebOrder(Sale_Order order, Sale_Order_Invoice invoice, Sale_Order_Deliver deliver, Sale_Order_Prom_Rela orderProm, int userId, string guid, int channelId, int clusterId, int promID, out string message) { var orderNo = -1; message = ""; var order_rela = new List <Sale_Order_Prom_Rela>(); using (var ctx = new HolycaEntities()) { using (var cart = new HolycaEntities()) { ctx.Connection.Open(); var tran = ctx.Connection.BeginTransaction(); try { //保存订单主表 ctx.Sale_Order.AddObject(order); //先提交得到订单编号 ctx.SaveChanges(); //返回订单编号 orderNo = order.intOrderNO; #region 保存发票表 if (invoice != null) { invoice.vchOrderCode = order.vchOrderCode; invoice.dtCreateDate = DateTime.Now; invoice.dtBillingTime = DateTime.Now; ctx.Sale_Order_Invoice.AddObject(invoice); } #endregion Sale_Order_Detail item = null; //获取购物车信息 var all = from cartItem in cart.Sale_ShoppingCart where cartItem.intUserID == userId && cartItem.intChannelID == channelId && cartItem.intIsDelete == 0 select cartItem; var v = from allitem in all where (allitem.intProductType == null || allitem.intProductType == 0) select allitem; if (v.Any()) { decimal totalMoney = 0; foreach (var cartItem in v) { #region 购物车转订单明细 item = new Sale_Order_Detail(); item.numTotalAmount = ((decimal?)cartItem.numSalePrice ?? 0) * cartItem.intBuyCount; if (invoice != null) { item.intIsInvoice = 1; } else { item.intIsInvoice = 0; } item.numCleanCost = 0; item.numCost = 0; item.intBaseStar = (int?)cartItem.intOrgScore ?? 0; item.intUserID = userId; item.dtOpDate = DateTime.Now; item.vchOrderCode = order.vchOrderCode; item.numStandarPrice = cartItem.numOrgPrice; item.numSalePrice = cartItem.numSalePrice; item.intHerdPriceID = clusterId; item.intProductID = cartItem.intProductID; item.vchProductName = cartItem.nchProductName; item.vchProductPrinted = cartItem.vchProductPrinted; if (promID > 0) { if (cartItem.intPromID > 0) { item.intPromID = cartItem.intPromID ?? 0; } else { item.intPromID = promID; } } else { item.intPromID = cartItem.intPromID ?? 0; } item.intQty = cartItem.intBuyCount; item.intRtnQty = 0; item.intScores = (cartItem.intScore == 0 ? 0 : cartItem.intOrgScore) * cartItem.intBuyCount; item.intChannel = channelId; item.intStockID = order.intStockID; //修复ckid为空的情况 item.intLogisticsID = 21; ctx.Sale_Order_Detail.AddObject(item); totalMoney += item.numTotalAmount; #endregion } #region 促销处理 /* * PromOrderRelation orderrelation = null; * //保存满减促销的关系 * foreach (Sale_ShoppingCart cartItem in p) * { * orderrelation = new PromOrderRelation(); * orderrelation.vchOrderCode = order.vchOrderCode; * orderrelation.intPromID = (int)cartItem.intPromID; * orderrelation.numCouponAmount = cartItem.numSalePrice; * ctx.PromOrderRelation.InsertOnSubmit(orderrelation); * } * * //修改已经保存的满减和购物车关系中的订单号 * //var productrelation= from r in ctx.PromOrderProductRelation * // from q in v * // where r.intShopCartID == q.intShopCartID * // select r; * string intshopcartids = ","; * foreach (Sale_ShoppingCart productid in v) * { * intshopcartids = intshopcartids + productid.intShopCartID.ToString() + ","; * } * * var productrelation = ctx.PromOrderProductRelation.Where(c => intshopcartids.IndexOf("," + c.intShopCartID.ToString() + ",") >= 0).ToList(); * //保存满减促销的关系 * foreach (PromOrderProductRelation pre in productrelation) * { * pre.vchOrderCode = order.vchOrderCode; * ctx.SubmitChanges(); * } */ #endregion #region 货款+运费 if (order.numGoodsAmount != totalMoney - order.numCouponAmount || order.numReceAmount != totalMoney + order.numCarriage - order.numCouponAmount) { order.numGoodsAmount = totalMoney; order.numReceAmount = totalMoney + order.numCarriage; } #endregion #region 保存支付状态 var orderPayStatus = new Sale_Order_PayState(); orderPayStatus.intUserID = 555; //顾客 orderPayStatus.dtOpdate = DateTime.Now; orderPayStatus.vchOrderCode = order.vchOrderCode; orderPayStatus.intPayState = 0; //未付款 ctx.AddToSale_Order_PayState(orderPayStatus); #endregion #region 保存订单状态 var orderStatus = new Sale_Order_State(); orderStatus.intUserID = 555; //顾客 orderStatus.intOrderState = 1; //新建 orderStatus.dtOpdate = DateTime.Now; orderStatus.vchOrderCode = order.vchOrderCode; ctx.Sale_Order_State.AddObject(orderStatus); #endregion #region 保存销售订单配送信息 ctx.Sale_Order_Deliver.AddObject(deliver); ctx.SaveChanges(); #endregion #region 保存订单和促销关系 foreach (var rela_item in v) { var shopcart_rela = cart.Sale_ShopCart_Prom_Rela.FirstOrDefault(c => c.intShopCartID == rela_item.intShopCartID); if (shopcart_rela != null) { orderProm = new Sale_Order_Prom_Rela(); orderProm.vchOrderCode = order.vchOrderCode; orderProm.intChannelID = channelId; orderProm.intUserID = userId; orderProm.intProductID = rela_item.intProductID; orderProm.intPromID = shopcart_rela.intPromID ?? 0; orderProm.intDetailID = item.intDetailID; orderProm.dtCreateDate = DateTime.Now; ctx.Sale_Order_Prom_Rela.AddObject(orderProm); } } #endregion //提交所有更改 tran.Commit(); } } catch (Exception e) { orderNo = -1; message = e.Message; tran.Rollback(); } } } return(orderNo); }
public void addSO(Sale_Order obj) { db.Sale_Order.Add(obj); }