Exemplo n.º 1
0
        /// <summary>
        /// 购物车方式提交的订单
        /// </summary>
        /// <param name="value">数据</param>
        private object SubmitOrderByCart(OrderSubmitOrderByCartModel value)
        {
            string cartItemIds      = value.cartItemIds;
            long   recieveAddressId = value.recieveAddressId;
            string couponIds        = value.couponIds;
            int    integral         = value.integral;

            bool   isCashOnDelivery = value.isCashOnDelivery;
            int    invoiceType      = value.invoiceType;
            string invoiceTitle     = value.invoiceTitle;
            string invoiceContext   = value.invoiceContext;
            //end
            string           orderRemarks = "";//value.orderRemarks;//订单备注
            OrderCreateModel model        = new OrderCreateModel();
            List <OrderInfo> infos        = new List <OrderInfo>();

            var orderService = ServiceProvider.Instance <IOrderService> .Create;
            IEnumerable <long> orderIds;

            model.PlatformType     = PlatformType.WeiXinSmallProg;
            model.CurrentUser      = CurrentUser;
            model.ReceiveAddressId = recieveAddressId;
            model.Integral         = integral;

            model.formId = value.formId;

            model.IsCashOnDelivery = isCashOnDelivery;
            model.Invoice          = (InvoiceType)invoiceType;
            model.InvoiceContext   = invoiceContext;
            model.InvoiceTitle     = invoiceTitle;
            //end
            CommonModel.OrderShop[] OrderShops = Newtonsoft.Json.JsonConvert.DeserializeObject <OrderShop[]>(value.jsonOrderShops);
            model.OrderShops   = OrderShops;//用户APP选择门店自提时用到,2.5版本未支持门店自提
            model.OrderRemarks = OrderShops.Select(p => p.Remark).ToArray();
            try
            {
                var cartItemIdsArr = cartItemIds.Split(',').Select(item => long.Parse(item)).ToArray();
                //根据购物车项补充sku数据
                var cartItems = CartApplication.GetCartItems(cartItemIdsArr);
                model.SkuIds = cartItems.Select(e => e.SkuId).ToList();
                model.Counts = cartItems.Select(e => e.Quantity).ToList();

                model.CartItemIds  = cartItemIdsArr;
                model.CouponIdsStr = OrderHelper.ConvertUsedCoupon(couponIds);

                var orders = orderService.CreateOrder(model);
                orderIds = orders.Select(item => item.Id).ToArray();
                decimal orderTotals = orders.Sum(item => item.OrderTotalAmount);

                return(Json(new { Status = "OK", Message = "提交成功", OrderId = string.Join(",", orderIds), OrderTotal = orderTotals }));
            }
            catch (HimallException he)
            {
                return(Json(new { Status = "NO", Message = he.Message }));
            }
        }
Exemplo n.º 2
0
        public JsonResult GetCartProducts()
        {
            var memberId  = CurrentUser?.Id ?? 0;
            var cartItems = CartApplication.GetCartItems(memberId);
            var products  = cartItems.Select(item =>
            {
                var product = item.Product;
                var shop    = ShopApplication.GetShop(product.ShopId);
                var sku     = item.Sku;
                return(new
                {
                    cartItemId = item.ItemId,
                    skuId = sku.Id,
                    id = product.Id,
                    imgUrl = Himall.Core.HimallIO.GetProductSizeImage(product.RelativePath, 1, (int)ImageSize.Size_50),
                    name = product.ProductName,
                    productstatus = item.IsLimit ? 0 : (sku.Stock <= 0 ? ProductInfo.ProductSaleStatus.InStock.GetHashCode() : product.SaleStatus.GetHashCode()),
                    status = item.ShowStatus,
                    productauditstatus = product.AuditStatus,
                    price = sku.SalePrice,
                    Color = sku.Color,
                    Size = sku.Size,
                    Version = sku.Version,
                    count = item.Quantity,
                    shopId = shop.Id,
                    shopName = shop.ShopName,
                    productcode = !(sku.Version + sku.Color + sku.Size).Equals("") ? sku.Sku : product.ProductCode,
                    ColorAlias = sku.ColorAlias,
                    SizeAlias = sku.SizeAlias,
                    VersionAlias = sku.VersionAlias,
                    AddTime = item.AddTime,
                    minMath = item.Quantity < item.MinMach ? 0 : 1
                });
            }).OrderBy(s => s.status).ThenByDescending(o => o.AddTime).ToList();

            var newproducts = products.Where(p => p.status == 0 && p.productauditstatus != Entities.ProductInfo.ProductAuditStatus.InfractionSaleOff && p.productauditstatus != Entities.ProductInfo.ProductAuditStatus.WaitForAuditing);//获取有效商品
            var cartModel   = new
            {
                products,
                amount     = newproducts.Sum(item => item.price * item.count),
                totalCount = newproducts.Sum(item => item.count),
            };

            return(Json(cartModel));
        }
