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.º 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);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 获取优惠券
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult OtherCouponOwn(int id)
        {
            if (_workContext.CurrentUser == null)
            {
                return Redirect("http://www.iyookee.cn/#/user/login");
            }
            var couponCategory = _otherCouponCategoryService.GetCouponCategoryById(id);
            var condition = new OtherCouponSearchCondition
            {
                CouponCategoryId = id,
                Status = 0
            };
            var coupon = _otherCouponService.GetCouponByCondition(condition).FirstOrDefault();

            if (coupon != null)
            {
                _otherCouponOwnerService.CreateRecord(_workContext.CurrentUser.Id, coupon.Id);
                coupon.Status = EnumOtherCouponStatus.Owned;
                _otherCouponService.Update(coupon);
                couponCategory.Count = couponCategory.Count - 1;
                _otherCouponCategoryService.UpdateCouponCategory(couponCategory);
                var brand = _productBrandService.GetProductBrandById(couponCategory.BrandId);
                var couponOwn = new CouponCategoryModel
                {
                    Name = couponCategory.Name,
                    Number = coupon.Number,
                    BrandName = brand.Bname
                };
                return View(couponOwn);
            }
            return RedirectToAction("OtherCoupons", "OtherCoupons");
        }