/// <summary>
        /// 用户收藏的店铺
        /// </summary>
        /// <param name="pageNo"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public object GetUserCollectionShop(int pageNo = 1, int pageSize = 8)
        {
            CheckUserLogin();
            if (CurrentUser != null)
            {
                var model = ServiceProvider.Instance <IShopService> .Create.GetUserConcernShops(CurrentUser.Id, pageNo, pageSize);

                var result = model.Models.Select(item =>
                {
                    var shop  = ShopApplication.GetShop(item.ShopId);
                    var vShop = VshopApplication.GetVShopByShopId(item.ShopId);
                    return(new
                    {
                        //Id = item.Id,
                        Id = vShop?.Id ?? 0,
                        ShopId = item.ShopId,
                        Logo = vShop == null ? HimallIO.GetRomoteImagePath(shop.Logo) : HimallIO.GetRomoteImagePath(vShop.Logo),
                        Name = shop.ShopName,
                        Status = shop.ShopStatus,
                        ConcernTime = item.Date,
                        ConcernTimeStr = item.Date.ToString("yyyy-MM-dd"),
                        ConcernCount = FavoriteApplication.GetFavoriteShopCountByShop(item.ShopId)
                    });
                });
                return(new { success = true, data = result });
            }
            else
            {
                return(new Result {
                    success = false, msg = "未登录"
                });
            }
        }
        protected override void OnActionExecuting(System.Web.Mvc.ActionExecutingContext filterContext)
        {
            ViewBag.AreaName = string.Format("m-{0}", PlatformType.ToString());
            ViewBag.Logo     = SiteSettings.Logo;
            ViewBag.SiteName = SiteSettings.SiteName;
            //区分平台还是商家
            var MAppType = WebHelper.GetCookie(CookieKeysCollection.MobileAppType);
            var MVshopId = WebHelper.GetCookie(CookieKeysCollection.HIMALL_VSHOPID);

            if (MAppType == string.Empty)
            {
                if (filterContext.HttpContext.Request["shop"] != null)
                {//微信菜单中是否存在店铺ID
                    MAppType = filterContext.HttpContext.Request["shop"].ToString();
                    long shopid = 0;
                    if (long.TryParse(MAppType, out shopid))
                    {//记录当前微店(从微信菜单进来,都带有shop参数)
                        var vshop = VshopApplication.GetVShopByShopId(shopid) ?? new Entities.VShopInfo()
                        {
                        };
                        WebHelper.SetCookie(CookieKeysCollection.HIMALL_VSHOPID, vshop.Id.ToString());
                    }
                    WebHelper.SetCookie(CookieKeysCollection.MobileAppType, MAppType);
                }
            }
            ViewBag.MAppType = MAppType;
            ViewBag.MVshopId = MVshopId;
            if (!filterContext.IsChildAction && !filterContext.HttpContext.Request.IsAjaxRequest())
            {
                //统计代码
                StatisticApplication.StatisticPlatVisitUserCount();
            }
            base.OnActionExecuting(filterContext);
        }