Exemplo n.º 3
0
        public object PostSubmitOrderByCart(OrderSubmitOrderByCartModel value)
        {
            CheckUserLogin();
            if (value.CapitalAmount > 0 && !string.IsNullOrEmpty(value.PayPwd))
            {
                var flag = MemberApplication.VerificationPayPwd(CurrentUser.Id, value.PayPwd);
                if (!flag)
                {
                    throw new MallApiException("预存款支付密码错误");
                }
            }

            string cartItemIds = value.cartItemIds;
            long recieveAddressId = value.recieveAddressId;
            string couponIds = value.couponIds;
            int integral = value.integral;

            bool isCashOnDelivery = value.isCashOnDelivery;
            int invoiceType = value.invoiceType;
            string invoiceTitle = value.invoiceTitle;
            string invoiceContext = value.invoiceContext;


            IEnumerable<long> orderIds;

           
            CommonModel.OrderShop[] OrderShops = Newtonsoft.Json.JsonConvert.DeserializeObject<OrderShop[]>(value.jsonOrderShops);

            OrderPostModel model = new OrderPostModel();
            model.CurrentUser = CurrentUser;
            model.PlatformType = PlatformType.Android.GetHashCode();
            model.IsShopbranchOrder = true;
            model.RecieveAddressId = recieveAddressId;
            model.Integral = integral;
            model.Capital = value.CapitalAmount;
            model.IsCashOnDelivery = isCashOnDelivery;
            //model.InvoiceType = invoiceType;
            //model.InvoiceContext = invoiceContext;
            //model.InvoiceTitle = invoiceTitle;
            //model.InvoiceCode = value.invoiceCode;
            model.OrderShops = OrderShops;//用户APP选择门店自提时用到,2.5版本未支持门店自提
            model.CartItemIds = cartItemIds;
            model.IsShopbranchOrder = true;
            if (model.OrderShops == null || model.OrderShops.Count() < 1)
            {
                throw new MallApiException("订单信息错误");
            }
            try
            {
                var cartItemIdsArr = cartItemIds.Split(',').Where(d => !string.IsNullOrWhiteSpace(d)).Select(item => long.Parse(item)).ToArray();
                //根据购物车项补充sku数据
                var cartItems = CartApplication.GetCartItems(cartItemIdsArr);
                List<OrderSku> skus = new List<OrderSku>();
                foreach (var _item in cartItems)
                {
                    OrderSku _tmp = new OrderSku();
                    _tmp.SkuId = _item.SkuId;
                    _tmp.Count = _item.Quantity;
                    skus.Add(_tmp);
                }

                model.CouponIds = couponIds;
                model.OrderShops[0].OrderSkus = skus.ToArray();
                var result = OrderApplication.SubmitOrder(model, value.PayPwd);
                orderIds = result.OrderIds;
                decimal orderTotals = result.OrderTotal;
                var _result = new { success = true, OrderIds = orderIds, RealTotalIsZero = orderTotals == 0 };
                return _result;
            }
            catch (MallException he)
            {
                return ErrorResult(he.Message);
            }
            catch (Exception ex)
            {
                return ErrorResult("提交订单异常");
            }
        }
        public object PostSubmitOrderByCart(OrderSubmitOrderByCartModel value)
        {
            this.CheckUserLogin();
            if (value.CapitalAmount > new Decimal(0) && !string.IsNullOrEmpty(value.PayPwd) && !MemberApplication.VerificationPayPwd(this.CurrentUser.Id, value.PayPwd))
            {
                return((object)this.Json(new
                {
                    Success = "false",
                    Msg = "预付款支付密码错误"
                }));
            }
            string           cartItemIds      = value.cartItemIds;
            long             recieveAddressId = value.recieveAddressId;
            string           couponIds        = value.couponIds;
            int              integral         = value.integral;
            bool             isCashOnDelivery = value.isCashOnDelivery;
            int              invoiceType      = value.invoiceType;
            string           invoiceTitle     = value.invoiceTitle;
            string           invoiceContext   = value.invoiceContext;
            OrderCreateModel model            = new OrderCreateModel();
            IOrderService    create           = Instance <IOrderService> .Create;

            model.PlatformType     = PlatformType.Android;
            model.CurrentUser      = this.CurrentUser;
            model.ReceiveAddressId = recieveAddressId;
            model.Integral         = integral;
            model.Capital          = value.CapitalAmount;
            model.IsCashOnDelivery = isCashOnDelivery;
            model.Invoice          = (InvoiceType)invoiceType;
            model.InvoiceContext   = invoiceContext;
            model.InvoiceTitle     = invoiceTitle;
            model.InvoiceCode      = value.invoiceCode;
            OrderShop[] orderShopArray = JsonConvert.DeserializeObject <OrderShop[]>(value.jsonOrderShops);
            model.OrderShops   = orderShopArray;
            model.OrderRemarks = (IEnumerable <string>)Enumerable.ToArray <string>(Enumerable.Select <OrderShop, string>((IEnumerable <OrderShop>)orderShopArray, (Func <OrderShop, string>)(p => p.Remark)));
            try
            {
                long[] numArray = Enumerable.ToArray <long>(Enumerable.Select <string, long>(Enumerable.Where <string>((IEnumerable <string>)cartItemIds.Split(','), (Func <string, bool>)(d => !string.IsNullOrWhiteSpace(d))), (Func <string, long>)(item => long.Parse(item))));
                IQueryable <ShoppingCartItem> cartItems = CartApplication.GetCartItems((IEnumerable <long>)numArray);
                model.SkuIds       = (IEnumerable <string>)Enumerable.ToList <string>((IEnumerable <string>)Queryable.Select <ShoppingCartItem, string>(cartItems, (Expression <Func <ShoppingCartItem, string> >)(e => e.SkuId)));
                model.Counts       = (IEnumerable <int>)Enumerable.ToList <int>((IEnumerable <int>)Queryable.Select <ShoppingCartItem, int>(cartItems, (Expression <Func <ShoppingCartItem, int> >)(e => e.Quantity)));
                model.CartItemIds  = numArray;
                model.CouponIdsStr = OrderHelper.ConvertUsedCoupon(couponIds);
                List <OrderInfo>   order      = create.CreateOrder(model);
                IEnumerable <long> enumerable = (IEnumerable <long>)Enumerable.ToArray <long>(Enumerable.Select <OrderInfo, long>((IEnumerable <OrderInfo>)order, (Func <OrderInfo, long>)(item => item.Id)));
                Decimal            num        = Enumerable.Sum <OrderInfo>((IEnumerable <OrderInfo>)order, (Func <OrderInfo, Decimal>)(item => item.OrderTotalAmount));
                string             str        = "false";
                if (num == new Decimal(0))
                {
                    str = "true";
                }
                return((object)this.Json(new
                {
                    Success = "true",
                    OrderIds = enumerable,
                    RealTotalIsZero = str
                }));
            }
            catch (HimallException ex)
            {
                return((object)this.Json(new
                {
                    Success = "false",
                    Msg = ex.Message
                }));
            }
            catch (Exception ex)
            {
                return((object)this.Json(new
                {
                    Success = "false",
                    Msg = "提交订单异常"
                }));
            }
        }
