/// <summary>
        /// 根据商品ID取门店sku信息
        /// </summary>
        /// <param name="shopBranchId"></param>
        /// <param name="pid"></param>
        /// <returns></returns>
        public static List <DTO.SKU> GetSkusByProductId(long shopBranchId, long pid)
        {
            var sku            = ProductManagerApplication.GetSKU(pid);
            var shopBranchSkus = _shopBranchService.GetSkusByIds(shopBranchId, sku.Select(e => e.Id));

            foreach (var item in sku)
            {
                var branchSku = shopBranchSkus.FirstOrDefault(e => e.SkuId == item.Id);
                if (branchSku != null)
                {
                    item.Stock = branchSku.Stock;
                }
            }
            return(sku);
        }
Example #2
0
        public static bool BranchCanBuy(long userId, long productId, int count, string skuId, long shopBranchId, out int reason)
        {
            var product = Service.GetProduct(productId);

            if (product.SaleStatus != Entities.ProductInfo.ProductSaleStatus.OnSale || product.AuditStatus != Entities.ProductInfo.ProductAuditStatus.Audited)
            {
                //商城商品下架,但是门店的商品状态销售中,允许用户购买。
                //商城商品下架后,销售状态-仓库中,审核状态-待审核
                if (product.SaleStatus != Entities.ProductInfo.ProductSaleStatus.InStock && product.AuditStatus != Entities.ProductInfo.ProductAuditStatus.WaitForAuditing)
                {
                    reason = 1;
                    return(false);
                }
            }
            var sku = ProductManagerApplication.GetSKU(skuId);

            if (sku == null)
            {
                reason = 2;
                return(false);
            }
            var shopBranch = ShopBranchApplication.GetShopBranchById(shopBranchId);

            if (shopBranch == null)
            {
                reason = 4;
                return(false);
            }
            var shopBranchSkuList = ShopBranchApplication.GetSkusByIds(shopBranchId, new List <string> {
                skuId
            });

            if (shopBranchSkuList == null || shopBranchSkuList.Count == 0 || shopBranchSkuList[0].Status == ShopBranchSkuStatus.InStock)
            {
                reason = 2;
                return(false);
            }
            var sbsku = shopBranchSkuList.FirstOrDefault();

            if (sbsku.Stock < count)
            {
                reason = 9;
                return(false);
            }
            if (product.IsDeleted)
            {
                reason = 2;
                return(false);
            }

            if (product.MaxBuyCount <= 0)
            {
                reason = 0;
                return(true);
            }

            var buyedCounts = OrderApplication.GetProductBuyCount(userId, new long[] { productId });

            if (product.MaxBuyCount < count + (buyedCounts.ContainsKey(productId) ? buyedCounts[productId] : 0))
            {
                reason = 3;
                return(false);
            }
            reason = 0;
            return(true);
        }