/// <summary>
        /// 用户收藏的商品
        /// </summary>
        /// <param name="pageNo"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public object GetUserCollectionProduct(int pageNo = 1, int pageSize = 16)
        {
            CheckUserLogin();
            if (CurrentUser != null)
            {
                var model = ServiceProvider.Instance <IProductService> .Create.GetUserConcernProducts(CurrentUser.Id, pageNo, pageSize);

                var result = model.Models.ToArray().Select(item =>
                {
                    var pro = ProductManagerApplication.GetProduct(item.ProductId);
                    return(new
                    {
                        Id = item.ProductId,
                        Image = HimallIO.GetRomoteProductSizeImage(pro.RelativePath, 1, (int)Himall.CommonModel.ImageSize.Size_220),
                        ProductName = pro.ProductName,
                        SalePrice = pro.MinSalePrice.ToString("F2"),
                        Evaluation = CommentApplication.GetCommentCountByProduct(pro.Id),
                        Status = ProductManagerApplication.GetProductShowStatus(pro)
                    });
                });
                return(new { success = true, data = result, total = model.Total });
            }
            else
            {
                return(new Result {
                    success = false, msg = "未登录"
                });
            }
        }
Example #2
0
        public void AddRemind(long flashSaleId, string openId)
        {
#if DEBUG
            Log.Info("限时购 - 添加订阅用户");
#endif
            if (DbFactory.Default.Get <FlashSaleRemindInfo>().Where(p => p.FlashSaleId == flashSaleId && p.OpenId == openId).Exist())
            {
                return;
            }

            FlashSaleRemindInfo model = new FlashSaleRemindInfo();
            model.FlashSaleId = flashSaleId;
            model.OpenId      = openId;
            model.RecordDate  = DateTime.Now;
            DbFactory.Default.Add(model);

            var    flashSale = DbFactory.Default.Get <FlashSaleInfo>().Where(p => p.Id == flashSaleId).FirstOrDefault();
            var    product   = ProductManagerApplication.GetProduct(flashSale.ProductId);
            string openid    = openId;
            var    msgdata   = new WX_MsgTemplateSendDataModel();
            msgdata.first.value    = "亲爱的用户,您已经成功设置限时购订阅提醒!";
            msgdata.first.color    = "#000000";
            msgdata.keyword1.value = product.ProductName;
            msgdata.keyword1.color = "#FF0000";
            msgdata.keyword2.value = flashSale.MinPrice.ToString();
            msgdata.keyword2.color = "#FF0000";
            msgdata.keyword3.value = model.RecordDate.ToString("yyyy-MM-dd HH:mm");
            msgdata.keyword3.color = "#000000";
            msgdata.remark.value   = "活动开始时将自动提醒您,请关注您的微信消息。";
            msgdata.remark.color   = "#000000";
            //处理url
            var _iwxtser = Mall.ServiceProvider.Instance <IWXMsgTemplateService> .Create;
            //string url = _iwxtser.GetMessageTemplateShowUrl(MessageTypeEnum.SubscribeLimitTimeBuy);
            //Task.Factory.StartNew(() => ServiceProvider.Instance<IWXMsgTemplateService>.Create.SendMessageByTemplate(MessageTypeEnum.SubscribeLimitTimeBuy, 0, msgdata, url, openid));
        }
Example #3
0
        public JsonResult UpdateCartItem(string skuId, int count)
        {
            long userId       = CurrentUser != null ? CurrentUser.Id : 0;
            var  orderService = _iOrderService;
            var  skuinfo      = orderService.GetSkuByID(skuId);
            var  product      = ProductManagerApplication.GetProduct(skuinfo.ProductId);

            if (product != null)
            {
                if (product.MaxBuyCount > 0 && count > product.MaxBuyCount && !product.IsOpenLadder)
                {
                    return(Json(new { success = false, msg = string.Format("每个ID限购{0}件", product.MaxBuyCount), stock = product.MaxBuyCount }));
                }
            }

            if (skuinfo.Stock < count)
            {
                return(Json(new { success = false, msg = "库存不足", stock = skuinfo.Stock }));
            }

            cartHelper.UpdateCartItem(skuId, count, userId);

            #region 购物车修改数量阶梯价变动--张宇枫
            //获取产品详情
            var price = 0m;
            if (product.IsOpenLadder)
            {
                var shop = ShopApplication.GetShop(product.ShopId);

                var groupCartByProduct = cartHelper.GetCart(userId).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();
                var quantity = groupCartByProduct.Where(i => i.Key == product.Id).ToList().Sum(cartitem => cartitem.Sum(i => i.Quantity));

                decimal discount = 1M;
                if (CurrentUser != null)
                {
                    discount = CurrentUser.MemberDiscount;
                }
                price = ProductManagerApplication.GetProductLadderPrice(product.Id, quantity);
                if (shop.IsSelf)
                {
                    price = price * discount;
                }
            }

            #endregion

            return(Json(new { success = true, saleprice = price.ToString("F2"), productid = product.Id, isOpenLadder = product.IsOpenLadder }));
        }
Example #4
0
        public FlashSaleModel GetFlaseSaleByProductId(long pid)
        {
            if (pid <= 0)
            {
                throw new MallException("商品Id不能识别");
            }

            var model = DbFactory.Default
                        .Get <FlashSaleInfo>()
                        .Where(m => m.ProductId == pid && m.Status == FlashSaleInfo.FlashSaleStatus.Ongoing &&
                               m.BeginDate <= DateTime.Now && m.EndDate > DateTime.Now)
                        .FirstOrDefault();
            FlashSaleModel result = new FlashSaleModel();

            if (model != null)
            {
                var product = ProductManagerApplication.GetProduct(model.ProductId);
                result.Id                    = model.Id;
                result.Title                 = model.Title;
                result.ShopId                = model.ShopId;
                result.ProductId             = model.ProductId;
                result.Status                = model.Status;
                result.ProductName           = product.ProductName;
                result.ProductImg            = product.RelativePath;
                result.StatusStr             = model.Status.ToDescription();
                result.BeginDate             = model.BeginDate.ToString("yyyy-MM-dd HH:mm");
                result.EndDate               = model.EndDate.ToString("yyyy-MM-dd HH:mm");
                result.LimitCountOfThePeople = model.LimitCountOfThePeople;
                result.SaleCount             = model.SaleCount;
                result.CategoryName          = model.CategoryName;
                result.MinPrice              = model.MinPrice;
                result.Details               = new List <FlashSaleDetailModel>();
                return(result);
            }
            else
            {
                return(null);
            }
        }
        /// <summary>
        /// 修正商品sku
        /// <para>0库存添加新的sku</para>
        /// </summary>
        /// <param name="productId"></param>
        public static void CorrectBranchProductSkus(long productId, long shopId)
        {
            var productsInfo = ProductManagerApplication.GetProduct(productId);

            if (productsInfo == null || productsInfo.ShopId != shopId)
            {
                throw new MallException("未找到商品数据");
            }
            var         shopbrids = Service.GetAgentShopBranchIds(productId);
            List <long> pids      = new List <long>();

            pids.Add(productId);

            foreach (var shopBranchId in shopbrids)
            {
                //查询已添加的SKU,用于添加时过滤
                var oldskus = Service.GetSkus(shopId, new List <long> {
                    shopBranchId
                }, null).Select(e => e.SkuId);
                var allSkus        = ProductManagerApplication.GetSKUByProducts(pids);
                var shopBranchSkus = new List <Entities.ShopBranchSkuInfo> {
                };

                var skus = allSkus.Where(s => !oldskus.Any(sku => sku == s.Id)).Select(e => new Entities.ShopBranchSkuInfo
                {
                    ProductId    = e.ProductId,
                    SkuId        = e.Id,
                    ShopId       = shopId,
                    ShopBranchId = shopBranchId,
                    Stock        = 0,
                    CreateDate   = DateTime.Now
                });
                shopBranchSkus.AddRange(skus);

                Service.AddSkus(shopBranchSkus);
            }
        }
Example #6
0
        public FlashSaleModel IsFlashSaleDoesNotStarted(long productid)
        {
            string cacheKey = CacheKeyCollection.CACHE_PRODUCTLIMITNOTSTART(productid);

            if (Cache.Exists(cacheKey))
            {
                return(Cache.Get <FlashSaleModel>(cacheKey));
            }

            var model = DbFactory.Default.Get <FlashSaleInfo>().Where(p => p.ProductId == productid &&
                                                                      p.Status == FlashSaleInfo.FlashSaleStatus.Ongoing &&
                                                                      p.BeginDate > DateTime.Now).FirstOrDefault();

            if (model != null)
            {
                var            product = ProductManagerApplication.GetProduct(model.ProductId);
                FlashSaleModel result  = new FlashSaleModel();
                result.Id                    = model.Id;
                result.Title                 = model.Title;
                result.ShopId                = model.ShopId;
                result.ProductId             = model.ProductId;
                result.Status                = model.Status;
                result.ProductName           = product.ProductName;
                result.ProductImg            = product.ImagePath;
                result.StatusStr             = model.Status.ToDescription();
                result.BeginDate             = model.BeginDate.ToString("yyyy-MM-dd HH:mm");
                result.EndDate               = model.EndDate.ToString("yyyy-MM-dd HH:mm");
                result.LimitCountOfThePeople = model.LimitCountOfThePeople;
                result.SaleCount             = model.SaleCount;
                result.CategoryName          = model.CategoryName;
                result.MinPrice              = model.MinPrice;
                Cache.Insert <FlashSaleModel>(cacheKey, result, model.BeginDate.AddSeconds(-10));//缓存至开始时间前10秒
                return(result);
            }
            Cache.Insert <FlashSaleModel>(cacheKey, null, 60);
            return(null);
        }
Example #7
0
        public JsonResult List(int page, int rows, string productName, bool?isReply = null, int Rank = -1, bool hasAppend = false)
        {
            if (!string.IsNullOrEmpty(productName))
            {
                productName = productName.Trim();
            }
            var orderItemService = _iOrderService;
            var iTypeService     = _iTypeService;
            var query            = new CommentQuery()
            {
                PageNo = page, PageSize = rows, HasAppend = hasAppend, ProductName = productName, Rank = Rank, ShopID = base.CurrentSellerManager.ShopId, IsReply = isReply
            };
            var result       = _iCommentService.GetComments(query);
            var orderItemIds = result.Models.Select(a => a.SubOrderId).ToList();

            var orderItems = orderItemService.GetOrderItemsByOrderItemId(orderItemIds).ToDictionary(item => item.Id, item => item);
            var comments   = result.Models.Select(item =>
            {
                var product = ProductManagerApplication.GetProduct(item.ProductId);
                return(new ProductCommentModel()
                {
                    CommentContent = item.ReviewContent,
                    CommentDate = item.ReviewDate,
                    ReplyContent = item.ReplyContent,
                    AppendContent = item.AppendContent,
                    AppendDate = item.AppendDate,
                    ReplyAppendDate = item.ReplyAppendDate,
                    CommentMark = item.ReviewMark,
                    ReplyDate = item.ReplyDate,
                    Id = item.Id,
                    ProductName = (product == null) ? "" : product.ProductName,
                    ProductId = item.ProductId,
                    ImagePath = orderItems[item.SubOrderId].ThumbnailsUrl,
                    UserName = item.UserName,
                    OderItemId = item.SubOrderId,
                    Color = "",
                    Version = "",
                    Size = "",
                    UserId = item.UserId
                });
            }).ToList();

            //TODO LRL 2015/08/06 从评价信息添加商品的规格信息
            foreach (var item in comments)
            {
                item.ImagePath = Core.MallIO.GetProductSizeImage(item.ImagePath, 1, (int)ImageSize.Size_100);
                if (item.OderItemId.HasValue)
                {
                    var obj = orderItemService.GetOrderItem(item.OderItemId.Value);
                    if (obj != null)
                    {
                        item.Color   = obj.Color;
                        item.Size    = obj.Size;
                        item.Version = obj.Version;
                        item.OrderId = obj.OrderId;

                        var member = MemberApplication.GetMember(item.UserId);
                        if (member != null)
                        {
                            item.UserName  = member.UserName;
                            item.UserPhone = member.CellPhone;
                        }
                    }
                }
                Entities.TypeInfo typeInfo = iTypeService.GetTypeByProductId(item.ProductId);
                item.ColorAlias   = (typeInfo == null || string.IsNullOrEmpty(typeInfo.ColorAlias)) ? SpecificationType.Color.ToDescription() : typeInfo.ColorAlias;
                item.SizeAlias    = (typeInfo == null || string.IsNullOrEmpty(typeInfo.SizeAlias)) ? SpecificationType.Size.ToDescription() : typeInfo.SizeAlias;
                item.VersionAlias = (typeInfo == null || string.IsNullOrEmpty(typeInfo.VersionAlias)) ? SpecificationType.Version.ToDescription() : typeInfo.VersionAlias;
                var productInfo = ProductManagerApplication.GetProduct(item.ProductId);
                if (productInfo != null)
                {
                    item.ColorAlias   = !string.IsNullOrWhiteSpace(productInfo.ColorAlias) ? productInfo.ColorAlias : item.ColorAlias;
                    item.SizeAlias    = !string.IsNullOrWhiteSpace(productInfo.SizeAlias) ? productInfo.SizeAlias : item.SizeAlias;
                    item.VersionAlias = !string.IsNullOrWhiteSpace(productInfo.VersionAlias) ? productInfo.VersionAlias : item.VersionAlias;
                }
            }
            DataGridModel <ProductCommentModel> model = new DataGridModel <ProductCommentModel>()
            {
                rows = comments, total = result.Total
            };

            return(Json(model));
        }
Example #8
0
        public void AddToCart(string skuId, int count, long memberId)
        {
            CheckSkuIdIsValid(skuId);
            //判断库存
            var sku = ProductManagerApplication.GetSKU(skuId);

            if (sku == null)
            {
                throw new HimallException("错误的SKU");
            }
            if (count > sku.Stock)
            {
                throw new HimallException("库存不足");
            }
            #region 商品限购判断
            var prouctInfo = ProductManagerApplication.GetProduct(sku.ProductId);
            if (prouctInfo != null && prouctInfo.MaxBuyCount > 0 && !prouctInfo.IsOpenLadder)//商品有限购数量
            {
                var carInfo = CartApplication.GetCart(memberId);
                if (carInfo != null)
                {
                    var quantity = carInfo.Items.Where(p => p.ProductId == sku.ProductId).Sum(d => d.Quantity); //当前用户该商品已加入购物车数量
                    if (count + quantity > prouctInfo.MaxBuyCount)                                              //已有数量+新数量
                    {
                        throw new HimallException(string.Format("每个ID限购{0}件", prouctInfo.MaxBuyCount));
                    }
                }
            }
            #endregion

            if (memberId > 0)
            {
                CartApplication.AddToCart(skuId, count, memberId);
            }
            else
            {
                string cartInfo = WebHelper.GetCookie(CookieKeysCollection.HIMALL_CART);
                if (!string.IsNullOrWhiteSpace(cartInfo))
                {
                    string[] cartItems   = cartInfo.Split(',');
                    string   newCartInfo = string.Empty;
                    bool     exist       = false;
                    foreach (string cartItem in cartItems)
                    {
                        var cartItemParts = cartItem.Split(':');
                        if (cartItemParts[0] == skuId)
                        {
                            newCartInfo += "," + skuId + ":" + (int.Parse(cartItemParts[1]) + count);
                            exist        = true;
                        }
                        else
                        {
                            newCartInfo += "," + cartItem;
                        }
                    }
                    if (!exist)
                    {
                        newCartInfo += "," + skuId + ":" + count;
                    }

                    if (!string.IsNullOrWhiteSpace(newCartInfo))
                    {
                        newCartInfo = newCartInfo.Substring(1);
                    }
                    WebHelper.SetCookie(CookieKeysCollection.HIMALL_CART, newCartInfo);
                }
                else
                {
                    WebHelper.SetCookie(CookieKeysCollection.HIMALL_CART, string.Format("{0}:{1}", skuId, count));
                }
            }
        }
