Beispiel #1
0
        /// <summary>
        /// 领取优惠券
        /// </summary>
        /// <returns></returns>
        public JsonResult <Result <int> > GetUserCoupon(string openId, long couponId)
        {
            CheckUserLogin();
            bool   status  = true;
            string message = "";
            //long vshopId = vspId;// value.vshopId; 店铺Id
            //long couponId = couponId;// value.couponId; 优惠劵Id
            var couponInfo = CouponApplication.GetCouponInfo(couponId);

            if (couponInfo.EndTime < DateTime.Now)
            {//已经失效
                status  = false;
                message = "优惠券已经过期";
            }
            CouponRecordQuery crQuery = new CouponRecordQuery();

            crQuery.CouponId = couponId;
            crQuery.UserId   = CurrentUser.Id;
            QueryPageModel <CouponRecordInfo> pageModel = CouponApplication.GetCouponRecordList(crQuery);

            if (couponInfo.PerMax != 0 && pageModel.Total >= couponInfo.PerMax)
            {//达到个人领取最大张数
                status  = false;
                message = "达到领取最大张数";
            }
            crQuery = new CouponRecordQuery()
            {
                CouponId = couponId
            };
            pageModel = CouponApplication.GetCouponRecordList(crQuery);
            if (pageModel.Total >= couponInfo.Num)
            {//达到领取最大张数
                status  = false;
                message = "此优惠券已经领完了";
            }
            if (couponInfo.ReceiveType == CouponInfo.CouponReceiveType.IntegralExchange)
            {
                var userInte = MemberIntegralApplication.GetMemberIntegral(CurrentUserId);
                if (userInte.AvailableIntegrals < couponInfo.NeedIntegral)
                {
                    //积分不足
                    status  = false;
                    message = "积分不足 ";
                }
            }
            if (status)
            {
                CouponRecordInfo couponRecordInfo = new CouponRecordInfo()
                {
                    CouponId = couponId,
                    UserId   = CurrentUser.Id,
                    UserName = CurrentUser.UserName,
                    ShopId   = couponInfo.ShopId
                };
                CouponApplication.AddCouponRecord(couponRecordInfo);
                return(JsonResult <int>(msg: "领取成功"));//执行成功
            }
            else
            {
                return(Json(ErrorResult <int>(message)));
            }
        }