예제 #1
0
 private string SubmitOrder(HttpContext context)
 {
     ShoppingCartInfo info2;
     Action<ShoppingCartItem> action = null;
     ShoppingCartHelper shoppingCartHelper;
     OrderInfo mainOrder;
     Maticsoft.Model.Shop.Order.OrderItems tmpOrderItem;
     JsonObject obj2 = new JsonObject();
     PaymentModeInfo paymentModeInfo = this.GetPaymentModeInfo(context);
     if (paymentModeInfo == null)
     {
         obj2.Accumulate("STATUS", "NOPAYMENTMODEINFO");
         return obj2.ToString();
     }
     User buyerUserInfo = this.GetBuyerUserInfo(context);
     if (buyerUserInfo == null)
     {
         obj2.Accumulate("STATUS", "NOLOGIN");
         return obj2.ToString();
     }
     if (buyerUserInfo.UserType == "AA")
     {
         obj2.Accumulate("STATUS", "UNAUTHORIZED");
         return obj2.ToString();
     }
     try
     {
         info2 = this.GetShoppingCart(context, buyerUserInfo, out shoppingCartHelper);
     }
     catch (ArgumentNullException)
     {
         obj2.Accumulate("STATUS", "PROSALEEXPIRED");
         return obj2.ToString();
     }
     if (((info2 == null) || (info2.Items == null)) || (info2.Items.Count < 1))
     {
         obj2.Accumulate("STATUS", "NOSHOPPINGCARTINFO");
         return obj2.ToString();
     }
     List<ShoppingCartItem> list = new List<ShoppingCartItem>();
     foreach (ShoppingCartItem item in info2.Items)
     {
         if (item.Quantity > this._skuInfoManage.GetStockBySKU(item.SKU))
         {
             list.Add(item);
         }
     }
     if (list.Count > 0)
     {
         obj2.Accumulate("STATUS", "NOSTOCK");
         obj2.Accumulate("DATA", list);
         if (shoppingCartHelper != null)
         {
             if (action == null)
             {
                 action = delegate (ShoppingCartItem info) {
                     shoppingCartHelper.RemoveItem(info.ItemId);
                 };
             }
             list.ForEach(action);
         }
         return obj2.ToString();
     }
     Maticsoft.Model.Shop.Shipping.ShippingAddress shippingAddress = this.GetShippingAddress(context);
     if (shippingAddress == null)
     {
         obj2.Accumulate("STATUS", "NOSHIPPINGADDRESS");
         return obj2.ToString();
     }
     Maticsoft.Model.Ms.Regions modelByCache = this._regionManage.GetModelByCache(shippingAddress.RegionId);
     if (modelByCache == null)
     {
         obj2.Accumulate("STATUS", "NOREGIONINFO");
         return obj2.ToString();
     }
     Maticsoft.Model.Shop.Shipping.ShippingType shippingType = this.GetShippingType(context);
     if (shippingType == null)
     {
         obj2.Accumulate("STATUS", "NOSHIPPINGTYPE");
         return obj2.ToString();
     }
     mainOrder = new OrderInfo {
         CreatedDate = DateTime.Now,
         OrderCode = mainOrder.CreatedDate.ToString("yyyyMMddHHmmssfff"),
         PaymentTypeId = paymentModeInfo.ModeId,
         PaymentTypeName = paymentModeInfo.Name,
         PaymentGateway = paymentModeInfo.Gateway,
         Weight = new int?(info2.TotalWeight),
         FreightAdjusted = mainOrder.FreightActual = mainOrder.Freight = new decimal?(info2.CalcFreight(shippingType)),
         CouponAmount = 0
     };
     string couponCode = context.Request.Form["Coupon"];
     Maticsoft.Model.Shop.Coupon.CouponInfo couponInfo = this.couponBll.GetCouponInfo(couponCode, false);
     if (couponInfo != null)
     {
         mainOrder.CouponAmount = new decimal?(couponInfo.CouponPrice);
         mainOrder.CouponCode = couponInfo.CouponCode;
         mainOrder.CouponName = couponInfo.CouponName;
         mainOrder.CouponValue = new decimal?(couponInfo.CouponPrice);
         mainOrder.CouponValueType = 1;
     }
     mainOrder.ProductTotal = info2.TotalSellPrice;
     decimal totalCostPrice = info2.TotalCostPrice;
     mainOrder.OrderCostPrice = totalCostPrice + mainOrder.FreightActual;
     mainOrder.OrderTotal = info2.TotalSellPrice + mainOrder.Freight.Value;
     mainOrder.Amount = (info2.TotalAdjustedPrice + mainOrder.FreightAdjusted.Value) - mainOrder.CouponAmount.Value;
     mainOrder.OrderType = 1;
     mainOrder.OrderStatus = 0;
     mainOrder.BuyerID = buyerUserInfo.UserID;
     mainOrder.BuyerName = buyerUserInfo.UserName;
     mainOrder.BuyerEmail = string.IsNullOrWhiteSpace(buyerUserInfo.Email) ? "*****@*****.**" : buyerUserInfo.Email;
     mainOrder.BuyerCellPhone = buyerUserInfo.Phone;
     Dictionary<int, List<Maticsoft.Model.Shop.Order.OrderItems>> dicSuppOrderItems = new Dictionary<int, List<Maticsoft.Model.Shop.Order.OrderItems>>();
     int orderPoint = 0;
     info2.Items.ForEach(delegate (ShoppingCartItem item) {
         Maticsoft.Model.Shop.Order.OrderItems items = new Maticsoft.Model.Shop.Order.OrderItems {
             Name = item.Name,
             SKU = item.SKU,
             Quantity = item.Quantity,
             ShipmentQuantity = item.Quantity,
             ThumbnailsUrl = item.ThumbnailsUrl,
             Points = item.Points,
             Weight = item.Weight,
             ProductId = item.ProductId,
             Description = item.Description,
             CostPrice = item.CostPrice,
             SellPrice = item.SellPrice,
             AdjustedPrice = item.AdjustedPrice,
             Deduct = new decimal?(item.SellPrice - item.AdjustedPrice),
             SupplierId = item.SupplierId,
             SupplierName = item.SupplierName
         };
         tmpOrderItem = items;
         if ((item.SkuValues != null) && (item.SkuValues.Length > 0))
         {
             tmpOrderItem.Attribute = string.Join(",", item.SkuValues);
         }
         mainOrder.OrderItems.Add(tmpOrderItem);
         if (tmpOrderItem.SupplierId.HasValue && (tmpOrderItem.SupplierId.Value > 0))
         {
             if (dicSuppOrderItems.ContainsKey(tmpOrderItem.SupplierId.Value))
             {
                 dicSuppOrderItems[tmpOrderItem.SupplierId.Value].Add(tmpOrderItem);
             }
             else
             {
                 List<Maticsoft.Model.Shop.Order.OrderItems> list = new List<Maticsoft.Model.Shop.Order.OrderItems> {
                     tmpOrderItem
                 };
                 dicSuppOrderItems.Add(tmpOrderItem.SupplierId.Value, list);
             }
         }
         orderPoint += tmpOrderItem.Points;
     });
     mainOrder.OrderPoint = orderPoint;
     mainOrder.RegionId = new int?(shippingAddress.RegionId);
     mainOrder.ShipRegion = modelByCache.RegionName;
     mainOrder.ShipName = shippingAddress.ShipName;
     mainOrder.ShipEmail = shippingAddress.EmailAddress;
     mainOrder.ShipCellPhone = shippingAddress.CelPhone;
     mainOrder.ShipTelPhone = shippingAddress.TelPhone;
     mainOrder.ShipAddress = shippingAddress.Address;
     mainOrder.ShipZipCode = shippingAddress.Zipcode;
     mainOrder.ShippingModeId = new int?(shippingType.ModeId);
     mainOrder.ShippingModeName = shippingType.Name;
     mainOrder.RealShippingModeId = new int?(shippingType.ModeId);
     mainOrder.RealShippingModeName = shippingType.Name;
     mainOrder.ShippingStatus = 0;
     mainOrder.ExpressCompanyName = shippingType.ExpressCompanyName;
     mainOrder.ExpressCompanyAbb = shippingType.ExpressCompanyEn;
     Maticsoft.BLL.Shop.Supplier.SupplierInfo info4 = new Maticsoft.BLL.Shop.Supplier.SupplierInfo();
     if (dicSuppOrderItems.Count > 1)
     {
         foreach (KeyValuePair<int, List<Maticsoft.Model.Shop.Order.OrderItems>> pair in dicSuppOrderItems)
         {
             OrderInfo subOrder;
             subOrder = new OrderInfo(mainOrder) {
                 Weight = 0,
                 FreightAdjusted = subOrder.FreightActual = subOrder.Freight = 0,
                 OrderPoint = 0,
                 ProductTotal = 0M,
                 OrderCostPrice = 0,
                 OrderOptionPrice = 0,
                 OrderProfit = 0,
                 Amount = 0M
             };
             pair.Value.ForEach(delegate (Maticsoft.Model.Shop.Order.OrderItems info) {
                 int? weight = subOrder.Weight;
                 int num = info.Weight;
                 subOrder.Weight = weight.HasValue ? new int?(weight.GetValueOrDefault() + num) : null;
                 subOrder.OrderPoint += info.Points;
                 subOrder.ProductTotal += info.SellPrice * info.Quantity;
                 decimal? orderCostPrice = subOrder.OrderCostPrice;
                 decimal num2 = info.CostPrice * info.Quantity;
                 subOrder.OrderCostPrice = orderCostPrice.HasValue ? new decimal?(orderCostPrice.GetValueOrDefault() + num2) : null;
                 subOrder.Amount += info.AdjustedPrice * info.Quantity;
             });
             decimal? freightAdjusted = mainOrder.FreightAdjusted;
             decimal count = dicSuppOrderItems.Count;
             subOrder.FreightAdjusted = subOrder.FreightActual = subOrder.Freight = freightAdjusted.HasValue ? new decimal?(freightAdjusted.GetValueOrDefault() / count) : null;
             subOrder.OrderTotal = subOrder.ProductTotal + subOrder.Freight.Value;
             subOrder.Amount += subOrder.FreightAdjusted.Value;
             subOrder.OrderItems = pair.Value;
             subOrder.OrderType = 2;
             Maticsoft.Model.Shop.Supplier.SupplierInfo info5 = info4.GetModelByCache(pair.Key);
             if (info5 == null)
             {
                 obj2.Accumulate("STATUS", "NOSUPPLIERINFO");
                 return obj2.ToString();
             }
             subOrder.SupplierId = new int?(info5.SupplierId);
             subOrder.SupplierName = info5.Name;
             subOrder.CreatedDate = DateTime.Now;
             subOrder.OrderCode = subOrder.CreatedDate.ToString("yyyyMMddHHmmssfff");
             mainOrder.SubOrders.Add(subOrder);
         }
         mainOrder.HasChildren = true;
     }
     else
     {
         mainOrder.SupplierId = info2.Items[0].SupplierId;
         mainOrder.SupplierName = info2.Items[0].SupplierName;
         mainOrder.HasChildren = false;
     }
     try
     {
         mainOrder.OrderId = OrderManage.CreateOrder(mainOrder);
     }
     catch (Exception exception)
     {
         LogHelp.AddErrorLog("订单创建失败: " + exception.Message, exception.StackTrace, context.Request);
     }
     obj2.Accumulate("DATA", new { OrderId = mainOrder.OrderId, OrderCode = mainOrder.OrderCode, Amount = mainOrder.Amount, PaymentTypeId = mainOrder.PaymentTypeId, PaymentTypeName = mainOrder.PaymentTypeName });
     if (mainOrder.OrderId == -1L)
     {
         obj2.Accumulate("STATUS", "FAILED");
         return obj2.ToString();
     }
     if (!string.IsNullOrWhiteSpace(couponCode))
     {
         this.couponBll.UseCoupon(couponCode, mainOrder.BuyerID, mainOrder.BuyerEmail);
     }
     if (shoppingCartHelper != null)
     {
         shoppingCartHelper.ClearShoppingCart();
     }
     obj2.Accumulate("STATUS", "SUCCESS");
     return obj2.ToString();
 }
