Beispiel #1
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
        }