예제 #1
0
        public IList <product_sku_model> GetSkus(int num_iid)
        {
            DbCommand sqlStringCommand = base.database.GetSqlStringCommand("SELECT s.SkuId, s.SKU, s.ProductId, s.Stock, s.SalePrice, AttributeName, ValueStr FROM Hishop_SKUs s left join Hishop_SKUItems si on s.SkuId = si.SkuId left join Hishop_Attributes a on si.AttributeId = a.AttributeId left join Hishop_AttributeValues av on si.ValueId = av.ValueId WHERE s.SkuId IN (SELECT SkuId FROM Hishop_SKUs WHERE ProductId = @ProductId)");

            base.database.AddInParameter(sqlStringCommand, "ProductId", DbType.Int32, num_iid);
            IList <product_sku_model> list = new List <product_sku_model>();
            IDataReader reader             = base.database.ExecuteReader(sqlStringCommand);

            try
            {
                while (reader.Read())
                {
                    product_sku_model product_sku_model = list.FirstOrDefault((product_sku_model item) => item.sku_id == (string)((IDataRecord)reader)["SkuId"]);
                    if (product_sku_model == null)
                    {
                        product_sku_model        = new product_sku_model();
                        product_sku_model.sku_id = (string)((IDataRecord)reader)["SkuId"];
                        if (((IDataRecord)reader)["SKU"] != DBNull.Value)
                        {
                            product_sku_model.outer_sku_id = (string)((IDataRecord)reader)["SKU"];
                        }
                        product_sku_model.quantity = (int)((IDataRecord)reader)["Stock"];
                        product_sku_model.price    = (decimal)((IDataRecord)reader)["SalePrice"];
                        if (((IDataRecord)reader)["AttributeName"] != DBNull.Value && ((IDataRecord)reader)["ValueStr"] != DBNull.Value)
                        {
                            product_sku_model.sku_properties_name = (string)((IDataRecord)reader)["AttributeName"] + ":" + (string)((IDataRecord)reader)["ValueStr"];
                        }
                        list.Add(product_sku_model);
                    }
                    else if (((IDataRecord)reader)["AttributeName"] != DBNull.Value && ((IDataRecord)reader)["ValueStr"] != DBNull.Value)
                    {
                        product_sku_model product_sku_model2 = product_sku_model;
                        product_sku_model2.sku_properties_name = product_sku_model2.sku_properties_name + ";" + (string)((IDataRecord)reader)["AttributeName"] + ":" + (string)((IDataRecord)reader)["ValueStr"];
                    }
                }
            }
            finally
            {
                if (reader != null)
                {
                    reader.Dispose();
                }
            }
            return(list);
        }
예제 #2
0
        /// <summary>
        /// 商品信息转换
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        private product_item_model ProductInfoMapChange(ProductInfo data)
        {
            var prodata = data;

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

            #region 装配信息
            result.num_iid    = (int)prodata.Id;
            result.outer_id   = prodata.ProductCode;
            result.brand_id   = (int)prodata.BrandId;
            result.brand_name = prodata.BrandName;
            result.cid        = (int)prodata.CategoryId;
            result.type_id    = (int)prodata.TypeId;
            if (prodata.Himall_Categories != null)
            {
                result.cat_name = prodata.Himall_Categories.Name;
                if (prodata.Himall_Categories.ProductTypeInfo != null)
                {
                    result.type_name = prodata.Himall_Categories.ProductTypeInfo.Name;
                }
            }
            result.title            = prodata.ProductName.Trim();
            result.list_time        = prodata.AddedDate;
            result.modified         = prodata.AddedDate;
            result.display_sequence = (int)prodata.DisplaySequence;
            result.sold_quantity    = (int)prodata.SaleCounts;
            result.desc             = prodata.ProductDescriptionInfo.Description;
            result.wap_desc         = prodata.ProductDescriptionInfo.MobileDescription;
            result.pic_url.Add(System.IO.Path.Combine(OpenAPIHelper.HostUrl, prodata.GetImage(ImageSize.Size_350, 1)));
            ProductStatus ps = GetProductStatus(prodata);
            result.approve_status = ps.ToString();

            #region 商品属性填充
            var prodAttrs   = _iProductService.GetProductAttribute(prodata.Id).ToList();
            var prodAttrids = prodAttrs.Select(d => d.AttributeId).Distinct().ToList();
            result.props_name = "";
            if (prodAttrids.Count > 0)
            {
                List <string> propslst    = new List <string>();
                List <string> propsvallst = new List <string>();
                foreach (var curattid in prodAttrids)
                {
                    var item = prodAttrs.FirstOrDefault(d => d.AttributeId == curattid);
                    propsvallst.Clear();
                    foreach (var attrV in item.AttributesInfo.AttributeValueInfo.ToList())
                    {
                        if (prodAttrs.Any(p => p.ValueId == attrV.Id))
                        {
                            propsvallst.Add(attrV.Value);
                        }
                    }
                    propslst.Add(item.AttributesInfo.Name + "#cln#[" + string.Join(",", propsvallst.ToArray()) + "]");
                }
                result.props_name = string.Join("#scln#", propslst.ToArray());
            }
            #endregion

            #region  发货地区
            var prolocid = prodata.Himall_FreightTemplate.SourceAddress;
            result.location = "";
            if (prolocid.HasValue)
            {
                var locpath = _iRegionService.GetFullName(prolocid.Value, ",");
                result.location = "{'city':'#c#', 'state':'#p#'}";
                if (!string.IsNullOrWhiteSpace(locpath))
                {
                    var _tmparr = locpath.Split(',');
                    result.location = result.location.Replace("#p#", _tmparr[0]);
                    if (_tmparr.Length > 1)
                    {
                        result.location = result.location.Replace("#c#", _tmparr[1]);
                    }
                    else
                    {
                        result.location = result.location.Replace("#c#", "");
                    }
                }
            }
            #endregion

            #region SKUS

            ProductTypeInfo typeInfo     = _iTypeService.GetType(data.TypeId);
            string          colorAlias   = (typeInfo == null || string.IsNullOrEmpty(typeInfo.ColorAlias)) ? SpecificationType.Color.ToDescription() : typeInfo.ColorAlias;
            string          sizeAlias    = (typeInfo == null || string.IsNullOrEmpty(typeInfo.SizeAlias)) ? SpecificationType.Size.ToDescription() : typeInfo.SizeAlias;
            string          versionAlias = (typeInfo == null || string.IsNullOrEmpty(typeInfo.VersionAlias)) ? SpecificationType.Version.ToDescription() : typeInfo.VersionAlias;
            result.skus = new List <product_sku_model>();
            foreach (var item in prodata.SKUInfo)
            {
                product_sku_model skudata = new product_sku_model();
                skudata.sku_id       = item.Id;
                skudata.outer_sku_id = item.Sku;
                skudata.price        = item.SalePrice;
                skudata.quantity     = (int)item.Stock;
                //skudata.sku_properties_name = "颜色:" + item.Color + "尺寸:" + item.Size + "版本:" + item.Version;
                skudata.sku_properties_name = colorAlias + ":" + item.Color + sizeAlias + ":" + item.Size + versionAlias + ":" + item.Version;
                string sku_properties_name = item.Color + item.Size + item.Version;
                if (string.IsNullOrWhiteSpace(sku_properties_name))
                {
                    skudata.sku_properties_name = "";
                }
                if (!string.IsNullOrWhiteSpace(skudata.sku_properties_name))
                {
                    result.skus.Add(skudata);
                }
            }
            #endregion

            #endregion

            return(result);
        }