예제 #2
0
 public Maticsoft.Model.Shop.Order.OrderItems DataRowToModel(DataRow row)
 {
     Maticsoft.Model.Shop.Order.OrderItems items = new Maticsoft.Model.Shop.Order.OrderItems();
     if (row != null)
     {
         if ((row["ItemId"] != null) && (row["ItemId"].ToString() != ""))
         {
             items.ItemId = long.Parse(row["ItemId"].ToString());
         }
         if ((row["OrderId"] != null) && (row["OrderId"].ToString() != ""))
         {
             items.OrderId = long.Parse(row["OrderId"].ToString());
         }
         if (row["OrderCode"] != null)
         {
             items.OrderCode = row["OrderCode"].ToString();
         }
         if ((row["ProductId"] != null) && (row["ProductId"].ToString() != ""))
         {
             items.ProductId = long.Parse(row["ProductId"].ToString());
         }
         if (row["ProductCode"] != null)
         {
             items.ProductCode = row["ProductCode"].ToString();
         }
         if (row["SKU"] != null)
         {
             items.SKU = row["SKU"].ToString();
         }
         if (row["Name"] != null)
         {
             items.Name = row["Name"].ToString();
         }
         if (row["ThumbnailsUrl"] != null)
         {
             items.ThumbnailsUrl = row["ThumbnailsUrl"].ToString();
         }
         if (row["Description"] != null)
         {
             items.Description = row["Description"].ToString();
         }
         if ((row["Quantity"] != null) && (row["Quantity"].ToString() != ""))
         {
             items.Quantity = int.Parse(row["Quantity"].ToString());
         }
         if ((row["ShipmentQuantity"] != null) && (row["ShipmentQuantity"].ToString() != ""))
         {
             items.ShipmentQuantity = int.Parse(row["ShipmentQuantity"].ToString());
         }
         if ((row["CostPrice"] != null) && (row["CostPrice"].ToString() != ""))
         {
             items.CostPrice = decimal.Parse(row["CostPrice"].ToString());
         }
         if ((row["SellPrice"] != null) && (row["SellPrice"].ToString() != ""))
         {
             items.SellPrice = decimal.Parse(row["SellPrice"].ToString());
         }
         if ((row["AdjustedPrice"] != null) && (row["AdjustedPrice"].ToString() != ""))
         {
             items.AdjustedPrice = decimal.Parse(row["AdjustedPrice"].ToString());
         }
         if (row["Attribute"] != null)
         {
             items.Attribute = row["Attribute"].ToString();
         }
         if (row["Remark"] != null)
         {
             items.Remark = row["Remark"].ToString();
         }
         if ((row["Weight"] != null) && (row["Weight"].ToString() != ""))
         {
             items.Weight = int.Parse(row["Weight"].ToString());
         }
         if ((row["Deduct"] != null) && (row["Deduct"].ToString() != ""))
         {
             items.Deduct = new decimal?(decimal.Parse(row["Deduct"].ToString()));
         }
         if ((row["Points"] != null) && (row["Points"].ToString() != ""))
         {
             items.Points = int.Parse(row["Points"].ToString());
         }
         if ((row["ProductLineId"] != null) && (row["ProductLineId"].ToString() != ""))
         {
             items.ProductLineId = new int?(int.Parse(row["ProductLineId"].ToString()));
         }
         if ((row["SupplierId"] != null) && (row["SupplierId"].ToString() != ""))
         {
             items.SupplierId = new int?(int.Parse(row["SupplierId"].ToString()));
         }
         if (row["SupplierName"] != null)
         {
             items.SupplierName = row["SupplierName"].ToString();
         }
     }
     return items;
 }