Example #9
0
        public object PostUpdateCartItem(CartUpdateCartItemModel value)
        {
            var productService = ServiceProvider.Instance <IProductService> .Create;

            CheckUserLogin();
            string Jsonstr      = value.jsonstr;
            var    datavalue    = Newtonsoft.Json.JsonConvert.DeserializeObject <UpdateCartSKusModel>(Jsonstr);
            var    cartService  = ServiceProvider.Instance <ICartService> .Create;
            var    ladderPrice  = 0m;
            long   productId    = 0;
            var    isOpenLadder = false;

            foreach (var sku in datavalue.skus)
            {
                Entities.SKUInfo skuinfo = OrderApplication.GetSkuByID(sku.skuId);
                if (skuinfo != null)
                {
                    var productInfo = ProductManagerApplication.GetProduct(skuinfo.ProductId);
                    if (productInfo != null)
                    {
                        if (productInfo.MaxBuyCount > 0 && sku.count > productInfo.MaxBuyCount && !productInfo.IsOpenLadder)
                        {
                            return(ErrorResult(string.Format("商品[{0}]限购{1}件", productInfo.ProductName, productInfo.MaxBuyCount), data: new { maxBuyCount = productInfo.MaxBuyCount }));
                            //throw new MallException(string.Format("每个ID限购{0}件", productInfo.MaxBuyCount));
                        }
                    }
                }
                cartService.UpdateCart(sku.skuId, sku.count, CurrentUser.Id);
                #region 阶梯价--张宇枫
                var skus    = CartApplication.GetCart(CurrentUser.Id);
                var skuItem = skus.Items.ToList().Find(i => i.SkuId == sku.skuId);
                productId = skuItem.ProductId;
                var product = ProductManagerApplication.GetProduct(productId);
                isOpenLadder = product.IsOpenLadder;
                if (isOpenLadder)
                {
                    var shop = ShopApplication.GetShop(product.ShopId);
                    var groupCartByProduct = skus.Items.Where(item => item.ShopBranchId == 0).Select(c =>
                    {
                        var cItem   = new Mall.Entities.ShoppingCartItem();
                        var skuInfo = productService.GetSku(c.SkuId);
                        if (skuInfo != null)
                        {
                            cItem = c;
                        }
                        return(cItem);
                    }).GroupBy(i => i.ProductId).ToList();
                    var quantity =
                        groupCartByProduct.Where(i => i.Key == productId)
                        .ToList()
                        .Sum(cartitem => cartitem.Sum(i => i.Quantity));
                    ladderPrice = ProductManagerApplication.GetProductLadderPrice(skuItem.ProductId, quantity);
                    if (shop.IsSelf)
                    {
                        ladderPrice = CurrentUser.MemberDiscount * ladderPrice;
                    }
                }
                #endregion
            }
            var result = new
            {
                success = true,
                //d.Url = "http://" + Url.Request.RequestUri.Host + "/m-IOS/Order/SubmiteByCart";
                Url          = Core.MallIO.GetRomoteImagePath("/m-IOS/Order/SubmiteByCart"),
                Price        = ladderPrice.ToString("F2"),
                ProductId    = productId,
                IsOpenLadder = isOpenLadder ? 1 : 0,
            };
            return(result);
        }
