package cygx import ( "encoding/json" "hongze/hz_crm_api/controllers" "hongze/hz_crm_api/models" "hongze/hz_crm_api/models/cygx" "hongze/hz_crm_api/models/roadshow" cygxService "hongze/hz_crm_api/services/cygx" "hongze/hz_crm_api/utils" "strconv" "time" ) // 权益用户标签 type UserRaiLabelController struct { controllers.BaseAuthController } // @Title 销售输入标签 // @Description 销售输入标签接口 // @Param request body cygx.WxUserRaiLabelAddReq true "type json string" // @Success 200 {object} "保存成功" // @router /use_rai_label/add [post] func (this *UserRaiLabelController) Add() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() AdminUser := this.SysUser if AdminUser == nil { br.Msg = "请登录" br.ErrMsg = "请登录,SysUser Is Empty" br.Ret = 408 return } var req cygx.WxUserRaiLabelAddReq err := json.Unmarshal(this.Ctx.Input.RequestBody, &req) if err != nil { br.Msg = "参数解析异常!" br.ErrMsg = "参数解析失败,Err:" + err.Error() return } userId := req.UserId label := req.Label wxUser, err := models.GetWxUserItemByUserId(userId) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取失败, GetWxUserItemByUserId Err:" + err.Error() return } item := new(cygx.WxUserRaiLabel) item.UserId = wxUser.UserId item.RealName = wxUser.RealName item.Mobile = wxUser.Mobile item.Email = wxUser.Email item.CompanyId = wxUser.CompanyId item.CompanyName = wxUser.CompanyName item.Label = label item.SysUserId = AdminUser.AdminId item.SysUserRealName = AdminUser.RealName item.SourceType = 6 item.CreateTime = time.Now() item.ModifyTime = time.Now() err = cygx.AddWxUserRaiLabel(item) if err != nil { br.Msg = "保存失败" br.ErrMsg = "保存失败,Err:" + err.Error() return } br.Ret = 200 br.Success = true br.IsAddLog = true br.Msg = "操作成功" } // @Title 删除销售输入标签 // @Description 删除销售输入标签接口 // @Param request body cygx.WxUserRaiLabelAddReq true "type json string" // @Success 200 {object} "保存成功" // @router /use_rai_label/delte [post] func (this *UserRaiLabelController) Delte() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() AdminUser := this.SysUser if AdminUser == nil { br.Msg = "请登录" br.ErrMsg = "请登录,SysUser Is Empty" br.Ret = 408 return } var req cygx.WxUserRaiLabelIdReq err := json.Unmarshal(this.Ctx.Input.RequestBody, &req) if err != nil { br.Msg = "参数解析异常!" br.ErrMsg = "参数解析失败,Err:" + err.Error() return } raiLabelId := req.RaiLabelId err = cygx.DeleteWxUserRaiLabel(raiLabelId) if err != nil { br.Msg = "删除失败" br.ErrMsg = "删除失败,Err:" + err.Error() return } br.Ret = 200 br.Success = true br.IsAddLog = true br.Msg = "操作成功" } // @Title 标签详情 // @Description 获取标签详情接口 // @Param RaiLabelId query int true "标签ID" // @Success Ret=200 {object} cygx.ActivityDetail // @router /use_rai_label/detail [get] func (this *UserRaiLabelController) Detail() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() AdminUser := this.SysUser if AdminUser == nil { br.Msg = "请登录" br.ErrMsg = "请登录,用户信息为空" br.Ret = 408 return } raiLabelId, _ := this.GetInt("RaiLabelId") detail, err := cygx.GetWxUserRaiLabelDetailById(raiLabelId) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取失败,标签不存在Err:" + err.Error() + "RaiLabelId:" + strconv.Itoa(raiLabelId) return } resp := new(cygx.WxUserRaiLabelDetailResp) sourceType := detail.SourceType sourceId := detail.SourceId //来源1:搜索关键字标签、2:产业/个股标签(线下活动)、3:产业/个股标签(线下路演)、4:产业/个股标签(线上活动)、5:产业/个股标签(线上路演)、6:销售输入标签、7:产业/个股标签(报告)、8:报告类型标签 switch sourceType { case 1: item := new(cygx.WxUserRaiLabelKeyWordResp) item.Label = detail.Label item.CreateTime = detail.CreateTime.Format(utils.FormatDateTime) resp.KeyWord = item case 2, 4: item := new(cygx.WxUserRaiLabelActivityResp) activityInfo, errInfo := cygx.GetAddActivityInfoById(sourceId) if activityInfo == nil { br.Msg = "操作失败" br.ErrMsg = "活动ID错误,不存在activityId:" + strconv.Itoa(sourceId) return } if errInfo != nil { br.Msg = "操作失败" br.ErrMsg = "操作失败,Err:" + errInfo.Error() return } activitySignupDetai, _ := cygx.GetCygxActivitySignupDetailDetailLast(sourceId, detail.Mobile) item.ActivityName = activityInfo.ActivityName item.ActivityTypeName = activityInfo.ActivityTypeName item.ActivityTime = activityInfo.ActivityTime if activitySignupDetai != nil { item.Duration = activitySignupDetai.Duration } item.Label = detail.Label resp.Activity = item case 3, 5: item := new(cygx.WxUserRaiLabelRoadShowResp) rsCalendarItem, err := roadshow.GetRsCalendarById(sourceId) if err != nil { br.Msg = "获取数据失败!" br.ErrMsg = "获取数据失败!GetRsCalendarById:" + err.Error() return } if rsCalendarItem == nil { br.Msg = "保存失败!" br.ErrMsg = "获取数据失败!GetRsCalendarById:" + err.Error() return } rsCalendarResearcherList, tmpErr := roadshow.GetRsCalendarResearcherListByRsCalendarId(sourceId) if tmpErr != nil { br.Msg = "获取数据失败!" br.ErrMsg = "获取数据失败!GetRsCalendarResearcherListByRsCalendarId:" + tmpErr.Error() return } for _, v := range rsCalendarResearcherList { item.ResearcherName = v.ResearcherName item.RoadShowTime = v.StartDate + " " + v.StartTime } item.Theme = rsCalendarItem.Theme item.Label = detail.Label resp.RoadShow = item case 6: item := new(cygx.WxUserRaiLabelSellerResp) item.Label = detail.Label item.SysUserRealName = detail.SysUserRealName item.CreateTime = detail.CreateTime.Format(utils.FormatDateTime) resp.Seller = item case 7, 8: item := new(cygx.WxUserRaiLabelArticleResp) switch detail.TableName { case "cygx_article": //文章 detailArticle, err := cygx.GetArticleIdInfoByArticleId(sourceId) if err != nil { br.Msg = "内容不存在" br.ErrMsg = "操作失败,Err:" + err.Error() return } historyDetail := new(cygx.CygxArticleHistoryRecordAll) if detail.Mobile != "" { historyDetail, err = cygx.GetCygxArticleHistoryRecordAllDetailLastByMobile(sourceId, detail.Mobile) } else { historyDetail, err = cygx.GetCygxArticleHistoryRecordAllDetailLast(sourceId, detail.UserId) } item.Title = detailArticle.Title item.PublishDate = detailArticle.PublishDate.Format(utils.FormatDateTime) item.CreateTime = detail.CreateTime.Format(utils.FormatDateTime) item.SourceText = cygxService.GetArticleSourcePlatformText(historyDetail.RegisterPlatform) item.StopTime = strconv.Itoa(historyDetail.StopTime) case "cygx_report_selection": //报告精选 detailReportSelection, err := cygx.GetCygxReportSelectionInfoById(sourceId) if err != nil { br.Msg = "内容不存在" br.ErrMsg = "操作失败,Err:" + err.Error() return } historyDetail, err := cygx.GetCygxReportHistoryRecordDetailLast(sourceId, detail.Mobile, "bgjx") if err != nil { br.Msg = "内容不存在" br.ErrMsg = "操作失败,Err:" + err.Error() return } item.Title = detailReportSelection.Title item.PublishDate = detailReportSelection.PublishDate item.CreateTime = detail.CreateTime.Format(utils.FormatDateTime) item.SourceText = cygxService.GetArticleSourcePlatformText(historyDetail.RegisterPlatform) item.StopTime = strconv.Itoa(historyDetail.StopTime) case "cygx_research_summary": //本周研究汇总 detailResearchSummary, err := cygx.GetCygxResearchSummaryInfoById(sourceId) if err != nil { br.Msg = "内容不存在" br.ErrMsg = "操作失败,Err:" + err.Error() return } historyDetail, err := cygx.GetCygxReportHistoryRecordDetailLast(sourceId, detail.Mobile, "bzyjhz") if err != nil { br.Msg = "内容不存在" br.ErrMsg = "操作失败,Err:" + err.Error() return } item.Title = detailResearchSummary.Title item.PublishDate = detailResearchSummary.PublishDate item.CreateTime = detail.CreateTime.Format(utils.FormatDateTime) item.SourceText = cygxService.GetArticleSourcePlatformText(historyDetail.RegisterPlatform) item.StopTime = strconv.Itoa(historyDetail.StopTime) } item.Label = detail.Label resp.Article = item } resp.SourceType = detail.SourceType br.Ret = 200 br.Success = true br.Msg = "获取成功" br.Data = resp } // @Title 标签详情 // @Description 获取标签详情接口 // @Param UserId query int true "用户ID" // @Success Ret=200 {object} cygx.ActivityDetail // @router /use_rai_label/list [get] func (this *UserRaiLabelController) List() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() AdminUser := this.SysUser if AdminUser == nil { br.Msg = "请登录" br.ErrMsg = "请登录,用户信息为空" br.Ret = 408 return } userId, _ := this.GetInt("UserId") resp := new(cygx.WxUserRaiLabelList) list, err := cygx.GetWxUserRaiLabelListByUserId(userId) if err != nil { br.Msg = "获取失败" br.ErrMsg = "获取失败,Err:" + err.Error() + "userId:" + strconv.Itoa(userId) return } if len(list) == 0 { list = make([]*cygx.WxUserRaiLabelListResp, 0) } resp.List = list br.Ret = 200 br.Success = true br.Msg = "获取成功" br.Data = resp }