1. 程式人生 > >微信裡面的簽到加積分介面(已經測試過沒問題)服務號不能每天傳送訊息,為了避免這個,每天簽到的時候,推送一條最新的訊息給客戶。

微信裡面的簽到加積分介面(已經測試過沒問題)服務號不能每天傳送訊息,為了避免這個,每天簽到的時候,推送一條最新的訊息給客戶。

  public string QianDao(string WeiXinId, string key)//引數是微訊號
        {
            strs = WeiXinId.Trim() + "WJXFGCLN+Mihaha";
            strs = DESEncrypt.Encrypt(strs);
            if (strs == key)//驗證
            {
                string qdstr = "";
                DTcms.Model.users user = new BLL.users().LoginWeiXin(WeiXinId);//通過微信id來獲取當前登入使用者的id;
                if (user != null)
                {
                    string spoint = "0";//初始分值
                    string epoint = "0";//每日增長分值
                    string zpoint = "0";//最高分值
                    string day = "0";
                    List<DTcms.Model.dt_qiandaopoint_log> modelpoint = new BLL.dt_qiandaopoint_log().GetModelList(string.Format("parent=0"));//查詢出管理員對應的有沒有資訊
                    if (modelpoint.Count > 0)
                    {
                        for (int i = 0; i < modelpoint.Count; i++)
                        {
                            epoint = modelpoint[i].epoint;//遞增分值
                            zpoint = modelpoint[i].zpoint;//最高分值
                            List<DTcms.Model.dt_qiandaopoint_log> listlog = new BLL.dt_qiandaopoint_log().GetModelList(string.Format("user_id='{0}'", user.id));//根據當前的使用者id查詢當前使用者有沒有簽到過
                            if (listlog.Count > 0)//如果有對應的使用者
                            {
                                for (int j = 0; j < listlog.Count; j++)
                                {
                                    DateTime datetime_old = DateTime.Parse(listlog[j].addtime.ToString());
                                    if (DateTime.Now.AddDays(-1).ToString("yyyyMMdd") == datetime_old.ToString("yyyyMMdd"))//連續簽到的(當天的日期-1=昨天的日期)
                                    {
                                        #region
                                        if (DateTime.Now.AddDays(0).ToString("yyyyMMdd") != datetime_old.ToString("yyyyMMdd"))//如果不是當天的時間就可以簽到
                                        {
                                            day = (Int32.Parse(listlog[j].day) + 1).ToString();//天數
                                            if (listlog[i].spoint == zpoint)//判斷增長分值等於最高連續增長的分值
                                            {
                                                spoint = zpoint;
                                            }
                                            else
                                            {
                                                spoint = (Int32.Parse(listlog[i].epoint) * (Int32.Parse(listlog[i].day) + 1)).ToString();//每天的增長值
                                            }
                                            //新增point_log表(積分表)
                                            Model.point_log modelpointlog = new Model.point_log();
                                            modelpointlog.user_id = Convert.ToInt32(user.id.ToString());
                                            modelpointlog.user_name = user.user_name;
                                            modelpointlog.value = Convert.ToInt32(spoint.ToString());
                                            modelpointlog.remark = "簽到" + int.Parse(day) + "天,送" + spoint + "積分";
                                            modelpointlog.add_time = DateTime.Now;
                                            new BLL.point_log().Add(modelpointlog);


                                            //修改user表(使用者表)
                                            user.point = user.point + Convert.ToInt32(spoint.ToString());
                                            new BLL.users().Update(user);


                                            //存資料(簽到表)
                                            Model.dt_qiandaopoint_log model = new Model.dt_qiandaopoint_log();
                                            model.user_id = user.id.ToString();
                                            model.addtime = DateTime.Now;
                                            model.spoint = spoint;
                                            model.epoint = epoint;
                                            model.zpoint = modelpoint[i].zpoint;
                                            model.day = day;//天數
                                            model.parent = 1;
                                            new BLL.dt_qiandaopoint_log().Add(model);
                                            string points = user.point.ToString();
                                            string a = HttpContext.Current.Request.Url.Authority;
                                            //推送一條訊息
                                            DataSet ds = new BLL.user_message().GetListName(1, user.user_name);
                                            if (ds.Tables[0].Rows.Count > 0)
                                            {
                                                qdstr = "您好,您今天簽到成功!\n今日所獲積分為:" + model.spoint + "分,\n" + "您已連續簽到:" + model.day + "天,\n" + "目前總積分數為:" + points + "分.\n" + "推送訊息:<a href=\'http://" + a + "/user/message/accept.aspx\'>" + ds.Tables[0].Rows[0]["title"].ToString() + "</a>";
                                            }
                                            else
                                            {
                                                qdstr = "您好,您今天簽到成功!\n今日所獲積分為:" + model.spoint + "分,\n" + "您已連續簽到:" + model.day + "天,\n" + "目前總積分數為:" + points + "分.";
                                            }
                                        }
                                        else//如果是當天的時間就說明已經簽到過
                                        {
                                            qdstr = "您好,您今天已經簽到,改天再來吧.";
                                        }
                                        #endregion
                                    }
                                    else //不連續簽到的
                                    {
                                        #region
                                        if (DateTime.Now.AddDays(0).ToString("yyyyMMdd") != datetime_old.ToString("yyyyMMdd"))//如果不是當天的時間就簽到
                                        {
                                            //新增point_log表
                                            Model.point_log modelpointlog = new Model.point_log();
                                            modelpointlog.user_id = Convert.ToInt32(user.id.ToString());
                                            modelpointlog.user_name = user.user_name;
                                            modelpointlog.value = Convert.ToInt32(epoint.ToString());
                                            modelpointlog.remark = "簽到1天,送" + epoint + "積分";
                                            modelpointlog.add_time = DateTime.Now;
                                            int result = new BLL.point_log().Add(modelpointlog);


                                            //修改user表
                                            user.point = user.point + int.Parse(epoint.ToString());
                                            new BLL.users().Update(user);


                                            //存資料
                                            Model.dt_qiandaopoint_log model = new Model.dt_qiandaopoint_log();
                                            model.user_id = user.id.ToString();
                                            model.addtime = DateTime.Now;
                                            model.spoint = epoint;
                                            model.epoint = epoint;
                                            model.zpoint = zpoint;
                                            model.day = "1";//天數
                                            model.parent = 1;
                                            new BLL.dt_qiandaopoint_log().Add(model);
                                            string points = user.point.ToString();
                                            //推送一條訊息
                                            string a = HttpContext.Current.Request.Url.Authority;
                                            DataSet ds = new BLL.user_message().GetListName(1,user.user_name);
                                            if (ds.Tables[0].Rows.Count > 0)
                                            {
                                                qdstr = "您好,您今天簽到成功!\n今日所獲積分為:" + model.spoint + "分,\n" + "您已連續簽到:" + model.day + "天,\n" + "目前總積分數為:" + points + "分.\n" + "推送訊息:<a href=\'http://" + a + "/user/message/accept.aspx\'>" + ds.Tables[0].Rows[0]["title"].ToString() + "</a>";
                                            }
                                            else
                                            {
                                                qdstr = "您好,您今天簽到成功!\n今日所獲積分為:" + model.spoint + "分,\n" + "您已連續簽到:" + model.day + "天,\n" + "目前總積分數為:" + points + "分.";
                                            }
                                        }
                                        else
                                        {
                                            qdstr = "您好,您今天已經簽到,改天再來吧.";
                                        }
                                        #endregion
                                    }


                                }
                            }
                            else//如果之前沒有簽到過的
                            {
                                #region
                                //新增point_log表
                                Model.point_log modelpointlog = new Model.point_log();
                                modelpointlog.user_id = Convert.ToInt32(user.id.ToString());
                                modelpointlog.user_name = user.user_name;
                                modelpointlog.value = Convert.ToInt32(epoint.ToString());
                                modelpointlog.remark = "簽到1天,送" + epoint + "積分";
                                modelpointlog.add_time = DateTime.Now;
                                int result = new BLL.point_log().Add(modelpointlog);


                                //修改user表
                                //  string str = spoint;
                                user.point = user.point + int.Parse(epoint.ToString());
                                new BLL.users().Update(user);


                                //存資料
                                Model.dt_qiandaopoint_log model = new Model.dt_qiandaopoint_log();
                                model.user_id = user.id.ToString();
                                model.addtime = DateTime.Now;
                                model.spoint = epoint;
                                model.epoint = epoint;
                                model.zpoint = zpoint;
                                model.day = "1";//天數
                                model.parent = 1;
                                new BLL.dt_qiandaopoint_log().Add(model);
                                string points = user.point.ToString();


                                //推送一條訊息
                                DataSet ds = new BLL.user_message().GetListName(1, user.user_name);
                                string a = HttpContext.Current.Request.Url.Authority;
                                if (ds.Tables[0].Rows.Count > 0)
                                {
                                    qdstr = "您好,您今天簽到成功!\n今日所獲積分為:" + model.spoint + "分,\n" + "您已連續簽到:" + model.day + "天,\n" + "目前總積分數為:" + points + "分.\n" + "推送訊息:<a href=\'http://" + a + "/user/message/accept.aspx\'>" + ds.Tables[0].Rows[0]["title"].ToString() + "</a>";
                                }
                                else
                                {
                                    qdstr = "您好,您今天簽到成功!\n今日所獲積分為:" + model.spoint + "分,\n" + "您已連續簽到:" + model.day + "天,\n" + "目前總積分數為:" + points + "分.";
                                }


                                #endregion
                            }
                        }
                    }
                    else//管理員沒有添加簽到的積分規則
                    {
                        qdstr = "請聯絡管理員分配簽到功能!!!";
                    }
                    return qdstr;
                }
                else
                {
                    qdstr = "0";//沒有繫結
                }
                return qdstr;
            }
            else
            {
                strs = "驗證失敗";
                return strs;
            }
        }