public void AppendComment(List <AppendCommentModel> list) { var userid = 0L; var userName = ""; long orderId = 0; var addImageList = new List <ProductCommentImageInfo>(); DbFactory.Default.InTransaction(() => { foreach (var model in list) { var m = DbFactory.Default.Get <ProductCommentInfo>().Where(item => item.Id == model.Id && item.UserId == model.UserId).FirstOrDefault(); if (model.UserId == 0 || m == null) { throw new Mall.Core.MallException("该商品尚未评论,请先评论。"); } if (m.AppendDate.HasValue) { throw new Mall.Core.MallException("您已追加评价过了,不需再重复操作。"); } userid = m.UserId; userName = m.UserName; var orderItem = OrderApplication.GetOrderItem(m.SubOrderId); orderId = orderItem.OrderId; m.AppendContent = model.AppendContent; m.AppendDate = DateTime.Now; if (model.Images != null && model.Images.Length > 0) { foreach (var img in model.Images) { var p = new ProductCommentImageInfo(); p.CommentType = 1;//1代表表示追加评论的图片 p.CommentImage = MoveImages(img, model.UserId); p.CommentId = model.Id; addImageList.Add(p); } } else if (model.WXmediaId != null && model.WXmediaId.Length > 0) { foreach (var img in model.WXmediaId) { var p = new ProductCommentImageInfo(); p.CommentType = 1;//1表示追加的图片 p.CommentImage = DownloadWxImage(img); p.CommentId = model.Id; if (!string.IsNullOrEmpty(p.CommentImage)) { addImageList.Add(p); } } } DbFactory.Default.Update(m); } DbFactory.Default.Add <ProductCommentImageInfo>(addImageList); }); }
/// <summary> /// 订单退款减少销量 /// </summary> /// <param name="orderids"></param> public void ReduceSaleCount(OrderRefundInfo refund) { var order = DbFactory.Default.Get <OrderInfo>().Where(p => p.Id == refund.OrderId).FirstOrDefault(); if (order == null) { return; } var orderItem = OrderApplication.GetOrderItem(refund.OrderItemId); //限时购销量 var orderid = orderItem.OrderId; long productid = orderItem.ProductId; var result = DbFactory.Default.Get <FlashSaleInfo>().Where(p => p.Id == orderItem.FlashSaleId && p.ProductId == productid && p.BeginDate <DateTime.Now && p.EndDate> DateTime.Now && p.Status == FlashSaleInfo.FlashSaleStatus.Ongoing).FirstOrDefault(); if (result != null) { var refoundInfo = DbFactory.Default.Get <OrderRefundInfo>().Where(p => p.OrderId == orderid).FirstOrDefault(); if (refoundInfo != null) { long saleCount = 0; //退款取订单详情数量 if (refoundInfo.RefundMode == OrderRefundInfo.OrderRefundMode.OrderRefund) { saleCount = orderItem.Quantity; } //退货退款,取退货数量 else if (refoundInfo.RefundMode == OrderRefundInfo.OrderRefundMode.ReturnGoodsRefund) { if (refund.IsReturn) { //判断是否有会员发货,没有会员发货视为弃货,不扣销量 if (!string.IsNullOrEmpty(refoundInfo.ExpressCompanyName) && !string.IsNullOrEmpty(refoundInfo.ShipOrderNumber)) { saleCount = refoundInfo.ReturnQuantity; } } } //弃货不扣销量 var count = result.SaleCount - (int)saleCount; result.SaleCount = count < 0 ? 0 : count; DbFactory.Default.Update(result); } } }
/// <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)); }
/// <summary> /// 显示售后记录 /// </summary> /// <param name="applyDate"></param> /// <param name="auditStatus"></param> /// <param name="pageNo"></param> /// <param name="pageSize"></param> /// <param name="showtype">0 所有 1 订单退款 2 仅退款(包含订单退款) 3 退货 4 仅退款</param> /// <returns></returns> public JsonResult List(int pageNo = 1, int pageSize = 10) { DateTime?startDate = null; DateTime?endDate = null; var queryModel = new RefundQuery() { StartDate = startDate, EndDate = endDate, UserId = CurrentUser.Id, PageSize = pageSize, PageNo = pageNo, ShowRefundType = 0 }; var refunds = _iRefundService.GetOrderRefunds(queryModel); var list = refunds.Models.Select(item => { var vshop = _iVShopService.GetVShopByShopId(item.ShopId) ?? new Entities.VShopInfo() { Id = 0 }; bool IsSelfTake = false; var order = _iOrderService.GetOrder(item.OrderId, CurrentUser.Id); if (order.DeliveryType == CommonModel.DeliveryType.SelfTake) { IsSelfTake = true; } var status = string.Empty; if (IsSelfTake || order.ShopBranchId > 0)//分配门店订单与自提订单一致 { status = item.RefundStatus.Replace("商家", "门店"); } var shopBranch = ShopBranchApplication.GetShopBranchById(order.ShopBranchId); var branchName = shopBranch == null ? "" : shopBranch.ShopBranchName; var orderItem = OrderApplication.GetOrderItem(item.OrderItemId); var orderItems = new List <Entities.OrderItemInfo>(); if (item.RefundMode == OrderRefundInfo.OrderRefundMode.OrderRefund) { orderItems = _iOrderService.GetOrderItemsByOrderId(item.OrderId); } else { orderItems.Add(orderItem); } return(new { ShopName = item.ShopName, Vshopid = vshop.Id, ShopBranchId = order.ShopBranchId, ShopBranchName = branchName, RefundStatus = string.IsNullOrEmpty(status) ? item.RefundStatus : status, Id = item.Id, ProductName = orderItem.ProductName, EnabledRefundAmount = item.EnabledRefundAmount, Amount = item.Amount, Img = MallIO.GetProductSizeImage(orderItem.ThumbnailsUrl, 1, (int)ImageSize.Size_100), ShopId = item.ShopId, RefundMode = item.RefundMode, OrderId = item.OrderId, OrderTotal = order.OrderTotalAmount.ToString("f2"), OrderItems = orderItems != null ? orderItems.Select(e => new { ThumbnailsUrl = MallIO.GetProductSizeImage(e.ThumbnailsUrl, 1, (int)ImageSize.Size_100), ProductName = e.ProductName, SkuText = e.Color + " " + e.Size + " " + e.Version, }) : null, SellerAuditStatus = item.SellerAuditStatus }); }); return(SuccessResult <dynamic>(data: list)); }
/// <summary> /// 查询退款状态 /// </summary> /// <param name="context"></param> /// <returns></returns> public string CheckRefundStatus(HttpContext context) { string bizcontent = context.Request["bizcontent"]; JObject jo = (JObject)JsonConvert.DeserializeObject(bizcontent); long orderid = GetJObjectValue <long>(jo, "PlatOrderNo"); if (orderid == 0) { throw new HimallApiException("错误的参数"); } RefundQuery query = new RefundQuery(); query.OrderId = orderid; query.PageNo = 1; query.PageSize = int.MaxValue; var data = RefundApplication.GetOrderRefunds(query); StringBuilder sb = new StringBuilder(); sb.Append("{"); if (data.Models.Count() > 0) { var ordRefund = data.Models.FirstOrDefault(d => d.RefundMode == OrderRefundInfo.OrderRefundMode.OrderRefund); string refundStatus = ""; string refundStatusName = ""; if (ordRefund.RefundMode == OrderRefundInfo.OrderRefundMode.OrderRefund && ordRefund.SellerAuditStatus != OrderRefundInfo.OrderRefundAuditStatus.UnAudit) { switch (ordRefund.SellerAuditStatus) { case OrderRefundInfo.OrderRefundAuditStatus.WaitAudit: refundStatus = "JH_01"; refundStatusName = "已申请"; break; case OrderRefundInfo.OrderRefundAuditStatus.UnAudit: refundStatus = "JH_04"; refundStatusName = "拒绝申请"; break; case OrderRefundInfo.OrderRefundAuditStatus.Audited: if (ordRefund.ManagerConfirmStatus == OrderRefundInfo.OrderRefundConfirmStatus.Confirmed) { refundStatus = "JH_06"; refundStatusName = "已退款"; } else { refundStatus = "JH_99"; refundStatusName = "其他"; } break; } //订单退款 sb.Append("\"refundStatus\":" + "\"" + refundStatus + "\""); sb.Append(",\"refundStatusdescription\":" + "\"" + refundStatusName + "\""); sb.Append(",\"childrenrefundStatus\":" + "\"" + "" + "\""); sb.Append(",\"code\":" + "\"" + "10000" + "\""); sb.Append(",\"message\":" + "\"" + "SUCCESS" + "\""); sb.Append(",\"submessage\":" + "\"" + "退款成功" + "\""); } else { var itemRefund = data.Models.Where(d => d.RefundMode != OrderRefundInfo.OrderRefundMode.OrderRefund).ToList(); if (itemRefund.Count > 0) { sb.Append("\"refundStatus\":" + "\"JH_99\""); sb.Append(",\"refundStatusdescription\":" + "\"其他\""); sb.Append(",\"code\":" + "\"" + "10000" + "\""); sb.Append(",\"message\":" + "\"" + "SUCCESS" + "\""); sb.Append(",\"submessage\":" + "\"" + "退款成功" + "\""); sb.Append(",\"childrenrefundStatus\":["); int curitemno = 0; foreach (var item in itemRefund) { if (curitemno > 0) { sb.Append(","); } sb.Append("{"); switch (item.SellerAuditStatus) { case OrderRefundInfo.OrderRefundAuditStatus.WaitAudit: refundStatus = "JH_01"; refundStatusName = "已申请"; break; case OrderRefundInfo.OrderRefundAuditStatus.UnAudit: refundStatus = "JH_04"; refundStatusName = "拒绝申请"; break; case OrderRefundInfo.OrderRefundAuditStatus.Audited: if (item.ManagerConfirmStatus == OrderRefundInfo.OrderRefundConfirmStatus.Confirmed) { refundStatus = "JH_06"; refundStatusName = "已退款"; } else { refundStatus = "JH_99"; refundStatusName = "其他"; } break; } var orditem = OrderApplication.GetOrderItem(item.OrderItemId); if (orditem != null) { sb.Append("\"refundno\":\"" + item.Id + "\""); sb.Append("\"productname\":\"" + orditem.ProductName + "\""); sb.Append("\"refundstatus\":\"" + refundStatus + "\""); sb.Append("\"refundstatusdescription\":\"" + refundStatusName + "\""); sb.Append("}"); curitemno++; } } sb.Append("]"); } } } else { sb.Append("\"code\":" + "\"" + "10000" + "\""); sb.Append(",\"message\":" + "\"" + "Succes" + "\""); sb.Append(",\"submessage\":" + "\"" + "没有退款" + "\""); sb.Append(",\"refundStatus\":" + "\"JH_07\""); sb.Append(",\"refundStatusdescription\":" + "\"没有退款\""); sb.Append(",\"childrenrefundStatus\":" + "\"" + "" + "\""); } sb.Append("}"); return(sb.ToString()); }
/// <summary> /// 获取退款/售后列表 /// </summary> /// <param name="pageNo">页码</param> /// <param name="pageSize">每页数量</param> /// <returns></returns> public object GetRefundList(int pageNo, int pageSize) { CheckUserLogin(); var orderser = ServiceProvider.Instance <IOrderService> .Create; var refundser = ServiceProvider.Instance <IRefundService> .Create; var vshopser = ServiceProvider.Instance <IVShopService> .Create; DateTime?startDate = null; DateTime?endDate = null; var queryModel = new RefundQuery() { StartDate = startDate, EndDate = endDate, UserId = CurrentUser.Id, PageSize = pageSize, PageNo = pageNo, ShowRefundType = 0 }; var refunds = refundser.GetOrderRefunds(queryModel); var list = refunds.Models.Select(item => { var vshop = vshopser.GetVShopByShopId(item.ShopId) ?? new VShopInfo() { Id = 0 }; var order = orderser.GetOrder(item.OrderId, CurrentUser.Id); var orderItem = OrderApplication.GetOrderItem(item.OrderItemId); var status = item.RefundStatus; if (order != null && order.ShopBranchId > 0) { if (!string.IsNullOrWhiteSpace(status)) { status = status.Replace("商家", "门店"); } } IEnumerable <Entities.OrderItemInfo> orderItems = null; if (item.RefundMode == Entities.OrderRefundInfo.OrderRefundMode.OrderRefund) { var cOrder = orderser.GetOrder(item.OrderId, CurrentUser.Id); orderItems = OrderApplication.GetOrderItems(cOrder.Id); } var shopBranch = ShopBranchApplication.GetShopBranchById(order.ShopBranchId); var branchName = shopBranch == null ? "" : shopBranch.ShopBranchName; return(new { ShopName = item.ShopName, Vshopid = vshop.Id, ShopBranchId = order.ShopBranchId, ShopBranchName = branchName, RefundStatus = status, Id = item.Id, ProductName = orderItem.ProductName, ColorAlias = orderItem.ColorAlias, Color = orderItem.Color, SizeAlias = orderItem.SizeAlias, Size = orderItem.Size, VersionAlias = orderItem.VersionAlias, Version = orderItem.Version, EnabledRefundAmount = item.EnabledRefundAmount, Amount = item.Amount, Img = Core.HimallIO.GetRomoteProductSizeImage(orderItem.ThumbnailsUrl, 1, (int)Himall.CommonModel.ImageSize.Size_350), ShopId = item.ShopId, RefundMode = item.RefundMode.ToDescription(), RefundModeValue = (int)item.RefundMode, OrderId = item.OrderId, OrderTotal = order.OrderTotalAmount.ToString("f2"), OrderItems = orderItems != null ? orderItems.Select(e => new { ThumbnailsUrl = Core.HimallIO.GetRomoteProductSizeImage(e.ThumbnailsUrl, 1, (int)Himall.CommonModel.ImageSize.Size_350), ProductName = e.ProductName, ColorAlias = e.ColorAlias, Color = e.Color, SizeAlias = e.SizeAlias, Size = e.Size, VersionAlias = e.VersionAlias, Version = e.Version }) : null, SellerAuditStatus = item.SellerAuditStatus.ToDescription(), SellerAuditStatusValue = (int)item.SellerAuditStatus, }); }); return(new { total = refunds.Total, data = list, success = true }); }
/// <summary> /// 提交退款/售后申请 /// </summary> /// <param name="value"></param> /// <returns></returns> public object PostRefundApply(OrderRefundApplyModel value) { CheckUserLogin(); try { var ordser = ServiceProvider.Instance <IOrderService> .Create; var refundser = ServiceProvider.Instance <IRefundService> .Create; OrderRefundInfo info = new OrderRefundInfo(); #region 表单数据 info.OrderId = value.OrderId; if (null != value.OrderItemId) { info.OrderItemId = value.OrderItemId.Value; } if (null != value.refundId) { info.Id = value.refundId.Value; } info.RefundType = value.RefundType; info.ReturnQuantity = value.ReturnQuantity; info.Amount = value.Amount; info.Reason = value.Reason; info.ContactPerson = value.ContactPerson; info.ContactCellPhone = value.ContactCellPhone; info.RefundPayType = value.RefundPayType; info.VerificationCodeIds = value.VerificationCodeIds; if (info.RefundMode != OrderRefundInfo.OrderRefundMode.OrderRefund && !value.refundId.HasValue && value.OrderItemId.HasValue) { var _refobj = OrderApplication.GetOrderRefunds(new long[] { value.OrderItemId.Value }).FirstOrDefault(d => d.RefundMode != OrderRefundInfo.OrderRefundMode.OrderRefund); if (_refobj != null) { info.Id = _refobj.Id; } } #endregion #region 初始化售后单的数据 var order = ordser.GetOrder(info.OrderId, CurrentUser.Id); if (order == null) { throw new Himall.Core.HimallException("该订单已删除或不属于该用户"); } if (order.OrderType != OrderInfo.OrderTypes.Virtual && (int)order.OrderStatus < 2) { throw new Himall.Core.HimallException("错误的售后申请,订单状态有误"); } if (value.ReasonDetail != null && value.ReasonDetail.Length > 1000) { throw new Himall.Core.HimallException("退款理由不能超过1000字符"); } if (order.OrderStatus == Entities.OrderInfo.OrderOperateStatus.WaitDelivery || order.OrderStatus == Entities.OrderInfo.OrderOperateStatus.WaitSelfPickUp) { info.RefundMode = OrderRefundInfo.OrderRefundMode.OrderRefund; info.ReturnQuantity = 0; } if (info.RefundType == 1) { info.ReturnQuantity = 0; info.IsReturn = false; } if (order.OrderType != OrderInfo.OrderTypes.Virtual && info.ReturnQuantity < 0) { throw new Himall.Core.HimallException("错误的退货数量"); } var orderitem = OrderApplication.GetOrderItem(info.OrderItemId); if (orderitem == null && info.RefundMode != OrderRefundInfo.OrderRefundMode.OrderRefund) { throw new Himall.Core.HimallException("该订单条目已删除或不属于该用户"); } if (order.OrderType != OrderInfo.OrderTypes.Virtual) { if (info.RefundMode == OrderRefundInfo.OrderRefundMode.OrderRefund) { if (order.OrderStatus != Entities.OrderInfo.OrderOperateStatus.WaitDelivery && order.OrderStatus != Entities.OrderInfo.OrderOperateStatus.WaitSelfPickUp) { throw new Himall.Core.HimallException("错误的订单退款申请,订单状态有误"); } info.IsReturn = false; info.ReturnQuantity = 0; if (info.Amount > order.OrderEnabledRefundAmount) { throw new Himall.Core.HimallException("退款金额不能超过订单的实际支付金额"); } } else { if (info.Amount > (orderitem.EnabledRefundAmount - orderitem.RefundPrice)) { throw new Himall.Core.HimallException("退款金额不能超过订单的可退金额"); } if (info.ReturnQuantity > (orderitem.Quantity - orderitem.ReturnQuantity)) { throw new Himall.Core.HimallException("退货数量不可以超出可退数量"); } } } info.IsReturn = false; if (info.ReturnQuantity > 0) { info.IsReturn = true; } if (info.RefundType == 2) { info.IsReturn = true; } if (order.OrderType != OrderInfo.OrderTypes.Virtual && info.IsReturn == true && info.ReturnQuantity < 1) { throw new Himall.Core.HimallException("错误的退货数量"); } if (info.Amount <= 0) { throw new Himall.Core.HimallException("错误的退款金额"); } info.ShopId = order.ShopId; info.ShopName = order.ShopName; info.UserId = CurrentUser.Id; info.Applicant = CurrentUser.UserName; info.ApplyDate = DateTime.Now; info.Reason = HTMLEncode(info.Reason.Replace("'", "‘").Replace("\"", "”")); info.ReasonDetail = value.ReasonDetail; info.CertPic1 = MoveImages(value.CertPic1, CurrentUser.Id, info.OrderItemId); info.CertPic2 = MoveImages(value.CertPic2, CurrentUser.Id, info.OrderItemId); info.CertPic3 = MoveImages(value.CertPic3, CurrentUser.Id, info.OrderItemId); #endregion //info.RefundAccount = HTMLEncode(info.RefundAccount.Replace("'", "‘").Replace("\"", "”")); if (order.OrderType == OrderInfo.OrderTypes.Virtual) { if (string.IsNullOrWhiteSpace(info.VerificationCodeIds)) { throw new Himall.Core.HimallException("虚拟订单退款核销码不能为空"); } info.VerificationCodeIds = Regex.Replace(info.VerificationCodeIds, @"\s", ""); //检测核销码都为正确的 var codeList = info.VerificationCodeIds.Split(',').ToList(); var codes = OrderApplication.GetOrderVerificationCodeInfoByCodes(codeList); if (codes.Count != codeList.Count) { throw new Himall.Core.HimallException("包含无效的核销码"); } foreach (var item in codes) { if (item.Status != OrderInfo.VerificationCodeStatus.WaitVerification) { throw new Himall.Core.HimallException("包含已申请售后的核销码"); } } info.ReturnQuantity = codes.Count; } if (order.OrderType != OrderInfo.OrderTypes.Virtual) { if (info.Id > 0) { refundser.ActiveRefund(info); } else { refundser.AddOrderRefund(info); } } else { refundser.AddOrderRefund(info); #region 处理退款 try { //虚拟订单自动退款,异常不提示用户,进入平台待审核 string notifyurl = CurrentUrlHelper.CurrentUrlNoPort() + "/Pay/RefundNotify/{0}"; var result = refundser.ConfirmRefund(info.Id, "虚拟订单申请售后自动退款", "", notifyurl); } catch (Exception ex) { Log.Error("虚拟商品自动退异常", ex); } #endregion } return(new { success = true, msg = "提交成功", id = info.Id }); } catch (HimallException he) { return(new { success = false, msg = he.Message }); } catch (Exception ex) { return(new { success = false, msg = "系统异常:" + ex.Message }); } }