Exemple #1
0
 protected void Page_Load(object sender, EventArgs e)
 {
     JuactivityInfo = bllJuactivity.GetJuActivityByActivityID(Request["activityid"]);
     ActivityConfig = bllJuactivity.Get <BLLJIMP.Model.ActivityConfig>(string.Format(" WebsiteOwner='{0}'", bllJuactivity.WebsiteOwner));
     if (ActivityConfig == null)
     {
         ActivityConfig = new BLLJIMP.Model.ActivityConfig()
         {
             ShowName = "活动"
         };
     }
 }
Exemple #2
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!string.IsNullOrEmpty(Request["oid"]))
     {
         var currentUserInfo = bll.Get <ZentCloud.BLLJIMP.Model.UserInfo>(string.Format("WXOpenId='{0}'", Request["oid"]));
         if (currentUserInfo != null)
         {
             Session[SessionKey.UserID]     = currentUserInfo.UserID;
             Session[SessionKey.LoginStatu] = 1;
             Session[SessionKey.UserType]   = currentUserInfo.UserType;
         }
     }
     Response.Write(bll.GetTemplateSource(bll.WebsiteOwner, "mypub"));
 }
Exemple #3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                model = bll.GetJuActivity(int.Parse(Request["id"]));
                model.PV++;
                bll.Update(model);
                txtPraiseNum.Text = model.UpCount.ToString();
                try
                {
                    BLLJIMP.Model.ForwardingRecord frecord = bll.Get <BLLJIMP.Model.ForwardingRecord>(string.Format(" FUserID='{0}' AND RUserID='{1}' AND websiteOwner='{2}' AND TypeName = '文章赞'", bll.GetCurrentUserInfo().UserID, int.Parse(Request["id"]), bll.WebsiteOwner));
                    if (frecord != null)
                    {
                        zan = true;
                    }

                    #region 加投票功能
                    if (model.ActivityDescription.Contains("$TOUPIAO@"))
                    {
                        int    start  = model.ActivityDescription.IndexOf("$TOUPIAO@");
                        int    end    = model.ActivityDescription.LastIndexOf("TOUPIAO$");
                        int    length = end - start - 1;
                        string Voteid = model.ActivityDescription.Substring(model.ActivityDescription.IndexOf("$TOUPIAO@") + 1, length).Replace("TOUPIAO@", null);
                        string str    = "$TOUPIAO@" + Voteid + "TOUPIAO$";
                        model.ActivityDescription = model.ActivityDescription.Replace(str, bll.GetTheVoteInfo(Voteid));
                    }
                    #endregion
                }
                catch (Exception)
                {
                }
            }
            catch (Exception)
            {
                Response.End();
            }
        }
