Exemplo n.º 1
0
        public JsonResult DeleteType(long Id)
        {
            Result result = new Result();

            try
            {
                TypeApplication.DeleteType(Id);
                // ServiceApplication.Create<IOperationLogService>().AddPlatformOperationLog(
                //new LogInfo
                //{
                //    Date = DateTime.Now,
                //    Description = "删除平台类目,Id=" + Id,
                //    IPAddress =  base.Request.HttpContext.Features.Get<IHttpConnectionFeature>()?.RemoteIpAddress.ToString(),
                //    PageUrl = "/ProductType/DeleteTyp",
                //    UserName = CurrentManager.UserName,
                //    ShopId = 0

                //});
                result.success = true;
            }
            catch (MallException ex)
            {
                result.msg = ex.Message;
            }
            catch (Exception ex)
            {
                Log.Error("删除平台类目失败", ex);
                result.msg = "删除平台类目失败";
            }
            return(Json(result));
        }
Exemplo n.º 2
0
        public JsonResult DeleteType(long Id)
        {
            Result result = new Result();

            try
            {
                TypeApplication.DeleteType(Id);
                // ServiceHelper.Create<IOperationLogService>().AddPlatformOperationLog(
                //new LogInfo
                //{
                //    Date = DateTime.Now,
                //    Description = "删除平台类目,Id=" + Id,
                //    IPAddress = Request.UserHostAddress,
                //    PageUrl = "/ProductType/DeleteTyp",
                //    UserName = CurrentManager.UserName,
                //    ShopId = 0

                //});
                result.success = true;
            }
            catch (HimallException ex)
            {
                result.msg = ex.Message;
            }
            catch (Exception ex)
            {
                Log.Error("删除平台类目失败", ex);
                result.msg = "删除平台类目失败";
            }
            return(Json(result));
        }
Exemplo n.º 3
0
        /// <summary>
        /// 商品列表信息项转换
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        private product_list_model ProductInfoListMapChange(Entities.ProductInfo data)
        {
            product_list_model dresult = null;
            var prodata = data;

            dresult = new product_list_model();

            if (prodata == null)
            {
                throw new MallApiException(OpenApiErrorCode.Product_Not_Exists, "num_iid");
            }

            #region 装配信息
            dresult.num_iid    = (int)prodata.Id;
            dresult.outer_id   = prodata.ProductCode;
            dresult.brand_id   = (int)prodata.BrandId;
            dresult.brand_name = prodata.BrandName;
            dresult.cid        = (int)prodata.CategoryId;
            dresult.type_id    = (int)prodata.TypeId;

            var category = CategoryApplication.GetCategory(prodata.CategoryId);
            if (category != null)
            {
                dresult.cat_name = category.Name;
                var type = TypeApplication.GetType(category.TypeId);
                if (type != null)
                {
                    dresult.type_name = type.Name;
                }
            }
            dresult.price = prodata.MinSalePrice;
            var skus = ProductManagerApplication.GetSKUs(prodata.Id);
            if (skus.Count > 0)
            {
                dresult.num = (int)skus.Sum(d => d.Stock);
            }
            else
            {
                dresult.num = 0;
                dresult.num = prodata.Quantity;
            }
            dresult.title         = prodata.ProductName.Trim();
            dresult.list_time     = prodata.AddedDate;
            dresult.modified      = prodata.AddedDate;
            dresult.sold_quantity = (int)prodata.SaleCounts;
            dresult.pic_url       = new System.Collections.ArrayList();
            dresult.pic_url.Add(System.IO.Path.Combine(OpenAPIHelper.HostUrl, prodata.GetImage(ImageSize.Size_350, 1)));
            ProductStatus ps = GetProductStatus(prodata);
            dresult.approve_status = ps.ToString();
            #endregion

            return(dresult);
        }
Exemplo n.º 4
0
        private static ImmutableDictionary <Sig, TypeScheme <ConstructorType> > InferConstructors(IEnumerable <TypeDecl> typeDecls)
        {
            var types = typeDecls.Select(d => new Sig(d.Name, d.Params.Length)).ToImmutableHashSet();

            TypeScheme <ConstructorType> GetConstructorType(TypeDecl decl, TypeApplication constructor)
            {
                var mentionedVariables = constructor.Variables <Type>();

                if (!mentionedVariables.Except(decl.Params).IsEmpty)
                {
                    throw new Exception("type variable not in scope");
                }

                var mentionedTypes = constructor.Args
                                     .SelectMany(a => a.SelfAndDescendants())
                                     .OfType <TypeApplication>()
                                     .Select(a => new Sig(a.Name, a.Args.Length));

                if (mentionedTypes.Any(t => !types.Contains(t)))
                {
                    throw new Exception("type not in scope");
                }

                var returnType = new TypeApplication(
                    decl.Name,
                    decl.Params
                    .Select(n => new TypeVariable(n))
                    .Cast <Type>()
                    .ToImmutableArray()
                    );

                return(new TypeScheme <ConstructorType>(decl.Params, new ConstructorType(constructor.Args, returnType)));
            }

            return((
                       from typeDecl in typeDecls
                       from constructor in typeDecl.Constructors
                       select KeyValuePair.Create(
                           constructor.Sig,
                           GetConstructorType(typeDecl, constructor)
                           )
                       ).ToImmutableDictionary());
        }
Exemplo n.º 5
0
        public JsonResult GetCartProducts()
        {
            var cartHelper     = new CartHelper();
            var cart           = cartHelper.GetCart(CurrentUser.Id);
            var productService = _iProductService;
            var shopService    = _iShopService;
            var vshopService   = _iVShopService;
            //会员折扣
            decimal discount = 1.0M;//默认折扣为1(没有折扣)

            if (CurrentUser != null)
            {
                discount = CurrentUser.MemberDiscount;
            }
            List <long> pids          = new List <long>();
            decimal     prodPrice     = 0.0M;                                                                                    //优惠价格
            var         limitProducts = LimitTimeApplication.GetPriceByProducrIds(cart.Items.Select(e => e.ProductId).ToList()); //限时购价格
            var         products      = cart.Items.Select(item =>
            {
                var product         = productService.GetProduct(item.ProductId);
                var shop            = shopService.GetShop(product.ShopId);
                SKUInfo sku         = null;
                string colorAlias   = "";
                string sizeAlias    = "";
                string versionAlias = "";
                string skuDetails   = "";
                if (null != shop)
                {
                    var vshop = vshopService.GetVShopByShopId(shop.Id);
                    sku       = productService.GetSku(item.SkuId);
                    if (sku == null)
                    {
                        return(null);
                    }
                    //处理限时购、会员折扣价格
                    var prod  = limitProducts.FirstOrDefault(e => e.ProductId == item.ProductId);
                    prodPrice = sku.SalePrice;
                    if (prod != null)
                    {
                        prodPrice = prod.MinPrice;
                    }
                    else
                    {
                        if (shop.IsSelf)
                        {//官方自营店才计算会员折扣
                            prodPrice = sku.SalePrice * discount;
                        }
                    }
                    var typeInfo = TypeApplication.GetType(product.TypeId);
                    colorAlias   = (typeInfo == null || string.IsNullOrEmpty(typeInfo.ColorAlias)) ? SpecificationType.Color.ToDescription() : typeInfo.ColorAlias;
                    sizeAlias    = (typeInfo == null || string.IsNullOrEmpty(typeInfo.SizeAlias)) ? SpecificationType.Size.ToDescription() : typeInfo.SizeAlias;
                    versionAlias = (typeInfo == null || string.IsNullOrEmpty(typeInfo.VersionAlias)) ? SpecificationType.Version.ToDescription() : typeInfo.VersionAlias;
                    skuDetails   = "";
                    if (!string.IsNullOrWhiteSpace(sku.Size))
                    {
                        skuDetails += sizeAlias + ":" + sku.Size + "&nbsp;&nbsp;";
                    }
                    if (!string.IsNullOrWhiteSpace(sku.Color))
                    {
                        skuDetails += colorAlias + ":" + sku.Color + "&nbsp;&nbsp;";
                    }
                    if (!string.IsNullOrWhiteSpace(sku.Version))
                    {
                        skuDetails += versionAlias + ":" + sku.Version + "&nbsp;&nbsp;";
                    }
                    return(new
                    {
                        cartItemId = item.Id,
                        skuId = item.SkuId,
                        id = product.Id,
                        imgUrl = Himall.Core.HimallIO.GetProductSizeImage(product.RelativePath, 1, (int)ImageSize.Size_150),
                        name = product.ProductName,
                        price = prodPrice,
                        count = item.Quantity,
                        shopId = shop.Id,
                        vshopId = vshop == null ? 0 : vshop.Id,
                        shopName = shop.ShopName,
                        shopLogo = vshop == null ? "" : vshop.Logo,
                        status = (product.AuditStatus == ProductInfo.ProductAuditStatus.Audited && product.SaleStatus == ProductInfo.ProductSaleStatus.OnSale) ? 1 : 0,
                        Size = sku.Size,
                        Color = sku.Color,
                        Version = sku.Version,
                        ColorAlias = colorAlias,
                        SizeAlias = sizeAlias,
                        VersionAlias = versionAlias,
                        skuDetails = skuDetails,
                        AddTime = item.AddTime
                    });
                }
                else
                {
                    return(null);
                }
            }).Where(d => d != null).OrderBy(s => s.vshopId).ThenByDescending(o => o.AddTime);

            var cartModel = new { products = products, amount = products.Sum(item => item.price * item.count), totalCount = products.Sum(item => item.count) };

            return(Json(cartModel));
        }
