Пример #1
0
        /// <summary>
        /// 查询商品
        /// </summary>
        /// <param name="timeStamp"></param>
        /// <param name="uCode"></param>
        /// <param name="mType"></param>
        /// <param name="Sign"></param>
        /// <param name="PageSize"></param>
        /// <param name="Page"></param>
        /// <param name="GoodsType"></param>
        /// <param name="OuterID"></param>
        /// <param name="GoodsName"></param>
        /// <returns></returns>
        public string findProduct(HttpContext context)
        {
            string uCode     = context.Request["uCode"];
            string PageSize  = context.Request["PageSize"];
            string Page      = context.Request["Page"];
            string GoodsType = context.Request["GoodsType"];
            string OuterID   = context.Request["OuterID"];
            string GoodsName = context.Request["GoodsName"];


            ProductQuery query      = new ProductQuery();
            int          page_size  = 0;
            int          page_index = 0;

            if (!string.IsNullOrEmpty(PageSize))
            {
                page_size = Convert.ToInt32(PageSize);
            }
            if (!string.IsNullOrEmpty(Page))
            {
                page_index = Convert.ToInt32(Page);
            }
            string type = null;
            string code = null;
            string name = null;

            Entities.ProductInfo.ProductSaleStatus status = new Entities.ProductInfo.ProductSaleStatus();
            if (!string.IsNullOrWhiteSpace(GoodsType)) //按类型
            {
                type = GoodsType;                      //1在售 2下架
                if (type.Equals("OnSale"))
                {
                    status = Entities.ProductInfo.ProductSaleStatus.OnSale;
                }
                else if (type.Equals("InStock"))
                {
                    status = Entities.ProductInfo.ProductSaleStatus.InStock;
                }
            }
            else if (!string.IsNullOrWhiteSpace(OuterID))//按商家编码
            {
                code = OuterID;
            }
            else if (!string.IsNullOrWhiteSpace(GoodsName))//按商品名称
            {
                name = GoodsName;
            }
            query.PageSize    = page_size;
            query.PageNo      = page_index;
            query.SaleStatus  = status;
            query.KeyWords    = name;
            query.ProductCode = code;
            query.ShopId      = 1;
            if (ServiceApplication.Create <IShopService>().GetshopInfoByCode(uCode) != null)
            {
                query.ShopId = ServiceApplication.Create <IShopService>().GetshopInfoByCode(uCode).ShopId; //根据uCode获取店铺信息
            }
            var           products = ProductManagerApplication.GetProducts(query);
            StringBuilder sb       = new StringBuilder();

            sb.Append("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
            try
            {
                sb.Append("<Goods>");
                foreach (var item in products.Models)
                {
                    sb.Append("<Ware>");

                    bool hasSku = ProductManagerApplication.HasSKU(item.Id);

                    int isSku = hasSku ? 1 : 0;
                    sb.Append(string.Format("<ItemID><![CDATA[{0}]]></ItemID>", item.Id));
                    sb.Append(string.Format("<ItemName><![CDATA[{0}]]></ItemName>", item.ProductName));
                    sb.Append(string.Format("<OuterID><![CDATA[{0}]]></OuterID>", item.ProductCode));
                    sb.Append(string.Format("<Price><![CDATA[{0}]]></Price>", item.MinSalePrice));
                    sb.Append(string.Format("<IsSku><![CDATA[{0}]]></IsSku>", isSku));
                    var skus = ProductManagerApplication.GetSKUs(item.Id);
                    sb.Append(string.Format("<Num><![CDATA[{0}]]></Num>", skus.Sum(d => d.Stock)));//总数
                    sb.Append("<Items>");
                    if (hasSku)
                    {
                        foreach (var sku in skus)
                        {
                            sb.Append("<Item>");
                            sb.Append(string.Format("<Unit><![CDATA[{0}]]></Unit>", sku.Color + " " + sku.Size + " " + sku.Version));
                            sb.Append(string.Format("<SkuOuterID><![CDATA[{0}]]></SkuOuterID>", sku.Sku));
                            sb.Append(string.Format("<SkuID><![CDATA[{0}]]></SkuID>", sku.Id));
                            sb.Append(string.Format("<Num><![CDATA[{0}]]></Num>", sku.Stock));
                            sb.Append(string.Format("<SkuPrice><![CDATA[{0}]]></SkuPrice>", sku.SalePrice));
                            sb.Append("</Item>");
                        }
                    }
                    sb.Append("</Items>");
                    sb.Append("</Ware>");
                }
                sb.Append("<Result>1</Result>");
                sb.Append(string.Format("<TotalCount>{0}</TotalCount>", products.Total));
                sb.Append("<Cause></Cause>");
                sb.Append("</Goods>");
            }
            catch (Exception ex)
            {
                sb.Clear();
                sb.Append("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
                sb.Append("<Rsp><Result>0</Result><Cause>" + ex.Message + "</Cause></Rsp>");
            }
            return(sb.ToString());
        }
Пример #2
0
 public bool isShowSku(long id)
 {
     return(ProductManagerApplication.HasSKU(id));
 }