Example #10
0
        private List <CartProductModel> PackageCartProducts(Mall.Entities.ShoppingCartInfo cart, decimal prodPrice, decimal discount, IProductService productService, IShopService shopService, IShopBranchService shopBranchService, IVShopService vshopService, ITypeService typeservice, 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 Mall.Entities.ShoppingCartItem();
                var skuInfo = productService.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          = shopService.GetShop(product.ShopId);
                DTO.ShopBranch             shopbranch    = null;
                Entities.ShopBranchSkuInfo shopbranchsku = null;
                if (item.ShopBranchId > 0)
                {
                    shopbranch    = ShopBranchApplication.GetShopBranchById(item.ShopBranchId);
                    shopbranchsku = shopBranchService.GetSkusByIds(item.ShopBranchId, new List <string> {
                        item.SkuId
                    }).FirstOrDefault();
                }

                if (null != shop)
                {
                    var vshop = vshopService.GetVShopByShopId(shop.Id);
                    var sku   = ProductManagerApplication.GetSKU(item.SkuId);
                    if (sku == null)
                    {
                        continue;
                    }
                    //处理限时购、会员折扣价格
                    var prod = limitProducts.FirstOrDefault(e => e.ProductId == item.ProductId);
                    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
                    Entities.TypeInfo typeInfo     = typeservice.GetType(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.ToString(),
                            SkuId          = item.SkuId,
                            Id             = product.Id.ToString(),
                            ImgUrl         = Core.MallIO.GetRomoteProductSizeImage(product.RelativePath, 1, (int)Mall.CommonModel.ImageSize.Size_150),
                            Name           = product.ProductName,
                            Price          = prodPrice.ToString("F2"),
                            Count          = item.Quantity.ToString(),
                            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.MallIO.GetRomoteImagePath(vshop.StrLogo),
                            Url            = Core.MallIO.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, shopbranch == null ? 1 : 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.MallIO.GetRomoteImagePath(shopbranch.ShopImages)
                        };
                        products.Add(_tmp);
                    }
                }
            }
            return(products);
        }
        /// <summary>
        /// 拼团活动商品详情
        /// </summary>
        /// <param name="id">拼团活动ID</param>
        /// /// <param name="grouId">团活动ID</param>
        /// <returns></returns>
        public JsonResult <Result <dynamic> > GetActiveDetail(long id, long grouId = 0, bool isFirst = true, string ids = "")
        {
            var userList = new List <FightGroupOrderInfo>();
            var data     = FightGroupApplication.GetActive(id, true, true);
            FightGroupActiveModel result = data;

            //先初始化拼团商品主图
            result.InitProductImages();
            var imgpath = data.ProductImgPath;

            if (result != null)
            {
                result.IsEnd = true;
                if (data.EndTime.Date >= DateTime.Now.Date)
                {
                    result.IsEnd = false;
                }
                //商品图片地址修正
                result.ProductDefaultImage = HimallIO.GetRomoteProductSizeImage(imgpath, 1, (int)ImageSize.Size_350);
                result.ProductImgPath      = HimallIO.GetRomoteProductSizeImage(imgpath, 1);
            }
            if (result.ProductImages != null)
            {//将主图相对路径处理为绝对路径
                result.ProductImages = result.ProductImages.Select(e => HimallIO.GetRomoteImagePath(e)).ToList();
            }

            if (!string.IsNullOrWhiteSpace(result.IconUrl))
            {
                result.IconUrl = Himall.Core.HimallIO.GetRomoteImagePath(result.IconUrl);
            }
            bool IsUserEnter = false;
            long currentUser = 0;

            if (CurrentUser != null)
            {
                currentUser = CurrentUser.Id;
            }
            if (grouId > 0)//获取已参团的用户
            {
                userList = ServiceProvider.Instance <IFightGroupService> .Create.GetActiveUsers(id, grouId);

                foreach (var item in userList)
                {
                    item.Photo        = !string.IsNullOrWhiteSpace(item.Photo) ? Core.HimallIO.GetRomoteImagePath(item.Photo) : "";
                    item.HeadUserIcon = !string.IsNullOrWhiteSpace(item.HeadUserIcon) ? Core.HimallIO.GetRomoteImagePath(item.HeadUserIcon) : "";
                    if (currentUser.Equals(item.OrderUserId))
                    {
                        IsUserEnter = true;
                    }
                }
            }
            #region 商品规格
            var product = ProductManagerApplication.GetProduct((long)result.ProductId);

            ProductShowSkuInfoModel model = new ProductShowSkuInfoModel();
            model.MinSalePrice     = data.MiniSalePrice;
            model.ProductImagePath = string.IsNullOrWhiteSpace(imgpath) ? "" : HimallIO.GetRomoteProductSizeImage(imgpath, 1, (int)Himall.CommonModel.ImageSize.Size_350);

            List <SKUDataModel> skudata = data.ActiveItems.Where(d => d.ActiveStock > 0).Select(d => new SKUDataModel
            {
                SkuId     = d.SkuId,
                Color     = d.Color,
                Size      = d.Size,
                Version   = d.Version,
                Stock     = (int)d.ActiveStock,
                CostPrice = d.ProductCostPrice,
                SalePrice = d.ProductPrice,
                Price     = d.ActivePrice,
            }).ToList();

            Entities.TypeInfo typeInfo = ServiceProvider.Instance <ITypeService> .Create.GetType(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;
            }
            model.ColorAlias   = colorAlias;
            model.SizeAlias    = sizeAlias;
            model.VersionAlias = versionAlias;

            if (result.ActiveItems != null && result.ActiveItems.Count() > 0)
            {
                long colorId = 0, sizeId = 0, versionId = 0;
                var  skus = ProductManagerApplication.GetSKUs((long)result.ProductId);
                foreach (var sku in result.ActiveItems)
                {
                    var specs = sku.SkuId.Split('_');
                    if (specs.Count() > 0 && !string.IsNullOrEmpty(sku.Color))
                    {
                        if (long.TryParse(specs[1], out colorId))
                        {
                        }
                        if (colorId != 0)
                        {
                            if (!model.Color.Any(v => v.Value.Equals(sku.Color)))
                            {
                                var c = result.ActiveItems.Where(s => s.Color.Equals(sku.Color)).Sum(s => s.ActiveStock);
                                model.Color.Add(new ProductSKU
                                {
                                    //Name = "选择颜色",
                                    Name         = "选择" + colorAlias,
                                    EnabledClass = c != 0 ? " " : "disabled",
                                    //SelectedClass = !model.Color.Any(c1 => c1.SelectedClass.Equals("selected")) && c != 0 ? "selected" : "",
                                    SelectedClass = "",
                                    SkuId         = colorId,
                                    Value         = sku.Color,
                                    Img           = string.IsNullOrWhiteSpace(sku.ShowPic) ? "" : Core.HimallIO.GetRomoteImagePath(sku.ShowPic)
                                });
                            }
                        }
                    }
                    if (specs.Count() > 1 && !string.IsNullOrEmpty(sku.Size))
                    {
                        if (long.TryParse(specs[2], out sizeId))
                        {
                        }
                        if (sizeId != 0)
                        {
                            if (!model.Size.Any(v => v.Value.Equals(sku.Size)))
                            {
                                var ss = result.ActiveItems.Where(s => s.Size.Equals(sku.Size)).Sum(s1 => s1.ActiveStock);
                                model.Size.Add(new ProductSKU
                                {
                                    //Name = "选择尺码",
                                    Name          = "选择" + sizeAlias,
                                    EnabledClass  = ss != 0 ? "enabled" : "disabled",
                                    SelectedClass = "",
                                    SkuId         = sizeId,
                                    Value         = sku.Size
                                });
                            }
                        }
                    }

                    if (specs.Count() > 2 && !string.IsNullOrEmpty(sku.Version))
                    {
                        if (long.TryParse(specs[3], out versionId))
                        {
                        }
                        if (versionId != 0)
                        {
                            if (!model.Version.Any(v => v.Value.Equals(sku.Version)))
                            {
                                var v = result.ActiveItems.Where(s => s.Version.Equals(sku.Version)).Sum(s => s.ActiveStock);
                                model.Version.Add(new ProductSKU
                                {
                                    //Name = "选择规格",
                                    Name          = "选择" + versionAlias,
                                    EnabledClass  = v != 0 ? "enabled" : "disabled",
                                    SelectedClass = "",
                                    SkuId         = versionId,
                                    Value         = sku.Version
                                });
                            }
                        }
                    }
                }
            }
            #endregion

            var cashDepositModel = CashDepositsApplication.GetCashDepositsObligation((long)result.ProductId);//提供服务(消费者保障、七天无理由、及时发货)

            var GroupsData = new List <FightGroupsListModel>();
            List <FightGroupBuildStatus> stlist = new List <FightGroupBuildStatus>();
            stlist.Add(FightGroupBuildStatus.Ongoing);
            GroupsData = FightGroupApplication.GetGroups(id, stlist, null, null, 1, 10).Models.ToList();
            foreach (var item in GroupsData)
            {
                TimeSpan mid = item.AddGroupTime.AddHours((double)item.LimitedHour) - DateTime.Now;
                item.Seconds         = (int)mid.TotalSeconds;
                item.EndHourOrMinute = item.ShowHourOrMinute(item.GetEndHour);
                item.HeadUserIcon    = !string.IsNullOrWhiteSpace(item.HeadUserIcon) ? Core.HimallIO.GetRomoteImagePath(item.HeadUserIcon) : "";
            }

            #region 商品评论
            ProductCommentShowModel modelSay = new ProductCommentShowModel();
            modelSay.ProductId = (long)result.ProductId;
            var productSay = ProductManagerApplication.GetProduct((long)result.ProductId);
            modelSay.CommentList       = new List <ProductDetailCommentModel>();
            modelSay.IsShowColumnTitle = true;
            modelSay.IsShowCommentList = true;

            if (productSay == null)
            {
                //跳转到404页面
                throw new Core.HimallException("商品不存在");
            }
            var comments = CommentApplication.GetCommentsByProduct(product.Id);
            modelSay.CommentCount = comments.Count;
            if (comments.Count > 0)
            {
                var comment   = comments.OrderByDescending(a => a.ReviewDate).FirstOrDefault();
                var orderItem = OrderApplication.GetOrderItem(comment.SubOrderId);
                var order     = OrderApplication.GetOrder(orderItem.OrderId);
                modelSay.CommentList = comments.OrderByDescending(a => a.ReviewDate)
                                       .Take(1)
                                       .Select(c => {
                    var images = CommentApplication.GetProductCommentImagesByCommentIds(new List <long> {
                        c.Id
                    });
                    return(new ProductDetailCommentModel
                    {
                        Sku = ServiceProvider.Instance <IProductService> .Create.GetSkuString(orderItem.SkuId),
                        UserName = c.UserName,
                        ReviewContent = c.ReviewContent,
                        AppendContent = c.AppendContent,
                        AppendDate = c.AppendDate,
                        ReplyAppendContent = c.ReplyAppendContent,
                        ReplyAppendDate = c.ReplyAppendDate,
                        FinshDate = order.FinishDate,
                        Images = images.Where(a => a.CommentType == 0).Select(a => a.CommentImage).ToList(),
                        AppendImages = images.Where(a => a.CommentType == 1).Select(a => a.CommentImage).ToList(),
                        ReviewDate = c.ReviewDate,
                        ReplyContent = string.IsNullOrWhiteSpace(c.ReplyContent) ? "暂无回复" : c.ReplyContent,
                        ReplyDate = c.ReplyDate,
                        ReviewMark = c.ReviewMark,
                        BuyDate = order.OrderDate
                    });
                }).ToList();
                foreach (var citem in modelSay.CommentList)
                {
                    if (citem.Images.Count > 0)
                    {
                        for (var _imgn = 0; _imgn < citem.Images.Count; _imgn++)
                        {
                            citem.Images[_imgn] = Himall.Core.HimallIO.GetRomoteImagePath(citem.Images[_imgn]);
                        }
                    }
                    if (citem.AppendImages.Count > 0)
                    {
                        for (var _imgn = 0; _imgn < citem.AppendImages.Count; _imgn++)
                        {
                            citem.AppendImages[_imgn] = Himall.Core.HimallIO.GetRomoteImagePath(citem.AppendImages[_imgn]);
                        }
                    }
                }
            }
            #endregion

            #region 店铺信息
            VShopShowShopScoreModel modelShopScore = new VShopShowShopScoreModel();
            modelShopScore.ShopId = result.ShopId;
            var shop = ServiceProvider.Instance <IShopService> .Create.GetShop(result.ShopId);

            if (shop == null)
            {
                throw new HimallException("错误的店铺信息");
            }

            modelShopScore.ShopName = shop.ShopName;

            #region 获取店铺的评价统计
            var shopStatisticOrderComments = ServiceProvider.Instance <IShopService> .Create.GetShopStatisticOrderComments(result.ShopId);

            var productAndDescription = shopStatisticOrderComments.Where(c => c.CommentKey == Entities.StatisticOrderCommentInfo.EnumCommentKey.ProductAndDescription).FirstOrDefault();
            var sellerServiceAttitude = shopStatisticOrderComments.Where(c => c.CommentKey == Entities.StatisticOrderCommentInfo.EnumCommentKey.SellerServiceAttitude).FirstOrDefault();
            var sellerDeliverySpeed   = shopStatisticOrderComments.Where(c => c.CommentKey ==
                                                                         Entities.StatisticOrderCommentInfo.EnumCommentKey.SellerDeliverySpeed).FirstOrDefault();

            var productAndDescriptionPeer = shopStatisticOrderComments.Where(c => c.CommentKey == Entities.StatisticOrderCommentInfo.EnumCommentKey.ProductAndDescriptionPeer).FirstOrDefault();
            var sellerServiceAttitudePeer = shopStatisticOrderComments.Where(c => c.CommentKey == Entities.StatisticOrderCommentInfo.EnumCommentKey.SellerServiceAttitudePeer).FirstOrDefault();
            var sellerDeliverySpeedPeer   = shopStatisticOrderComments.Where(c => c.CommentKey ==
                                                                             Entities.StatisticOrderCommentInfo.EnumCommentKey.SellerDeliverySpeedPeer).FirstOrDefault();

            var productAndDescriptionMax = shopStatisticOrderComments.Where(c => c.CommentKey == Entities.StatisticOrderCommentInfo.EnumCommentKey.ProductAndDescriptionMax).FirstOrDefault();
            var productAndDescriptionMin = shopStatisticOrderComments.Where(c => c.CommentKey == Entities.StatisticOrderCommentInfo.EnumCommentKey.ProductAndDescriptionMin).FirstOrDefault();

            var sellerServiceAttitudeMax = shopStatisticOrderComments.Where(c => c.CommentKey == Entities.StatisticOrderCommentInfo.EnumCommentKey.SellerServiceAttitudeMax).FirstOrDefault();
            var sellerServiceAttitudeMin = shopStatisticOrderComments.Where(c => c.CommentKey == Entities.StatisticOrderCommentInfo.EnumCommentKey.SellerServiceAttitudeMin).FirstOrDefault();

            var sellerDeliverySpeedMax = shopStatisticOrderComments.Where(c => c.CommentKey == Entities.StatisticOrderCommentInfo.EnumCommentKey.SellerDeliverySpeedMax).FirstOrDefault();
            var sellerDeliverySpeedMin = shopStatisticOrderComments.Where(c => c.CommentKey == Entities.StatisticOrderCommentInfo.EnumCommentKey.SellerDeliverySpeedMin).FirstOrDefault();

            decimal defaultValue = 5;

            modelShopScore.SellerServiceAttitude     = defaultValue;
            modelShopScore.SellerServiceAttitudePeer = defaultValue;
            modelShopScore.SellerServiceAttitudeMax  = defaultValue;
            modelShopScore.SellerServiceAttitudeMin  = defaultValue;

            //宝贝与描述
            if (productAndDescription != null && productAndDescriptionPeer != null && !shop.IsSelf)
            {
                modelShopScore.ProductAndDescription     = productAndDescription.CommentValue;
                modelShopScore.ProductAndDescriptionPeer = productAndDescriptionPeer.CommentValue;
                modelShopScore.ProductAndDescriptionMin  = productAndDescriptionMin.CommentValue;
                modelShopScore.ProductAndDescriptionMax  = productAndDescriptionMax.CommentValue;
            }
            else
            {
                modelShopScore.ProductAndDescription     = defaultValue;
                modelShopScore.ProductAndDescriptionPeer = defaultValue;
                modelShopScore.ProductAndDescriptionMin  = defaultValue;
                modelShopScore.ProductAndDescriptionMax  = defaultValue;
            }

            //卖家服务态度
            if (sellerServiceAttitude != null && sellerServiceAttitudePeer != null && !shop.IsSelf)
            {
                modelShopScore.SellerServiceAttitude     = sellerServiceAttitude.CommentValue;
                modelShopScore.SellerServiceAttitudePeer = sellerServiceAttitudePeer.CommentValue;
                modelShopScore.SellerServiceAttitudeMax  = sellerServiceAttitudeMax.CommentValue;
                modelShopScore.SellerServiceAttitudeMin  = sellerServiceAttitudeMin.CommentValue;
            }
            else
            {
                modelShopScore.SellerServiceAttitude     = defaultValue;
                modelShopScore.SellerServiceAttitudePeer = defaultValue;
                modelShopScore.SellerServiceAttitudeMax  = defaultValue;
                modelShopScore.SellerServiceAttitudeMin  = defaultValue;
            }
            //卖家发货速度
            if (sellerDeliverySpeedPeer != null && sellerDeliverySpeed != null && !shop.IsSelf)
            {
                modelShopScore.SellerDeliverySpeed     = sellerDeliverySpeed.CommentValue;
                modelShopScore.SellerDeliverySpeedPeer = sellerDeliverySpeedPeer.CommentValue;
                modelShopScore.SellerDeliverySpeedMax  = sellerDeliverySpeedMax != null ? sellerDeliverySpeedMax.CommentValue : 0;
                modelShopScore.sellerDeliverySpeedMin  = sellerDeliverySpeedMin != null ? sellerDeliverySpeedMin.CommentValue : 0;
            }
            else
            {
                modelShopScore.SellerDeliverySpeed     = defaultValue;
                modelShopScore.SellerDeliverySpeedPeer = defaultValue;
                modelShopScore.SellerDeliverySpeedMax  = defaultValue;
                modelShopScore.sellerDeliverySpeedMin  = defaultValue;
            }
            #endregion

            modelShopScore.ProductNum = ServiceProvider.Instance <IProductService> .Create.GetShopOnsaleProducts(result.ShopId);

            modelShopScore.IsFavoriteShop    = false;
            modelShopScore.FavoriteShopCount = ServiceProvider.Instance <IShopService> .Create.GetShopFavoritesCount(result.ShopId);

            if (CurrentUser != null)
            {
                modelShopScore.IsFavoriteShop = ServiceProvider.Instance <IShopService> .Create.GetFavoriteShopInfos(CurrentUser.Id).Any(d => d.ShopId == result.ShopId);
            }

            long vShopId;
            var  vshopinfo = ServiceProvider.Instance <IVShopService> .Create.GetVShopByShopId(shop.Id);

            if (vshopinfo == null)
            {
                vShopId = -1;
            }
            else
            {
                vShopId = vshopinfo.Id;
            }
            modelShopScore.VShopId  = vShopId;
            modelShopScore.VShopLog = ServiceProvider.Instance <IVShopService> .Create.GetVShopLog(vShopId);

            if (!string.IsNullOrWhiteSpace(modelShopScore.VShopLog))
            {
                modelShopScore.VShopLog = Himall.Core.HimallIO.GetRomoteImagePath(modelShopScore.VShopLog);
            }

            // 客服
            var customerServices = CustomerServiceApplication.GetMobileCustomerServiceAndMQ(shop.Id);
            #endregion
            #region 根据运费模板获取发货地址
            var    freightTemplateService = ServiceApplication.Create <IFreightTemplateService>();
            var    template       = freightTemplateService.GetFreightTemplate(product.FreightTemplateId);
            string productAddress = string.Empty;
            if (template != null)
            {
                var fullName = ServiceApplication.Create <IRegionService>().GetFullName(template.SourceAddress);
                if (fullName != null)
                {
                    var ass = fullName.Split(' ');
                    if (ass.Length >= 2)
                    {
                        productAddress = ass[0] + " " + ass[1];
                    }
                    else
                    {
                        productAddress = ass[0];
                    }
                }
            }

            var ProductAddress  = productAddress;
            var FreightTemplate = template;
            #endregion

            #region 获取店铺优惠信息
            VShopShowPromotionModel modelVshop = new VShopShowPromotionModel();
            modelVshop.ShopId = result.ShopId;
            var shopInfo = ServiceProvider.Instance <IShopService> .Create.GetShop(result.ShopId);

            if (shopInfo == null)
            {
                throw new HimallException("错误的店铺编号");
            }

            modelVshop.FreeFreight = shop.FreeFreight;


            var bonus = ServiceApplication.Create <IShopBonusService>().GetByShopId(result.ShopId);
            if (bonus != null)
            {
                modelVshop.BonusCount             = bonus.Count;
                modelVshop.BonusGrantPrice        = bonus.GrantPrice;
                modelVshop.BonusRandomAmountStart = bonus.RandomAmountStart;
                modelVshop.BonusRandomAmountEnd   = bonus.RandomAmountEnd;
            }
            FullDiscountActive fullDiscount = null;
            //var fullDiscount = FullDiscountApplication.GetOngoingActiveByProductId(id, shop.Id);
            #endregion
            //商品描述

            var description = ProductManagerApplication.GetProductDescription(result.ProductId);
            if (description == null)
            {
                throw new HimallException("错误的商品编号");
            }

            string DescriptionPrefix = "", DescriptiondSuffix = "";
            var    iprodestempser = ServiceApplication.Create <IProductDescriptionTemplateService>();
            if (description.DescriptionPrefixId != 0)
            {
                var desc = iprodestempser.GetTemplate(description.DescriptionPrefixId, product.ShopId);
                DescriptionPrefix = desc == null ? "" : desc.MobileContent;
            }

            if (description.DescriptiondSuffixId != 0)
            {
                var desc = iprodestempser.GetTemplate(description.DescriptiondSuffixId, product.ShopId);
                DescriptiondSuffix = desc == null ? "" : desc.MobileContent;
            }
            var productDescription = DescriptionPrefix + description.ShowMobileDescription + DescriptiondSuffix;
            //统计商品浏览量、店铺浏览人数
            StatisticApplication.StatisticVisitCount(product.Id, product.ShopId);

            AutoMapper.Mapper.CreateMap <FightGroupActiveModel, FightGroupActiveResult>();
            var     fightGroupData = AutoMapper.Mapper.Map <FightGroupActiveResult>(result);
            decimal discount       = 1M;
            if (CurrentUser != null)
            {
                discount = CurrentUser.MemberDiscount;
            }
            var shopItem = ShopApplication.GetShop(result.ShopId);
            fightGroupData.MiniSalePrice = shopItem.IsSelf ? fightGroupData.MiniSalePrice * discount : fightGroupData.MiniSalePrice;

            string loadShowPrice = string.Empty;//app拼团详细页加载时显示的区间价
            loadShowPrice = fightGroupData.MiniSalePrice.ToString("f2");

            if (fightGroupData != null && fightGroupData.ActiveItems.Count() > 0)
            {
                decimal min = fightGroupData.ActiveItems.Min(s => s.ActivePrice);
                decimal max = fightGroupData.ActiveItems.Max(s => s.ActivePrice);
                loadShowPrice = (min < max) ? (min.ToString("f2") + " - " + max.ToString("f2")) : min.ToString("f2");
            }

            var _result = new
            {
                success        = true,
                FightGroupData = fightGroupData,
                ShowSkuInfo    = new
                {
                    ColorAlias       = model.ColorAlias,
                    SizeAlias        = model.SizeAlias,
                    VersionAlias     = model.VersionAlias,
                    MinSalePrice     = model.MinSalePrice,
                    ProductImagePath = model.ProductImagePath,
                    Color            = model.Color.OrderByDescending(p => p.SkuId),
                    Size             = model.Size.OrderByDescending(p => p.SkuId),
                    Version          = model.Version.OrderByDescending(p => p.SkuId)
                },
                ShowPromotion       = modelVshop,
                fullDiscount        = fullDiscount,
                ShowNewCanJoinGroup = GroupsData,
                ProductCommentShow  = modelSay,
                ProductDescription  = productDescription.Replace("src=\"/Storage/", "src=\"" + Core.HimallIO.GetRomoteImagePath("/Storage") + "/"),
                ShopScore           = modelShopScore,
                CashDepositsServer  = cashDepositModel,
                ProductAddress      = ProductAddress,
                //Free = FreightTemplate.IsFree == FreightTemplateType.Free ? "免运费" : "",
                userList              = userList,
                IsUserEnter           = IsUserEnter,
                SkuData               = skudata,
                CustomerServices      = customerServices,
                IsOpenLadder          = product.IsOpenLadder,
                VideoPath             = string.IsNullOrWhiteSpace(product.VideoPath) ? string.Empty : Himall.Core.HimallIO.GetRomoteImagePath(product.VideoPath),
                LoadShowPrice         = loadShowPrice,                                                                                                           //商品时区间价
                ProductSaleCountOnOff = (SiteSettingApplication.SiteSettings.ProductSaleCountOnOff == 1),                                                        //是否显示销量
                SaleCounts            = data.ActiveItems.Sum(d => d.BuyCount),                                                                                   //销量
                FreightStr            = FreightTemplateApplication.GetFreightStr(product.Id, FreightTemplate, CurrentUser, product),                             //运费多少或免运费
                SendTime              = (FreightTemplate != null && !string.IsNullOrEmpty(FreightTemplate.SendTime) ? (FreightTemplate.SendTime + "h内发货") : ""), //运费模板发货时间
            };
            return(JsonResult <dynamic>(_result));
        }
