示例#1
0
        /// <summary>
        /// 添加活动
        /// </summary>
        /// <param name="iid">商品宝贝ID</param>
        /// <param name="discountType">促销类型</param>
        /// <param name="discountValue">促销值</param>
        /// <param name="sdate">活动开始时间</param>
        /// <param name="edate">活动结束时间</param>
        /// <param name="name">活动标题</param>
        /// <param name="decreaseNum">是否限制</param>
        /// <param name="session"></param>
        /// <param name="actionId">活动ID</param>
        public void delORaddpromotion(string iid, string discountType, string discountValue, string sdate, string edate, string name, string decreaseNum, string session, string actionId, string promotion_id)
        {
            //创建活动及相关人群
            string appkey = "12287381";
            string secret = "d3486dac8198ef01000e7bd4504601a4";

            IDictionary <string, string> param2 = new Dictionary <string, string>();

            //删除活动
            param2 = new Dictionary <string, string>();
            param2.Add("promotion_id", promotion_id);
            string result = Post("http://gw.api.taobao.com/router/rest", appkey, secret, "taobao.marketing.promotion.delete", session, param2);

            Thread.Sleep(2000);//一秒一次, 太快 淘宝有限制
            //创建活动相关人群
            string guid = Guid.NewGuid().ToString().Substring(0, 4);
            IDictionary <string, string> param = new Dictionary <string, string>();

            string tagid = "1";

            //创建活动
            param = new Dictionary <string, string>();
            param.Add("num_iids", iid);
            param.Add("discount_type", discountType);
            param.Add("discount_value", discountValue);
            param.Add("start_date", DateTime.Parse(sdate).ToString("yyyy-MM-dd hh:mm:ss"));
            param.Add("end_date", DateTime.Parse(edate).ToString("yyyy-MM-dd hh:mm:ss"));
            param.Add("promotion_title", name);
            param.Add("decrease_num", decreaseNum);


            param.Add("tag_id", tagid);
            result = Post("http://gw.api.taobao.com/router/rest", appkey, secret, "taobao.marketing.promotion.add", session, param);


            if (result.IndexOf("error_response") != -1)
            {
                string sql = "update  tete_activitylist set Status=4 ,isok=1   WHERE ActivityID = " + actionId + " and  ProductID=" + iid;

                DBSql.getInstance().ExecSql(sql);

                string err = new Regex(@"<sub_msg>([^<]*)</sub_msg>", RegexOptions.IgnoreCase).Match(result).Groups[1].ToString();
                if (err == "")
                {
                    WriteLog3("活动创建失败,错误原因:您的session已经失效,需要重新授权", "1");
                }
                else
                {
                    WriteLog3("活动创建失败,错误原因:" + err, "1");
                }


                return;
            }

            string promotionid = new Regex(@"<promotion_id>([^<]*)</promotion_id>", RegexOptions.IgnoreCase).Match(result).Groups[1].ToString();

            //更新活动
            string sql2 = "update  tete_activitylist set Status=1 ,isok=1,promotionID=" + promotionid + "  WHERE ActivityID = " + actionId + " and  ProductID=" + iid;

            DBSql.getInstance().ExecSql(sql2);
        }
示例#2
0
        /// <summary>
        /// 刷新已开始的服务(更新修改,延迟活动)
        /// </summary>
        private void activityupdateStart()
        {
            try
            {
                string session = string.Empty;

                DBSql db = DBSql.getInstance();

                string    sql1 = "select * from tete_activity where status=1 and isok=0  "; //更新修改,延迟活动
                DataTable dt1  = DBSql.getInstance().GetTable(sql1);
                if (dt1 != null && dt1.Rows.Count > 0)
                {
                    for (int i = 0; i < dt1.Rows.Count; i++)
                    {
                        string    sql2  = " select * from tete_activitylist where ActivityID=" + dt1.Rows[i]["ID"].ToString();//更新该活动下的商品
                        DataTable dt1s2 = DBSql.getInstance().GetTable(sql2);
                        if (dt1s2 != null && dt1s2.Rows.Count > 0)
                        {
                            for (int j = 0; j < dt1s2.Rows.Count; j++)
                            {
                                string sqlstr1 = "SELECT session FROM TopTaobaoShop WHERE nick = '" + dt1s2.Rows[j]["nick"].ToString() + "'";

                                DataTable dtnick = db.GetTable(sqlstr1);
                                if (dtnick.Rows.Count != 0)
                                {
                                    session = dtnick.Rows[0]["session"].ToString();
                                }

                                //删除活动,在添加活动
                                delORaddpromotion(dt1s2.Rows[j]["ProductID"].ToString(), dt1s2.Rows[j]["discountType"].ToString(), dt1s2.Rows[j]["discountValue"].ToString(), dt1s2.Rows[j]["startDate"].ToString(), dt1s2.Rows[j]["endDate"].ToString(), dt1s2.Rows[j]["Name"].ToString(), dt1s2.Rows[j]["decreaseNum"].ToString(), session, dt1s2.Rows[j]["ActivityID"].ToString(), dt1s2.Rows[j]["promotionID"].ToString());
                            }
                        }

                        sql1 = "update tete_activity set Status=1, isok=1 where id=" + dt1.Rows[i]["ID"].ToString(); //更新修改延迟活动状态
                        DBSql.getInstance().ExecSql(sql1);
                    }
                }
                dt1.Dispose();

                string sqls3 = " select * from tete_activitylist where status=1  and isok=0 ";//未开始的活动列表

                DataTable dt1s3 = DBSql.getInstance().GetTable(sqls3);
                if (dt1s3 != null && dt1s3.Rows.Count > 0)
                {
                    for (int j = 0; j < dt1s3.Rows.Count; j++)
                    {
                        string sqlstr1 = "SELECT session FROM TopTaobaoShop WHERE nick = '" + dt1s3.Rows[j]["nick"].ToString() + "'";

                        DataTable dtnick = db.GetTable(sqlstr1);
                        if (dtnick.Rows.Count != 0)
                        {
                            session = dtnick.Rows[0]["session"].ToString();
                        }

                        //删除活动
                        delORaddpromotion(dt1s3.Rows[j]["ProductID"].ToString(), dt1s3.Rows[j]["discountType"].ToString(), dt1s3.Rows[j]["discountValue"].ToString(), dt1s3.Rows[j]["startDate"].ToString(), dt1s3.Rows[j]["endDate"].ToString(), dt1s3.Rows[j]["Name"].ToString(), dt1s3.Rows[j]["decreaseNum"].ToString(), session, dt1s3.Rows[j]["ActivityID"].ToString(), dt1s3.Rows[j]["promotionID"].ToString());
                    }
                }
                dt1s3.Dispose();
                //休息后继续循环-默认1分半钟一次
                Thread.Sleep(90000);

                Thread newThread44 = new Thread(activityupdateStart);
                newThread44.Start();
            }
            catch (Exception e)
            {
                WriteLog3("自动取消活动运行错误*****************************************" + e.StackTrace + e.Message + "----error!!!", "1");
                //MessageBox.Show("\r\n" + e.StackTrace);
                Thread newThread44 = new Thread(activityupdateStart);
                //休息后继续循环-默认1分半钟一次
                Thread.Sleep(90000);
                newThread44.Start();
            }
        }