示例#1
0
        private ListResult <ProductListItem> GetSuggestProducts(int siteId, string userId, string appId, int count)
        {
            //猜你喜欢没有实现,准确的应该按客户的浏览历史来
            int    intUserId = 0;
            string username  = "";

            Member member = GetMember(userId.ToSeesionId());

            if (member != null)
            {
                intUserId = member.UserId;
                username  = member.Username;
            }

            DataTable dt = ProductBrowser.GetSuggestProducts(intUserId, username, count);     //TODO

            List <ProductListItem> products = new List <ProductListItem>();

            if (dt != null)
            {
                ProductListItem item = null;

                foreach (DataRow row in dt.Rows)
                {
                    item = new ProductListItem();

                    item.ProductId = 0;
                    if (row["ProductId"] != DBNull.Value)
                    {
                        item.ProductId = (int)row["ProductId"];
                    }

                    item.CategoryId = 0;
                    if (row["CategoryId"] != DBNull.Value)
                    {
                        item.CategoryId = (int)row["CategoryId"];
                    }

                    item.Title = "";
                    if (row["ProductName"] != DBNull.Value)
                    {
                        item.Title = (string)row["ProductName"];
                    }

                    item.ImageUrl = "";
                    if (row["ThumbnailUrl220"] != DBNull.Value)
                    {
                        item.ImageUrl = Util.AppendImageHost((string)row["ThumbnailUrl220"]);
                    }

                    item.SalePrice = 0;
                    if (row["SalePrice"] != DBNull.Value)
                    {
                        item.SalePrice = (decimal)row["SalePrice"];
                    }

                    item.MarketPrice = 0;
                    if (row["MarketPrice"] != DBNull.Value)
                    {
                        item.MarketPrice = (decimal)row["MarketPrice"];
                    }


                    item.Quantity = 0;
                    if (row["Stock"] != DBNull.Value)
                    {
                        item.Quantity = (int)row["Stock"];
                    }

                    item.HasSku = false;
                    if (row["fastbuy_skuid"] != DBNull.Value)
                    {
                        item.SkuId  = (string)row["fastbuy_skuid"];
                        item.HasSku = item.SkuId.Equals("");
                    }

                    if (item.HasSku)
                    {
                        item.SkuItems = this.GetSkuItems(item.ProductId);
                        item.Skus     = this.GetSkus(ProductBrowser.GetProductSkus(item.ProductId));
                    }

                    item.ShortDescription = "";
                    if (row["ShortDescription"] != DBNull.Value)
                    {
                        item.ShortDescription = (string)row["ShortDescription"];
                    }

                    if (row["IsCollect"] != DBNull.Value)
                    {
                        item.IsCollect = (int)row["IsCollect"];
                    }

                    item.ShortDescription = "";
                    if (row["ShortDescription"] != DBNull.Value)
                    {
                        item.ShortDescription = (string)row["ShortDescription"];
                    }

                    item.IsCustomsClearance = false;
                    if (row["IsCustomsClearance"] != DBNull.Value)
                    {
                        item.IsCustomsClearance = (bool)row["IsCustomsClearance"];
                    }

                    item.IsFreeShipping = false;
                    if (row["IsfreeShipping"] != DBNull.Value)
                    {
                        item.IsFreeShipping = (bool)row["IsfreeShipping"];
                    }

                    item.ShippingMode = "";
                    if (row["ShippingMode"] != DBNull.Value)
                    {
                        item.ShippingMode = (string)row["ShippingMode"];
                    }



                    item.SaleCounts = 0;
                    if (row["SaleCounts"] != DBNull.Value)
                    {
                        item.SaleCounts = (int)row["SaleCounts"];
                    }

                    item.VistiCounts = 0;
                    if (row["VistiCounts"] != DBNull.Value)
                    {
                        item.VistiCounts = (int)row["VistiCounts"];
                    }

                    item.BuyCardinality = 1;
                    if (row["BuyCardinality"] != DBNull.Value)
                    {
                        item.BuyCardinality = (int)row["BuyCardinality"];
                    }

                    item.Icon = "";
                    if (row["Icon"] != DBNull.Value)
                    {
                        item.Icon = Util.AppendImageHost((string)row["Icon"]);
                    }

                    item.ShopName = "";
                    if (row["ShopName"] != DBNull.Value)
                    {
                        item.ShopName = (string)row["ShopName"];
                    }

                    bool IsDisplayDiscount = false;
                    if (row["IsDisplayDiscount"] != DBNull.Value)
                    {
                        IsDisplayDiscount = (bool)row["IsDisplayDiscount"];
                    }

                    item.Discount = "";
                    if (IsDisplayDiscount && item.MarketPrice > 0)
                    {
                        item.Discount = (item.SalePrice * 10 / item.MarketPrice).ToString("0.00") + "折";
                    }

                    decimal mintaxrate = 0M;
                    if (row["MinTaxRate"] != System.DBNull.Value)
                    {
                        mintaxrate = (decimal)row["MinTaxRate"];
                    }

                    decimal maxtaxrate = 0M;
                    if (row["MaxTaxRate"] != System.DBNull.Value)
                    {
                        maxtaxrate = (decimal)row["MaxTaxRate"];
                    }


                    item.TaxRate = 0;
                    if (row["TaxRate"] != DBNull.Value)
                    {
                        item.TaxRate = (decimal)row["TaxRate"];
                    }

                    item.ExtendTaxRate = item.GetExtendTaxRate(item.TaxRate, mintaxrate, maxtaxrate);

                    products.Add(item);
                }
            }

            ListResult <ProductListItem> data = new ListResult <ProductListItem>();

            data.TotalNumOfRecords = products.Count;
            data.Results           = products;

            return(data);
        }