Esempio n. 1
0
        public JsonResult RefundApply(OrderRefundInfo info)
        {
            if (info.ReasonDetail != null && info.ReasonDetail.Length > 1000)
            {
                throw new Mall.Core.MallException("退款说明不能超过1000字符");
            }
            var order = _iOrderService.GetOrder(info.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 && _iOrderService.IsRefundTimeOut(info.OrderId))
            {
                throw new Mall.Core.MallException("订单已超过售后期");
            }
            if (order.OrderStatus == Entities.OrderInfo.OrderOperateStatus.WaitDelivery || order.OrderStatus == Entities.OrderInfo.OrderOperateStatus.WaitSelfPickUp)
            {
                info.RefundMode     = OrderRefundInfo.OrderRefundMode.OrderRefund;
                info.ReturnQuantity = 0;
            }
            if (info.RefundMode != OrderRefundInfo.OrderRefundMode.OrderRefund && info.Id == 0)
            {
                var _refobj = OrderApplication.GetOrderRefunds(new long[] { info.OrderItemId }).FirstOrDefault(d => d.RefundMode != OrderRefundInfo.OrderRefundMode.OrderRefund);
                if (_refobj != null)
                {
                    info.Id = _refobj.Id;
                }
            }
            if (info.RefundType == 1)
            {
                info.ReturnQuantity = 0;
                info.IsReturn       = false;
            }
            if (order.OrderType != OrderInfo.OrderTypes.Virtual && info.ReturnQuantity < 0)
            {
                throw new MallException("错误的退货数量");
            }
            var orderitem = _iOrderService.GetOrderItem(info.OrderItemId);

            if (orderitem == null && info.RefundMode != OrderRefundInfo.OrderRefundMode.OrderRefund)
            {
                throw new Mall.Core.MallException("该订单条目已删除或不属于该用户");
            }

            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 Mall.Core.MallException("错误的订单退款申请,订单状态有误");
                    }
                    info.IsReturn       = false;
                    info.ReturnQuantity = 0;
                    if (info.Amount > order.OrderEnabledRefundAmount)
                    {
                        throw new Mall.Core.MallException("退款金额不能超过订单的实际支付金额");
                    }
                }
                else
                {
                    if (info.Amount > (orderitem.EnabledRefundAmount - orderitem.RefundPrice))
                    {
                        throw new Mall.Core.MallException("退款金额不能超过订单的可退金额");
                    }
                    if (info.ReturnQuantity > (orderitem.Quantity - orderitem.ReturnQuantity))
                    {
                        throw new Mall.Core.MallException("退货数量不可以超出可退数量");
                    }
                }
            }
            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 Mall.Core.MallException("错误的退货数量");
            }
            if (info.Amount <= 0)
            {
                throw new Mall.Core.MallException("错误的退款金额");
            }
            info.ShopId       = order.ShopId;
            info.ShopName     = order.ShopName;
            info.UserId       = CurrentUser.Id;
            info.Applicant    = CurrentUser.UserName;
            info.ApplyDate    = DateTime.Now;
            info.ReasonDetail = HttpUtility.HtmlEncode(info.ReasonDetail);
            info.Reason       = HTMLEncode(info.Reason.Replace("'", "‘").Replace("\"", "”"));
            if (!info.IsWxUpload)
            {
                info.CertPic1 = MoveImages(info.CertPic1, CurrentUser.Id, info.OrderItemId);
                info.CertPic2 = MoveImages(info.CertPic2, CurrentUser.Id, info.OrderItemId);
                info.CertPic3 = MoveImages(info.CertPic3, CurrentUser.Id, info.OrderItemId);
            }
            else
            {
                info.CertPic1 = DownloadWxImage(info.CertPic1, CurrentUser.Id, info.OrderItemId);
                info.CertPic2 = DownloadWxImage(info.CertPic2, CurrentUser.Id, info.OrderItemId);
                info.CertPic3 = DownloadWxImage(info.CertPic3, CurrentUser.Id, info.OrderItemId);
            }
            if (order.OrderType == OrderInfo.OrderTypes.Virtual)
            {
                if (string.IsNullOrWhiteSpace(info.VerificationCodeIds))
                {
                    throw new Mall.Core.MallException("虚拟订单退款核销码不能为空");
                }

                //检测核销码都为正确的
                var codeList = info.VerificationCodeIds.Split(',').ToList();
                var codes    = OrderApplication.GetOrderVerificationCodeInfoByCodes(codeList);
                if (codes.Count != codeList.Count)
                {
                    throw new Mall.Core.MallException("包含无效的核销码");
                }
                foreach (var item in codes)
                {
                    if (item.Status != OrderInfo.VerificationCodeStatus.WaitVerification)
                    {
                        throw new Mall.Core.MallException("包含已申请售后的核销码");
                    }
                }
                info.ReturnQuantity = codes.Count;
            }
            //info.RefundAccount = HTMLEncode(info.RefundAccount.Replace("'", "‘").Replace("\"", "”"));
            if (order.OrderType != OrderInfo.OrderTypes.Virtual)
            {
                if (info.Id > 0)
                {
                    _iRefundService.ActiveRefund(info);
                }
                else
                {
                    _iRefundService.AddOrderRefund(info);
                }
            }
            else
            {
                _iRefundService.AddOrderRefund(info);
                #region 处理退款
                try
                {
                    //虚拟订单自动退款,异常不提示用户,进入平台待审核
                    //获取异步通知地址
                    string notifyurl = CurrentUrlHelper.CurrentUrlNoPort() + "/Pay/RefundNotify/{0}";
                    var    result    = _iRefundService.ConfirmRefund(info.Id, "虚拟订单申请售后自动退款", "", notifyurl);
                }
                catch (MallException ex)
                {
                    Log.Error("虚拟商品自动退异常", ex);
                }
                #endregion
            }
            return(SuccessResult <dynamic>(msg: "提交成功", data: info.Id));
        }
        public JsonResult RefundApply(OrderRefundInfo info)
        {
            if (info.ReasonDetail != null && info.ReasonDetail.Length > 1000)
            {
                throw new Himall.Core.HimallException("退款原因不能超过1000字符");
            }
            var order = _iOrderService.GetOrder(info.OrderId, CurrentUser.Id);

            if (order == null)
            {
                throw new Himall.Core.HimallException("该预约单已删除或不属于该用户");
            }
            if ((int)order.OrderStatus < 2)
            {
                throw new Himall.Core.HimallException("错误的售后申请,预约单状态有误");
            }
            //售后时间限制
            if (_iOrderService.IsRefundTimeOut(info.OrderId))
            {
                throw new Himall.Core.HimallException("预约单已超过售后期");
            }
            if (order.OrderStatus == OrderInfo.OrderOperateStatus.WaitDelivery || order.OrderStatus == OrderInfo.OrderOperateStatus.WaitSelfPickUp)
            {
                info.RefundMode     = OrderRefundInfo.OrderRefundMode.OrderRefund;
                info.ReturnQuantity = 0;
            }
            if (info.RefundType == 1)
            {
                info.ReturnQuantity = 0;
                info.IsReturn       = false;
            }
            if (info.ReturnQuantity == null || info.ReturnQuantity < 0)
            {
                throw new Himall.Core.HimallException("错误的退货数量");
            }
            var orderitem = order.OrderItemInfo.FirstOrDefault(a => a.Id == info.OrderItemId);

            if (orderitem == null && info.RefundMode != OrderRefundInfo.OrderRefundMode.OrderRefund)
            {
                throw new Himall.Core.HimallException("该预约单条目已删除或不属于该用户");
            }
            if (info.RefundMode == OrderRefundInfo.OrderRefundMode.OrderRefund)
            {
                if (order.OrderStatus != OrderInfo.OrderOperateStatus.WaitDelivery && order.OrderStatus != 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 (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.ReasonDetail = HttpUtility.HtmlEncode(info.ReasonDetail);
            info.Reason       = HTMLEncode(info.Reason.Replace("'", "‘").Replace("\"", "”"));
            info.CertPic1     = MoveImages(info.CertPic1, CurrentUser.Id, info.OrderItemId);
            info.CertPic2     = MoveImages(info.CertPic2, CurrentUser.Id, info.OrderItemId);
            info.CertPic3     = MoveImages(info.CertPic3, CurrentUser.Id, info.OrderItemId);
            //info.RefundAccount = HTMLEncode(info.RefundAccount.Replace("'", "‘").Replace("\"", "”"));
            if (info.Id > 0)
            {
                _iRefundService.ActiveRefund(info);
            }
            else
            {
                _iRefundService.AddOrderRefund(info);
            }
            return(Json(new { success = true, msg = "提交成功", id = info.Id }));
        }
Esempio n. 3
0
 /// <summary>
 /// 添加一个退款申请
 /// </summary>
 /// <param name="info"></param>
 public static void AddOrderRefund(OrderRefundInfo info)
 {
     _iRefundService.AddOrderRefund(info);
 }