public static int CreatOrder(OrderInfo orderInfo, bool isUseBalance, decimal remainingMondy) { int num = 0; if (orderInfo.GetTotal() <= 0m) { orderInfo.OrderStatus = OrderStatus.BuyerAlreadyPaid; orderInfo.PayDate = new DateTime?(DateTime.Now); } if (orderInfo.PaymentType == null && orderInfo.PointExchange > 0) { orderInfo.PaymentType = "积分抵现"; orderInfo.Gateway = "hishop.plugins.payment.pointtocach"; orderInfo.PaymentTypeId = 77; } else if (orderInfo.PaymentType == null && orderInfo.RedPagerID.HasValue && orderInfo.RedPagerID.Value > 0) { orderInfo.PaymentType = "优惠券抵扣"; orderInfo.Gateway = "hishop.plugins.payment.coupontocach"; orderInfo.PaymentTypeId = 55; } MemberInfo currentMember = MemberProcessor.GetCurrentMember(); Database database = DatabaseFactory.CreateDatabase(); int quantity = orderInfo.LineItems.Sum((KeyValuePair <string, LineItemInfo> item) => item.Value.Quantity); int result; lock (ShoppingProcessor.createOrderLocker) { if (orderInfo.GroupBuyId > 0) { ShoppingProcessor.checkCanGroupBuy(quantity, orderInfo.GroupBuyId); } using (System.Data.Common.DbConnection dbConnection = database.CreateConnection()) { dbConnection.Open(); System.Data.Common.DbTransaction dbTransaction = dbConnection.BeginTransaction(); try { orderInfo.ClientShortType = (ClientShortType)Globals.GetClientShortType(); if (!new OrderDao().CreatOrder(orderInfo, dbTransaction)) { dbTransaction.Rollback(); result = 0; return(result); } if (orderInfo.LineItems.Count > 0) { if (orderInfo.OrderStatus == OrderStatus.BuyerAlreadyPaid) { foreach (LineItemInfo lineItemInfo in orderInfo.LineItems.Values) { lineItemInfo.OrderItemsStatus = OrderStatus.BuyerAlreadyPaid; } } if (!new LineItemDao().AddOrderLineItems(orderInfo.OrderId, orderInfo.LineItems.Values, dbTransaction)) { dbTransaction.Rollback(); result = 0; return(result); } } if (!string.IsNullOrEmpty(orderInfo.CouponCode)) { if (!new CouponDao().AddCouponUseRecord(orderInfo, dbTransaction)) { dbTransaction.Rollback(); result = 0; return(result); } } ICollection values = orderInfo.LineItems.Values; foreach (LineItemInfo lineItemInfo in values) { if (lineItemInfo.Type == 1) { if (lineItemInfo.ExchangeId > 0) { PointExchangeChangedInfo pointExchangeChangedInfo = new PointExchangeChangedInfo(); pointExchangeChangedInfo.exChangeId = lineItemInfo.ExchangeId; pointExchangeChangedInfo.exChangeName = new OrderDao().GetexChangeName(pointExchangeChangedInfo.exChangeId); pointExchangeChangedInfo.ProductId = lineItemInfo.ProductId; pointExchangeChangedInfo.PointNumber = lineItemInfo.PointNumber; pointExchangeChangedInfo.MemberID = orderInfo.UserId; pointExchangeChangedInfo.Date = DateTime.Now; pointExchangeChangedInfo.MemberGrades = currentMember.GradeId; if (!new OrderDao().InsertPointExchange_Changed(pointExchangeChangedInfo, dbTransaction, lineItemInfo.Quantity)) { dbTransaction.Rollback(); result = 0; return(result); } IntegralDetailInfo integralDetailInfo = new IntegralDetailInfo(); integralDetailInfo.IntegralChange = -lineItemInfo.PointNumber; integralDetailInfo.IntegralSource = "积分兑换商品-订单号:" + orderInfo.OrderMarking; integralDetailInfo.IntegralSourceType = 2; integralDetailInfo.Remark = "积分兑换商品"; integralDetailInfo.Userid = orderInfo.UserId; integralDetailInfo.GoToUrl = Globals.ApplicationPath + "/Vshop/MemberOrderDetails.aspx?OrderId=" + orderInfo.OrderId; integralDetailInfo.IntegralStatus = Convert.ToInt32(IntegralDetailStatus.IntegralExchange); if (!new IntegralDetailDao().AddIntegralDetail(integralDetailInfo, dbTransaction)) { dbTransaction.Rollback(); result = 0; return(result); } } } } if (orderInfo.PointExchange > 0) { IntegralDetailInfo integralDetailInfo = new IntegralDetailInfo(); integralDetailInfo.IntegralChange = -orderInfo.PointExchange; integralDetailInfo.IntegralSource = "积分抵现,订单号:" + orderInfo.OrderId; integralDetailInfo.IntegralSourceType = 2; integralDetailInfo.Remark = ""; integralDetailInfo.Userid = orderInfo.UserId; integralDetailInfo.GoToUrl = Globals.ApplicationPath + "/Vshop/MemberOrderDetails.aspx?OrderId=" + orderInfo.OrderId; integralDetailInfo.IntegralStatus = Convert.ToInt32(IntegralDetailStatus.NowArrived); if (!new IntegralDetailDao().AddIntegralDetail(integralDetailInfo, dbTransaction)) { dbTransaction.Rollback(); result = 0; return(result); } } if (orderInfo.RedPagerID > 0) { if (!new OrderDao().UpdateCoupon_MemberCoupons(orderInfo, dbTransaction)) { dbTransaction.Rollback(); result = 0; return(result); } } dbTransaction.Commit(); num = 1; if (orderInfo.OrderStatus == OrderStatus.BuyerAlreadyPaid) { num = 2; } } catch { dbTransaction.Rollback(); throw; } finally { dbConnection.Close(); } } } if (isUseBalance && num == 1) { orderInfo = new OrderDao().GetOrderInfo(orderInfo.OrderId); lock (ShoppingProcessor.BalanceUpdateLock) { num = ShoppingProcessor.OrderBalanceUpdate(orderInfo, currentMember.UserId, remainingMondy); } } result = num; return(result); }
public static bool CreatOrder(OrderInfo orderInfo) { bool flag = false; if (orderInfo.GetTotal() == 0m) { orderInfo.OrderStatus = OrderStatus.BuyerAlreadyPaid; } Database database = DatabaseFactory.CreateDatabase(); int quantity = orderInfo.LineItems.Sum((KeyValuePair <string, LineItemInfo> item) => item.Value.Quantity); bool result; lock (ShoppingProcessor.createOrderLocker) { if (orderInfo.GroupBuyId > 0) { ShoppingProcessor.checkCanGroupBuy(quantity, orderInfo.GroupBuyId); } using (System.Data.Common.DbConnection dbConnection = database.CreateConnection()) { dbConnection.Open(); System.Data.Common.DbTransaction dbTransaction = dbConnection.BeginTransaction(); try { orderInfo.ClientShortType = (ClientShortType)Globals.GetClientShortType(); if (!new OrderDao().CreatOrder(orderInfo, dbTransaction)) { dbTransaction.Rollback(); result = false; return(result); } if (orderInfo.LineItems.Count > 0) { if (!new LineItemDao().AddOrderLineItems(orderInfo.OrderId, orderInfo.LineItems.Values, dbTransaction)) { dbTransaction.Rollback(); result = false; return(result); } } if (!string.IsNullOrEmpty(orderInfo.CouponCode)) { if (!new CouponDao().AddCouponUseRecord(orderInfo, dbTransaction)) { dbTransaction.Rollback(); result = false; return(result); } } ICollection values = orderInfo.LineItems.Values; MemberInfo currentMember = MemberProcessor.GetCurrentMember(); foreach (LineItemInfo lineItemInfo in values) { if (lineItemInfo.Type == 1) { if (lineItemInfo.ExchangeId > 0) { PointExchangeChangedInfo pointExchangeChangedInfo = new PointExchangeChangedInfo(); pointExchangeChangedInfo.exChangeId = lineItemInfo.ExchangeId; pointExchangeChangedInfo.exChangeName = new OrderDao().GetexChangeName(pointExchangeChangedInfo.exChangeId); pointExchangeChangedInfo.ProductId = lineItemInfo.ProductId; pointExchangeChangedInfo.PointNumber = lineItemInfo.PointNumber; pointExchangeChangedInfo.MemberID = orderInfo.UserId; pointExchangeChangedInfo.Date = DateTime.Now; pointExchangeChangedInfo.MemberGrades = currentMember.GradeId; if (!new OrderDao().InsertPointExchange_Changed(pointExchangeChangedInfo, dbTransaction, lineItemInfo.Quantity)) { dbTransaction.Rollback(); result = false; return(result); } IntegralDetailInfo integralDetailInfo = new IntegralDetailInfo(); integralDetailInfo.IntegralChange = -lineItemInfo.PointNumber; integralDetailInfo.IntegralSource = "积分兑换商品-订单号:" + orderInfo.OrderMarking; integralDetailInfo.IntegralSourceType = 2; integralDetailInfo.Remark = "积分兑换商品"; integralDetailInfo.Userid = orderInfo.UserId; integralDetailInfo.GoToUrl = Globals.ApplicationPath + "/Vshop/MemberOrderDetails.aspx?OrderId=" + orderInfo.OrderId; integralDetailInfo.IntegralStatus = Convert.ToInt32(IntegralDetailStatus.IntegralExchange); if (!new IntegralDetailDao().AddIntegralDetail(integralDetailInfo, dbTransaction)) { dbTransaction.Rollback(); result = false; return(result); } } } } if (orderInfo.PointExchange > 0) { IntegralDetailInfo integralDetailInfo = new IntegralDetailInfo(); integralDetailInfo.IntegralChange = -orderInfo.PointExchange; integralDetailInfo.IntegralSource = "积分抵现-订单号:" + orderInfo.OrderMarking; integralDetailInfo.IntegralSourceType = 2; integralDetailInfo.Remark = "积分抵现"; integralDetailInfo.Userid = orderInfo.UserId; integralDetailInfo.GoToUrl = Globals.ApplicationPath + "/Vshop/MemberOrderDetails.aspx?OrderId=" + orderInfo.OrderId; integralDetailInfo.IntegralStatus = Convert.ToInt32(IntegralDetailStatus.NowArrived); if (!new IntegralDetailDao().AddIntegralDetail(integralDetailInfo, dbTransaction)) { dbTransaction.Rollback(); result = false; return(result); } } if (orderInfo.RedPagerID > 0) { if (!new OrderDao().UpdateCoupon_MemberCoupons(orderInfo, dbTransaction)) { dbTransaction.Rollback(); result = false; return(result); } } dbTransaction.Commit(); flag = true; } catch { dbTransaction.Rollback(); throw; } finally { dbConnection.Close(); } } } result = flag; return(result); }