Exemplo n.º 1
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 + "  ";
                }
                if (!string.IsNullOrWhiteSpace(sku.Color))
                {
                    skuDetails += sku.ColorAlias + ":" + sku.Color + "  ";
                }
                if (!string.IsNullOrWhiteSpace(sku.Version))
                {
                    skuDetails += sku.VersionAlias + ":" + sku.Version + "  ";
                }


                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.º 2
0
        public JsonResult GetUserOrders(int?orderStatus, int pageNo, int pageSize = 8)
        {
            if (orderStatus.HasValue && orderStatus == 0)
            {
                orderStatus = null;
            }
            var queryModel = new OrderQuery()
            {
                Status   = (Entities.OrderInfo.OrderOperateStatus?)orderStatus,
                UserId   = CurrentUser.Id,
                PageSize = pageSize,
                PageNo   = pageNo,
                IsFront  = true
            };

            if (queryModel.Status.HasValue && queryModel.Status.Value == Entities.OrderInfo.OrderOperateStatus.WaitReceiving)
            {
                if (queryModel.MoreStatus == null)
                {
                    queryModel.MoreStatus = new List <Entities.OrderInfo.OrderOperateStatus>()
                    {
                    };
                }
                queryModel.MoreStatus.Add(Entities.OrderInfo.OrderOperateStatus.WaitSelfPickUp);
            }
            if (orderStatus.GetValueOrDefault() == (int)OrderInfo.OrderOperateStatus.Finish)
            {
                queryModel.Commented = false;//只查询未评价的订单
            }
            var orders        = OrderApplication.GetOrders(queryModel);
            var orderItems    = OrderApplication.GetOrderItemsByOrderId(orders.Models.Select(p => p.Id));
            var orderComments = OrderApplication.GetOrderCommentCount(orders.Models.Select(p => p.Id));
            var orderRefunds  = OrderApplication.GetOrderRefunds(orderItems.Select(p => p.Id));
            var products      = ProductManagerApplication.GetProductsByIds(orderItems.Select(p => p.ProductId));
            var vshops        = VshopApplication.GetVShopsByShopIds(products.Select(p => p.ShopId));
            //查询结果的门店ID
            var branchIds = orders.Models.Where(e => e.ShopBranchId > 0).Select(p => p.ShopBranchId).ToList();
            //根据门店ID获取门店信息
            var shopBranchs            = ShopBranchApplication.GetShopBranchByIds(branchIds);
            var orderVerificationCodes = OrderApplication.GetOrderVerificationCodeInfosByOrderIds(orders.Models.Select(p => p.Id).ToList());
            var result = orders.Models.Select(item =>
            {
                var codes      = orderVerificationCodes.Where(a => a.OrderId == item.Id);
                var _ordrefobj = _iRefundService.GetOrderRefundByOrderId(item.Id) ?? new Entities.OrderRefundInfo {
                    Id = 0
                };
                if (item.OrderStatus != Entities.OrderInfo.OrderOperateStatus.WaitDelivery && item.OrderStatus != Entities.OrderInfo.OrderOperateStatus.WaitSelfPickUp)
                {
                    _ordrefobj = new Entities.OrderRefundInfo {
                        Id = 0
                    };
                }
                int?ordrefstate   = (_ordrefobj == null ? null : (int?)_ordrefobj.SellerAuditStatus);
                ordrefstate       = (ordrefstate > 4 ? (int?)_ordrefobj.ManagerConfirmStatus : ordrefstate);
                var branchObj     = shopBranchs.FirstOrDefault(e => item.ShopBranchId > 0 && e.Id == item.ShopBranchId);
                string branchName = branchObj == null ? string.Empty : branchObj.ShopBranchName;
                return(new
                {
                    id = item.Id,
                    status = item.OrderStatus.ToDescription(),
                    orderStatus = item.OrderStatus,
                    shopname = item.ShopName,
                    orderTotalAmount = item.OrderTotalAmount,
                    capitalAmount = item.CapitalAmount,
                    productCount = orderItems.Where(oi => oi.OrderId == item.Id).Sum(a => a.Quantity),
                    commentCount = orderComments.ContainsKey(item.Id) ? orderComments[item.Id] : 0,
                    PaymentType = item.PaymentType,
                    RefundStats = ordrefstate,
                    OrderRefundId = _ordrefobj.Id,
                    OrderType = item.OrderType,
                    PickUp = item.PickupCode,
                    ShopBranchId = item.ShopBranchId,
                    ShopBranchName = branchName,
                    DeliveryType = item.DeliveryType,
                    ShipOrderNumber = item.ShipOrderNumber,
                    EnabledRefundAmount = item.OrderEnabledRefundAmount,
                    itemInfo = orderItems.Where(oi => oi.OrderId == item.Id).Select(a =>
                    {
                        var prodata = products.FirstOrDefault(p => p.Id == a.ProductId);
                        VShop vshop = null;
                        if (prodata != null)
                        {
                            vshop = vshops.FirstOrDefault(vs => vs.ShopId == prodata.ShopId);
                        }
                        if (vshop == null)
                        {
                            vshop = new VShop {
                                Id = 0
                            }
                        }
                        ;

                        var itemrefund = orderRefunds.Where(or => or.OrderItemId == a.Id).FirstOrDefault(d => d.RefundMode != OrderRefundInfo.OrderRefundMode.OrderRefund);
                        int?itemrefstate = (itemrefund == null ? null : (int?)itemrefund.SellerAuditStatus);
                        itemrefstate = (itemrefstate > 4 ? (int?)itemrefund.ManagerConfirmStatus : itemrefstate);
                        return new
                        {
                            itemid = a.Id,
                            productId = a.ProductId,
                            productName = a.ProductName,
                            image = HimallIO.GetProductSizeImage(a.ThumbnailsUrl, 1, (int)ImageSize.Size_100),
                            count = a.Quantity,
                            price = a.SalePrice,
                            Unit = prodata == null ? "" : prodata.MeasureUnit,
                            vshopid = vshop.Id,
                            color = a.Color,
                            size = a.Size,
                            version = a.Version,
                            RefundStats = itemrefstate,
                            OrderRefundId = (itemrefund == null ? 0 : itemrefund.Id),
                            EnabledRefundAmount = a.EnabledRefundAmount
                        };
                    }),
                    HasAppendComment = HasAppendComment(orderItems.Where(oi => oi.OrderId == item.Id).FirstOrDefault()),
                    CanRefund = OrderApplication.CanRefund(item, ordrefstate),
                    IsVirtual = item.OrderType == OrderInfo.OrderTypes.Virtual ? 1 : 0,
                    IsPay = item.PayDate.HasValue ? 1 : 0
                });
            });
Exemplo n.º 3
0
        public JsonResult GetUserOrders(int?orderStatus, int pageNo, int pageSize = 8)
        {
            if (orderStatus.HasValue && orderStatus == 0)
            {
                orderStatus = null;
            }
            var queryModel = new OrderQuery()
            {
                Status   = (Model.OrderInfo.OrderOperateStatus?)orderStatus,
                UserId   = CurrentUser.Id,
                PageSize = pageSize,
                PageNo   = pageNo
            };

            if (queryModel.Status.HasValue && queryModel.Status.Value == OrderInfo.OrderOperateStatus.WaitReceiving)
            {
                if (queryModel.MoreStatus == null)
                {
                    queryModel.MoreStatus = new List <OrderInfo.OrderOperateStatus>()
                    {
                    };
                }
                queryModel.MoreStatus.Add(OrderInfo.OrderOperateStatus.WaitSelfPickUp);
            }
            if (orderStatus.GetValueOrDefault() == (int)Model.OrderInfo.OrderOperateStatus.Finish)
            {
                queryModel.Commented = false;//只查询未评价的订单
            }
            var orders        = OrderApplication.GetOrders(queryModel);
            var orderItems    = OrderApplication.GetOrderItemsByOrderId(orders.Models.Select(p => p.Id));
            var orderComments = OrderApplication.GetOrderCommentCount(orders.Models.Select(p => p.Id));
            var orderRefunds  = OrderApplication.GetOrderRefunds(orderItems.Select(p => p.Id));
            var products      = ProductManagerApplication.GetProductsByIds(orderItems.Select(p => p.ProductId));
            var vshops        = VshopApplication.GetVShopsByShopIds(products.Select(p => p.ShopId));

            var result = orders.Models.Select(item =>
            {
                var _ordrefobj = _iRefundService.GetOrderRefundByOrderId(item.Id) ?? new OrderRefundInfo {
                    Id = 0
                };
                if (item.OrderStatus != OrderInfo.OrderOperateStatus.WaitDelivery && item.OrderStatus != OrderInfo.OrderOperateStatus.WaitSelfPickUp)
                {
                    _ordrefobj = new OrderRefundInfo {
                        Id = 0
                    };
                }
                int?ordrefstate = (_ordrefobj == null ? null : (int?)_ordrefobj.SellerAuditStatus);
                ordrefstate     = (ordrefstate > 4 ? (int?)_ordrefobj.ManagerConfirmStatus : ordrefstate);
                return(new
                {
                    id = item.Id,
                    status = item.OrderStatus.ToDescription(),
                    orderStatus = item.OrderStatus,
                    shopname = item.ShopName,
                    orderTotalAmount = item.OrderTotalAmount.ToString("F2"),
                    productCount = item.OrderProductQuantity,
                    commentCount = orderComments.ContainsKey(item.Id) ? orderComments[item.Id] : 0,
                    PaymentType = item.PaymentType,
                    RefundStats = ordrefstate,
                    OrderRefundId = _ordrefobj.Id,
                    OrderType = item.OrderType,
                    PickUp = item.PickupCode,
                    ShopBranchId = item.ShopBranchId,
                    DeliveryType = item.DeliveryType,
                    ShipOrderNumber = item.ShipOrderNumber,
                    EnabledRefundAmount = item.OrderEnabledRefundAmount,
                    itemInfo = orderItems.Where(oi => oi.OrderId == item.Id).Select(a =>
                    {
                        var prodata = products.FirstOrDefault(p => p.Id == a.ProductId);
                        VShop vshop = null;
                        if (prodata != null)
                        {
                            vshop = vshops.FirstOrDefault(vs => vs.ShopId == prodata.ShopId);
                        }
                        if (vshop == null)
                        {
                            vshop = new VShop {
                                Id = 0
                            }
                        }
                        ;

                        var itemrefund = orderRefunds.Where(or => or.OrderItemId == a.Id).FirstOrDefault(d => d.RefundMode != OrderRefundInfo.OrderRefundMode.OrderRefund);
                        int?itemrefstate = (itemrefund == null ? null : (int?)itemrefund.SellerAuditStatus);
                        itemrefstate = (itemrefstate > 4 ? (int?)itemrefund.ManagerConfirmStatus : itemrefstate);
                        return new
                        {
                            itemid = a.Id,
                            productId = a.ProductId,
                            productName = a.ProductName,
                            image = HimallIO.GetProductSizeImage(a.ThumbnailsUrl, 1, (int)ImageSize.Size_100),
                            count = a.Quantity,
                            price = a.SalePrice,
                            Unit = prodata == null ? "" : prodata.MeasureUnit,
                            vshopid = vshop.Id,
                            color = a.Color,
                            size = a.Size,
                            version = a.Version,
                            RefundStats = itemrefstate,
                            OrderRefundId = (itemrefund == null ? 0 : itemrefund.Id),
                            EnabledRefundAmount = a.EnabledRefundAmount
                        };
                    }),
                    HasAppendComment = HasAppendComment(orderItems.Where(oi => oi.OrderId == item.Id).FirstOrDefault()),
                    CanRefund = (item.OrderStatus == Himall.Model.OrderInfo.OrderOperateStatus.WaitDelivery || item.OrderStatus == Himall.Model.OrderInfo.OrderOperateStatus.WaitSelfPickUp) &&
                                !item.RefundStats.HasValue && item.PaymentType != Himall.Model.OrderInfo.PaymentTypes.CashOnDelivery && item.PaymentType != Himall.Model.OrderInfo.PaymentTypes.None &&
                                (item.FightGroupCanRefund == null || item.FightGroupCanRefund == true) && ordrefstate.GetValueOrDefault().Equals(0)
                });
            });
Exemplo n.º 4
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 }));
        }