Exemplo n.º 1
0
        /// <summary>
        /// 商品列表信息项转换
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        private product_list_model ProductInfoListMapChange(Entities.ProductInfo data)
        {
            product_list_model dresult = null;
            var prodata = data;

            dresult = new product_list_model();

            if (prodata == null)
            {
                throw new MallApiException(OpenApiErrorCode.Product_Not_Exists, "num_iid");
            }

            #region 装配信息
            dresult.num_iid    = (int)prodata.Id;
            dresult.outer_id   = prodata.ProductCode;
            dresult.brand_id   = (int)prodata.BrandId;
            dresult.brand_name = prodata.BrandName;
            dresult.cid        = (int)prodata.CategoryId;
            dresult.type_id    = (int)prodata.TypeId;

            var category = CategoryApplication.GetCategory(prodata.CategoryId);
            if (category != null)
            {
                dresult.cat_name = category.Name;
                var type = TypeApplication.GetType(category.TypeId);
                if (type != null)
                {
                    dresult.type_name = type.Name;
                }
            }
            dresult.price = prodata.MinSalePrice;
            var skus = ProductManagerApplication.GetSKUs(prodata.Id);
            if (skus.Count > 0)
            {
                dresult.num = (int)skus.Sum(d => d.Stock);
            }
            else
            {
                dresult.num = 0;
                dresult.num = prodata.Quantity;
            }
            dresult.title         = prodata.ProductName.Trim();
            dresult.list_time     = prodata.AddedDate;
            dresult.modified      = prodata.AddedDate;
            dresult.sold_quantity = (int)prodata.SaleCounts;
            dresult.pic_url       = new System.Collections.ArrayList();
            dresult.pic_url.Add(System.IO.Path.Combine(OpenAPIHelper.HostUrl, prodata.GetImage(ImageSize.Size_350, 1)));
            ProductStatus ps = GetProductStatus(prodata);
            dresult.approve_status = ps.ToString();
            #endregion

            return(dresult);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 商品列表信息项转换
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        private product_list_model ProductInfoListMapChange(ProductInfo data)
        {
            product_list_model dresult = null;
            var prodata = data;

            dresult = new product_list_model();

            if (prodata == null)
            {
                throw new HimallOpenApiException(OpenApiErrorCode.Product_Not_Exists, "num_iid");
            }

            #region 装配信息
            dresult.num_iid    = (int)prodata.Id;
            dresult.outer_id   = prodata.ProductCode;
            dresult.brand_id   = (int)prodata.BrandId;
            dresult.brand_name = prodata.BrandName;
            dresult.cid        = (int)prodata.CategoryId;
            dresult.type_id    = (int)prodata.TypeId;
            if (prodata.Himall_Categories != null)
            {
                dresult.cat_name = prodata.Himall_Categories.Name;
                if (prodata.Himall_Categories.ProductTypeInfo != null)
                {
                    dresult.type_name = prodata.Himall_Categories.ProductTypeInfo.Name;
                }
            }
            dresult.price = prodata.MinSalePrice;
            if (prodata.SKUInfo.Count > 0)
            {
                dresult.num = (int)prodata.SKUInfo.Sum(d => d.Stock);
            }
            else
            {
                dresult.num = 0;
                if (prodata.Quantity.HasValue)
                {
                    dresult.num = prodata.Quantity.Value;
                }
            }
            dresult.title         = prodata.ProductName.Trim();
            dresult.list_time     = prodata.AddedDate;
            dresult.modified      = prodata.AddedDate;
            dresult.sold_quantity = (int)prodata.SaleCounts;
            dresult.pic_url       = new System.Collections.ArrayList();
            dresult.pic_url.Add(System.IO.Path.Combine(OpenAPIHelper.HostUrl, prodata.GetImage(ImageSize.Size_350, 1)));
            ProductStatus ps = GetProductStatus(prodata);
            dresult.approve_status = ps.ToString();
            #endregion

            return(dresult);
        }
Exemplo n.º 3
0
        public string ConvertProductSold(DataTable dt)
        {
            List <product_list_model> list = new List <product_list_model>();

            foreach (DataRow row in dt.Rows)
            {
                product_list_model item = new product_list_model
                {
                    cid = (int)row["CategoryId"]
                };
                if (row["CategoryName"] != DBNull.Value)
                {
                    item.cat_name = (string)row["CategoryName"];
                }
                if (row["BrandId"] != DBNull.Value)
                {
                    item.brand_id = (int)row["BrandId"];
                }
                if (row["BrandName"] != DBNull.Value)
                {
                    item.brand_name = (string)row["BrandName"];
                }
                if (row["TypeId"] != DBNull.Value)
                {
                    item.type_id = (int)row["TypeId"];
                }
                if (row["TypeName"] != DBNull.Value)
                {
                    item.type_name = (string)row["TypeName"];
                }
                item.num_iid = (int)row["ProductId"];
                item.title   = (string)row["ProductName"];
                if (row["ProductCode"] != DBNull.Value)
                {
                    item.outer_id = (string)row["ProductCode"];
                }
                if ((row["ImageUrl1"] != DBNull.Value) && !string.IsNullOrEmpty((string)row["ImageUrl1"]))
                {
                    item.pic_url.Add((string)row["ImageUrl1"]);
                }
                if ((row["ImageUrl2"] != DBNull.Value) && !string.IsNullOrEmpty((string)row["ImageUrl2"]))
                {
                    item.pic_url.Add((string)row["ImageUrl2"]);
                }
                if ((row["ImageUrl3"] != DBNull.Value) && !string.IsNullOrEmpty((string)row["ImageUrl3"]))
                {
                    item.pic_url.Add((string)row["ImageUrl3"]);
                }
                if ((row["ImageUrl4"] != DBNull.Value) && !string.IsNullOrEmpty((string)row["ImageUrl4"]))
                {
                    item.pic_url.Add((string)row["ImageUrl4"]);
                }
                if ((row["ImageUrl5"] != DBNull.Value) && !string.IsNullOrEmpty((string)row["ImageUrl5"]))
                {
                    item.pic_url.Add((string)row["ImageUrl5"]);
                }
                item.list_time = new DateTime?((DateTime)row["AddedDate"]);
                switch (((ProductSaleStatus)row["SaleStatus"]))
                {
                case ProductSaleStatus.OnSale:
                    item.approve_status = "On_Sale";
                    break;

                case ProductSaleStatus.UnSale:
                    item.approve_status = "Un_Sale";
                    break;

                default:
                    item.approve_status = "In_Stock";
                    break;
                }
                item.sold_quantity = (int)row["SaleCounts"];
                item.num           = (int)row["Stock"];
                item.price         = (decimal)row["SalePrice"];
                list.Add(item);
            }
            return(JsonConvert.SerializeObject(list));
        }
Exemplo n.º 4
0
 public string ConvertProductSold(System.Data.DataTable dt)
 {
     System.Collections.Generic.List <product_list_model> list = new System.Collections.Generic.List <product_list_model>();
     foreach (System.Data.DataRow dataRow in dt.Rows)
     {
         product_list_model product_list_model = new product_list_model();
         product_list_model.cid = (int)dataRow["CategoryId"];
         if (dataRow["CategoryName"] != System.DBNull.Value)
         {
             product_list_model.cat_name = (string)dataRow["CategoryName"];
         }
         if (dataRow["BrandId"] != System.DBNull.Value)
         {
             product_list_model.brand_id = (int)dataRow["BrandId"];
         }
         if (dataRow["BrandName"] != System.DBNull.Value)
         {
             product_list_model.brand_name = (string)dataRow["BrandName"];
         }
         if (dataRow["TypeId"] != System.DBNull.Value)
         {
             product_list_model.type_id = (int)dataRow["TypeId"];
         }
         if (dataRow["TypeName"] != System.DBNull.Value)
         {
             product_list_model.type_name = (string)dataRow["TypeName"];
         }
         product_list_model.num_iid = (int)dataRow["ProductId"];
         product_list_model.title   = (string)dataRow["ProductName"];
         if (dataRow["ProductCode"] != System.DBNull.Value)
         {
             product_list_model.outer_id = (string)dataRow["ProductCode"];
         }
         if (dataRow["ImageUrl1"] != System.DBNull.Value && !string.IsNullOrEmpty((string)dataRow["ImageUrl1"]))
         {
             product_list_model.pic_url.Add((string)dataRow["ImageUrl1"]);
         }
         if (dataRow["ImageUrl2"] != System.DBNull.Value && !string.IsNullOrEmpty((string)dataRow["ImageUrl2"]))
         {
             product_list_model.pic_url.Add((string)dataRow["ImageUrl2"]);
         }
         if (dataRow["ImageUrl3"] != System.DBNull.Value && !string.IsNullOrEmpty((string)dataRow["ImageUrl3"]))
         {
             product_list_model.pic_url.Add((string)dataRow["ImageUrl3"]);
         }
         if (dataRow["ImageUrl4"] != System.DBNull.Value && !string.IsNullOrEmpty((string)dataRow["ImageUrl4"]))
         {
             product_list_model.pic_url.Add((string)dataRow["ImageUrl4"]);
         }
         if (dataRow["ImageUrl5"] != System.DBNull.Value && !string.IsNullOrEmpty((string)dataRow["ImageUrl5"]))
         {
             product_list_model.pic_url.Add((string)dataRow["ImageUrl5"]);
         }
         product_list_model.list_time = new System.DateTime?((System.DateTime)dataRow["AddedDate"]);
         ProductSaleStatus productSaleStatus = (ProductSaleStatus)dataRow["SaleStatus"];
         if (productSaleStatus == ProductSaleStatus.OnSale)
         {
             product_list_model.approve_status = "On_Sale";
         }
         else if (productSaleStatus == ProductSaleStatus.UnSale)
         {
             product_list_model.approve_status = "Un_Sale";
         }
         else
         {
             product_list_model.approve_status = "In_Stock";
         }
         product_list_model.sold_quantity = (int)dataRow["SaleCounts"];
         product_list_model.num           = (int)dataRow["Stock"];
         product_list_model.price         = (decimal)dataRow["SalePrice"];
         list.Add(product_list_model);
     }
     return(JsonConvert.SerializeObject(list));
 }