Esempio n. 1
0
        public static Dictionary <string, Item> SearchNumIid(string num_iid, SellerInfoEntity sellerinfo, string reqName, int useplatform)
        {
            Dictionary <string, Item> itemDic = new Dictionary <string, Item>();

            #region 非全店选择批量
            if (string.IsNullOrWhiteSpace(num_iid))
            {
                return(null);
            }
            string itemid = num_iid;                       //商品id
            Regex  reg    = new Regex(@"(\d+,){0,19}\d+"); //正则获取每次20个
            foreach (Match m in reg.Matches(itemid))
            {
                ItemsSellerListGetRequest itemGetRequest = new ItemsSellerListGetRequest
                {
                    Fields  = reqName,
                    NumIids = m.Value
                };
                ItemsSellerListGetResponse itemGetResponse = TopClient.Execute(itemGetRequest, sellerinfo.top_session, (TopClient.CrmPlatForm)useplatform);
                for (int j = 0; j < 3; j++)
                {
                    itemGetResponse = TopClient.Execute(itemGetRequest, sellerinfo.top_session, (TopClient.CrmPlatForm)useplatform);
                    bool isok = string.IsNullOrWhiteSpace(itemGetResponse.SubErrMsg) ? true : false;
                    if (isok)//没有错就跳出  有错误暂停0.5s 继续执行
                    {
                        break;
                    }
                    else
                    {
                        Thread.Sleep(500);
                    }
                }
                if (itemGetResponse.IsError)
                {
                    TxtLog.WriteLine("getItemListErrorLog", sellerinfo.strUserNick + ":" + sellerinfo.strUserId + "===" + m.Value + ":出现异常:" + itemGetResponse.Body);
                    continue;
                }
                foreach (Item item in itemGetResponse.Items.Where(item => !itemDic.ContainsKey(item.NumIid.ToString())))
                {
                    itemDic.Add(item.NumIid.ToString(), item);
                }
            }
            #endregion
            return(itemDic);
        }
Esempio n. 2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string serverurl = GetSiteRoot() + "/TopHandler.ashx";

            var client = new TopClient(serverurl, APPID, APPSECRET);

            var req = new DemoRequest();

            req.p1 = new DemoObject()
            {
                id = 10,
                name = "hello world!",
            };

            var rsp = client.Execute(req);

            System.Diagnostics.Debugger.Break();
        }
Esempio n. 3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string serverurl = GetSiteRoot() + "/TopHandler.ashx";

            var client = new TopClient(serverurl, APPID, APPSECRET);

            var req = new DemoRequest();

            req.p1 = new DemoObject()
            {
                id   = 10,
                name = "hello world!",
            };

            var rsp = client.Execute(req);

            System.Diagnostics.Debugger.Break();
        }
