/// <summary>
        /// 根据提货码取订单
        /// </summary>
        /// <param name="pickcode"></param>
        /// <returns></returns>
        public object GetShopBranchOrder(string pickcode)
        {
            CheckUserLogin();
            var order = Application.OrderApplication.GetOrderByPickCode(pickcode);

            if (order == null)
            {
                return(Json(new { success = false, msg = "该提货码无效" }));
            }
            if (order.ShopBranchId.Value != CurrentShopBranch.Id)
            {
                return(Json(new { success = false, msg = "非本门店提货码,请买家核对提货信息" }));
            }
            if (order.OrderStatus == Himall.Model.OrderInfo.OrderOperateStatus.Finish && order.DeliveryType == CommonModel.Enum.DeliveryType.SelfTake)
            {
                return(Json(new { success = false, msg = "该提货码于" + order.FinishDate.ToString() + "已核销" }));
            }

            var orderItem = Application.OrderApplication.GetOrderItemsByOrderId(order.Id);

            foreach (var item in orderItem)
            {
                item.ThumbnailsUrl = Core.HimallIO.GetRomoteProductSizeImage(item.ThumbnailsUrl, 1, (int)Himall.CommonModel.ImageSize.Size_100);
                ProductTypeInfo typeInfo = ServiceProvider.Instance <ITypeService> .Create.GetTypeByProductId(item.ProductId);

                item.ColorAlias   = (typeInfo == null || string.IsNullOrEmpty(typeInfo.ColorAlias)) ? SpecificationType.Color.ToDescription() : typeInfo.ColorAlias;
                item.SizeAlias    = (typeInfo == null || string.IsNullOrEmpty(typeInfo.SizeAlias)) ? SpecificationType.Size.ToDescription() : typeInfo.SizeAlias;
                item.VersionAlias = (typeInfo == null || string.IsNullOrEmpty(typeInfo.VersionAlias)) ? SpecificationType.Version.ToDescription() : typeInfo.VersionAlias;
            }
            //退款状态
            var refundobjs = OrderApplication.GetOrderRefunds(orderItem.Select(e => e.Id));
            //小于4表示商家未确认;与平台未审核,都算退款、退货中
            var refundProcessing = refundobjs.Where(e => (int)e.SellerAuditStatus < 4 || e.ManagerConfirmStatus == OrderRefundInfo.OrderRefundConfirmStatus.UnConfirm);

            if (refundProcessing.Count() > 0)
            {
                order.RefundStats = 1;
            }

            return(Json(new { success = true, order = order, orderItem = orderItem }));
        }
Пример #2
0
        public object GetOrders(int?status, int pageIndex, int pageSize = 8)
        {
            CheckUserLogin();
            IShopAppletService iShopAppletService = ServiceProvider.Instance <IShopAppletService> .Create;
            var orderService = ServiceProvider.Instance <IOrderService> .Create;
            var allOrders    = orderService.GetTopOrders(int.MaxValue, CurrentUser.Id);

            //待评价
            var queryModelAll = new OrderQuery()
            {
                Status    = OrderInfo.OrderOperateStatus.Finish,
                UserId    = CurrentUser.Id,
                PageSize  = int.MaxValue,
                PageNo    = 1,
                Commented = false
            };
            var allOrderCounts     = allOrders.Count();
            var waitingForComments = orderService.GetOrders <OrderInfo>(queryModelAll).Total;
            var waitingForRecieve  = allOrders.Count(item => item.OrderStatus == OrderInfo.OrderOperateStatus.WaitReceiving); //获取待收货订单数
            var waitingForPay      = allOrders.Count(item => item.OrderStatus == OrderInfo.OrderOperateStatus.WaitPay);       //获取待支付订单数

            if (status.HasValue && status == 0)
            {
                status = null;
            }
            var queryModel = new OrderQuery()
            {
                Status   = (OrderInfo.OrderOperateStatus?)status,
                UserId   = CurrentUser.Id,
                PageSize = pageSize,
                PageNo   = pageIndex
            };

            if (queryModel.Status.HasValue && queryModel.Status.Value == OrderInfo.OrderOperateStatus.WaitReceiving)
            {
                if (queryModel.MoreStatus == null)
                {
                    queryModel.MoreStatus = new List <OrderInfo.OrderOperateStatus>()
                    {
                    };
                }
                queryModel.MoreStatus.Add(OrderInfo.OrderOperateStatus.WaitSelfPickUp);
            }
            if (status.GetValueOrDefault() == (int)OrderInfo.OrderOperateStatus.Finish)
            {
                queryModel.Commented = false;//只查询未评价的订单
            }
            ObsoletePageModel <OrderInfo> orders = orderService.GetOrders <OrderInfo>(queryModel);
            var productService     = ServiceProvider.Instance <IProductService> .Create;
            var vshopService       = ServiceProvider.Instance <IVShopService> .Create;
            var orderRefundService = ServiceProvider.Instance <IRefundService> .Create;
            var orderItems         = OrderApplication.GetOrderItemsByOrderId(orders.Models.Select(p => p.Id));
            var orderRefunds       = OrderApplication.GetOrderRefunds(orderItems.Select(p => p.Id));
            var result             = orders.Models.ToArray().Select(item =>
            {
                if (item.OrderStatus >= OrderInfo.OrderOperateStatus.WaitDelivery)
                {
                    orderService.CalculateOrderItemRefund(item.Id);
                }
                var vshop      = vshopService.GetVShopByShopId(item.ShopId);
                var _ordrefobj = orderRefundService.GetOrderRefundByOrderId(item.Id) ?? new OrderRefundInfo {
                    Id = 0
                };
                if (item.OrderStatus != OrderInfo.OrderOperateStatus.WaitDelivery && item.OrderStatus != OrderInfo.OrderOperateStatus.WaitSelfPickUp)
                {
                    _ordrefobj = new OrderRefundInfo {
                        Id = 0
                    };
                }
                int?ordrefstate = (_ordrefobj == null ? null : (int?)_ordrefobj.SellerAuditStatus);
                ordrefstate     = (ordrefstate > 4 ? (int?)_ordrefobj.ManagerConfirmStatus : ordrefstate);
                //参照PC端会员中心的状态描述信息
                string statusText = item.OrderStatus.ToDescription();
                if (item.OrderStatus == OrderInfo.OrderOperateStatus.WaitDelivery || item.OrderStatus == OrderInfo.OrderOperateStatus.WaitSelfPickUp)
                {
                    if (ordrefstate.HasValue && ordrefstate != 0 && ordrefstate != 4)
                    {
                        statusText = "退款中";
                    }
                }
                var shopInfo = ServiceProvider.Instance <IShopService> .Create.GetShop(item.ShopId);
                if (shopInfo != null)
                {
                    shopInfo.Logo = Himall.Core.HimallIO.GetRomoteImagePath(shopInfo.Logo);
                    //是否可退货、退款
                    bool IsShowReturn = (item.OrderStatus == Himall.Model.OrderInfo.OrderOperateStatus.WaitDelivery || item.OrderStatus == Himall.Model.OrderInfo.OrderOperateStatus.WaitSelfPickUp) &&
                                        !item.RefundStats.HasValue && item.PaymentType != Himall.Model.OrderInfo.PaymentTypes.CashOnDelivery && item.PaymentType != Himall.Model.OrderInfo.PaymentTypes.None &&
                                        (item.FightGroupCanRefund == null || item.FightGroupCanRefund == true) && ordrefstate.GetValueOrDefault().Equals(0);
                    return(new
                    {
                        PayCode = item.PayCode,
                        ShopId = item.ShopId,
                        ShopLogo = shopInfo.Logo,
                        OrderAmount = item.OrderAmount,
                        OrderId = item.Id,
                        StatusText = statusText,
                        Status = item.OrderStatus,
                        orderType = item.OrderType,
                        orderTypeName = item.OrderType.ToDescription(),
                        shopname = item.ShopName,
                        vshopId = vshop == null ? 0 : vshop.Id,
                        Amount = item.OrderTotalAmount.ToString("F2"),
                        Quantity = item.OrderProductQuantity,
                        commentCount = item.OrderCommentInfo.Count(),
                        pickupCode = item.PickupCode,
                        EnabledRefundAmount = item.OrderEnabledRefundAmount,
                        LineItems = item.OrderItemInfo.Select(a =>
                        {
                            var prodata = productService.GetProduct(a.ProductId);
                            ProductTypeInfo typeInfo = ServiceProvider.Instance <ITypeService> .Create.GetType(prodata.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 == a.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 = "退款成功";
                                }
                            }

                            var activeModel = ServiceProvider.Instance <IFightGroupService> .Create.GetActiveByProId(a.ProductId);

                            return new
                            {
                                Status = itemrefstate,
                                StatusText = itemStatusText,
                                Id = activeModel.Id,
                                productId = a.ProductId,
                                Name = a.ProductName,
                                Image = activeModel.ProductDefaultImage,
                                Amount = a.Quantity,
                                Price = a.SalePrice,
                                Unit = prodata == null ? "" : prodata.MeasureUnit,
                                SkuText = colorAlias + ":" + a.Color + " " + sizeAlias + ":" + a.Size + " " + versionAlias + ":" + a.Version,
                                color = a.Color,
                                size = a.Size,
                                version = a.Version,
                                ColorAlias = colorAlias,
                                SizeAlias = sizeAlias,
                                VersionAlias = versionAlias,
                                RefundStats = itemrefstate,
                                OrderRefundId = (itemrefund == null ? 0 : itemrefund.Id),
                                EnabledRefundAmount = a.EnabledRefundAmount,
                                IsShowRefund = IsShowReturn,
                                IsShowAfterSale = IsShowReturn,
                                SalePrice = iShopAppletService.GetSkuSalePrice(a.SkuId, a.ProductId)
                            };
                        }),
                        RefundStats = ordrefstate,
                        OrderRefundId = _ordrefobj.Id,
                        IsShowLogistics = !string.IsNullOrWhiteSpace(item.ShipOrderNumber),
                        ShipOrderNumber = item.ShipOrderNumber,
                        IsShowCreview = item.OrderStatus == OrderInfo.OrderOperateStatus.Finish,
                        IsShowPreview = false,
                        Invoice = item.InvoiceType.ToDescription(),
                        InvoiceValue = (int)item.InvoiceType,
                        InvoiceContext = item.InvoiceContext,
                        InvoiceTitle = item.InvoiceTitle,
                        PaymentType = item.PaymentType.ToDescription(),
                        PaymentTypeValue = (int)item.PaymentType,
                        IsShowClose = (item.OrderStatus == OrderInfo.OrderOperateStatus.WaitPay),
                        IsShowFinishOrder = (item.OrderStatus == OrderInfo.OrderOperateStatus.WaitReceiving),
                        IsShowRefund = IsShowReturn,
                        IsShowReturn = IsShowReturn,
                        IsShowTakeCodeQRCode = !string.IsNullOrWhiteSpace(item.PickupCode),
                        OrderDate = item.OrderDate,
                        SupplierId = 0,
                        ShipperName = string.Empty,
                        StoreName = item.ShopName,
                        IsShowCertification = false,
                        CreviewText = !HasAppendComment(item) ? "评价订单" : "追加评论",
                        ProductCommentPoint = 0
                    });
                }
                else
                {
                    return(null);
                }
            });

            return(Json(new { Status = "OK", AllOrderCounts = allOrderCounts, WaitingForComments = waitingForComments, WaitingForRecieve = waitingForRecieve, WaitingForPay = waitingForPay, Data = result }));
        }
