示例#1
0
        public JsonResult RefundApply(OrderRefundInfo info)
        {
            var order = _iOrderService.GetOrder(info.OrderId, CurrentUser.Id);

            if (order == null)
            {
                throw new Mall.Core.MallException("该订单已删除或不属于该用户");
            }
            if (info.RefundType == 1)
            {
                info.ReturnQuantity = 0;
                info.IsReturn       = false;
            }
            if (order.OrderType != OrderInfo.OrderTypes.Virtual)
            {
                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 Mall.Core.MallException("错误的退货数量");
                }
            }
            if (info.Amount <= 0)
            {
                throw new Mall.Core.MallException("错误的退款金额");
            }
            if (info.ReasonDetail != null && info.ReasonDetail.Length > 1000)
            {
                throw new Mall.Core.MallException("退款说明不能超过1000字符");
            }
            // info.ReasonDetail=
            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);

            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("\"", "”"));
            Result result = new Result()
            {
                success = true, data = info.Id, msg = "提交成功"
            };

            if (order.OrderType != OrderInfo.OrderTypes.Virtual)
            {
                if (info.Id > 0)
                {
                    _iRefundService.ActiveRefund(info);
                }
                else
                {
                    var status = RefundApplication.CanApplyRefund(info.OrderId, info.OrderItemId, info.OrderItemId == 0 ? true : false);
                    if (!status)
                    {
                        result.success = false;
                        result.status  = 2;
                        result.msg     = "您已申请过售后,不可重复申请";
                    }
                    else
                    {
                        RefundApplication.AddOrderRefund(info);
                    }
                    //TODO:FG 查询逻辑
                    //取退款ID
                    var refundInfos = RefundApplication.GetOrderRefunds(new RefundQuery()
                    {
                        OrderId = info.OrderId, PageNo = 1, PageSize = int.MaxValue
                    }).Models;
                    if (refundInfos.Count > 0)
                    {
                        if (info.OrderItemId != 0)
                        {
                            var refund = refundInfos.FirstOrDefault(e => e.OrderItemId == info.OrderItemId);
                            result.data = refund.Id;
                        }
                        else
                        {
                            var refund = refundInfos.FirstOrDefault();
                            result.data = refund.Id;
                        }
                    }
                }
            }
            else
            {
                RefundApplication.AddOrderRefund(info);
                //取退款ID
                result.data = info.Id;
                #region 处理退款
                //虚拟订单自动退款,异常不提示用户,进入平台待审核
                try
                {
                    //获取异步通知地址
                    string notifyurl    = CurrentUrlHelper.CurrentUrlNoPort() + "/Pay/RefundNotify/{0}";
                    var    refundResult = _iRefundService.ConfirmRefund(info.Id, "虚拟订单申请售后自动退款", "", notifyurl);
                }
                catch (MallException ex)
                {
                    Log.Error("虚拟商品自动退异常", ex);
                }
                #endregion
            }
            return(Json(result));
        }
        /// <summary>
        /// 门店核销订单
        /// </summary>
        /// <param name="pickcode"></param>
        /// <returns></returns>
        public object GetShopBranchOrderConfirm(string pickcode)
        {
            CheckUserLogin();

            if (string.IsNullOrWhiteSpace(pickcode))
            {
                return new { success = false, msg = "该核销码无效" }
            }
            ;

            var codes = pickcode.Split(',').ToList();
            var list  = OrderApplication.GetOrderVerificationCodeInfoByCodes(codes);

            if (list != null && list.Count > 0)
            {
                var orderCount = list.Select(a => a.OrderId).Distinct().Count();

                if (orderCount > 1)
                {
                    return(new { success = false, msg = "非同一个订单的核销码无法一起核销" });
                }

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

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

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


                var waitVerificationNum = list.Where(a => a.Status == OrderInfo.VerificationCodeStatus.WaitVerification).Count();
                if (waitVerificationNum != list.Count)
                {
                    return(new { success = false, msg = "包含非待消费的核销码" });
                }

                var orderItem = Application.OrderApplication.GetOrderItemsByOrderId(order.Id).FirstOrDefault();
                if (orderItem != null && orderItem.EffectiveDate.HasValue)
                {
                    if (DateTime.Now < orderItem.EffectiveDate.Value)
                    {
                        return new { success = false, msg = "该核销码暂时不能核销,请留意生效时间!" }
                    }
                    ;
                }
                var verificationTime = DateTime.Now;
                OrderApplication.UpdateOrderVerificationCodeStatusByCodes(list.Select(a => a.VerificationCode).ToList(), order.Id, OrderInfo.VerificationCodeStatus.AlreadyVerification, DateTime.Now, this.CurrentShopBranch.UserName);
                OrderApplication.AddVerificationRecord(new VerificationRecordInfo()
                {
                    OrderId             = order.Id,
                    VerificationCodeIds = "," + string.Join(",", list.Select(a => a.VerificationCode)) + ",",
                    VerificationTime    = verificationTime,
                    VerificationUser    = this.CurrentShopBranch.UserName
                });
                return(new { success = true, msg = "已核销", verificationCodes = string.Join(",", list.Select(a => a.VerificationCode)), verificationTime = verificationTime.ToString("yyyy-MM-dd HH:mm:ss"), verificationUser = this.CurrentShopBranch.UserName });
            }
            else
            {
                var order = Application.OrderApplication.GetOrderByPickCode(pickcode);
                if (order == null)
                {
                    return new { success = false, msg = "该提货码无效" }
                }
                ;
                if (order.ShopBranchId != CurrentShopBranch.Id)
                {
                    return new { success = false, msg = "非本门店提货码,请买家核对提货信息" }
                }
                ;
                if (order.OrderStatus == Entities.OrderInfo.OrderOperateStatus.Finish && order.DeliveryType == CommonModel.DeliveryType.SelfTake)
                {
                    return new { success = false, msg = "该提货码于" + order.FinishDate.ToString() + "已核销" }
                }
                ;
                if (order.OrderStatus != Entities.OrderInfo.OrderOperateStatus.WaitSelfPickUp)
                {
                    return new { success = false, msg = "只有待自提的订单才能进行核销" }
                }
                ;

                Application.OrderApplication.ShopBranchConfirmOrder(order.Id, CurrentShopBranch.Id, this.CurrentUser.UserName);
                return(new { success = true, msg = "已核销" });
            }
        }
示例#3
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));
        }
        /// <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 });
            }
        }