/// <summary> /// 文本回复 /// </summary> /// <param name="user"></param> /// <param name="entity"></param> /// <param name="keywords"></param> /// <returns></returns> public IActionResult TextReplyForm(SysUser user, TextReply entity = null, string[] keywords = null) { if (Request.IsAjaxRequest()) { StateCode state = ServiceIoc.Get <TextReplyService>().Save(user, entity, keywords); return(Json(GetResult(state))); } else { TextReply textReply = ServiceIoc.Get <TextReplyService>().GetById(bid); if (textReply != null) { ViewBag.reply_contents = textReply.reply_contents; ViewBag.keywords = ServiceIoc.Get <KeyWordService>().GetKeywords(bid, KeyWordBizType.TextReply); } } return(View()); }
/// <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); } }
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); } }