//private string GetProductNames(string productCodes)
        //{
        //    if (string.IsNullOrEmpty(productCodes))
        //    {
        //        return string.Empty;
        //    }
        //    var requestUri = string.Format("{0}/OpenApi/Member/GetProducts?productCodes={1}",
        //        AppContext.Settings.PosService, productCodes);
        //    var httpClient = new HttpClient();
        //    httpClient.DefaultRequestHeaders.Add(Constants.HttpHeaderCompanyCode, AppContext.Settings.CompanyCode);
        //    var response = httpClient.GetStringAsync(requestUri).Result;
        //    var result = JsonHelper.FromJson<PagedActionResult<ProductDto>>(response);
        //    if (!result.IsSuccessful)
        //    {
        //        AppContext.Logger.Error("GetProductNames has error. ErrorMessage:{0}", result.ErrorMessage);
        //        return string.Empty;
        //    }
        //    var productNames = string.Empty;
        //    result.Data.ForEach(item =>
        //    {
        //        productNames += item.Name + ',';
        //    });
        //    if (productNames.Length > 0)
        //    {
        //        productNames = productNames.Substring(0, productNames.Length - 1);
        //    }
        //    return productNames;
        //}

        /// <summary>
        /// 有效劵信息
        /// </summary>
        /// <param name="filter"></param>
        /// <param name="totalCount"></param>
        /// <returns></returns>
        public IEnumerable <CouponTemplateDto> GetValidCouponTemplateInfo(CouponTemplateFilter filter, out int totalCount)
        {
            var queryable = this.Repository.GetIncludes(false, "Stock", "UseTimeList");
            var dateNow   = DateTime.Now;

            if (filter != null)
            {
                if (!string.IsNullOrEmpty(filter.Title))
                {
                    queryable = queryable.Where(t => t.Title.Contains(filter.Title));
                }
                if (!string.IsNullOrEmpty(filter.TemplateCodeOrTitle))
                {
                    queryable = queryable.Where(t => t.TemplateCode.Contains(filter.TemplateCodeOrTitle) || t.Title.Contains(filter.TemplateCodeOrTitle));
                }
            }
            var result = queryable.Where(c => c.ApproveStatus == EApproveStatus.Delivered && !c.IsSpecialCoupon && ((c.EffectiveDate != null && c.ExpiredDate > dateNow) || c.EffectiveDate == null) && (c.PutInStartDate != null && c.PutInStartDate <= dateNow) && (c.PutInEndDate != null && c.PutInEndDate > dateNow)).ToArray();

            result = result.Where(t => t.Stock.FreeStock > 0).ToArray();

            totalCount = result.Count();

            return(result.Select(c => new CouponTemplateDto
            {
                ID = c.ID,
                CouponTypeName = this.GetEnumDescription(c.CouponType),
                TemplateCode = c.TemplateCode,
                Title = c.Title,
                Validity = c.IsFiexedEffectPeriod ? ((DateTime)c.EffectiveDate).ToString("yyyy-MM-dd") + "~" + ((DateTime)c.ExpiredDate).ToString("yyyy-MM-dd") : "领取后" + (c.EffectiveDaysAfterReceived != null ? c.EffectiveDaysAfterReceived : 0) + "天生效," + (c.EffectiveDays != null ? c.EffectiveDays : 0) + "天有效",
                AproveStatusText = this.GetEnumDescription(c.ApproveStatus),
                FreeStock = c.Stock.FreeStock,
                ExpiredDate = c.GetExpiredDate().ToDateString(),
                IsFiexedEffectPeriod = c.IsFiexedEffectPeriod,
            }).OrderByDescending(t => t.CreatedDate));
        }