Exemplo n.º 6
0
        public JsonResult GetBranchCartProducts(long shopBranchId)
        {
            var  branchCartHelper = new BranchCartHelper();
            long userId           = 0;
            //会员折扣
            decimal discount = 1.0M;//默认折扣为1(没有折扣)

            if (CurrentUser != null)
            {
                userId   = CurrentUser.Id;
                discount = CurrentUser.MemberDiscount;
            }
            var cart = branchCartHelper.GetCart(userId, shopBranchId);
            //var shopBranch = _iShopBranchService.GetShopBranchById(shopBranchId);
            var shopBranch = ShopBranchApplication.GetShopBranchById(shopBranchId);
            Dictionary <long, long> buyedCounts = null;

            if (userId > 0)
            {
                buyedCounts = new Dictionary <long, long>();
                buyedCounts = OrderApplication.GetProductBuyCount(userId, cart.Items.Select(x => x.ProductId));
            }
            decimal prodPrice         = 0.0M;//优惠价格
            var     shopBranchSkuList = _iShopBranchService.GetSkusByIds(shopBranchId, cart.Items.Select(x => x.SkuId).ToList());

            var products = cart.Items.Select(item =>
            {
                var product       = _iProductService.GetProduct(item.ProductId);
                var shopbranchsku = shopBranchSkuList.FirstOrDefault(x => x.SkuId == item.SkuId);
                long stock        = shopbranchsku == null ? 0 : shopbranchsku.Stock;

                if (stock > product.MaxBuyCount && product.MaxBuyCount != 0)
                {
                    stock = product.MaxBuyCount;
                }
                if (product.MaxBuyCount > 0 && buyedCounts != null && buyedCounts.ContainsKey(item.ProductId))
                {
                    long buynum = buyedCounts[item.ProductId];
                    stock       = stock - buynum;
                }

                var shop = _iShopService.GetShop(product.ShopId);
                //Entities.SKUInfo sku = null;
                string skuDetails = "";
                if (null != shop)
                {
                    var vshop = _iVShopService.GetVShopByShopId(shop.Id);
                    //sku = _iProductService.GetSku(item.SkuId);
                    DTO.SKU sku = ProductManagerApplication.GetSKU(item.SkuId);
                    if (sku == null)
                    {
                        return(null);
                    }
                    prodPrice = sku.SalePrice;
                    if (shop.IsSelf)
                    {//官方自营店才计算会员折扣
                        prodPrice = sku.SalePrice * discount;
                    }

                    var typeInfo = TypeApplication.GetProductType(product.TypeId);
                    skuDetails   = "";
                    if (!string.IsNullOrWhiteSpace(sku.Size))
                    {
                        skuDetails += sku.Size + "&nbsp;&nbsp;";
                    }
                    if (!string.IsNullOrWhiteSpace(sku.Color))
                    {
                        skuDetails += sku.Color + "&nbsp;&nbsp;";
                    }
                    if (!string.IsNullOrWhiteSpace(sku.Version))
                    {
                        skuDetails += sku.Version + "&nbsp;&nbsp;";
                    }
                    return(new
                    {
                        bId = shopBranchId,
                        cartItemId = item.Id,
                        skuId = item.SkuId,
                        id = product.Id,
                        name = product.ProductName,
                        price = prodPrice,
                        count = item.Quantity,
                        stock = shopbranchsku == null ? 0 : stock,
                        //阶梯价商品在门店购物车自动下架
                        //status = product.IsOpenLadder ? 1 : (shopbranchsku == null ? 1 : (shopbranchsku.Status == ShopBranchSkuStatus.Normal) ? (item.Quantity > stock ? 2 : 0) : 1),//0:正常;1:冻结;2:库存不足
                        status = ProductManagerApplication.GetProductShowStatus(product, sku, 1, shopBranch, shopbranchsku),//0:正常;1:冻结;2:库存不足;3:已下架;
                        skuDetails = skuDetails,
                        AddTime = item.AddTime
                    });
                }
                else
                {
                    return(null);
                }
            }).Where(d => d != null).OrderBy(s => s.status).ThenByDescending(o => o.AddTime);

            var cartModel = new { products = products, amount = products.Where(x => x.status == 0).Sum(item => item.price * item.count), totalCount = products.Where(x => x.status == 0).Sum(item => item.count), DeliveFee = shopBranch.DeliveFee, DeliveTotalFee = shopBranch.DeliveTotalFee, FreeMailFee = shopBranch.FreeMailFee, IsFreeMail = shopBranch.IsFreeMail, shopBranchStatus = (int)shopBranch.Status };

            return(SuccessResult <dynamic>(data: cartModel));
        }
Exemplo n.º 7
0
        private List <CartProductModel> PackageCartProducts(Himall.Entities.ShoppingCartInfo cart, decimal discount, bool isBranch = false)
        {
            List <CartProductModel> products = new List <CartProductModel>();
            var limitProducts = LimitTimeApplication.GetPriceByProducrIds(cart.Items.Select(e => e.ProductId).ToList());//限时购价格
            var groupCart     = cart.Items.Where(item => item.ShopBranchId == 0).Select(c =>
            {
                var cItem   = new Himall.Entities.ShoppingCartItem();
                var skuInfo = _iProductService.GetSku(c.SkuId);
                if (skuInfo != null)
                {
                    cItem = c;
                }
                return(cItem);
            }).GroupBy(i => i.ProductId).ToList();

            foreach (var item in cart.Items)
            {
                var                        product       = ProductManagerApplication.GetProduct(item.ProductId);
                var                        shop          = _iShopService.GetShop(product.ShopId);
                DTO.ShopBranch             shopbranch    = null;
                Entities.ShopBranchSkuInfo shopbranchsku = null;
                if (item.ShopBranchId > 0)
                {
                    shopbranch    = ShopBranchApplication.GetShopBranchById(item.ShopBranchId);
                    shopbranchsku = ShopBranchApplication.GetSkusByIds(item.ShopBranchId, new List <string> {
                        item.SkuId
                    }).FirstOrDefault();
                }

                if (null != shop)
                {
                    var vshop = VshopApplication.GetVShopByShopId(shop.Id);
                    var sku   = ProductManagerApplication.GetSKU(item.SkuId);
                    if (sku == null)
                    {
                        continue;
                    }
                    //处理限时购、会员折扣价格
                    var prod      = limitProducts.FirstOrDefault(e => e.ProductId == item.ProductId);
                    var prodPrice = sku.SalePrice;
                    if (prod != null && !isBranch)
                    {
                        prodPrice = prod.MinPrice;
                    }
                    else
                    {
                        if (shop.IsSelf)
                        {//官方自营店才计算会员折扣
                            prodPrice = sku.SalePrice * discount;
                        }
                    }
                    #region 阶梯价--张宇枫
                    //阶梯价
                    if (product.IsOpenLadder)
                    {
                        var quantity = groupCart.Where(i => i.Key == item.ProductId).ToList().Sum(cartitem => cartitem.Sum(i => i.Quantity));
                        prodPrice = ProductManagerApplication.GetProductLadderPrice(item.ProductId, quantity);
                        if (shop.IsSelf)
                        {
                            prodPrice = prodPrice * discount;
                        }
                    }
                    #endregion
                    var    typeInfo     = TypeApplication.GetProductType(product.TypeId);
                    string colorAlias   = (typeInfo == null || string.IsNullOrEmpty(typeInfo.ColorAlias)) ? SpecificationType.Color.ToDescription() : typeInfo.ColorAlias;
                    string sizeAlias    = (typeInfo == null || string.IsNullOrEmpty(typeInfo.SizeAlias)) ? SpecificationType.Size.ToDescription() : typeInfo.SizeAlias;
                    string versionAlias = (typeInfo == null || string.IsNullOrEmpty(typeInfo.VersionAlias)) ? SpecificationType.Version.ToDescription() : typeInfo.VersionAlias;
                    if (product != null)
                    {
                        colorAlias   = !string.IsNullOrWhiteSpace(product.ColorAlias) ? product.ColorAlias : colorAlias;
                        sizeAlias    = !string.IsNullOrWhiteSpace(product.SizeAlias) ? product.SizeAlias : sizeAlias;
                        versionAlias = !string.IsNullOrWhiteSpace(product.VersionAlias) ? product.VersionAlias : versionAlias;
                    }
                    if (sku != null)
                    {
                        #region 正在参加限时抢购商品在购物车失效 TDO:ZYF
                        var isLimit = false;
                        //门店商品,在参加限时购,也可以正常购买
                        var limit = LimitTimeApplication.GetLimitTimeMarketItemByProductId(item.ProductId);
                        if (limit != null && !isBranch)
                        {
                            isLimit = limit.Status == Entities.FlashSaleInfo.FlashSaleStatus.Ongoing;
                        }
                        #endregion
                        var _tmp = new CartProductModel
                        {
                            cartItemId     = item.Id,
                            skuId          = item.SkuId,
                            id             = product.Id,
                            imgUrl         = Core.HimallIO.GetRomoteProductSizeImage(product.RelativePath, 1, (int)Himall.CommonModel.ImageSize.Size_150),
                            name           = product.ProductName,
                            price          = prodPrice.ToString("F2"),
                            count          = item.Quantity,
                            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.HimallIO.GetRomoteImagePath(vshop.StrLogo),
                            Url            = Core.HimallIO.GetRomoteImagePath("/m-IOS/product/detail/") + item.ProductId,
                            ProductStatus  = isLimit ? 0 : (sku.Stock <= 0 ? ProductInfo.ProductSaleStatus.InStock.GetHashCode() : product.SaleStatus.GetHashCode()),
                            status         = isLimit ? 1 : ProductManagerApplication.GetProductShowStatus(product, sku, item.Quantity, shopbranch, shopbranchsku),// 0:正常;1:已失效;2:库存不足;3:已下架;
                            ColorAlias     = colorAlias,
                            SizeAlias      = sizeAlias,
                            VersionAlias   = versionAlias,
                            AddTime        = item.AddTime,
                            shopBranchId   = item.ShopBranchId,
                            shopBranchName = null == shopbranch ? "" : shopbranch.ShopBranchName,
                            ShopBranchLogo = null == shopbranch ? "" : Core.HimallIO.GetRomoteImagePath(shopbranch.ShopImages)
                        };
                        products.Add(_tmp);
                    }
                }
            }
            return(products);
        }
