Пример #1
0
        public StateCode SaveDefaultSets(DefaultSet defaultSet)
        {
            using (ISession s = SessionFactory.Instance.CreateSession())
            {
                try
                {
                    s.StartTransaction();

                    //关注时回复 设置
                    if (!string.IsNullOrEmpty(defaultSet.a_reply_value) && defaultSet.a_reply_value.IndexOf("#") != -1)
                    {
                        int biz_id = 0;
                        //图文或文本类型
                        string a_type = defaultSet.a_reply_value.Split('#')[1];
                        //图文或文本ID
                        string a_biz_id = defaultSet.a_reply_value.Split('#')[0];

                        int.TryParse(a_biz_id, out biz_id);

                        if (KeyWordBizType.TextReply.Equals(a_type))
                        {
                            TextReply textReply = s.Get <TextReply>(biz_id);
                            if (textReply == null)
                            {
                                defaultSet.a_reply_value = null;
                            }
                        }
                        else if (KeyWordBizType.ImgTextReply.Equals(a_type))
                        {
                            ImgTextReply imgTextReply = s.Get <ImgTextReply>(biz_id);
                            if (imgTextReply == null)
                            {
                                defaultSet.a_reply_value = null;
                            }
                        }
                        else
                        {
                            defaultSet.a_reply_value = null;
                        }
                    }
                    else
                    {
                        defaultSet.a_reply_value = null;
                    }

                    //默认无匹配关键词ID
                    if (!string.IsNullOrEmpty(defaultSet.d_reply_value) && defaultSet.d_reply_value.IndexOf("#") != -1)
                    {
                        int biz_id = 0;
                        //图文或文本类型
                        string d_type = defaultSet.d_reply_value.Split('#')[1];
                        //图文或文本ID
                        string d_biz_id = defaultSet.d_reply_value.Split('#')[0];

                        int.TryParse(d_biz_id, out biz_id);

                        if (KeyWordBizType.TextReply.Equals(d_type))
                        {
                            TextReply textReply = s.Get <TextReply>(biz_id);
                            if (textReply == null)
                            {
                                defaultSet.d_reply_value = null;
                            }
                        }
                        else if (KeyWordBizType.ImgTextReply.Equals(d_type))
                        {
                            ImgTextReply imgTextReply = s.Get <ImgTextReply>(biz_id);
                            if (imgTextReply == null)
                            {
                                defaultSet.d_reply_value = null;
                            }
                        }
                        else
                        {
                            defaultSet.d_reply_value = null;
                        }
                    }
                    else
                    {
                        defaultSet.d_reply_value = null;
                    }

                    DefaultSet dSet = s.Get <DefaultSet>("where id != @0 ", 0);
                    if (dSet == null)
                    {
                        s.Insert <DefaultSet>(defaultSet);
                    }
                    else
                    {
                        defaultSet.id = dSet.id;
                        s.Update <DefaultSet>(defaultSet);
                    }
                }
                catch
                {
                    s.RollBack();
                    return(StateCode.State_500);
                }
                s.Commit();
                return(StateCode.State_200);
            }
        }
Пример #2
0
        /// <summary>
        /// 菜单初始化
        /// </summary>
        /// <param name="nemu_id"></param>
        /// <returns></returns>
        public DefineMenuGroup Init(long menu_id)
        {
            using (ISession s = SessionFactory.Instance.CreateSession())
            {
                //获取当前
                DefineMenuGroup menu_group = s.Get <DefineMenuGroup>(menu_id);
                //当前菜单是否存在
                if (menu_group != null)
                {
                    List <DefineMenu> buttons = s.List <DefineMenu>("where group_id = @0 order by sort asc", menu_group.id);
                    foreach (DefineMenu menu in buttons)
                    {
                        //内容
                        DefineMenuBizContent content = new DefineMenuBizContent();
                        //如果是主菜单且存在子菜单
                        if (menu.parent_id == 0 && buttons.Exists(b => b.parent_id == menu.id))
                        {
                            continue;
                        }

                        if ("click".Equals(menu.type))
                        {
                            //对应关键词
                            KeyWord keyWord = s.Get <KeyWord>("where keyword = @0", menu.key_val);
                            if (keyWord == null)
                            {
                                continue;
                            }

                            if ("ImgTextReply".Equals(keyWord.biz_type))
                            {
                                menu.biz_type = 1;
                                ImgTextReply imgTextReply = s.Get <ImgTextReply>(keyWord.biz_id);
                                if (imgTextReply != null)
                                {
                                    Img img = s.Get <Img>(" where biz_type = @0 and biz_id = @1", ImgType.ImgTextReply_Title, imgTextReply.id);
                                    content.id      = imgTextReply.id;
                                    content.imgurl  = img == null ? "" : img.getImgUrl();
                                    content.key_val = keyWord.keyword;
                                }
                            }
                            else
                            {
                                menu.biz_type = 2;
                                TextReply textReply = s.Get <TextReply>(keyWord.biz_id);
                                content.id      = textReply.id;
                                content.key_val = keyWord.keyword;
                                content.text    = keyWord.keyword;
                            }
                        }
                        else
                        {
                            content.key_val = menu.key_val;
                        }

                        menu.biz_content = content;
                    }

                    menu_group.buttons = buttons;
                }
                return(menu_group);
            }
        }
