コード例 #1
0
ファイル: CommentController.cs プロジェクト: redpanda321/Mall
        public object GetComment(long orderId)
        {
            CheckUserLogin();
            var order = ServiceProvider.Instance <IOrderService> .Create.GetOrder(orderId);

            var comments = OrderApplication.GetOrderComment(orderId);

            if (order != null && comments.Count == 0)
            {
                var model = ServiceProvider.Instance <ICommentService> .Create.GetProductEvaluationByOrderId(orderId, CurrentUser.Id).Select(item => new
                {
                    item.ProductId,
                    item.ProductName,
                    Image = Core.MallIO.GetRomoteProductSizeImage(item.ThumbnailsUrl, 1, (int)Mall.CommonModel.ImageSize.Size_220) //商城App评论时获取商品图片
                });

                var orderEvaluation = ServiceProvider.Instance <ITradeCommentService> .Create.GetOrderCommentInfo(orderId, CurrentUser.Id);

                var orderitems = OrderApplication.GetOrderItems(order.Id);
                var isVirtual  = order.OrderType == Mall.Entities.OrderInfo.OrderTypes.Virtual ? 1 : 0;
                return(new { success = true, Product = model, orderItemIds = orderitems.Select(item => item.Id), isVirtual = isVirtual });
            }
            else
            {
                throw new MallApiException("该订单不存在或者已评论过");
            }
        }
コード例 #2
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
            });
        }