123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316 |
- 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
- }
|