Exemplo n.º 5
0
        public JsonResult GetCartProducts()
        {
            var memberId  = CurrentUser?.Id ?? 0;
            var cartItems = CartApplication.GetCartItems(memberId);
            var vshops    = VshopApplication.GetVShopsByShopIds(cartItems.Select(p => p.Shop.Id));
            var products  = cartItems.Select(item =>
            {
                var sku     = item.Sku;
                var product = item.Product;
                var shop    = item.Shop;
                var vshop   = vshops.FirstOrDefault(p => p.ShopId == shop.Id);

                var skuDetails = string.Empty;
                if (!string.IsNullOrWhiteSpace(sku.Size))
                {
                    skuDetails += sku.SizeAlias + ":" + sku.Size + "&nbsp;&nbsp;";
                }
                if (!string.IsNullOrWhiteSpace(sku.Color))
                {
                    skuDetails += sku.ColorAlias + ":" + sku.Color + "&nbsp;&nbsp;";
                }
                if (!string.IsNullOrWhiteSpace(sku.Version))
                {
                    skuDetails += sku.VersionAlias + ":" + sku.Version + "&nbsp;&nbsp;";
                }


                return(new
                {
                    cartItemId = item.ItemId,
                    skuId = sku.Id,
                    id = product.Id,
                    imgUrl = Himall.Core.HimallIO.GetProductSizeImage(product.RelativePath, 1, (int)ImageSize.Size_150),
                    name = product.ProductName,
                    price = sku.SalePrice,
                    count = item.Quantity,
                    shopId = shop.Id,
                    vshopId = vshop == null ? 0 : vshop.Id,
                    shopName = shop.ShopName,
                    shopLogo = vshop == null ? "" : vshop.Logo,
                    productstatus = item.IsLimit ? 0 : (sku.Stock <= 0 ? ProductInfo.ProductSaleStatus.InStock.GetHashCode() : product.SaleStatus.GetHashCode()),
                    status = item.IsLimit ? 1 : ProductManagerApplication.GetProductShowStatus(product, sku.Map <DTO.SKU>(), 1),   // 0:正常;1:已失效;2:库存不足;3:已下架;
                    Size = sku.Size,
                    Color = sku.Color,
                    Version = sku.Version,
                    ColorAlias = sku.ColorAlias,
                    SizeAlias = sku.SizeAlias,
                    VersionAlias = sku.VersionAlias,
                    skuDetails = skuDetails,
                    AddTime = item.AddTime,
                    minMath = ProductManagerApplication.GetProductLadderMinMath(product.Id)
                });
            }).OrderBy(p => p.status).ThenByDescending(o => o.AddTime).ToList();

            #region 门店购物车
            var  discount         = CurrentUser?.MemberDiscount ?? 1;
            var  branchCartHelper = new BranchCartHelper();
            long userId           = 0;
            if (CurrentUser != null)
            {
                userId = CurrentUser.Id;
            }
            var Branchcart     = branchCartHelper.GetCartNoCache(userId, 0);
            var shopBranchList = Branchcart.Items.Where(x => x.ShopBranchId > 0).Select(x => x.ShopBranchId).ToList();
            shopBranchList = shopBranchList.GroupBy(x => x).Select(x => x.First()).ToList();
            Dictionary <long, long> buyedCounts = null;
            if (userId > 0)
            {
                buyedCounts = new Dictionary <long, long>();
                buyedCounts = OrderApplication.GetProductBuyCount(userId, Branchcart.Items.Select(x => x.ProductId));
            }

            var branchProducts = PackageCartProducts(Branchcart, discount, true);
            var sbProducts     = branchProducts.OrderBy(p => p.status).ThenByDescending(item => item.AddTime);
            var shopBranchCart = sbProducts.GroupBy(item => item.shopBranchId);
            #endregion

            var cartModel = new { products = products, amount = products.Sum(item => item.price * item.count), totalCount = products.Sum(item => item.count), shopBranchCart = shopBranchCart };
            return(SuccessResult <dynamic>(data: cartModel));
        }