Пример #3
0
        public object GetOrderDetail(long orderId)
        {
            CheckUserLogin();
            var       orderService = ServiceProvider.Instance <IOrderService> .Create;
            OrderInfo order        = orderService.GetOrder(orderId, CurrentUser.Id);

            var orderRefundService = ServiceProvider.Instance <IRefundService> .Create;
            var productService     = ServiceProvider.Instance <IProductService> .Create;
            var coupon             = ServiceProvider.Instance <ICouponService> .Create.GetCouponRecordInfo(order.UserId, order.Id);

            bool    isCanApply  = false;
            string  couponName  = "";
            decimal couponAmout = 0;

            if (coupon != null)
            {
                couponName  = coupon.Himall_Coupon.CouponName;
                couponAmout = coupon.Himall_Coupon.Price;
            }

            //订单信息是否正常
            if (order == null)
            {
                throw new HimallException("订单号不存在!");
            }
            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(order.OrderItemInfo.Select(p => p.Id));
            var isCanOrderReturn = false;
            //获取订单商品项数据
            var orderDetail = new
            {
                ShopId     = order.ShopId,
                OrderItems = order.OrderItemInfo.Select(item =>
                {
                    var productinfo = productService.GetProduct(item.ProductId);
                    //是否有售后记录
                    if (order.OrderStatus == OrderInfo.OrderOperateStatus.WaitDelivery)
                    {
                        isCanApply = orderRefundService.CanApplyRefund(orderId, item.Id, true);
                    }
                    else
                    {
                        isCanApply = orderRefundService.CanApplyRefund(orderId, item.Id, false);
                    }
                    ProductTypeInfo 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 = "退款成功";
                        }
                    }

                    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.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,
                        SkuText = colorAlias + ":" + item.Color + ";" + sizeAlias + ":" + item.Size + ";" + versionAlias + ":" + item.Version,
                        EnabledRefundAmount = item.EnabledRefundAmount
                    });
                })
            };
            //取拼团订单状态
            var fightGroupOrderInfo = ServiceProvider.Instance <IFightGroupService> .Create.GetFightGroupOrderStatusByOrderId(order.Id);

            var orderModel = new
            {
                OrderId                     = order.Id,
                Status                      = (int)order.OrderStatus,
                StatusText                  = order.OrderStatus.ToDescription(),
                OrderTotal                  = order.OrderTotalAmount,
                OrderAmount                 = order.ProductTotalAmount,
                DeductionPoints             = 0,
                DeductionMoney              = order.IntegralDiscount,
                CouponAmount                = couponAmout.ToString("F2"), //优惠劵金额
                CouponName                  = couponName,                 //优惠劵名称
                RefundAmount                = order.RefundTotalAmount,
                Tax                         = 0,
                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.RegionFullName + " " + order.Address,
                FreightFreePromotionName    = string.Empty,
                ReducedPromotionName        = string.Empty,
                ReducedPromotionAmount      = string.Empty,
                SentTimesPointPromotionName = string.Empty,
                CanBackReturn               = !string.IsNullOrWhiteSpace(order.PaymentTypeGateway),
                CanCashierReturn            = false,
                PaymentType                 = order.PaymentType.ToDescription(),
                Remark                      = string.IsNullOrEmpty(order.OrderRemarks) ? "" : order.OrderRemarks,
                InvoiceTitle                = order.InvoiceTitle,
                ModeName                    = order.DeliveryType.ToDescription(),
                LogisticsData               = expressTrace,
                TakeCode                    = order.PickupCode,
                LineItems                   = orderDetail.OrderItems,
                IsCanRefund                 = (orderDetail.OrderItems.Where(e => e.IsCanRefund == false).Count() == 0) && !orderService.IsRefundTimeOut(order.Id)
            };

            return(Json(new { Status = "OK", Data = orderModel }));
        }