Exemple #4
0
        public void ProcessRequest(HttpContext context)
        {
            //try
            //{
            BLLJIMP.BLLJuActivity   bllJuactivity   = new BLLJIMP.BLLJuActivity("");
            BLLJIMP.BLLUser         bllUser         = new BLLJIMP.BLLUser("");
            BLLJIMP.BLLMonitor      bllMonitor      = new BLLJIMP.BLLMonitor();
            BLLJIMP.BLLWebSite      bllwebSite      = new BLLJIMP.BLLWebSite();
            BLLJIMP.BLLShareMonitor bllShareMonitor = new BLLJIMP.BLLShareMonitor();

            ///推广用户信息
            UserInfo spreadUser = null;

            //分享用户
            UserInfo shareUser = null;

            CompanyWebsite_Config companyConfig = bllwebSite.GetCompanyWebsiteConfig();

            currentUrl = context.Request.Url.ToString(); //当前绝对地址
            string filePath = context.Request.FilePath;  //当前相对路径

            #region 微信推广(展示文章页面)
            if (filePath.Contains(".chtml"))
            {
                ToLog(context, " monitorhandler filePath:" + filePath);
                string[] parameters = filePath.Split('/');
                if (parameters.Length > 2)
                {
                    int activityId = Convert.ToInt32(parameters[1], 16);//ZCJ_JuActivityInfo 文章ID;
                    ToLog(context, " monitorhandler 文章ID:" + activityId);
                    long memberID = 0;

                    if (parameters.Length > 3)
                    {
                        //memberID = parameters[2] == "XXX" ? 0 : Convert.ToInt32(parameters[2], 16);//ZCJ_WXMemberInfo 会员注册ID;
                        spreadUser = bllUser.GetUserInfoByAutoID(Convert.ToInt32(parameters[2], 16));
                    }


                    string currOpenerOpenID = parameters.Length > 5 ? parameters[3] : string.Empty;//当前打开者的OpenID

                    string spreadUserID = context.Request["spreadU"] == null ? "" : context.Request["spreadU"].ToString();

                    string shareTimestamp = context.Request["shareTimestamp"];

                    if (!string.IsNullOrWhiteSpace(spreadUserID))
                    {
                        spreadUserID = Common.Base64Change.DecodeBase64ByUTF8(spreadUserID);
                    }

                    string spreadUserAutoIDStr = context.Request["ua"] == null ? "" : context.Request["ua"].ToString();//推广ID,原始id*1000,16进制后进行base64,然后“=”变成“_”
                    int    spreadUserAutoID    = 0;
                    if (!string.IsNullOrWhiteSpace(spreadUserAutoIDStr))
                    {
                        spreadUserAutoID = bllJuactivity.TransmitIntDeCode(spreadUserAutoIDStr);//Convert.ToInt32(Common.Base64Change.DecodeBase64ByUTF8(spreadUserAutoIDStr.Replace("_", "=")), 16) / 1000;
                    }

                    string shareId = context.Request["comeonshareid"] == null ? "" : context.Request["comeonshareid"].ToString();

                    if (!string.IsNullOrWhiteSpace(shareId))
                    {
                        ToLog(context, " monitorhandler 执行shareId查找分享任务: " + shareId);
                        try
                        {
                            var shareInfo = bllShareMonitor.GetShareInfo(shareId);

                            if (!string.IsNullOrWhiteSpace(shareInfo.UserId))
                            {
                                shareUser = bllUser.GetUserInfo(shareInfo.UserId);
                            }
                        }
                        catch (Exception ex)
                        {
                            ToLog(context, " monitorhandler 获取shareUser异常: " + ex.Message);
                        }
                    }



                    JuActivityInfo activityInfo = bllJuactivity.Get <JuActivityInfo>(string.Format("JuActivityID={0} AND IsDelete=0 ", activityId));//文章信息

                    if (activityInfo == null)
                    {
                        context.Response.WriteFile("/Error/NotExist.html");
                        return;
                    }

                    ToLog(context, " monitorhandler 找到文章,开始构造内容: " + activityInfo.JuActivityID);

                    //if (activityInfo.ArticleType == "activity")
                    //{
                    //    if (activityInfo.ActivityStatus == 1)
                    //    {
                    //        context.Response.Redirect("/Error/CommonMsg.aspx?msg=报名已结束,有疑问请联系我们&&icon=icon iconfont icon-kulian kulian");
                    //        return;
                    //    }
                    //}

                    #region 检查是否付费活动

                    if (activityInfo.IsFee == 1 && !bllJuactivity.IsLogin)
                    {
                        context.Response.Redirect("/App/Cation/Wap/FreeActivityPage.aspx?aid=" + activityInfo.JuActivityID);
                        return;
                    }
                    #endregion

                    #region 检查访问级别
                    if (activityInfo.AccessLevel > 0)
                    {
                        if (!bllUser.IsLogin)
                        {
                            appLoginUrl = Common.ConfigHelper.GetConfigString("appLoginUrl").ToLower();
                            context.Response.Redirect(appLoginUrl + string.Format("?redirect=" + HttpUtility.UrlEncode(currentUrl)), true);
                            return;
                        }
                        //else if (!bllUser.IsMember() && activityInfo.AccessLevel == 1)
                        //{

                        //}
                        else if (bllUser.GetCurrentUserInfo().AccessLevel < activityInfo.AccessLevel)
                        {
                            //if (companyConfig.NoPermissionsPage == 0)
                            //{
                            //    context.Response.WriteFile("/Error/NoPmsMobile.htm");
                            //    return;
                            //}
                            //else if (companyConfig.NoPermissionsPage == 1)
                            //{
                            //    context.Response.Redirect("/App/Cation/Wap/UserEdit.aspx",true);
                            //    context.Response.End();
                            //    return;
                            //}
                            context.Response.WriteFile("/Error/NoPmsMobile.htm");
                            return;
                        }
                    }
                    #endregion

                    #region 检查访问级别

                    //WXMemberInfo regInfo = juactivityBll.Get<WXMemberInfo>(string.Format("MemberID={0}", memberID));//会员注册信息
                    // UserInfo userInfo = juactivityBll.Get<UserInfo>(string.Format("UserID='{0}'", activityInfo.UserID));//文章发布者信息
                    SystemSet systemset  = bllJuactivity.Get <SystemSet>(""); //系统配置信息
                    string    pageSource = "";                                //待输出的html源代码

                    if (systemset != null)
                    {
                        if (string.IsNullOrWhiteSpace(currOpenerOpenID))
                        {
                            //取得Session里的当前OpenID
                            currOpenerOpenID = context.Session[systemset.WXCurrOpenerOpenIDKey] != null ? context.Session[systemset.WXCurrOpenerOpenIDKey].ToString() : "";
                        }

                        if (string.IsNullOrWhiteSpace(currOpenerOpenID))
                        {
                            //如果再为空,由链接上面get参数获取
                            currOpenerOpenID = context.Request[systemset.WXCurrOpenerOpenIDKey] != null ? context.Request[systemset.WXCurrOpenerOpenIDKey].ToString() : "";
                        }
                    }
                    #endregion



                    //if (regInfo == null)
                    //{
                    //    regInfo = new WXMemberInfo() { Name = "none", WeixinOpenID = "" };
                    //}

                    if ((activityInfo != null))//
                    {
                        //var planInfo = bllJuactivity.Get<MonitorPlan>(string.Format("MonitorPlanID={0}", activityInfo.MonitorPlanID));
                        //if (planInfo == null)
                        //{
                        //    return;
                        //}
                        //else
                        //{
                        //    if (planInfo.PlanStatus == "0")//任务已停止
                        //    {
                        //        return;
                        //    }

                        //}

                        ToLog(context, " monitorhandler 开始执行GetJuactivityHtml: " + activityInfo.JuActivityID);
                        pageSource = bllJuactivity.GetJuactivityHtml(activityInfo, currOpenerOpenID, context.Request.Url.ToString(), spreadUser, shareUser);
                        ToLog(context, " monitorhandler 执行GetJuactivityHtml完毕: " + activityInfo.JuActivityID);

                        #region 事件记录
                        //事件
                        //int OpenCount = 0;//打开人数
                        //int DistinctOpenCount = 0;//独立IP数量
                        MonitorEventDetailsInfo detailInfo = new MonitorEventDetailsInfo();
                        detailInfo.MonitorPlanID  = activityInfo.MonitorPlanID;
                        detailInfo.EventType      = 0;
                        detailInfo.EventBrowser   = HttpContext.Current.Request.Browser == null ? "" : HttpContext.Current.Request.Browser.ToString();
                        detailInfo.EventBrowserID = HttpContext.Current.Request.Browser.Id;;
                        if (HttpContext.Current.Request.Browser.Beta)
                        {
                            detailInfo.EventBrowserIsBata = "测试版";
                        }
                        else
                        {
                            detailInfo.EventBrowserIsBata = "正式版";
                        }

                        detailInfo.EventBrowserVersion = HttpContext.Current.Request.Browser.Version;
                        detailInfo.EventDate           = DateTime.Now;
                        if (HttpContext.Current.Request.Browser.Win16)
                        {
                            detailInfo.EventSysByte = "16位系统";
                        }
                        else
                        if (HttpContext.Current.Request.Browser.Win32)
                        {
                            detailInfo.EventSysByte = "32位系统";
                        }
                        else
                        {
                            detailInfo.EventSysByte = "64位系统";
                        }

                        detailInfo.EventSysPlatform = HttpContext.Current.Request.Browser.Platform;
                        detailInfo.SourceIP         = Common.MySpider.GetClientIP();
                        detailInfo.IPLocation       = Common.MySpider.GetIPLocation(detailInfo.SourceIP);
                        detailInfo.SourceUrl        = HttpContext.Current.Request.Url.ToString();
                        detailInfo.RequesSourcetUrl = HttpContext.Current.Request.UrlReferrer != null?HttpContext.Current.Request.UrlReferrer.ToString() : "";

                        if (spreadUser != null)
                        {
                            detailInfo.SpreadUserID = spreadUser.UserID;
                        }
                        detailInfo.SpreadUserAutoID = spreadUserAutoID;
                        detailInfo.ShareTimestamp   = shareTimestamp;
                        detailInfo.WebsiteOwner     = bllJuactivity.WebsiteOwner;
                        detailInfo.ModuleType       = activityInfo.ArticleType;
                        if (bllUser.IsLogin)
                        {
                            detailInfo.EventUserID = bllUser.GetCurrUserID();
                        }


                        if (spreadUser != null)//带推广信息
                        {
                            //try
                            //{
                            //    if (!string.IsNullOrWhiteSpace(currOpenerOpenID))
                            //    {
                            //        //记录触发人
                            //        UserInfo eventUser = new BLLJIMP.BLLUser("").GetUserInfoByOpenId(currOpenerOpenID);
                            //        detailInfo.EventUserID = eventUser.UserID;
                            //    }
                            //}
                            //catch { }
                            string          url = string.Format("http://{0}{1}", context.Request.Url.Host, filePath);
                            MonitorLinkInfo linkInfo;
                            try
                            {
                                linkInfo = bllJuactivity.Get <MonitorLinkInfo>(string.Format(" LinkName='{0}' And MonitorPlanID={1}", spreadUser.UserID, activityInfo.MonitorPlanID));
                            }
                            catch (Exception ex)
                            {
                                context.Response.Write("ex" + ex.ToString());
                                return;
                            }



                            if (linkInfo != null)
                            {
                                linkInfo.ActivityName   = activityInfo.ActivityName;
                                linkInfo.ThumbnailsPath = activityInfo.ThumbnailsPath;
                                //已经为该用户建立推广链接
                                detailInfo.LinkID = linkInfo.LinkID;
                                //if (linkInfo.OpenCount != null)//增加打开人数
                                //{
                                linkInfo.OpenCount++;
                                //}
                                //else
                                //{
                                //    linkInfo.OpenCount = 1;
                                //}
                                int shareCount = bllJuactivity.GetCount <MonitorEventDetailsInfo>("ShareTimestamp", string.Format(" LinkID ={0} and ShareTimestamp is not null and ShareTimestamp <> '' and ShareTimestamp <> '0' ", linkInfo.LinkID));
                                linkInfo.ShareCount = shareCount;
                                int ipCount = bllJuactivity.GetCount <MonitorEventDetailsInfo>(" SourceIP ", string.Format(" LinkID = {0} ", linkInfo.LinkID));
                                linkInfo.DistinctOpenCount = ipCount;
                                bllJuactivity.Update(linkInfo, string.Format(" OpenCount={0},DistinctOpenCount={1},ShareCount={2}", linkInfo.OpenCount, ipCount, shareCount), string.Format("LinkID={0}", linkInfo.LinkID));
                            }
                            else
                            {
                                //还没有为该用户建立推广链接
                                MonitorLinkInfo newLinkinfo = new MonitorLinkInfo();
                                newLinkinfo.LinkID            = int.Parse(bllJuactivity.GetGUID(ZentCloud.BLLJIMP.TransacType.MonitorLinkID));
                                newLinkinfo.MonitorPlanID     = activityInfo.MonitorPlanID;
                                newLinkinfo.WXMemberID        = memberID;
                                newLinkinfo.LinkName          = spreadUser.UserID;
                                newLinkinfo.RealLink          = url;
                                newLinkinfo.InsertDate        = DateTime.Now;
                                newLinkinfo.OpenCount         = 1;
                                newLinkinfo.ActivityName      = activityInfo.ActivityName;
                                newLinkinfo.ThumbnailsPath    = activityInfo.ThumbnailsPath;
                                newLinkinfo.WebsiteOwner      = bllJuactivity.WebsiteOwner;
                                newLinkinfo.DistinctOpenCount = 1; // ip
                                newLinkinfo.ShareCount        = 0; //分享数
                                if (activityInfo.ArticleType == "article")
                                {
                                    newLinkinfo.ForwardType = "fans";
                                    newLinkinfo.ActivityId  = activityInfo.JuActivityID;
                                }
                                if (!string.IsNullOrEmpty(activityInfo.SignUpActivityID) && activityInfo.ArticleType == "activity")
                                {
                                    newLinkinfo.ActivityId = int.Parse(activityInfo.SignUpActivityID);
                                }

                                StringBuilder sqlWhere = new StringBuilder();
                                sqlWhere.AppendFormat(@"
                                if not exists(select 1 from ZCJ_MonitorLinkInfo where LinkName='{14}' and MonitorPlanID={15} ) 
                                begin
                                    insert into ZCJ_MonitorLinkInfo (LinkID,MonitorPlanID,WXMemberID,LinkName,RealLink,InsertDate,OpenCount,ActivityName,ThumbnailsPath,WebsiteOwner,DistinctOpenCount,ShareCount,ForwardType,ActivityId)
                                                values({0},{1},{2},'{3}','{4}','{5}',{6},'{7}','{8}','{9}',{10},{11},'{12}',{13})
                                end 
                                ", newLinkinfo.LinkID, newLinkinfo.MonitorPlanID, newLinkinfo.WXMemberID, newLinkinfo.LinkName, newLinkinfo.RealLink, newLinkinfo.InsertDate, newLinkinfo.OpenCount, newLinkinfo.ActivityName, newLinkinfo.ThumbnailsPath, newLinkinfo.WebsiteOwner, newLinkinfo.DistinctOpenCount, newLinkinfo.ShareCount, newLinkinfo.ForwardType, newLinkinfo.ActivityId, spreadUser.UserID, activityInfo.MonitorPlanID);


                                if (ZentCloud.ZCDALEngine.DALEngine.ExecuteSql(sqlWhere.ToString()) > 0)
                                {
                                    detailInfo.LinkID = newLinkinfo.LinkID;
                                }
                            }
                        }


                        //添加事件详细
                        //if (!filePath.Contains("?"))
                        //{
                        bllJuactivity.Add(detailInfo);
                        //DistinctOpenCount = juactivityBll.GetCount<ZentCloud.BLLJIMP.Model.MonitorEventDetailsInfo>("SourceIP", string.Format("LinkID={0} and EventType=0", detailInfo.LinkID));
                        //juactivityBll.Update(new MonitorLinkInfo(), string.Format(" OpenCount={0},DistinctOpenCount={1}", OpenCount, DistinctOpenCount), string.Format("LinkID={0}", detailInfo.LinkID));
                        #region 微转发活动加积分
                        if (bllUser.IsLogin && spreadUser != null)
                        {
                            if (activityInfo.ArticleType == "activity")
                            {
                                if (bllJuactivity.GetCount <MonitorEventDetailsInfo>(string.Format(" MonitorPlanID='{0}' And EventUserID='{1}' And SpreadUserID='{2}' And EventUserID!='{2}'", detailInfo.MonitorPlanID, bllUser.GetCurrUserID(), spreadUser.UserID)) == 1)
                                {
                                    string remark = string.Format("转发活动《{0}》", activityInfo.ActivityName);
                                    //微转发加积分
                                    bllUser.AddUserScoreDetail(spreadUser.UserID, CommonPlatform.Helper.EnumStringHelper.ToString(ZentCloud.BLLJIMP.Enums.ScoreDefineType.ForwardArticle), spreadUser.WebsiteOwner, null, remark);
                                }
                            }
                        }
                        #endregion


                        //}
                        context.Response.ClearContent();
                        //处理完成
                        context.Response.Write(pageSource);
                        //更新微信阅读人数
                        //bllJuactivity.UpdateUVCount(activityInfo.JuActivityID);
                        bllJuactivity.UpDateIPPVShareCount(activityInfo);
                        bllJuactivity.UpdateActivityForwardPVUV(activityInfo);
                        if (spreadUser != null)
                        {
                            bllMonitor.UpdateUV(activityInfo.MonitorPlanID, spreadUser.UserID);
                            //bllMonitor.UpdateSignUpCount(activityInfo.MonitorPlanID, spreadUser.UserID);
                        }
                        if (!string.IsNullOrWhiteSpace(activityInfo.RedirectUrl))
                        {
                            context.Response.Redirect(activityInfo.RedirectUrl);
                        }
                        return;

                        #endregion

                        ToLog(context, " monitorhandler 事件记录完毕: " + activityInfo.JuActivityID);
                    }
                    else
                    {
                        context.Response.Write("<html><head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1, maximum-scale=1\" /></head><body>链接无效。</body></html>");
                        return;
                    }
                }
            }
            #endregion
            #region 注释
            //#region 微信会员注册
            //else if (filePath.StartsWith("/weixin"))
            //{

            //    //微信会员注册
            //    if (filePath.Contains("wx_reg.chtml") && (!filePath.Contains("/weixin/wx_reg.chtml")))
            //    {
            //        string[] parameters = filePath.Split('/');

            //        string weixinMemberId = Convert.ToInt32(parameters[2], 16).ToString();// ZCJ_WeixinMemberInfo WeixinMemberID
            //        var weixinmemberinfo = juactivityBll.Get<WeixinMemberInfo>(string.Format("WeixinMemberID={0}", weixinMemberId));
            //        string RegCode = Common.IOHelper.GetFileStr(context.Server.MapPath("/weixin/wx_reg.htm"), Encoding.UTF8);//注册代码

            //        if (RegCode.Contains("$CCWXOPENID$"))
            //        {
            //            RegCode = RegCode.Replace("$CCWXOPENID$", weixinmemberinfo.WeixinOpenID);
            //        }
            //        if (RegCode.Contains("$CCWXAID$"))//注册到哪个账户下
            //        {

            //            RegCode = RegCode.Replace("$CCWXAID$", Convert.ToString(juactivityBll.Get<UserInfo>(string.Format("UserID='{0}'", weixinmemberinfo.UserID)).AutoID, 16));

            //        }

            //        context.Response.Write(RegCode);//输出注册代码


            //        //微信会员注册

            //    }

            //}

            //#endregion
            #endregion

            //}
            //catch (Exception ex)
            //{
            //    using (StreamWriter sw = new StreamWriter(@"C:\MonitorHandlerException.txt", true, Encoding.UTF8))
            //    {
            //        sw.WriteLine(string.Format("{0} MonitorHandler拦截处理异常:{1}", DateTime.Now.ToString(), ex.ToString()));

            //    }
            //    context.Response.Write("exception");
            //}
        }
Exemple #5
0
 private void GetTheVoteInfo(string AutoId)
 {
     model = jubll.Get <BLLJIMP.Model.TheVoteInfo>("  AutoID=" + AutoId);
 }
Exemple #6
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            if (bll.IsLogin)
            {
                currentUserInfo = bll.GetCurrentUserInfo();
            }
            string activityId = context.Request["activity_id"];

            if (string.IsNullOrEmpty(activityId))
            {
                resp.errcode = 1;
                resp.errmsg  = "activity_id 为必填项,请检查";
                context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
                return;
            }
            JuActivityInfo juInfo = bll.GetJuActivity(int.Parse(activityId), true);

            if (juInfo == null)
            {
                resp.errcode = 4;
                resp.errmsg  = "活动不存在!";
                context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
                return;
            }
            #region 是否可以报名
            if (juInfo.ActivityStatus.Equals(1))
            {
                resp.errcode = 2;
                resp.errmsg  = "活动已停止";
                context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
                return;
            }
            if (juInfo.MaxSignUpTotalCount > 0)//检查报名人数
            {
                if (juInfo.SignUpTotalCount > (juInfo.MaxSignUpTotalCount - 1))
                {
                    resp.errcode = 3;
                    resp.errmsg  = "报名人数已满";
                    context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
                    return;
                }
            }
            if (juInfo.ActivityIntegral > 0)
            {
                if (currentUserInfo.TotalScore < juInfo.ActivityIntegral)
                {
                    resp.errcode = 4;
                    resp.errmsg  = "您的积分不足";
                    context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
                    return;
                }
            }
            if (juInfo.GuaranteeCreditAcount > 0)
            {
                if (currentUserInfo.CreditAcount < juInfo.GuaranteeCreditAcount)
                {
                    resp.errcode = 6;
                    resp.errmsg  = "您的信用金不足";
                    context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
                    return;
                }
            }
            #endregion
            dicPar = bll.GetRequestParameter();
            //string weixinOpenID = null;
            string activityIdBySignUp = juInfo.SignUpActivityID;
            string spreadUserId       = null;
            dicPar.TryGetValue("SpreadUserID", out spreadUserId);
            string strDistinctKeys = null;//检查重复的字段,多个字段用,分隔, //没有此参数默认用手机检查
            dicPar.TryGetValue("DistinctKeys", out strDistinctKeys);
            string monitorPlanID = null;
            dicPar.TryGetValue("MonitorPlanID", out monitorPlanID);
            string name = null;
            dicPar.TryGetValue("Name", out name);
            string phone = null;
            dicPar.TryGetValue("Phone", out phone);
            ActivityInfo activity = bll.Get <ActivityInfo>(string.Format("ActivityID='{0}'", activityIdBySignUp));

            #region IP限制
            //获取用户IP;
            string userHostAddress = context.Request.UserHostAddress;
            var    count           = DataCache.GetCache(userHostAddress);
            if (count != null)
            {
                int newCount = int.Parse(count.ToString()) + 1;
                DataCache.SetCache(userHostAddress, newCount);
                int limitCount = 1000;
                if (activity != null)
                {
                    limitCount = activity.LimitCount;
                }
                if (newCount >= limitCount)
                {
                    resp.errcode = 5;
                    resp.errmsg  = "您的提交过于频繁,请稍后再试";
                    context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
                    return;
                }
            }
            else
            {
                DataCache.SetCache(userHostAddress, 1, DateTime.MaxValue, new TimeSpan(4, 0, 0));
            }

            #endregion

            #region 活动权限验证
            if (juInfo == null)
            {
                resp.errcode = 6;
                resp.errmsg  = "活动不存在!";
                context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
                return;
            }
            if (juInfo.ActivityStatus.Equals(1))
            {
                resp.errcode = 7;
                resp.errmsg  = "活动已关闭!";
                context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
                return;
            }

            if (activity.IsDelete.Equals(1))
            {
                resp.errcode = 8;
                resp.errmsg  = "活动已删除!";
                context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
                return;
            }
            #endregion

            #region 判断必填项
            if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(phone))
            {
                resp.errcode = 9;
                resp.errmsg  = "姓名和手机不能为空!";
                context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
                return;
            }

            if ((!phone.StartsWith("1")) || (!phone.Length.Equals(11)))
            {
                resp.errcode = 10;
                resp.errmsg  = "手机号码无效!";
                context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
                return;
            }

            #endregion

            #region 检查自定义必填项
            List <ActivityFieldMappingInfo> listRequiredField = bll.GetList <ActivityFieldMappingInfo>(string.Format("ActivityID='{0}' And FieldIsNull=1", activity.ActivityID));
            if (listRequiredField.Count > 0)
            {
                foreach (var requiredField in listRequiredField)
                {
                    if (string.IsNullOrEmpty(dicPar.SingleOrDefault(p => p.Key.Equals(string.Format("K{0}", requiredField.ExFieldIndex))).Value))
                    {
                        resp.errcode = 11;
                        resp.errmsg  = string.Format(" {0} 必填", requiredField.MappingName);
                        context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
                        return;
                    }
                }
            }
            #endregion

            #region 检查数据格式
            //检查数据格式
            List <ActivityFieldMappingInfo> activityFieldMapping = bll.GetList <ActivityFieldMappingInfo>(string.Format("ActivityID='{0}'", activity.ActivityID));
            foreach (var item in activityFieldMapping)
            {
                string value = dicPar.SingleOrDefault(p => p.Key.Equals(string.Format("K{0}", item.ExFieldIndex))).Value;

                if (string.IsNullOrWhiteSpace(value))
                {
                    continue;
                }

                //检查数据格式
                if (item.FormatValiFunc == "email")//email检查
                {
                    if (!ZentCloud.Common.ValidatorHelper.EmailLogicJudge(value))
                    {
                        resp.errcode = 12;
                        resp.errmsg  = string.Format("{0}格式不正确", item.MappingName);
                        context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
                        return;
                    }
                }
                if (item.FormatValiFunc == "url")                                                                                                             //url检查
                {
                    System.Text.RegularExpressions.Regex regUrl = new System.Text.RegularExpressions.Regex(@"http(s)?://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?"); //网址
                    System.Text.RegularExpressions.Match m      = regUrl.Match(value);
                    if (!m.Success)
                    {
                        resp.errcode = 13;
                        resp.errmsg  = string.Format("{0}格式不正确", item.MappingName);
                        context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
                        return;
                    }
                }
            }
            #endregion

            #region 检查是否已经报名
            if (!string.IsNullOrEmpty(strDistinctKeys))
            {
                if (!strDistinctKeys.Equals("none"))//自定义检查重复
                {
                    System.Text.StringBuilder sb = new System.Text.StringBuilder("1=1 ");
                    string[] distinctKeys        = strDistinctKeys.Split(',');
                    foreach (var item in distinctKeys)
                    {
                        sb.AppendFormat("And {0}='{1}' ", item, dicPar.Single(p => p.Key.Equals(item)).Value);
                    }
                    sb.Append("  and IsDelete = 0  ");
                    if (bll.GetCount <ActivityDataInfo>(sb.ToString()) > 0)
                    {
                        resp.errcode = 14;
                        resp.errmsg  = "重复的报名!";
                        context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
                        return;
                    }
                }
                else//不检查重复
                {
                }
            }
            else//默认检查
            {
                if (bll.GetCount <ActivityDataInfo>(string.Format("ActivityID='{0}' And Phone='{1}' and IsDelete = 0 ", activityIdBySignUp, phone)) > 0)
                {
                    resp.errcode = 15;
                    resp.errmsg  = "已经报过名了!";
                    context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
                    return;
                }
            }



            #endregion


            var newActivityUID       = 1001;
            var lastActivityDataInfo = bll.Get <ActivityDataInfo>(string.Format("ActivityID='{0}' order by UID DESC", activityIdBySignUp));
            if (lastActivityDataInfo != null)
            {
                newActivityUID = lastActivityDataInfo.UID + 1;
            }
            ActivityDataInfo model = bll.ConvertRequestToModel <ActivityDataInfo>(new ActivityDataInfo());
            model.UID          = newActivityUID;
            model.SpreadUserID = spreadUserId;
            model.ActivityID   = activityIdBySignUp;
            if (juInfo.GuaranteeCreditAcount > 0)
            {
                if (model.GuaranteeCreditAcount < juInfo.GuaranteeCreditAcount)
                {
                    resp.errcode = 18;
                    resp.errmsg  = string.Format("担保信用金不能少于{0}!", Convert.ToDouble(juInfo.GuaranteeCreditAcount));
                    context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
                    return;
                }
            }
            if (!string.IsNullOrEmpty(monitorPlanID))
            {
                model.MonitorPlanID = int.Parse(monitorPlanID);
            }
            model.WebsiteOwner = bll.WebsiteOwner;
            if (bll.IsLogin)
            {
                UserInfo curUser = bll.GetCurrentUserInfo();
                model.UserId       = curUser.UserID;
                model.WeixinOpenID = curUser.WXOpenId;
                if (context.Request["limit_userid_signupcount"] == "1")//限制每个登录账号只能报名一次
                {
                    if (bll.GetCount <ActivityDataInfo>(string.Format(" UserId='{0}' AND ActivityID={1} AND IsDelete=0 "
                                                                      , model.UserId, juInfo.SignUpActivityID)) > 0)
                    {
                        resp.errcode = 14;
                        resp.errmsg  = "重复的报名!";
                        context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
                        return;
                    }
                }
                if (context.Request["limit_wxopenid_signupcount"] == "1")//限制每个微信只能报名一次
                {
                    if (bll.GetCount <ActivityDataInfo>(string.Format(" UserId='{0}' AND ActivityID={1} AND IsDelete=0 "
                                                                      , model.WeixinOpenID, juInfo.SignUpActivityID)) > 0)
                    {
                        resp.errcode = 14;
                        resp.errmsg  = "重复的报名!";
                        context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
                        return;
                    }
                }
            }

            if (bll.Add(model))
            {
                bll.PlusNumericalCol("SignUpCount", juInfo.JuActivityID);//报名数+1

                resp.errmsg    = "ok";
                resp.errcode   = 0;
                resp.isSuccess = true;
                #region 当ActivityIntegral>0   扣积分
                if (juInfo.ActivityIntegral > 0)//扣积分
                {
                    currentUserInfo.TotalScore -= juInfo.ActivityIntegral;
                    if (bll.Update(currentUserInfo, string.Format("TotalScore={0}", currentUserInfo.TotalScore), string.Format(" AutoID={0}", currentUserInfo.AutoID)) <= 0)
                    {
                        resp.errcode = 16;
                        resp.errmsg  = "扣除用户积分失败";
                        context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
                        return;
                    }
                    else
                    {
                        //
                        BLLJIMP.Model.WBHScoreRecord scoreRecord = new BLLJIMP.Model.WBHScoreRecord();
                        scoreRecord.Nums         = "b55";
                        scoreRecord.InsertDate   = DateTime.Now;
                        scoreRecord.WebsiteOwner = bll.WebsiteOwner;
                        scoreRecord.UserId       = currentUserInfo.UserID;
                        scoreRecord.RecordType   = "2";
                        scoreRecord.NameStr      = "参加活动:" + juInfo.ActivityName;
                        scoreRecord.ScoreNum     = string.Format("-{0}", juInfo.ActivityIntegral);
                        if (!bll.Add(scoreRecord))
                        {
                            resp.errcode = 17;
                            resp.errmsg  = "插入积分记录失败";
                            context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
                            return;
                        }
                    }
                }
                #endregion

                #region 当ActivityIntegral>0   扣信用金
                if (juInfo.GuaranteeCreditAcount > 0)//扣积分
                {
                    BLLJIMP.BLLUser bllUser = new BLLJIMP.BLLUser();
                    bllUser.AddUserCreditAcountDetails(currentUserInfo.UserID, "ApplyCost", bllUser.WebsiteOwner, 0 - model.GuaranteeCreditAcount
                                                       , string.Format("报名【{0}】消耗{1}信用金", juInfo.ActivityName, Convert.ToDouble(model.GuaranteeCreditAcount)));
                }
                #endregion
            }
            else
            {
                resp.errcode = 1;
                resp.errmsg  = "报名失败,请重试或联系管理员!";
            }
            context.Response.Write(ZentCloud.Common.JSONHelper.ObjectToJson(resp));
        }
 private void GetBarCodeInfo(string AutoId)
 {
     model = jubll.Get <BLLJIMP.Model.BarCodeInfo>("  AutoID=" + AutoId);
 }
