예제 #1
0
        /// <summary>
        /// 获取已付款和已打印的订单,同时会调用接口下载订单
        /// </summary>
        /// <param name="payType">支付类型</param>
        /// <returns></returns>
        public static List <Order> DownloadOrder(PopPayType payType, string shipper)
        {
            var allShops             = ServiceContainer.GetService <ShopService>().GetByAll().Datas.Where(obj => obj.Enabled).ToList();
            var allAppEnabledShops   = allShops.Where(obj => obj.AppEnabled).ToArray();
            var allAppUnEnabledShops = allShops.Where(obj => obj.AppEnabled == false).ToArray();

            if (allShops.Count < 1)
            {
                return(new List <Order>());
            }

            string mode = LocalConfigService.GetValue(SystemNames.CONFIG_ORDER_DOWNLOAD_MODE, "").Trim();

            if (mode.Equals("本地读取"))
            {
                return(ServiceContainer.GetService <OrderService>().GetPayedAndPrintedOrders(null, OrderCreateType.NONE, payType, shipper, 0, 0).Datas.OrderBy(obj => obj.ShopId).ToList());
            }

            OrderDownloadWindow win = new OrderDownloadWindow()
            {
                PayType = payType
            };
            var ret = win.ShowDialog();

            if (ret == null || ret.Value == false)
            {
                return(new List <Order>());
            }
            var onlineOrders = win.Orders.Where(obj => obj.PopPayType == payType).ToList();

            if (allAppEnabledShops.Length > 0)
            {
                //对于采用自动下载订单的店铺,需要再读取其手动创建的订单
                var orders = ServiceContainer.GetService <OrderService>().GetPayedAndPrintedOrders(allAppEnabledShops.Select(obj => obj.Id).ToArray(), OrderCreateType.MANUAL, payType, shipper, 0, 0).Datas;
                if (orders.Count > 0)
                {
                    onlineOrders.AddRange(orders);
                }
            }

            if (allAppUnEnabledShops.Length > 0)
            {
                //对于没有自动下载的订单需要读取所有的订单
                var orders = ServiceContainer.GetService <OrderService>().GetPayedAndPrintedOrders(allAppUnEnabledShops.Select(obj => obj.Id).ToArray(), OrderCreateType.NONE, payType, shipper, 0, 0).Datas;
                if (orders.Count > 0)
                {
                    onlineOrders.AddRange(orders);
                }
            }
            if (string.IsNullOrWhiteSpace(shipper))
            {
                return(onlineOrders);
            }

            var retOrders = new List <Order>();

            foreach (var o in onlineOrders)
            {
                if (o.OrderGoodss == null || o.OrderGoodss.Count < 0)
                {
                    continue;
                }

                if (o.OrderGoodss.Any(obj => obj.Shipper.Equals(shipper, StringComparison.OrdinalIgnoreCase)))
                {
                    retOrders.Add(o);
                }
            }

            return(retOrders);
        }