package controllers import ( "encoding/json" "hongze/hongze_cygx/models" "hongze/hongze_cygx/utils" "time" ) type YanxuanSpecialController struct { BaseAuthController } // @Title 专栏列表 // @Description 专栏列表 // @Param request body help_doc.AddHelpDocReq true "type json string" // @Success 200 {object} models.AddEnglishReportResp // @router /list [get] func (this *YanxuanSpecialController) List() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() sysUser := this.User if sysUser == nil { br.Msg = "请登录" br.ErrMsg = "请登录,SysUser Is Empty" br.Ret = 408 return } userId, _ := this.GetInt("UserId", 0) var condition string var pars []interface{} var specialUser *models.CygxYanxuanSpecialAuthorItem var err error if userId > 0 { condition += ` AND a.user_id = ? ` pars = append(pars, userId) } specialUser, err = models.GetYanxuanSpecialAuthor(sysUser.UserId) if err != nil && err.Error() != utils.ErrNoRow(){ br.Msg = "获取失败" br.ErrMsg = "获取失败, Err:" + err.Error() return } condition += ` AND a.status = 2 ` list, tmpErr := models.GetYanxuanSpecialList(condition, pars) if tmpErr != nil { br.Msg = "获取失败" br.ErrMsg = "获取失败, Err:" + tmpErr.Error() return } resp := new(models.SpecialListResp) if specialUser != nil { resp.IsAuthor = true } resp.List = list br.Data = resp br.Ret = 200 br.Success = true br.Msg = "获取成功" } // @Title 专栏详情 // @Description 专栏详情 // @Param request body help_doc.AddHelpDocReq true "type json string" // @Success 200 {object} models.AddEnglishReportResp // @router /detail [get] func (this *YanxuanSpecialController) Detail() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() sysUser := this.User if sysUser == nil { br.Msg = "请登录" br.ErrMsg = "请登录,SysUser Is Empty" br.Ret = 408 return } specialId, _ := this.GetInt("Id", 0) if specialId <= 0 { br.Msg = "参数错误" br.ErrMsg = "参数错误" return } item, tmpErr := models.GetYanxuanSpecialById(specialId,sysUser.UserId) if tmpErr != nil { br.Msg = "获取失败" br.ErrMsg = "获取失败, Err:" + tmpErr.Error() return } if item.Status != 3 && item.Status != 2 { br.Msg = "获取失败,专栏未发布" br.ErrMsg = "获取失败, 专栏未发布" br.Ret = 200 return } br.Data = item br.Ret = 200 br.Success = true br.Msg = "获取成功" } // @Title 新增保存专栏作者详情 // @Description 新增保存专栏作者详情 // @Param request body help_doc.AddHelpDocReq true "type json string" // @Success 200 {object} models.AddEnglishReportResp // @router /author/save [post] func (this *YanxuanSpecialController) AuthorSave() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() sysUser := this.User if sysUser == nil { br.Msg = "请登录" br.ErrMsg = "请登录,SysUser Is Empty" br.Ret = 408 return } var req models.SaveCygxYanxuanSpecialAuthorReq err := json.Unmarshal(this.Ctx.Input.RequestBody, &req) if err != nil { br.Msg = "参数解析异常!" br.ErrMsg = "参数解析失败,Err:" + err.Error() return } if req.UserId <= 0 { br.Msg = "用户id有误" return } if req.SpecialName == "" { br.Msg = "请输入专栏名称" return } if req.NickName == "" { br.Msg = "请输入昵称" return } item := models.CygxYanxuanSpecialAuthor{ UserId: req.UserId, SpecialName: req.SpecialName, Introduction: req.Introduction, Label: req.Label, NickName: req.NickName, CreateTime: time.Now(), ModifyTime: time.Now(), BgImg: "", Status: 1, } //if req.Id == 0{ // _, err = models.AddCygxYanxuanSpecialAuthor(&item) // if err != nil { // br.Msg = "新增失败" // br.ErrMsg = "新增失败,Err:" + err.Error() // return // } //} else { // err = models.UpdateYanxuanSpecialAuthor(&item) // if err != nil { // br.Msg = "保存失败" // br.ErrMsg = "保存失败,Err:" + err.Error() // return // } //} err = models.UpdateYanxuanSpecialAuthor(&item) if err != nil { br.Msg = "保存失败" br.ErrMsg = "保存失败,Err:" + err.Error() return } br.Ret = 200 br.Success = true br.Msg = "保存成功" } // @Title 新增保存专栏 // @Description 新增保存专栏 // @Param request body help_doc.AddHelpDocReq true "type json string" // @Success 200 {object} models.AddEnglishReportResp // @router /save [post] func (this *YanxuanSpecialController) Save() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() sysUser := this.User if sysUser == nil { br.Msg = "请登录" br.ErrMsg = "请登录,SysUser Is Empty" br.Ret = 408 return } var req models.CygxYanxuanSpecialReq err := json.Unmarshal(this.Ctx.Input.RequestBody, &req) if err != nil { br.Msg = "参数解析异常!" br.ErrMsg = "参数解析失败,Err:" + err.Error() return } if req.Content == "" { br.Msg = "请输入内容" return } if req.Tags == "" { br.Msg = "请至少输入一个标签" return } item := models.CygxYanxuanSpecial{ Id: req.Id, UserId: sysUser.UserId, CreateTime: time.Now(), ModifyTime: time.Now(), PublishTime: time.Now(), Content: req.Content, Tags: req.Tags, ImgUrl: req.ImgUrl, DocUrl: req.DocUrl, Title: req.Title, Type: req.Type, } if req.DoType == 1 { item.Status = 1 } else { item.Status = 2 } errCode := models.WxCheckContent(req.Content) if errCode != 0{ br.Msg = "文章内容含有违法违规内容" br.ErrMsg = "文章内容含有违法违规内容" return } if req.Id == 0{ _, err = models.AddCygxYanxuanSpecial(&item) if err != nil { br.Msg = "新增失败" br.ErrMsg = "新增失败,Err:" + err.Error() return } } else { err = models.UpdateYanxuanSpecial(&item) if err != nil { br.Msg = "保存失败" br.ErrMsg = "保存失败,Err:" + err.Error() return } } br.Ret = 200 br.Success = true br.Msg = "保存成功" } // @Title 专栏作者详情 // @Description 专栏作者详情 // @Param request body help_doc.AddHelpDocReq true "type json string" // @Success 200 {object} models.AddEnglishReportResp // @router /author/detail [get] func (this *YanxuanSpecialController) AuthorDetail() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() sysUser := this.User if sysUser == nil { br.Msg = "请登录" br.ErrMsg = "请登录,SysUser Is Empty" br.Ret = 408 return } userId, _ := this.GetInt("UserId", 0) if userId == 0 { userId = sysUser.UserId } item, tmpErr := models.GetYanxuanSpecialAuthor(userId) if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() { br.Msg = "获取失败" br.ErrMsg = "获取失败, Err:" + tmpErr.Error() return } br.Data = item br.Ret = 200 br.Success = true br.Msg = "获取成功" } // @Title 审批研选专栏 // @Description 审批研选专栏 // @Param request body help_doc.AddHelpDocReq true "type json string" // @Success 200 {object} models.AddEnglishReportResp // @router /enable [post] func (this *YanxuanSpecialController) Enable() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() sysUser := this.User if sysUser == nil { br.Msg = "请登录" br.ErrMsg = "请登录,SysUser Is Empty" br.Ret = 408 return } var req models.EnableCygxYanxuanSpecialReq err := json.Unmarshal(this.Ctx.Input.RequestBody, &req) if err != nil { br.Msg = "参数解析异常!" br.ErrMsg = "参数解析失败,Err:" + err.Error() return } if req.Id <= 0 { br.Msg = "文章id错误" return } if req.Status <= 0 { br.Msg = "参数错误" return } status := 0 if req.Status == 1 { status = 3 } else { status = 4 } if tmpErr := models.EnableYanxuanSpecial(req.Id, status, req.Reason); tmpErr != nil { br.Msg = "审批失败" br.ErrMsg = "审批失败, Err:" + tmpErr.Error() return } br.Msg = "审批成功" br.Ret = 200 br.Success = true } // @Title 研选专栏收藏 // @Description 研选专栏收藏 // @Param request body help_doc.AddHelpDocReq true "type json string" // @Success 200 {object} models.AddEnglishReportResp // @router /collect [post] func (this *YanxuanSpecialController) Collect() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() sysUser := this.User if sysUser == nil { br.Msg = "请登录" br.ErrMsg = "请登录,SysUser Is Empty" br.Ret = 408 return } var req models.CollectCygxYanxuanSpecialReq err := json.Unmarshal(this.Ctx.Input.RequestBody, &req) if err != nil { br.Msg = "参数解析异常!" br.ErrMsg = "参数解析失败,Err:" + err.Error() return } if req.Id <= 0 { br.Msg = "文章id错误" return } if req.Status <= 0 { br.Msg = "参数错误" return } var sellerName string sellerName, err = models.GetCompanySellerName(sysUser.CompanyId) if err != nil { br.Msg = "报名失败!" br.ErrMsg = "获取对应销售失败,Err:" + err.Error() return } if req.Status == 1 { item := models.CygxYanxuanSpecialCollect{ UserId: sysUser.UserId, Mobile: sysUser.Mobile, Email: sysUser.Email, CompanyId: sysUser.CompanyId, CompanyName: sysUser.CompanyName, RealName: sysUser.RealName, SellerName: sellerName, CreateTime: time.Now(), ModifyTime: time.Now(), RegisterPlatform: utils.REGISTER_PLATFORM, YanxuanSpecialId: req.Id, } _, err = models.AddCygxYanxuanSpecialCollect(&item) if err != nil { br.Msg = "新增失败" br.ErrMsg = "新增失败,Err:" + err.Error() return } br.Msg = "收藏成功" } else { err = models.DelCygxYanxuanSpecialCollect(sysUser.UserId, req.Id) if err != nil { br.Msg = "删除失败" br.ErrMsg = "删除失败,Err:" + err.Error() return } br.Msg = "取消收藏成功" } br.Ret = 200 br.Success = true } // @Title 专栏内容中心 // @Description 专栏内容中心 // @Param request body help_doc.AddHelpDocReq true "type json string" // @Success 200 {object} models.AddEnglishReportResp // @router /center [get] func (this *YanxuanSpecialController) Center() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() sysUser := this.User if sysUser == nil { br.Msg = "请登录" br.ErrMsg = "请登录,SysUser Is Empty" br.Ret = 408 return } // 1:未发布,2:审核中 3:已发布 4:驳回 status, _ := this.GetInt("Status", 0) if status <= 0 { br.Msg = "参数错误" br.ErrMsg = "参数错误" return } var condition string var pars []interface{} condition += ` AND a.user_id = ? ` pars = append(pars, sysUser.UserId) condition += ` AND a.status = ? ` pars = append(pars, status) list, tmpErr := models.GetYanxuanSpecialList(condition, pars) if tmpErr != nil { br.Msg = "获取失败" br.ErrMsg = "获取失败, Err:" + tmpErr.Error() return } br.Data = list br.Ret = 200 br.Success = true br.Msg = "获取成功" } // @Title 专栏点击记录 // @Description 专栏点击记录 // @Param request body models.AddCygxReportSelectionSubjectHistoryReq true "type json string" // @router /record [post] func (this *YanxuanSpecialController) Record() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() user := this.User if user == nil { br.Msg = "请重新登录" br.Ret = 408 return } var req models.AddCygxYanxuanSpecialRecordReq err := json.Unmarshal(this.Ctx.Input.RequestBody, &req) if err != nil { br.Msg = "参数解析异常!" br.ErrMsg = "参数解析失败,Err:" + err.Error() return } if req.SpecialId <= 0 { br.Msg = "文章不存在" br.ErrMsg = "文章不存在,文章ID错误" return } var sellerName string sellerName, err = models.GetCompanySellerName(user.CompanyId) if err != nil { br.Msg = "报名失败!" br.ErrMsg = "获取对应销售失败,Err:" + err.Error() return } item := models.CygxYanxuanSpecialRecord{ UserId: user.UserId, Mobile: user.Mobile, Email: user.Email, CompanyId: user.CompanyId, CompanyName: user.CompanyName, RealName: user.RealName, SellerName: sellerName, CreateTime: time.Now(), ModifyTime: time.Now(), RegisterPlatform: utils.REGISTER_PLATFORM, YanxuanSpecialId: req.SpecialId, } _, err = models.AddCygxYanxuanSpecialRecord(&item) if err != nil { br.Msg = "记录失败" br.ErrMsg = "记录失败,Err:" + err.Error() return } br.Ret = 200 br.Success = true br.Msg = "记录成功" } // @Title 研选专栏关注 // @Description 研选专栏关注 // @Param request body help_doc.AddHelpDocReq true "type json string" // @Success 200 {object} models.AddEnglishReportResp // @router /follow [post] func (this *YanxuanSpecialController) Follow() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() sysUser := this.User if sysUser == nil { br.Msg = "请登录" br.ErrMsg = "请登录,SysUser Is Empty" br.Ret = 408 return } var req models.FollowCygxYanxuanSpecialReq err := json.Unmarshal(this.Ctx.Input.RequestBody, &req) if err != nil { br.Msg = "参数解析异常!" br.ErrMsg = "参数解析失败,Err:" + err.Error() return } if req.FollowUserId <= 0 { br.Msg = "被关注的用户id" return } if req.Status <= 0 { br.Msg = "参数错误" return } var sellerName string sellerName, err = models.GetCompanySellerName(sysUser.CompanyId) if err != nil { br.Msg = "报名失败!" br.ErrMsg = "获取对应销售失败,Err:" + err.Error() return } if req.Status == 1 { item := models.CygxYanxuanSpecialFollow{ UserId: sysUser.UserId, FollowUserId: req.FollowUserId, Mobile: sysUser.Mobile, Email: sysUser.Email, CompanyId: sysUser.CompanyId, CompanyName: sysUser.CompanyName, RealName: sysUser.RealName, SellerName: sellerName, CreateTime: time.Now(), ModifyTime: time.Now(), RegisterPlatform: utils.REGISTER_PLATFORM, YanxuanSpecialId: req.SpecialId, } err = models.AddCygxYanxuanSpecialFollow(&item) if err != nil { br.Msg = "新增失败" br.ErrMsg = "新增失败,Err:" + err.Error() return } br.Msg = "关注成功" } else { err = models.DelCygxYanxuanSpecialFollow(sysUser.UserId, req.FollowUserId) if err != nil { br.Msg = "删除失败" br.ErrMsg = "删除失败,Err:" + err.Error() return } br.Msg = "取消关注成功" } br.Ret = 200 br.Success = true } // @Title 行业标签搜索 // @Description 行业标签搜索 // @Param request body help_doc.AddHelpDocReq true "type json string" // @Success 200 {object} models.AddEnglishReportResp // @router /industrySearch [get] func (this *YanxuanSpecialController) IndustrySearch() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() sysUser := this.User if sysUser == nil { br.Msg = "请登录" br.ErrMsg = "请登录,SysUser Is Empty" br.Ret = 408 return } keyword := this.GetString("Keyword") list, tmpErr := models.GetYanxuanSpecialIndustry(keyword) if tmpErr != nil { br.Msg = "获取失败" br.ErrMsg = "获取失败, Err:" + tmpErr.Error() return } br.Data = list br.Ret = 200 br.Success = true br.Msg = "获取成功" } // @Title 公司标签搜索 // @Description 公司标签搜索 // @Param request body help_doc.AddHelpDocReq true "type json string" // @Success 200 {object} models.AddEnglishReportResp // @router /companySearch [get] func (this *YanxuanSpecialController) CompanySearch() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() sysUser := this.User if sysUser == nil { br.Msg = "请登录" br.ErrMsg = "请登录,SysUser Is Empty" br.Ret = 408 return } keyword := this.GetString("Keyword") if keyword == "" { br.Ret = 200 return } list, tmpErr := models.GetYanxuanSpecialCompany(keyword) if tmpErr != nil { br.Msg = "获取失败" br.ErrMsg = "获取失败, Err:" + tmpErr.Error() return } br.Data = list br.Ret = 200 br.Success = true br.Msg = "获取成功" } // @Title 专栏取消发布 // @Description 专栏取消发布 // @Param request body help_doc.AddHelpDocReq true "type json string" // @Success 200 {object} models.AddEnglishReportResp // @router /cancel [post] func (this *YanxuanSpecialController) Cancel() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() sysUser := this.User if sysUser == nil { br.Msg = "请登录" br.ErrMsg = "请登录,SysUser Is Empty" br.Ret = 408 return } var req models.CancelPublishCygxYanxuanSpecialReq err := json.Unmarshal(this.Ctx.Input.RequestBody, &req) if err != nil { br.Msg = "参数解析异常!" br.ErrMsg = "参数解析失败,Err:" + err.Error() return } if req.Id <= 0 { br.Msg = "文章id错误" return } if tmpErr := models.CancelPublishYanxuanSpecial(req.Id); tmpErr != nil { br.Msg = "取消发布失败" br.ErrMsg = "取消发布失败, Err:" + tmpErr.Error() return } br.Msg = "取消发布成功" br.Ret = 200 br.Success = true }