Пример #4
0
        public object GetOrders(int?orderStatus, int pageNo, int pageSize = 8)
        {
            CheckUserLogin();
            var allOrders = ServiceProvider.Instance <IOrderService> .Create.GetTopOrders(int.MaxValue, CurrentUser.Id);

            var orderService = ServiceProvider.Instance <IOrderService> .Create;

            //待评价
            var queryModelAll = new OrderQuery()
            {
                Status    = OrderInfo.OrderOperateStatus.Finish,
                UserId    = CurrentUser.Id,
                PageSize  = int.MaxValue,
                PageNo    = 1,
                Commented = false
            };
            var allOrderCounts     = allOrders.Count();
            var waitingForComments = orderService.GetOrders <OrderInfo>(queryModelAll).Total;
            var waitingForRecieve  = allOrders.Count(item => item.OrderStatus == OrderInfo.OrderOperateStatus.WaitReceiving); //获取待收货订单数
            var waitingForPay      = allOrders.Count(item => item.OrderStatus == OrderInfo.OrderOperateStatus.WaitPay);       //获取待支付订单数

            if (orderStatus.HasValue && orderStatus == 0)
            {
                orderStatus = null;
            }
            var queryModel = new OrderQuery()
            {
                Status   = (OrderInfo.OrderOperateStatus?)orderStatus,
                UserId   = CurrentUser.Id,
                PageSize = pageSize,
                PageNo   = pageNo
            };

            if (queryModel.Status.HasValue && queryModel.Status.Value == OrderInfo.OrderOperateStatus.WaitReceiving)
            {
                if (queryModel.MoreStatus == null)
                {
                    queryModel.MoreStatus = new List <OrderInfo.OrderOperateStatus>()
                    {
                    };
                }
                queryModel.MoreStatus.Add(OrderInfo.OrderOperateStatus.WaitSelfPickUp);
            }
            if (orderStatus.GetValueOrDefault() == (int)OrderInfo.OrderOperateStatus.Finish)
            {
                queryModel.Commented = false;//只查询未评价的订单
            }
            ObsoletePageModel <OrderInfo> orders = orderService.GetOrders <OrderInfo>(queryModel);
            var productService     = ServiceProvider.Instance <IProductService> .Create;
            var vshopService       = ServiceProvider.Instance <IVShopService> .Create;
            var orderRefundService = ServiceProvider.Instance <IRefundService> .Create;
            var orderItems         = OrderApplication.GetOrderItemsByOrderId(orders.Models.Select(p => p.Id));
            var orderRefunds       = OrderApplication.GetOrderRefunds(orderItems.Select(p => p.Id));
            var result             = orders.Models.ToArray().Select(item =>
            {
                if (item.OrderStatus >= OrderInfo.OrderOperateStatus.WaitDelivery)
                {
                    orderService.CalculateOrderItemRefund(item.Id);
                }
                var vshop      = vshopService.GetVShopByShopId(item.ShopId);
                var _ordrefobj = orderRefundService.GetOrderRefundByOrderId(item.Id) ?? new OrderRefundInfo {
                    Id = 0
                };
                if (item.OrderStatus != OrderInfo.OrderOperateStatus.WaitDelivery && item.OrderStatus != OrderInfo.OrderOperateStatus.WaitSelfPickUp)
                {
                    _ordrefobj = new OrderRefundInfo {
                        Id = 0
                    };
                }
                int?ordrefstate = (_ordrefobj == null ? null : (int?)_ordrefobj.SellerAuditStatus);
                ordrefstate     = (ordrefstate > 4 ? (int?)_ordrefobj.ManagerConfirmStatus : ordrefstate);
                return(new
                {
                    id = item.Id,
                    status = item.OrderStatus.ToDescription(),
                    orderStatus = item.OrderStatus,
                    orderType = item.OrderType,
                    orderTypeName = item.OrderType.ToDescription(),
                    shopname = item.ShopName,
                    vshopId = vshop == null ? 0 : vshop.Id,
                    orderTotalAmount = item.OrderTotalAmount.ToString("F2"),
                    productCount = item.OrderProductQuantity,
                    commentCount = item.OrderCommentInfo.Count(),
                    pickupCode = item.PickupCode,
                    EnabledRefundAmount = item.OrderEnabledRefundAmount,
                    itemInfo = item.OrderItemInfo.Select(a =>
                    {
                        var prodata = productService.GetProduct(a.ProductId);
                        ProductTypeInfo typeInfo = ServiceProvider.Instance <ITypeService> .Create.GetType(prodata.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 itemrefund = orderRefunds.Where(or => or.OrderItemId == a.Id).FirstOrDefault(d => d.RefundMode != OrderRefundInfo.OrderRefundMode.OrderRefund);
                        int?itemrefstate = (itemrefund == null ? null : (int?)itemrefund.SellerAuditStatus);
                        itemrefstate = (itemrefstate > 4 ? (int?)itemrefund.ManagerConfirmStatus : itemrefstate);

                        return new
                        {
                            productId = a.ProductId,
                            productName = a.ProductName,
                            image = Core.HimallIO.GetRomoteProductSizeImage(a.ThumbnailsUrl, 1, (int)Himall.CommonModel.ImageSize.Size_350),
                            count = a.Quantity,
                            price = a.SalePrice,
                            Unit = prodata == null ? "" : prodata.MeasureUnit,
                            color = a.Color,
                            size = a.Size,
                            version = a.Version,
                            ColorAlias = colorAlias,
                            SizeAlias = sizeAlias,
                            VersionAlias = versionAlias,
                            RefundStats = itemrefstate,
                            OrderRefundId = (itemrefund == null ? 0 : itemrefund.Id),
                            EnabledRefundAmount = a.EnabledRefundAmount
                        };
                    }),
                    RefundStats = ordrefstate,
                    OrderRefundId = _ordrefobj.Id,
                    HasExpressStatus = !string.IsNullOrWhiteSpace(item.ShipOrderNumber),
                    HasAppendComment = HasAppendComment(item),
                    Invoice = item.InvoiceType.ToDescription(),
                    InvoiceValue = (int)item.InvoiceType,
                    InvoiceContext = item.InvoiceContext,
                    InvoiceTitle = item.InvoiceTitle,
                    PaymentType = item.PaymentType.ToDescription(),
                    PaymentTypeValue = (int)item.PaymentType,
                    CanRefund = (item.OrderStatus == Himall.Model.OrderInfo.OrderOperateStatus.WaitDelivery || item.OrderStatus == Himall.Model.OrderInfo.OrderOperateStatus.WaitSelfPickUp) &&
                                !item.RefundStats.HasValue && item.PaymentType != Himall.Model.OrderInfo.PaymentTypes.CashOnDelivery && item.PaymentType != Himall.Model.OrderInfo.PaymentTypes.None &&
                                (item.FightGroupCanRefund == null || item.FightGroupCanRefund == true) && ordrefstate.GetValueOrDefault().Equals(0)
                });
            });

            return(Json(new { Success = "true", AllOrderCounts = allOrderCounts, WaitingForComments = waitingForComments, WaitingForRecieve = waitingForRecieve, WaitingForPay = waitingForPay, Orders = result }));
        }
Пример #5
0
        public ActionResult Index(string orderDate, string keywords, string orderids, DateTime?startDateTime, DateTime?endDateTime, int?orderStatus, int pageNo = 1, int pageSize = 10)
        {
            ViewBag.Grant = null;

            if (!string.IsNullOrEmpty(orderids) && orderids.IndexOf(',') <= 0)
            {
                ViewBag.Grant = _iShopBonusService.GetByOrderId(long.Parse(orderids));
            }

            DateTime?startDate = startDateTime;
            DateTime?endDate   = endDateTime;

            if (!string.IsNullOrEmpty(orderDate) && orderDate.ToLower() != "all")
            {
                switch (orderDate.ToLower())
                {
                case "threemonth":
                    startDate = DateTime.Now.AddMonths(-3);
                    break;

                case "halfyear":
                    startDate = DateTime.Now.AddMonths(-6);
                    break;

                case "year":
                    startDate = DateTime.Now.AddYears(-1);
                    break;

                case "yearago":
                    endDate = DateTime.Now.AddYears(-1);
                    break;
                }
            }

            if (orderStatus.HasValue && orderStatus == 0)
            {
                orderStatus = null;
            }

            var queryModel = new OrderQuery()
            {
                StartDate      = startDate,
                EndDate        = endDate,
                Status         = (Model.OrderInfo.OrderOperateStatus?)orderStatus,
                UserId         = CurrentUser.Id,
                SearchKeyWords = keywords,
                PageSize       = pageSize,
                PageNo         = pageNo
            };

            var orders        = OrderApplication.GetOrders(queryModel);
            var orderComments = OrderApplication.GetOrderCommentCount(orders.Models.Select(p => p.Id));
            var orderItems    = OrderApplication.GetOrderItemsByOrderId(orders.Models.Select(p => p.Id));
            var orderRefunds  = OrderApplication.GetOrderRefunds(orderItems.Select(p => p.Id));

            PagingInfo info = new PagingInfo
            {
                CurrentPage  = pageNo,
                ItemsPerPage = pageSize,
                TotalItems   = orders.Total
            };

            ViewBag.pageInfo = info;
            ViewBag.UserId   = CurrentUser.Id;
            var siteSetting = _iSiteSettingService.GetSiteSettings();
            var shopBonus   = _iShopBonusService;

            ViewBag.SalesRefundTimeout = siteSetting.SalesReturnTimeout;

            var cashDepositsService = _iCashDepositsService;
            //IEnumerable<OrderListModel> orderList = new IEnumerable<OrderListModel>();
            IEnumerable <OrderListModel> orderList = orders.Models.Select(item => new OrderListModel
            {
                Id                 = item.Id,
                ActiveType         = item.ActiveType,
                OrderType          = item.OrderType,
                Address            = item.Address,
                CellPhone          = item.CellPhone,
                CloseReason        = item.CloseReason,
                CommisTotalAmount  = item.CommisAmount,
                DiscountAmount     = item.DiscountAmount,
                ExpressCompanyName = item.ExpressCompanyName,
                FinishDate         = item.FinishDate,
                Freight            = item.Freight,
                GatewayOrderId     = item.GatewayOrderId,
                IntegralDiscount   = item.IntegralDiscount,
                UserId             = item.UserId,
                ShopId             = item.ShopId,
                ShopName           = item.ShopName,
                ShipTo             = item.ShipTo,
                OrderTotalAmount   = item.OrderTotalAmount,
                PaymentTypeName    = item.PaymentTypeName,
                //满额减
                FullDiscount  = item.FullDiscount,
                OrderStatus   = item.OrderStatus,
                RefundStats   = item.RefundStats,
                CommentCount  = orderComments.ContainsKey(item.Id)?orderComments[item.Id]:0,
                OrderDate     = item.OrderDate,
                PaymentType   = item.PaymentType,
                PickupCode    = item.PickupCode,
                OrderItemList = orderItems.Where(oi => oi.OrderId == item.Id).Select(oItem =>
                {
                    var itemrefund = orderRefunds.Where(or => or.OrderItemId == oItem.Id).FirstOrDefault();
                    var orderItem  = new OrderItemListModel
                    {
                        Id                     = oItem.Id,
                        ProductId              = oItem.ProductId,
                        Color                  = oItem.Color,
                        Size                   = oItem.Size,
                        Version                = oItem.Version,
                        ProductName            = oItem.ProductName,
                        ThumbnailsUrl          = oItem.ThumbnailsUrl,
                        SalePrice              = oItem.SalePrice,
                        SkuId                  = oItem.SkuId,
                        Quantity               = oItem.Quantity,
                        CashDepositsObligation = cashDepositsService.GetCashDepositsObligation(oItem.ProductId),
                    };

                    if (itemrefund != null)
                    {
                        orderItem.RefundStats  = itemrefund.RefundStatusValue;
                        orderItem.ItemRefundId = itemrefund.Id;

                        string showRefundStats = "";
                        if (itemrefund.SellerAuditStatus == OrderRefundInfo.OrderRefundAuditStatus.Audited)
                        {
                            showRefundStats = itemrefund.ManagerConfirmStatus.ToDescription();
                        }
                        else if (item.DeliveryType == CommonModel.Enum.DeliveryType.SelfTake || (item.ShopBranchId.HasValue && item.ShopBranchId.Value > 0))//如果是自提预约单或分配门店预约单则转为门店审核状态
                        {
                            showRefundStats = ((CommonModel.Enum.OrderRefundShopAuditStatus)itemrefund.SellerAuditStatus).ToDescription();
                        }
                        else
                        {
                            showRefundStats = itemrefund.SellerAuditStatus.ToDescription();
                        }

                        orderItem.ShowRefundStats = showRefundStats;
                    }
                    orderItem.EnabledRefundAmount = oItem.EnabledRefundAmount;
                    ProductTypeInfo typeInfo      = _iTypeService.GetTypeByProductId(oItem.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;

                    return(orderItem);
                }).ToList(),
                ReceiveBonus = shopBonus.GetGrantByUserOrder(item.Id, CurrentUser.Id),
            }).ToList();

            foreach (var o in orderList)
            {
                o.HasAppendComment = HasAppendComment(o);
            }

            #region 数据补偿
            List <long> ordidl = orderList.Select(d => d.Id).ToList();
            if (ordidl.Count > 0)
            {
                foreach (var item in orderList)
                {
                    var _ord = orders.Models.FirstOrDefault(o => o.Id == item.Id);

                    item.IsRefundTimeOut     = OrderApplication.IsRefundTimeOut(_ord);
                    item.EnabledRefundAmount = _ord.OrderEnabledRefundAmount;
                    //退款状态补偿
                    var _tmpobj = orderRefunds.FirstOrDefault(d => d.OrderId == item.Id && d.RefundMode == OrderRefundInfo.OrderRefundMode.OrderRefund);
                    if (_tmpobj != null)
                    {
                        item.RefundStats   = (int)_tmpobj.SellerAuditStatus;
                        item.OrderRefundId = _tmpobj.Id;
                    }

                    item.OrderCanRefund = false;

                    if (item.OrderStatus == Himall.Model.OrderInfo.OrderOperateStatus.Finish)
                    {
                        if (item.FinishDate.Value.AddDays(siteSetting.SalesReturnTimeout) > DateTime.Now)
                        {
                            item.OrderCanRefund = true;
                        }
                    }
                    if (item.OrderStatus == Himall.Model.OrderInfo.OrderOperateStatus.WaitReceiving)
                    {
                        item.OrderCanRefund = true;
                    }
                    if (item.PaymentType == Himall.Model.OrderInfo.PaymentTypes.CashOnDelivery)
                    {
                        if (item.OrderStatus == Himall.Model.OrderInfo.OrderOperateStatus.Finish)
                        {
                            item.OrderCanRefund = true;
                        }
                    }
                    else
                    {
                        item.OrderCanRefund = true;
                    }

                    item.FightGroupCanRefund = true;   //非拼团预约单默认可退

                    //拼团状态补偿
                    if (item.OrderType == OrderInfo.OrderTypes.FightGroup)
                    {
                        var fgord = _iFightGroupService.GetFightGroupOrderStatusByOrderId(item.Id);
                        if (fgord != null)
                        {
                            item.FightGroupJoinStatus = fgord.GetJoinStatus;
                            item.FightGroupCanRefund  = fgord.CanRefund;
                        }
                        else
                        {
                            item.FightGroupJoinStatus = CommonModel.FightGroupOrderJoinStatus.JoinFailed;
                            item.FightGroupCanRefund  = false;
                        }
                        item.OrderCanRefund = item.OrderCanRefund && item.FightGroupCanRefund;
                    }
                }
            }
            #endregion

            return(View(orderList.ToList()));
        }
Пример #6
0
        /// <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));
        }
Пример #7
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));
        }
