Пример #1
0
        /// <summary>
        /// 获取用户优惠券列表
        /// </summary>
        /// <returns></returns>
        public JsonResult <Result <dynamic> > GetLoadCoupon()
        {
            CheckUserLogin();
            var userCouponList = CouponApplication.GetUserCouponList(CurrentUser.Id);
            var shopBonus      = GetBonusList();

            if (userCouponList != null || shopBonus != null)
            {
                //优惠券
                var couponlist = new Object();
                if (userCouponList != null)
                {
                    couponlist = userCouponList.ToArray().Select(a => new
                    {
                        UserId          = a.UserId,
                        ShopId          = a.ShopId,
                        CouponId        = a.CouponId,
                        Price           = a.Price,
                        PerMax          = a.PerMax,
                        OrderAmount     = a.OrderAmount,
                        ShowOrderAmount = a.OrderAmount,
                        Num             = a.Num,
                        StartTime       = a.StartTime.ToString(),
                        EndTime         = a.EndTime.ToString(),
                        CreateTime      = a.CreateTime.ToString(),
                        CouponName      = a.CouponName,
                        UseStatus       = a.UseStatus,
                        UseTime         = a.UseTime.HasValue ? a.UseTime.ToString() : null,
                        VShop           = GetVShop(a.ShopId),
                        ShopName        = a.ShopName,
                        Remark          = a.Remark,
                        UseArea         = a.UseArea
                    });
                }
                else
                {
                    couponlist = null;
                }
                //代金红包
                var userBonus = new List <dynamic>();
                if (shopBonus != null)
                {
                    userBonus = shopBonus.Select(item =>
                    {
                        var bonusService    = ServiceProvider.Instance <IShopBonusService> .Create;
                        var grant           = bonusService.GetGrant(item.BonusGrantId);
                        var bonus           = bonusService.GetShopBonus(grant.ShopBonusId);
                        var shop            = ShopApplication.GetShop(bonus.ShopId);
                        var vShop           = VshopApplication.GetVShopByShopId(shop.Id);
                        var Price           = item.Price;
                        var showOrderAmount = bonus.UsrStatePrice > 0 ? bonus.UsrStatePrice : item.Price;
                        if (bonus.UseState != Entities.ShopBonusInfo.UseStateType.FilledSend)
                        {
                            showOrderAmount = item.Price;
                        }
                        var Logo     = string.Empty;
                        long VShopId = 0;
                        if (vShop != null)
                        {
                            Logo    = Core.HimallIO.GetRomoteImagePath(vShop.StrLogo);
                            VShopId = vShop.Id;
                        }

                        var State = (int)item.State;
                        if (item.State != ShopBonusReceiveInfo.ReceiveState.Use && bonus.DateEnd < DateTime.Now)
                        {
                            State = (int)ShopBonusReceiveInfo.ReceiveState.Expired;
                        }
                        var BonusDateEnd    = bonus.BonusDateEnd.ToString("yyyy-MM-dd");
                        dynamic obj         = new System.Dynamic.ExpandoObject();
                        obj.Price           = Price;
                        obj.ShowOrderAmount = showOrderAmount;
                        obj.Logo            = Logo;
                        obj.VShopId         = VShopId;
                        obj.State           = State;
                        obj.BonusDateEnd    = BonusDateEnd;
                        obj.ShopName        = shop.ShopName;
                        obj.DateEnd         = bonus.DateEnd;
                        return(obj);
                    }).ToList();
                }
                else
                {
                    shopBonus = null;
                }
                //优惠券
                int NoUseCouponCount = 0;
                int UseCouponCount   = 0;
                if (userCouponList != null)
                {
                    NoUseCouponCount = userCouponList.Count(item => (item.EndTime > DateTime.Now && item.UseStatus == CouponRecordInfo.CounponStatuses.Unuse));
                    UseCouponCount   = userCouponList.Count() - NoUseCouponCount;
                }
                //红包
                int NoUseBonusCount = 0;
                int UseBonusCount   = 0;
                if (shopBonus != null)
                {
                    var nusv = ShopBonusReceiveInfo.ReceiveState.NotUse.GetHashCode();
                    NoUseBonusCount = userBonus.Count(r => r.State == nusv && r.DateEnd > DateTime.Now);
                    UseBonusCount   = userBonus.Count() - NoUseBonusCount;
                }

                int UseCount    = UseCouponCount + UseBonusCount;
                int NotUseCount = NoUseCouponCount + NoUseBonusCount;

                var result = new
                {
                    success    = true,
                    NoUseCount = NotUseCount,
                    UserCount  = UseCount,
                    Coupon     = couponlist,
                    Bonus      = userBonus
                };
                return(JsonResult <dynamic>(result));
            }
            else
            {
                throw new Himall.Core.HimallException("没有领取记录!");
            }
        }