Пример #1
0
        public virtual void List(int id, long page = 1, Arguments args = null)
        {
            //int temp;
            //do
            //{
            //    temp = M.ProductCategory.GetDefaultChild(DataSource, id);
            //    if (temp > 0)
            //        id = temp;
            //}
            //while (temp > 0);

            IList <M.ProductCategory> cates = M.ProductCategory.GetAllParentsById(DataSource, id);

            IList <M.ProductAttribute> attrs  = M.ProductAttribute.GetAllByCategory(DataSource, id);
            FilterParameters           filter = new FilterParameters(attrs);

            filter.Load(page, args);

            this["Filter"]          = filter;
            this["Category"]        = M.ProductCategory.GetById(DataSource, id);
            this["CategoryList"]    = cates;
            this["BigCategoryList"] = M.ProductCategory.GetAll(DataSource, cates[0].Id);
            if (cates.Count > 1)
            {
                this["SmallCategoryList"] = M.ProductCategory.GetAll(DataSource, cates[1].Id);
            }
            if (cates.Count > 2)
            {
                this["ThreeCategoryList"] = M.ProductCategory.GetAll(DataSource, cates[2].Id);
            }
            this["BrandList"]     = M.ProductBrand.GetAllByCategory(DataSource, id);
            this["AttributeList"] = attrs;
            this["RecommendList"] = M.Product.GetTopRecommendByCategory(DataSource, 5, id);
            this["ProductList"]   = M.Product.GetBrandPageByArguments(DataSource, id, false, filter, cates.Count, 5);

            this["PageUrl"] = new FuncHandler((object[] ps) =>
            {
                return(GetUrl("/category/list/", id.ToString(), filter.CopyByPage(Convert.ToInt64(ps[0])).ToString()));
            });
            this["BrandUrl"] = new FuncHandler((object[] ps) =>
            {
                return(GetUrl("/category/list/", id.ToString(), filter.CopyByBrand(Convert.ToInt32(ps[0])).ToString()));
            });
            this["OrderUrl"] = new FuncHandler((object[] ps) =>
            {
                return(GetUrl("/category/list/", id.ToString(), filter.CopyByOrderBy(Convert.ToInt32(ps[0])).ToString()));
            });
            this["AttrUrl"] = new FuncHandler((object[] ps) =>
            {
                return(GetUrl("/category/list/", id.ToString(), filter.Copy(Convert.ToInt64(ps[0]), ps[1] as string).ToString()));
            });

            long index = filter.Page;

            filter.Page = 1;
            SplitPageData <DataJoin <M.Product, S.StatisticData> > BrandList = M.Product.GetBrandPageByArguments(DataSource, id, true, filter, cates.Count, 4, 8);

            if (BrandList.PagesCount >= index)
            {
                filter.Page = index;
            }
            else
            {
                filter.Page = BrandList.PagesCount;
            }
            this["BrandProductList"] = M.Product.GetBrandPageByArguments(DataSource, id, true, filter, cates.Count, 4, 8);
            Render("category.html");
        }
Пример #2
0
        //public static SplitPageData<Distributor> GetPage(DataSource ds, string state, long index, int size, int show = 11)
        //{
        //    long count;
        //    IList<Distributor> list;
        //    if ("_".Equals(state))
        //    {
        //        list = Db<Distributor>.Query(ds)
        //            .Select()
        //            .OrderBy(D("CreationDate"))
        //            .ToList<Distributor>(size, index, out count);
        //    }
        //    else
        //    {
        //        list = Db<Distributor>.Query(ds)
        //            .Select()
        //            .Where(W("State", Enum.Parse(TType<DistributorState>.Type, state)))
        //            .OrderBy(D("CreationDate"))
        //            .ToList<Distributor>(size, index, out count);
        //    }
        //    return new SplitPageData<Distributor>(index, size, list, count, show);
        //}

        public static dynamic GetMoneyByParent(DataSource ds, long parent, long index, int size, int show = 8)
        {
            Distributor dis = GetById(ds, parent);

            int level = dis.Level;

            long[]      temp;
            List <long> all = new List <long>();

            all.Add(parent);
            Dictionary <int, long[]> dict = new Dictionary <int, long[]>();

            dict.Add(level, new long[] { parent });

            while (++level < 5)
            {
                if (dict.TryGetValue(level - 1, out temp) && temp != null && temp.Length > 0)
                {
                    temp = Db <Distributor> .Query(ds)
                           .Select(S("UserId"))
                           .Where(W("ParentId", temp, DbWhereType.In) & W("State", -1, DbWhereType.NotEqual))
                           .ToArray <long>();

                    if (temp != null && temp.Length > 0)
                    {
                        all.AddRange(temp);
                        dict.Add(level, temp);
                    }
                }
            }

            double               value;
            double               total  = 0;
            double               money  = 0;
            DateTime             now    = DateTime.Now.AddDays(-7);
            IList <ProductOrder> orders = Db <ProductOrder> .Query(ds)
                                          .Select(S("ShopId"), S("TotalMoney"), S("FreightMoney"), S("ReceiptDate"))
                                          .Where(W("ShopId", all, DbWhereType.In) & (/*W("State", OrderState.Evaluation) | */ W("State", OrderState.Finished)))
                                          .ToList <ProductOrder>();

            foreach (ProductOrder order in orders)
            {
                value  = dis.GetRoyalty(order);
                total += value;
                if (order.ReceiptDate <= now)
                {
                    money += value;
                }
            }

            long count;
            IList <ProductOrder> list = Db <ProductOrder> .Query(ds)
                                        .Select()
                                        .Where(W("ShopId", all, DbWhereType.In) & (/*W("State", OrderState.Evaluation) | */ W("State", OrderState.Finished)))
                                        .OrderBy(D("CreationDate"))
                                        .ToList <ProductOrder>(size, index, out count);

            SplitPageData <ProductOrder> data = new SplitPageData <ProductOrder>(index, size, list, count, show);

            return(new
            {
                Total = total,
                Money = money,
                Data = data
            });
        }
Пример #3
0
 public FilterData(FilterParameters filter, SplitPageData <T> data)
 {
     _filter = filter;
     _data   = data;
 }