Пример #8
0
        public JsonResult GetUserOrders(int?orderStatus, int pageNo, int pageSize = 8)
        {
            if (orderStatus.HasValue && orderStatus == 0)
            {
                orderStatus = null;
            }
            var queryModel = new OrderQuery()
            {
                Status   = (Model.OrderInfo.OrderOperateStatus?)orderStatus,
                UserId   = CurrentUser.Id,
                PageSize = pageSize,
                PageNo   = pageNo
            };

            if (queryModel.Status.HasValue && queryModel.Status.Value == OrderInfo.OrderOperateStatus.WaitReceiving)
            {
                if (queryModel.MoreStatus == null)
                {
                    queryModel.MoreStatus = new List <OrderInfo.OrderOperateStatus>()
                    {
                    };
                }
                queryModel.MoreStatus.Add(OrderInfo.OrderOperateStatus.WaitSelfPickUp);
            }
            if (orderStatus.GetValueOrDefault() == (int)Model.OrderInfo.OrderOperateStatus.Finish)
            {
                queryModel.Commented = false;//只查询未评价的订单
            }
            var orders        = OrderApplication.GetOrders(queryModel);
            var orderItems    = OrderApplication.GetOrderItemsByOrderId(orders.Models.Select(p => p.Id));
            var orderComments = OrderApplication.GetOrderCommentCount(orders.Models.Select(p => p.Id));
            var orderRefunds  = OrderApplication.GetOrderRefunds(orderItems.Select(p => p.Id));
            var products      = ProductManagerApplication.GetProductsByIds(orderItems.Select(p => p.ProductId));
            var vshops        = VshopApplication.GetVShopsByShopIds(products.Select(p => p.ShopId));

            var result = orders.Models.Select(item =>
            {
                var _ordrefobj = _iRefundService.GetOrderRefundByOrderId(item.Id) ?? new OrderRefundInfo {
                    Id = 0
                };
                if (item.OrderStatus != OrderInfo.OrderOperateStatus.WaitDelivery && item.OrderStatus != OrderInfo.OrderOperateStatus.WaitSelfPickUp)
                {
                    _ordrefobj = new OrderRefundInfo {
                        Id = 0
                    };
                }
                int?ordrefstate = (_ordrefobj == null ? null : (int?)_ordrefobj.SellerAuditStatus);
                ordrefstate     = (ordrefstate > 4 ? (int?)_ordrefobj.ManagerConfirmStatus : ordrefstate);
                return(new
                {
                    id = item.Id,
                    status = item.OrderStatus.ToDescription(),
                    orderStatus = item.OrderStatus,
                    shopname = item.ShopName,
                    orderTotalAmount = item.OrderTotalAmount.ToString("F2"),
                    productCount = item.OrderProductQuantity,
                    commentCount = orderComments.ContainsKey(item.Id) ? orderComments[item.Id] : 0,
                    PaymentType = item.PaymentType,
                    RefundStats = ordrefstate,
                    OrderRefundId = _ordrefobj.Id,
                    OrderType = item.OrderType,
                    PickUp = item.PickupCode,
                    ShopBranchId = item.ShopBranchId,
                    DeliveryType = item.DeliveryType,
                    ShipOrderNumber = item.ShipOrderNumber,
                    EnabledRefundAmount = item.OrderEnabledRefundAmount,
                    itemInfo = orderItems.Where(oi => oi.OrderId == item.Id).Select(a =>
                    {
                        var prodata = products.FirstOrDefault(p => p.Id == a.ProductId);
                        VShop vshop = null;
                        if (prodata != null)
                        {
                            vshop = vshops.FirstOrDefault(vs => vs.ShopId == prodata.ShopId);
                        }
                        if (vshop == null)
                        {
                            vshop = new VShop {
                                Id = 0
                            }
                        }
                        ;

                        var itemrefund = orderRefunds.Where(or => or.OrderItemId == a.Id).FirstOrDefault(d => d.RefundMode != OrderRefundInfo.OrderRefundMode.OrderRefund);
                        int?itemrefstate = (itemrefund == null ? null : (int?)itemrefund.SellerAuditStatus);
                        itemrefstate = (itemrefstate > 4 ? (int?)itemrefund.ManagerConfirmStatus : itemrefstate);
                        return new
                        {
                            itemid = a.Id,
                            productId = a.ProductId,
                            productName = a.ProductName,
                            image = HimallIO.GetProductSizeImage(a.ThumbnailsUrl, 1, (int)ImageSize.Size_100),
                            count = a.Quantity,
                            price = a.SalePrice,
                            Unit = prodata == null ? "" : prodata.MeasureUnit,
                            vshopid = vshop.Id,
                            color = a.Color,
                            size = a.Size,
                            version = a.Version,
                            RefundStats = itemrefstate,
                            OrderRefundId = (itemrefund == null ? 0 : itemrefund.Id),
                            EnabledRefundAmount = a.EnabledRefundAmount
                        };
                    }),
                    HasAppendComment = HasAppendComment(orderItems.Where(oi => oi.OrderId == item.Id).FirstOrDefault()),
                    CanRefund = (item.OrderStatus == Himall.Model.OrderInfo.OrderOperateStatus.WaitDelivery || item.OrderStatus == Himall.Model.OrderInfo.OrderOperateStatus.WaitSelfPickUp) &&
                                !item.RefundStats.HasValue && item.PaymentType != Himall.Model.OrderInfo.PaymentTypes.CashOnDelivery && item.PaymentType != Himall.Model.OrderInfo.PaymentTypes.None &&
                                (item.FightGroupCanRefund == null || item.FightGroupCanRefund == true) && ordrefstate.GetValueOrDefault().Equals(0)
                });
            });
Пример #9
0
        public JsonResult GetUserOrders(int?orderStatus, int pageNo, int pageSize = 8)
        {
            if (orderStatus.HasValue && orderStatus == 0)
            {
                orderStatus = null;
            }
            var queryModel = new OrderQuery()
            {
                Status   = (Entities.OrderInfo.OrderOperateStatus?)orderStatus,
                UserId   = CurrentUser.Id,
                PageSize = pageSize,
                PageNo   = pageNo,
                IsFront  = true
            };

            if (queryModel.Status.HasValue && queryModel.Status.Value == Entities.OrderInfo.OrderOperateStatus.WaitReceiving)
            {
                if (queryModel.MoreStatus == null)
                {
                    queryModel.MoreStatus = new List <Entities.OrderInfo.OrderOperateStatus>()
                    {
                    };
                }
                queryModel.MoreStatus.Add(Entities.OrderInfo.OrderOperateStatus.WaitSelfPickUp);
            }
            if (orderStatus.GetValueOrDefault() == (int)OrderInfo.OrderOperateStatus.Finish)
            {
                queryModel.Commented = false;//只查询未评价的订单
            }
            var orders        = OrderApplication.GetOrders(queryModel);
            var orderItems    = OrderApplication.GetOrderItemsByOrderId(orders.Models.Select(p => p.Id));
            var orderComments = OrderApplication.GetOrderCommentCount(orders.Models.Select(p => p.Id));
            var orderRefunds  = OrderApplication.GetOrderRefunds(orderItems.Select(p => p.Id));
            var products      = ProductManagerApplication.GetProductsByIds(orderItems.Select(p => p.ProductId));
            var vshops        = VshopApplication.GetVShopsByShopIds(products.Select(p => p.ShopId));
            //查询结果的门店ID
            var branchIds = orders.Models.Where(e => e.ShopBranchId > 0).Select(p => p.ShopBranchId).ToList();
            //根据门店ID获取门店信息
            var shopBranchs            = ShopBranchApplication.GetShopBranchByIds(branchIds);
            var orderVerificationCodes = OrderApplication.GetOrderVerificationCodeInfosByOrderIds(orders.Models.Select(p => p.Id).ToList());
            var result = orders.Models.Select(item =>
            {
                var codes      = orderVerificationCodes.Where(a => a.OrderId == item.Id);
                var _ordrefobj = _iRefundService.GetOrderRefundByOrderId(item.Id) ?? new Entities.OrderRefundInfo {
                    Id = 0
                };
                if (item.OrderStatus != Entities.OrderInfo.OrderOperateStatus.WaitDelivery && item.OrderStatus != Entities.OrderInfo.OrderOperateStatus.WaitSelfPickUp)
                {
                    _ordrefobj = new Entities.OrderRefundInfo {
                        Id = 0
                    };
                }
                int?ordrefstate   = (_ordrefobj == null ? null : (int?)_ordrefobj.SellerAuditStatus);
                ordrefstate       = (ordrefstate > 4 ? (int?)_ordrefobj.ManagerConfirmStatus : ordrefstate);
                var branchObj     = shopBranchs.FirstOrDefault(e => item.ShopBranchId > 0 && e.Id == item.ShopBranchId);
                string branchName = branchObj == null ? string.Empty : branchObj.ShopBranchName;
                return(new
                {
                    id = item.Id,
                    status = item.OrderStatus.ToDescription(),
                    orderStatus = item.OrderStatus,
                    shopname = item.ShopName,
                    orderTotalAmount = item.OrderTotalAmount,
                    capitalAmount = item.CapitalAmount,
                    productCount = orderItems.Where(oi => oi.OrderId == item.Id).Sum(a => a.Quantity),
                    commentCount = orderComments.ContainsKey(item.Id) ? orderComments[item.Id] : 0,
                    PaymentType = item.PaymentType,
                    RefundStats = ordrefstate,
                    OrderRefundId = _ordrefobj.Id,
                    OrderType = item.OrderType,
                    PickUp = item.PickupCode,
                    ShopBranchId = item.ShopBranchId,
                    ShopBranchName = branchName,
                    DeliveryType = item.DeliveryType,
                    ShipOrderNumber = item.ShipOrderNumber,
                    EnabledRefundAmount = item.OrderEnabledRefundAmount,
                    itemInfo = orderItems.Where(oi => oi.OrderId == item.Id).Select(a =>
                    {
                        var prodata = products.FirstOrDefault(p => p.Id == a.ProductId);
                        VShop vshop = null;
                        if (prodata != null)
                        {
                            vshop = vshops.FirstOrDefault(vs => vs.ShopId == prodata.ShopId);
                        }
                        if (vshop == null)
                        {
                            vshop = new VShop {
                                Id = 0
                            }
                        }
                        ;

                        var itemrefund = orderRefunds.Where(or => or.OrderItemId == a.Id).FirstOrDefault(d => d.RefundMode != OrderRefundInfo.OrderRefundMode.OrderRefund);
                        int?itemrefstate = (itemrefund == null ? null : (int?)itemrefund.SellerAuditStatus);
                        itemrefstate = (itemrefstate > 4 ? (int?)itemrefund.ManagerConfirmStatus : itemrefstate);
                        return new
                        {
                            itemid = a.Id,
                            productId = a.ProductId,
                            productName = a.ProductName,
                            image = HimallIO.GetProductSizeImage(a.ThumbnailsUrl, 1, (int)ImageSize.Size_100),
                            count = a.Quantity,
                            price = a.SalePrice,
                            Unit = prodata == null ? "" : prodata.MeasureUnit,
                            vshopid = vshop.Id,
                            color = a.Color,
                            size = a.Size,
                            version = a.Version,
                            RefundStats = itemrefstate,
                            OrderRefundId = (itemrefund == null ? 0 : itemrefund.Id),
                            EnabledRefundAmount = a.EnabledRefundAmount
                        };
                    }),
                    HasAppendComment = HasAppendComment(orderItems.Where(oi => oi.OrderId == item.Id).FirstOrDefault()),
                    CanRefund = OrderApplication.CanRefund(item, ordrefstate),
                    IsVirtual = item.OrderType == OrderInfo.OrderTypes.Virtual ? 1 : 0,
                    IsPay = item.PayDate.HasValue ? 1 : 0
                });
            });
Пример #10
0
        /// <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="pickcode"></param>
        /// <returns></returns>
        public object GetShopBranchOrder(string pickcode)
        {
            CheckUserLogin();

            var codeInfo = OrderApplication.GetOrderVerificationCodeInfoByCode(pickcode);

            if (codeInfo != null)
            {
                var order = OrderApplication.GetOrderInfo(codeInfo.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 = "非本店核销码,请买家核对信息" }
                }
                ;

                if (codeInfo.Status == OrderInfo.VerificationCodeStatus.AlreadyVerification)
                {
                    return new { success = false, msg = string.Format("该核销码于{0}已核销", codeInfo.VerificationTime.Value.ToString("yyyy-MM-dd HH:mm")) }
                }
                ;

                if (codeInfo.Status == OrderInfo.VerificationCodeStatus.Expired)
                {
                    return new { success = false, msg = "此核销码已过期,无法核销" }
                }
                ;

                if (codeInfo.Status == OrderInfo.VerificationCodeStatus.Refund)
                {
                    return new { success = false, msg = "此核销码正处于退款中,无法核销" }
                }
                ;

                if (codeInfo.Status == OrderInfo.VerificationCodeStatus.RefundComplete)
                {
                    return new { success = false, msg = "此核销码已经退款成功,无法核销" }
                }
                ;

                var orderItem          = Application.OrderApplication.GetOrderItemsByOrderId(order.Id);
                var orderItemInfo      = orderItem.FirstOrDefault();
                var virtualProductInfo = ProductManagerApplication.GetVirtualProductInfoByProductId(orderItemInfo.ProductId);
                if (virtualProductInfo != null && virtualProductInfo.ValidityType && DateTime.Now < virtualProductInfo.StartDate.Value)
                {
                    return(new { success = false, msg = "该核销码暂时不能核销,请留意生效时间!" });
                }
                if (orderItemInfo.EffectiveDate.HasValue)
                {
                    if (DateTime.Now < orderItemInfo.EffectiveDate.Value)
                    {
                        return new { success = false, msg = "该核销码暂时不能核销,请留意生效时间!" }
                    }
                    ;
                }

                foreach (var item in orderItem)
                {
                    item.ThumbnailsUrl = Core.HimallIO.GetRomoteProductSizeImage(item.ThumbnailsUrl, 1, (int)Himall.CommonModel.ImageSize.Size_100);
                    Entities.TypeInfo typeInfo = ServiceProvider.Instance <ITypeService> .Create.GetTypeByProductId(item.ProductId);

                    item.ColorAlias   = (typeInfo == null || string.IsNullOrEmpty(typeInfo.ColorAlias)) ? SpecificationType.Color.ToDescription() : typeInfo.ColorAlias;
                    item.SizeAlias    = (typeInfo == null || string.IsNullOrEmpty(typeInfo.SizeAlias)) ? SpecificationType.Size.ToDescription() : typeInfo.SizeAlias;
                    item.VersionAlias = (typeInfo == null || string.IsNullOrEmpty(typeInfo.VersionAlias)) ? SpecificationType.Version.ToDescription() : typeInfo.VersionAlias;
                    var productInfo = ProductManagerApplication.GetProduct(item.ProductId);
                    if (productInfo != null)
                    {
                        item.ColorAlias = !string.IsNullOrWhiteSpace(productInfo.ColorAlias) ? productInfo.ColorAlias : item.ColorAlias;

                        item.SizeAlias    = !string.IsNullOrWhiteSpace(productInfo.SizeAlias) ? productInfo.SizeAlias : item.SizeAlias;
                        item.VersionAlias = !string.IsNullOrWhiteSpace(productInfo.VersionAlias) ? productInfo.VersionAlias : item.VersionAlias;
                    }
                }

                var verifications = OrderApplication.GetOrderVerificationCodeInfosByOrderIds(new List <long>()
                {
                    order.Id
                }).Where(a => a.Status == OrderInfo.VerificationCodeStatus.WaitVerification);
                var codes = verifications.ToList();//待消费的核销码
                if (codes != null)
                {
                    codes.ForEach(a =>
                    {
                        a.SourceCode       = a.VerificationCode;
                        a.VerificationCode = System.Text.RegularExpressions.Regex.Replace(a.VerificationCode, "(\\d{4})\\d{4}(\\d{4})", "$1****$2");
                    });
                }
                var virtualOrderItemInfos = OrderApplication.GetVirtualOrderItemInfosByOrderId(order.Id).Select(p =>
                {
                    return(new
                    {
                        VirtualProductItemType = p.VirtualProductItemType,
                        VirtualProductItemName = p.VirtualProductItemName,
                        Content = ReplaceImage(p.Content, p.VirtualProductItemType)
                    });
                });
                order.OrderStatusText = order.OrderStatus.ToDescription();
                order.PaymentTypeName = PaymentApplication.GetPaymentTypeDescById(order.PaymentTypeGateway) ?? order.PaymentTypeName;//统一显示支付方式名称
                return(new { success = true, order = order, orderItem = orderItem, virtualProductInfo = virtualProductInfo, virtualOrderItemInfos = virtualOrderItemInfos, verificationCodes = codes });
            }
            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() + "已核销" }
                }
                ;
                var orderRefundInfo = RefundApplication.GetOrderRefundByOrderId(order.Id);
                if (orderRefundInfo != null && orderRefundInfo.ManagerConfirmStatus == OrderRefundInfo.OrderRefundConfirmStatus.Confirmed)
                {
                    return(new { success = false, msg = "该订单已退款,不能再核销" });
                }
                var orderItem = Application.OrderApplication.GetOrderItemsByOrderId(order.Id);
                foreach (var item in orderItem)
                {
                    item.ThumbnailsUrl = Core.HimallIO.GetRomoteProductSizeImage(item.ThumbnailsUrl, 1, (int)Himall.CommonModel.ImageSize.Size_100);
                    Entities.TypeInfo typeInfo = ServiceProvider.Instance <ITypeService> .Create.GetTypeByProductId(item.ProductId);

                    item.ColorAlias   = (typeInfo == null || string.IsNullOrEmpty(typeInfo.ColorAlias)) ? SpecificationType.Color.ToDescription() : typeInfo.ColorAlias;
                    item.SizeAlias    = (typeInfo == null || string.IsNullOrEmpty(typeInfo.SizeAlias)) ? SpecificationType.Size.ToDescription() : typeInfo.SizeAlias;
                    item.VersionAlias = (typeInfo == null || string.IsNullOrEmpty(typeInfo.VersionAlias)) ? SpecificationType.Version.ToDescription() : typeInfo.VersionAlias;
                    var productInfo = ProductManagerApplication.GetProduct(item.ProductId);
                    if (productInfo != null)
                    {
                        item.ColorAlias   = !string.IsNullOrWhiteSpace(productInfo.ColorAlias) ? productInfo.ColorAlias : item.ColorAlias;
                        item.SizeAlias    = !string.IsNullOrWhiteSpace(productInfo.SizeAlias) ? productInfo.SizeAlias : item.SizeAlias;
                        item.VersionAlias = !string.IsNullOrWhiteSpace(productInfo.VersionAlias) ? productInfo.VersionAlias : item.VersionAlias;
                    }
                }
                //退款状态
                var refundobjs = OrderApplication.GetOrderRefunds(orderItem.Select(e => e.Id));
                //小于4表示商家未确认;与平台未审核,都算退款、退货中
                var refundProcessing = refundobjs.Where(e => (int)e.SellerAuditStatus > 4 && ((int)e.SellerAuditStatus < 4 || e.ManagerConfirmStatus == OrderRefundInfo.OrderRefundConfirmStatus.UnConfirm));
                if (refundProcessing.Count() > 0)
                {
                    order.RefundStats = 1;
                }

                order.OrderStatusText = order.OrderStatus.ToDescription();
                return(new { success = true, order = order, orderItem = orderItem });
            }
        }
