示例#1
0
        public bool AddUserCoupon(int id, int userId)
        {
            if (id <= 0 || userId <= 0)
            {
                return(false);
            }

            using (var cxt = DbContext(DbOperation.Write))
            {
                cxt.BeginTransaction();

                var repo = new CouponRepo(cxt);
                var flag = repo.AddUserCoupon(id, userId);

                if (flag)
                {
                    cxt.Commit();
                }
                else
                {
                    cxt.Rollback();
                }

                return(flag);
            }
        }
        public CouponTemplateDto GetCouponTemplateDto(Guid id)
        {
            var couponTemplate = Repository.GetIncludes(false, "Stock").FirstOrDefault(f => f.ID == id);

            if (couponTemplate == null)
            {
                throw new DomainException("未找到记录");
            }
            var couponQueryable = CouponRepo.GetQueryable(false);

            return(new CouponTemplateDto
            {
                ID = couponTemplate.ID,
                CouponType = (int)couponTemplate.CouponType,
                CouponTypeName = this.GetEnumDescription(couponTemplate.CouponType),
                TemplateCode = couponTemplate.TemplateCode,
                Title = couponTemplate.Title,
                PutInStartDate = couponTemplate.PutInStartDate.GetValueOrDefault().ToDateString(),
                PutInEndDate = couponTemplate.PutInEndDate.GetValueOrDefault().ToDateString(),
                FreeStock = couponTemplate.Stock.FreeStock,
                Validity = couponTemplate.IsFiexedEffectPeriod ?
                           couponTemplate.EffectiveDate.Value.ToDateString() + "~" + couponTemplate.ExpiredDate.Value.ToDateString()
                            : $"领取后{couponTemplate.EffectiveDaysAfterReceived.GetValueOrDefault()}天生效,{couponTemplate.EffectiveDays.GetValueOrDefault()}天有效",
                CreatedDate = couponTemplate.CreatedDate,
            });
        }
示例#3
0
        public UserCouponDto GetDefault(int userId, int totalFee)
        {
            if (userId <= 0)
            {
                return(null);
            }

            using (var cxt = DbContext(DbOperation.Read))
            {
                var repo = new CouponRepo(cxt);
                return(repo.GetDefault(userId, totalFee));
            }
        }
示例#4
0
        public CouponDto GetDetail(int id, int userId)
        {
            if (id <= 0)
            {
                return(null);
            }

            using (var cxt = DbContext(DbOperation.Read))
            {
                var repo = new CouponRepo(cxt);
                return(repo.GetDetail(id, userId));
            }
        }
示例#5
0
        public IEnumerable <UserCouponDto> GetNoUseList(int userId, int totalFee)
        {
            if (userId <= 0 && totalFee <= 0)
            {
                return(null);
            }

            using (var cxt = DbContext(DbOperation.Read))
            {
                var repo = new CouponRepo(cxt);
                return(repo.GetNoUseList(userId, totalFee));
            }
        }
 public CouponController(CouponRepo couponRepo)
 {
     this.couponRepo = couponRepo;
 }
        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));
        }