Beispiel #3
0
        /// <summary>
        /// 取积分优惠券
        /// </summary>
        /// <param name="page"></param>
        /// <param name="pagesize"></param>
        /// <returns></returns>
        public JsonResult <Result <dynamic> > GetIntegralCoupon(int pageNo = 1, int pageSize = 10)
        {
            QueryPageModel <CouponInfo> coupons = CouponApplication.GetIntegralCoupons(pageNo, pageSize);

            Mapper.CreateMap <CouponInfo, CouponGetIntegralCouponModel>();
            QueryPageModel <CouponGetIntegralCouponModel> result = new QueryPageModel <CouponGetIntegralCouponModel>();

            result.Total = coupons.Total;
            if (result.Total > 0)
            {
                var datalist = coupons.Models.ToList();

                var objlist = new List <CouponGetIntegralCouponModel>();
                foreach (var item in datalist)
                {
                    var tmp = Mapper.Map <CouponGetIntegralCouponModel>(item);
                    tmp.ShowIntegralCover = Core.HimallIO.GetRomoteImagePath(item.IntegralCover);
                    var vshopobj = VshopApplication.GetVShopByShopId(tmp.ShopId);
                    if (vshopobj != null)
                    {
                        tmp.VShopId = vshopobj.Id;
                        //优惠价封面为空时,取微店Logo,微店Logo为空时,取商城微信Logo
                        if (string.IsNullOrWhiteSpace(tmp.ShowIntegralCover))
                        {
                            if (!string.IsNullOrWhiteSpace(vshopobj.WXLogo))
                            {
                                tmp.ShowIntegralCover = Core.HimallIO.GetRomoteImagePath(vshopobj.WXLogo);
                            }
                        }
                    }
                    if (string.IsNullOrWhiteSpace(tmp.ShowIntegralCover))
                    {
                        var siteset = SiteSettingApplication.SiteSettings;
                        tmp.ShowIntegralCover = Core.HimallIO.GetRomoteImagePath(siteset.WXLogo);
                    }
                    objlist.Add(tmp);
                }
                result.Models = objlist.ToList();
            }
            return(JsonResult <dynamic>(new { total = result.Total, Data = result.Models }));
        }
Beispiel #4
0
        public ActionResult Detail(long id)
        {
            var    topic   = TopicApplication.GetTopic(id);
            string tmppath = VTemplateHelper.GetTemplatePath(id.ToString(), VTemplateClientTypes.WapSpecial);

            tmppath = "~" + tmppath;
            string viewpath = tmppath + "Skin-HomePage.cshtml";

            if (topic != null)
            {//判空处理
                ViewBag.Title = "专题-" + topic.Name;
            }
            else
            {
                throw new Himall404();
            }
            VTemplateHelper.DownloadTemplate(id.ToString(), VTemplateClientTypes.WapSpecial);
            ViewBag.ShopId = topic.ShopId;
            var vshop = VshopApplication.GetVShopByShopId(topic.ShopId);

            ViewBag.VshopId = vshop == null ? 0 : vshop.Id;
            return(View(viewpath, topic));
        }