Exemplo n.º 8
0
        public object GetBranchCartProducts(long shopBranchId)
        {
            long userId = 0;
            //会员折扣
            decimal discount = 1.0M;//默认折扣为1(没有折扣)

            if (CurrentUser != null)
            {
                userId   = CurrentUser.Id;
                discount = CurrentUser.MemberDiscount;
            }
            var cart = GetCart(userId, shopBranchId);
            //var shopBranch = _iShopBranchService.GetShopBranchById(shopBranchId);
            var         shopBranch     = ShopBranchApplication.GetShopBranchById(shopBranchId);
            var         productService = _iProductService;
            var         shopService    = _iShopService;
            var         vshopService   = _iVShopService;
            List <long> pids           = new List <long>();
            decimal     prodPrice      = 0.0M;//优惠价格
            var         products       = cart.Items.Select(item =>
            {
                var product       = productService.GetProduct(item.ProductId);
                var shopbranchsku = _iShopBranchService.GetSkusByIds(shopBranchId, new List <string> {
                    item.SkuId
                }).FirstOrDefault();
                var shop = shopService.GetShop(product.ShopId);
                //Entities.SKUInfo sku = null;
                string skuDetails = "";
                if (null != shop)
                {
                    var vshop = vshopService.GetVShopByShopId(shop.Id);
                    //sku = productService.GetSku(item.SkuId);
                    DTO.SKU sku = ProductManagerApplication.GetSKU(item.SkuId);
                    if (sku == null)
                    {
                        return(null);
                    }
                    prodPrice = sku.SalePrice;
                    if (shop.IsSelf)
                    {//官方自营店才计算会员折扣
                        prodPrice = sku.SalePrice * discount;
                    }

                    var typeInfo = TypeApplication.GetProductType(product.TypeId);
                    skuDetails   = "";
                    if (!string.IsNullOrWhiteSpace(sku.Size))
                    {
                        skuDetails += sku.Size + "&nbsp;&nbsp;";
                    }
                    if (!string.IsNullOrWhiteSpace(sku.Color))
                    {
                        skuDetails += sku.Color + "&nbsp;&nbsp;";
                    }
                    if (!string.IsNullOrWhiteSpace(sku.Version))
                    {
                        skuDetails += sku.Version + "&nbsp;&nbsp;";
                    }
                    return(new
                    {
                        bId = shopBranchId,
                        cartItemId = item.Id,
                        skuId = item.SkuId,
                        id = product.Id,
                        name = product.ProductName,
                        price = prodPrice,
                        count = item.Quantity,
                        stock = shopbranchsku == null ? 0 : shopbranchsku.Stock,
                        //阶梯价商品在门店购物车自动下架
                        //status = product.IsOpenLadder ? 1 : (shopbranchsku == null ? 1 : (shopbranchsku.Status == ShopBranchSkuStatus.Normal) ? (item.Quantity > shopbranchsku.Stock ? 2 : 0) : 1),//0:正常;1:冻结;2:库存不足
                        status = ProductManagerApplication.GetProductShowStatus(product, sku, 1, shopBranch, shopbranchsku),//0:正常;1:冻结;2:库存不足;3:已下架;
                        skuDetails = skuDetails,
                        AddTime = item.AddTime
                    });
                }
                else
                {
                    return(null);
                }
            }).Where(d => d != null).OrderBy(s => s.status).ThenByDescending(o => o.AddTime);

            var cartModel = new
            {
                success          = true,
                products         = products,
                amount           = products.Where(x => x.status == 0).Sum(item => item.price * item.count),
                totalCount       = products.Where(x => x.status == 0).Sum(item => item.count),
                DeliveFee        = shopBranch.DeliveFee,
                DeliveTotalFee   = shopBranch.DeliveTotalFee,
                FreeMailFee      = shopBranch.FreeMailFee,
                shopBranchStatus = (int)shopBranch.Status
            };

            return(cartModel);
        }
