Beispiel #1
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            /*
             * 1.保存Token、链接、公众号名称,并且设置注册也验证状态都为开启状态;
             * 2.保存或者更改注册回复;
             * 3.保存或者更改菜单回复;
             *
             */

            try
            {
                user = Comm.DataLoadTool.GetCurrUserModel();
                user.WeixinPublicName = this.txtWeinxinPublicName.Text.Trim();
                user.WeixinAPIUrl     = this.lbURL.Text.Trim();
                user.WeixinToken      = this.txtToken.Text.Trim();

                user.WeixinIsEnableMenu = int.Parse(rblEnableMenu.SelectedValue);
                user.IsWeixinVerify     = int.Parse(rblIsWeixinVerify.SelectedValue);

                user.WeixinAppId     = txtAppId.Text;
                user.WeixinAppSecret = txtAppSecret.Text;
                if (user.WeixinIsEnableMenu == 0)
                {
                    weixinBll.DeleteWeixinClientMenu(weixinBll.GetAccessToken(user.UserID));
                }



                //关闭内定注册模块
                user.WeixinIsOpenReg      = 0;
                user.WeixinRegIsVerifySMS = 0;

                this.userBll.Update(user);

                ZentCloud.BLLJIMP.Model.WeixinReplyRuleInfo regModel = weixinBll.Get <ZentCloud.BLLJIMP.Model.WeixinReplyRuleInfo>(string.Format(" UserID = '{0}' and RuleType = 3 ", user.UserID));

                if (regModel != null)
                {
                    regModel.MsgKeyword = this.txtRegKeyWord.Text.Trim();
                    this.weixinBll.Update(regModel);
                }
                else
                {
                    regModel = new WeixinReplyRuleInfo();
                    regModel.ReplyContent = "请输入手机号码进行注册";
                    regModel.ReplyType    = "text";
                    regModel.ReceiveType  = "text";
                    regModel.MatchType    = "全文匹配";
                    regModel.UserID       = user.UserID;
                    regModel.UID          = this.weixinBll.GetGUID(BLLJIMP.TransacType.WeixinReplyRuleAdd);
                    regModel.RuleType     = 3;
                    regModel.MsgKeyword   = this.txtRegKeyWord.Text.Trim();
                    regModel.CreateDate   = DateTime.Now;
                    this.weixinBll.Add(regModel);
                }

                ZentCloud.BLLJIMP.Model.WeixinReplyRuleInfo menuModel = weixinBll.Get <ZentCloud.BLLJIMP.Model.WeixinReplyRuleInfo>(string.Format(" UserID = '{0}' and RuleType = 4 ", user.UserID));

                if (menuModel != null)
                {
                    menuModel.MsgKeyword   = this.txtMenuKeyWord.Text.Trim();
                    menuModel.ReplyContent = this.txtMenuContent.Text.Trim();
                    this.weixinBll.Update(menuModel);
                }
                else
                {
                    menuModel = new WeixinReplyRuleInfo();
                    menuModel.ReplyContent = this.txtMenuContent.Text.Trim();
                    menuModel.ReplyType    = "text";
                    menuModel.ReceiveType  = "text";
                    menuModel.MatchType    = "全文匹配";
                    menuModel.UserID       = user.UserID;
                    menuModel.UID          = this.weixinBll.GetGUID(BLLJIMP.TransacType.WeixinReplyRuleAdd);
                    menuModel.RuleType     = 4;
                    menuModel.MsgKeyword   = this.txtMenuKeyWord.Text.Trim();
                    menuModel.CreateDate   = DateTime.Now;
                    this.weixinBll.Add(menuModel);
                }

                //添加默认注册流程
                if (this.weixinBll.GetList <WXFlowInfo>(string.Format(" UserID = '{0}' and FlowSysType = 3", user.UserID)).Count.Equals(0))
                {
                    this.weixinBll.AddUserDefaultFlow(user.UserID);
                }

                this.ShowMessge("保存成功!");
            }
            catch (Exception ex)
            {
                this.ShowMessge("保存失败:" + ex.Message);
            }
        }