Beispiel #5
0
        public object GetUserCounponList()
        {
            CheckUserLogin();
            var service        = ServiceProvider.Instance <ICouponService> .Create;
            var vshop          = ServiceProvider.Instance <IVShopService> .Create;
            var userCouponList = service.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,
                        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 Price = item.Price;

                        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 showOrderAmount = bonus.UsrStatePrice > 0 ? bonus.UsrStatePrice : item.Price;
                        if (bonus.UseState != 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.DateEnd         = bonus.DateEnd;
                        obj.ShopName        = shop.ShopName;
                        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)
                {
                    NoUseBonusCount = userBonus.Count(r => r.State == (int)ShopBonusReceiveInfo.ReceiveState.NotUse && 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(result);
            }
            else
            {
                throw new Himall.Core.HimallException("没有领取记录!");
            }
        }
Beispiel #6
0
        public object GetIndexData(string openId = "")
        {
            //轮播图
            dynamic result  = new System.Dynamic.ExpandoObject();
            var     slidads = SlideApplication.GetSlidAds(0, Entities.SlideAdInfo.SlideAdType.AppGifts).ToList();

            foreach (var item in slidads)
            {
                item.ImageUrl = MallIO.GetRomoteImagePath(item.ImageUrl);
            }
            result.SlideAds = slidads;

            //大转盘刮刮卡
            var malllist = new List <IntegralMallAdInfo>();
            var robj     = GiftApplication.GetAdInfo(IntegralMallAdInfo.AdActivityType.Roulette, IntegralMallAdInfo.AdShowPlatform.APP);

            if (robj != null)
            {
                //robj.LinkUrl = Request.RequestUri.Scheme + "://" + Request.RequestUri.Authority + "/m-wap/BigWheel/index/" + robj.ActivityId;
                robj.LinkUrl = "/m-wap/BigWheel/index/" + robj.ActivityId;
                malllist.Add(robj);
            }
            var cobj = GiftApplication.GetAdInfo(IntegralMallAdInfo.AdActivityType.ScratchCard, IntegralMallAdInfo.AdShowPlatform.APP);

            if (cobj != null)
            {
                //cobj.LinkUrl = Request.RequestUri.Scheme + "://" + Request.RequestUri.Authority + "/m-wap/ScratchCard/index/" + cobj.ActivityId;
                cobj.LinkUrl = "/m-wap/ScratchCard/index/" + cobj.ActivityId;
                malllist.Add(cobj);
            }
            result.WeiActives = malllist;

            //首页礼品
            GiftQuery query = new GiftQuery();

            query.skey     = "";
            query.status   = Mall.Entities.GiftInfo.GiftSalesStatus.Normal;
            query.PageSize = 4;
            query.PageNo   = 1;
            QueryPageModel <GiftModel> gifts = GiftApplication.GetGifts(query);

            result.HomeGiftses  = gifts.Models.ToList();
            result.HasMoreGifts = gifts.Total > 4;
            foreach (var item in result.HomeGiftses)
            {
                item.DefaultShowImage = MallIO.GetRomoteImagePath(item.GetImage(ImageSize.Size_350));
            }

            //积分优惠券
            var coupons = CouponApplication.GetIntegralCoupons(1, 3);

            //   Mapper.CreateMap<CouponInfo, CouponGetIntegralCouponModel>();
            if (coupons.Models.Count > 0)
            {
                var datalist = coupons.Models.ToList();
                var objlist  = new List <CouponGetIntegralCouponModel>();
                foreach (var item in datalist)
                {
                    var tmp = item.Map <CouponGetIntegralCouponModel>();
                    tmp.ShowIntegralCover = MallIO.GetRomoteImagePath(item.IntegralCover);
                    var vshopobj = VshopApplication.GetVShopByShopId(tmp.ShopId);
                    if (vshopobj != null)
                    {
                        tmp.VShopId = vshopobj.Id;
                        //优惠价封面为空时,取微店Logo,微店Logo为空时,取商城微信Logo
                        if (string.IsNullOrWhiteSpace(tmp.ShowIntegralCover))
                        {
                            if (!string.IsNullOrWhiteSpace(vshopobj.WXLogo))
                            {
                                tmp.ShowIntegralCover = MallIO.GetRomoteImagePath(vshopobj.WXLogo);
                            }
                        }
                    }
                    if (string.IsNullOrWhiteSpace(tmp.ShowIntegralCover))
                    {
                        var siteset = SiteSettingApplication.SiteSettings;
                        tmp.ShowIntegralCover = MallIO.GetRomoteImagePath(siteset.WXLogo);
                    }
                    objlist.Add(tmp);
                }
                result.IntegralCoupons        = objlist.ToList();
                result.HasMoreIntegralCoupons = coupons.Total > 3;
            }

            result.HasLogined = false;

            //用户积分与等级
            if (CurrentUser != null)
            {
                //登录后处理会员积分
                var userInte  = MemberIntegralApplication.GetMemberIntegral(CurrentUser.Id);
                var userGrade = MemberGradeApplication.GetMemberGradeByUserIntegral(userInte.HistoryIntegrals);
                result.MemberAvailableIntegrals = userInte.AvailableIntegrals;
                result.MemberGradeName          = userGrade.GradeName;
                result.HasLogined = true;
            }
            return(Json(result));
        }
Beispiel #7
0
        private List <CartProductModel> PackageCartProducts(Himall.Entities.ShoppingCartInfo cart, decimal discount, bool isBranch = false)
        {
            List <CartProductModel> products = new List <CartProductModel>();
            var limitProducts = LimitTimeApplication.GetPriceByProducrIds(cart.Items.Select(e => e.ProductId).ToList());//限时购价格
            var groupCart     = cart.Items.Where(item => item.ShopBranchId == 0).Select(c =>
            {
                var cItem   = new Himall.Entities.ShoppingCartItem();
                var skuInfo = _iProductService.GetSku(c.SkuId);
                if (skuInfo != null)
                {
                    cItem = c;
                }
                return(cItem);
            }).GroupBy(i => i.ProductId).ToList();

            foreach (var item in cart.Items)
            {
                var                        product       = ProductManagerApplication.GetProduct(item.ProductId);
                var                        shop          = _iShopService.GetShop(product.ShopId);
                DTO.ShopBranch             shopbranch    = null;
                Entities.ShopBranchSkuInfo shopbranchsku = null;
                if (item.ShopBranchId > 0)
                {
                    shopbranch    = ShopBranchApplication.GetShopBranchById(item.ShopBranchId);
                    shopbranchsku = ShopBranchApplication.GetSkusByIds(item.ShopBranchId, new List <string> {
                        item.SkuId
                    }).FirstOrDefault();
                }

                if (null != shop)
                {
                    var vshop = VshopApplication.GetVShopByShopId(shop.Id);
                    var sku   = ProductManagerApplication.GetSKU(item.SkuId);
                    if (sku == null)
                    {
                        continue;
                    }
                    //处理限时购、会员折扣价格
                    var prod      = limitProducts.FirstOrDefault(e => e.ProductId == item.ProductId);
                    var prodPrice = sku.SalePrice;
                    if (prod != null && !isBranch)
                    {
                        prodPrice = prod.MinPrice;
                    }
                    else
                    {
                        if (shop.IsSelf)
                        {//官方自营店才计算会员折扣
                            prodPrice = sku.SalePrice * discount;
                        }
                    }
                    #region 阶梯价--张宇枫
                    //阶梯价
                    if (product.IsOpenLadder)
                    {
                        var quantity = groupCart.Where(i => i.Key == item.ProductId).ToList().Sum(cartitem => cartitem.Sum(i => i.Quantity));
                        prodPrice = ProductManagerApplication.GetProductLadderPrice(item.ProductId, quantity);
                        if (shop.IsSelf)
                        {
                            prodPrice = prodPrice * discount;
                        }
                    }
                    #endregion
                    var    typeInfo     = TypeApplication.GetProductType(product.TypeId);
                    string colorAlias   = (typeInfo == null || string.IsNullOrEmpty(typeInfo.ColorAlias)) ? SpecificationType.Color.ToDescription() : typeInfo.ColorAlias;
                    string sizeAlias    = (typeInfo == null || string.IsNullOrEmpty(typeInfo.SizeAlias)) ? SpecificationType.Size.ToDescription() : typeInfo.SizeAlias;
                    string versionAlias = (typeInfo == null || string.IsNullOrEmpty(typeInfo.VersionAlias)) ? SpecificationType.Version.ToDescription() : typeInfo.VersionAlias;
                    if (product != null)
                    {
                        colorAlias   = !string.IsNullOrWhiteSpace(product.ColorAlias) ? product.ColorAlias : colorAlias;
                        sizeAlias    = !string.IsNullOrWhiteSpace(product.SizeAlias) ? product.SizeAlias : sizeAlias;
                        versionAlias = !string.IsNullOrWhiteSpace(product.VersionAlias) ? product.VersionAlias : versionAlias;
                    }
                    if (sku != null)
                    {
                        #region 正在参加限时抢购商品在购物车失效 TDO:ZYF
                        var isLimit = false;
                        //门店商品,在参加限时购,也可以正常购买
                        var limit = LimitTimeApplication.GetLimitTimeMarketItemByProductId(item.ProductId);
                        if (limit != null && !isBranch)
                        {
                            isLimit = limit.Status == Entities.FlashSaleInfo.FlashSaleStatus.Ongoing;
                        }
                        #endregion
                        var _tmp = new CartProductModel
                        {
                            cartItemId     = item.Id,
                            skuId          = item.SkuId,
                            id             = product.Id,
                            imgUrl         = Core.HimallIO.GetRomoteProductSizeImage(product.RelativePath, 1, (int)Himall.CommonModel.ImageSize.Size_150),
                            name           = product.ProductName,
                            price          = prodPrice.ToString("F2"),
                            count          = item.Quantity,
                            ShopId         = shop.Id.ToString(),
                            Size           = sku.Size,
                            Color          = sku.Color,
                            Version        = sku.Version,
                            VShopId        = vshop == null ? "0" : vshop.Id.ToString(),
                            ShopName       = shop.ShopName,
                            ShopLogo       = vshop == null ? "" : Core.HimallIO.GetRomoteImagePath(vshop.StrLogo),
                            Url            = Core.HimallIO.GetRomoteImagePath("/m-IOS/product/detail/") + item.ProductId,
                            ProductStatus  = isLimit ? 0 : (sku.Stock <= 0 ? ProductInfo.ProductSaleStatus.InStock.GetHashCode() : product.SaleStatus.GetHashCode()),
                            status         = isLimit ? 1 : ProductManagerApplication.GetProductShowStatus(product, sku, item.Quantity, shopbranch, shopbranchsku),// 0:正常;1:已失效;2:库存不足;3:已下架;
                            ColorAlias     = colorAlias,
                            SizeAlias      = sizeAlias,
                            VersionAlias   = versionAlias,
                            AddTime        = item.AddTime,
                            shopBranchId   = item.ShopBranchId,
                            shopBranchName = null == shopbranch ? "" : shopbranch.ShopBranchName,
                            ShopBranchLogo = null == shopbranch ? "" : Core.HimallIO.GetRomoteImagePath(shopbranch.ShopImages)
                        };
                        products.Add(_tmp);
                    }
                }
            }
            return(products);
        }
Beispiel #8
0
        /// <summary>
        /// 跳转到手机URL
        /// </summary>
        /// <param name="JumpUrl">为空表示自动处理</param>
        //TODO:DZY[150730] 统一跳转

        /* zjt
         * Url请改为小写 【参数命名规范】
         */
        protected void JumpMobileUrl(ActionExecutingContext filterContext, string url = "")
        {
            string curUrl  = Request.Path.ToString() + Request.QueryString.ToString();
            string jumpUrl = curUrl;
            var    route   = filterContext.RouteData;

            //无路由信息不跳转
            if (route == null)
            {
                return;
            }

            //路由处理
            string controller = route.Values["controller"].ToString().ToLower();
            string action     = route.Values["action"].ToString().ToLower();
            //string area = (route.DataTokens["area"] == null ? "" : route.DataTokens["area"].ToString().ToLower());


            object areaObj = null;
            string area    = "";

            if (filterContext.RouteData.Values.TryGetValue("area", out areaObj))
            {
                area = areaObj.ToString().ToLower();
            }



            if (area == "mobile" || area == "admin")
            {
                return;  //在移动端跳出
            }
            //Web区域跳转移动端
            if (area == "web")
            {
                IsAutoJumpMobile = true;
            }

            if (this.IsAutoJumpMobile && IsMobileTerminal)
            {
                if (Regex.Match(curUrl, @"\/m(\-.*)?").Length < 1)
                {
                    JumpUrlRoute jurdata = GetRouteUrl(controller, action, area, curUrl);
                    //非手机端跳转
                    switch (visitorTerminalInfo.Terminal)
                    {
                    case EnumVisitorTerminal.WeiXin:
                        if (jurdata != null)
                        {
                            jumpUrl = jurdata.WX;
                        }
                        jumpUrl = @"/m-WeiXin" + jumpUrl;
                        break;

                    case EnumVisitorTerminal.IOS:
                        if (jurdata != null)
                        {
                            jumpUrl = jurdata.WAP;
                        }
                        jumpUrl = @"/m-ios" + jumpUrl;
                        break;

                    default:
                        if (jurdata != null)
                        {
                            jumpUrl = jurdata.WAP;
                        }
                        jumpUrl = @"/m-wap" + jumpUrl;
                        break;
                    }

                    #region 参数特殊处理
                    if (jurdata.IsSpecial)
                    {
                        #region 店铺参数转换
                        if (jurdata.PC.ToLower() == @"/shop")
                        {
                            //商家首页参数处理
                            string strid   = route.Values["id"].ToString();
                            long   shopId  = 0;
                            long   vshopId = 0;
                            if (!long.TryParse(strid, out shopId))
                            {
                                shopId = 0;
                            }
                            if (shopId > 0)
                            {
                                var vshop = VshopApplication.GetVShopByShopId(shopId);
                                if (vshop != null)
                                {
                                    vshopId = vshop.Id;
                                }
                            }
                            jumpUrl = jumpUrl + "/" + vshopId.ToString();
                        }
                        #endregion

                        //TODO:LRL 订单页面参数转换

                        /* zjt
                         * TODO可移除,保留注释即可
                         */
                        #region  单页面参数转换
                        if (jurdata.PC.ToLower() == @"/order/submit")
                        {
                            //商家首页参数处理
                            var strcartid = string.Empty;
                            var arg       = route.Values["cartitemids"];
                            if (arg == null)
                            {
                                strcartid = Request.Query["cartitemids"].ToString();
                            }
                            else
                            {
                                strcartid = arg.ToString();
                            }
                            jumpUrl = jumpUrl + "/?cartItemIds=" + strcartid;
                        }
                        #endregion
                    }
                    #endregion

                    if (!string.IsNullOrWhiteSpace(url))
                    {
                        jumpUrl = url;
                    }
                    //string testurl = jumpUrl;
                    //testurl = Request.Url.Scheme + "://" + Request.Url.Authority + testurl;
                    ////页面不存在
                    //if (!IsExistPage(testurl))
                    //{
                    //    if (visitorTerminalInfo.Terminal == EnumVisitorTerminal.WeiXin)
                    //    {
                    //        jumpUrl = @"/m-WeiXin/";
                    //    }
                    //    else
                    //    {
                    //        jumpUrl = @"/m-wap/";
                    //    }

                    //}

                    filterContext.Result = Redirect(jumpUrl);
                }
            }
        }
Beispiel #9
0
        public object GetCart(long shopBranchId)
        {
            //CheckUserLogin();
            long userId = 0;
            //会员折扣
            decimal discount = 1.0M;//默认折扣为1(没有折扣)

            if (CurrentUser != null)
            {
                userId   = CurrentUser.Id;
                discount = CurrentUser.MemberDiscount;
            }
            var cart       = GetCart(userId, shopBranchId);
            var shopBranch = ShopBranchApplication.GetShopBranchById(shopBranchId);

            if (shopBranch == null)
            {
                throw new MallException("门店库存不足");
            }
            var     stores    = cart.Items.Where(d => d.ShopBranchId > 0).OrderByDescending(d => d.AddTime).Select(d => d.ShopBranchId).GroupBy(d => d);
            decimal prodPrice = 0.0M;//优惠价格
            //var rets = new List<CartStoreModel>();
            var _store = new CartStoreModel();

            _store.ShopBranchId   = shopBranch.Id;
            _store.ShopId         = shopBranch.ShopId;
            _store.ShopBranchName = shopBranch.ShopBranchName;
            _store.Status         = shopBranch.Status.GetHashCode();
            _store.DeliveFee      = shopBranch.DeliveFee;
            _store.DeliveTotalFee = shopBranch.DeliveTotalFee;
            _store.FreeMailFee    = shopBranch.FreeMailFee;
            var product = cart.Items.Where(d => d.ShopBranchId == shopBranch.Id).OrderBy(s => s.Status).ThenByDescending(o => o.AddTime).ToList();

            _store.Products = new List <CartStoreProduct>();
            foreach (var pitem in product)
            {
                var pro           = ProductManagerApplication.GetProduct(pitem.ProductId);
                var shopbranchsku = ShopBranchApplication.GetSkusByIds(_store.ShopBranchId, new List <string> {
                    pitem.SkuId
                }).FirstOrDefault();
                var     shop       = ShopApplication.GetShop(pro.ShopId);
                var     vshop      = VshopApplication.GetVShopByShopId(pro.ShopId);
                DTO.SKU sku        = ProductManagerApplication.GetSKU(pitem.SkuId);
                string  skuDetails = "";
                if (null != shop && sku != null)
                {
                    prodPrice = sku.SalePrice;
                    if (shop.IsSelf)
                    {
                        //官方自营店才计算会员折扣
                        prodPrice = sku.SalePrice * discount;
                    }
                    prodPrice = decimal.Round(prodPrice, 2, MidpointRounding.AwayFromZero);

                    var typeInfo = TypeApplication.GetProductType(pro.TypeId);
                    skuDetails = "";
                    if (!string.IsNullOrWhiteSpace(sku.Size))
                    {
                        if (!string.IsNullOrWhiteSpace(skuDetails))
                        {
                            skuDetails += "、";
                        }
                        skuDetails += sku.Size;
                    }
                    if (!string.IsNullOrWhiteSpace(sku.Color))
                    {
                        if (!string.IsNullOrWhiteSpace(skuDetails))
                        {
                            skuDetails += "、";
                        }
                        skuDetails += sku.Color;
                    }
                    if (!string.IsNullOrWhiteSpace(sku.Version))
                    {
                        if (!string.IsNullOrWhiteSpace(skuDetails))
                        {
                            skuDetails += "、";
                        }
                        skuDetails += sku.Version;
                    }
                    string colorAlias   = (typeInfo == null || string.IsNullOrEmpty(typeInfo.ColorAlias)) ? SpecificationType.Color.ToDescription() : typeInfo.ColorAlias;
                    string sizeAlias    = (typeInfo == null || string.IsNullOrEmpty(typeInfo.SizeAlias)) ? SpecificationType.Size.ToDescription() : typeInfo.SizeAlias;
                    string versionAlias = (typeInfo == null || string.IsNullOrEmpty(typeInfo.VersionAlias)) ? SpecificationType.Version.ToDescription() : typeInfo.VersionAlias;
                    if (pro != null)
                    {
                        colorAlias   = !string.IsNullOrWhiteSpace(pro.ColorAlias) ? pro.ColorAlias : colorAlias;
                        sizeAlias    = !string.IsNullOrWhiteSpace(pro.SizeAlias) ? pro.SizeAlias : sizeAlias;
                        versionAlias = !string.IsNullOrWhiteSpace(pro.VersionAlias) ? pro.VersionAlias : versionAlias;
                    }
                    var _product = new CartStoreProduct
                    {
                        ShopBranchId = shopBranchId,
                        CartItemId   = pitem.Id,
                        SkuId        = pitem.SkuId,
                        Id           = pro.Id,
                        ProductName  = pro.ProductName,
                        Price        = prodPrice,
                        Count        = pitem.Quantity,
                        Stock        = shopbranchsku == null ? 0 : shopbranchsku.Stock,
                        //阶梯价商品在门店购物车自动下架
                        Status       = ProductManagerApplication.GetProductShowStatus(pro, sku, 1, shopBranch, shopbranchsku),//0:正常;1:冻结;2:库存不足
                        SkuDetails   = skuDetails,
                        ColorAlias   = colorAlias,
                        SizeAlias    = sizeAlias,
                        VersionAlias = versionAlias,
                        Size         = sku.Size,
                        Color        = sku.Color,
                        Version      = sku.Version,
                        AddTime      = pitem.AddTime,
                        DefaultImage = MallIO.GetRomoteProductSizeImage(pro.ImagePath, 1, 500)
                    };
                    _store.Products.Add(_product);
                }
            }
            _store.Amount     = (_store.Products != null && _store.Products.Count > 0) ? _store.Products.Where(x => x.Status == 0).Sum(s => s.Price * s.Count) : 0;
            _store.TotalCount = (_store.Products != null && _store.Products.Count > 0) ? _store.Products.Where(x => x.Status == 0).Sum(s => s.Count) : 0;
            if (_store.Products.Count > 0)
            {//有商品数据,才返回门店信息
                _store.Products = _store.Products.OrderBy(p => p.Status).ThenByDescending(p => p.AddTime).ToList();
                //rets.Add(_store);
            }
            return(Json(_store));
        }