Example #12
0
        public object GetUpdateToCart(string openId, string SkuID, int Quantity, int GiftID = 0)
        {
            //验证用户
            CheckUserLogin();
            var  cartHelper  = new CartHelper();
            long userId      = CurrentUser != null ? CurrentUser.Id : 0;
            var  skus        = cartHelper.GetCart(userId);
            var  oldQuantity = GetCartProductQuantity(skus, skuId: SkuID);

            oldQuantity = oldQuantity + Quantity;

            long productId = 0;
            var  skuItem   = skus.Items.FirstOrDefault(i => i.SkuId == SkuID);

            if (null == skuItem)
            {
                var sku = ProductManagerApplication.GetSKU(SkuID);
                if (null == sku)
                {
                    return(Json(ErrorResult <dynamic>("错误的参数:SkuId")));
                }
                productId = sku.ProductId;
            }
            else
            {
                productId = skuItem.ProductId;
            }
            var ladderPrice = 0m;
            var product     = ProductManagerApplication.GetProduct(productId);

            if (product != null)
            {
                if (product.MaxBuyCount > 0 && oldQuantity > product.MaxBuyCount && !product.IsOpenLadder)
                {
                    cartHelper.UpdateCartItem(SkuID, product.MaxBuyCount, userId);
                    return(Json(ErrorResult <dynamic>(string.Format("每个ID限购{0}件", product.MaxBuyCount), new { stock = product.MaxBuyCount })));
                }
            }


            SKUInfo skuinfo = OrderApplication.GetSkuByID(SkuID);

            if (skuinfo.Stock < oldQuantity)
            {
                cartHelper.UpdateCartItem(SkuID, Convert.ToInt32(skuinfo.Stock), userId);
                return(Json(ErrorResult <dynamic>("库存不足", new { stock = skuinfo.Stock })));
            }

            cartHelper.UpdateCartItem(SkuID, oldQuantity, userId);
            //调用查询购物车数据

            #region 阶梯价--张宇枫
            var isOpenLadder = product.IsOpenLadder;
            if (isOpenLadder)
            {
                var shop = ShopApplication.GetShop(product.ShopId);
                var groupCartByProduct = cartHelper.GetCart(userId).Items.Where(item => item.ShopBranchId == 0).GroupBy(i => i.ProductId).ToList();
                //var groupCartByProduct = skus.Items.Where(item => item.ShopBranchId == 0).Select(c =>
                //{
                //    var cItem = new Mall.Entities.ShoppingCartItem();
                //    var skuInfo = ServiceProvider.Instance<IProductService>.Create.GetSku(c.SkuId);
                //    if (skuInfo != null)
                //        cItem = c;
                //    return cItem;
                //}).GroupBy(i => i.ProductId).ToList();

                var quantity =
                    groupCartByProduct.Where(i => i.Key == productId)
                    .ToList()
                    .Sum(cartitem => cartitem.Sum(i => i.Quantity));
                ladderPrice = ProductManagerApplication.GetProductLadderPrice(productId, quantity);
                if (shop.IsSelf)
                {
                    ladderPrice = CurrentUser.MemberDiscount * ladderPrice;
                }
            }
            #endregion
            return(Json(new { Price = ladderPrice.ToString("F2"), ProductId = productId, IsOpenLadder = isOpenLadder ? 1 : 0 }));
        }
Example #13
0
        /// <summary>
        /// 根据核销码取订单
        /// </summary>
        /// <param name="pickcode"></param>
        /// <returns></returns>
        public object GetShopOrder(string pickcode)
        {
            CheckUserLogin();

            var codeInfo = OrderApplication.GetOrderVerificationCodeInfoByCode(pickcode);

            if (codeInfo == null)
            {
                return new { success = false, msg = "该核销码无效" }
            }
            ;

            var order = OrderApplication.GetOrderInfo(codeInfo.OrderId);

            if (order == null)
            {
                return new { success = false, msg = "该核销码无效" }
            }
            ;

            if (order.OrderType != OrderInfo.OrderTypes.Virtual)
            {
                return new { success = false, msg = "核销订单无效" }
            }
            ;

            if (order.ShopId != this.CurrentShop.Id)
            {
                return new { success = false, msg = "非本店核销码,请买家核对信息" }
            }
            ;

            if (order.ShopBranchId > 0)//商家只能核销本商家,而非下面门店的
            {
                return new { success = false, msg = "非本店核销码,请买家核对信息" }
            }
            ;

            if (codeInfo.Status == OrderInfo.VerificationCodeStatus.AlreadyVerification)
            {
                return new { success = false, msg = string.Format("该核销码于{0}已核销", codeInfo.VerificationTime.Value.ToString("yyyy-MM-dd HH:mm")) }
            }
            ;

            if (codeInfo.Status == OrderInfo.VerificationCodeStatus.Expired)
            {
                return new { success = false, msg = "此核销码已过期,无法核销" }
            }
            ;

            if (codeInfo.Status == OrderInfo.VerificationCodeStatus.Refund)
            {
                return new { success = false, msg = "此核销码正处于退款中,无法核销" }
            }
            ;

            if (codeInfo.Status == OrderInfo.VerificationCodeStatus.RefundComplete)
            {
                return new { success = false, msg = "此核销码已经退款成功,无法核销" }
            }
            ;

            var orderItem          = Application.OrderApplication.GetOrderItemsByOrderId(order.Id);
            var orderItemInfo      = orderItem.FirstOrDefault();
            var virtualProductInfo = ProductManagerApplication.GetVirtualProductInfoByProductId(orderItemInfo.ProductId);

            if (virtualProductInfo != null && virtualProductInfo.ValidityType && DateTime.Now < virtualProductInfo.StartDate.Value)
            {
                return(new { success = false, msg = "该核销码暂时不能核销,请留意生效时间!" });
            }
            if (orderItemInfo.EffectiveDate.HasValue)
            {
                if (DateTime.Now < orderItemInfo.EffectiveDate.Value)
                {
                    return new { success = false, msg = "该核销码暂时不能核销,请留意生效时间!" }
                }
                ;
            }

            foreach (var item in orderItem)
            {
                item.ThumbnailsUrl = Core.HimallIO.GetRomoteProductSizeImage(item.ThumbnailsUrl, 1, (int)Himall.CommonModel.ImageSize.Size_100);
                Entities.TypeInfo typeInfo = ServiceProvider.Instance <ITypeService> .Create.GetTypeByProductId(item.ProductId);

                item.ColorAlias   = (typeInfo == null || string.IsNullOrEmpty(typeInfo.ColorAlias)) ? SpecificationType.Color.ToDescription() : typeInfo.ColorAlias;
                item.SizeAlias    = (typeInfo == null || string.IsNullOrEmpty(typeInfo.SizeAlias)) ? SpecificationType.Size.ToDescription() : typeInfo.SizeAlias;
                item.VersionAlias = (typeInfo == null || string.IsNullOrEmpty(typeInfo.VersionAlias)) ? SpecificationType.Version.ToDescription() : typeInfo.VersionAlias;
                var productInfo = ProductManagerApplication.GetProduct(item.ProductId);
                if (productInfo != null)
                {
                    item.ColorAlias = !string.IsNullOrWhiteSpace(productInfo.ColorAlias) ? productInfo.ColorAlias : item.ColorAlias;

                    item.SizeAlias    = !string.IsNullOrWhiteSpace(productInfo.SizeAlias) ? productInfo.SizeAlias : item.SizeAlias;
                    item.VersionAlias = !string.IsNullOrWhiteSpace(productInfo.VersionAlias) ? productInfo.VersionAlias : item.VersionAlias;
                }
            }
            int validityType = 0; string startDate = string.Empty, endDate = string.Empty;

            if (virtualProductInfo != null)
            {
                validityType = virtualProductInfo.ValidityType ? 1 : 0;
                if (validityType == 1)
                {
                    startDate = virtualProductInfo.StartDate.Value.ToString("yyyy-MM-dd");
                    endDate   = virtualProductInfo.EndDate.Value.ToString("yyyy-MM-dd");
                }
            }
            var verifications = OrderApplication.GetOrderVerificationCodeInfosByOrderIds(new List <long>()
            {
                order.Id
            }).Where(a => a.Status == OrderInfo.VerificationCodeStatus.WaitVerification);
            var codes = verifications.ToList();//待消费的核销码

            if (codes != null)
            {
                codes.ForEach(a =>
                {
                    a.SourceCode       = a.VerificationCode;
                    a.VerificationCode = System.Text.RegularExpressions.Regex.Replace(a.VerificationCode, "(\\d{4})\\d{4}(\\d{4})", "$1****$2");
                });
            }
            var verificationCode = codes.Select(p =>
            {
                return(new
                {
                    Status = p.Status,
                    VerificationCode = p.VerificationCode,
                    SourceCode = p.SourceCode
                });
            });
            var virtualOrderItemInfos = OrderApplication.GetVirtualOrderItemInfosByOrderId(order.Id).Select(p =>
            {
                return(new
                {
                    VirtualProductItemType = p.VirtualProductItemType,
                    VirtualProductItemName = p.VirtualProductItemName,
                    Content = ReplaceImage(p.Content, p.VirtualProductItemType)
                });
            });

            order.OrderStatusText = order.OrderStatus.ToDescription();
            order.PaymentTypeName = PaymentApplication.GetPaymentTypeDescById(order.PaymentTypeGateway) ?? order.PaymentTypeName;//统一显示支付方式名称
            return(new { success = true, order = order, orderItem = orderItem, virtualOrderItemInfos = virtualOrderItemInfos, verificationCodes = verificationCode, validityType = validityType, startDate = startDate, endDate = endDate });
        }
Example #14
0
        public FlashSaleModel Get(long id)
        {
            var model = DbFactory.Default.Get <FlashSaleInfo>().Where(p => p.Id == id).FirstOrDefault();

            if (model == null)
            {
                throw new MallException("活动不存在!");
            }
            var            product = ProductManagerApplication.GetProduct(model.ProductId);
            FlashSaleModel result  = new FlashSaleModel();

            result.Id                    = model.Id;
            result.Title                 = model.Title;
            result.ShopId                = model.ShopId;
            result.ProductId             = model.ProductId;
            result.Status                = model.Status;
            result.ProductName           = product.ProductName;
            result.ProductImg            = product.RelativePath;
            result.MarketPrice           = product.MarketPrice;
            result.StatusStr             = model.Status.ToDescription();
            result.BeginDate             = model.BeginDate.ToString("yyyy-MM-dd HH:mm");
            result.EndDate               = model.EndDate.ToString("yyyy-MM-dd HH:mm");
            result.LimitCountOfThePeople = model.LimitCountOfThePeople;
            result.SaleCount             = model.SaleCount;
            result.CategoryName          = model.CategoryName;
            result.MinPrice              = result.SkuMinPrice = result.SkuMaxPrice = model.MinPrice;
            result.Details               = new List <FlashSaleDetailModel>();

            var details = DbFactory.Default.Get <FlashSaleDetailInfo>().Where(p => p.FlashSaleId == result.Id).ToList();
            var skus    = DbFactory.Default.Get <SKUInfo>().Where(p => p.ProductId == model.ProductId).ToList();

            #region 阶梯商品价格--ZYF
            var price = GetMinLadderPrice(model.ProductId);
            #endregion
            if (details != null && details.Count() > 0)
            {
                result.SkuMinPrice = details.Min(t => t.Price);
                result.SkuMaxPrice = details.Max(t => t.Price);
            }

            foreach (var sku in skus)
            {
                var detail             = details.FirstOrDefault(p => p.SkuId == sku.Id);
                FlashSaleDetailModel d = new FlashSaleDetailModel();
                d.Id         = detail == null ? 0 : detail.Id;
                d.SkuId      = sku.Id;
                d.Price      = detail == null ? sku.SalePrice : (decimal)detail.Price;
                d.Color      = sku.Color;
                d.Size       = sku.Size;
                d.Version    = sku.Version;
                d.Stock      = (int)sku.Stock;
                d.TotalCount = detail == null ? 0 : Math.Min((int)sku.Stock, detail.TotalCount);
                d.CostPrice  = sku.CostPrice;
                d.SalePrice  = price > 0 ? price : sku.SalePrice;
                d.minMath    = 0;
                result.Details.Add(d);
            }
            result.Quantity = result.Details.Sum(a => a.TotalCount);

            //if( details != null )
            //{
            //    foreach( var detail in details )
            //    {
            //        var sku = context.SKUInfo.FirstOrDefault( p => p.Id == detail.SkuId );
            //        if( sku == null )
            //        {
            //            //如果sku为空,证明限时购的sku记录与商品的不一致
            //            //证明商品在限时购已存在的情况下修改了sku相关信息
            //            //暂时还没做处理
            //            break;
            //        }
            //        FlashSaleDetailModel d = new FlashSaleDetailModel();
            //        d.Id = detail.Id;
            //        d.SkuId = detail.SkuId;
            //        d.Price = ( decimal )detail.Price;
            //        d.Color = sku.Color;
            //        d.Size = sku.Size;
            //        d.Version = sku.Version;
            //        d.Stock = ( int )sku.Stock;
            //        d.CostPrice = sku.CostPrice;
            //        d.SalePrice = sku.SalePrice;
            //        result.Details.Add( d );
            //    }
            //}

            return(result);
        }