Exemplo n.º 9
0
        public string DownloadProduct(HttpContext context)
        {
            string  bizcontent = context.Request["bizcontent"];
            JObject jo         = (JObject)JsonConvert.DeserializeObject(bizcontent);
            int     PageIndex  = GetJObjectValue <int>(jo, "PageIndex");

            if (PageIndex < 1)
            {
                PageIndex = 1;
            }
            int PageSize = GetJObjectValue <int>(jo, "PageSize");

            if (PageSize < 1)
            {
                PageSize = 10;
            }

            ProductQuery query = new ProductQuery
            {
                PageSize = PageSize,
                PageNo   = PageIndex,
                ShopId   = CurShopId
            };

            long ProductId = 0;

            if (jo["ProductId"] != null)
            {
                long.TryParse("", out ProductId);
            }
            if (ProductId > 0)
            {
                query.Ids = new long[] { ProductId };
            }
            string ProductName = GetJObjectValue <string>(jo, "ProductName");

            if (!string.IsNullOrWhiteSpace(ProductName))
            {
                query.KeyWords = ProductName;
            }
            string QStatus = GetJObjectValue <string>(jo, "Status");

            switch (QStatus)
            {
            case "JH_01":
                //已上架商品
                query.SaleStatus  = ProductInfo.ProductSaleStatus.OnSale;
                query.AuditStatus = new ProductInfo.ProductAuditStatus[] { ProductInfo.ProductAuditStatus.Audited };
                break;

            case "JH_02":
                //已下架商品(违规下架)
                query.AuditStatus = new ProductInfo.ProductAuditStatus[] { ProductInfo.ProductAuditStatus.InfractionSaleOff };
                break;

            case "JH_03":
                //已售罄商品(超过警界库存)
                query.OverSafeStock = true;
                break;

            case "JH_04":
                //未通过审核
                query.AuditStatus = new ProductInfo.ProductAuditStatus[] { Entities.ProductInfo.ProductAuditStatus.AuditFailed };
                break;

            case "JH_05":
                //审核中商品
                query.AuditStatus = new ProductInfo.ProductAuditStatus[] { Entities.ProductInfo.ProductAuditStatus.WaitForAuditing };
                break;

            case "JH_06":
                //即将上架商品(仓库)
                query.SaleStatus = ProductInfo.ProductSaleStatus.InStock;
                break;
            }
            var _iTypeService = ObjectContainer.Current.Resolve <Himall.IServices.ITypeService>();

            var           data = ProductManagerApplication.GetProducts(query);
            StringBuilder sb   = new StringBuilder();

            sb.Append("{");
            sb.Append("\"code\":" + "\"" + "10000" + "\"");
            sb.Append(",\"message\":" + "\"" + "SUCCESS" + "\"");
            sb.Append(",\"totalcount\":" + "\"" + data.Total + "\"");
            sb.Append(",\"goodslist\":");
            sb.Append("[");
            int curitemnum = 0;
            var allskus    = ProductManagerApplication.GetSKUByProducts(data.Models.Select(d => d.Id));

            foreach (var item in data.Models)
            {
                var skus = allskus.Where(p => p.ProductId == item.Id);
                if (curitemnum > 0)
                {
                    sb.Append(",");
                }
                sb.Append("{");
                sb.Append("\"PlatProductID\":" + "\"" + item.Id + "\"");
                sb.Append(",\"name\":" + "\"" + item.ProductName + "\"");
                sb.Append(",\"OuterID\":" + "\"" + item.Id + "\"");
                sb.Append(",\"price\":" + "\"" + item.MinSalePrice + "\"");
                sb.Append(",\"num\":" + "\"" + skus.Sum(d => d.Stock) + "\"");
                sb.Append(",\"pictureurl\":" + "\"" + HimallIO.GetProductSizeImage(item.ImagePath, 1, ImageSize.Size_400.GetHashCode()) + "\"");
                sb.Append(",\"whsecode\":" + "\"" + "" + "\"");
                sb.Append(",\"attrbutes\":");
                sb.Append("[");
                #region 商品属性填充
                var prodAttrs   = ProductManagerApplication.GetProductAttributes(item.Id);
                var prodAttrids = prodAttrs.Select(d => d.AttributeId).Distinct().ToList();

                if (prodAttrids.Count > 0)
                {
                    List <string> propslst    = new List <string>();
                    List <string> propsvallst = new List <string>();
                    int           curattrnum  = 0;
                    foreach (var curattid in prodAttrids)
                    {
                        var attr = prodAttrs.FirstOrDefault(d => d.AttributeId == curattid);
                        propsvallst.Clear();
                        var values    = _iTypeService.GetAttributeValues(curattid);
                        var attribute = _iTypeService.GetAttribute(curattid);
                        foreach (var attrV in values)
                        {
                            if (prodAttrs.Any(p => p.ValueId == attrV.Id))
                            {
                                if (curattrnum > 0)
                                {
                                    sb.Append(",");
                                }
                                sb.Append("{");
                                sb.Append("\"name\":\"" + attribute.Name + "\"");
                                sb.Append(",\"value\":\"" + attrV.Value + "\"");
                                sb.Append(",\"attributeid\":\"" + attrV.Id + "\"");
                                sb.Append(",\"iscustom\":\"1\"");
                                sb.Append("}");
                                propsvallst.Add(attrV.Value);
                                curattrnum++;
                            }
                        }
                    }
                }
                #endregion
                sb.Append("]");

                sb.Append(",\"skus\":");
                sb.Append("[");
                #region SKUS

                var    typeInfo     = TypeApplication.GetProductType(item.TypeId);
                string colorAlias   = (typeInfo == null || string.IsNullOrEmpty(typeInfo.ColorAlias)) ? SpecificationType.Color.ToDescription() : typeInfo.ColorAlias;
                string sizeAlias    = (typeInfo == null || string.IsNullOrEmpty(typeInfo.SizeAlias)) ? SpecificationType.Size.ToDescription() : typeInfo.SizeAlias;
                string versionAlias = (typeInfo == null || string.IsNullOrEmpty(typeInfo.VersionAlias)) ? SpecificationType.Version.ToDescription() : typeInfo.VersionAlias;
                if (item != null)
                {
                    colorAlias   = !string.IsNullOrWhiteSpace(item.ColorAlias) ? item.ColorAlias : colorAlias;
                    sizeAlias    = !string.IsNullOrWhiteSpace(item.SizeAlias) ? item.SizeAlias : sizeAlias;
                    versionAlias = !string.IsNullOrWhiteSpace(item.VersionAlias) ? item.VersionAlias : versionAlias;
                }
                int curskunum = 0;
                foreach (var skuitem in skus)
                {
                    if (curskunum > 0)
                    {
                        sb.Append(",");
                    }
                    string sku_properties_all_name = colorAlias + ":" + skuitem.Color + " " + sizeAlias + ":" + skuitem.Size + versionAlias + " " + ":" + skuitem.Version;
                    string sku_properties_name     = skuitem.Color + " " + skuitem.Size + " " + skuitem.Version;
                    string skuOuterID = skuitem.Sku;
                    if (string.IsNullOrWhiteSpace(skuOuterID))
                    {
                        skuOuterID = item.ProductCode;
                    }
                    sb.Append("{");
                    sb.Append("\"SkuID\":" + "\"" + skuitem.Id + "\"");
                    sb.Append(",\"skuOuterID\":" + "\"" + skuOuterID + "\"");
                    sb.Append(",\"skuprice\":" + "\"" + skuitem.SalePrice + "\"");
                    sb.Append(",\"skuQuantity\":" + "\"" + skuitem.Stock + "\"");
                    sb.Append(",\"skuname\":" + "\"" + skuitem.Sku + "\"");
                    sb.Append(",\"skuproperty\":" + "\"" + "" + "\"");
                    sb.Append(",\"skupictureurl\":" + "\"" + "" + "\"");
                    sb.Append("}");
                    curskunum++;
                }
                #endregion
                sb.Append("]");
                sb.Append("}");
                curitemnum++;
            }
            sb.Append("]");
            sb.Append("}");
            return(sb.ToString());
        }
