Пример #1
0
        /// <summary>
        /// 获取系统可领取优惠券列表
        /// </summary>
        /// <returns></returns>
        public JsonResult <Result <dynamic> > GetLoadSiteCoupon(string openId = "", int pageSize = 10, int pageIndex = 1, int obtainWay = 1)
        {
            CheckUserLogin();
            CouponRecordQuery query = new CouponRecordQuery();

            query.UserId   = CurrentUser.Id;
            query.PageNo   = pageIndex;
            query.PageSize = pageSize;
            if (obtainWay == 1) //(1=未使用 2=已使用 3=已过期)
            {
                query.Status = 0;
            }
            else if (obtainWay == 2)
            {
                query.Status = 1;
            }
            else
            {
                query.Status = obtainWay;
            }
            var record  = CouponApplication.GetCouponRecordList(query);
            var coupons = CouponApplication.GetCouponInfo(record.Models.Select(p => p.Id));
            var list    = record.Models.Select(
                item => {
                var coupon = coupons.FirstOrDefault(p => p.Id == item.CouponId);
                return(new
                {
                    CouponId = coupon.Id,
                    CouponName = coupon.CouponName,
                    Price = Math.Round(coupon.Price, 2),
                    SendCount = coupon.Num,
                    UserLimitCount = coupon.PerMax,
                    OrderUseLimit = Math.Round(coupon.OrderAmount, 2),
                    StartTime = coupon.StartTime.ToString("yyyy.MM.dd"),
                    ClosingTime = coupon.EndTime.ToString("yyyy.MM.dd"),
                    ObtainWay = coupon.ReceiveType,
                    NeedPoint = coupon.NeedIntegral,
                    UseArea = coupon.UseArea,
                    Remark = coupon.Remark
                });
            });

            return(JsonResult <dynamic>(new { total = record.Total, Data = list }));
        }
Пример #2
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)));
            }
        }