/// <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 Himall.Core.HimallException("该预约单已删除或不属于该用户"); } if ((int)order.OrderStatus < 2) { throw new Himall.Core.HimallException("错误的售后申请,预约单状态有误"); } if (itemId == null && order.OrderStatus != OrderInfo.OrderOperateStatus.WaitDelivery && order.OrderStatus != OrderInfo.OrderOperateStatus.WaitSelfPickUp) { throw new Himall.Core.HimallException("错误的预约单退款申请,预约单状态有误"); } //售后时间限制 if (_iOrderService.IsRefundTimeOut(orderid)) { throw new Himall.Core.HimallException("预约单已超过售后期"); } //计算可退金额 预留 _iOrderService.CalculateOrderItemRefund(orderid); OrderItemInfo item = new OrderItemInfo(); model.MaxRefundGoodsNumber = 0; model.MaxRefundAmount = order.OrderEnabledRefundAmount; if (itemId == null) { model.OrderItems = order.OrderItemInfo.ToList(); if (model.OrderItems.Count == 1) { item = model.OrderItems.FirstOrDefault(); } } else { item = order.OrderItemInfo.Where(a => a.Id == itemId).FirstOrDefault(); model.OrderItems.Add(item); model.MaxRefundGoodsNumber = item.Quantity - item.ReturnQuantity; model.MaxRefundAmount = item.EnabledRefundAmount - item.RefundPrice; } foreach (var orderItem in model.OrderItems) { ProductTypeInfo typeInfo = _iTypeService.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; } if (!model.MaxRefundAmount.HasValue) { model.MaxRefundAmount = 0; } bool isCanApply = false; var refundser = _iRefundService; OrderRefundInfo refunddata; if (order.OrderStatus == OrderInfo.OrderOperateStatus.WaitDelivery) { isCanApply = refundser.CanApplyRefund(orderid, item.Id); } else { isCanApply = refundser.CanApplyRefund(orderid, item.Id, false); } if (!refundid.HasValue) { if (!isCanApply) { var orderRefunds = OrderApplication.GetOrderRefunds(new long[] { item.Id }); if (orderRefunds.Count == 1) { Response.Redirect("/OrderRefund/Detail/" + orderRefunds[0].Id); } throw new Himall.Core.HimallException("您已申请过售后,不可重复申请"); } model.ContactPerson = CurrentUser.RealName; model.ContactCellPhone = CurrentUser.CellPhone; model.OrderItemId = itemId; if (!model.OrderItemId.HasValue) { model.IsOrderAllRefund = true; model.RefundMode = OrderRefundInfo.OrderRefundMode.OrderRefund; } } else { refunddata = refundser.GetOrderRefund(refundid.Value, CurrentUser.Id); if (refunddata == null) { throw new Himall.Core.HimallException("错误的售后数据"); } if (refunddata.SellerAuditStatus != OrderRefundInfo.OrderRefundAuditStatus.UnAudit) { throw new Himall.Core.HimallException("错误的售后状态,不可激活"); } model.ContactPerson = refunddata.ContactPerson; model.ContactCellPhone = refunddata.ContactCellPhone; model.OrderItemId = refunddata.OrderItemId; model.IsOrderAllRefund = (refunddata.RefundMode == 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.Enum.DeliveryType.SelfTake) { var shopBranch = ShopBranchApplication.GetShopBranchById(order.ShopBranchId.Value); model.ReturnGoodsAddress = RegionApplication.GetFullName(shopBranch.AddressId); model.ReturnGoodsAddress += " " + shopBranch.AddressDetail; model.ReturnGoodsAddress += " " + shopBranch.ContactPhone; } return(View(model)); }
/// <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)); }
public ApiResult ApplyRefund([FromBody] RefundApplyModel apply) { Argument.ThrowIfNullOrEmpty(apply.Reason, "退款原因"); if (apply.RefundAmount <= 0) { throw new WebApiInnerException("0009", "退款金额不能小于等于0"); } if (apply.OrderId.Equals(Guid.Empty)) { throw new WebApiInnerException("0001", "订单Id不合法"); } var order = _currencyService.GetSingleById <Order>(apply.OrderId); if (order == null) { throw new WebApiInnerException("0002", "订单不存在"); } if (order.OrderStatus == OrderStatus.WaitingForDelivery && apply.RefundType == RefundType.RefundAndReturn) { throw new WebApiInnerException("0003", "订单未发货,不能申请退款并退货"); } if (order.OrderStatus != OrderStatus.WaitingForDelivery && order.OrderStatus != OrderStatus.WaitingForReceiving) { throw new WebApiInnerException("0004", "当前订单状态不能申请退款"); } if (!order.MemberId.Equals(AuthorizedUser.Id)) { throw new WebApiInnerException("0005", "只能对自己的订单申请退款"); } var singleGoods = _currencyService.GetSingleByConditon <OrderGoods>(x => x.OrderId == apply.OrderId && x.SingleGoodsId == apply.SingleGoodsId); if (singleGoods == null) { throw new WebApiInnerException("0006", "商品不存在"); } if (singleGoods.RefundStatus != OrderRefundStatus.NoRefund) { throw new WebApiInnerException("0007", "已申请退款不可重复申请"); } var maxRefundAmount = singleGoods.Price * singleGoods.Quantity; if (order.IntegralMoney > 0) { maxRefundAmount -= order.IntegralMoney * (singleGoods.Price * singleGoods.Quantity / order.GoodsAmount); } if (apply.RefundAmount > maxRefundAmount) { throw new WebApiInnerException("0008", "退款金额不能大于单品实付金额"); } var model = new OrderRefund() { OrderId = apply.OrderId, SingleGoodsId = apply.SingleGoodsId, RefundType = apply.RefundType, RefundAmount = apply.RefundAmount, Reason = apply.Reason }; _refundService.CreateOrderRefund(model); ApiResult result = new ApiResult(); return(result); }