Example #15
0
        /// <summary>
        /// 查询订单
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public string GetOrder(HttpContext context)
        {
            string  bizcontent  = context.Request["bizcontent"];
            JObject jo          = (JObject)JsonConvert.DeserializeObject(bizcontent);
            string  OrderStatus = GetJObjectValue <string>(jo, "OrderStatus");
            string  PlatOrderNo = GetJObjectValue <string>(jo, "PlatOrderNo");
            string  StartTime   = GetJObjectValue <string>(jo, "StartTime");;
            string  EndTime     = GetJObjectValue <string>(jo, "EndTime");
            string  TimeType    = GetJObjectValue <string>(jo, "TimeType"); //未使用,所有都是按订单创建时间搜索
            int     PageIndex   = GetJObjectValue <int>(jo, "PageIndex");
            int     PageSize    = GetJObjectValue <int>(jo, "PageSize");

            if (PageIndex <= 0)
            {
                PageIndex = 1;
            }
            if (PageSize <= 0)
            {
                PageSize = 10;
            }
            OrderQuery query = new OrderQuery {
                ShopId = CurShopId
            };

            switch (OrderStatus)
            {
            case "JH_01":
                query.Status = Entities.OrderInfo.OrderOperateStatus.WaitPay;
                break;

            case "JH_02":
                query.Status = Entities.OrderInfo.OrderOperateStatus.WaitDelivery;
                if (query.MoreStatus == null)
                {
                    query.MoreStatus = new List <OrderInfo.OrderOperateStatus>()
                    {
                    };
                }
                query.MoreStatus.Add(OrderInfo.OrderOperateStatus.WaitSelfPickUp);
                break;

            case "JH_03":
                query.Status = Entities.OrderInfo.OrderOperateStatus.WaitReceiving;
                break;

            case "JH_04":
                query.Status = Entities.OrderInfo.OrderOperateStatus.Finish;
                break;

            case "JH_05":
                query.Status = Entities.OrderInfo.OrderOperateStatus.Close;
                break;

            case "JH_99":
                query.Status = null;      //所有
                break;
            }
            if (!string.IsNullOrEmpty(PlatOrderNo) && PlatOrderNo != "")
            {
                query.OrderId = PlatOrderNo;
            }
            else
            {
                //检测参数
                if (string.IsNullOrWhiteSpace(StartTime) ||
                    string.IsNullOrWhiteSpace(EndTime) ||
                    string.IsNullOrWhiteSpace(OrderStatus)
                    )
                {
                    throw new HimallApiException("参数错误,有必填参数未给值");
                }
                query.StartDate = DateTime.Parse(StartTime);
                query.EndDate   = DateTime.Parse(EndTime);
            }
            query.PageNo   = PageIndex;
            query.PageSize = PageSize;
            var  orders        = OrderApplication.GetFullOrders(query);
            bool ishasnextpage = false;

            if (orders.Total > 0)
            {
                ishasnextpage = orders.Models.Count == PageSize;
            }
            StringBuilder sb = new StringBuilder();

            sb.Append("{");
            sb.Append("\"code\":" + "\"" + "10000" + "\"");
            sb.Append(",\"message\":" + "\"" + "SUCCESS" + "\"");
            sb.Append(",\"numtotalorder\":" + "\"" + orders.Total + "\"");
            sb.Append(",\"ishasnextpage\":" + "\"" + (ishasnextpage ? "1" : "0") + "\"");
            sb.Append(",\"orders\":");
            sb.Append("[");
            int curordernum = 0;

            foreach (var order in orders.Models)
            {
                if (curordernum > 0)
                {
                    sb.Append(",");
                }
                sb.Append("{");
                sb.Append("\"PlatOrderNo\":" + "\"" + order.OrderId + "\"");
                string tradeStatus     = "";
                string tradeStatusName = "";
                string itemStatus      = "";
                switch (order.OrderStatus)
                {
                case Entities.OrderInfo.OrderOperateStatus.WaitPay:
                    tradeStatus     = "JH_01";
                    tradeStatusName = "等待买家付款";
                    itemStatus      = "JH_01";
                    break;

                case Entities.OrderInfo.OrderOperateStatus.WaitDelivery:
                    tradeStatus     = "JH_02";
                    tradeStatusName = "等待卖家发货";
                    itemStatus      = "JH_02";
                    break;

                case Entities.OrderInfo.OrderOperateStatus.WaitReceiving:
                    tradeStatus     = "JH_03";
                    tradeStatusName = "等待买家确认收货";
                    itemStatus      = "JH_03";
                    break;

                case Entities.OrderInfo.OrderOperateStatus.Close:
                    tradeStatus     = "JH_05";
                    tradeStatusName = "交易关闭";
                    itemStatus      = "JH_05";
                    break;

                case Entities.OrderInfo.OrderOperateStatus.Finish:
                    tradeStatus     = "JH_04";
                    tradeStatusName = "交易完成";
                    itemStatus      = "JH_04";
                    break;

                case Entities.OrderInfo.OrderOperateStatus.WaitSelfPickUp:
                    tradeStatus     = "JH_02";
                    tradeStatusName = "等待卖家发货";
                    itemStatus      = "JH_02";
                    break;

                default:
                    tradeStatus     = "JH_99";
                    tradeStatusName = "其他";
                    itemStatus      = "JH_99";
                    break;
                }
                sb.Append(",\"tradeStatus\":" + "\"" + tradeStatus + "\"");
                sb.Append(",\"tradeStatusdescription\":" + "\"" + tradeStatusName + "\"");
                sb.Append(",\"tradetime\":" + "\"" + order.OrderDate.ToString("yyyy-MM-dd HH:mm:ss") + "\"");
                sb.Append(",\"payorderno\":" + "\"" + "" + "\"");
                sb.Append(",\"country\":" + "\"" + "CN" + "\"");
                string[] ShippingRegion = order.RegionFullName.Split(' ');
                string   province       = "";
                if (ShippingRegion.Length > 0)
                {
                    province = ShippingRegion[0];
                }
                string city = "";
                if (ShippingRegion.Length > 1)
                {
                    city = ShippingRegion[1];
                }
                string area = "";
                if (ShippingRegion.Length > 2)
                {
                    area = ShippingRegion[2];
                }
                string town = "";
                if (ShippingRegion.Length > 3)
                {
                    town = ShippingRegion[3];
                }

                sb.Append(",\"province\":" + "\"" + province + "\"");
                sb.Append(",\"city\":" + "\"" + city + "\"");
                sb.Append(",\"area\":" + "\"" + area + "\"");
                sb.Append(",\"town\":" + "\"" + town + "\"");
                sb.Append(",\"address\":" + "\"" + order.Address + "\"");
                sb.Append(",\"zip\":" + "\"\"");
                sb.Append(",\"phone\":" + "\"\"");
                sb.Append(",\"mobile\":" + "\"" + order.CellPhone + "\"");
                sb.Append(",\"email\":" + "\"\"");
                sb.Append(",\"customerremark\":" + "\"" + order.OrderRemarks + "\"");
                sb.Append(",\"sellerremark\":" + "\"" + order.SellerRemark + "\"");
                sb.Append(",\"postfee\":" + "\"" + order.Freight.ToString("F2") + "\"");
                sb.Append(",\"goodsfee\":" + "\"" + order.ProductTotalAmount.ToString("F2") + "\"");
                sb.Append(",\"totalmoney\":" + "\"" + order.OrderTotalAmount.ToString("F2") + "\"");
                sb.Append(",\"favourablemoney\":" + "\"" + (order.DiscountAmount + order.FullDiscount + order.IntegralDiscount).ToString("F2") + "\"");
                sb.Append(",\"commissionvalue\":" + "\"" + "" + "\"");
                sb.Append(",\"taxamount\":" + "\"0\"");
                sb.Append(",\"tariffamount\":" + "\"" + "" + "\"");
                sb.Append(",\"addedvalueamount\":" + "\"" + order.Tax + "\"");
                sb.Append(",\"consumptiondutyamount\":" + "\"" + "" + "\"");
                sb.Append(",\"sendstyle\":" + "\"" + order.DeliveryType.ToDescription() + "\"");
                sb.Append(",\"paytime\":" + "\"" + GetDateTimeString(order.PayDate, "yyyy-MM-dd HH:mm:ss") + "\"");
                sb.Append(",\"invoicetitle\":" + "\"" + order.InvoiceTitle + "\"");
                sb.Append(",\"taxpayerident\":" + "\"" + order.InvoiceCode + "\"");
                sb.Append(",\"codservicefee\":" + "\"" + "" + "\"");
                sb.Append(",\"receivername\":" + "\"" + order.ShipTo + "\"");
                sb.Append(",\"nick\":" + "\"" + order.UserName + "\"");
                sb.Append(",\"whsecode\":" + "\"" + "" + "\"");
                sb.Append(",\"IsHwgFlag\":" + "\"" + "0" + "\"");
                sb.Append(",\"ShouldPayType\":" + "\"" + GetShouldPayType(order.PaymentType) + "\"");
                sb.Append(",\"StoreName\":" + "\"" + order.ShopBranchName + "\"");
                sb.Append(",\"StoreId\":" + "\"" + order.ShopBranchId + "\"");
                sb.Append(",\"VerifyCode\":" + "\"" + order.PickupCode + "\"");
                //订单项
                sb.Append(",\"goodinfos\":");
                sb.Append("[");
                int curitemnum = 0;
                foreach (var item in order.OrderItems)
                {
                    var sku = ProductManagerApplication.GetSKU(item.SkuId);
                    if (curitemnum > 0)
                    {
                        sb.Append(",");
                    }
                    var skuproid = item.SkuId;
                    if (!string.IsNullOrWhiteSpace(sku.Sku))
                    {
                        skuproid = sku.Sku;
                    }
                    if (skuproid.IndexOf("_0_0_0") > -1 || string.IsNullOrWhiteSpace(skuproid))
                    {
                        var _pro = ProductManagerApplication.GetProduct(item.ProductId);
                        skuproid = _pro.ProductCode;
                    }
                    sb.Append("{");
                    sb.Append("\"ProductId\":" + "\"" + item.SkuId + "\"");
                    sb.Append(",\"suborderno\":" + "\"" + "" + "\"");
                    sb.Append(",\"tradegoodsno\":" + "\"" + skuproid + "\"");
                    sb.Append(",\"tradegoodsname\":" + "\"" + item.ProductName + "\"");
                    sb.Append(",\"tradegoodsspec\":" + "\"" + item.SKU + "\"");
                    sb.Append(",\"goodscount\":" + "\"" + item.Quantity + "\"");
                    sb.Append(",\"price\":" + "\"" + item.Price.ToString("F2") + "\"");
                    sb.Append(",\"discountmoney\":" + "\"" + (item.FullDiscount + item.CouponDiscount + item.DiscountAmount).ToString("F2") + "\"");
                    sb.Append(",\"taxamount\":" + "\"0\"");
                    sb.Append(",\"addedvalueamount\":" + "\"0\"");
                    sb.Append(",\"consumptiondutyamount\":" + "\"0\"");
                    string refundStatus = "JH_07";
                    switch (item.RefundStats)
                    {
                    case 1:
                        refundStatus = "JH_01";
                        break;

                    case 2:
                        refundStatus = "JH_02";
                        break;

                    case 3:
                        refundStatus = "JH_03";
                        break;

                    case 4:
                        refundStatus = "JH_04";
                        break;

                    case 5:
                    case 6:
                        refundStatus = "JH_99";
                        break;

                    case 7:
                        refundStatus = "JH_07";
                        break;
                    }
                    sb.Append(",\"refundStatus\":" + "\"" + refundStatus + "\"");
                    sb.Append(",\"status\":" + "\"" + itemStatus + "\"");
                    sb.Append(",\"remark\":" + "\"" + "" + "\"");
                    sb.Append("}");
                    curitemnum++;
                }
                sb.Append("]");
                //优惠
                sb.Append(",\"coupondetails\":");
                sb.Append("[");
                curitemnum = 0;
                foreach (var item in order.OrderItems)
                {
                    if (item.FullDiscount > 0)
                    {
                        if (curitemnum > 0)
                        {
                            sb.Append(",");
                        }
                        sb.Append(AddCouponDetail(item.SkuId, "JH_OffFreeCoupon", "满减", item.FullDiscount.ToString("F2")));
                        curitemnum++;
                    }
                    if (item.CouponDiscount > 0)
                    {
                        if (curitemnum > 0)
                        {
                            sb.Append(",");
                        }
                        sb.Append(AddCouponDetail(item.SkuId, "JH_Coupon", "优惠券", item.CouponDiscount.ToString("F2")));
                        curitemnum++;
                    }
                    if (item.EnabledRefundIntegral > 0)
                    {
                        if (curitemnum > 0)
                        {
                            sb.Append(",");
                        }
                        sb.Append(AddCouponDetail(item.SkuId, "JH_Point", "积分抵扣", item.EnabledRefundIntegral.Value.ToString("F2")));
                        curitemnum++;
                    }
                    if (item.DiscountAmount > 0)
                    {
                        if (curitemnum > 0)
                        {
                            sb.Append(",");
                        }
                        sb.Append(AddCouponDetail(item.SkuId, "JH_PeopleCoupon", "人工优惠", item.EnabledRefundIntegral.Value.ToString("F2")));
                        curitemnum++;
                    }
                }
                sb.Append("]");

                sb.Append("}");
                curordernum++;
            }
            sb.Append("]");
            sb.Append("}");

            return(sb.ToString());
        }