示例#2
0
 public PagedActionResult <CouponTemplateDto> GetValidCouponTemplateInfo([FromUri] CouponTemplateFilter filter)
 {
     return(SafeGetPagedData <CouponTemplateDto>((result) =>
     {
         var totalCount = 0;
         var data = this.CouponTemplateService.GetValidCouponTemplateInfo(filter, out totalCount);
         result.Data = data;
         result.TotalCount = totalCount;
     }));
 }
        public IEnumerable <CouponTemplate> Query(CouponTemplateFilter filter, out int totalCount)
        {
            var queryable = this.Repository.GetQueryable(false);

            if (filter.CouponType != -1)
            {
                queryable = queryable.Where(c => c.CouponType == (ECouponType)filter.CouponType);
            }
            if (!string.IsNullOrEmpty(filter.Title))
            {
                queryable = queryable.Where(c => c.Title.Contains(filter.Title));
            }
            totalCount = queryable.Count();
            if (filter.Start.HasValue && filter.Limit.HasValue)
            {
                queryable = queryable.Skip(filter.Start.Value).Take(filter.Limit.Value);
            }
            return(queryable.ToArray());
        }
        public IEnumerable <CouponTemplateDto> CouponTemplateInfo(CouponTemplateFilter filter, out int totalCount)
        {
            var queryable = this.Repository.GetIncludes(false, "Stock", "UseTimeList");

            if (filter.CouponType != -1)
            {
                queryable = queryable.Where(c => c.CouponType == (ECouponType)filter.CouponType);
            }
            if (filter.AproveStatus != -2)
            {
                queryable = queryable.Where(c => c.ApproveStatus == (EApproveStatus)filter.AproveStatus);
            }
            if (!string.IsNullOrEmpty(filter.Title))
            {
                queryable = queryable.Where(c => c.Title.Contains(filter.Title));
            }
            if (filter.HiddenExpirePutInDate)
            {
                var nowDate = DateTime.Now;
                queryable = queryable.Where(c => c.PutInEndDate >= nowDate);
            }
            if (filter.IsNotSpecialCoupon)
            {
                queryable = queryable.Where(t => !t.IsSpecialCoupon);
            }
            totalCount = queryable.Count();
            if (filter.Start.HasValue && filter.Limit.HasValue)
            {
                queryable = queryable.OrderByDescending(t => t.CreatedDate).Skip(filter.Start.Value).Take(filter.Limit.Value);
            }
            var couponQueryable = CouponRepo.GetQueryable(false);
            var result          = queryable.ToArray().Select(c => new CouponTemplateDto
            {
                ID             = c.ID,
                IsRecommend    = c.IsRecommend,
                CouponType     = (int)c.CouponType,
                Nature         = c.Nature,
                CouponTypeName = this.GetEnumDescription(c.CouponType),
                CouponCode     = couponQueryable.Where(cou => cou.TemplateID == c.ID).FirstOrDefault() != null ? couponQueryable.Where(cou => cou.TemplateID == c.ID).FirstOrDefault().CouponCode : string.Empty,
                TemplateCode   = c.TemplateCode,
                Title          = c.Title,
                Validity       = c.IsFiexedEffectPeriod ?
                                 c.EffectiveDate.Value.ToDateString() + "~" + c.ExpiredDate.Value.ToDateString()
                    : $"领取后{c.EffectiveDaysAfterReceived.GetValueOrDefault()}天生效,{c.EffectiveDays.GetValueOrDefault()}天有效",
                EffectiveDate              = c.GetEffectiveDate().ToDateString(),
                ExpiredDate                = c.GetExpiredDate().ToDateString(),
                PutInStartDate             = c.PutInStartDate.GetValueOrDefault().ToDateString(),
                PutInEndDate               = c.PutInEndDate.GetValueOrDefault().ToDateString(),
                AproveStatus               = c.ApproveStatus,
                AproveStatusText           = this.GetEnumDescription(c.ApproveStatus),
                Stock                      = c.Stock.Stock,
                FreeStock                  = c.Stock.FreeStock,
                CreatedDate                = c.CreatedDate,
                IsSpecialCoupon            = c.IsSpecialCoupon,
                Color                      = c.Color,
                CouponValue                = c.CouponValue,
                SubTitle                   = c.SubTitle,
                CoverImage                 = c.CoverImage,
                UseInstructions            = c.UseInstructions,
                MerchantPhoneNo            = c.MerchantPhoneNo,
                OperationTips              = c.OperationTips,
                VerificationModeDesc       = GetEnumDescription(c.VerificationMode),
                IsMinConsumeLimit          = c.IsMinConsumeLimit,
                MinConsume                 = c.MinConsume,
                IsExclusive                = c.IsExclusive,
                MerchantServiceDesc        = GetMerchantServiceDesc(c.MerchantService),
                ApplyStoresName            = GetDepartmentInfo(c.ApplyStores),
                IsApplyAllStore            = c.IsApplyAllStore,
                CollarQuantityLimit        = c.Stock.CollarQuantityLimit,
                UseTimeList                = c.UseTimeList,
                UseDaysOfWeek              = c.UseDaysOfWeek,
                PutInUseDaysOfWeek         = c.PutInUseDaysOfWeek,
                IsPutaway                  = c.IsPutaway,
                IncludeProductNames        = c.IncludeProducts, //!= null ? GetProductNames(c.IncludeProducts) : string.Empty,
                ExcludeProductNames        = c.ExcludeProducts, //!= null ? GetProductNames(c.ExcludeProducts) : string.Empty,
                IncludeProducts            = c.IncludeProducts,
                ExcludeProducts            = c.ExcludeProducts,
                EffectiveDaysAfterReceived = c.EffectiveDaysAfterReceived,
                EffectiveDays              = c.EffectiveDays,
                CoverIntro                 = c.CoverIntro,
                IntroDetail                = c.IntroDetail,
                MerchantService            = c.MerchantService,
                IsNoCollarQuantityLimit    = c.Stock.IsNoCollarQuantityLimit,
                CanShareByPeople           = c.CanShareByPeople,
                VerificationMode           = c.VerificationMode,
                ApplyStores                = c.ApplyStores,
                PutawayTime                = c.PutawayTime != null ? ((DateTime)c.PutawayTime).ToString("yyyy-MM-dd") : string.Empty,
                SoldOutTime                = c.SoldOutTime != null ? ((DateTime)c.SoldOutTime).ToString("yyyy-MM-dd") : string.Empty,
                IsFiexedEffectPeriod       = c.IsFiexedEffectPeriod,
                IsUseAllTime               = c.IsUseAllTime,
                CanGiveToPeople            = c.CanGiveToPeople,
                Remark                     = c.Remark,
                PutInIsUseAllTime          = c.PutInIsUseAllTime,
                IsDeductionFirst           = c.IsDeductionFirst,
            }).ToArray();

            return(result.OrderByDescending(t => t.CreatedDate));
        }