示例#1
0
        public List <CommodityInfoDTO> GetGoodsByClassify(int commodityCategoryId)
        {
            Core.Data.QueryResult <CCommodityPropertyPO> resultCCommodityProperty;
            Core.Data.QueryResult <CPropertyCategoryPO>  resultPropertyCategory;
            if (commodityCategoryId <= 0)
            {
                throw new BusinessException("商品类别错误");
            }
            List <CommodityInfoDTO> listCommodity = new List <CommodityInfoDTO>();
            CCommodityCategoryPO    po            = this.GetById(commodityCategoryId);

            if (po != null)
            {
                int?          id = null;
                List <string> commodityCategoryUUIDs = new List <string> {
                    po.CommodityCategoryUUID
                };
                List <int> states = new List <int> {
                    1
                };
                Core.Data.QueryResult <CCommodityPO> resultCommodity = CCommodityManager.Instance.GetCCommoditys(id, null, null, commodityCategoryUUIDs, states, 1, 1, null);
                if (((resultCommodity == null) || (resultCommodity.Items == null)) || (resultCommodity.Items.Length == 0))
                {
                    return(listCommodity);
                }
                if (resultCommodity.TotalCount > 1)
                {
                    List <string> list3 = new List <string> {
                        po.CommodityCategoryUUID
                    };
                    List <int> list4 = new List <int> {
                        1
                    };
                    resultCommodity = CCommodityManager.Instance.GetCCommoditys(null, null, null, list3, list4, 1, (int)resultCommodity.TotalCount, null);
                }
                List <string> commodityUUIDs = new List <string>();
                if ((resultCommodity.Items != null) && (resultCommodity.Items.Length > 0))
                {
                    commodityUUIDs = resultCommodity.Items.Select(x => x.CommodityUUID).Distinct <string>().ToList <string>();
                }
                resultCCommodityProperty = CCommodityPropertyManager.Instance.GetCommodityPropertys(null, po.ResUUID, null, commodityUUIDs, null, 1, 1);
                if (((resultCCommodityProperty != null) && (resultCCommodityProperty.Items != null)) && (resultCCommodityProperty.TotalCount > 1))
                {
                    resultCCommodityProperty = CCommodityPropertyManager.Instance.GetCommodityPropertys(null, po.ResUUID, null, commodityUUIDs, null, 1, (int)resultCCommodityProperty.TotalCount);
                }
                List <string> listPropertyCategory = new List <string>();
                if (((resultCCommodityProperty != null) && (resultCCommodityProperty.Items != null)) && (resultCCommodityProperty.Items.Length > 0))
                {
                    listPropertyCategory = resultCCommodityProperty.Items.Select(x => x.PropertyCategoryUUID).Distinct <string>().ToList <string>();
                }
                resultPropertyCategory = new Core.Data.QueryResult <CPropertyCategoryPO>();
                if ((listPropertyCategory != null) && (listPropertyCategory.Count > 0))
                {
                    resultPropertyCategory = CPropertyCategoryManager.Instance.GetPropertyCategorys(po.ResUUID, listPropertyCategory, 1, 1);
                }
                if (((resultPropertyCategory != null) && (resultPropertyCategory.Items != null)) && (resultPropertyCategory.TotalCount > 1))
                {
                    resultPropertyCategory = CPropertyCategoryManager.Instance.GetPropertyCategorys(po.ResUUID, listPropertyCategory, 1, (int)resultPropertyCategory.TotalCount);
                }
                CommodityCategoryInfoDTO odto1 = new CommodityCategoryInfoDTO
                {
                    Id          = po.Id,
                    ChineseName = po.ChineseName,
                    EnglishName = po.EnglishName,
                    PicPath     = po.PicPath
                };
                CommodityCategoryInfoDTO commodityCategoryInfo = odto1;
                List <CCommodityPO>      listCCommodity        = (from x in resultCommodity.Items
                                                                  where x.CommodityCategoryUUID == po.CommodityCategoryUUID
                                                                  select x).ToList <CCommodityPO>();
                if (listCCommodity == null)
                {
                    return(listCommodity);
                }
                commodityCategoryInfo.GoodsList = listCommodity;
                listCCommodity.ForEach(delegate(CCommodityPO itemCommodity)
                {
                    if (itemCommodity != null)
                    {
                        CommodityInfoDTO odto11 = new CommodityInfoDTO
                        {
                            ChineseName = itemCommodity.ChineseName,
                            EnglishName = itemCommodity.EnglishName,
                            Id          = itemCommodity.Id,
                            Price       = itemCommodity.Price.HasValue ? itemCommodity.Price.Value : decimal.Zero,
                            ShowRemark  = itemCommodity.ShowRemark,
                            Type        = itemCommodity.Type,
                            PicPath     = itemCommodity.PicPath
                        };
                        CommodityInfoDTO commodityInfoDTO = odto11;
                        listCommodity.Add(commodityInfoDTO);
                        List <CCommodityPropertyPO> listCommodityProperty = (from x in resultCCommodityProperty.Items
                                                                             where x.CommodityUUID == itemCommodity.CommodityUUID
                                                                             select x).ToList <CCommodityPropertyPO>();
                        if ((listCommodityProperty != null) && (listCommodityProperty.Count != 0))
                        {
                            List <string> listPropertyCategoryUUID = listCommodityProperty.Select <CCommodityPropertyPO, string>(x => x.PropertyCategoryUUID).Distinct <string>().ToList <string>();
                            List <PropertyCategoryInfoDTO> listPropertyCategoryInfo = new List <PropertyCategoryInfoDTO>();
                            listPropertyCategoryUUID.ForEach(delegate(string itemPropertyCategoryUUID)
                            {
                                if (!string.IsNullOrWhiteSpace(itemPropertyCategoryUUID))
                                {
                                    CPropertyCategoryPO propertyCategoryPO = resultPropertyCategory.Items.FirstOrDefault <CPropertyCategoryPO>(x => x.PropertyCategoryUUID == itemPropertyCategoryUUID);
                                    if (propertyCategoryPO != null)
                                    {
                                        PropertyCategoryInfoDTO odto2 = new PropertyCategoryInfoDTO
                                        {
                                            ChineseName    = propertyCategoryPO.ChineseName,
                                            EnableMultiple = propertyCategoryPO.EnableMultiple,
                                            EnglishName    = propertyCategoryPO.EnglishName,
                                            Id             = propertyCategoryPO.Id,
                                            Type           = propertyCategoryPO.Type,
                                            Sort           = propertyCategoryPO.Sort
                                        };
                                        PropertyCategoryInfoDTO propertyCategoryInfoDTO = odto2;
                                        listPropertyCategoryInfo.Add(propertyCategoryInfoDTO);
                                        List <CCommodityPropertyPO> listCommodityPropertyOther = (from x in listCommodityProperty
                                                                                                  where x.PropertyCategoryUUID == itemPropertyCategoryUUID
                                                                                                  select x).ToList <CCommodityPropertyPO>();
                                        if (listCommodityPropertyOther != null)
                                        {
                                            List <CCommodityPropertyInfoDTO> commodityPropertyInfos = new List <CCommodityPropertyInfoDTO>();
                                            propertyCategoryInfoDTO.List = commodityPropertyInfos;
                                            listCommodityPropertyOther.ForEach(delegate(CCommodityPropertyPO x)
                                            {
                                                if (x != null)
                                                {
                                                    CCommodityPropertyInfoDTO odto3 = new CCommodityPropertyInfoDTO
                                                    {
                                                        AddPrice    = x.AddPrice.HasValue ? x.AddPrice.Value : decimal.Zero,
                                                        ChineseName = x.ChineseName,
                                                        EnglishName = x.EnglishName,
                                                        Id          = x.Id
                                                    };
                                                    CCommodityPropertyInfoDTO commodityPropertyInfo = odto3;
                                                    commodityPropertyInfos.Add(commodityPropertyInfo);
                                                }
                                            });
                                        }
                                    }
                                }
                            });
                            commodityInfoDTO.SkuInfo = listPropertyCategoryInfo.OrderByDescending(x => x.Sort).ToList <PropertyCategoryInfoDTO>();
                        }
                    }
                });
            }
            return(listCommodity);
        }