Example #16
0
        /// <summary>
        /// 更新库存
        /// </summary>
        /// <param name="ItemID"></param>
        /// <param name="SkuID"></param>
        /// <param name="Quantity"></param>
        /// <returns></returns>
        public string AdjustQuantity(HttpContext context)
        {
            string ItemID   = context.Request["ItemID"];
            string SkuID    = context.Request["SkuID"];
            string Quantity = context.Request["Quantity"];

            int    productId = Convert.ToInt32(ItemID);
            string SkuId     = SkuID.Trim();
            int    quantity  = Convert.ToInt32(Quantity);
            string ids       = "";

            if (!string.IsNullOrWhiteSpace(SkuId))
            {
                ids = SkuId;
            }
            else
            {
                ids = string.Format("{0}_0_0_0", productId);
            }

            StringBuilder sb = new StringBuilder();

            try
            {
                sb.Append("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
                sb.Append("<Rsp>");
                if (string.IsNullOrEmpty(SkuId) || string.IsNullOrWhiteSpace(SkuId))
                {
                    try
                    {
                        ProductManagerApplication.SetProductStock(productId, quantity, CommonModel.StockOptionType.Normal);
                        var product = ProductManagerApplication.GetProduct(productId);
                        sb.Append("<Result>1</Result>");
                        if (product != null && product.SaleStatus == Entities.ProductInfo.ProductSaleStatus.OnSale)
                        {
                            sb.Append("<GoodsType>Onsale</GoodsType>");
                        }
                        else
                        {
                            sb.Append("<GoodsType>InStock</GoodsType>");
                        }
                        sb.Append("<Cause></Cause>");
                    }
                    catch
                    {
                        sb.Append("<Result>0</Result>");
                        sb.Append("<GoodsType></GoodsType>");
                        sb.Append("<Cause><![CDATA[{修改库存失败}]]></Cause>");
                    }
                }
                else
                {
                    var skuIdArr  = SkuId.Split(',').ToList();
                    var quantitys = Quantity.Split(',').Select(e => long.Parse(e)).ToList();
                    var changes   = new System.Collections.Generic.Dictionary <string, long>();
                    for (var i = 0; i < skuIdArr.Count; i++)
                    {
                        changes.Add(skuIdArr[i], quantitys[i]);
                    }
                    ProductManagerApplication.SetSkuStock(CommonModel.StockOptionType.Normal, changes);
                    var product = ProductManagerApplication.GetProduct(productId);
                    if (product != null)
                    {
                        sb.Append("<Result>1</Result>");
                        if (product != null && product.SaleStatus == Entities.ProductInfo.ProductSaleStatus.OnSale)
                        {
                            sb.Append("<GoodsType>Onsale</GoodsType>");
                        }
                        else
                        {
                            sb.Append("<GoodsType>InStock</GoodsType>");
                        }
                        sb.Append("<Cause></Cause>");
                    }
                    else
                    {
                        sb.Append("<Result>0</Result>");
                        sb.Append("<GoodsType></GoodsType>");
                        sb.Append("<Cause><![CDATA[{修改库存失败}]]></Cause>");
                    }
                }
                sb.Append("</Rsp>");
            }
            catch (Exception ex)
            {
                sb.Clear();
                sb.Append("<Result>0</Result>");
                sb.Append("<GoodsType></GoodsType>");
                sb.Append("<Cause>" + ex.Message + "</Cause>");
                sb.Append("</Rsp>");
            }
            return(sb.ToString());
        }
        public object GetVerificationRecordDetail(long id)
        {
            CheckUserLogin();

            var recordInfo = OrderApplication.GetVerificationRecordInfoById(id);

            if (recordInfo == null)
            {
                return new { success = false, msg = "错误的ID" }
            }
            ;

            var order = OrderApplication.GetOrderInfo(recordInfo.OrderId);

            if (order == null)
            {
                return new { success = false, msg = "该核销码无效" }
            }
            ;

            if (order.ShopBranchId != this.CurrentShopBranch.Id)
            {
                return new { success = false, msg = "非本店核销记录" }
            }
            ;

            var orderItem = Application.OrderApplication.GetOrderItemsByOrderId(order.Id);

            foreach (var item in orderItem)
            {
                item.ThumbnailsUrl = Core.HimallIO.GetRomoteProductSizeImage(item.ThumbnailsUrl, 1, (int)Himall.CommonModel.ImageSize.Size_100);

                Entities.TypeInfo typeInfo = ServiceProvider.Instance <ITypeService> .Create.GetTypeByProductId(item.ProductId);

                item.ColorAlias   = (typeInfo == null || string.IsNullOrEmpty(typeInfo.ColorAlias)) ? SpecificationType.Color.ToDescription() : typeInfo.ColorAlias;
                item.SizeAlias    = (typeInfo == null || string.IsNullOrEmpty(typeInfo.SizeAlias)) ? SpecificationType.Size.ToDescription() : typeInfo.SizeAlias;
                item.VersionAlias = (typeInfo == null || string.IsNullOrEmpty(typeInfo.VersionAlias)) ? SpecificationType.Version.ToDescription() : typeInfo.VersionAlias;
                var productInfo = ProductManagerApplication.GetProduct(item.ProductId);
                if (productInfo != null)
                {
                    item.ColorAlias   = !string.IsNullOrWhiteSpace(productInfo.ColorAlias) ? productInfo.ColorAlias : item.ColorAlias;
                    item.SizeAlias    = !string.IsNullOrWhiteSpace(productInfo.SizeAlias) ? productInfo.SizeAlias : item.SizeAlias;
                    item.VersionAlias = !string.IsNullOrWhiteSpace(productInfo.VersionAlias) ? productInfo.VersionAlias : item.VersionAlias;
                }
            }
            int validityType = 0; string startDate = string.Empty, endDate = string.Empty;
            var virtualProductInfo = ProductManagerApplication.GetVirtualProductInfoByProductId(orderItem.FirstOrDefault().ProductId);

            if (virtualProductInfo != null)
            {
                validityType = virtualProductInfo.ValidityType ? 1 : 0;
                if (validityType == 1)
                {
                    startDate = virtualProductInfo.StartDate.Value.ToString("yyyy-MM-dd");
                    endDate   = virtualProductInfo.EndDate.Value.ToString("yyyy-MM-dd");
                }
            }

            var verificationCode = recordInfo.VerificationCodeIds.Trim(',').Split(',').ToList();

            verificationCode = verificationCode.Select(a => a = Regex.Replace(a, @"(\d{4})", "$1 ")).ToList();
            var virtualOrderItemInfos = OrderApplication.GetVirtualOrderItemInfosByOrderId(order.Id).Select(p =>
            {
                return(new
                {
                    VirtualProductItemType = p.VirtualProductItemType,
                    VirtualProductItemName = p.VirtualProductItemName,
                    Content = ReplaceImage(p.Content, p.VirtualProductItemType)
                });
            });

            order.OrderStatusText = order.OrderStatus.ToDescription();
            return(new { success = true, order = order, orderItem = orderItem, virtualOrderItemInfos = virtualOrderItemInfos, verificationCodes = verificationCode, validityType = validityType, startDate = startDate, endDate = endDate, verificationTime = recordInfo.VerificationTime.ToString("yyyy-MM-dd HH:mm:ss"), verificationUser = recordInfo.VerificationUser });
        }
        /// <summary>
        /// 根据提货码取订单
        /// </summary>
        /// <param name="pickcode"></param>
        /// <returns></returns>
        public object GetShopBranchOrder(string pickcode)
        {
            CheckUserLogin();

            var codeInfo = OrderApplication.GetOrderVerificationCodeInfoByCode(pickcode);

            if (codeInfo != null)
            {
                var order = OrderApplication.GetOrderInfo(codeInfo.OrderId);
                if (order == null)
                {
                    return new { success = false, msg = "该核销码无效" }
                }
                ;

                if (order.OrderType != OrderInfo.OrderTypes.Virtual)
                {
                    return new { success = false, msg = "核销订单无效" }
                }
                ;

                if (order.ShopBranchId != CurrentShopBranch.Id)
                {
                    return new { success = false, msg = "非本店核销码,请买家核对信息" }
                }
                ;

                if (codeInfo.Status == OrderInfo.VerificationCodeStatus.AlreadyVerification)
                {
                    return new { success = false, msg = string.Format("该核销码于{0}已核销", codeInfo.VerificationTime.Value.ToString("yyyy-MM-dd HH:mm")) }
                }
                ;

                if (codeInfo.Status == OrderInfo.VerificationCodeStatus.Expired)
                {
                    return new { success = false, msg = "此核销码已过期,无法核销" }
                }
                ;

                if (codeInfo.Status == OrderInfo.VerificationCodeStatus.Refund)
                {
                    return new { success = false, msg = "此核销码正处于退款中,无法核销" }
                }
                ;

                if (codeInfo.Status == OrderInfo.VerificationCodeStatus.RefundComplete)
                {
                    return new { success = false, msg = "此核销码已经退款成功,无法核销" }
                }
                ;

                var orderItem          = Application.OrderApplication.GetOrderItemsByOrderId(order.Id);
                var orderItemInfo      = orderItem.FirstOrDefault();
                var virtualProductInfo = ProductManagerApplication.GetVirtualProductInfoByProductId(orderItemInfo.ProductId);
                if (virtualProductInfo != null && virtualProductInfo.ValidityType && DateTime.Now < virtualProductInfo.StartDate.Value)
                {
                    return(new { success = false, msg = "该核销码暂时不能核销,请留意生效时间!" });
                }
                if (orderItemInfo.EffectiveDate.HasValue)
                {
                    if (DateTime.Now < orderItemInfo.EffectiveDate.Value)
                    {
                        return new { success = false, msg = "该核销码暂时不能核销,请留意生效时间!" }
                    }
                    ;
                }

                foreach (var item in orderItem)
                {
                    item.ThumbnailsUrl = Core.HimallIO.GetRomoteProductSizeImage(item.ThumbnailsUrl, 1, (int)Himall.CommonModel.ImageSize.Size_100);
                    Entities.TypeInfo typeInfo = ServiceProvider.Instance <ITypeService> .Create.GetTypeByProductId(item.ProductId);

                    item.ColorAlias   = (typeInfo == null || string.IsNullOrEmpty(typeInfo.ColorAlias)) ? SpecificationType.Color.ToDescription() : typeInfo.ColorAlias;
                    item.SizeAlias    = (typeInfo == null || string.IsNullOrEmpty(typeInfo.SizeAlias)) ? SpecificationType.Size.ToDescription() : typeInfo.SizeAlias;
                    item.VersionAlias = (typeInfo == null || string.IsNullOrEmpty(typeInfo.VersionAlias)) ? SpecificationType.Version.ToDescription() : typeInfo.VersionAlias;
                    var productInfo = ProductManagerApplication.GetProduct(item.ProductId);
                    if (productInfo != null)
                    {
                        item.ColorAlias = !string.IsNullOrWhiteSpace(productInfo.ColorAlias) ? productInfo.ColorAlias : item.ColorAlias;

                        item.SizeAlias    = !string.IsNullOrWhiteSpace(productInfo.SizeAlias) ? productInfo.SizeAlias : item.SizeAlias;
                        item.VersionAlias = !string.IsNullOrWhiteSpace(productInfo.VersionAlias) ? productInfo.VersionAlias : item.VersionAlias;
                    }
                }

                var verifications = OrderApplication.GetOrderVerificationCodeInfosByOrderIds(new List <long>()
                {
                    order.Id
                }).Where(a => a.Status == OrderInfo.VerificationCodeStatus.WaitVerification);
                var codes = verifications.ToList();//待消费的核销码
                if (codes != null)
                {
                    codes.ForEach(a =>
                    {
                        a.SourceCode       = a.VerificationCode;
                        a.VerificationCode = System.Text.RegularExpressions.Regex.Replace(a.VerificationCode, "(\\d{4})\\d{4}(\\d{4})", "$1****$2");
                    });
                }
                var virtualOrderItemInfos = OrderApplication.GetVirtualOrderItemInfosByOrderId(order.Id).Select(p =>
                {
                    return(new
                    {
                        VirtualProductItemType = p.VirtualProductItemType,
                        VirtualProductItemName = p.VirtualProductItemName,
                        Content = ReplaceImage(p.Content, p.VirtualProductItemType)
                    });
                });
                order.OrderStatusText = order.OrderStatus.ToDescription();
                order.PaymentTypeName = PaymentApplication.GetPaymentTypeDescById(order.PaymentTypeGateway) ?? order.PaymentTypeName;//统一显示支付方式名称
                return(new { success = true, order = order, orderItem = orderItem, virtualProductInfo = virtualProductInfo, virtualOrderItemInfos = virtualOrderItemInfos, verificationCodes = codes });
            }
            else
            {
                var order = Application.OrderApplication.GetOrderByPickCode(pickcode);
                if (order == null)
                {
                    return new { success = false, msg = "该核销码无效" }
                }
                ;
                if (order.ShopBranchId != CurrentShopBranch.Id)
                {
                    return new { success = false, msg = "非本门店核销码,请买家核对提货信息" }
                }
                ;
                if (order.OrderStatus == Entities.OrderInfo.OrderOperateStatus.Finish && order.DeliveryType == CommonModel.DeliveryType.SelfTake)
                {
                    return new { success = false, msg = "该核销码于" + order.FinishDate.ToString() + "已核销" }
                }
                ;
                var orderRefundInfo = RefundApplication.GetOrderRefundByOrderId(order.Id);
                if (orderRefundInfo != null && orderRefundInfo.ManagerConfirmStatus == OrderRefundInfo.OrderRefundConfirmStatus.Confirmed)
                {
                    return(new { success = false, msg = "该订单已退款,不能再核销" });
                }
                var orderItem = Application.OrderApplication.GetOrderItemsByOrderId(order.Id);
                foreach (var item in orderItem)
                {
                    item.ThumbnailsUrl = Core.HimallIO.GetRomoteProductSizeImage(item.ThumbnailsUrl, 1, (int)Himall.CommonModel.ImageSize.Size_100);
                    Entities.TypeInfo typeInfo = ServiceProvider.Instance <ITypeService> .Create.GetTypeByProductId(item.ProductId);

                    item.ColorAlias   = (typeInfo == null || string.IsNullOrEmpty(typeInfo.ColorAlias)) ? SpecificationType.Color.ToDescription() : typeInfo.ColorAlias;
                    item.SizeAlias    = (typeInfo == null || string.IsNullOrEmpty(typeInfo.SizeAlias)) ? SpecificationType.Size.ToDescription() : typeInfo.SizeAlias;
                    item.VersionAlias = (typeInfo == null || string.IsNullOrEmpty(typeInfo.VersionAlias)) ? SpecificationType.Version.ToDescription() : typeInfo.VersionAlias;
                    var productInfo = ProductManagerApplication.GetProduct(item.ProductId);
                    if (productInfo != null)
                    {
                        item.ColorAlias   = !string.IsNullOrWhiteSpace(productInfo.ColorAlias) ? productInfo.ColorAlias : item.ColorAlias;
                        item.SizeAlias    = !string.IsNullOrWhiteSpace(productInfo.SizeAlias) ? productInfo.SizeAlias : item.SizeAlias;
                        item.VersionAlias = !string.IsNullOrWhiteSpace(productInfo.VersionAlias) ? productInfo.VersionAlias : item.VersionAlias;
                    }
                }
                //退款状态
                var refundobjs = OrderApplication.GetOrderRefunds(orderItem.Select(e => e.Id));
                //小于4表示商家未确认;与平台未审核,都算退款、退货中
                var refundProcessing = refundobjs.Where(e => (int)e.SellerAuditStatus > 4 && ((int)e.SellerAuditStatus < 4 || e.ManagerConfirmStatus == OrderRefundInfo.OrderRefundConfirmStatus.UnConfirm));
                if (refundProcessing.Count() > 0)
                {
                    order.RefundStats = 1;
                }

                order.OrderStatusText = order.OrderStatus.ToDescription();
                return(new { success = true, order = order, orderItem = orderItem });
            }
        }
Example #19
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));
        }
