Exemplo n.º 1
0
        public IQueryable<Entity.Entity.Coupon.Coupon> GetCouponByCondition(CouponSearchCondition condition)
        {
            var query = _couponRepository.Table;
            try
            {
                if (condition.Ids.HasValue)
                {
                    query = query.Where(q => condition.Ids==q.Id);
                }
                if (!string.IsNullOrEmpty(condition.Number))
                {
                    query = query.Where(q => q.Number== condition.Number);
                }
                if (condition.CouponCategoryId.HasValue)
                {
                    query = query.Where(q => condition.CouponCategoryId == q.CouponCategoryId);
                }
                if (condition.Status.HasValue)
                {
                    query = query.Where(q => (EnumCouponStatus)condition.Status == q.Status);
                }
                if (condition.IdArray != null && condition.IdArray.Any())
                {
                    query = query.Where(q => condition.IdArray.Contains(q.Id));
                }
                if(condition.OrderBy.HasValue)
				{
					switch (condition.OrderBy.Value)
                    {
						case EnumCouponSearchOrderBy.OrderById:
							query = condition.IsDescending?query.OrderByDescending(q=>q.Id):query.OrderBy(q=>q.Id);
							break;
                    }					
				}
				else
				{
					query = query.OrderBy(q=>q.Id);
				}

				if (condition.Page.HasValue && condition.PageCount.HasValue)
                {
                    query = query.Skip((condition.Page.Value - 1)*condition.PageCount.Value).Take(condition.PageCount.Value);
                }
                return query;
            }
                
            catch (Exception e)
            {
                _log.Error(e, "数据库操作出错");
                return null;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 抢优惠券
        /// </summary>
        /// <param name="id">优惠券种类Id</param>
        /// <returns></returns>

        public ActionResult couponOwn(int id)
        {
            

            if (_workContext.CurrentUser == null)
            {
                return Redirect("http://www.iyookee.cn/#/user/login");
            }
            var couponCategory = _couponCategoryService.GetCouponCategoryById(id);
            var condition = new CouponSearchCondition
            {
                CouponCategoryId = id,
                Status = 0
            };
            var coupon = _couponService.GetCouponByCondition(condition).FirstOrDefault();
            _couponOwnerService.CreateRecord(_workContext.CurrentUser.Id, coupon.Id);
            coupon.Status = EnumCouponStatus.Owned;
            _couponService.Update(coupon);
            couponCategory.Count = couponCategory.Count - 1;
            _couponCategoryService.UpdateCouponCategory(couponCategory);
            var brand = _productBrandService.GetProductBrandById(couponCategory.BrandId);
            var CouponOwn = new CouponCategoryModel
            {
                Name = couponCategory.Name,
                Number = coupon.Number,
                BrandName = brand.Bname
            };
            var phone = _brokerService.GetBrokerByUserId(_workContext.CurrentUser.Id).Phone;

            //短信发送
            SMSHelper.Sending(phone, "优惠券为:" + brand.Bname + ",券号为:" + coupon.Number + " 【优客惠】");
            
            return View(CouponOwn);
        }
        public HttpResponseMessage couponOwn(int id)
        {
            if (_workContext.CurrentUser == null)
            {
                return PageHelper.toJson(PageHelper.ReturnValue(false, "请先登录优客惠"));
            }

            var couponCategory = _couponCategoryService.GetCouponCategoryById(id);

            //检测是否已经抢过
            var sech = new CouponOwnerSearchCondition
            {
                userId = _workContext.CurrentUser.Id
            };
            var list = _couponOwnerService.GetCouponOwnByCondition(sech).Select(p => p.CouponId).ToArray();
            if (list.Any())
            {
                var sech2 = new CouponSearchCondition
                {
                    CouponCategoryId = id,
                    IdArray = list
                };
                var count = _couponService.GetCouponCount(sech2);
                if (count != 0)
                {
                    return PageHelper.toJson(PageHelper.ReturnValue(false, "您已经抢过这家的优惠券了"));
                }
            }

            var condition = new CouponSearchCondition
            {
                CouponCategoryId = id,
                Status = 0
            };
            var coupon = _couponService.GetCouponByCondition(condition).FirstOrDefault();
            _couponOwnerService.CreateRecord(_workContext.CurrentUser.Id, coupon.Id);
            coupon.Status = EnumCouponStatus.Owned;
            _couponService.Update(coupon);
            couponCategory.Count = couponCategory.Count - 1;
            _couponCategoryService.UpdateCouponCategory(couponCategory);
            var brand = _productBrandService.GetProductBrandById(couponCategory.BrandId);
            var CouponOwn = new CouponCategoryModel
            {
                Name = couponCategory.Name,
                Number = coupon.Number,
                BrandName = brand.Bname
            };
            var model = _brokerService.GetBrokerByUserId(_workContext.CurrentUser.Id);

            //短信发送
            SMSHelper.Sending(model.Phone, "优惠券为:" + brand.Bname + ",券号为:" + coupon.Number + " 【优客惠】");

            return PageHelper.toJson(CouponOwn);
        }
Exemplo n.º 4
0
        public int GetCouponCount(CouponSearchCondition condition)
        {
            var query = _couponRepository.Table;
            try
            {
                if (condition.Ids.HasValue)
                {
                    query = query.Where(q => condition.Ids == q.Id);
                }
                if (!string.IsNullOrEmpty(condition.Number))
                {
                    query = query.Where(q => q.Number == condition.Number);
                }
                if (condition.CouponCategoryId.HasValue)
                {
                    query = query.Where(q => condition.CouponCategoryId == q.CouponCategoryId);
                }
                if (condition.IdArray != null && condition.IdArray.Any())
                {
                    query = query.Where(q => condition.IdArray.Contains(q.Id));
                }
                if (condition.Status.HasValue)
                {
                    query = query.Where(q => (EnumCouponStatus)condition.Status == q.Status);
                }
                return query.Count();
            }

            catch (Exception e)
            {
                _log.Error(e, "数据库操作出错");
                return -1;
            }
        }