Exemplo n.º 10
0
        public object GetOrderDetail(long id)
        {
            CheckUserLogin();
            OrderInfo order = ServiceProvider.Instance <IOrderService> .Create.GetOrder(id, CurrentUser.Id);

            var    orderService       = ServiceProvider.Instance <IOrderService> .Create;
            var    bonusService       = ServiceProvider.Instance <IShopBonusService> .Create;
            var    orderRefundService = ServiceProvider.Instance <IRefundService> .Create;
            var    bonusmodel         = bonusService.GetGrantByUserOrder(id, CurrentUser.Id);
            bool   hasBonus           = bonusmodel != null ? true : false;
            string shareHref          = "";
            string shareTitle         = "";
            string shareDetail        = "";
            string shareImg           = "";

            if (hasBonus)
            {
                shareHref = CurrentUrlHelper.CurrentUrlNoPort() + "/m-weixin/shopbonus/index/" + bonusService.GetGrantIdByOrderId(id);
                var bonus = ShopBonusApplication.GetBonus(bonusmodel.ShopBonusId);
                shareTitle  = bonus.ShareTitle;
                shareDetail = bonus.ShareDetail;
                shareImg    = HimallIO.GetRomoteImagePath(bonus.ShareImg);
            }
            var vshop = ServiceProvider.Instance <IVShopService> .Create.GetVShopByShopId(order.ShopId);

            var customerServices = CustomerServiceApplication.GetMobileCustomerServiceAndMQ(order.ShopId);

            var shop        = ShopApplication.GetShop(order.ShopId);
            var orderItems  = OrderApplication.GetOrderItemsByOrderId(order.Id);
            var products    = ProductManagerApplication.GetProducts(orderItems.Select(p => p.ProductId));
            var refunds     = OrderApplication.GetOrderRefundsByOrder(order.Id);        //获取订单商品项数据
            var orderDetail = new
            {
                ShopId     = shop.Id,
                ShopName   = shop.ShopName,
                OrderItems = orderItems.Select(item =>
                {
                    var product  = products.FirstOrDefault(p => p.Id == item.ProductId);
                    var typeInfo = TypeApplication.GetType(product.TypeId);

                    string colorAlias   = (typeInfo == null || string.IsNullOrEmpty(typeInfo.ColorAlias)) ? SpecificationType.Color.ToDescription() : typeInfo.ColorAlias;
                    string sizeAlias    = (typeInfo == null || string.IsNullOrEmpty(typeInfo.SizeAlias)) ? SpecificationType.Size.ToDescription() : typeInfo.SizeAlias;
                    string versionAlias = (typeInfo == null || string.IsNullOrEmpty(typeInfo.VersionAlias)) ? SpecificationType.Version.ToDescription() : typeInfo.VersionAlias;
                    if (product != null)
                    {
                        colorAlias   = !string.IsNullOrWhiteSpace(product.ColorAlias) ? product.ColorAlias : colorAlias;
                        sizeAlias    = !string.IsNullOrWhiteSpace(product.SizeAlias) ? product.SizeAlias : sizeAlias;
                        versionAlias = !string.IsNullOrWhiteSpace(product.VersionAlias) ? product.VersionAlias : versionAlias;
                    }
                    var itemrefund   = refunds.FirstOrDefault(d => d.OrderItemId == item.Id && d.RefundMode != OrderRefundInfo.OrderRefundMode.OrderRefund);
                    int?itemrefstate = (itemrefund == null ? null : (int?)itemrefund.SellerAuditStatus);
                    itemrefstate     = (itemrefstate > 4 ? (int?)itemrefund.ManagerConfirmStatus : itemrefstate);
                    var IsCanRefund  = OrderApplication.CanRefund(order, itemrefstate, itemId: item.Id);
                    return(new
                    {
                        ItemId = item.Id,
                        ProductId = item.ProductId,
                        ProductName = item.ProductName,
                        Count = item.Quantity,
                        Price = item.SalePrice,
                        ProductImage = Core.HimallIO.GetRomoteProductSizeImage(product.RelativePath, 1, (int)Himall.CommonModel.ImageSize.Size_100),
                        color = item.Color,
                        size = item.Size,
                        version = item.Version,
                        IsCanRefund = IsCanRefund,
                        ColorAlias = colorAlias,
                        SizeAlias = sizeAlias,
                        VersionAlias = versionAlias,
                        EnabledRefundAmount = item.EnabledRefundAmount,
                        OrderRefundId = (itemrefund == null ? 0 : itemrefund.Id),
                        RefundStats = itemrefstate
                    });
                })
            };
            //取拼团订单状态
            var fightGroupOrderInfo = ServiceProvider.Instance <IFightGroupService> .Create.GetFightGroupOrderStatusByOrderId(order.Id);

            var _ordrefobj = orderRefundService.GetOrderRefundByOrderId(order.Id) ?? new OrderRefundInfo {
                Id = 0
            };

            if (order.OrderStatus != OrderInfo.OrderOperateStatus.WaitDelivery && order.OrderStatus != OrderInfo.OrderOperateStatus.WaitSelfPickUp)
            {
                _ordrefobj = new OrderRefundInfo {
                    Id = 0
                };
            }
            int?ordrefstate = (_ordrefobj == null ? null : (int?)_ordrefobj.SellerAuditStatus);

            ordrefstate = (ordrefstate > 4 ? (int?)_ordrefobj.ManagerConfirmStatus : ordrefstate);

            var hasAppendComment = ServiceProvider.Instance <ICommentService> .Create.HasAppendComment(orderItems.FirstOrDefault().Id);

            var orderModel = new
            {
                Id                 = order.Id,
                OrderType          = order.OrderType,
                OrderTypeName      = order.OrderType.ToDescription(),
                Status             = order.OrderStatus.ToDescription(),
                JoinStatus         = fightGroupOrderInfo == null ? -2 : fightGroupOrderInfo.JoinStatus,
                ShipTo             = order.ShipTo,
                Phone              = order.CellPhone,
                Address            = order.RegionFullName + " " + order.Address,
                HasExpressStatus   = !string.IsNullOrWhiteSpace(order.ShipOrderNumber),
                ExpressCompanyName = order.ExpressCompanyName,
                Freight            = order.Freight,
                Tax                = order.Tax,
                IntegralDiscount   = order.IntegralDiscount,
                RealTotalAmount    = order.OrderTotalAmount,
                CapitalAmount      = order.CapitalAmount,
                RefundTotalAmount  = order.RefundTotalAmount,
                ProductTotalAmount = order.ProductTotalAmount,
                OrderPayAmount     = order.OrderPayAmount,//订单需要第三方支付的金额
                PaymentTypeName    = PaymentApplication.GetPaymentTypeDescById(order.PaymentTypeGateway) ?? order.PaymentTypeName,
                PaymentTypeDesc    = order.PaymentTypeDesc,
                OrderDate          = order.OrderDate.ToString("yyyy-MM-dd HH:mm:ss"),
                ShopName           = order.ShopName,
                VShopId            = vshop == null ? 0 : vshop.Id,
                commentCount       = OrderApplication.GetOrderCommentCount(order.Id),
                ShopId             = order.ShopId,
                orderStatus        = (int)order.OrderStatus,
                //Invoice = order.InvoiceType.ToDescription(),
                //InvoiceValue = (int)order.InvoiceType,
                //InvoiceContext = order.InvoiceContext,
                //InvoiceTitle = order.InvoiceTitle,
                //InvoiceCode = order.InvoiceCode,
                PaymentType         = order.PaymentType.ToDescription(),
                PaymentTypeValue    = (int)order.PaymentType,
                FullDiscount        = order.FullDiscount,
                DiscountAmount      = order.DiscountAmount,
                OrderRemarks        = string.IsNullOrEmpty(order.OrderRemarks) ? "" : order.OrderRemarks,
                HasBonus            = hasBonus,
                ShareHref           = shareHref,
                ShareTitle          = shareTitle,
                ShareDetail         = shareDetail,
                ShareImg            = shareImg,
                IsCanRefund         = !(orderDetail.OrderItems.Any(e => e.IsCanRefund == true)) && OrderApplication.CanRefund(order, ordrefstate, null),
                RefundStats         = ordrefstate,
                OrderRefundId       = _ordrefobj.Id > 0 ? _ordrefobj.Id : 0,
                EnabledRefundAmount = order.OrderEnabledRefundAmount,
                HasAppendComment    = hasAppendComment,
                SelfTake            = order.DeliveryType == Himall.CommonModel.DeliveryType.SelfTake ? 1 : 0,
                OrderInvoice        = OrderApplication.GetOrderInvoiceInfo(order.Id)
            };

            #region 门店配送信息
            Himall.DTO.ShopBranch storeInfo = null;
            if (order.ShopBranchId > 0)
            {
                storeInfo = ShopBranchApplication.GetShopBranchById(order.ShopBranchId);
            }
            #endregion
            #region 虚拟订单信息
            VirtualProductInfo virtualProductInfo = null;
            int            validityType = 0; string startDate = string.Empty, endDate = string.Empty;
            List <dynamic> orderVerificationCodes = null;
            List <dynamic> virtualOrderItemInfos  = null;
            bool           isCanRefundVirtual     = false;
            if (order.OrderType == OrderInfo.OrderTypes.Virtual)
            {
                var orderItemInfo = orderItems.FirstOrDefault();
                if (orderItemInfo != null)
                {
                    virtualProductInfo = ProductManagerApplication.GetVirtualProductInfoByProductId(orderItemInfo.ProductId);
                    if (virtualProductInfo != null)
                    {
                        validityType = virtualProductInfo.ValidityType ? 1 : 0;
                        if (validityType == 1)
                        {
                            startDate = virtualProductInfo.StartDate.Value.ToString("yyyy-MM-dd");
                            endDate   = virtualProductInfo.EndDate.Value.ToString("yyyy-MM-dd");
                        }
                    }
                    var codes = OrderApplication.GetOrderVerificationCodeInfosByOrderIds(new List <long>()
                    {
                        order.Id
                    });
                    orderVerificationCodes = codes.Select(p =>
                    {
                        return(new
                        {
                            VerificationCode = Regex.Replace(p.VerificationCode, @"(\d{4})", "$1 "),
                            Status = p.Status,
                            StatusText = p.Status.ToDescription(),
                            QRCode = GetQRCode(p.VerificationCode)
                        });
                    }).ToList <dynamic>();

                    var virtualItems = OrderApplication.GetVirtualOrderItemInfosByOrderId(order.Id);
                    virtualOrderItemInfos = virtualItems.Select(p =>
                    {
                        return(new
                        {
                            VirtualProductItemName = p.VirtualProductItemName,
                            Content = ReplaceImage(p.Content, p.VirtualProductItemType),
                            VirtualProductItemType = p.VirtualProductItemType
                        });
                    }).ToList <dynamic>();
                }
            }
            if (order.OrderStatus == Himall.Entities.OrderInfo.OrderOperateStatus.WaitVerification)
            {
                if (virtualProductInfo != null)
                {
                    if (virtualProductInfo.SupportRefundType == 2)
                    {
                        isCanRefundVirtual = true;
                    }
                    else if (virtualProductInfo.SupportRefundType == 1)
                    {
                        if (virtualProductInfo.EndDate.Value > DateTime.Now)
                        {
                            isCanRefundVirtual = true;
                        }
                    }
                    else if (virtualProductInfo.SupportRefundType == 3)
                    {
                        isCanRefundVirtual = false;
                    }

                    if (isCanRefundVirtual)
                    {
                        long num = orderVerificationCodes.Where(a => a.Status == OrderInfo.VerificationCodeStatus.WaitVerification).Count();
                        if (num > 0)
                        {
                            isCanRefundVirtual = true;
                        }
                        else
                        {
                            isCanRefundVirtual = false;
                        }
                    }
                }
            }
            #endregion
            #region 虚拟订单核销地址信息
            string shipperAddress = string.Empty, shipperTelPhone = string.Empty;
            if (order.OrderType == OrderInfo.OrderTypes.Virtual)
            {
                if (order.ShopBranchId > 0 && storeInfo != null)
                {
                    shipperAddress  = RegionApplication.GetFullName(storeInfo.AddressId) + " " + storeInfo.AddressDetail;
                    shipperTelPhone = storeInfo.ContactPhone;
                }
                else
                {
                    var verificationShipper = ShopShippersApplication.GetDefaultVerificationShipper(order.ShopId);
                    if (verificationShipper != null)
                    {
                        shipperAddress  = RegionApplication.GetFullName(verificationShipper.RegionId) + " " + verificationShipper.Address;
                        shipperTelPhone = verificationShipper.TelPhone;
                    }
                }
            }
            #endregion
            return(new
            {
                success = true,
                Order = orderModel,
                OrderItem = orderDetail.OrderItems,
                StoreInfo = storeInfo,
                CustomerServices = customerServices,
                ValidityType = validityType,
                StartDate = startDate,
                EndDate = endDate,
                OrderVerificationCodes = orderVerificationCodes,
                VirtualOrderItemInfos = virtualOrderItemInfos,
                IsCanRefundVirtual = isCanRefundVirtual,
                ShipperAddress = shipperAddress,
                ShipperTelPhone = shipperTelPhone
            });
        }