Example #20
0
        /// <summary>
        /// 退款申请
        /// </summary>
        /// <param name="id"></param>
        /// <param name="itemId"></param>
        /// <returns></returns>
        public ActionResult RefundApply(long orderid, long?itemId, long?refundid)
        {
            RefundApplyModel model = new RefundApplyModel();

            model.RefundMode  = null;
            model.OrderItemId = null;
            var order = _iOrderService.GetOrder(orderid, CurrentUser.Id);

            if (order == null)
            {
                throw new Mall.Core.MallException("该订单已删除或不属于该用户");
            }
            if (order.OrderType != OrderInfo.OrderTypes.Virtual && (int)order.OrderStatus < 2)
            {
                throw new Mall.Core.MallException("错误的售后申请,订单状态有误");
            }
            if (order.OrderType != OrderInfo.OrderTypes.Virtual && itemId == null && order.OrderStatus != Entities.OrderInfo.OrderOperateStatus.WaitDelivery && order.OrderStatus != Entities.OrderInfo.OrderOperateStatus.WaitSelfPickUp)
            {
                throw new Mall.Core.MallException("错误的订单退款申请,订单状态有误");
            }
            //售后时间限制
            if (order.OrderType != OrderInfo.OrderTypes.Virtual && _iOrderService.IsRefundTimeOut(orderid))
            {
                throw new Mall.Core.MallException("订单已超过售后期");
            }
            if (order.OrderType == OrderInfo.OrderTypes.Virtual)
            {
                //如果为虚拟商品,则要判断该商品是否允许退款,且该订单中是否至少有一个待核销的核销码
                var orderItemInfo = OrderApplication.GetOrderItemsByOrderId(order.Id).FirstOrDefault();
                if (orderItemInfo != null)
                {
                    itemId = orderItemInfo.Id;
                    var virtualProductInfo = ProductManagerApplication.GetVirtualProductInfoByProductId(orderItemInfo.ProductId);
                    if (virtualProductInfo != null)
                    {
                        if (virtualProductInfo.SupportRefundType == 3)
                        {
                            throw new Mall.Core.MallException("该商品不支持退款");
                        }
                        if (virtualProductInfo.SupportRefundType == 1 && DateTime.Now > virtualProductInfo.EndDate.Value)
                        {
                            throw new Mall.Core.MallException("该商品不支持过期退款");
                        }
                        var orderVerificationCodes = OrderApplication.GetOrderVerificationCodeInfosByOrderIds(new List <long>()
                        {
                            order.Id
                        });
                        long num = orderVerificationCodes.Where(a => a.Status == OrderInfo.VerificationCodeStatus.WaitVerification).Count();
                        if (num == 0)
                        {
                            throw new Mall.Core.MallException("该商品没有可退的核销码");
                        }
                    }
                }
            }

            //计算可退金额 预留
            _iOrderService.CalculateOrderItemRefund(orderid);

            var item = new Entities.OrderItemInfo();

            model.MaxRefundGoodsNumber = 0;
            model.MaxRefundAmount      = order.OrderEnabledRefundAmount;
            if (itemId == null)
            {
                model.OrderItems = _iOrderService.GetOrderItemsByOrderId(order.Id);
                if (model.OrderItems.Count == 1)
                {
                    item = model.OrderItems.FirstOrDefault();
                }
            }
            else
            {
                item = _iOrderService.GetOrderItem(itemId.Value);
                model.OrderItems.Add(item);
                model.MaxRefundGoodsNumber = item.Quantity - item.ReturnQuantity;
                model.MaxRefundAmount      = item.EnabledRefundAmount - item.RefundPrice;
            }
            if (order.OrderType == OrderInfo.OrderTypes.Virtual)
            {
                var count = OrderApplication.GetOrderVerificationCodeInfosByOrderIds(new List <long>()
                {
                    order.Id
                }).Where(a => a.Status != OrderInfo.VerificationCodeStatus.WaitVerification).ToList().Count;
                if (item.EnabledRefundAmount.HasValue)
                {
                    decimal price = item.EnabledRefundAmount.Value / item.Quantity;
                    model.MaxRefundAmount = item.EnabledRefundAmount.Value - Math.Round(count * price, 2, MidpointRounding.AwayFromZero);
                }
            }
            foreach (var orderItem in model.OrderItems)
            {
                Entities.TypeInfo typeInfo = _iTypeService.GetTypeByProductId(orderItem.ProductId);
                var productInfo            = ProductManagerApplication.GetProduct(orderItem.ProductId);
                orderItem.ColorAlias   = (typeInfo == null || string.IsNullOrEmpty(typeInfo.ColorAlias)) ? SpecificationType.Color.ToDescription() : typeInfo.ColorAlias;
                orderItem.SizeAlias    = (typeInfo == null || string.IsNullOrEmpty(typeInfo.SizeAlias)) ? SpecificationType.Size.ToDescription() : typeInfo.SizeAlias;
                orderItem.VersionAlias = (typeInfo == null || string.IsNullOrEmpty(typeInfo.VersionAlias)) ? SpecificationType.Version.ToDescription() : typeInfo.VersionAlias;
                if (productInfo != null)
                {
                    orderItem.ColorAlias   = !string.IsNullOrWhiteSpace(productInfo.ColorAlias) ? productInfo.ColorAlias : orderItem.ColorAlias;
                    orderItem.SizeAlias    = !string.IsNullOrWhiteSpace(productInfo.SizeAlias) ? productInfo.SizeAlias : orderItem.SizeAlias;
                    orderItem.VersionAlias = !string.IsNullOrWhiteSpace(productInfo.VersionAlias) ? productInfo.VersionAlias : orderItem.VersionAlias;
                }
            }
            if (!model.MaxRefundAmount.HasValue)
            {
                model.MaxRefundAmount = 0;
            }
            bool isCanApply = false;
            var  refundser  = _iRefundService;

            Entities.OrderRefundInfo refunddata;

            if (order.OrderStatus == Entities.OrderInfo.OrderOperateStatus.WaitDelivery)
            {
                isCanApply = refundser.CanApplyRefund(orderid, item.Id);
            }
            else
            {
                isCanApply = refundser.CanApplyRefund(orderid, item.Id, false);
            }
            if (!refundid.HasValue)
            {
                if (order.OrderType != OrderInfo.OrderTypes.Virtual)
                {
                    if (!isCanApply)
                    {
                        var orderRefunds = OrderApplication.GetOrderRefunds(new long[] { item.Id });
                        if (orderRefunds.Count == 1)
                        {
                            Response.Redirect("/OrderRefund/Detail/" + orderRefunds[0].Id);
                        }

                        throw new Mall.Core.MallException("您已申请过售后,不可重复申请");
                    }
                }
                //model.ContactPerson = CurrentUser.RealName;
                //model.ContactCellPhone = CurrentUser.CellPhone;
                //model.ContactCellPhone = order.CellPhone;

                model.ContactPerson    = string.IsNullOrEmpty(order.ShipTo) ? CurrentUser.RealName : order.ShipTo;
                model.ContactCellPhone = string.IsNullOrEmpty(order.CellPhone) ? CurrentUser.CellPhone : order.CellPhone;
                model.OrderItemId      = itemId;
                if (!model.OrderItemId.HasValue)
                {
                    model.IsOrderAllRefund = true;
                    model.RefundMode       = Entities.OrderRefundInfo.OrderRefundMode.OrderRefund;
                }
            }
            else
            {
                refunddata = refundser.GetOrderRefund(refundid.Value, CurrentUser.Id);
                if (refunddata == null)
                {
                    throw new Mall.Core.MallException("错误的售后数据");
                }
                if (order.OrderType != OrderInfo.OrderTypes.Virtual && refunddata.SellerAuditStatus != Entities.OrderRefundInfo.OrderRefundAuditStatus.UnAudit)
                {
                    throw new Mall.Core.MallException("错误的售后状态,不可激活");
                }
                model.ContactPerson      = refunddata.ContactPerson;
                model.ContactCellPhone   = refunddata.ContactCellPhone;
                model.OrderItemId        = refunddata.OrderItemId;
                model.IsOrderAllRefund   = (refunddata.RefundMode == Entities.OrderRefundInfo.OrderRefundMode.OrderRefund);
                model.RefundMode         = refunddata.RefundMode;
                model.RefundReasonValue  = refunddata.Reason;
                model.RefundReasonDetail = refunddata.ReasonDetail;
                model.RefundWayValue     = refunddata.RefundPayType;
                model.CertPic1           = refunddata.CertPic1;
                model.CertPic2           = refunddata.CertPic2;
                model.CertPic3           = refunddata.CertPic3;
            }
            if (!model.IsOrderAllRefund && item.EnabledRefundAmount.HasValue)
            {
                model.RefundGoodsPrice = item.EnabledRefundAmount.Value / item.Quantity;
            }
            model.OrderInfo = order;
            model.OrderId   = orderid;
            model.RefundId  = refundid;

            var reasons = refundser.GetRefundReasons();

            foreach (var _ir in reasons)
            {
                _ir.AfterSalesText = _ir.AfterSalesText.Trim();
            }
            List <SelectListItem> reasel = new List <SelectListItem>();
            SelectListItem        _tmpsel;

            _tmpsel = new SelectListItem {
                Text = "选择售后理由", Value = ""
            };
            reasel.Add(_tmpsel);
            foreach (var _i in reasons)
            {
                _tmpsel = new SelectListItem {
                    Text = _i.AfterSalesText, Value = _i.AfterSalesText
                };
                if (!string.IsNullOrWhiteSpace(model.RefundReasonValue))
                {
                    if (_i.AfterSalesText == model.RefundReasonValue)
                    {
                        _tmpsel.Selected = true;
                    }
                }
                reasel.Add(_tmpsel);
            }
            model.RefundReasons = reasel;

            List <SelectListItem> list = new List <SelectListItem> {
                new SelectListItem {
                    Text  = OrderRefundInfo.OrderRefundPayType.BackCapital.ToDescription(),
                    Value = ((int)OrderRefundInfo.OrderRefundPayType.BackCapital).ToString()
                }
            };

            if (order.CanBackOut())
            {
                _tmpsel = new SelectListItem
                {
                    Text  = OrderRefundInfo.OrderRefundPayType.BackOut.ToDescription(),
                    Value = ((int)OrderRefundInfo.OrderRefundPayType.BackOut).ToString()
                };
                //if (model.RefundWayValue.HasValue)
                //{
                //    if (_tmpsel.Value == model.RefundWayValue.ToString())
                //    {
                //        _tmpsel.Selected = true;
                //    }
                //}
                _tmpsel.Selected = true;  //若订单支付方式为支付宝、微信支付则退款方式默认选中“退款原路返回”
                list.Add(_tmpsel);
            }
            model.RefundWay = list;

            if (order.DeliveryType == CommonModel.DeliveryType.SelfTake)
            {
                var shopBranch = ShopBranchApplication.GetShopBranchById(order.ShopBranchId);
                model.ReturnGoodsAddress  = RegionApplication.GetFullName(shopBranch.AddressId);
                model.ReturnGoodsAddress += " " + shopBranch.AddressDetail;
                model.ReturnGoodsAddress += " " + shopBranch.ContactPhone;
            }

            ViewBag.Keyword  = string.IsNullOrWhiteSpace(SiteSettings.SearchKeyword) ? SiteSettings.Keyword : SiteSettings.SearchKeyword;
            ViewBag.Keywords = SiteSettings.HotKeyWords;
            #region 虚拟订单退款
            ViewBag.orderVerificationCode = OrderApplication.GetOrderVerificationCodeInfosByOrderIds(new List <long>()
            {
                order.Id
            }).Where(a => a.Status == OrderInfo.VerificationCodeStatus.WaitVerification).ToList();
            #endregion
            ViewBag.IsVirtual = order.OrderType == OrderInfo.OrderTypes.Virtual ? 1 : 0;
            return(View(model));
        }
