public string Verification(PromotionEntity promotionEntity)
        {
            if (promotionEntity == null)
            {
                return "活动不存在";
            }

            if (promotionEntity.StartDate > DateTime.Now)
            {
                return "活动还没有开始";
            }

            if (promotionEntity.EndDate < DateTime.Now)
            {
                return "活动已经结束";
            }

            if (promotionEntity.PublicationLimit != null && promotionEntity.PublicationLimit > 0)
            {
                //验证优惠券领取数
                var c = _couponService.GetCouponCount(promotionEntity.Id, SourceType.Promotion);
                if (promotionEntity.PublicationLimit <= c)
                {
                    return "活动优惠码已售罄";
                }
            }

            return null;
        }
        public PromotionInfoResponse PromotionInfoResponseMapping(PromotionEntity source)
        {
            if (source == null)
            {
                return null;
            }

            var target = Mapper.Map<PromotionEntity, PromotionInfoResponse>(source);

            return target;
        }
        public PromotionEntity PromotionEntityMapping(PromotionEntity source, PromotionEntity target)
        {
            var result = Mapper.Map(source, target);

            return result;
        }
        private static ItemsInfoResponse ItemsInfoResponseMapping(PromotionEntity source, StoreInfoResponse store, List<ResourceInfoResponse> resources, PromotionInfo info)
        {
            var target = Mapper.Map<PromotionEntity, ItemsInfoResponse>(source);

            target.SType = SourceType.Promotion;
            target.Store = store;
            target.Resources = resources;

            if (info != null)
            {
                target.Promotions = new List<PromotionInfo> { info };
            }

            return target;
        }
 private ItemsInfoResponse ItemsInfoResponseMapping(PromotionEntity source, StoreInfoResponse store, List<ResourceInfoResponse> resources)
 {
     return ItemsInfoResponseMapping(source, store, resources, null);
 }
        public FavoriteInfoResponse FavoriteInfoResponseMapping(FavoriteEntity source, PromotionEntity promotionEntity)
        {
            var target = Mapper.Map<FavoriteEntity, FavoriteInfoResponse>(source);
            target.FavoriteSourceName = promotionEntity == null ? String.Empty : promotionEntity.Name;

            return target;
        }
        public static CouponCodeResponse CouponCodeResponseMapping(CouponHistoryEntity source, ProductEntity product,
                                                                   PromotionEntity promotion)
        {
            if (source == null)
            {
                return null;
            }

            var target = Mapper.Map<CouponHistoryEntity, CouponCodeResponse>(source);

            var productname = String.Empty;
            var producttype = 0;
            var productid = 0;
            var productDescription = String.Empty;
            if (promotion != null)
            {
                productname = promotion.Name;
                producttype = (int)SourceType.Promotion;
                productid = promotion.Id;
                productDescription =
                promotion.Description;
                target.Stype = SourceType.Promotion;
            }
            else
            {
                if (product != null)
                {
                    productname = product.Name;
                    producttype = (int)SourceType.Product;
                    productid = product.Id;
                    productDescription =
                    product.Description;
                    target.Stype = SourceType.Product;
                }
            }

            target.ProductId = productid;
            target.ProductName = productname;
            target.ProductType = producttype;
            target.ProductDescription = productDescription;


            return target;
        }
 public PromotionInfoResponse PromotionResponseMapping(PromotionEntity source)
 {
     return PromotionResponseMapping(source, null);
 }
        /// <summary>
        /// 需要计算 距离
        /// </summary>
        /// <param name="source"></param>
        /// <param name="coordinateInfo">坐标</param>
        /// <returns></returns>
        public PromotionInfoResponse PromotionResponseMapping(PromotionEntity source, CoordinateInfo coordinateInfo)
        {
            if (source == null)
            {
                return null;
            }

            ShowCustomerInfoResponse showCustomer = null;
            StoreInfoResponse storeInfoResponse = null;
            List<ResourceInfoResponse> resourceInfoResponses = null;
            List<int> brandIds = null;
            if (source.RecommendUser > 0)
            {
                var userEntity = _customerRepository.GetItem(source.RecommendUser);
                if (userEntity != null)
                {
                    showCustomer = ShowCustomerInfoResponseMapping(userEntity);
                }
            }

            if (source.Store_Id > 0)
            {
                var store = _storeRepository.GetItem(source.Store_Id);
                storeInfoResponse = StoreResponseMapping(store, coordinateInfo);
            }

            var resource =
                _resourceRepository.Get(
                    v =>
                    v.Status == (int)DataStatus.Normal && v.SourceId == source.Id &&
                    (int)SourceType.Promotion == v.SourceType).OrderByDescending(r=>r.SortOrder).ToList();

            resourceInfoResponses = ResourceInfoResponsesMapping(resource).ToList();

            var brandids = _promotionBrandRelationRepository.GetList(source.Id).Select(v => v.Brand_Id).ToList();

            if (brandids.Count > 0)
            {
                brandIds = brandids;
            }

            return PromotionResponseMapping(source, coordinateInfo, brandIds, resourceInfoResponses, storeInfoResponse,
                                            showCustomer);
        }
        public PromotionInfoResponse PromotionResponseMapping(PromotionEntity source, CoordinateInfo coordinateInfo, List<int> brandIds, List<ResourceInfoResponse> resourceInfoResponses, StoreInfoResponse storeInfoResponse, ShowCustomerInfoResponse showCustomerInfoResponse)
        {
            if (source == null)
            {
                return null;
            }

            var target = PromotionInfoResponseMapping(source);

            if (showCustomerInfoResponse != null)
            {
                target.ShowCustomer = showCustomerInfoResponse;
            }

            if (storeInfoResponse != null)
            {
                target.StoreInfoResponse = storeInfoResponse;
            }

            if (resourceInfoResponses != null)
            {
                target.ResourceInfoResponses = resourceInfoResponses;
            }

            if (brandIds != null)
            {
                target.BrandIds = brandIds;
            }

            return target;
        }