private void OnDataLoaded(string rawData) { this.virtualCatalogDictionary = new Dictionary <string, VirtualProductInfo>(); Hashtable hashtable = MiniJSON.jsonDecode(rawData) as Hashtable; if (hashtable != null) { if (hashtable.ContainsKey("catalog")) { ArrayList arrayList = (ArrayList)hashtable["catalog"]; IEnumerator enumerator = arrayList.GetEnumerator(); try { while (enumerator.MoveNext()) { object obj = enumerator.Current; Hashtable hashtable2 = (Hashtable)obj; if (hashtable2.ContainsKey("productID")) { string key = (string)hashtable2["productID"]; if (!this.virtualCatalogDictionary.ContainsKey(key)) { VirtualProductInfo value = new VirtualProductInfo(hashtable2); this.virtualCatalogDictionary.Add(key, value); } } } } finally { IDisposable disposable; if ((disposable = (enumerator as IDisposable)) != null) { disposable.Dispose(); } } this.hasCatalog = true; if (VirtualCatalogManager.onVirtualProductListParsed != null) { VirtualCatalogManager.onVirtualProductListParsed(); } } } }
// GET: Web/OrderRefund /// <summary> /// 退款申请 /// </summary> /// <param name="id"></param> /// <param name="itemId"></param> /// <returns></returns> public ActionResult RefundApply(long orderid, long?itemId, long?refundid) { Mall.Web.Areas.Web.Models.RefundApplyModel model = new Mall.Web.Areas.Web.Models.RefundApplyModel(); model.RefundMode = null; model.OrderItemId = null; var ordser = ServiceApplication.Create <IOrderService>(); var order = ordser.GetOrder(orderid, CurrentUser.Id); string errormsg = ""; string jumpurl = "/" + ViewBag.AreaName + "/Member/Center"; bool isok = true; VirtualProductInfo vProductInfo = null; if (isok) { if (order == null) { isok = false; errormsg = "该订单已删除或不属于该用户"; return(Redirect(jumpurl)); throw new Mall.Core.MallException("该订单已删除或不属于该用户"); } } if (isok) { if (order.OrderType != OrderInfo.OrderTypes.Virtual && (int)order.OrderStatus < 2) { isok = false; errormsg = "错误的售后申请,订单状态有误"; return(Redirect(jumpurl)); 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) { isok = false; errormsg = "该商品不支持退款"; return(Redirect(jumpurl)); 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) { isok = false; errormsg = "该商品没有可退的核销码"; return(Redirect(jumpurl)); throw new Mall.Core.MallException("该商品没有可退的核销码"); } vProductInfo = virtualProductInfo; } } } } if (isok) { if (order.OrderType != OrderInfo.OrderTypes.Virtual) { if (itemId == null && order.OrderStatus != Entities.OrderInfo.OrderOperateStatus.WaitDelivery && order.OrderStatus != Entities.OrderInfo.OrderOperateStatus.WaitSelfPickUp) { isok = false; errormsg = "错误的订单退款申请,订单状态有误"; return(Redirect(jumpurl)); throw new Mall.Core.MallException("错误的订单退款申请,订单状态有误"); } } } if (isok) { if (order.OrderType != OrderInfo.OrderTypes.Virtual) { //售后时间限制 if (_iOrderService.IsRefundTimeOut(orderid)) { isok = false; errormsg = "订单已超过售后期"; return(Redirect(jumpurl)); throw new Mall.Core.MallException("订单已超过售后期"); } } } if (isok) { //计算可退金额 预留 ordser.CalculateOrderItemRefund(orderid); var item = new OrderItemInfo(); model.MaxRefundGoodsNumber = 0; model.MaxRefundAmount = order.OrderEnabledRefundAmount; if (itemId == null) { model.OrderItems = _iOrderService.GetOrderItemsByOrderId(order.Id); } else { item = _iOrderService.GetOrderItem(itemId.Value); model.OrderItems.Add(item); model.MaxRefundGoodsNumber = item.Quantity - item.ReturnQuantity; model.MaxRefundAmount = item.EnabledRefundAmount - item.RefundPrice; } if (!model.MaxRefundAmount.HasValue) { model.MaxRefundAmount = 0; } 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); } } 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 (!isCanApply) { isok = false; errormsg = "您已申请过售后,不可重复申请"; return(Redirect(jumpurl)); 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) { isok = false; errormsg = "错误的售后数据"; return(Redirect(jumpurl)); throw new Mall.Core.MallException("错误的售后数据"); } if (isok) { if (order.OrderType != OrderInfo.OrderTypes.Virtual) { if (refunddata.SellerAuditStatus != Entities.OrderRefundInfo.OrderRefundAuditStatus.UnAudit) { isok = false; errormsg = "错误的售后状态,不可激活"; return(Redirect(jumpurl)); throw new Mall.Core.MallException("错误的售后状态,不可激活"); } } } if (isok) { 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.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; } if (isok) { 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.BackOut = 1; } model.RefundWay = list; } if (order.DeliveryType == DeliveryType.SelfTake) { var shopBranch = ShopBranchApplication.GetShopBranchById(order.ShopBranchId); model.ReturnGoodsAddress = RegionApplication.GetFullName(shopBranch.AddressId); model.ReturnGoodsAddress += " " + shopBranch.AddressDetail; model.ReturnGoodsAddress += " " + shopBranch.ContactPhone; } } ViewBag.errormsg = errormsg; #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; ViewBag.VirtualProductInfo = vProductInfo; return(View(model)); }
public object GetOrderDetail(long orderId) { CheckUserLogin(); var orderService = ServiceProvider.Instance <IOrderService> .Create; var order = orderService.GetOrder(orderId, CurrentUser.Id); var orderitems = orderService.GetOrderItemsByOrderId(order.Id); var orderRefundService = ServiceProvider.Instance <IRefundService> .Create; var productService = ServiceProvider.Instance <IProductService> .Create; var coupon = ServiceProvider.Instance <ICouponService> .Create.GetCouponRecordInfo(order.UserId, order.Id); string couponName = ""; decimal couponAmout = 0; if (coupon != null) { var c = CouponApplication.GetCouponInfo(coupon.CouponId); couponName = c.CouponName; couponAmout = c.Price; } //订单信息是否正常 if (order == null) { throw new MallException("订单号不存在!"); } dynamic expressTrace = new ExpandoObject(); //取订单物流信息 if (!string.IsNullOrWhiteSpace(order.ShipOrderNumber)) { var expressData = ServiceProvider.Instance <IExpressService> .Create.GetExpressData(order.ExpressCompanyName, order.ShipOrderNumber); if (expressData.Success) { expressData.ExpressDataItems = expressData.ExpressDataItems.OrderByDescending(item => item.Time);//按时间逆序排列 expressTrace.traces = expressData.ExpressDataItems.Select(item => new { acceptTime = item.Time.ToString("yyyy-MM-dd HH:mm:ss"), acceptStation = item.Content }); } } var orderRefunds = OrderApplication.GetOrderRefunds(orderitems.Select(p => p.Id)); var isCanOrderReturn = OrderApplication.CanRefund(order); //获取订单商品项数据 var orderDetail = new { ShopId = order.ShopId, EnabledRefundAmount = order.OrderEnabledRefundAmount, OrderItems = orderitems.Select(item => { var productinfo = productService.GetProduct(item.ProductId); Entities.TypeInfo typeInfo = ServiceProvider.Instance <ITypeService> .Create.GetType(productinfo.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; var itemStatusText = ""; var itemrefund = orderRefunds.Where(or => or.OrderItemId == item.Id).FirstOrDefault(d => d.RefundMode != OrderRefundInfo.OrderRefundMode.OrderRefund); int?itemrefstate = (itemrefund == null ? 0 : (int?)itemrefund.SellerAuditStatus); itemrefstate = (itemrefstate > 4 ? (int?)itemrefund.ManagerConfirmStatus : itemrefstate); if (itemrefund != null) { //默认为商家处理进度 if (itemrefstate == 4) { //商家拒绝,可以再发起申请 itemStatusText = ""; } else { itemStatusText = "售后处理中"; } } if (itemrefstate > 4) {//如果商家已经处理完,则显示平台处理进度 if (itemrefstate == 7) { itemStatusText = "退款成功"; } } if (productinfo != null) { colorAlias = (!string.IsNullOrWhiteSpace(productinfo.ColorAlias)) ? productinfo.ColorAlias : colorAlias;//如果商品有自定义规格名称,则用 sizeAlias = (!string.IsNullOrWhiteSpace(productinfo.SizeAlias)) ? productinfo.SizeAlias : sizeAlias; versionAlias = (!string.IsNullOrWhiteSpace(productinfo.VersionAlias)) ? productinfo.VersionAlias : versionAlias; } long activeId = 0; int activetype = 0; var limitbuyser = ServiceProvider.Instance <ILimitTimeBuyService> .Create; var limitBuy = limitbuyser.GetLimitTimeMarketItemByProductId(item.ProductId); if (limitBuy != null) { //salePrice = limitBuy.MinPrice; activeId = limitBuy.Id; activetype = 1; } else { #region 限时购预热 var FlashSale = limitbuyser.IsFlashSaleDoesNotStarted(item.ProductId); var FlashSaleConfig = limitbuyser.GetConfig(); if (FlashSale != null) { TimeSpan flashSaleTime = DateTime.Parse(FlashSale.BeginDate) - DateTime.Now; //开始时间还剩多久 TimeSpan preheatTime = new TimeSpan(FlashSaleConfig.Preheat, 0, 0); //预热时间是多久 if (preheatTime >= flashSaleTime) //预热大于开始 { if (!FlashSaleConfig.IsNormalPurchase) { activeId = FlashSale.Id; activetype = 1; } } } #endregion } return(new { Status = itemrefstate, StatusText = itemStatusText, Id = item.Id, SkuId = item.SkuId, ProductId = item.ProductId, Name = item.ProductName, Amount = item.Quantity, Price = item.SalePrice, //ProductImage = "http://" + Url.Request.RequestUri.Host + productService.GetProduct(item.ProductId).GetImage(ProductInfo.ImageSize.Size_100), Image = Core.MallIO.GetRomoteProductSizeImage(productService.GetProduct(item.ProductId).RelativePath, 1, (int)Mall.CommonModel.ImageSize.Size_100), color = item.Color, size = item.Size, version = item.Version, IsCanRefund = OrderApplication.CanRefund(order, itemrefstate, itemId: item.Id), ColorAlias = colorAlias, SizeAlias = sizeAlias, VersionAlias = versionAlias, SkuText = colorAlias + ":" + item.Color + ";" + sizeAlias + ":" + item.Size + ";" + versionAlias + ":" + item.Version, EnabledRefundAmount = item.EnabledRefundAmount, ActiveId = activeId, //活动Id ActiveType = activetype //活动类型(1代表限购,2代表团购,3代表商品预售,4代表限购预售,5代表团购预售) }); }) }; //取拼团订单状态 var fightGroupOrderInfo = ServiceProvider.Instance <IFightGroupService> .Create.GetFightGroupOrderStatusByOrderId(order.Id); #region 门店信息 var branchInfo = new ShopBranch(); if (order.ShopBranchId > 0) { branchInfo = ShopBranchApplication.GetShopBranchById(order.ShopBranchId); } else { branchInfo = null; } #endregion #region 虚拟订单信息 VirtualProductInfo virtualProductInfo = null; int validityType = 0; string startDate = string.Empty, endDate = string.Empty; List <dynamic> orderVerificationCodes = null; List <dynamic> virtualOrderItemInfos = null; bool isCanRefundVirtual = false; if (order.OrderType == OrderInfo.OrderTypes.Virtual) { var orderItemInfo = orderitems.FirstOrDefault(); if (orderItemInfo != null) { virtualProductInfo = ProductManagerApplication.GetVirtualProductInfoByProductId(orderItemInfo.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 codes = OrderApplication.GetOrderVerificationCodeInfosByOrderIds(new List <long>() { order.Id }); orderVerificationCodes = codes.Select(p => { return(new { VerificationCode = Regex.Replace(p.VerificationCode, @"(\d{4})", "$1 "), Status = p.Status, StatusText = p.Status.ToDescription(), QRCode = GetQRCode(p.VerificationCode) }); }).ToList <dynamic>(); var virtualItems = OrderApplication.GetVirtualOrderItemInfosByOrderId(order.Id); virtualOrderItemInfos = virtualItems.Select(p => { return(new { VirtualProductItemName = p.VirtualProductItemName, Content = ReplaceImage(p.Content, p.VirtualProductItemType), VirtualProductItemType = p.VirtualProductItemType }); }).ToList <dynamic>(); } } if (order.OrderStatus == Mall.Entities.OrderInfo.OrderOperateStatus.WaitVerification) { if (virtualProductInfo != null) { if (virtualProductInfo.SupportRefundType == 2) { isCanRefundVirtual = true; } else if (virtualProductInfo.SupportRefundType == 1) { if (virtualProductInfo.EndDate.Value > DateTime.Now) { isCanRefundVirtual = true; } } else if (virtualProductInfo.SupportRefundType == 3) { isCanRefundVirtual = false; } if (isCanRefundVirtual) { long num = orderVerificationCodes.Where(a => a.Status == OrderInfo.VerificationCodeStatus.WaitVerification).Count(); if (num > 0) { isCanRefundVirtual = true; } else { isCanRefundVirtual = false; } } } } #endregion #region 虚拟订单核销地址信息 string shipperAddress = string.Empty, shipperTelPhone = string.Empty; if (order.OrderType == OrderInfo.OrderTypes.Virtual) { if (order.ShopBranchId > 0 && branchInfo != null) { shipperAddress = RegionApplication.GetFullName(branchInfo.AddressId) + " " + branchInfo.AddressDetail; shipperTelPhone = branchInfo.ContactPhone; } else { var verificationShipper = ShopShippersApplication.GetDefaultVerificationShipper(order.ShopId); if (verificationShipper != null) { shipperAddress = RegionApplication.GetFullName(verificationShipper.RegionId) + " " + verificationShipper.Address; shipperTelPhone = verificationShipper.TelPhone; } } } #endregion var bonusmodel = ServiceProvider.Instance <IShopBonusService> .Create.GetGrantByUserOrder(orderId, CurrentUser.Id); bool hasBonus = bonusmodel != null ? true : false; string shareHref = ""; string shareTitle = ""; string shareDetail = ""; string shareImg = ""; if (hasBonus) { shareHref = "/m-weixin/ShopBonus/Index/" + ServiceProvider.Instance <IShopBonusService> .Create.GetGrantIdByOrderId(orderId); var bonus = ShopBonusApplication.GetBonus(bonusmodel.ShopBonusId); shareTitle = bonus.ShareTitle; shareDetail = bonus.ShareDetail; shareImg = MallIO.GetRomoteImagePath(bonus.ShareImg); } var orderModel = new { OrderId = order.Id, Status = (int)order.OrderStatus, StatusText = order.OrderStatus.ToDescription(), EnabledRefundAmount = order.OrderEnabledRefundAmount, OrderTotal = order.OrderTotalAmount, CapitalAmount = order.CapitalAmount, OrderAmount = order.ProductTotalAmount, DeductionPoints = 0, DeductionMoney = order.IntegralDiscount, //CouponAmount = couponAmout.ToString("F2"),//优惠劵金额 CouponAmount = order.DiscountAmount, //优惠劵金额 CouponName = couponName, //优惠劵名称 RefundAmount = order.RefundTotalAmount, Tax = order.Tax, AdjustedFreight = order.Freight, OrderDate = order.OrderDate.ToString("yyyy-MM-dd HH:mm:ss"), ItemStatus = 0, ItemStatusText = "", ShipTo = order.ShipTo, ShipToDate = order.ShippingDate.HasValue ? order.ShippingDate.Value.ToString("yyyy-MM-dd HH:mm:ss") : "", Cellphone = order.CellPhone, Address = order.DeliveryType == CommonModel.DeliveryType.SelfTake && branchInfo != null ? branchInfo.AddressFullName : (order.RegionFullName + " " + order.Address), FreightFreePromotionName = string.Empty, ReducedPromotionName = string.Empty, ReducedPromotionAmount = order.FullDiscount, SentTimesPointPromotionName = string.Empty, CanBackReturn = !string.IsNullOrWhiteSpace(order.PaymentTypeGateway), CanCashierReturn = false, PaymentType = order.PaymentType.ToDescription(), OrderPayAmount = order.OrderPayAmount,//订单需要第三方支付的金额 PaymentTypeName = PaymentApplication.GetPaymentTypeDescById(order.PaymentTypeGateway) ?? order.PaymentTypeName, PaymentTypeDesc = order.PaymentTypeDesc, Remark = string.IsNullOrEmpty(order.OrderRemarks) ? "" : order.OrderRemarks, //InvoiceTitle = order.InvoiceTitle, //Invoice = order.InvoiceType.ToDescription(), //InvoiceValue = (int)order.InvoiceType, //InvoiceContext = order.InvoiceContext, //InvoiceCode = order.InvoiceCode, ModeName = order.DeliveryType.ToDescription(), LogisticsData = expressTrace, TakeCode = order.PickupCode, LineItems = orderDetail.OrderItems, IsCanRefund = !(orderDetail.OrderItems.Any(e => e.IsCanRefund == true)) && OrderApplication.CanRefund(order, null, null), IsSelfTake = order.DeliveryType == Mall.CommonModel.DeliveryType.SelfTake ? 1 : 0, BranchInfo = branchInfo, DeliveryType = (int)order.DeliveryType, OrderInvoice = OrderApplication.GetOrderInvoiceInfo(order.Id), ValidityType = validityType, StartDate = startDate, EndDate = endDate, OrderVerificationCodes = orderVerificationCodes, VirtualOrderItemInfos = virtualOrderItemInfos, IsCanRefundVirtual = isCanRefundVirtual, ShipperAddress = shipperAddress, ShipperTelPhone = shipperTelPhone, OrderType = order.OrderType, JoinStatus = fightGroupOrderInfo == null ? -2 : fightGroupOrderInfo.JoinStatus, HasBonus = hasBonus, ShareHref = shareHref, ShareTitle = shareTitle, ShareDetail = shareDetail, ShareImg = shareImg, ShopName = order.ShopName }; return(Json(orderModel)); }
public object GetOrderDetail(long id) { CheckUserLogin(); long shopid = CurrentShopBranch.ShopId; long sbid = CurrentUser.ShopBranchId; var ordser = ServiceProvider.Instance <IOrderService> .Create; Entities.OrderInfo order = ordser.GetOrder(id); if (order == null || order.ShopBranchId != sbid) { throw new HimallApiException("错误的订单编号"); } var bonusService = ServiceProvider.Instance <IShopBonusService> .Create; var orderRefundService = ServiceProvider.Instance <IRefundService> .Create; var shopService = ServiceProvider.Instance <IShopService> .Create; var productService = ServiceProvider.Instance <IProductService> .Create; var vshop = ServiceProvider.Instance <IVShopService> .Create.GetVShopByShopId(order.ShopId); var orderitems = OrderApplication.GetOrderItems(order.Id); bool isCanApply = false; //获取订单商品项数据 var orderDetail = new { ShopName = shopService.GetShop(order.ShopId).ShopName, ShopId = order.ShopId, OrderItems = orderitems.Select(item => { var productinfo = productService.GetProduct(item.ProductId); if (order.OrderStatus == Entities.OrderInfo.OrderOperateStatus.WaitDelivery) { isCanApply = orderRefundService.CanApplyRefund(id, item.Id); } else { isCanApply = orderRefundService.CanApplyRefund(id, item.Id, false); } Entities.TypeInfo typeInfo = ServiceProvider.Instance <ITypeService> .Create.GetType(productinfo.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 (productinfo != null) { colorAlias = !string.IsNullOrWhiteSpace(productinfo.ColorAlias) ? productinfo.ColorAlias : colorAlias; sizeAlias = !string.IsNullOrWhiteSpace(productinfo.SizeAlias) ? productinfo.SizeAlias : sizeAlias; versionAlias = !string.IsNullOrWhiteSpace(productinfo.VersionAlias) ? productinfo.VersionAlias : versionAlias; } return(new { ItemId = item.Id, ProductId = item.ProductId, ProductName = item.ProductName, Count = item.Quantity, Price = item.SalePrice, //ProductImage = "http://" + Url.Request.RequestUri.Host + productService.GetProduct(item.ProductId).GetImage(ProductInfo.ImageSize.Size_100), ProductImage = Core.HimallIO.GetRomoteProductSizeImage(productService.GetProduct(item.ProductId).RelativePath, 1, (int)Himall.CommonModel.ImageSize.Size_100), color = item.Color, size = item.Size, version = item.Version, IsCanRefund = isCanApply, ColorAlias = colorAlias, SizeAlias = sizeAlias, VersionAlias = versionAlias }); }) }; VirtualProductInfo virtualProductInfo = null; List <dynamic> codes = null; List <dynamic> virtualItems = null; int validityType = 0; string startDate = string.Empty, endDate = string.Empty; if (order.OrderType == OrderInfo.OrderTypes.Virtual && orderDetail.OrderItems != null) { virtualProductInfo = ProductManagerApplication.GetVirtualProductInfoByProductId(orderDetail.OrderItems.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 verificationCodes = OrderApplication.GetOrderVerificationCodeInfosByOrderIds(new List <long>() { order.Id }); if (verificationCodes != null) { verificationCodes.ForEach(a => { if (a.Status == OrderInfo.VerificationCodeStatus.WaitVerification || a.Status == OrderInfo.VerificationCodeStatus.Refund) { a.VerificationCode = System.Text.RegularExpressions.Regex.Replace(a.VerificationCode, "(\\d{4})\\d{4}(\\d{4})", "$1****$2"); } a.VerificationCode = System.Text.RegularExpressions.Regex.Replace(a.VerificationCode, @"(\d{4})", "$1 "); }); } codes = verificationCodes.Select(p => { return(new { VerificationCode = p.VerificationCode, Status = p.Status, StatusText = p.Status.ToDescription() }); }).ToList <dynamic>(); var virtualOrderItems = OrderApplication.GetVirtualOrderItemInfosByOrderId(order.Id); virtualItems = virtualOrderItems.Select(p => { return(new { VirtualProductItemName = p.VirtualProductItemName, VirtualProductItemType = p.VirtualProductItemType, Content = ReplaceImage(p.Content, p.VirtualProductItemType) }); }).ToList <dynamic>(); } var orderModel = new { Id = order.Id, OrderType = order.OrderType, OrderTypeName = order.OrderType.ToDescription(), Status = order.OrderStatus.ToDescription(), ShipTo = order.ShipTo, Phone = order.CellPhone, Address = order.RegionFullName + " " + order.Address, HasExpressStatus = !string.IsNullOrWhiteSpace(order.ShipOrderNumber), ExpressCompanyName = order.ExpressCompanyName, Freight = order.Freight, Tax = order.Tax, IntegralDiscount = order.IntegralDiscount, RealTotalAmount = order.OrderTotalAmount - order.RefundTotalAmount, CapitalAmount = order.CapitalAmount, RefundTotalAmount = order.RefundTotalAmount, ProductTotalAmount = order.ProductTotalAmount, OrderDate = order.OrderDate.ToString("yyyy-MM-dd HH:mm:ss"), ShopName = order.ShopName, ShopBranchName = CurrentShopBranch.ShopBranchName, VShopId = vshop == null ? 0 : vshop.Id, commentCount = OrderApplication.GetOrderCommentCount(order.Id), ShopId = order.ShopId, orderStatus = (int)order.OrderStatus, //Invoice = order.InvoiceType.ToDescription(), //InvoiceValue = (int)order.InvoiceType, //InvoiceContext = order.InvoiceContext, //InvoiceTitle = order.InvoiceTitle, PaymentType = order.PaymentType.ToDescription(), PaymentTypeValue = (int)order.PaymentType, PaymentTypeDesc = order.PaymentTypeDesc, OrderPayAmount = order.OrderPayAmount, PaymentTypeName = PaymentApplication.GetPaymentTypeDescById(order.PaymentTypeGateway) ?? order.PaymentTypeName, FullDiscount = order.FullDiscount, DiscountAmount = order.DiscountAmount, OrderRemarks = order.OrderRemarks, DeliveryType = order.DeliveryType, //InvoiceCode = order.InvoiceCode, OrderInvoice = OrderApplication.GetOrderInvoiceInfo(order.Id) }; return(new { success = true, Order = orderModel, OrderItem = orderDetail.OrderItems, VerificationCodes = codes, VirtualOrderItems = virtualItems, StartDate = startDate, EndDate = endDate, ValidityType = validityType }); }
public object GetOrderDetail(long id) { CheckUserLogin(); OrderInfo order = ServiceProvider.Instance <IOrderService> .Create.GetOrder(id, CurrentUser.Id); var orderService = ServiceProvider.Instance <IOrderService> .Create; var bonusService = ServiceProvider.Instance <IShopBonusService> .Create; var orderRefundService = ServiceProvider.Instance <IRefundService> .Create; var bonusmodel = bonusService.GetGrantByUserOrder(id, CurrentUser.Id); bool hasBonus = bonusmodel != null ? true : false; string shareHref = ""; string shareTitle = ""; string shareDetail = ""; string shareImg = ""; if (hasBonus) { shareHref = CurrentUrlHelper.CurrentUrlNoPort() + "/m-weixin/shopbonus/index/" + bonusService.GetGrantIdByOrderId(id); var bonus = ShopBonusApplication.GetBonus(bonusmodel.ShopBonusId); shareTitle = bonus.ShareTitle; shareDetail = bonus.ShareDetail; shareImg = HimallIO.GetRomoteImagePath(bonus.ShareImg); } var vshop = ServiceProvider.Instance <IVShopService> .Create.GetVShopByShopId(order.ShopId); var customerServices = CustomerServiceApplication.GetMobileCustomerServiceAndMQ(order.ShopId); var shop = ShopApplication.GetShop(order.ShopId); var orderItems = OrderApplication.GetOrderItemsByOrderId(order.Id); var products = ProductManagerApplication.GetProducts(orderItems.Select(p => p.ProductId)); var refunds = OrderApplication.GetOrderRefundsByOrder(order.Id); //获取订单商品项数据 var orderDetail = new { ShopId = shop.Id, ShopName = shop.ShopName, OrderItems = orderItems.Select(item => { var product = products.FirstOrDefault(p => p.Id == item.ProductId); var typeInfo = TypeApplication.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; } var itemrefund = refunds.FirstOrDefault(d => d.OrderItemId == item.Id && d.RefundMode != OrderRefundInfo.OrderRefundMode.OrderRefund); int?itemrefstate = (itemrefund == null ? null : (int?)itemrefund.SellerAuditStatus); itemrefstate = (itemrefstate > 4 ? (int?)itemrefund.ManagerConfirmStatus : itemrefstate); var IsCanRefund = OrderApplication.CanRefund(order, itemrefstate, itemId: item.Id); return(new { ItemId = item.Id, ProductId = item.ProductId, ProductName = item.ProductName, Count = item.Quantity, Price = item.SalePrice, ProductImage = Core.HimallIO.GetRomoteProductSizeImage(product.RelativePath, 1, (int)Himall.CommonModel.ImageSize.Size_100), color = item.Color, size = item.Size, version = item.Version, IsCanRefund = IsCanRefund, ColorAlias = colorAlias, SizeAlias = sizeAlias, VersionAlias = versionAlias, EnabledRefundAmount = item.EnabledRefundAmount, OrderRefundId = (itemrefund == null ? 0 : itemrefund.Id), RefundStats = itemrefstate }); }) }; //取拼团订单状态 var fightGroupOrderInfo = ServiceProvider.Instance <IFightGroupService> .Create.GetFightGroupOrderStatusByOrderId(order.Id); var _ordrefobj = orderRefundService.GetOrderRefundByOrderId(order.Id) ?? new OrderRefundInfo { Id = 0 }; if (order.OrderStatus != OrderInfo.OrderOperateStatus.WaitDelivery && order.OrderStatus != OrderInfo.OrderOperateStatus.WaitSelfPickUp) { _ordrefobj = new OrderRefundInfo { Id = 0 }; } int?ordrefstate = (_ordrefobj == null ? null : (int?)_ordrefobj.SellerAuditStatus); ordrefstate = (ordrefstate > 4 ? (int?)_ordrefobj.ManagerConfirmStatus : ordrefstate); var hasAppendComment = ServiceProvider.Instance <ICommentService> .Create.HasAppendComment(orderItems.FirstOrDefault().Id); var orderModel = new { Id = order.Id, OrderType = order.OrderType, OrderTypeName = order.OrderType.ToDescription(), Status = order.OrderStatus.ToDescription(), JoinStatus = fightGroupOrderInfo == null ? -2 : fightGroupOrderInfo.JoinStatus, ShipTo = order.ShipTo, Phone = order.CellPhone, Address = order.RegionFullName + " " + order.Address, HasExpressStatus = !string.IsNullOrWhiteSpace(order.ShipOrderNumber), ExpressCompanyName = order.ExpressCompanyName, Freight = order.Freight, Tax = order.Tax, IntegralDiscount = order.IntegralDiscount, RealTotalAmount = order.OrderTotalAmount, CapitalAmount = order.CapitalAmount, RefundTotalAmount = order.RefundTotalAmount, ProductTotalAmount = order.ProductTotalAmount, OrderPayAmount = order.OrderPayAmount,//订单需要第三方支付的金额 PaymentTypeName = PaymentApplication.GetPaymentTypeDescById(order.PaymentTypeGateway) ?? order.PaymentTypeName, PaymentTypeDesc = order.PaymentTypeDesc, OrderDate = order.OrderDate.ToString("yyyy-MM-dd HH:mm:ss"), ShopName = order.ShopName, VShopId = vshop == null ? 0 : vshop.Id, commentCount = OrderApplication.GetOrderCommentCount(order.Id), ShopId = order.ShopId, orderStatus = (int)order.OrderStatus, //Invoice = order.InvoiceType.ToDescription(), //InvoiceValue = (int)order.InvoiceType, //InvoiceContext = order.InvoiceContext, //InvoiceTitle = order.InvoiceTitle, //InvoiceCode = order.InvoiceCode, PaymentType = order.PaymentType.ToDescription(), PaymentTypeValue = (int)order.PaymentType, FullDiscount = order.FullDiscount, DiscountAmount = order.DiscountAmount, OrderRemarks = string.IsNullOrEmpty(order.OrderRemarks) ? "" : order.OrderRemarks, HasBonus = hasBonus, ShareHref = shareHref, ShareTitle = shareTitle, ShareDetail = shareDetail, ShareImg = shareImg, IsCanRefund = !(orderDetail.OrderItems.Any(e => e.IsCanRefund == true)) && OrderApplication.CanRefund(order, ordrefstate, null), RefundStats = ordrefstate, OrderRefundId = _ordrefobj.Id > 0 ? _ordrefobj.Id : 0, EnabledRefundAmount = order.OrderEnabledRefundAmount, HasAppendComment = hasAppendComment, SelfTake = order.DeliveryType == Himall.CommonModel.DeliveryType.SelfTake ? 1 : 0, OrderInvoice = OrderApplication.GetOrderInvoiceInfo(order.Id) }; #region 门店配送信息 Himall.DTO.ShopBranch storeInfo = null; if (order.ShopBranchId > 0) { storeInfo = ShopBranchApplication.GetShopBranchById(order.ShopBranchId); } #endregion #region 虚拟订单信息 VirtualProductInfo virtualProductInfo = null; int validityType = 0; string startDate = string.Empty, endDate = string.Empty; List <dynamic> orderVerificationCodes = null; List <dynamic> virtualOrderItemInfos = null; bool isCanRefundVirtual = false; if (order.OrderType == OrderInfo.OrderTypes.Virtual) { var orderItemInfo = orderItems.FirstOrDefault(); if (orderItemInfo != null) { virtualProductInfo = ProductManagerApplication.GetVirtualProductInfoByProductId(orderItemInfo.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 codes = OrderApplication.GetOrderVerificationCodeInfosByOrderIds(new List <long>() { order.Id }); orderVerificationCodes = codes.Select(p => { return(new { VerificationCode = Regex.Replace(p.VerificationCode, @"(\d{4})", "$1 "), Status = p.Status, StatusText = p.Status.ToDescription(), QRCode = GetQRCode(p.VerificationCode) }); }).ToList <dynamic>(); var virtualItems = OrderApplication.GetVirtualOrderItemInfosByOrderId(order.Id); virtualOrderItemInfos = virtualItems.Select(p => { return(new { VirtualProductItemName = p.VirtualProductItemName, Content = ReplaceImage(p.Content, p.VirtualProductItemType), VirtualProductItemType = p.VirtualProductItemType }); }).ToList <dynamic>(); } } if (order.OrderStatus == Himall.Entities.OrderInfo.OrderOperateStatus.WaitVerification) { if (virtualProductInfo != null) { if (virtualProductInfo.SupportRefundType == 2) { isCanRefundVirtual = true; } else if (virtualProductInfo.SupportRefundType == 1) { if (virtualProductInfo.EndDate.Value > DateTime.Now) { isCanRefundVirtual = true; } } else if (virtualProductInfo.SupportRefundType == 3) { isCanRefundVirtual = false; } if (isCanRefundVirtual) { long num = orderVerificationCodes.Where(a => a.Status == OrderInfo.VerificationCodeStatus.WaitVerification).Count(); if (num > 0) { isCanRefundVirtual = true; } else { isCanRefundVirtual = false; } } } } #endregion #region 虚拟订单核销地址信息 string shipperAddress = string.Empty, shipperTelPhone = string.Empty; if (order.OrderType == OrderInfo.OrderTypes.Virtual) { if (order.ShopBranchId > 0 && storeInfo != null) { shipperAddress = RegionApplication.GetFullName(storeInfo.AddressId) + " " + storeInfo.AddressDetail; shipperTelPhone = storeInfo.ContactPhone; } else { var verificationShipper = ShopShippersApplication.GetDefaultVerificationShipper(order.ShopId); if (verificationShipper != null) { shipperAddress = RegionApplication.GetFullName(verificationShipper.RegionId) + " " + verificationShipper.Address; shipperTelPhone = verificationShipper.TelPhone; } } } #endregion return(new { success = true, Order = orderModel, OrderItem = orderDetail.OrderItems, StoreInfo = storeInfo, CustomerServices = customerServices, ValidityType = validityType, StartDate = startDate, EndDate = endDate, OrderVerificationCodes = orderVerificationCodes, VirtualOrderItemInfos = virtualOrderItemInfos, IsCanRefundVirtual = isCanRefundVirtual, ShipperAddress = shipperAddress, ShipperTelPhone = shipperTelPhone }); }