Пример #1
0
 public static DBSql getInstance()
 {
     if (instance == null)
     {
         instance = new DBSql();
     }
     return(instance);
 }
Пример #2
0
        /// <summary>
        /// 创建删除活动关联的宝贝描述
        /// </summary>
        /// <param name="taobaoNick"></param>
        /// <param name="id">活动ID</param>
        private void Delete(string taobaoNick, string id)
        {
            WriteLog("自动取消活动 开始创建任务*************************************************", "");
            string sql = "SELECT COUNT(*) as count FROM TopMission WHERE groupbuyid = " + id + " AND typ='delete' AND isok = 0 AND nick<>'' ";

            DBSql     db  = DBSql.getInstance();
            DataTable dt3 = db.GetTable(sql);

            if (dt3 != null && dt3.Rows.Count > 0)
            {
                if (dt3.Rows[0]["count"].ToString().Trim() != "0")
                {
                    WriteLog("活动已经创建任务了*************************************************" + dt3.Rows[0]["count"].ToString().Trim(), "");
                    return;
                }
            }

            sql = "INSERT INTO TopMission (typ, nick, groupbuyid) VALUES ('delete', '" + taobaoNick + "', '" + id + "')";
            WriteLog("活动创建任务了*************************************************" + sql, "");
            db.ExecSql(sql);


            sql = "SELECT TOP 1 ID FROM TopMission where nick='" + taobaoNick + "' ORDER BY ID DESC";
            dt3 = db.GetTable(sql);
            if (dt3 == null)
            {
                return;
            }
            if (dt3 != null && dt3.Rows.Count > 0)
            {
                string missionid = dt3.Rows[0]["ID"].ToString();

                //获取团购信息并更新
                sql = "SELECT name,productimg,productid FROM TopGroupBuy WHERE id = '" + id + "'";
                DataTable dt = db.GetTable(sql);
                if (dt.Rows.Count != 0)
                {
                    sql = "UPDATE TopMission SET groupbuyname = '" + dt.Rows[0]["name"].ToString() + "',groupbuypic = '" + dt.Rows[0]["productimg"].ToString() + "',itemid = '" + dt.Rows[0]["productid"].ToString() + "' WHERE id = " + missionid;
                    db.ExecSql(sql);
                }

                //更新任务总数
                sql = "SELECT COUNT(*) as count  FROM TopWriteContent WHERE groupbuyid = '" + id + "' AND isok = 1";
                dt3 = db.GetTable(sql);
                if (dt3 != null && dt3.Rows.Count > 0)
                {
                    sql = "UPDATE TopMission SET total = '" + dt3.Rows[0]["count"] + "' WHERE id = " + missionid;
                    db.ExecSql(sql);
                }
            }

            WriteLog("活动创建任务完成*************************************************" + sql, "");
        }
Пример #3
0
        /// <summary>
        ///  获取到期团购,创建取消团购任务
        /// </summary>
        private void DelGroupbuy()
        {
            try
            {
                //获取正在进行中的团购项目
                string appkey  = "12287381";//"12287381";
                string secret  = "d3486dac8198ef01000e7bd4504601a4";
                string session = string.Empty;

                //获取已经结束的团购活动并取消
                DBSql  db  = DBSql.getInstance();
                string sql = "SELECT top 500 * FROM TopGroupBuy WHERE DATEDIFF(s,GETDATE(),endtime) < 0    AND isdelete = 0 and nick<>'' ";
                WriteLog("自动取消活动开始运行。。" + sql, "");
                #region 取消活动 创建取消任务 删除该活动关联的用户群 将该团购标志为已结束

                DataTable enddt = db.GetTable(sql);
                if (enddt == null)
                {
                    WriteLog("自动取消活动开始运行结束 没有到期活动", "");
                    return;
                }
                WriteLog("自动取消活动开始运行结束  到期活动" + enddt.Rows.Count.ToString() + "个", "");
                //通过接口将该用户加入人群
                for (int y = 0; y < enddt.Rows.Count; y++)
                {
                    //活动id为空
                    if (enddt.Rows[y]["promotionid"].ToString().Trim() == "0")
                    {
                        WriteLog("自动取消活动运行中。。promotionid为空" + enddt.Rows[y]["nick"].ToString(), "");
                        sql = "UPDATE TopGroupBuy SET isdelete = 1 WHERE id = " + enddt.Rows[y]["id"].ToString();
                        db.ExecSql(sql);
                        continue;
                    }
                    //店铺id为空
                    if (enddt.Rows[y]["nick"].ToString().Trim() == "")
                    {
                        sql = "UPDATE TopGroupBuy SET isdelete = 1 WHERE id = " + enddt.Rows[y]["id"].ToString();
                        WriteLog("自动取消活动运行中。。nick为空" + enddt.Rows[y]["nick"].ToString(), "");
                        db.ExecSql(sql);
                        continue;
                    }
                    sql = "SELECT session FROM TopTaobaoShop WHERE nick = '" + enddt.Rows[y]["nick"].ToString() + "'";

                    WriteLog("自动取消活动运行中。。" + sql, "");
                    DataTable dtnick = db.GetTable(sql);
                    if (dtnick.Rows.Count != 0)
                    {
                        session = db.GetTable(sql).Rows[0]["session"].ToString();
                    }
                    //店铺session为空
                    if (session == "")
                    {
                        WriteLog("自动取消活动运行中。。session为空" + enddt.Rows[y]["nick"].ToString(), "");
                        sql = "UPDATE TopGroupBuy SET isdelete = 1 WHERE id = " + enddt.Rows[y]["id"].ToString();
                        db.ExecSql(sql);
                        continue;
                    }
                    //取消该活动
                    IDictionary <string, string> paramnew = new Dictionary <string, string>();
                    paramnew.Add("promotion_id", enddt.Rows[y]["promotionid"].ToString());
                    string resultnew = Post("http://gw.api.taobao.com/router/rest", appkey, secret, "taobao.marketing.promotion.delete", session, paramnew);

                    WriteLog("自动取消活动运行中。。清除代码" + resultnew, "");
                    //创建删除活动关联的宝贝描述
                    Delete(enddt.Rows[y]["nick"].ToString(), enddt.Rows[y]["id"].ToString());
                    //将该团购标志为已结束
                    sql = "UPDATE TopGroupBuy SET isdelete = 1 WHERE id = " + enddt.Rows[y]["id"].ToString();

                    db.ExecSql(sql);
                }
                #endregion


                enddt.Dispose();

                WriteLog("自动取消活动运行结束*************************************************", "");
                //休息后继续循环-默认15分钟一次
                Thread.Sleep(600000);

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