Пример #3
0
        /// <summary>
        /// 图文回复
        /// </summary>
        /// <param name="user"></param>
        /// <param name="entity"></param>
        /// <param name="keywords"></param>
        /// <param name="imgmsg"></param>
        /// <returns></returns>
        public IActionResult ImgTextReplyForm(SysUser user, ImgTextReply entity = null, string[] keywords = null, string imgmsg = null)
        {
            if (Request.IsAjaxRequest())
            {
                StateCode state = ServiceIoc.Get <ImgTextReplyService>().Save(user, entity, keywords, imgmsg);
                return(Json(GetResult(state)));
            }
            else
            {
                //上传票据ID
                ViewBag.Ticket = StringHelper.GetEncryption(ImgType.ImgTextReply_Title + "#" + bid.ToString());
                //上传票据ID
                ViewBag.DetailsTicket = StringHelper.GetEncryption(ImgType.ImgTextReply_Details + "#" + bid.ToString());
                //缺省图片路径
                ViewBag.defimgurl = ResXmlConfig.Instance.DefaultImgSrc(AppGlobal.Res, ImgType.ImgTextReply_Title);
                //用户图片路径
                ViewBag.imgurl = string.Empty;

                //缺省图片路劲
                ViewBag.defurl = ResXmlConfig.Instance.DefaultImgSrc(AppGlobal.Res, ImgType.ImgTextReply_Title);
                ViewBag.imgurl = ViewBag.defimgurl;

                //地图坐标
                ViewBag.lat_lng      = "22.541234,114.06262";
                ViewBag.address_text = "广东省深圳市福田区益田路48号";

                /**********回复外链类型************/
                Dictionary <int, string> imgTextTypes = new Dictionary <int, string>();
                imgTextTypes.Add(MsgContentType.ImgTextDetails, "请选择");
                foreach (var v in MsgContentType.typeList)
                {
                    imgTextTypes.Add(v.Key, v.Value);
                }
                ViewBag.imgTextTypes = imgTextTypes;

                entity = ServiceIoc.Get <ImgTextReplyService>().GetById(bid);
                if (entity != null)
                {
                    Img img = ServiceIoc.Get <ImgService>().GetImg(ImgType.ImgTextReply_Title, entity.id);
                    if (img != null)
                    {
                        ViewBag.imgurl = img.getImgUrl();
                    }
                    ViewBag.keywords = ServiceIoc.Get <KeyWordService>().GetKeywords(bid, KeyWordBizType.ImgTextReply);
                    ViewBag.entity   = JsonConvert.SerializeObject(entity);

                    long[] moreIds = StringHelper.StringToLongArray(entity.quote_detailsIds);
                    //绑定多图文
                    ViewBag.moreImgTextReplys = ServiceIoc.Get <ImgTextReplyService>().GetTextReplysByIds(moreIds);

                    long[] recIds = StringHelper.StringToLongArray(entity.rec_detailsIds);
                    //绑定推荐阅读
                    ViewBag.recImgTextReplys = ServiceIoc.Get <ImgTextReplyService>().GetTextReplysByIds(recIds);

                    switch (entity.content_type)
                    {
                    //外链
                    case MsgContentType.OutLink:
                        ViewBag.outlink = entity.content_value;
                        break;

                    //导航
                    case MsgContentType.Navigation:
                        if (!string.IsNullOrEmpty(entity.content_value) && entity.content_value.IndexOf(",") != -1 && entity.content_value.IndexOf("#") != -1)
                        {
                            string val = entity.content_value.Split('#')[0].ToString();
                            if (val.Length > 3)
                            {
                                ViewBag.lat_lng = val;
                            }
                            ViewBag.address_text = entity.content_value.Split('#')[1].ToString();
                        }
                        break;
                    }
                }

                if (ViewBag.moreImgTextReplys == null)
                {
                    ViewBag.moreImgTextReplys = new List <ImgTextReply>();
                }

                if (ViewBag.recImgTextReplys == null)
                {
                    ViewBag.recImgTextReplys = new List <ImgTextReply>();
                }
            }

            return(View());
        }