示例#2
0
        public List <CommodityCategoryInfoDTO> GetCommodityCategory(int resId)
        {
            Core.Data.QueryResult <CCommodityPropertyPO> resultCCommodityProperty;
            Core.Data.QueryResult <CPropertyCategoryPO>  resultPropertyCategory;
            if (resId <= 0)
            {
                throw new BusinessException("餐厅ID不正确");
            }
            CRestaurantPO restaurant = CRestaurantManager.Instance.GetById(resId);

            if (restaurant == null)
            {
                throw new BusinessException("餐厅不存在");
            }
            List <CommodityCategoryInfoDTO> listCommodityCategoryInfo = new List <CommodityCategoryInfoDTO>();

            Core.Data.QueryResult <CCommodityCategoryPO> queryCommodityCategory = this.GetCommodityCategorys(restaurant.ResUUID, null, 1, 1);

            if (queryCommodityCategory.TotalCount != 0)
            {
                queryCommodityCategory = this.GetCommodityCategorys(restaurant.ResUUID, null, 1, (int)queryCommodityCategory.TotalCount);
                List <string> listCommodityCategory = new List <string>();
                if ((queryCommodityCategory.Items != null) && (queryCommodityCategory.Items.Length > 0))
                {
                    listCommodityCategory = queryCommodityCategory.Items.Select(x => x.CommodityCategoryUUID).Distinct <string>().ToList <string>();
                }
                int?       id     = null;
                List <int> states = new List <int> {
                    1
                };
                Core.Data.QueryResult <CCommodityPO> resultCommodity = CCommodityManager.Instance.GetCCommoditys(id, restaurant.ResUUID, null, listCommodityCategory, states, 1, 1, null);
                if (((resultCommodity == null) || (resultCommodity.Items == null)) || (resultCommodity.Items.Length == 0))
                {
                    return(listCommodityCategoryInfo);
                }
                if (resultCommodity.TotalCount > 1)
                {
                    List <int> list2 = new List <int> {
                        1
                    };
                    resultCommodity = CCommodityManager.Instance.GetCCommoditys(null, restaurant.ResUUID, null, listCommodityCategory, list2, 1, (int)resultCommodity.TotalCount, null);
                }
                List <string> commodityUUIDs = new List <string>();
                if ((resultCommodity.Items != null) && (resultCommodity.Items.Length > 0))
                {
                    commodityUUIDs = resultCommodity.Items.Select(x => x.CommodityUUID).Distinct <string>().ToList <string>();
                }
                resultCCommodityProperty = CCommodityPropertyManager.Instance.GetCommodityPropertys(null, restaurant.ResUUID, null, commodityUUIDs, null, 1, 1);
                if (((resultCCommodityProperty != null) && (resultCCommodityProperty.Items != null)) && (resultCCommodityProperty.TotalCount > 1))
                {
                    resultCCommodityProperty = CCommodityPropertyManager.Instance.GetCommodityPropertys(null, restaurant.ResUUID, null, commodityUUIDs, null, 1, (int)resultCCommodityProperty.TotalCount);
                }
                List <string> listPropertyCategory = new List <string>();
                if (((resultCCommodityProperty != null) && (resultCCommodityProperty.Items != null)) && (resultCCommodityProperty.Items.Length > 0))
                {
                    listPropertyCategory = resultCCommodityProperty.Items.Select(x => x.PropertyCategoryUUID).Distinct <string>().ToList <string>();
                }
                resultPropertyCategory = new Core.Data.QueryResult <CPropertyCategoryPO>();
                if ((listPropertyCategory != null) && (listPropertyCategory.Count > 0))
                {
                    resultPropertyCategory = CPropertyCategoryManager.Instance.GetPropertyCategorys(restaurant.ResUUID, listPropertyCategory, 1, 1);
                }
                if (((resultPropertyCategory != null) && (resultPropertyCategory.Items != null)) && (resultPropertyCategory.TotalCount > 1))
                {
                    resultPropertyCategory = CPropertyCategoryManager.Instance.GetPropertyCategorys(restaurant.ResUUID, listPropertyCategory, 1, (int)resultPropertyCategory.TotalCount);
                }
                CCommodityCategoryPO[] items = queryCommodityCategory.Items;

                for (int i = 0; i < items.Length; i++)
                {
                    CCommodityCategoryPO    itemCommodityCategory = items[i];
                    List <CommodityInfoDTO> listCommodityInfoD;
                    if (itemCommodityCategory != null)
                    {
                        CommodityCategoryInfoDTO odto1 = new CommodityCategoryInfoDTO
                        {
                            Id          = itemCommodityCategory.Id,
                            ChineseName = itemCommodityCategory.ChineseName,
                            EnglishName = itemCommodityCategory.EnglishName,
                            PicPath     = itemCommodityCategory.PicPath
                        };
                        CommodityCategoryInfoDTO commodityCategoryInfo = odto1;
                        listCommodityCategoryInfo.Add(commodityCategoryInfo);
                        List <CCommodityPO> listCCommodity = resultCommodity.Items.Where(x => x.CommodityCategoryUUID == itemCommodityCategory.CommodityCategoryUUID).ToList();

                        if (listCCommodity != null)
                        {
                            listCommodityInfoD = new List <CommodityInfoDTO>();
                            commodityCategoryInfo.GoodsList = listCommodityInfoD;
                            listCCommodity.ForEach(delegate(CCommodityPO itemCommodity)
                            {
                                if (itemCommodity != null)
                                {
                                    CommodityInfoDTO odto2 = new CommodityInfoDTO
                                    {
                                        ChineseName = itemCommodity.ChineseName,
                                        EnglishName = itemCommodity.EnglishName,
                                        Id          = itemCommodity.Id,
                                        Price       = itemCommodity.Price.HasValue ? itemCommodity.Price.Value : decimal.Zero,
                                        ShowRemark  = itemCommodity.ShowRemark,
                                        Type        = itemCommodity.Type,
                                        PicPath     = itemCommodity.PicPath
                                    };
                                    CommodityInfoDTO commodityInfoDTO = odto2;
                                    listCommodityInfoD.Add(commodityInfoDTO);
                                    List <CCommodityPropertyPO> listCommodityProperty = (from x in resultCCommodityProperty.Items
                                                                                         where x.CommodityUUID == itemCommodity.CommodityUUID
                                                                                         select x).ToList <CCommodityPropertyPO>();
                                    if ((listCommodityProperty != null) && (listCommodityProperty.Count != 0))
                                    {
                                        List <string> listPropertyCategoryUUID = listCommodityProperty.Select(x => x.PropertyCategoryUUID).Distinct <string>().ToList <string>();
                                        List <PropertyCategoryInfoDTO> listPropertyCategoryInfo = new List <PropertyCategoryInfoDTO>();
                                        commodityInfoDTO.SkuInfo = listPropertyCategoryInfo;
                                        listPropertyCategoryUUID.ForEach(delegate(string itemPropertyCategoryUUID)
                                        {
                                            if (!string.IsNullOrWhiteSpace(itemPropertyCategoryUUID))
                                            {
                                                CPropertyCategoryPO propertyCategoryPO = resultPropertyCategory.Items.FirstOrDefault <CPropertyCategoryPO>(x => x.PropertyCategoryUUID == itemPropertyCategoryUUID);
                                                if (propertyCategoryPO != null)
                                                {
                                                    PropertyCategoryInfoDTO odto3 = new PropertyCategoryInfoDTO
                                                    {
                                                        ChineseName    = propertyCategoryPO.ChineseName,
                                                        EnableMultiple = propertyCategoryPO.EnableMultiple,
                                                        EnglishName    = propertyCategoryPO.EnglishName,
                                                        Id             = propertyCategoryPO.Id,
                                                        Type           = propertyCategoryPO.Type
                                                    };
                                                    PropertyCategoryInfoDTO propertyCategoryInfoDTO = odto3;
                                                    listPropertyCategoryInfo.Add(propertyCategoryInfoDTO);
                                                    List <CCommodityPropertyPO> listCommodityPropertyOther = (from x in listCommodityProperty
                                                                                                              where x.PropertyCategoryUUID == itemPropertyCategoryUUID
                                                                                                              select x).ToList <CCommodityPropertyPO>();
                                                    if (listCommodityPropertyOther != null)
                                                    {
                                                        List <CCommodityPropertyInfoDTO> commodityPropertyInfos = new List <CCommodityPropertyInfoDTO>();
                                                        propertyCategoryInfoDTO.List = commodityPropertyInfos;
                                                        listCommodityPropertyOther.ForEach(delegate(CCommodityPropertyPO x) {
                                                            if (x != null)
                                                            {
                                                                CCommodityPropertyInfoDTO odto4 = new CCommodityPropertyInfoDTO
                                                                {
                                                                    AddPrice    = x.AddPrice.HasValue ? x.AddPrice.Value : decimal.Zero,
                                                                    ChineseName = x.ChineseName,
                                                                    EnglishName = x.EnglishName,
                                                                    Id          = x.Id
                                                                };
                                                                CCommodityPropertyInfoDTO commodityPropertyInfo = odto4;
                                                                commodityPropertyInfos.Add(commodityPropertyInfo);
                                                            }
                                                        });
                                                    }
                                                }
                                            }
                                        });
                                    }
                                }
                            });
                        }
                    }
                }
            }

            return(listCommodityCategoryInfo);
        }