Beispiel #2
0
        /// <summary>
        /// 分享统计
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        private string GetShareCountStatistics(HttpContext context)
        {
            string preId = context.Request["preId"], //shareId,每次查询是取出传入shareId的子集
                   mid   = context.Request["mid"];

            bool          isRoot       = false;
            StringBuilder strShareInfo = new StringBuilder(" 1=1 ");

            if (string.IsNullOrWhiteSpace(preId))
            {
                //一级目录,返回一级分享和当前检测实体信息, 分享总数  阅读总数  成果总数
                strShareInfo.Append(" AND ( PreId = '' OR PreId IS NULL)");
                isRoot = true;
            }
            else
            {
                if (preId.IndexOf(',') > 0)
                {
                    var tmpList = preId.Split(',').ToList();
                    strShareInfo.AppendFormat(" AND PreId in ({0}) ", Common.StringHelper.ListToStr <string>(tmpList, "'", ","));
                }
                else
                {
                    strShareInfo.AppendFormat(" AND PreId = '{0}' ", preId);
                }
            }

            strShareInfo.AppendFormat(" AND MonitorId = {0} ", mid);

            var shareList = this.bll.GetList <ShareInfo>(strShareInfo.ToString());

            //share信息处理,按个人分享数归类到一块
            List <object> shareResultList = new List <object>();

            #region share信息处理

            if (shareList != null && shareList.Count > 0)
            {
                //取出分享人列表
                var               sharerList = shareList.GroupBy(p => p.UserId).ToList();
                BLLJIMP.BLLUser   userBll    = new BLLJIMP.BLLUser();
                BLLJIMP.BLLWeixin wxBll      = new BLLJIMP.BLLWeixin();

                foreach (var item in sharerList)
                {
                    //获取user信息
                    var userInfo = userBll.GetUserInfo(item.Key);

                    if (userInfo == null)
                    {
                        continue;
                    }

                    //TODO:如果没有头像和姓名  需要去接口取相关头像和姓名 并保存到数据库
                    try
                    {
                        if (string.IsNullOrWhiteSpace(userInfo.WXHeadimgurl))
                        {
                            string accesstoken   = wxBll.GetAccessToken(userInfo.WebsiteOwner);
                            var    newflowerInfo = wxBll.GetWeixinUserInfo(accesstoken, userInfo.WXOpenId);

                            userInfo.WXHeadimgurl = newflowerInfo.headimgurl;
                            userInfo.WXNickname   = newflowerInfo.nickname;

                            this.bll.Update(
                                new UserInfo(),
                                string.Format(" WXHeadimgurl='{0}',WXNickname='{1}' ", userInfo.WXHeadimgurl, userInfo.WXNickname),
                                string.Format(" UserID='{0}' ", userInfo.UserID)
                                );
                        }
                    }
                    catch { }//TODO:临时方案取用户信息,如果出现异常暂时不处理

                    //获取ShareIds
                    var userShareList = shareList.Where(p => (p.UserId != null && p.UserId.ToLower() == userInfo.UserID.ToLower())).Select(p => p.ShareId).ToList();

                    //获取子分享数(所有shareIds的子分享数)
                    var childShareCount = this.bll.GetCount <ShareInfo>(string.Format(" PreId in ({0}) ", Common.StringHelper.ListToStr <string>(userShareList, "'", ",")));

                    //获取阅读数(所有shareIds的阅读总数)
                    var readCount = this.bll.GetCount <ShareReaderInfo>(string.Format(" ShareId in ({0}) ", Common.StringHelper.ListToStr <string>(userShareList, "'", ",")));

                    //获取分享数(等于shareIds总数)
                    var shareCount = userShareList.Count;

                    //获取成果数(所有shareIds带来的报名数,目前统计的是校服对应的那个报名表来统计)
                    //var achievement = this.bll.GetCount<VoteObjectInfo>(string.Format(" ComeonShareId in ({0}) ", Common.StringHelper.ListToStr<string>(userShareList, "'", ",")));

                    //成果数改成活动报名数,取出分享的活动id,查询活动报名是来自哪个用户或者哪个分享id

                    //var achievement =
                    //    this.bll.GetCount<VoteObjectInfo>(string.Format(" ComeonShareId in ({0}) ", Common.StringHelper.ListToStr<string>(userShareList, "'", ",")));

                    var achievement =
                        this.bll.GetCount <ActivityDataInfo>(string.Format(" ShareID in ({0}) ", Common.StringHelper.ListToStr <string>(userShareList, "'", ",")));

                    shareResultList.Add(new
                    {
                        tmpDataKey = Guid.NewGuid().ToString(),
                        userInfo   = new
                        {
                            avatar   = userInfo.WXHeadimgurl,
                            userName = string.IsNullOrWhiteSpace(userInfo.WXNickname) ? "" : userInfo.WXNickname,
                            userId   = userInfo.UserID,
                            wxOpenId = userInfo.WXOpenId
                        },
                        shareIds        = userShareList,
                        preId           = preId,
                        childShareCount = childShareCount,
                        readCount       = readCount,
                        shareCount      = shareCount,
                        achievement     = achievement//成果
                    });
                }
            }
            #endregion

            object rootInfo = new object();

            #region rootInfo处理
            if (isRoot)
            {
                //当前检测实体信息, 分享总数  阅读总数  成果总数
                var monitor         = this.bll.Get <ShareMonitorInfo>(string.Format(" MonitorId = {0} ", mid));
                var shareTotalCount = this.bll.GetCount <ShareInfo>(string.Format(" MonitorId = {0} ", mid));

                //阅读总数= 分享的阅读总数 + 直接阅读总数(未分享)
                var readTotalCount = this.bll.GetCount <ShareReaderInfo>(string.Format(" MonitorId = {0} ", mid));

                //成果总数= 分享的成功总数
                var achievementTotalCount = 0;

                //取出所有分享id
                var allShareList = this.bll.GetList <ShareInfo>(string.Format(" MonitorId = {0} ", mid));
                if (allShareList != null && allShareList.Count > 0)
                {
                    var allShareIds = allShareList.Select(p => p.ShareId).ToList();
                    readTotalCount += this.bll.GetCount <ShareReaderInfo>(string.Format(" ShareId IN ({0}) ", Common.StringHelper.ListToStr <string>(allShareIds, "'", ",")));

                    achievementTotalCount = this.bll.GetCount <VoteObjectInfo>(string.Format(" ComeonShareId IN ({0}) ", Common.StringHelper.ListToStr <string>(allShareIds, "'", ",")));
                }
                rootInfo = new
                {
                    title                 = monitor.MonitorName,
                    shareTotalCount       = shareTotalCount,
                    readTotalCount        = readTotalCount,
                    achievementTotalCount = achievementTotalCount
                };
            }
            #endregion

            return(Common.JSONHelper.ObjectToJson(new
            {
                rootInfo = isRoot ? rootInfo : null,
                shareResultList = shareResultList
            }));
        }