Esempio n. 1
0
        /// <summary>
        /// 获取商品列表(平台获取平台商品、店铺获取店铺商品)
        /// </summary>
        /// <param name="search"></param>
        /// <returns></returns>
        public Jinher.AMP.BTP.Deploy.CustomDTO.ComdtyListResultCDTO GetCommodityListV2Ext(CommodityListSearchDTO search)
        {
            Jinher.AMP.BTP.Deploy.CustomDTO.ComdtyListResultCDTO comdtyListResultCDTO = new Jinher.AMP.BTP.Deploy.CustomDTO.ComdtyListResultCDTO();
            try
            {
                if (search == null || search.PageSize <= 0 || search.PageIndex <= 0)
                {
                    comdtyListResultCDTO.isSuccess   = false;
                    comdtyListResultCDTO.Code        = 1;
                    comdtyListResultCDTO.Message     = "参数不能为空";
                    comdtyListResultCDTO.realCount   = 0;
                    comdtyListResultCDTO.comdtyList  = null;
                    comdtyListResultCDTO.appInfoList = null;
                    return(comdtyListResultCDTO);
                }
                if (!search.AppId.HasValue || search.AppId == Guid.Empty)
                {
                    comdtyListResultCDTO.isSuccess   = false;
                    comdtyListResultCDTO.Code        = 1;
                    comdtyListResultCDTO.Message     = "参数不能为空";
                    comdtyListResultCDTO.realCount   = 0;
                    comdtyListResultCDTO.comdtyList  = null;
                    comdtyListResultCDTO.appInfoList = null;
                    return(comdtyListResultCDTO);
                }

                DateTime now = DateTime.Now;

                var appId = search.AppId.Value;

                IQueryable <Commodity> ocommodityList;
                //用于存储临加入真实价格后的Commodity信息
                IQueryable <TempCommodity> tempOcommodityList;
                //根据是否平台区分
                bool isPavilion = Jinher.AMP.BTP.TPS.ZPHSV.Instance.IsAppPavilion(search.AppId.Value);
                if (isPavilion)
                {
                    tempOcommodityList = (from cs in CommodityCategory.ObjectSet()
                                          join cate in Category.ObjectSet() on cs.CategoryId equals cate.Id
                                          join c in Commodity.ObjectSet() on cs.CommodityId equals c.Id
                                          join pro in
                                          (
                                              from query in TodayPromotion.ObjectSet()
                                              where
                                              (query.PromotionType != 3 &&
                                               (query.StartTime <= now || query.PresellStartTime <= now) &&
                                               query.EndTime > now)
                                              select query
                                          ) on c.Id equals pro.CommodityId
                                          into todayPros
                                          from promotion in todayPros.DefaultIfEmpty()
                                          where cs.AppId == appId && c.IsDel == false && c.State == 0 && c.CommodityType == 0 && !cate.IsDel
                                          orderby c.Salesvolume descending, c.SubTime descending
                                          select new TempCommodity
                    {
                        Com = c,
                        newPrice = (promotion.Id == null) ? c.Price : (promotion.DiscountPrice > 0 ? promotion.DiscountPrice : c.Price * promotion.Intensity / 10)
                    });
                }
                else
                {
                    tempOcommodityList = (from c in Commodity.ObjectSet()
                                          join pro in
                                          (
                                              from query in TodayPromotion.ObjectSet()
                                              where (query.PromotionType != 3 && (query.StartTime <= now || query.PresellStartTime <= now) && query.EndTime > now)
                                              select query
                                          ) on c.Id equals pro.CommodityId
                                          into todayPros
                                          from promotion in todayPros.DefaultIfEmpty()

                                          where c.AppId == appId && c.IsDel == false && c.State == 0 && c.CommodityType == 0
                                          select new TempCommodity
                    {
                        Com = c,
                        newPrice = (promotion.Id == null) ? c.Price : (promotion.DiscountPrice > 0 ? promotion.DiscountPrice : c.Price * promotion.Intensity / 10)
                    });
                }

                if (search.MinPrice.HasValue && search.MinPrice != 0)
                {
                    tempOcommodityList = tempOcommodityList.Where(c => c.newPrice >= search.MinPrice);
                }
                if (search.MaxPrice.HasValue && search.MaxPrice != 0)
                {
                    tempOcommodityList = tempOcommodityList.Where(c => c.newPrice <= search.MaxPrice);
                }

                ocommodityList = tempOcommodityList.Select(c => c.Com).Distinct();


                if (search.IsHasStock)
                {
                    ocommodityList = ocommodityList.Where(c => c.Stock > 0);
                }

                if (!ProvinceCityHelper.IsTheWholeCountry(search.areaCode))
                {
                    var province = ProvinceCityHelper.GetProvinceByAreaCode(search.areaCode);
                    var city     = ProvinceCityHelper.GetCityByAreaCode(search.areaCode);
                    if (province != null && city != null)
                    {
                        if (province.AreaCode == city.AreaCode)
                        {
                            ocommodityList = ocommodityList.Where(c => c.SaleAreas == null || c.SaleAreas == "" || c.SaleAreas == ProvinceCityHelper.CountryCode || c.SaleAreas.Contains(province.AreaCode));
                        }
                        else
                        {
                            ocommodityList = ocommodityList.Where(c => c.SaleAreas == null || c.SaleAreas == "" || c.SaleAreas == ProvinceCityHelper.CountryCode || c.SaleAreas.Contains(province.AreaCode) || c.SaleAreas.Contains(city.AreaCode));
                        }
                    }
                }
                var commoditiesQuery         = from c in ocommodityList select c;
                List <Commodity> commodities = null;
                List <Jinher.AMP.BTP.Deploy.CustomDTO.CommodityListCDTO> commodityList = null;

                comdtyListResultCDTO.realCount = commoditiesQuery.Count();
                if (isPavilion)
                {
                    commodities = (from c in commoditiesQuery
                                   orderby c.Salesvolume descending, c.SubTime descending
                                   select c).Skip((search.PageIndex - 1) * search.PageSize).Take(search.PageSize).ToList();
                }
                else
                {
                    commodities = (from c in commoditiesQuery
                                   orderby c.SortValue
                                   select c).Skip((search.PageIndex - 1) * search.PageSize).Take(search.PageSize).ToList();
                }

                //commodities = commoditiesQuery.Skip((search.PageIndex - 1) * search.PageSize).Take(search.PageSize).ToList();


                if (!commodities.Any())
                {
                    return(comdtyListResultCDTO);
                }

                commodityList = commodities.Select(c => new Jinher.AMP.BTP.Deploy.CustomDTO.CommodityListCDTO
                {
                    Id               = c.Id,
                    Pic              = c.PicturesPath,
                    Price            = c.Price,
                    State            = c.State,
                    Stock            = c.Stock,
                    Name             = c.Name,
                    MarketPrice      = c.MarketPrice,
                    AppId            = c.AppId,
                    IsEnableSelfTake = c.IsEnableSelfTake,
                    ComAttribute     = c.ComAttribute,
                    ComAttrType      = (c.ComAttribute == "[]" || c.ComAttribute == null) ? 1 : 3
                }).ToList();

                var appList = commodities.Select(c => c.AppId).Distinct().ToList();

                #region 众筹
                if (CustomConfig.CrowdfundingFlag)
                {
                    var crowdFundingApps = Crowdfunding.ObjectSet().Where(c => c.StartTime < now && c.State == 0 && appList.Contains(c.AppId)).Select(c => c.AppId).ToList();
                    if (crowdFundingApps.Any())
                    {
                        for (int i = 0; i < commodityList.Count; i++)
                        {
                            if (crowdFundingApps.Any(c => c == commodityList[i].AppId))
                            {
                                commodityList[i].IsActiveCrowdfunding = true;
                            }
                        }
                    }
                }
                #endregion

                var commodityIds = commodityList.Select(c => c.Id).Distinct().ToList();
                var comStockList = CommodityStock.ObjectSet()
                                   .Where(c => commodityIds.Contains(c.CommodityId))
                                   .Select(
                    c =>
                    new Deploy.CommodityStockDTO
                {
                    Id          = c.Id,
                    CommodityId = c.CommodityId,
                    Price       = c.Price,
                    MarketPrice = c.MarketPrice
                })
                                   .ToList();
                var todayPromotions = TodayPromotion.GetCurrentPromotionsWithPresell(commodityIds);

                foreach (var commodity in commodityList)
                {
                    commodity.IsMultAttribute = Commodity.CheckComMultAttribute(commodity.ComAttribute);
                    List <Deploy.CommodityStockDTO> comStocks = comStockList.Where(c => c.CommodityId == commodity.Id).ToList();

                    var todayPromotion = todayPromotions.FirstOrDefault(c => c.CommodityId == commodity.Id && c.PromotionType != 3);

                    if (todayPromotion != null)
                    {
                        commodity.LimitBuyEach         = todayPromotion.LimitBuyEach ?? -1;
                        commodity.LimitBuyTotal        = todayPromotion.LimitBuyTotal ?? -1;
                        commodity.SurplusLimitBuyTotal = todayPromotion.SurplusLimitBuyTotal ?? 0;
                        commodity.PromotionType        = todayPromotion.PromotionType;
                        if (todayPromotion.DiscountPrice > -1)
                        {
                            commodity.DiscountPrice = Convert.ToDecimal(todayPromotion.DiscountPrice);
                            commodity.Intensity     = 10;
                        }
                        else
                        {
                            commodity.DiscountPrice = -1;
                            commodity.Intensity     = todayPromotion.Intensity;
                        }
                    }
                    else
                    {
                        commodity.DiscountPrice        = -1;
                        commodity.Intensity            = 10;
                        commodity.LimitBuyEach         = -1;
                        commodity.LimitBuyTotal        = -1;
                        commodity.SurplusLimitBuyTotal = -1;
                        commodity.PromotionType        = 9999;
                    }
                    buildShowPrice(commodity, comStocks, todayPromotion);
                }

                try
                {
                    var apps = APPSV.GetAppListByIds(appList);
                    if (apps != null && apps.Any())
                    {
                        comdtyListResultCDTO.appInfoList = new List <ComdtyAppInfoCDTO>();
                        foreach (var appInfo in apps)
                        {
                            comdtyListResultCDTO.appInfoList.Add(new ComdtyAppInfoCDTO
                            {
                                appId   = appInfo.AppId,
                                appName = appInfo.AppName,
                                icon    = appInfo.AppIcon
                            });
                        }

                        foreach (var commodityListCdto in commodityList)
                        {
                            var appInfo = apps.FirstOrDefault(c => c.AppId == commodityListCdto.AppId);
                            if (appInfo != null)
                            {
                                commodityListCdto.AppName = appInfo.AppName;
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    LogHelper.Error(string.Format("AppSetSV.GetCommodityListExt,获取app名称错误。appId:{0}", appId), ex);
                }

                comdtyListResultCDTO.comdtyList = commodityList;
            }
            catch (Exception ex)
            {
                LogHelper.Error(string.Format("商品列表查询错误,CommoditySV.GetCommodityListV2Ext。search:{0}", JsonHelper.JsonSerializer(search)), ex);
                comdtyListResultCDTO.isSuccess   = false;
                comdtyListResultCDTO.Code        = -1;
                comdtyListResultCDTO.Message     = "Error";
                comdtyListResultCDTO.realCount   = 0;
                comdtyListResultCDTO.comdtyList  = null;
                comdtyListResultCDTO.appInfoList = null;
                return(comdtyListResultCDTO);
            }
            comdtyListResultCDTO.isSuccess = true;
            comdtyListResultCDTO.Code      = 0;
            comdtyListResultCDTO.Message   = "Success";
            return(comdtyListResultCDTO);
        }
Esempio n. 2
0
        /// <summary>
        /// 根据用户ID查询收藏商品
        /// </summary>
        /// <param name="userId">商品ID</param>
        /// <param name="appId">appId</param>
        /// <returns></returns>
        public System.Collections.Generic.List <Jinher.AMP.BTP.Deploy.CustomDTO.CommoditySDTO> GetCollectionItemsExt(System.Guid userId, System.Guid appId)
        {
            var commodityList = (from data in Collection.ObjectSet()
                                 join data1 in Commodity.ObjectSet() on data.CommodityId equals data1.Id
                                 where data.UserId == userId && data.AppId == appId && data1.IsDel == false && data1.CommodityType == 0
                                 select new CommoditySDTO
            {
                Name = data1.Name,
                Id = data1.Id,
                Price = data1.Price,
                Pic = data1.PicturesPath,
                Stock = data1.Stock,
                State = data1.State,
                CollectNum = data1.TotalCollection,
                ReviewNum = data1.TotalReview,
                Total = data1.Salesvolume
            }).ToList();

            DateTime now = DateTime.Now;

            List <Guid> commodityIds = commodityList.Select(c => c.Id).ToList();

            //读今日折扣表
            try
            {
                //zgx-modify
                var comAttributeList = (from a in CommodityStock.ObjectSet()
                                        where commodityIds.Contains(a.CommodityId)
                                        group a by a.CommodityId into g
                                        select new
                {
                    minPrice = g.Min(a => a.Price),
                    maxPrice = g.Max(a => a.Price),
                    CommodityId = g.Key
                }).ToList();

                var promotionDic = TodayPromotion.GetCurrentPromotionsWithPresell(commodityIds);

                foreach (var commodity in commodityList)
                {
                    //zgx-modify
                    if (comAttributeList != null && comAttributeList.Count > 0)
                    {
                        var comAttribute = comAttributeList.Find(r => r.CommodityId == commodity.Id);
                        if (comAttribute != null)
                        {
                            commodity.MaxPrice = comAttribute.maxPrice;
                            commodity.MinPrice = comAttribute.minPrice;
                        }
                    }

                    bool isdi = false;
                    foreach (var com in promotionDic)
                    {
                        if (com.CommodityId == commodity.Id)
                        {
                            commodity.LimitBuyEach         = com.LimitBuyEach == null ? -1 : com.LimitBuyEach;
                            commodity.LimitBuyTotal        = com.LimitBuyTotal == null ? -1 : com.LimitBuyTotal;
                            commodity.SurplusLimitBuyTotal = com.SurplusLimitBuyTotal == null ? 0 : com.SurplusLimitBuyTotal;
                            if (com.DiscountPrice > -1)
                            {
                                commodity.DiscountPrice = Convert.ToDecimal(com.DiscountPrice);
                                commodity.Intensity     = 10;
                                isdi = true;
                                break;
                            }
                            else
                            {
                                commodity.DiscountPrice = -1;
                                commodity.Intensity     = com.Intensity;
                                isdi = true;
                                break;
                            }
                        }
                    }
                    if (!isdi)
                    {
                        commodity.DiscountPrice        = -1;
                        commodity.Intensity            = 10;
                        commodity.LimitBuyEach         = -1;
                        commodity.LimitBuyTotal        = -1;
                        commodity.SurplusLimitBuyTotal = -1;
                    }
                    //if (promotionDic.ContainsKey(commodity.Id))
                    //{
                    //    commodity.Intensity = promotionDic[commodity.Id];
                    //}
                    //else
                    //{
                    //    commodity.Intensity = 10;
                    //}
                }
            }
            catch (Exception e)
            {
                Jinher.JAP.Common.Loging.LogHelper.Error(string.Format("商品列表查询错误,userId{111},appId{111}", userId, appId), e);
            }
            return(commodityList);
        }