Example #21
0
        // GET: Web/UserOrder

        public ActionResult Index(string orderDate, string keywords, string orderids, DateTime?startDateTime, DateTime?endDateTime, int?orderStatus, int pageNo = 1, int pageSize = 10)
        {
            ViewBag.Grant = null;

            if (!string.IsNullOrEmpty(orderids) && orderids.IndexOf(',') <= 0)
            {
                ViewBag.Grant = _iShopBonusService.GetByOrderId(long.Parse(orderids));
            }

            DateTime?startDate = startDateTime;
            DateTime?endDate   = endDateTime;

            if (!string.IsNullOrEmpty(orderDate) && orderDate.ToLower() != "all")
            {
                switch (orderDate.ToLower())
                {
                case "threemonth":
                    startDate = DateTime.Now.AddMonths(-3);
                    break;

                case "halfyear":
                    startDate = DateTime.Now.AddMonths(-6);
                    break;

                case "year":
                    startDate = DateTime.Now.AddYears(-1);
                    break;

                case "yearago":
                    endDate = DateTime.Now.AddYears(-1);
                    break;
                }
            }

            if (orderStatus.HasValue && orderStatus == 0)
            {
                orderStatus = null;
            }

            var queryModel = new OrderQuery()
            {
                StartDate      = startDate,
                EndDate        = endDate,
                Status         = (Entities.OrderInfo.OrderOperateStatus?)orderStatus,
                UserId         = CurrentUser.Id,
                SearchKeyWords = keywords,
                PageSize       = pageSize,
                PageNo         = pageNo
            };

            var orders        = OrderApplication.GetOrders(queryModel);
            var orderComments = OrderApplication.GetOrderCommentCount(orders.Models.Select(p => p.Id));
            var orderItems    = OrderApplication.GetOrderItemsByOrderId(orders.Models.Select(p => p.Id));
            var orderRefunds  = OrderApplication.GetOrderRefunds(orderItems.Select(p => p.Id));

            PagingInfo info = new PagingInfo
            {
                CurrentPage  = pageNo,
                ItemsPerPage = pageSize,
                TotalItems   = orders.Total
            };

            ViewBag.pageInfo = info;
            ViewBag.UserId   = CurrentUser.Id;
            var siteSetting = SiteSettingApplication.SiteSettings;
            var shopBonus   = _iShopBonusService;

            ViewBag.SalesRefundTimeout = siteSetting.SalesReturnTimeout;

            var cashDepositsService = _iCashDepositsService;

            var orderList = orders.Models.Select(item => new OrderListModel
            {
                Id                 = item.Id,
                ActiveType         = item.ActiveType,
                OrderType          = item.OrderType,
                Address            = item.Address,
                CellPhone          = item.CellPhone,
                CloseReason        = item.CloseReason,
                CommisTotalAmount  = item.CommisAmount,
                DiscountAmount     = item.DiscountAmount,
                ExpressCompanyName = item.ExpressCompanyName,
                FinishDate         = item.FinishDate,
                Freight            = item.Freight,
                GatewayOrderId     = item.GatewayOrderId,
                IntegralDiscount   = item.IntegralDiscount,
                CapitalAmount      = item.CapitalAmount,
                UserId             = item.UserId,
                ShopId             = item.ShopId,
                ShopName           = item.ShopName,
                ShopBranchId       = item.ShopBranchId,
                ShopBranchName     = GetShopBranchName(item.ShopBranchId),
                ShipTo             = item.ShipTo,
                OrderTotalAmount   = item.OrderTotalAmount,
                PaymentTypeName    = item.PaymentTypeName,
                //满额减
                FullDiscount  = item.FullDiscount,
                OrderStatus   = item.OrderStatus,
                RefundStats   = item.RefundStats,
                CommentCount  = orderComments.ContainsKey(item.Id) ? orderComments[item.Id] : 0,
                OrderDate     = item.OrderDate,
                PaymentType   = item.PaymentType,
                PickupCode    = item.PickupCode,
                OrderItemList = orderItems.Where(oi => oi.OrderId == item.Id).Select(oItem =>
                {
                    var itemrefund = orderRefunds.Where(or => or.OrderItemId == oItem.Id && or.RefundMode != OrderRefundInfo.OrderRefundMode.OrderRefund).FirstOrDefault();
                    var orderItem  = new OrderItemListModel
                    {
                        Id                     = oItem.Id,
                        ProductId              = oItem.ProductId,
                        Color                  = oItem.Color,
                        Size                   = oItem.Size,
                        Version                = oItem.Version,
                        ProductName            = oItem.ProductName,
                        ThumbnailsUrl          = oItem.ThumbnailsUrl,
                        SalePrice              = oItem.SalePrice,
                        SkuId                  = oItem.SkuId,
                        Quantity               = oItem.Quantity,
                        CashDepositsObligation = cashDepositsService.GetCashDepositsObligation(oItem.ProductId),
                    };

                    if (itemrefund != null)
                    {
                        orderItem.RefundStats  = itemrefund.RefundStatusValue;
                        orderItem.ItemRefundId = itemrefund.Id;

                        string showRefundStats = "";
                        if (itemrefund.SellerAuditStatus == OrderRefundInfo.OrderRefundAuditStatus.Audited)
                        {
                            showRefundStats = itemrefund.ManagerConfirmStatus.ToDescription();
                        }
                        else if (item.DeliveryType == CommonModel.DeliveryType.SelfTake || item.ShopBranchId > 0)//如果是自提订单或分配门店订单则转为门店审核状态
                        {
                            showRefundStats = ((CommonModel.Enum.OrderRefundShopAuditStatus)itemrefund.SellerAuditStatus).ToDescription();
                        }
                        else
                        {
                            showRefundStats = itemrefund.SellerAuditStatus.ToDescription();
                        }

                        orderItem.ShowRefundStats = showRefundStats;
                    }
                    orderItem.EnabledRefundAmount = oItem.EnabledRefundAmount;
                    var typeInfo           = _iTypeService.GetTypeByProductId(oItem.ProductId);
                    var prodata            = ProductManagerApplication.GetProduct(oItem.ProductId);
                    orderItem.ColorAlias   = (typeInfo == null || string.IsNullOrEmpty(typeInfo.ColorAlias)) ? SpecificationType.Color.ToDescription() : typeInfo.ColorAlias;
                    orderItem.SizeAlias    = (typeInfo == null || string.IsNullOrEmpty(typeInfo.SizeAlias)) ? SpecificationType.Size.ToDescription() : typeInfo.SizeAlias;
                    orderItem.VersionAlias = (typeInfo == null || string.IsNullOrEmpty(typeInfo.VersionAlias)) ? SpecificationType.Version.ToDescription() : typeInfo.VersionAlias;
                    if (prodata != null)
                    {
                        orderItem.ColorAlias   = !string.IsNullOrWhiteSpace(prodata.ColorAlias) ? prodata.ColorAlias : orderItem.ColorAlias;
                        orderItem.SizeAlias    = !string.IsNullOrWhiteSpace(prodata.SizeAlias) ? prodata.SizeAlias : orderItem.SizeAlias;
                        orderItem.VersionAlias = !string.IsNullOrWhiteSpace(prodata.VersionAlias) ? prodata.VersionAlias : orderItem.VersionAlias;
                    }
                    return(orderItem);
                }).ToList(),
                ReceiveBonus = shopBonus.GetGrantByUserOrder(item.Id, CurrentUser.Id),
            }).ToList();


            foreach (var o in orderList)
            {
                o.HasAppendComment = HasAppendComment(o);
                if (o.ReceiveBonus != null)
                {
                    var bouns = shopBonus.GetByGrantId(o.ReceiveBonus.Id);
                    o.ReceiveBonusCount = bouns?.Count ?? 0;
                }
            }

            #region 数据补偿
            List <long> ordidl = orderList.Select(d => d.Id).ToList();
            if (ordidl.Count > 0)
            {
                foreach (var item in orderList)
                {
                    if (item.OrderType != OrderInfo.OrderTypes.Virtual)
                    {
                        var _ord = orders.Models.FirstOrDefault(o => o.Id == item.Id);

                        item.IsRefundTimeOut     = OrderApplication.IsRefundTimeOut(_ord);
                        item.EnabledRefundAmount = _ord.OrderEnabledRefundAmount;
                        //退款状态补偿
                        var _tmpobj = orderRefunds.FirstOrDefault(d => d.OrderId == item.Id && d.RefundMode == OrderRefundInfo.OrderRefundMode.OrderRefund);
                        if (_tmpobj != null)
                        {
                            item.RefundStats   = (int)_tmpobj.SellerAuditStatus;
                            item.OrderRefundId = _tmpobj.Id;
                        }

                        item.OrderCanRefund = false;

                        if (item.OrderStatus == Entities.OrderInfo.OrderOperateStatus.Finish)
                        {
                            if (item.FinishDate.Value.AddDays(siteSetting.SalesReturnTimeout) > DateTime.Now)
                            {
                                item.OrderCanRefund = true;
                            }
                        }
                        if (item.OrderStatus == Entities.OrderInfo.OrderOperateStatus.WaitReceiving)
                        {
                            item.OrderCanRefund = true;
                        }
                        if (item.PaymentType == Entities.OrderInfo.PaymentTypes.CashOnDelivery)
                        {
                            if (item.OrderStatus == Entities.OrderInfo.OrderOperateStatus.Finish)
                            {
                                item.OrderCanRefund = true;
                            }
                        }
                        else
                        {
                            item.OrderCanRefund = true;
                        }

                        item.FightGroupCanRefund = true;   //非拼团订单默认可退

                        //拼团状态补偿
                        if (item.OrderType == Entities.OrderInfo.OrderTypes.FightGroup)
                        {
                            var fgord = _iFightGroupService.GetFightGroupOrderStatusByOrderId(item.Id);
                            if (fgord != null)
                            {
                                item.FightGroupJoinStatus = fgord.GetJoinStatus;
                                item.FightGroupCanRefund  = fgord.CanRefund;
                            }
                            else
                            {
                                item.FightGroupJoinStatus = CommonModel.FightGroupOrderJoinStatus.JoinFailed;
                                item.FightGroupCanRefund  = false;
                            }
                            item.OrderCanRefund = item.OrderCanRefund && item.FightGroupCanRefund;
                        }
                    }
                    else
                    {
                        var itemInfo = item.OrderItemList.FirstOrDefault();
                        if (itemInfo != null)
                        {
                            var virtualProductInfo = ProductManagerApplication.GetVirtualProductInfoByProductId(itemInfo.ProductId);
                            if (virtualProductInfo != null)
                            {
                                //如果该商品支持退款,而订单状态为待消费,则可退款
                                if (virtualProductInfo.SupportRefundType == (sbyte)ProductInfo.SupportVirtualRefundType.SupportAnyTime)
                                {
                                    if (item.OrderStatus == OrderInfo.OrderOperateStatus.WaitVerification)
                                    {
                                        item.OrderCanRefund = true;
                                    }
                                }
                                else if (virtualProductInfo.SupportRefundType == (sbyte)ProductInfo.SupportVirtualRefundType.SupportValidity)
                                {
                                    if (virtualProductInfo.EndDate.Value > DateTime.Now)
                                    {
                                        if (item.OrderStatus == OrderInfo.OrderOperateStatus.WaitVerification)
                                        {
                                            item.OrderCanRefund = true;
                                        }
                                    }
                                }
                                else if (virtualProductInfo.SupportRefundType == (sbyte)ProductInfo.SupportVirtualRefundType.NonSupport)
                                {
                                    item.OrderCanRefund = false;
                                }
                                if (item.OrderCanRefund)
                                {
                                    var orderVerificationCodes = OrderApplication.GetOrderVerificationCodeInfosByOrderIds(new List <long>()
                                    {
                                        item.Id
                                    });
                                    long num = orderVerificationCodes.Where(a => a.Status == OrderInfo.VerificationCodeStatus.WaitVerification).Count();
                                    if (num > 0)
                                    {
                                        item.OrderCanRefund = true;
                                    }
                                    else
                                    {
                                        item.OrderCanRefund = false;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            #endregion

            ViewBag.Keyword  = string.IsNullOrWhiteSpace(SiteSettings.SearchKeyword) ? SiteSettings.Keyword : SiteSettings.SearchKeyword;
            ViewBag.Keywords = SiteSettings.HotKeyWords;
            return(View(orderList.ToList()));
        }
        private List <OrderRefundApiModel> FullModel(List <OrderRefund> refunds)
        {
            var orders     = Application.OrderApplication.GetOrders(refunds.Select(p => p.OrderId));
            var orderItems = Application.OrderApplication.GetOrderItemsByOrderId(refunds.Select(p => p.OrderId));
            var members    = Application.MemberApplication.GetMembers(orders.Select(p => p.UserId).ToList());

            AutoMapper.Mapper.CreateMap <OrderRefund, OrderRefundApiModel>();
            var result = refunds.Select(item =>
            {
                var orditems = new List <DTO.OrderItem>();
                var order    = orders.FirstOrDefault(o => o.Id == item.OrderId);

                if (item.RefundMode == OrderRefundInfo.OrderRefundMode.OrderRefund)
                {
                    orditems = orderItems.Where(d => d.OrderId == item.OrderId).ToList();
                }
                else
                {
                    orditems.Add(orderItems.FirstOrDefault(oi => oi.Id == item.OrderItemId));
                }
                foreach (var orderItem in orditems)
                {
                    orderItem.ThumbnailsUrl    = HimallIO.GetRomoteProductSizeImage(orderItem.ThumbnailsUrl, 1, (int)Himall.CommonModel.ImageSize.Size_100);
                    Entities.TypeInfo typeInfo = ServiceProvider.Instance <ITypeService> .Create.GetTypeByProductId(orderItem.ProductId);
                    orderItem.ColorAlias       = (typeInfo == null || string.IsNullOrEmpty(typeInfo.ColorAlias)) ? SpecificationType.Color.ToDescription() : typeInfo.ColorAlias;
                    orderItem.SizeAlias        = (typeInfo == null || string.IsNullOrEmpty(typeInfo.SizeAlias)) ? SpecificationType.Size.ToDescription() : typeInfo.SizeAlias;
                    orderItem.VersionAlias     = (typeInfo == null || string.IsNullOrEmpty(typeInfo.VersionAlias)) ? SpecificationType.Version.ToDescription() : typeInfo.VersionAlias;
                    orderItem.ShipTo           = order.ShipTo;
                    orderItem.CellPhone        = order.CellPhone;
                    orderItem.RegionFullName   = order.RegionFullName;
                    orderItem.Address          = order.Address;
                    var productInfo            = ProductManagerApplication.GetProduct(orderItem.ProductId);
                    if (productInfo != null)
                    {
                        orderItem.ColorAlias   = !string.IsNullOrWhiteSpace(productInfo.ColorAlias) ? productInfo.ColorAlias : orderItem.ColorAlias;
                        orderItem.SizeAlias    = !string.IsNullOrWhiteSpace(productInfo.SizeAlias) ? productInfo.SizeAlias : orderItem.SizeAlias;
                        orderItem.VersionAlias = !string.IsNullOrWhiteSpace(productInfo.VersionAlias) ? productInfo.VersionAlias : orderItem.VersionAlias;
                    }
                }
                var member = members.FirstOrDefault(m => m.Id == order.UserId);

                var model    = item.Map <OrderRefundApiModel>();
                model.Status = item.SellerAuditStatus == OrderRefundInfo.OrderRefundAuditStatus.Audited ? (int)item.ManagerConfirmStatus : (int)item.SellerAuditStatus;
                //model.StatusDescription = item.SellerAuditStatus == OrderRefundInfo.OrderRefundAuditStatus.Audited ? item.ManagerConfirmStatus.ToDescription() : ((CommonModel.Enum.OrderRefundShopAuditStatus)item.SellerAuditStatus).ToDescription();
                model.StatusDescription = item.SellerAuditStatus == OrderRefundInfo.OrderRefundAuditStatus.Audited ? item.ManagerConfirmStatus.ToDescription() : (order.ShopBranchId > 0 ?
                                                                                                                                                                  ((CommonModel.Enum.OrderRefundShopAuditStatus)item.SellerAuditStatus).ToDescription() : item.SellerAuditStatus.ToDescription());
                //model.UserName = member == null ? "" : member.RealName;
                //model.UserCellPhone = member == null ? "" : member.CellPhone;
                model.IsShopBranchOrder = item.IsShopBranchOrder;
                if (item.IsShopBranchOrder)
                {
                    model.StatusDescription = model.StatusDescription.Replace("商家", "门店");
                    model.RefundStatus      = model.RefundStatus.Replace("商家", "门店");
                }
                model.UserName        = item.ContactPerson;
                model.UserCellPhone   = item.ContactCellPhone;
                model.OrderItem       = orditems;
                model.CertPics        = new string[3];
                model.CertPics[0]     = HimallIO.GetRomoteImagePath(model.CertPic1);
                model.CertPics[1]     = HimallIO.GetRomoteImagePath(model.CertPic2);
                model.CertPics[2]     = HimallIO.GetRomoteImagePath(model.CertPic3);
                string shopBranchName = order.ShopName;
                if (order.ShopBranchId > 0)
                {
                    var shopBranchInfo = ShopBranchApplication.GetShopBranchById(order.ShopBranchId);
                    if (shopBranchInfo != null)
                    {
                        shopBranchName = shopBranchInfo.ShopBranchName;
                    }
                }
                model.ShopName         = shopBranchName;
                model.ReasonDetail     = item.ReasonDetail;
                model.OrderTotalAmount = order.OrderTotalAmount;

                return(model);
            });

            return(result.ToList());
        }
        public ActionResult ShowSkuInfo(FightGroupActiveModel data)
        {
            if (data == null)
            {
                throw new HimallException("错误的活动信息");
            }
            ProductShowSkuInfoModel model = new ProductShowSkuInfoModel();

            model.MinSalePrice     = data.MiniGroupPrice;
            model.ProductImagePath = data.ProductImgPath;
            model.MaxBuyCount      = data.LimitQuantity.HasValue ? data.LimitQuantity.Value : 0;

            #region 商品规格
            Entities.TypeInfo typeInfo     = _iTypeService.GetTypeByProductId((long)data.ProductId);
            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;
            var product = ProductManagerApplication.GetProduct((long)data.ProductId);
            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;
            }
            model.ColorAlias   = colorAlias;
            model.SizeAlias    = sizeAlias;
            model.VersionAlias = versionAlias;

            if (data.ActiveItems != null && data.ActiveItems.Count() > 0)
            {
                model.StockAll = (int)data.ActiveItems.Where(p => p.SkuId.Contains(product.Id + "_")).Sum(p => p.ActiveStock);//总库存(它where一次是因为有效规格是“产品ID_”,过滤无效“{0}_”)
                long colorId = 0, sizeId = 0, versionId = 0;
                foreach (var sku in data.ActiveItems)
                {
                    var specs = sku.SkuId.Split('_');
                    if (specs.Count() > 0 && !string.IsNullOrEmpty(sku.Color))
                    {
                        if (long.TryParse(specs[1], out colorId))
                        {
                        }
                        if (colorId != 0)
                        {
                            if (!model.Color.Any(v => v.Value.Equals(sku.Color)))
                            {
                                var c = data.ActiveItems.Where(s => s.Color.Equals(sku.Color)).Sum(s => s.ActiveStock);
                                model.Color.Add(new Himall.Web.Areas.Web.Models.ProductSKU
                                {
                                    //Name = "选择颜色",
                                    Name         = "选择" + colorAlias,
                                    EnabledClass = c != 0 ? "enabled" : "disabled",
                                    //SelectedClass = !model.Color.Any(c1 => c1.SelectedClass.Equals("selected")) && c != 0 ? "selected" : "",
                                    SelectedClass = "",
                                    SkuId         = colorId,
                                    Value         = sku.Color,
                                    Img           = sku.ShowPic
                                });
                            }
                        }
                    }
                    if (specs.Count() > 1)
                    {
                        if (long.TryParse(specs[2], out sizeId))
                        {
                        }
                        if (sizeId != 0 && !string.IsNullOrEmpty(sku.Size))
                        {
                            if (!model.Size.Any(v => v.Value.Equals(sku.Size)))
                            {
                                var ss = data.ActiveItems.Where(s => s.Size.Equals(sku.Size)).Sum(s1 => s1.ActiveStock);
                                model.Size.Add(new Himall.Web.Areas.Web.Models.ProductSKU
                                {
                                    //Name = "选择尺码",
                                    Name         = "选择" + sizeAlias,
                                    EnabledClass = ss != 0 ? "enabled" : "disabled",
                                    //SelectedClass = !model.Size.Any(s1 => s1.SelectedClass.Equals("selected")) && ss != 0 ? "selected" : "",
                                    SelectedClass = "",
                                    SkuId         = sizeId,
                                    Value         = sku.Size
                                });
                            }
                        }
                    }

                    if (specs.Count() > 2)
                    {
                        if (long.TryParse(specs[3], out versionId))
                        {
                        }
                        if (versionId != 0 && !string.IsNullOrEmpty(sku.Version))
                        {
                            if (!model.Version.Any(v => v.Value.Equals(sku.Version)))
                            {
                                var v = data.ActiveItems.Where(s => s.Version.Equals(sku.Version)).Sum(s => s.ActiveStock);
                                model.Version.Add(new Himall.Web.Areas.Web.Models.ProductSKU
                                {
                                    //Name = "选择版本",
                                    Name         = "选择" + versionAlias,
                                    EnabledClass = v != 0 ? "enabled" : "disabled",
                                    //SelectedClass = !model.Version.Any(v1 => v1.SelectedClass.Equals("selected")) && v != 0 ? "selected" : "",
                                    SelectedClass = "",
                                    SkuId         = versionId,
                                    Value         = sku.Version
                                });
                            }
                        }
                    }
                }
            }
            #endregion

            return(View(model));
        }