Пример #12
0
        public object GetOrders(int?status, int pageIndex, int pageSize = 8)
        {
            CheckUserLogin();
            var orderService = ServiceProvider.Instance <IOrderService> .Create;

            if (status.HasValue && status == 0)
            {
                status = null;
            }
            var queryModel = new OrderQuery()
            {
                Status   = (OrderInfo.OrderOperateStatus?)status,
                UserId   = CurrentUser.Id,
                PageSize = pageSize,
                PageNo   = pageIndex,
                IsFront  = true
            };

            if (queryModel.Status.HasValue && queryModel.Status.Value == Entities.OrderInfo.OrderOperateStatus.WaitReceiving)
            {
                if (queryModel.MoreStatus == null)
                {
                    queryModel.MoreStatus = new List <Entities.OrderInfo.OrderOperateStatus>()
                    {
                    };
                }
                queryModel.MoreStatus.Add(Entities.OrderInfo.OrderOperateStatus.WaitSelfPickUp);
            }
            if (status.GetValueOrDefault() == (int)OrderInfo.OrderOperateStatus.Finish)
            {
                queryModel.Commented = false;//只查询未评价的订单
            }
            var orders             = orderService.GetOrders <OrderInfo>(queryModel);
            var productService     = ServiceProvider.Instance <IProductService> .Create;
            var vshopService       = ServiceProvider.Instance <IVShopService> .Create;
            var orderRefundService = ServiceProvider.Instance <IRefundService> .Create;
            var orderItems         = OrderApplication.GetOrderItemsByOrderId(orders.Models.Select(p => p.Id));
            var orderRefunds       = OrderApplication.GetOrderRefunds(orderItems.Select(p => p.Id));
            var shopBranchs        = ShopBranchApplication.GetShopBranchByIds(orders.Models.Where(a => a.ShopBranchId > 0).Select(p => p.ShopBranchId).ToList());
            var result             = orders.Models.Select(item =>
            {
                var orderitems     = orderItems.Where(p => p.OrderId == item.Id);
                var shopBranchInfo = shopBranchs.FirstOrDefault(a => a.Id == item.ShopBranchId);//当前订单所属门店信息
                if (item.OrderStatus >= Entities.OrderInfo.OrderOperateStatus.WaitDelivery)
                {
                    orderService.CalculateOrderItemRefund(item.Id);
                }
                var vshop      = vshopService.GetVShopByShopId(item.ShopId);
                var _ordrefobj = orderRefundService.GetOrderRefundByOrderId(item.Id) ?? new Entities.OrderRefundInfo {
                    Id = 0
                };
                if (item.OrderStatus != Entities.OrderInfo.OrderOperateStatus.WaitDelivery && item.OrderStatus != Entities.OrderInfo.OrderOperateStatus.WaitSelfPickUp)
                {
                    _ordrefobj = new Entities.OrderRefundInfo {
                        Id = 0
                    };
                }
                int?ordrefstate = (_ordrefobj == null ? null : (int?)_ordrefobj.SellerAuditStatus);
                ordrefstate     = (ordrefstate > 4 ? (int?)_ordrefobj.ManagerConfirmStatus : ordrefstate);
                //参照PC端会员中心的状态描述信息
                string statusText = item.OrderStatus.ToDescription();
                if (item.OrderStatus == Entities.OrderInfo.OrderOperateStatus.WaitDelivery || item.OrderStatus == Entities.OrderInfo.OrderOperateStatus.WaitSelfPickUp)
                {
                    if (ordrefstate.HasValue && ordrefstate != 0 && ordrefstate != 4)
                    {
                        statusText = "退款中";
                    }
                }
                //是否可售后
                bool IsShowReturn    = OrderApplication.CanRefund(item, ordrefstate, null);
                var hasAppendComment = ServiceProvider.Instance <ICommentService> .Create.HasAppendComment(orderitems.FirstOrDefault().Id);
                return(new
                {
                    OrderId = item.Id,
                    StatusText = statusText,
                    Status = item.OrderStatus,
                    orderType = item.OrderType,
                    orderTypeName = item.OrderType.ToDescription(),
                    shopname = item.ShopName,
                    vshopId = vshop == null ? 0 : vshop.Id,
                    Amount = item.OrderTotalAmount.ToString("F2"),
                    Quantity = OrderApplication.GetOrderTotalProductCount(item.Id),
                    commentCount = OrderApplication.GetOrderCommentCount(item.Id),
                    pickupCode = item.PickupCode,
                    EnabledRefundAmount = item.OrderEnabledRefundAmount,
                    LineItems = orderitems.Select(a =>
                    {
                        var prodata = productService.GetProduct(a.ProductId);
                        Entities.TypeInfo typeInfo = ServiceProvider.Instance <ITypeService> .Create.GetType(prodata.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 == a.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 = "退款成功";
                            }
                        }
                        return new
                        {
                            Status = itemrefstate,
                            StatusText = itemStatusText,
                            Id = a.SkuId,
                            productId = a.ProductId,
                            Name = a.ProductName,
                            Image = Core.MallIO.GetRomoteProductSizeImage(a.ThumbnailsUrl, 1, (int)Mall.CommonModel.ImageSize.Size_350),
                            Amount = a.Quantity,
                            Price = a.SalePrice,
                            Unit = prodata == null ? "" : prodata.MeasureUnit,
                            SkuText = colorAlias + ":" + a.Color + " " + sizeAlias + ":" + a.Size + " " + versionAlias + ":" + a.Version,
                            color = a.Color,
                            size = a.Size,
                            version = a.Version,
                            ColorAlias = (prodata != null && !string.IsNullOrWhiteSpace(prodata.ColorAlias)) ? prodata.ColorAlias : colorAlias,//如果商品有自定义规格名称则用
                            SizeAlias = (prodata != null && !string.IsNullOrWhiteSpace(prodata.SizeAlias)) ? prodata.SizeAlias : sizeAlias,
                            VersionAlias = (prodata != null && !string.IsNullOrWhiteSpace(prodata.VersionAlias)) ? prodata.VersionAlias : versionAlias,
                            RefundStats = itemrefstate,
                            OrderRefundId = (itemrefund == null ? 0 : itemrefund.Id),
                            EnabledRefundAmount = a.EnabledRefundAmount,
                            IsShowRefund = IsShowReturn,
                            IsShowAfterSale = IsShowReturn
                        };
                    }),
                    RefundStats = ordrefstate,
                    OrderRefundId = _ordrefobj.Id,
                    IsShowLogistics = !string.IsNullOrWhiteSpace(item.ShipOrderNumber) || item.DeliveryType == DeliveryType.ShopStore,
                    ShipOrderNumber = item.ShipOrderNumber,
                    IsShowCreview = (item.OrderStatus == Entities.OrderInfo.OrderOperateStatus.Finish && !hasAppendComment),
                    IsShowPreview = false,
                    //Invoice = item.InvoiceType.ToDescription(),
                    //InvoiceValue = (int)item.InvoiceType,
                    //InvoiceContext = item.InvoiceContext,
                    //InvoiceTitle = item.InvoiceTitle,
                    PaymentType = item.PaymentType.ToDescription(),
                    PaymentTypeValue = (int)item.PaymentType,
                    IsShowClose = (item.OrderStatus == Entities.OrderInfo.OrderOperateStatus.WaitPay),
                    IsShowFinishOrder = (item.OrderStatus == Entities.OrderInfo.OrderOperateStatus.WaitReceiving),
                    IsShowRefund = IsShowReturn,
                    IsShowReturn = IsShowReturn,
                    IsShowTakeCodeQRCode = (!string.IsNullOrWhiteSpace(item.PickupCode) && item.OrderStatus != Entities.OrderInfo.OrderOperateStatus.Finish && item.OrderStatus != Entities.OrderInfo.OrderOperateStatus.Close),
                    OrderDate = item.OrderDate,
                    SupplierId = 0,
                    ShipperName = string.Empty,
                    StoreName = shopBranchInfo != null ? shopBranchInfo.ShopBranchName : string.Empty,
                    IsShowCertification = false,
                    HasAppendComment = hasAppendComment,
                    CreviewText = OrderApplication.GetOrderCommentCount(item.Id) > 0 ? "追加评论" : "评价订单",
                    ProductCommentPoint = 0,
                    DeliveryType = (int)item.DeliveryType
                });
            });
            var statistic = StatisticApplication.GetMemberOrderStatistic(CurrentUser.Id);

            return(Json(
                       new
            {
                AllOrderCounts = statistic.OrderCount,
                WaitingForComments = statistic.WaitingForComments,
                WaitingForRecieve = statistic.WaitingForRecieve,
                WaitingForPay = statistic.WaitingForPay,
                Data = result
            }));
        }
