예제 #1
0
        /// <summary>
        /// 获取所有商品
        /// </summary>
        /// <param name="count"></param>
        /// <returns></returns>
        /// <remarks>2016-11-03 周 创建</remarks>
        private string GetAllGoodsInfos(int count)
        {
            string html = "[";
            string Data = "";
            ///接口参数
            Dictionary <string, string> date = new Dictionary <string, string>();

            date.Add("appKey", Config.Account);      //AppKey[必填]
            date.Add("proNo", "");                   //商品货号[可填]
            date.Add("proClassCode", "");            //商品类别[可填]
            date.Add("proSale", "2");                //商品状态[可填] 0:销售中 1:下架 2:全部[默认]
            date.Add("startTime", "");               //商品添加开始时间[可填]
            date.Add("endTime", "");                 //商品添加结束时间[可填]
            date.Add("pageIndex", count.ToString()); //页数[必填]
            date.Add("pageSize", "500");             //每页数量[必填][数量:10、20、50]
            ///调用接口GetProducts
            Client client = new Client(Config.GatewayUrl, "IOpenAPI.GetProducts", Config.Account, Config.Secert, "json");
            ///获得接口返回值
            string sAPIResult = "";

            try
            {
                sAPIResult = client.Post(date);
            }
            catch (Exception ex)
            {
                Data = "第三方平台的Api_Url无效。" + ex.Message;
            }

            string ApiCode     = Comm.get_JsonValueByName(sAPIResult, "Code");
            string PageSumRaws = Comm.get_JsonValueByName(sAPIResult, "SumNum");

            if (ApiCode == "101")
            {
                string ApiResult = Comm.get_JsonValueByName(sAPIResult, "Result");
                int    PageCount = int.Parse((int.Parse(PageSumRaws) / 500).ToString()) + 1;
                for (int i = 1; i <= PageCount; i++)
                {
                    ///接口参数
                    Dictionary <string, string> date2 = new Dictionary <string, string>();
                    date2.Add("appKey", Config.Account);  //AppKey[必填]
                    date2.Add("proNo", "");               //商品货号[可填]
                    date2.Add("proClassCode", "");        //商品类别[可填]
                    date2.Add("proSale", "2");            //商品状态[可填] 0:销售中 1:下架 2:全部[默认]
                    date2.Add("startTime", "");           //商品添加开始时间[可填]
                    date2.Add("endTime", "");             //商品添加结束时间[可填]
                    date2.Add("pageIndex", i.ToString()); //页数[必填]
                    date2.Add("pageSize", "500");         //每页数量[必填][数量:10、20、50]
                    ///调用接口GetProducts
                    Client client2 = new Client(Config.GatewayUrl, "IOpenAPI.GetProducts", Config.Account, Config.Secert, "json");
                    ///获得接口返回值
                    string sAPIResult2 = "";
                    try
                    {
                        sAPIResult2 = client2.Post(date2);
                        string ApiCode2 = Comm.get_JsonValueByName(sAPIResult2, "Code");
                        {
                            if (ApiCode2 == "101")
                            {
                                string ApiResult2 = Comm.get_JsonValueByName(sAPIResult2, "Result");
                                {
                                    ApiResult2 = ApiResult2.Substring(1);
                                    ApiResult2 = ApiResult2.TrimEnd(']');
                                    Data      += ApiResult2 + ",";
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Data = "第三方平台的Api_Url无效。" + ex.Message;
                    }
                }
                Data  = Data.TrimEnd(',');
                Data += "]";
                html += Data;
            }


            return(html);
        }
예제 #2
0
        /// <summary>
        /// 获取单个sku
        /// </summary>
        /// <returns></returns>
        /// <remarks>2016-11-03 周 创建</remarks>
        public override Result <string> GetGoodsSku(string skuid)
        {
            var result = new Result <string>()
            {
                Status     = true,
                StatusCode = 1,
                Message    = "更新成功"
            };

            lock (lockHelper)//防止多人同时操作造成产品重复添加
            {
                try
                {
                    ///接口参数
                    Dictionary <string, string> date = new Dictionary <string, string>();
                    date.Add("appKey", Config.Account); //AppKey[必填]
                    date.Add("proSkuNo", skuid);        //商品Sku[必填]
                    ///调用接口
                    Client client = new Client(Config.GatewayUrl, "IOpenAPI.GetProductSkuInfo", Config.Account, Config.Secert, "json");
                    ///获得接口返回值
                    string sAPIResult = "";
                    try
                    {
                        sAPIResult = client.Post(date);
                    }
                    catch (Exception ex)
                    {
                        result.Message    = "第三方平台的Api_Url无效。" + ex.Message;
                        result.Status     = false;
                        result.StatusCode = -2;
                        return(result);
                    }

                    string ApiCode = Comm.get_JsonValueByName(sAPIResult, "Code");
                    if (ApiCode == "101")
                    {
                        string ApiResult = Comm.get_JsonValueByName(sAPIResult, "Result");
                        List <Pro_Sku_Info> listResult = new List <Pro_Sku_Info>();
                        listResult = Newtonsoft.Json.JsonConvert.DeserializeObject <List <Pro_Sku_Info> >(ApiResult);
                        //var products = BLL.Supply.ScProductBo.Instance.GetScProductList((int)Code);

                        foreach (Pro_Sku_Info g in listResult)
                        {
                            var ScProduct = BLL.Supply.ScProductBo.Instance.GetScProductInfo(g.ProSkuNo, (int)Code);
                            if (ScProduct != null)
                            {
                                ScProduct Product    = Hyt.DataAccess.Supply.IScProductDao.Instance.GetScProductInfo(ScProduct.SysNo);
                                var       jsonObject = JObject.Parse(Product.Receipt);
                                //PdProductList PdData = new PdProductList();
                                string ProTitle    = g.ProTitle;
                                string ProNo       = g.ProNo;
                                string ProBrand    = jsonObject["ProBrand"].ToString();
                                string ProClass    = jsonObject["ProClass"].ToString();
                                string ProWeight   = jsonObject["ProWeight"].ToString();
                                string ProSimg     = jsonObject["ProSimg"].ToString();
                                string ProRemark   = jsonObject["ProRemark"].ToString();
                                string ProSale     = jsonObject["ProSale"].ToString();
                                string Pro_Unit    = jsonObject["Pro_Unit"].ToString();
                                string ProTagPrice = jsonObject["ProTagPrice"].ToString();
                                string ProFxPrice  = jsonObject["ProFxPrice"].ToString();
                                string ProRetPrice = jsonObject["ProRetPrice"].ToString();
                                string ProCount    = g.ProCount.ToString();
                                string ProductSpec = jsonObject["ProductSpec"].ToString();
                                string Receipt     = "{\"ProTitle\":\"" + ProTitle + "\",\"ProNo\":\"" + ProNo + "\",\"ProBrand\":\"" + ProBrand + "\",\"ProClass\":\"" + ProClass + "\""
                                                     + ",\"ProWeight\":\"" + ProWeight + "\",\"ProSimg\":\"" + ProSimg + "\",\"ProRemark\":\"" + ProRemark + "\",\"ProSale\":\"" + ProSale + "\""
                                                     + ",\"Pro_Unit\":\"" + Pro_Unit + "\",\"ProTagPrice\":\"" + ProTagPrice + "\",\"ProFxPrice\":\"" + ProFxPrice + "\",\"ProRetPrice\":\"" + ProRetPrice + "\""
                                                     + ",\"ProCount\":\"" + ProCount + "\",\"ProductSpec\":" + ProductSpec + ""
                                                     + "}";
                                try
                                {
                                    BLL.Supply.ScProductBo.Instance.UpdateScProduct(g.ProSkuNo, ProTitle, Receipt);
                                }
                                catch (Exception ex)
                                {
                                    result.Message    = "更新商品" + ProNo + "出现错误:" + ex.Message;
                                    result.Status     = false;
                                    result.StatusCode = -2;
                                    return(result);
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    result.Message    = ex.Message;
                    result.Status     = false;
                    result.StatusCode = -2;
                }
                return(result);
            }
        }