Exemple #8
0
        /// <summary>
        /// 接收活动转赠
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        private string ReceiveActivity(HttpContext context)
        {
            if (currentUserInfo==null)
            {
                resp.Msg = "请在微信中打开";
                return ZentCloud.Common.JSONHelper.ObjectToJson(resp);
            }
            string activityId = context.Request["ActivityId"];//活动ID
            string fromUserAutoId = context.Request["FromUserAutoId"];//赠送用户ID
            JuActivityInfo juActivityInfo = bllJuactivity.GetJuActivityByActivityID(activityId);

            //检查
            if (juActivityInfo == null)
            {
                resp.Msg = "转赠活动不存在";
                return ZentCloud.Common.JSONHelper.ObjectToJson(resp);
            }

            UserInfo fromUserInfo = bllUser.GetUserInfoByAutoID(int.Parse(fromUserAutoId));
            if (fromUserInfo == null)
            {
                resp.Msg = "转赠用户不存在";
                return ZentCloud.Common.JSONHelper.ObjectToJson(resp);
            }
            WXSignInInfo signInfo = bllActivity.Get<WXSignInInfo>(string.Format(" JuActivityID='{0}' And SignInUserID='{1}'", juActivityInfo.JuActivityID, fromUserInfo.UserID));
            if (signInfo!=null)
            {
                resp.Msg = "不能接受此转赠";
                return ZentCloud.Common.JSONHelper.ObjectToJson(resp);
            }
            ActivityDataInfo dataInfo = bllActivity.Get<ActivityDataInfo>(string.Format(" ActivityID='{0}' And UserId='{1}' And IsDelete=0 And OrderId!=''  And PaymentStatus=1", activityId, fromUserInfo.UserID));

            if (dataInfo == null)
            {
                resp.Msg = " 不能接受此转赠";
                return ZentCloud.Common.JSONHelper.ObjectToJson(resp);
            }
            if (fromUserInfo.UserID==currentUserInfo.UserID)
            {
                resp.Msg = "不能接收自己的转赠";
                return ZentCloud.Common.JSONHelper.ObjectToJson(resp);
            }
            if (!string.IsNullOrEmpty(dataInfo.ToUserId))
            {
                if (dataInfo.ToUserId == currentUserInfo.UserID)
                {
                    resp.Msg = " 您已经接收过转赠";
                    return ZentCloud.Common.JSONHelper.ObjectToJson(resp);
                }
                else
                {
                    resp.Msg = " 此活动已经转赠过了";
                    return ZentCloud.Common.JSONHelper.ObjectToJson(resp);
                }
            }
            ActivityDataInfo dataCurrentInfo = bllActivity.Get<ActivityDataInfo>(string.Format(" ActivityID='{0}' And UserId='{1}' And IsDelete=0", activityId,currentUserInfo.UserID));
            if (dataCurrentInfo!=null)
            {
                    resp.Msg = " 您已经报名过此活动,不能再接受转赠";
                    return ZentCloud.Common.JSONHelper.ObjectToJson(resp);
            }

            WXMallOrderInfo fromUserOrderInfo = bllMall.GetOrderInfo(dataInfo.OrderId);
            ZentCloud.ZCBLLEngine.BLLTransaction tran = new ZCBLLEngine.BLLTransaction();
            try
            {
                //订单
                WXMallOrderInfo orderInfo = new WXMallOrderInfo();//订单表
                orderInfo.Consignee = bllUser.GetUserDispalyName(currentUserInfo);
                orderInfo.InsertDate = DateTime.Now;
                orderInfo.OrderUserID = currentUserInfo.UserID;
                orderInfo.Phone = currentUserInfo.Phone;
                orderInfo.WebsiteOwner = bllMall.WebsiteOwner;
                orderInfo.OrderID = bllMall.GetGUID(BLLJIMP.TransacType.AddMallOrder);
                orderInfo.MyCouponCardId = fromUserOrderInfo.MyCouponCardId;
                orderInfo.UseScore = fromUserOrderInfo.UseScore;
                orderInfo.Status = "待发货";
                orderInfo.ArticleCategoryType = "Mall";
                orderInfo.OrderType = 4;
                orderInfo.Ex1 = juActivityInfo.ActivityName;
                orderInfo.Ex2 = orderInfo.Ex2;
                orderInfo.Ex3 = orderInfo.Ex3;
                orderInfo.OrderMemo = orderInfo.OrderMemo;
                orderInfo.TotalAmount = fromUserOrderInfo.TotalAmount;
                orderInfo.PaymentStatus = 1;
                orderInfo.PayTime = DateTime.Now;

                //订单
                if (!bllMall.Add(orderInfo,tran))
                {
                    tran.Rollback();
                    resp.Msg = " 插入订单表失败";
                    return ZentCloud.Common.JSONHelper.ObjectToJson(resp);
                }
                ActivityDataInfo newData = new ActivityDataInfo();
                newData.ActivityID = dataInfo.ActivityID;
                newData.UserId = currentUserInfo.UserID;
                newData.WebsiteOwner = bllUser.WebsiteOwner;
                newData.OrderId =orderInfo.OrderID;
                newData.PaymentStatus = 1;
                newData.Name = bllUser.GetUserDispalyName(currentUserInfo);
                newData.Phone = currentUserInfo.Phone;
                newData.FromUserId = fromUserInfo.UserID;
                newData.InsertDate = DateTime.Now;
                newData.UID = bllJuactivity.Get<ActivityDataInfo>(string.Format(" ActivityID='{0}'  Order By UID DESC",activityId)).UID + 1;
                if (!bllJuactivity.Add(newData, tran))
                {
                    tran.Rollback();
                    resp.Msg = " 插入报名表失败";
                    return ZentCloud.Common.JSONHelper.ObjectToJson(resp);
                }
                dataInfo.ToUserId = currentUserInfo.UserID;
                if (!bllJuactivity.Update(dataInfo,tran))
                {
                    tran.Rollback();
                    resp.Msg = " 转赠失败";
                    return ZentCloud.Common.JSONHelper.ObjectToJson(resp);
                }


                string showName = "活动";
                var config = bllActivity.Get<BLLJIMP.Model.ActivityConfig>(string.Format(" WebsiteOwner='{0}'", bllActivity.WebsiteOwner));
                if (config!=null)
                {
                    if (!string.IsNullOrEmpty(config.ShowName))
                    {
                        showName = config.ShowName;
                    }
                }

                bllWeixin.SendTemplateMessageNotifyComm(fromUserInfo, string.Format("{0}转赠通知",showName), string.Format(" {0}已接收你转赠的{1}{2}", bllUser.GetUserDispalyName(currentUserInfo),showName,juActivityInfo.ActivityName));

                bllWeixin.SendTemplateMessageNotifyComm(currentUserInfo, string.Format("{0}接收通知",showName), string.Format(" 您已接收了{0}转赠的{1}{2}", bllUser.GetUserDispalyName(fromUserInfo), showName,juActivityInfo.ActivityName));
               

                tran.Commit();
                resp.Status = 1;
                resp.Msg = "ok";
            }
            catch (Exception ex)
            {
                resp.Msg = ex.Message;
                tran.Rollback();

            }
            return ZentCloud.Common.JSONHelper.ObjectToJson(resp);

        }