Пример #13
0
        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));
        }
Пример #14
0
        public object GetOrders(int?orderStatus, int pageNo, int pageSize = 8)
        {
            CheckUserLogin();

            var orderStatistic = StatisticApplication.GetMemberOrderStatistic(CurrentUser.Id);

            var orderService = ServiceProvider.Instance <IOrderService> .Create;

            if (orderStatus.HasValue && orderStatus == 0)
            {
                orderStatus = null;
            }

            var queryModel = new OrderQuery()
            {
                Status   = (OrderInfo.OrderOperateStatus?)orderStatus,
                UserId   = CurrentUser.Id,
                PageSize = pageSize,
                PageNo   = pageNo,
                IsFront  = true
            };

            if (queryModel.Status.HasValue && queryModel.Status.Value == OrderInfo.OrderOperateStatus.WaitReceiving)
            {
                if (queryModel.MoreStatus == null)
                {
                    queryModel.MoreStatus = new List <OrderInfo.OrderOperateStatus>()
                    {
                    };
                }
                queryModel.MoreStatus.Add(OrderInfo.OrderOperateStatus.WaitSelfPickUp);
            }
            if (orderStatus.GetValueOrDefault() == (int)OrderInfo.OrderOperateStatus.Finish)
            {
                queryModel.Commented = false;//只查询未评价的订单
            }
            QueryPageModel <OrderInfo> orders = orderService.GetOrders <OrderInfo>(queryModel);
            var productService     = ServiceProvider.Instance <IProductService> .Create;
            var vshopService       = ServiceProvider.Instance <IVShopService> .Create;
            var orderRefundService = ServiceProvider.Instance <IRefundService> .Create;
            var orderItems         = OrderApplication.GetOrderItemsByOrderId(orders.Models.Select(p => p.Id));
            var orderRefunds       = OrderApplication.GetOrderRefunds(orderItems.Select(p => p.Id));
            //查询结果的门店ID
            var branchIds = orders.Models.Where(e => e.ShopBranchId > 0).Select(p => p.ShopBranchId).ToList();
            //根据门店ID获取门店信息
            var shopBranchs = ShopBranchApplication.GetShopBranchByIds(branchIds);

            //TODO:FG 关联数据查询提取至循环外层
            var result = orders.Models.Select(order =>
            {
                if (order.OrderStatus >= OrderInfo.OrderOperateStatus.WaitDelivery)
                {
                    orderService.CalculateOrderItemRefund(order.Id);
                }
                var vshop      = vshopService.GetVShopByShopId(order.ShopId);
                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 branchObj     = shopBranchs.FirstOrDefault(e => e.Id == order.ShopBranchId);
                string branchName = branchObj == null ? string.Empty : branchObj.ShopBranchName;
                //参照PC端会员中心的状态描述信息
                string statusText = order.OrderStatus.ToDescription();
                if (order.OrderStatus == OrderInfo.OrderOperateStatus.WaitDelivery || order.OrderStatus == OrderInfo.OrderOperateStatus.WaitSelfPickUp)
                {
                    if (ordrefstate.HasValue && ordrefstate != 0 && ordrefstate != 4)
                    {
                        statusText = "退款中";
                    }
                }
                var hasAppendComment = ServiceProvider.Instance <ICommentService> .Create.HasAppendComment(orderItems.FirstOrDefault(d => d.OrderId == order.Id).Id);
                return(new
                {
                    id = order.Id,
                    status = statusText,
                    orderStatus = order.OrderStatus,
                    orderType = order.OrderType,
                    orderTypeName = order.OrderType.ToDescription(),
                    shopname = order.ShopName,
                    vshopId = vshop == null ? 0 : vshop.Id,
                    orderTotalAmount = order.OrderTotalAmount.ToString("F2"),
                    productCount = OrderApplication.GetOrderTotalProductCount(order.Id),
                    commentCount = OrderApplication.GetOrderComment(order.Id).Count,
                    pickupCode = order.PickupCode,
                    ShopBranchId = order.ShopBranchId,
                    ShopBranchName = branchName,
                    EnabledRefundAmount = order.OrderEnabledRefundAmount,
                    itemInfo = orderItems.Where(oi => oi.OrderId == order.Id).Select(a =>
                    {
                        var prodata = productService.GetProduct(a.ProductId);
                        TypeInfo typeInfo = ServiceProvider.Instance <ITypeService> .Create.GetType(prodata.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 (prodata != null)
                        {
                            colorAlias = !string.IsNullOrWhiteSpace(prodata.ColorAlias) ? prodata.ColorAlias : colorAlias;
                            sizeAlias = !string.IsNullOrWhiteSpace(prodata.SizeAlias) ? prodata.SizeAlias : sizeAlias;
                            versionAlias = !string.IsNullOrWhiteSpace(prodata.VersionAlias) ? prodata.VersionAlias : versionAlias;
                        }
                        var itemrefund = orderRefunds.Where(or => or.OrderItemId == a.Id).FirstOrDefault(d => d.RefundMode != OrderRefundInfo.OrderRefundMode.OrderRefund);
                        int?itemrefstate = (itemrefund == null ? null : (int?)itemrefund.SellerAuditStatus);
                        itemrefstate = (itemrefstate > 4 ? (int?)itemrefund.ManagerConfirmStatus : itemrefstate);

                        return new
                        {
                            productId = a.ProductId,
                            productName = a.ProductName,
                            image = Core.HimallIO.GetRomoteProductSizeImage(a.ThumbnailsUrl, 1, (int)Himall.CommonModel.ImageSize.Size_350),
                            count = a.Quantity,
                            price = a.SalePrice,
                            Unit = prodata == null ? "" : prodata.MeasureUnit,
                            color = a.Color,
                            size = a.Size,
                            version = a.Version,
                            ColorAlias = colorAlias,
                            SizeAlias = sizeAlias,
                            VersionAlias = versionAlias,
                            RefundStats = itemrefstate,
                            OrderRefundId = (itemrefund == null ? 0 : itemrefund.Id),
                            EnabledRefundAmount = a.EnabledRefundAmount
                        };
                    }),
                    RefundStats = ordrefstate,
                    OrderRefundId = _ordrefobj.Id,
                    HasExpressStatus = !string.IsNullOrWhiteSpace(order.ShipOrderNumber),
                    HasAppendComment = hasAppendComment,
                    //Invoice = order.InvoiceType.ToDescription(),
                    //InvoiceValue = (int)order.InvoiceType,
                    //InvoiceContext = order.InvoiceContext,
                    //InvoiceTitle = order.InvoiceTitle,
                    PaymentType = order.PaymentType.ToDescription(),
                    PaymentTypeValue = (int)order.PaymentType,
                    CanRefund = OrderApplication.CanRefund(order, itemId: 0),
                    IsVirtual = order.OrderType == OrderInfo.OrderTypes.Virtual ? 1 : 0,
                    IsPay = order.PayDate.HasValue ? 1 : 0
                });
            });

            return(new
            {
                success = true,
                AllOrderCounts = orderStatistic.OrderCount,
                WaitingForComments = orderStatistic.WaitingForComments,
                WaitingForRecieve = orderStatistic.WaitingForRecieve + OrderApplication.GetWaitConsumptionOrderNumByUserId(CurrentUser.Id),
                WaitingForPay = orderStatistic.WaitingForPay,
                Orders = result
            });
        }
Пример #15
0
        /// <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 });
            }
        }