Exemplo n.º 11
0
        public object GetBranchCartProducts(long shopBranchId)
        {
            long    memberId = 0L;
            decimal discount = 1.0M;

            if (base.CurrentUser != null)
            {
                memberId = base.CurrentUser.Id;
                discount = base.CurrentUser.MemberDiscount;
            }
            ShoppingCartInfo cart           = this.GetCart(memberId, shopBranchId);
            ShopBranchInfo   shopBranchById = this._iShopBranchService.GetShopBranchById(shopBranchId);
            IProductService  productService = this._iProductService;
            IShopService     shopService    = this._iShopService;
            IVShopService    vshopService   = this._iVShopService;
            List <long>      list           = new List <long>();
            decimal          prodPrice      = 0.0M;
            var enumerable = from s in cart.Items.Select(delegate(ShoppingCartItem item)
            {
                ProductInfo product      = productService.GetProduct(item.ProductId);
                ShopBranchSkusInfo info2 = this._iShopBranchService.GetSkusByIds(shopBranchId, new List <string> {
                    item.SkuId
                }).FirstOrDefault <ShopBranchSkusInfo>();
                ShopInfo shop = shopService.GetShop(product.ShopId, false);
                SKUInfo sku   = null;
                string str    = "";
                if (null != shop)
                {
                    VShopInfo vShopByShopId = vshopService.GetVShopByShopId(shop.Id);
                    sku = productService.GetSku(item.SkuId);
                    if (sku == null)
                    {
                        return(null);
                    }
                    prodPrice = sku.SalePrice;
                    if (shop.IsSelf)
                    {
                        prodPrice = sku.SalePrice * discount;
                    }
                    ProductType type = TypeApplication.GetType(product.TypeId);
                    str = "";
                    if (!string.IsNullOrWhiteSpace(sku.Size))
                    {
                        str = str + sku.Size + "&nbsp;&nbsp;";
                    }
                    if (!string.IsNullOrWhiteSpace(sku.Color))
                    {
                        str = str + sku.Color + "&nbsp;&nbsp;";
                    }
                    if (!string.IsNullOrWhiteSpace(sku.Version))
                    {
                        str = str + sku.Version + "&nbsp;&nbsp;";
                    }
                    return(new { bId = shopBranchId, cartItemId = item.Id, skuId = item.SkuId, id = product.Id, name = product.ProductName, price = prodPrice, count = item.Quantity, stock = (info2 == null) ? 0 : info2.Stock, status = (info2 == null) ? 1 : ((info2.Status == ShopBranchSkuStatus.Normal) ? ((item.Quantity > info2.Stock) ? 2 : 0) : 1), skuDetails = str, AddTime = item.AddTime });
                }
                return(null);
            })
                             where s != null
                             orderby s.status, s.AddTime descending
            select s;
            var content = new
            {
                Success          = true,
                products         = enumerable,
                amount           = enumerable.Where(x => x.status == 0).Sum(x => x.price * x.count),
                totalCount       = enumerable.Where(x => x.status == 0).Sum(x => x.count),
                DeliveFee        = shopBranchById.DeliveFee,
                DeliveTotalFee   = shopBranchById.DeliveTotalFee,
                FreeMailFee      = shopBranchById.FreeMailFee,
                shopBranchStatus = shopBranchById.Status
            };

            return(base.Json(content));
        }
Exemplo n.º 12
0
        public object GetCart(long shopBranchId)
        {
            //CheckUserLogin();
            long userId = 0;
            //会员折扣
            decimal discount = 1.0M;//默认折扣为1(没有折扣)

            if (CurrentUser != null)
            {
                userId   = CurrentUser.Id;
                discount = CurrentUser.MemberDiscount;
            }
            var cart       = GetCart(userId, shopBranchId);
            var shopBranch = ShopBranchApplication.GetShopBranchById(shopBranchId);

            if (shopBranch == null)
            {
                throw new MallException("门店库存不足");
            }
            var     stores    = cart.Items.Where(d => d.ShopBranchId > 0).OrderByDescending(d => d.AddTime).Select(d => d.ShopBranchId).GroupBy(d => d);
            decimal prodPrice = 0.0M;//优惠价格
            //var rets = new List<CartStoreModel>();
            var _store = new CartStoreModel();

            _store.ShopBranchId   = shopBranch.Id;
            _store.ShopId         = shopBranch.ShopId;
            _store.ShopBranchName = shopBranch.ShopBranchName;
            _store.Status         = shopBranch.Status.GetHashCode();
            _store.DeliveFee      = shopBranch.DeliveFee;
            _store.DeliveTotalFee = shopBranch.DeliveTotalFee;
            _store.FreeMailFee    = shopBranch.FreeMailFee;
            var product = cart.Items.Where(d => d.ShopBranchId == shopBranch.Id).OrderBy(s => s.Status).ThenByDescending(o => o.AddTime).ToList();

            _store.Products = new List <CartStoreProduct>();
            foreach (var pitem in product)
            {
                var pro           = ProductManagerApplication.GetProduct(pitem.ProductId);
                var shopbranchsku = ShopBranchApplication.GetSkusByIds(_store.ShopBranchId, new List <string> {
                    pitem.SkuId
                }).FirstOrDefault();
                var     shop       = ShopApplication.GetShop(pro.ShopId);
                var     vshop      = VshopApplication.GetVShopByShopId(pro.ShopId);
                DTO.SKU sku        = ProductManagerApplication.GetSKU(pitem.SkuId);
                string  skuDetails = "";
                if (null != shop && sku != null)
                {
                    prodPrice = sku.SalePrice;
                    if (shop.IsSelf)
                    {
                        //官方自营店才计算会员折扣
                        prodPrice = sku.SalePrice * discount;
                    }
                    prodPrice = decimal.Round(prodPrice, 2, MidpointRounding.AwayFromZero);

                    var typeInfo = TypeApplication.GetProductType(pro.TypeId);
                    skuDetails = "";
                    if (!string.IsNullOrWhiteSpace(sku.Size))
                    {
                        if (!string.IsNullOrWhiteSpace(skuDetails))
                        {
                            skuDetails += "、";
                        }
                        skuDetails += sku.Size;
                    }
                    if (!string.IsNullOrWhiteSpace(sku.Color))
                    {
                        if (!string.IsNullOrWhiteSpace(skuDetails))
                        {
                            skuDetails += "、";
                        }
                        skuDetails += sku.Color;
                    }
                    if (!string.IsNullOrWhiteSpace(sku.Version))
                    {
                        if (!string.IsNullOrWhiteSpace(skuDetails))
                        {
                            skuDetails += "、";
                        }
                        skuDetails += sku.Version;
                    }
                    string colorAlias   = (typeInfo == null || string.IsNullOrEmpty(typeInfo.ColorAlias)) ? SpecificationType.Color.ToDescription() : typeInfo.ColorAlias;
                    string sizeAlias    = (typeInfo == null || string.IsNullOrEmpty(typeInfo.SizeAlias)) ? SpecificationType.Size.ToDescription() : typeInfo.SizeAlias;
                    string versionAlias = (typeInfo == null || string.IsNullOrEmpty(typeInfo.VersionAlias)) ? SpecificationType.Version.ToDescription() : typeInfo.VersionAlias;
                    if (pro != null)
                    {
                        colorAlias   = !string.IsNullOrWhiteSpace(pro.ColorAlias) ? pro.ColorAlias : colorAlias;
                        sizeAlias    = !string.IsNullOrWhiteSpace(pro.SizeAlias) ? pro.SizeAlias : sizeAlias;
                        versionAlias = !string.IsNullOrWhiteSpace(pro.VersionAlias) ? pro.VersionAlias : versionAlias;
                    }
                    var _product = new CartStoreProduct
                    {
                        ShopBranchId = shopBranchId,
                        CartItemId   = pitem.Id,
                        SkuId        = pitem.SkuId,
                        Id           = pro.Id,
                        ProductName  = pro.ProductName,
                        Price        = prodPrice,
                        Count        = pitem.Quantity,
                        Stock        = shopbranchsku == null ? 0 : shopbranchsku.Stock,
                        //阶梯价商品在门店购物车自动下架
                        Status       = ProductManagerApplication.GetProductShowStatus(pro, sku, 1, shopBranch, shopbranchsku),//0:正常;1:冻结;2:库存不足
                        SkuDetails   = skuDetails,
                        ColorAlias   = colorAlias,
                        SizeAlias    = sizeAlias,
                        VersionAlias = versionAlias,
                        Size         = sku.Size,
                        Color        = sku.Color,
                        Version      = sku.Version,
                        AddTime      = pitem.AddTime,
                        DefaultImage = MallIO.GetRomoteProductSizeImage(pro.ImagePath, 1, 500)
                    };
                    _store.Products.Add(_product);
                }
            }
            _store.Amount     = (_store.Products != null && _store.Products.Count > 0) ? _store.Products.Where(x => x.Status == 0).Sum(s => s.Price * s.Count) : 0;
            _store.TotalCount = (_store.Products != null && _store.Products.Count > 0) ? _store.Products.Where(x => x.Status == 0).Sum(s => s.Count) : 0;
            if (_store.Products.Count > 0)
            {//有商品数据,才返回门店信息
                _store.Products = _store.Products.OrderBy(p => p.Status).ThenByDescending(p => p.AddTime).ToList();
                //rets.Add(_store);
            }
            return(Json(_store));
        }