Esempio n. 4
0
        public static Dictionary <string, Item> SearchAll(string status, string reqName, bool isnum_iid, string strMainWord, string sellerCat, SellerInfoEntity sellerinfo, int useplatform)
        {
            TxtLog.WriteLine("getItemListErrorLog", sellerinfo.strUserNick + ":" + sellerinfo.strUserId + "===" + status + " ::" + sellerinfo.top_session);
            Dictionary <string, Item> itemDic    = new Dictionary <string, Item>();
            StringBuilder             strbNumIid = new StringBuilder();
            long totalResults = 0; //宝贝总数
            int  pageNo       = 0; //api查询页码
            int  pageNo2      = 0; //api查询页码

            status = status == "3" ? null : status;
            if (string.IsNullOrWhiteSpace(status))
            {
                #region 获取出售中的商品
                do
                {
                    pageNo++;
                    ItemsOnsaleGetRequest req = new ItemsOnsaleGetRequest();
                    req.Fields   = reqName;
                    req.PageSize = 200L;
                    req.PageNo   = Convert.ToInt64(pageNo);
                    req.OrderBy  = "list_time:asc";
                    if (strMainWord.Length > 0)
                    {
                        req.Q = strMainWord;
                    }
                    if (sellerCat.Trim().Length > 0)
                    {
                        req.SellerCids = sellerCat;
                    }
                    ItemsOnsaleGetResponse response = TopClient.Execute <ItemsOnsaleGetResponse>(req, sellerinfo.top_session, (TopClient.CrmPlatForm)useplatform);
                    if (response.IsError)
                    {
                        TxtLog.WriteLine("getItemListErrorLog", sellerinfo.strUserNick + ":" + sellerinfo.strUserId + "=== :出现异常:" + response.Body);
                    }
                    else
                    {
                        TxtLog.WriteLine("getItemListErrorLog", sellerinfo.strUserNick + ":" + sellerinfo.strUserId + "=== :出现异常:" + response.Body);
                        totalResults = response.TotalResults;
                        foreach (Item item in response.Items.Where(item => !itemDic.ContainsKey(item.NumIid.ToString())))
                        {
                            if (isnum_iid)
                            {
                                strbNumIid.Append(item.NumIid.ToString() + ",");
                            }
                            else
                            {
                                itemDic.Add(item.NumIid.ToString(), item);
                            }
                        }
                    }
                } while (totalResults > pageNo * 200);
                #endregion
                #region 获取仓库中的商品
                do
                {
                    pageNo2++;
                    ItemsInventoryGetRequest req = new ItemsInventoryGetRequest
                    {
                        Fields   = reqName,
                        PageSize = 200,
                        PageNo   = pageNo2
                    };
                    if (strMainWord.Length > 0)
                    {
                        req.Q = strMainWord;
                    }
                    if (sellerCat.Trim().Length > 0)
                    {
                        req.SellerCids = sellerCat;
                    }
                    ItemsInventoryGetResponse response = TopClient.Execute(req, sellerinfo.top_session, (TopClient.CrmPlatForm)useplatform);
                    if (response.IsError)
                    {
                        TxtLog.WriteLine("getItemListErrorLog", sellerinfo.strUserNick + ":" + sellerinfo.strUserId + "=== :出现异常:" + response.Body);
                    }
                    else
                    {
                        totalResults = response.TotalResults;
                        foreach (Item item in response.Items.Where(item => !itemDic.ContainsKey(item.NumIid.ToString())))
                        {
                            if (isnum_iid)
                            {
                                strbNumIid.Append(item.NumIid.ToString() + ",");
                            }
                            else
                            {
                                itemDic.Add(item.NumIid.ToString(), item);
                            }
                        }
                    }
                } while (totalResults > pageNo2 * 200);
                #endregion
            }
            else
            {
                if (status == "0")
                {
                    #region 获取出售中的商品
                    do
                    {
                        pageNo++;
                        ItemsOnsaleGetRequest req = new ItemsOnsaleGetRequest();
                        req.Fields   = reqName;
                        req.PageSize = 200L;
                        req.PageNo   = Convert.ToInt64(pageNo);
                        req.OrderBy  = "list_time:asc";
                        if (strMainWord.Length > 0)
                        {
                            req.Q = strMainWord;
                        }
                        if (sellerCat.Trim().Length > 0)
                        {
                            req.SellerCids = sellerCat;
                        }
                        ItemsOnsaleGetResponse response = TopClient.Execute <ItemsOnsaleGetResponse>(req, sellerinfo.top_session, (TopClient.CrmPlatForm)useplatform);
                        if (response.IsError)
                        {
                            TxtLog.WriteLine("getItemListErrorLog", sellerinfo.strUserNick + ":" + sellerinfo.strUserId + "=== :出现异常:" + response.Body);
                        }
                        else
                        {
                            totalResults = response.TotalResults;
                            foreach (Item item in response.Items.Where(item => !itemDic.ContainsKey(item.NumIid.ToString())))
                            {
                                if (isnum_iid)
                                {
                                    strbNumIid.Append(item.NumIid.ToString() + ",");
                                }
                                else
                                {
                                    itemDic.Add(item.NumIid.ToString(), item);
                                }
                            }
                        }
                    } while (totalResults > pageNo * 200);
                    #endregion
                }
                else if (status == "1")
                {
                    #region 获取仓库中的商品
                    do
                    {
                        pageNo++;
                        ItemsInventoryGetRequest req = new ItemsInventoryGetRequest
                        {
                            Fields   = reqName,
                            PageSize = 200,
                            PageNo   = pageNo
                        };
                        if (strMainWord.Length > 0)
                        {
                            req.Q = strMainWord;
                        }
                        if (sellerCat.Trim().Length > 0)
                        {
                            req.SellerCids = sellerCat;
                        }
                        ItemsInventoryGetResponse response = TopClient.Execute(req, sellerinfo.top_session, (TopClient.CrmPlatForm)useplatform);
                        if (response.IsError)
                        {
                            TxtLog.WriteLine("getItemListErrorLog", sellerinfo.strUserNick + ":" + sellerinfo.strUserId + "=== :出现异常:" + response.Body);
                        }
                        else
                        {
                            totalResults = response.TotalResults;
                            foreach (Item item in response.Items.Where(item => !itemDic.ContainsKey(item.NumIid.ToString())))
                            {
                                if (isnum_iid)
                                {
                                    strbNumIid.Append(item.NumIid.ToString() + ",");
                                }
                                else
                                {
                                    itemDic.Add(item.NumIid.ToString(), item);
                                }
                            }
                        }
                    } while (totalResults > pageNo * 200);
                    #endregion
                }
            }
            if (isnum_iid)
            {
                itemDic = SearchNumIid(strbNumIid.ToString(), sellerinfo, reqName, useplatform);
            }
            return(itemDic);
        }