Exemplo n.º 6
0
        /// <summary>
        /// 购物车方式提交的订单
        /// </summary>
        /// <param name="value">数据</param>
        public object PostSubmitOrderByCart(OrderSubmitOrderByCartModel value)
        {
            CheckUserLogin();
            string cartItemIds      = value.cartItemIds;
            long   recieveAddressId = value.recieveAddressId;
            string couponIds        = value.couponIds;
            int    integral         = value.integral;

            bool   isCashOnDelivery = value.isCashOnDelivery;
            int    invoiceType      = value.invoiceType;
            string invoiceTitle     = value.invoiceTitle;
            string invoiceContext   = value.invoiceContext;
            //end
            string           orderRemarks = "";//value.orderRemarks;//订单备注
            OrderCreateModel model        = new OrderCreateModel();
            var orderService = ServiceProvider.Instance <IOrderService> .Create;
            IEnumerable <long> orderIds;

            model.PlatformType     = PlatformType.Android;
            model.CurrentUser      = CurrentUser;
            model.ReceiveAddressId = recieveAddressId;
            model.Integral         = integral;


            model.IsCashOnDelivery = isCashOnDelivery;
            model.Invoice          = (InvoiceType)invoiceType;
            model.InvoiceContext   = invoiceContext;
            model.InvoiceTitle     = invoiceTitle;
            //end
            CommonModel.OrderShop[] OrderShops = Newtonsoft.Json.JsonConvert.DeserializeObject <OrderShop[]>(value.jsonOrderShops);
            model.OrderShops   = OrderShops;//用户APP选择门店自提时用到,2.5版本未支持门店自提
            model.OrderRemarks = OrderShops.Select(p => p.Remark).ToArray();
            try
            {
                var cartItemIdsArr = cartItemIds.Split(',').Select(item => long.Parse(item)).ToArray();
                //根据购物车项补充sku数据
                var cartItems = CartApplication.GetCartItems(cartItemIdsArr);
                model.SkuIds = cartItems.Select(e => e.SkuId).ToList();
                model.Counts = cartItems.Select(e => e.Quantity).ToList();

                model.CartItemIds  = cartItemIdsArr;
                model.CouponIdsStr = OrderHelper.ConvertUsedCoupon(couponIds);
                var orders = orderService.CreateOrder(model);
                orderIds = orders.Select(item => item.Id).ToArray();
                decimal orderTotals     = orders.Sum(item => item.OrderTotalAmount);
                var     realTotalIsZero = "false";
                if (orderTotals == 0)
                {
                    realTotalIsZero = "true";
                }
                return(Json(new { Success = "true", OrderIds = orderIds, RealTotalIsZero = realTotalIsZero }));
            }
            catch (HimallException he)
            {
                return(Json(new { Success = "false", Msg = he.Message }));
            }
            catch (Exception ex)
            {
                return(Json(new { Success = "false", Msg = "提交订单异常" }));
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// 购物车方式提交的订单
        /// </summary>
        /// <param name="value">数据</param>
        private object SubmitOrderByCart(OrderSubmitOrderByCartModel value)
        {
            string cartItemIds      = value.cartItemIds;
            long   recieveAddressId = value.recieveAddressId;
            string couponIds        = value.couponIds;
            int    integral         = value.integral;

            bool   isCashOnDelivery = value.isCashOnDelivery;
            int    invoiceType      = value.invoiceType;
            string invoiceTitle     = value.invoiceTitle;
            string invoiceContext   = value.invoiceContext;

            OrderCreateModel model = new OrderCreateModel();
            List <OrderInfo> infos = new List <OrderInfo>();

            var orderService = ServiceProvider.Instance <IOrderService> .Create;
            IEnumerable <long> orderIds;

            model.PlatformType     = PlatformType.WeiXinSmallProg;
            model.CurrentUser      = CurrentUser;
            model.ReceiveAddressId = recieveAddressId;
            model.Integral         = integral;

            model.formId  = value.formId;
            model.Capital = value.Capital;

            model.IsCashOnDelivery = isCashOnDelivery;
            model.Invoice          = (InvoiceType)invoiceType;
            model.InvoiceContext   = invoiceContext;
            model.InvoiceTitle     = invoiceTitle;

            if (value.isStore)
            {
                model.IsShopbranchOrder = true;
            }
            //end
            CommonModel.OrderShop[] OrderShops = Newtonsoft.Json.JsonConvert.DeserializeObject <OrderShop[]>(value.jsonOrderShops);
            model.OrderShops   = OrderShops;//用户APP选择门店自提时用到,2.5版本未支持门店自提
            model.OrderRemarks = OrderShops.Select(p => p.Remark).ToArray();
            try
            {
                var cartItemIdsArr = cartItemIds.Split(',').Select(item => long.Parse(item)).ToArray();
                //根据购物车项补充sku数据
                var cartItems = CartApplication.GetCartItems(cartItemIdsArr);
                model.SkuIds = cartItems.Select(e => e.SkuId).ToList();
                model.Counts = cartItems.Select(e => e.Quantity).ToList();

                model.CartItemIds  = cartItemIdsArr;
                model.CouponIdsStr = CouponApplication.ConvertUsedCoupon(couponIds);

                var orders = orderService.CreateOrder(model);
                orderIds = orders.Select(item => item.Id).ToArray();
                decimal orderTotals = orders.Where(d => d.PaymentType != Entities.OrderInfo.PaymentTypes.CashOnDelivery).Sum(item => item.OrderTotalAmount);

                return(Json(new { OrderId = string.Join(",", orderIds), OrderTotal = orderTotals,
                                  RealTotalIsZero = (orderTotals - model.Capital) == 0, msg = "提交成功" }));
            }
            catch (MallException he)
            {
                return(Json(ErrorResult <dynamic>(he.Message)));
            }
        }
Exemplo n.º 8
0
        public object GetCartProduct(string openId = "")
        {
            CheckUserLogin();
            List <CartProductModel> products = new List <CartProductModel>();
            var cartItems = CartApplication.GetCartItems(CurrentUser.Id);
            var vshops    = VshopApplication.GetVShopsByShopIds(cartItems.Select(p => p.Shop.Id));

            foreach (var item in cartItems)
            {
                var sku     = item.Sku;
                var product = item.Product;
                var shop    = item.Shop;
                var vshop   = vshops.FirstOrDefault(p => p.ShopId == shop.Id);

                var _tmp = new CartProductModel
                {
                    CartItemId    = item.ItemId.ToString(),
                    SkuId         = sku.Id,
                    Id            = product.Id.ToString(),
                    ImgUrl        = Core.MallIO.GetRomoteProductSizeImage(product.RelativePath, 1, (int)ImageSize.Size_150),
                    Name          = product.ProductName,
                    Price         = sku.SalePrice.ToString("F2"),
                    MarketPrice   = product.MarketPrice.ToString("F2"),
                    Count         = item.Quantity.ToString(),
                    ShopId        = shop.Id.ToString(),
                    Size          = sku.Size,
                    Color         = sku.Color,
                    Version       = sku.Version,
                    VShopId       = vshop == null ? "0" : vshop.Id.ToString(),
                    ShopName      = shop.ShopName,
                    ShopLogo      = vshop == null ? "" : Core.MallIO.GetRomoteImagePath(vshop.Logo),
                    Url           = Core.MallIO.GetRomoteImagePath("/m-IOS/product/detail/") + product.Id,
                    ProductStatus = item.ShowStatus,
                    ColorAlias    = sku.ColorAlias,
                    SizeAlias     = sku.SizeAlias,
                    VersionAlias  = sku.VersionAlias,
                    AddTime       = item.AddTime,
                    IsOpenLadder  = product.IsOpenLadder,
                    MaxBuyCount   = product.MaxBuyCount,
                    MinBath       = ProductManagerApplication.GetProductLadderMinMath(product.Id),
                    ActiveId      = item.LimitId
                };
                _tmp.IsValid = (_tmp.ProductStatus == 0) ? 0 : 1;
                products.Add(_tmp);
            }


            products = products.OrderBy(p => p.IsValid).ThenByDescending(item => item.AddTime).ToList();
            var     cartShop  = products.GroupBy(item => item.ShopId);
            decimal prodPrice = 0.0M; //优惠价格
            decimal discount  = 1.0M; //默认折扣为1(没有折扣)

            if (CurrentUser != null)
            {
                discount = CurrentUser.MemberDiscount;
            }
            var productService    = ServiceProvider.Instance <IProductService> .Create;
            var shopService       = ServiceProvider.Instance <IShopService> .Create;
            var vshopService      = ServiceProvider.Instance <IVShopService> .Create;
            var siteSetting       = SiteSettingApplication.SiteSettings;
            var typeservice       = ServiceProvider.Instance <ITypeService> .Create;
            var shopBranchService = ServiceProvider.Instance <IShopBranchService> .Create;
            var shopCartHelper    = ServiceProvider.Instance <IBranchCartService> .Create;
            var branchcart        = shopCartHelper.GetCart(CurrentUser.Id, 0);
            var branchProducts    = PackageCartProducts(branchcart, prodPrice, discount, productService, shopService, shopBranchService, vshopService, typeservice, true);
            var sbProducts        = branchProducts.OrderBy(p => p.Status).ThenByDescending(item => item.AddTime);
            var sbCartShop        = sbProducts.GroupBy(item => item.ShopBranchId);

            return(Json(new { Shop = cartShop, ShopBranch = sbCartShop }));
        }
Exemplo n.º 9
0
        /// <summary>
        /// 购物车方式提交的订单
        /// </summary>
        /// <param name="value">数据</param>
        public object PostSubmitOrderByCart(OrderSubmitOrderByCartModel value)
        {
            CheckUserLogin();
            if (value.CapitalAmount > 0 && !string.IsNullOrEmpty(value.PayPwd))
            {
                var flag = MemberApplication.VerificationPayPwd(CurrentUser.Id, value.PayPwd);
                if (!flag)
                {
                    return(ErrorResult("预存款支付密码错误"));
                }
            }
            string cartItemIds      = value.cartItemIds;
            long   recieveAddressId = value.recieveAddressId;
            string couponIds        = value.couponIds;
            int    integral         = value.integral;

            decimal capitalAmount = value.CapitalAmount;

            bool   isCashOnDelivery = value.isCashOnDelivery;
            int    invoiceType      = value.invoiceType;
            string invoiceTitle     = value.invoiceTitle;
            string invoiceContext   = value.invoiceContext;
            string invoiceCode      = value.invoiceCode;

            OrderCreateModel model = new OrderCreateModel();
            var orderService       = ServiceProvider.Instance <IOrderService> .Create;
            IEnumerable <long> orderIds;

            model.PlatformType     = PlatformType.Android;
            model.CurrentUser      = CurrentUser;
            model.ReceiveAddressId = recieveAddressId;
            model.Integral         = integral;

            model.Capital = capitalAmount;//预存款

            model.IsCashOnDelivery = isCashOnDelivery;
            model.Invoice          = (InvoiceType)invoiceType;
            model.InvoiceContext   = invoiceContext;
            model.InvoiceTitle     = invoiceTitle;
            model.InvoiceCode      = invoiceCode;
            //end
            CommonModel.OrderShop[] OrderShops = Newtonsoft.Json.JsonConvert.DeserializeObject <OrderShop[]>(value.jsonOrderShops);
            model.OrderShops   = OrderShops;//用户APP选择门店自提时用到,2.5版本未支持门店自提
            model.OrderRemarks = OrderShops.Select(p => p.Remark).ToArray();
            try
            {
                var cartItemIdsArr = cartItemIds.Split(',').Select(item => long.Parse(item)).ToArray();
                //根据购物车项补充sku数据
                var cartItems = CartApplication.GetCartItems(cartItemIdsArr);
                model.SkuIds = cartItems.Select(e => e.SkuId).ToList();
                model.Counts = cartItems.Select(e => e.Quantity).ToList();

                model.CartItemIds  = cartItemIdsArr;
                model.CouponIdsStr = CouponApplication.ConvertUsedCoupon(couponIds);
                var orders = orderService.CreateOrder(model);
                orderIds = orders.Select(item => item.Id).ToArray();
                decimal orderTotals = orders.Where(d => d.PaymentType != Entities.OrderInfo.PaymentTypes.CashOnDelivery).Sum(item => item.OrderTotalAmount);
                return(new { success = true, OrderIds = orderIds, RealTotalIsZero = orderTotals == 0 });
            }
            catch (HimallException he)
            {
                return(ErrorResult(he.Message));
            }
            catch (Exception ex)
            {
                return(ErrorResult("提交订单异常"));
            }
        }