Exemplo n.º 13
0
        /// <summary>
        /// 商品信息转换
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        private product_item_model ProductInfoMapChange(Entities.ProductInfo data)
        {
            var prodata = data;

            if (prodata == null)
            {
                throw new MallApiException(OpenApiErrorCode.Product_Not_Exists, "num_iid");
            }
            product_item_model result = new product_item_model();

            #region 装配信息
            result.num_iid    = (int)prodata.Id;
            result.outer_id   = prodata.ProductCode;
            result.brand_id   = (int)prodata.BrandId;
            result.brand_name = prodata.BrandName;
            result.cid        = (int)prodata.CategoryId;
            result.type_id    = (int)prodata.TypeId;

            var category = CategoryApplication.GetCategory(prodata.CategoryId);
            var desc     = ProductManagerApplication.GetProductDescription(prodata.Id);
            if (category != null)
            {
                result.cat_name = category.Name;
                var type = TypeApplication.GetType(category.TypeId);
                if (type != null)
                {
                    result.type_name = type.Name;
                }
            }
            result.title            = prodata.ProductName.Trim();
            result.list_time        = prodata.AddedDate;
            result.modified         = prodata.AddedDate;
            result.display_sequence = (int)prodata.DisplaySequence;
            result.sold_quantity    = (int)prodata.SaleCounts;
            result.desc             = desc.Description;
            result.wap_desc         = desc.MobileDescription;
            result.pic_url.Add(System.IO.Path.Combine(OpenAPIHelper.HostUrl, prodata.GetImage(ImageSize.Size_350, 1)));
            ProductStatus ps = GetProductStatus(prodata);
            result.approve_status = ps.ToString();

            #region 商品属性填充
            var prodAttrs      = ProductManagerApplication.GetProductAttributes(prodata.Id);
            var prodAttrids    = prodAttrs.Select(d => d.AttributeId).ToList();
            var prodAttrValues = _iTypeService.GetAttributeValues(prodAttrids);
            result.props_name = "";
            if (prodAttrids.Count > 0)
            {
                List <string> propslst    = new List <string>();
                List <string> propsvallst = new List <string>();
                foreach (var curattid in prodAttrids)
                {
                    var item = prodAttrs.FirstOrDefault(d => d.AttributeId == curattid);
                    propsvallst.Clear();
                    var attribute = _iTypeService.GetAttribute(item.AttributeId);
                    var values    = prodAttrValues.Where(p => p.AttributeId == curattid);
                    foreach (var attrV in values)
                    {
                        if (prodAttrs.Any(p => p.ValueId == attrV.Id))
                        {
                            propsvallst.Add(attrV.Value);
                        }
                    }
                    propslst.Add(attribute.Name + "#cln#[" + string.Join(",", propsvallst.ToArray()) + "]");
                }
                result.props_name = string.Join("#scln#", propslst.ToArray());
            }
            #endregion

            #region  发货地区

            var prolocid = FreightTemplateApplication.GetFreightTemplate(prodata.FreightTemplateId).SourceAddress;
            result.location = "";

            var locpath = _iRegionService.GetFullName(prolocid, ",");
            result.location = "{'city':'#c#', 'state':'#p#'}";
            if (!string.IsNullOrWhiteSpace(locpath))
            {
                var _tmparr = locpath.Split(',');
                result.location = result.location.Replace("#p#", _tmparr[0]);
                if (_tmparr.Length > 1)
                {
                    result.location = result.location.Replace("#c#", _tmparr[1]);
                }
                else
                {
                    result.location = result.location.Replace("#c#", "");
                }
            }

            #endregion

            #region SKUS

            Entities.TypeInfo typeInfo     = _iTypeService.GetType(data.TypeId);
            string            colorAlias   = (typeInfo == null || string.IsNullOrEmpty(typeInfo.ColorAlias)) ? SpecificationType.Color.ToDescription() : typeInfo.ColorAlias;
            string            sizeAlias    = (typeInfo == null || string.IsNullOrEmpty(typeInfo.SizeAlias)) ? SpecificationType.Size.ToDescription() : typeInfo.SizeAlias;
            string            versionAlias = (typeInfo == null || string.IsNullOrEmpty(typeInfo.VersionAlias)) ? SpecificationType.Version.ToDescription() : typeInfo.VersionAlias;
            if (prodata != null)
            {
                colorAlias   = !string.IsNullOrWhiteSpace(prodata.ColorAlias) ? prodata.ColorAlias : colorAlias;
                sizeAlias    = !string.IsNullOrWhiteSpace(prodata.SizeAlias) ? prodata.SizeAlias : sizeAlias;
                versionAlias = !string.IsNullOrWhiteSpace(prodata.VersionAlias) ? prodata.VersionAlias : versionAlias;
            }
            result.skus = new List <product_sku_model>();
            var skus = ProductManagerApplication.GetSKUs(prodata.Id);
            foreach (var item in skus)
            {
                product_sku_model skudata = new product_sku_model();
                skudata.sku_id       = item.Id;
                skudata.outer_sku_id = item.Sku;
                skudata.price        = item.SalePrice;
                skudata.quantity     = (int)item.Stock;
                //skudata.sku_properties_name = "颜色:" + item.Color + "尺寸:" + item.Size + "版本:" + item.Version;
                skudata.sku_properties_name = colorAlias + ":" + item.Color + " " + sizeAlias + ":" + item.Size + " " + versionAlias + ":" + item.Version;
                string sku_properties_name = item.Color + " " + item.Size + " " + item.Version;
                if (string.IsNullOrWhiteSpace(sku_properties_name))
                {
                    skudata.sku_properties_name = "";
                }
                if (!string.IsNullOrWhiteSpace(skudata.sku_properties_name))
                {
                    result.skus.Add(skudata);
                }
            }
            #endregion

            #endregion

            return(result);
        }