Esempio n. 5
0
        /// <summary>
        /// 获取一条复制的宝贝
        /// </summary>
        /// <returns></returns>
        public void Getids()
        {
            string    shoptype = string.Empty;                                                                                //复制类型
            DataTable dt       = sql.ExecuteDataTable("select * from crm_productscopy where state='4'    and shoptype='0' "); //获取未处理的宝贝,id复制

            //DataTable dt = sql.ExecuteDataTable("select * from crm_productscopy where state='0' and shoptype='0' and sellderid like '%" + textBox1.Text.ToString().Trim() + "'");//获取未处理的宝贝,id复制
            //DataTable dt = sql.ExecuteDataTable("select * from crm_productscopy where state='0' and shoptype='1' and sellderid like '%" + textBox1.Text.ToString().Trim() + "'");//获取未处理的宝贝,全店复制


            //#region 异常任务重新复制
            //DataTable dt = sql.ExecuteDataTable("select * from crm_productscopychild  WHERE TIMESTAMPDIFF(MINUTE,addtime,now())>100 and addtime is not null and state=0");
            //if (dt != null)
            //{
            //    foreach (DataRow dr in dt.Rows)
            //    {
            //        this.listBox1.Items.Insert(0, "【" + sellderid + "】【单个宝贝id:" + dr["id"].ToString() + "】【任务ID:" + dr["pid"].ToString() + "】重新复制(" + DateTime.Now.ToString() + ")");
            //        sql.ExecuteNonQuery("delete  from crm_productscopychild where id='" + dr["id"].ToString() + "'");
            //        sql.ExecuteNonQuery("update crm_productscopy set state=0 where id='" + dr["pid"].ToString() + "'");
            //    }
            //}
            //#endregion


            #region  制功能
            //DataTable dt = sql.ExecuteDataTable("select * from crm_productscopy where state='0' and shoptype='1' and sellderid like '%"+textBox1.Text.ToString().Trim()+"'");//获取未处理的宝贝,全店复制
            Copy      cp  = new Copy();
            TmallCopy tc  = new TmallCopy();
            string    ids = string.Empty;
            if (dt != null && dt.Rows.Count > 0)
            {
                int couts = 0;
                cp.dt     = dt;
                tc.dt     = dt;
                sellderid = dt.Rows[0]["sellderid"].ToString();
                string uid         = dt.Rows[0]["sellderid"].ToString();
                string useplatform = dt.Rows[0]["useplatform"].ToString();
                cp.useplatform = Convert.ToInt32(useplatform);
                tc.useplatform = Convert.ToInt32(useplatform);
                // DataTable dt1 = sql1.ExecuteDataTable("select * from crm_sellerinfo where userid='" + uid + "'")
                DataTable dt1 = null;
                if (useplatform == "2")
                {
                    dt1 = dbsp.ExecuteDataTable("select * from crm_sellerinfo where userid='" + uid + "'");
                }
                else
                {
                    dt1 = sql1.ExecuteDataTable("select * from crm_sellerinfo where userid='" + uid + "'");
                }
                cp.sessionKey = dt1.Rows[0]["SessionKey"].ToString();
                tc.sessionKey = dt1.Rows[0]["SessionKey"].ToString();
                //cp.sessionKey = "6201a25e36ce1973ce987c52b05163a6egi61aZZf135ab61805984332";
                // tc.sessionKey = "61011132b3c5a6d3941df1260bZZ477b572153033640b952769513611";
                ids      = dt.Rows[0]["oldid"].ToString();
                shoptype = dt.Rows[0]["shoptype"].ToString();//0:id复制,1:全店复制
                if (shoptype == "1")
                {
                    ShopGetRequest req = new ShopGetRequest();
                    req.Fields = "sid,cid,title,nick,desc,bulletin,pic_path,created,modified";
                    req.Nick   = ids;
                    ShopGetResponse rsp = TopClient.Execute(req);
                    if (rsp.Shop != null)
                    {
                        string url = "https://shop" + rsp.Shop.Sid + ".taobao.com/";
                        cp.GetIds(url);
                        ids = cp.ids;
                        //writlog("ids", ids);
                    }
                }
                if (ids.Contains(","))
                {
                    couts = ids.Substring(ids.Length - 1) == "," ? ids.Split(',').Length - 1 : ids.Split(',').Length;
                }
                else
                {
                    couts = 1;
                }
                sql.ExecuteNonQuery("update crm_productscopy set state='3',nums='" + (couts > 500 ? 500 : couts) + "' where id='" + dt.Rows[0]["id"].ToString() + "'");
                int    nums  = 0;                                  //当前执行的总数量
                string stype = dt1.Rows[0]["shopType"].ToString(); //b店 or C店
                // string stype = "B";
                if (ids.Contains(","))
                {
                    string[] aa = ids.Split(',');
                    foreach (string id in aa)
                    {
                        if ((sql.ExecuteDataTable("select id from crm_productscopychild where bbid='" + id + "' ")).Rows.Count == 0)
                        {
                            nums = nums + 1;
                        }
                        if (nums == 0)
                        {
                            nums = Convert.ToInt32((sql.ExecuteDataTable("select id from crm_productscopychild where pid='" + dt.Rows[0]["id"].ToString() + "'")).Rows.Count);
                        }
                        if (nums > 500)
                        {
                            //this.listBox1.Items.Insert(0, nums + ":0:" + dt.Rows[0]["id"].ToString());
                            this.listBox1.Items.Insert(0, "【" + sellderid + "】【已复制500个宝贝】");
                            break;
                        }
                        //if (aa.Length > 500)
                        //{
                        //    if (aa[500].ToString() == id)
                        //    {
                        //        //this.listBox1.Items.Insert(0, nums+":1");
                        //        this.listBox1.Items.Insert(0, "【" + sellderid + "】【已复制500个宝贝】");
                        //        break;
                        //    }
                        //}
                        if (dt.Rows[0]["oldid"].ToString() == "大牌小价01")
                        {
                            sql.ExecuteNonQuery("insert into crm_productscopychild(id,pid,bbid,state,addtime,remark) values ('" + Guid.NewGuid().ToString() + "','" + dt.Rows[0]["id"].ToString() + "','" + id + "','2','" + System.DateTime.Now.ToString() + "','因类目调整当前类目已被淘宝网关闭,请您将商品发布在其他相应类目下, 本类目已不能发布商品, 请移至其他类目进行发布!')");
                        }
                        else
                        {
                            if (!string.IsNullOrWhiteSpace(id))
                            {
                                if (checkid(id, dt.Rows[0]["id"].ToString(), dt.Rows[0]["is_gl"].ToString()))
                                {
                                    string a = AddChildCopy(id, dt.Rows[0]["id"].ToString(), shoptype, sellderid, dt.Rows[0]["is_gl"].ToString());
                                    if (a != "0")//添加宝贝复制
                                    {
                                        this.listBox1.Items.Insert(0, "【" + sellderid + "】【任务ID:" + a + "】开始复制(" + DateTime.Now.ToString() + ")");
                                        if (stype == "B")
                                        {
                                            try
                                            {
                                                tc.AddTaobao(id, a, sellderid, this.textBox1.Text);
                                            }
                                            catch (Exception ex)
                                            {
                                                writlog("copy", ex.ToString());
                                            }
                                        }
                                        else
                                        {
                                            //tc.AddTaobao(id, a, sellderid);
                                            try
                                            {
                                                cp.AddTaobao(id, a, sellderid, this.textBox1.Text);
                                            }
                                            catch (Exception ex)
                                            {
                                                writlog("copy", ex.ToString());
                                            }
                                        }
                                        this.listBox1.Items.Insert(0, "【" + sellderid + "】【任务ID:" + a + "】复制成功(" + DateTime.Now.ToString() + ")");
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    string a = AddChildCopy(ids, dt.Rows[0]["id"].ToString(), shoptype, sellderid, dt.Rows[0]["is_gl"].ToString());
                    if (a != "0")//添加宝贝复制
                    {
                        this.listBox1.Items.Insert(0, "【" + sellderid + "】【任务ID:" + a + "】开始复制(" + DateTime.Now.ToString() + ")");
                        if (stype == "B")
                        {
                            tc.AddTaobao(ids, a, sellderid, this.textBox1.Text);
                        }
                        else
                        {
                            //tc.AddTaobao(ids, a, sellderid);
                            cp.AddTaobao(ids, a, sellderid, this.textBox1.Text);
                        }
                        //cp.AddTaobao(ids, a, sellderid);
                        this.listBox1.Items.Insert(0, "【" + sellderid + "】【任务ID:" + a + "】复制成功(" + DateTime.Now.ToString() + ")");
                    }
                    //}
                }
                sql.ExecuteNonQuery("update crm_productscopy set state='1' where id='" + dt.Rows[0]["id"].ToString() + "'");
                sql.ExecuteNonQuery("update crm_productscopychild set state='2' where id='" + dt.Rows[0]["id"].ToString() + "' and state='3' ");
                sql.ExecuteNonQuery("update crm_productscopychild set state='2' where id='" + dt.Rows[0]["id"].ToString() + "' and state='0' ");
            }
            #endregion
        }