Exemplo n.º 14
0
        public JsonResult GetCartProducts()
        {
            ShoppingCartInfo cart           = new CartHelper().GetCart(base.CurrentUser.Id);
            IProductService  productService = this._iProductService;
            IShopService     shopService    = this._iShopService;
            IVShopService    vshopService   = this._iVShopService;
            decimal          discount       = 1.0M;

            if (base.CurrentUser != null)
            {
                discount = base.CurrentUser.MemberDiscount;
            }
            List <long>           list          = new List <long>();
            decimal               prodPrice     = 0.0M;
            List <FlashSalePrice> limitProducts = LimitTimeApplication.GetPriceByProducrIds((from e in cart.Items select e.ProductId).ToList <long>());
            var source = from s in cart.Items.Where <ShoppingCartItem>(delegate(ShoppingCartItem d)
            {
                long?nullable;
                return(!d.ShopBranchId.HasValue || (((nullable = d.ShopBranchId).GetValueOrDefault() == 0L) && nullable.HasValue));
            }).Select(delegate(ShoppingCartItem item)
            {
                Func <FlashSalePrice, bool> predicate = null;
                ProductInfo product = productService.GetProduct(item.ProductId);
                ShopInfo shop       = shopService.GetShop(product.ShopId, false);
                SKUInfo sku         = null;
                string str          = "";
                string str2         = "";
                string str3         = "";
                string str4         = "";
                if (null != shop)
                {
                    string str5;
                    VShopInfo vShopByShopId = vshopService.GetVShopByShopId(shop.Id);
                    sku = productService.GetSku(item.SkuId);
                    if (sku == null)
                    {
                        return(null);
                    }
                    if (predicate == null)
                    {
                        predicate = e => e.ProductId == item.ProductId;
                    }
                    FlashSalePrice price = limitProducts.FirstOrDefault <FlashSalePrice>(predicate);
                    prodPrice            = sku.SalePrice;
                    if (price != null)
                    {
                        prodPrice = price.MinPrice;
                    }
                    else if (shop.IsSelf)
                    {
                        prodPrice = sku.SalePrice * discount;
                    }
                    ProductType type = TypeApplication.GetType(product.TypeId);
                    str  = ((type == null) || string.IsNullOrEmpty(type.ColorAlias)) ? SpecificationType.Color.ToDescription() : type.ColorAlias;
                    str2 = ((type == null) || string.IsNullOrEmpty(type.SizeAlias)) ? SpecificationType.Size.ToDescription() : type.SizeAlias;
                    str3 = ((type == null) || string.IsNullOrEmpty(type.VersionAlias)) ? SpecificationType.Version.ToDescription() : type.VersionAlias;
                    str4 = "";
                    if (!string.IsNullOrWhiteSpace(sku.Size))
                    {
                        str5 = str4;
                        str4 = str5 + str2 + ":" + sku.Size + "&nbsp;&nbsp;";
                    }
                    if (!string.IsNullOrWhiteSpace(sku.Color))
                    {
                        str5 = str4;
                        str4 = str5 + str + ":" + sku.Color + "&nbsp;&nbsp;";
                    }
                    if (!string.IsNullOrWhiteSpace(sku.Version))
                    {
                        str5 = str4;
                        str4 = str5 + str3 + ":" + sku.Version + "&nbsp;&nbsp;";
                    }
                    return(new
                    {
                        cartItemId = item.Id,
                        skuId = item.SkuId,
                        id = product.Id,
                        imgUrl = HimallIO.GetProductSizeImage(product.RelativePath, 1, 150),
                        name = product.ProductName,
                        price = prodPrice,
                        count = item.Quantity,
                        shopId = shop.Id,
                        vshopId = (vShopByShopId == null) ? 0L : vShopByShopId.Id,
                        shopName = shop.ShopName,
                        shopLogo = (vShopByShopId == null) ? "" : vShopByShopId.Logo,
                        status = ((product.AuditStatus == ProductInfo.ProductAuditStatus.Audited) && (product.SaleStatus == ProductInfo.ProductSaleStatus.OnSale)) ? 1 : 0,
                        Size = sku.Size,
                        Color = sku.Color,
                        Version = sku.Version,
                        ColorAlias = str,
                        SizeAlias = str2,
                        VersionAlias = str3,
                        skuDetails = str4,
                        AddTime = item.AddTime
                    });
                }
                return(null);
            })
                         where s != null
                         orderby s.vshopId, s.AddTime descending
            select s;
            BranchCartHelper helper2  = new BranchCartHelper();
            long             memberId = 0L;

            if (base.CurrentUser != null)
            {
                memberId = base.CurrentUser.Id;
            }
            ShoppingCartInfo cartNoCache = helper2.GetCartNoCache(memberId, 0L);
            List <long>      list2       = (from x in
                                            (from x in cartNoCache.Items
                                             where x.ShopBranchId.HasValue
                                             select x.ShopBranchId.Value).ToList <long>()
                                            group x by x into x
                                            select x.First <long>()).ToList <long>();
            Dictionary <long, int> buyedCounts = null;

            if (memberId > 0L)
            {
                cart        = helper2.GetCart(memberId, 0L);
                buyedCounts = new Dictionary <long, int>();
                buyedCounts = OrderApplication.GetProductBuyCount(memberId, from x in cart.Items select x.ProductId);
            }
            List <object> list3 = new List <object>();

            using (List <long> .Enumerator enumerator = list2.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    Func <ShoppingCartItem, bool> func = null;
                    long shopBranchId = enumerator.Current;
                    prodPrice = 0.0M;
                    List <ShopBranchSkusInfo> shopBranchSkuList = this._iShopBranchService.GetSkusByIds(shopBranchId, from x in cartNoCache.Items select x.SkuId);
                    if (func == null)
                    {
                        func = delegate(ShoppingCartItem x)
                        {
                            long?nullable1 = x.ShopBranchId;
                            long num       = shopBranchId;
                            return((nullable1.GetValueOrDefault() == num) && nullable1.HasValue);
                        };
                    }
                    var enumerable2 = from s in cartNoCache.Items.Where <ShoppingCartItem>(func).Select(delegate(ShoppingCartItem item)
                    {
                        Func <ShopBranchSkusInfo, bool> predicate = null;
                        if (shopBranchId == 0x63L)
                        {
                        }
                        ShopBranchInfo shopBranchById = this._iShopBranchService.GetShopBranchById(shopBranchId);
                        ProductInfo product           = this._iProductService.GetProduct(item.ProductId);
                        ShopInfo shop = this._iShopService.GetShop(product.ShopId, false);
                        SKUInfo sku   = null;
                        if ((shop != null) && (shopBranchById != null))
                        {
                            VShopInfo vShopByShopId = this._iVShopService.GetVShopByShopId(shop.Id);
                            sku = this._iProductService.GetSku(item.SkuId);
                            if (sku == null)
                            {
                                return(null);
                            }
                            prodPrice = sku.SalePrice;
                            if (shop.IsSelf)
                            {
                                prodPrice = sku.SalePrice * discount;
                            }
                            if (predicate == null)
                            {
                                predicate = x => x.SkuId == item.SkuId;
                            }
                            ShopBranchSkusInfo info6 = shopBranchSkuList.FirstOrDefault <ShopBranchSkusInfo>(predicate);
                            long maxBuyCount         = (info6 == null) ? ((long)0) : ((long)info6.Stock);
                            if ((maxBuyCount > product.MaxBuyCount) && (product.MaxBuyCount > 0))
                            {
                                maxBuyCount = product.MaxBuyCount;
                            }
                            if (((product.MaxBuyCount > 0) && (buyedCounts != null)) && buyedCounts.ContainsKey(item.ProductId))
                            {
                                int num3     = buyedCounts[item.ProductId];
                                maxBuyCount -= num3;
                            }
                            return(new { cartItemId = item.Id, skuId = item.SkuId, id = product.Id, imgUrl = HimallIO.GetProductSizeImage(product.RelativePath, 1, 150), name = product.ProductName, price = prodPrice, count = item.Quantity, status = (info6 == null) ? 1 : ((info6.Status == ShopBranchSkuStatus.Normal) ? ((item.Quantity > maxBuyCount) ? 2 : 0) : 1), AddTime = item.AddTime, shopBranchId = shopBranchById.Id, shopBranchName = shopBranchById.ShopBranchName });
                        }
                        return(null);
                    })
                                      where s != null
                                      orderby s.AddTime descending
                                      select s;
                    list3.Add(enumerable2);
                }
            }
            var data = new
            {
                products       = source,
                amount         = Enumerable.Sum(source, item => item.price * (Decimal)item.count),
                totalCount     = Enumerable.Sum(source, item => item.count),
                shopBranchCart = list3
            };

            return(base.Json(data));
        }
Exemplo n.º 15
0
        public JsonResult GetBranchCartProducts(long shopBranchId)
        {
            BranchCartHelper helper   = new BranchCartHelper();
            long             memberId = 0L;
            decimal          discount = 1.0M;

            if (base.CurrentUser != null)
            {
                memberId = base.CurrentUser.Id;
                discount = base.CurrentUser.MemberDiscount;
            }
            ShoppingCartInfo       cart           = helper.GetCart(memberId, shopBranchId);
            ShopBranchInfo         shopBranchById = this._iShopBranchService.GetShopBranchById(shopBranchId);
            Dictionary <long, int> buyedCounts    = null;

            if (memberId > 0L)
            {
                buyedCounts = new Dictionary <long, int>();
                buyedCounts = OrderApplication.GetProductBuyCount(memberId, from x in cart.Items select x.ProductId);
            }
            decimal prodPrice = 0.0M;
            List <ShopBranchSkusInfo> shopBranchSkuList = this._iShopBranchService.GetSkusByIds(shopBranchId, from x in cart.Items select x.SkuId);
            var enumerable = from s in cart.Items.Select(delegate(ShoppingCartItem item)
            {
                ProductInfo product      = this._iProductService.GetProduct(item.ProductId);
                ShopBranchSkusInfo info2 = shopBranchSkuList.FirstOrDefault <ShopBranchSkusInfo>(x => x.SkuId == item.SkuId);
                long maxBuyCount         = (info2 == null) ? ((long)0) : ((long)info2.Stock);
                if ((maxBuyCount > product.MaxBuyCount) && (product.MaxBuyCount != 0))
                {
                    maxBuyCount = product.MaxBuyCount;
                }
                if (((product.MaxBuyCount > 0) && (buyedCounts != null)) && buyedCounts.ContainsKey(item.ProductId))
                {
                    int num2     = buyedCounts[item.ProductId];
                    maxBuyCount -= num2;
                }
                ShopInfo shop = this._iShopService.GetShop(product.ShopId, false);
                SKUInfo sku   = null;
                string str    = "";
                if (null != shop)
                {
                    VShopInfo vShopByShopId = this._iVShopService.GetVShopByShopId(shop.Id);
                    sku = this._iProductService.GetSku(item.SkuId);
                    if (sku == null)
                    {
                        return(null);
                    }
                    prodPrice = sku.SalePrice;
                    if (shop.IsSelf)
                    {
                        prodPrice = sku.SalePrice * discount;
                    }
                    ProductType type = TypeApplication.GetType(product.TypeId);
                    str = "";
                    if (!string.IsNullOrWhiteSpace(sku.Size))
                    {
                        str = str + sku.Size + "&nbsp;&nbsp;";
                    }
                    if (!string.IsNullOrWhiteSpace(sku.Color))
                    {
                        str = str + sku.Color + "&nbsp;&nbsp;";
                    }
                    if (!string.IsNullOrWhiteSpace(sku.Version))
                    {
                        str = str + sku.Version + "&nbsp;&nbsp;";
                    }
                    return(new { bId = shopBranchId, cartItemId = item.Id, skuId = item.SkuId, id = product.Id, name = product.ProductName, price = prodPrice, count = item.Quantity, stock = (info2 == null) ? 0L : maxBuyCount, status = (info2 == null) ? 1 : ((info2.Status == ShopBranchSkuStatus.Normal) ? ((item.Quantity > maxBuyCount) ? 2 : 0) : 1), skuDetails = str, AddTime = item.AddTime });
                }
                return(null);
            })
                             where s != null
                             orderby s.status, s.AddTime descending
            select s;
            var data = new
            {
                products         = enumerable,
                amount           = Enumerable.Sum(Enumerable.Where(enumerable, x => x.status == 0), item => item.price * (Decimal)item.count),
                totalCount       = Enumerable.Sum(Enumerable.Where(enumerable, x => x.status == 0), item => item.count),
                DeliveFee        = shopBranchById.DeliveFee,
                DeliveTotalFee   = shopBranchById.DeliveTotalFee,
                FreeMailFee      = shopBranchById.FreeMailFee,
                shopBranchStatus = shopBranchById.Status
            };

            return(base.Json(data));
        }