123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698 |
- package controllers
- import (
- "encoding/json"
- "fmt"
- "github.com/rdlucklib/rdluck_tools/paging"
- "hongze/hongze_web_mfyx/models"
- "hongze/hongze_web_mfyx/services"
- "hongze/hongze_web_mfyx/utils"
- "sort"
- "strconv"
- "strings"
- "time"
- )
- type UserController struct {
- BaseAuthController
- }
- type UserCommonController struct {
- BaseCommonController
- }
- // @Title 登录
- // @Description 登录接口
- // @Param request body models.LoginReq true "type json string"
- // @Success 200 {object} models.LoginResp
- // @router /login [post]
- func (this *UserCommonController) Login() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var token string
- var req models.LoginReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- mobile := req.Mobile
- req.Mobile = strings.Trim(req.Mobile, " ")
- if req.Mobile == "" {
- br.Msg = "参数错误"
- br.ErrMsg = "参数错误,手机号为空"
- return
- }
- code := req.VCode
- if code == "" {
- br.Msg = "参数错误"
- br.ErrMsg = "Code 为空"
- return
- }
- authorization := req.Token
- inviteShareCode := req.InviteShareCode
- item, err := models.GetMsgCode(req.Mobile, req.VCode)
- if err != nil {
- if err.Error() == utils.ErrNoRow() {
- br.Msg = "验证码错误,请重新输入"
- br.ErrMsg = "校验验证码失败,Err:" + err.Error()
- return
- } else {
- br.Msg = "验证码错误,请重新输入"
- br.ErrMsg = "校验验证码失败,Err:" + err.Error()
- return
- }
- }
- if item == nil {
- br.Msg = "验证码错误,请重新输入"
- return
- }
- user, err := services.BindWxUser(mobile, "86", inviteShareCode)
- //user, err := models.GetWxUserItemByMobile(mobile)
- if err != nil {
- br.Msg = "登录失败"
- br.ErrMsg = "获取用户信息失败,GetUserDetailByMobile Err:" + err.Error()
- return
- }
- if authorization != "" {
- session, err := models.GetSessionByToken(authorization)
- if err != nil {
- br.Msg = "登录失败"
- br.ErrMsg = "绑定失败,GetSessionByToken err:" + err.Error()
- return
- }
- openid := session.OpenId
- if openid == "" {
- br.Msg = "登录失败"
- br.ErrMsg = "获取用户信息失败,绑定用户openid失败,OpenId不能为空 "
- return
- }
- err = models.BindSessionMobile(mobile, authorization)
- if err != nil {
- br.Msg = "登录失败"
- br.ErrMsg = "获取用户信息失败,BindSessionMobile Err:" + err.Error()
- return
- }
- err = models.BindUserRecordByOpenid(user.UserId, openid, mobile)
- if err != nil {
- br.Msg = "登录失败"
- br.ErrMsg = "获取用户信息失败,BindUserRecordByOpenid Err:" + err.Error()
- return
- }
- token = authorization
- } else {
- timeUnix := time.Now().Unix()
- timeUnixStr := strconv.FormatInt(timeUnix, 10)
- token = utils.MD5(mobile) + utils.MD5(timeUnixStr)
- itemsSession := new(models.CygxMfyxWebSession)
- itemsSession.UserId = user.UserId
- itemsSession.Mobile = mobile
- itemsSession.AccessToken = token
- itemsSession.CreatedTime = time.Now()
- itemsSession.LastUpdatedTime = time.Now()
- itemsSession.ExpireTime = time.Now().AddDate(0, 3, 0)
- err = models.AddCygxMfyxWebSession(itemsSession)
- if err != nil {
- br.Msg = "获取用户信息失败"
- br.ErrMsg = "添加Token失败,Err:" + err.Error()
- return
- }
- }
- {
- services.AddInviteCompany(user) //记录通过三方合作机构过来的公司
- }
- resp := new(models.LoginResp)
- resp.UserId = user.UserId
- resp.Headimgurl = user.Headimgurl
- resp.Mobile = user.Mobile
- resp.Email = user.Email
- resp.CompanyName = user.CompanyName
- resp.Authorization = token
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // @Title 获取用户详情
- // @Description 获取用户详情接口
- // @Success 200 {object} models.UserDetailResp
- // @router /detail [get]
- func (this *UserController) Detail() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- user := this.User
- if user == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,用户信息为空"
- br.Ret = 408
- return
- }
- resp := new(models.UserDetailResp)
- resp.UserId = user.UserId
- resp.UserName = user.RealName
- resp.Headimgurl = user.Headimgurl
- resp.Mobile = user.Mobile
- resp.Email = user.Email
- resp.CompanyName = user.CompanyName
- userDetail, err := models.GetUserDetailByUserId(user.UserId)
- if err != nil {
- br.Msg = "获取用户信息失败"
- br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
- return
- }
- if userDetail.Mobile != "" {
- resp.InviteShareCode = services.GetInviteShareCode(userDetail.Mobile) //判断用户是否属于销售,并且获取对应加密的分享码
- }
- resp.OutboundCountryCode = userDetail.OutboundCountryCode
- resp.OutboundMobile = userDetail.OutboundMobile
- var hasPermission int
- if user.CompanyId > 1 {
- companyItem, err := models.GetCompanyDetailById(user.CompanyId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
- return
- }
- if companyItem != nil && companyItem.CompanyId > 0 {
- resp.CompanyName = companyItem.CompanyName
- // 获取用户所在公司剩余的点
- companyPointsNum, err := models.GetCompanyPoints(user.CompanyId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取用户所在公司剩余的点失败,Err:" + err.Error()
- return
- }
- resp.CompanyPointsNum = companyPointsNum
- userYanxunaDetail, err := models.GetCygxUserYanxuanPermissionDetailByUserId(user.UserId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取信息失败,GetCygxUserYanxuanPermissionDetailByUserId Err:" + err.Error()
- return
- }
- if userYanxunaDetail != nil {
- resp.PermissionStatus = userYanxunaDetail.Status
- resp.StartDate = userYanxunaDetail.StartDate
- resp.EndDate = userYanxunaDetail.EndDate
- hasPermission = 1
- //resp.PermissionName = utils.CHART_PERMISSION_NAME_MF_YANXUAN
- } else {
- //查询研选的权限状态
- var condition string
- var pars []interface{}
- condition += " AND company_id = ? AND status IN ('正式','试用') AND chart_permission_id IN (31,52) "
- pars = append(pars, user.CompanyId)
- companyReportPermissionDetail, err := models.GetCompanyReportPermissionDetailByCondition(condition, pars)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取用户所在公司剩余的点失败,Err:" + err.Error()
- return
- }
- companyReportPermissionList, err := models.GetCompanyReportPermissionList(condition, pars)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取用户所在公司剩余的点失败,Err:" + err.Error()
- return
- }
- companyProduct, err := models.GetCompanyProductDetail(user.CompanyId, 2)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
- return
- }
- if companyReportPermissionDetail == nil || companyProduct.IsSuspend == 1 {
- //hasPermission = 1
- hasPermission, err = services.GetUserDetailPermissionCode(user.UserId, user.CompanyId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取信息失败,GetUserDetailPermissionCode Err:" + err.Error()
- return
- }
- } else {
- hasPermission = 1
- //有研选订阅或研选扣点包任意一项试用权限,即为试用客户,期限显示两项合并之后的最长时间
- minDate := time.Now()
- maxDate := time.Now()
- var permissionStatus string
- for _, v := range companyReportPermissionList {
- if utils.StrDateToDate(v.StartDate).Before(minDate) {
- minDate = utils.StrDateToDate(v.StartDate)
- }
- if utils.StrDateToDate(v.EndDate).After(maxDate) {
- maxDate = utils.StrDateToDate(v.EndDate)
- }
- if permissionStatus != "正式" {
- permissionStatus = v.Status
- }
- }
- resp.PermissionStatus = companyReportPermissionDetail.Status
- resp.StartDate = companyReportPermissionDetail.StartDate
- resp.EndDate = companyReportPermissionDetail.EndDate
- }
- }
- }
- } else {
- userYanxunaDetail, err := models.GetCygxUserYanxuanPermissionDetailByUserId(user.UserId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取信息失败,GetCygxUserYanxuanPermissionDetailByUserId Err:" + err.Error()
- return
- }
- if userYanxunaDetail != nil {
- if !utils.InArrayByStr(resp.PermissionName, utils.CHART_PERMISSION_NAME_MF_YANXUAN) {
- resp.PermissionName = append(resp.PermissionName, utils.CHART_PERMISSION_NAME_MF_YANXUAN)
- }
- resp.PermissionStatus = userYanxunaDetail.Status
- resp.StartDate = userYanxunaDetail.StartDate
- resp.EndDate = userYanxunaDetail.EndDate
- hasPermission = 1
- } else {
- hasPermission, err = services.GetUserDetailPermissionCode(user.UserId, user.CompanyId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取信息失败,GetUserDetailPermissionCode Err:" + err.Error()
- return
- }
- }
- }
- if resp.Headimgurl == "" {
- resp.Headimgurl = utils.DefaultHeadimgurl
- }
- specialAuthorCheck := services.GetYanxuanSpecialAuthorInfo(user) //用户是否没开通研选专栏以及,专栏信息是否完善
- resp.IsAuthor = specialAuthorCheck.IsAuthor
- resp.SpecialColumnId = specialAuthorCheck.SpecialColumnId
- resp.IsImproveInformation = specialAuthorCheck.IsImproveInformation
- resp.HasPermission = hasPermission
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // @Title 未付费申请试用
- // @Description 未付费申请试用
- // @Param request body models.ApplyTryReq true "type json string"
- // @Success 200
- // @router /apply/try [post]
- func (this *UserController) ApplyTryOut() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- user := this.User
- if user == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- mobile := user.Mobile
- var req models.ApplyTryReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.RealName == "" {
- req.RealName = user.RealName
- }
- if req.CompanyName == "" {
- req.CompanyName = user.CompanyName
- }
- uid := user.UserId
- var title string
- var sourceId int
- var source string
- tryType := req.TryType
- detailId := req.DetailId
- sourceId = detailId
- source = tryType
- var isResearch bool // 是否属于研选
- if tryType == "Article" {
- detail, err := models.GetArticleDetailById(detailId)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取信息失败,Err:" + err.Error()
- return
- }
- title = detail.Title
- if detail.ArticleTypeId > 0 {
- isResearch = true
- }
- } else if tryType == "Activity" {
- detail, err := models.GetAddActivityInfoById(detailId)
- if err != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "活动ID错误,不存在activityId:" + strconv.Itoa(detailId)
- return
- }
- title = detail.ActivityName
- if strings.Contains(detail.ChartPermissionName, utils.CHART_PERMISSION_NAME_YANXUAN) {
- isResearch = true
- }
- } else if tryType == "MicroAudio" {
- // 微路演音频
- microAudio, e := models.GetCygxActivityVoiceById(detailId)
- if e != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "微路演音频信息有误, 不存在的VoiceId: " + strconv.Itoa(detailId)
- return
- }
- title = microAudio.VoiceName
- sourceId = microAudio.ActivityId
- source = "activityvoice"
- } else if tryType == "ActivityVideo" {
- // 活动视频
- activityVideo, e := models.GetCygxActivityVideoById(detailId)
- if e != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "微路演音频信息有误, 不存在的VoiceId: " + strconv.Itoa(detailId)
- return
- }
- title = activityVideo.Title
- sourceId = activityVideo.ActivityId
- source = "activityvideo"
- } else if tryType == "MicroVideo" {
- // 微路演视频
- microVideo, e := models.GetMicroRoadshowVideoById(detailId)
- if e != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "微路演视频信息有误, 不存在的VideoId: " + strconv.Itoa(detailId)
- return
- }
- title = microVideo.VideoName
- source = "roadshow"
- } else if tryType == "Researchsummary" {
- // 本周研究汇总
- ResearchSummaryInfo, e := models.GetCygxResearchSummaryInfoById(detailId)
- if e != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "本周研究汇总信息有误, 不存在的detailId: " + strconv.Itoa(detailId)
- return
- }
- title = ResearchSummaryInfo.Title
- source = "researchsummary"
- } else if tryType == "Minutessummary" {
- // 上周纪要汇总
- MinutesSummaryInfo, e := models.GetCygxMinutesSummaryInfoById(detailId)
- if e != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "上周纪要汇总信息有误, 不存在的detailId: " + strconv.Itoa(detailId)
- return
- }
- title = MinutesSummaryInfo.Title
- source = "minutessummary"
- } else if tryType == "ReportSelection" {
- // 报告精选
- ReportSelectionInfo, e := models.GetCygxReportSelectionInfoById(detailId)
- if e != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "报告精选信息有误, 不存在的detailId: " + strconv.Itoa(detailId)
- return
- }
- title = ReportSelectionInfo.Title
- source = "reportselection"
- } else if tryType == "ProductInterior" {
- // 产品内测
- ProductInteriorDetail, e := models.GetCygxProductInteriorDetail(detailId)
- if e != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "产品内测信息有误, 不存在的detailId: " + strconv.Itoa(detailId)
- return
- }
- title = ProductInteriorDetail.Title
- source = "productinterior"
- } else if tryType == "YanxuanSpecial" {
- // 研选专栏
- YanxuanSpecialBySpeciaDetail, e := models.GetYanxuanSpecialBySpecialId(detailId)
- if e != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "产品内测信息有误, 不存在的detailId: " + strconv.Itoa(detailId)
- return
- }
- title = YanxuanSpecialBySpeciaDetail.Title
- source = "yanxuanspecial"
- isResearch = true
- }
- //缓存校验
- cacheKey := fmt.Sprint("xygx:apply_record:add:", uid)
- ttlTime := utils.Rc.GetRedisTTL(cacheKey)
- if ttlTime > 0 {
- br.Msg = "申请失败,申请过于频繁"
- br.ErrMsg = "申请失败,申请过于频繁"
- return
- }
- utils.Rc.SetNX(cacheKey, user.Mobile, time.Second*10)
- //判断是否已经申请过
- applyCount, err := models.GetApplyRecordCount(uid)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取信息失败"
- br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
- return
- }
- if applyCount > 0 {
- br.Msg = "您已提交申请,请耐心等待。"
- br.IsSendEmail = false
- return
- }
- //判断是否存在申请
- var sellerMobile string
- if req.ApplyMethod == 2 {
- if req.BusinessCardUrl == "" {
- br.Msg = "请上传名片"
- return
- }
- if req.RealName == "" {
- br.Msg = "请输入姓名"
- return
- }
- if req.CompanyName == "" {
- br.Msg = "请输入公司名称"
- return
- }
- if req.BusinessCardUrl != "" && utils.RunMode == "release" {
- card, err := services.GetBusinessCard(req.BusinessCardUrl)
- if err != nil {
- br.Msg = "名片识别失败"
- br.ErrMsg = "名片识别失败,Err:" + err.Error()
- return
- }
- mobileStr := strings.Join(card.WordsResult.MOBILE, ",")
- isFlag := true
- if mobile != "" {
- if strings.Contains(mobileStr, mobile) || mobileStr == "" {
- isFlag = true
- } else {
- isFlag = false
- }
- }
- if !isFlag {
- //阿里云识别
- if utils.RunMode == "release" {
- aliyunResult, err := services.AliyunBusinessCard(req.BusinessCardUrl)
- if err != nil {
- br.Msg = "识别失败"
- br.ErrMsg = "识别失败,Err:" + err.Error()
- return
- }
- if !aliyunResult.Success {
- br.Msg = "识别失败"
- br.ErrMsg = "识别失败"
- return
- }
- mobileStr := strings.Join(aliyunResult.TelCell, ",")
- if mobile != "" {
- if strings.Contains(mobileStr, mobile) {
- isFlag = true
- } else {
- isFlag = false
- }
- }
- }
- }
- if !isFlag {
- br.Msg = "名片手机号与所填手机号不匹配,请重新填写"
- br.ErrMsg = "mobile:" + mobile
- return
- }
- }
- }
- //获取销售信息
- sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "申请失败"
- br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
- return
- }
- if sellerItem != nil {
- sellerMobile = sellerItem.Mobile
- //推送模板消息
- mobile := user.Mobile
- if mobile == "" {
- mobile = user.Email
- }
- }
- //用户状态,1:潜在客户 、2:现有客户 、3:FICC客户 、4:现有客户(正式,无对应权限) 、5:现有客户(试用,无对应权限) 、6:现有客户(试用暂停) 、7:现有客户(冻结) 、8:现有客户(流失)、9:永续客户(流失)?
- CompanyIdType := 1
- applyMethod := ""
- if sellerItem != nil {
- companyItem, err := models.GetCompanyDetailById(user.CompanyId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
- return
- }
- if companyItem != nil && companyItem.CompanyId > 0 {
- companyProduct, err := models.GetCompanyProductDetail(user.CompanyId, 2)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
- return
- }
- if companyProduct != nil && companyProduct.IsSuspend == 1 {
- CompanyIdType = 6
- } else {
- switch companyItem.Status {
- case "正式":
- CompanyIdType = 4
- case "试用":
- CompanyIdType = 5
- case "冻结":
- CompanyIdType = 7
- case "流失":
- CompanyIdType = 8
- case "永续":
- CompanyIdType = 9
- }
- }
- applyMethod = companyItem.Status + "客户申请"
- if detailId > 0 {
- if companyProduct != nil && companyProduct.IsSuspend == 1 {
- applyMethod = "试用暂停客户"
- } else {
- if companyItem.Status == "正式" || companyItem.Status == "试用" {
- applyMethod = companyItem.Status + "客户申请,无对应权限"
- } else if companyItem.Status == "冻结" || companyItem.Status == "流失" {
- applyMethod = companyItem.Status + "客户"
- }
- }
- applyMethod = applyMethod + "," + title
- }
- openIpItem, _ := models.GetUserRecordByMobile(4, sellerItem.Mobile)
- if openIpItem != nil && openIpItem.OpenId != "" {
- if req.ApplyMethod != 2 {
- req.RealName = user.RealName
- req.CompanyName = user.CompanyName
- }
- //go services.SendPermissionApplyTemplateMsg(req.RealName, req.CompanyName, mobile, applyMethod, openIpItem)
- }
- }
- } else {
- //获取销售信息
- sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 1)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "申请失败"
- br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
- return
- }
- if sellerItem != nil {
- CompanyIdType = 3
- applyMethod = "FICC客户"
- } else {
- CompanyIdType = 1
- applyMethod = "潜在客户"
- }
- if detailId > 0 {
- applyMethod = applyMethod + "," + title
- }
- }
- //openIpItem, _ := models.GetUserRecordByMobile(4, cnf.ConfigValue)
- //if openIpItem != nil && openIpItem.OpenId != "" {
- // if req.ApplyMethod != 2 {
- // req.RealName = user.RealName
- // req.CompanyName = user.CompanyName
- // }
- // utils.FileLog.Info("推送消息 %s %s,%s,%s,%s", req.RealName, req.CompanyName, mobile, openIpItem.OpenId, applyMethod)
- // go services.SendPermissionApplyTemplateMsg(req.RealName, req.CompanyName, mobile, applyMethod, openIpItem)
- //}
- //go services.SendPermissionApplyTemplateMsgAdmin(req, mobile, applyMethod, isResearch)
- item := new(models.CygxApplyRecord)
- item.UserId = user.UserId
- item.BusinessCardUrl = req.BusinessCardUrl
- item.RealName = req.RealName
- item.CompanyName = req.CompanyName
- item.Mobile = user.Mobile
- item.CreateTime = time.Now()
- item.ApplyMethod = req.ApplyMethod
- item.CompanyIdPay = user.CompanyId
- item.CompanyNamePay = user.CompanyName
- item.CompanyIdType = CompanyIdType
- if user.InviteCompany == utils.LUODING_CODE && user.CompanyId == 1 {
- //如果是潜在客户就标记来源
- item.InviteCompanySource = utils.REGISTER_PLATFORM
- }
- item.Title = title
- item.SourceId = sourceId
- item.Source = strings.ToLower(source)
- item.RegisterPlatform = utils.REGISTER_PLATFORM
- err = models.AddApplyRecord(item)
- if err != nil {
- br.Msg = "申请失败"
- br.ErrMsg = "申请失败,Err:" + err.Error()
- return
- }
- if sellerItem == nil {
- go services.SendPermissionApplyTemplateMsgAdmin(req, mobile, applyMethod, isResearch)
- } else {
- openIpItem, _ := models.GetUserRecordByMobile(4, sellerItem.Mobile)
- if openIpItem != nil && openIpItem.OpenId != "" {
- go services.SendPermissionApplyTemplateMsg(req.RealName, req.CompanyName, mobile, applyMethod, openIpItem)
- }
- }
- //添加成功后,设置5分钟缓存,不允许重复添加
- //utils.Rc.SetNX(cacheKey, user.Mobile, time.Second*60)
- br.Msg = "申请成功!"
- br.Ret = 200
- br.Success = true
- br.Data = sellerMobile
- }
- // @Title 用户修改外呼手机号以及区号
- // @Description 用户修改外呼手机号以及区号接口
- // @Param request body models.OutboundMobileItem true "type json string"
- // @Success Ret=200 操作成功
- // @router /countryCcode/addOutboundMobile [POST]
- func (this *UserController) AddOutboundMobile() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- user := this.User
- uid := user.UserId
- if user == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,用户信息为空"
- br.Ret = 408
- return
- }
- var req models.OutboundMobileItem
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.OutboundMobile == "" {
- br.Msg = "请填写区号!"
- return
- }
- item := new(models.OutboundMobileItem)
- item.OutboundMobile = req.OutboundMobile
- item.OutboundCountryCode = req.OutboundCountryCode
- //item.ActivityId = req.ActivityId
- //if req.ActivityId == 0 {
- // err = models.AddOutboundMobile(item, uid)
- //} else {
- // if user.Mobile == "" && user.OutboundMobile == "" {
- // items := new(models.CygxActivitySignup)
- // items.UserId = uid
- // items.ActivityId = req.ActivityId
- // items.CreateTime = time.Now()
- // items.Mobile = user.Mobile
- // items.Email = user.Email
- // items.CompanyId = user.CompanyId
- // items.CompanyName = user.CompanyName
- // items.SignupType = 1
- // items.FailType = 0
- // items.DoFailType = 0
- // items.OutboundMobile = req.OutboundMobile
- // items.CountryCode = req.OutboundCountryCode
- // _, err = models.AddActivitySignupFromEmail(items)
- // } else {
- // total, err := models.GetActivityCountByIdWithUid(item.ActivityId, uid)
- // if total == 0 {
- // br.Msg = "报名信息不存在"
- // br.ErrMsg = "报名信息不存在,Err:" + "活动ActivityId:" + strconv.Itoa(item.ActivityId) + "用户Uid:" + strconv.Itoa(uid)
- // return
- // }
- // if err != nil {
- // br.Msg = "操作失败"
- // br.ErrMsg = "操作失败,Err:" + err.Error()
- // return
- // }
- // err = models.AddOutboundMobile(item, uid)
- // }
- //}
- err = models.AddOutboundMobile(item, uid)
- if err != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "操作失败,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- }
- // @Title 校验用户状态信息
- // @Description 校验用户状态信息
- // @Success 200 {object} models.CheckStatusResp
- // @router /check/status [get]
- func (this *UserController) CheckLogin() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- user := this.User
- if user == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录"
- br.Ret = 408
- return
- }
- uid := user.UserId
- resp := new(models.CheckStatusResp)
- if uid > 0 {
- //判断token是否过期
- userRecord, err := models.GetUserSessionByUserId(uid)
- if err != nil {
- br.Msg = "获取用户信息失败"
- br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
- return
- }
- permissionStr, err := models.GetCompanyPermission(user.CompanyId)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
- return
- }
- resp.PermissionName = permissionStr
- if user.Mobile == "" && user.Email == "" {
- resp.IsBind = true
- }
- if userRecord.UnionId == "" {
- resp.IsAuth = true
- }
- } else {
- resp.IsBind = true
- if user.UnionId == "" {
- resp.IsAuth = true
- }
- resp.PermissionName = ""
- }
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- br.Ret = 200
- }
- // @Title 更改用户微信头像
- // @Description 更改用户微信头像
- // @Param request body models.Headimgurl true "type json string"
- // @Success 200 {object} models.ArticleDetailFileLink
- // @router /headimgurl/update [post]
- func (this *UserController) HeadimgurlUpdate() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- user := this.User
- if user == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,用户信息为空"
- br.Ret = 408
- return
- }
- var req models.Headimgurl
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- uid := user.UserId
- headimgurl := req.Headimgurl
- if headimgurl == "" {
- br.Msg = "操作失败"
- br.ErrMsg = "头像信息不能为空"
- return
- }
- err = models.UpdateUserHeadimgurl(headimgurl, uid)
- if err != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "头像信息不能为空"
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- }
- // @Title 获取我的收藏
- // @Description 获取我的收藏列表
- // @Param PageSize query int true "PageSize"
- // @Param CurrentIndex query int true "CurrentIndex"
- // @Success 200 {object} models.ArticleCollectListResp
- // @router /collect/list [get]
- func (this *UserController) CollectList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- user := this.User
- if user == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,用户信息为空"
- br.Ret = 408
- return
- }
- userId := this.User.UserId
- var pageSize, currentIndex, startSize int
- pageSize, _ = this.GetInt("PageSize")
- currentIndex, _ = this.GetInt("CurrentIndex")
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = utils.StartIndex(currentIndex, pageSize)
- total, err := models.GetArticleUserCollectCount(userId)
- if err != nil {
- br.Msg = "获取数据失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- list, err := models.GetArticleUserCollectList(startSize, pageSize, userId)
- if err != nil {
- br.Msg = "获取数据失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- resp := new(models.ArticleReportBillboardLIstPageResp)
- if len(list) == 0 {
- page := paging.GetPaging(currentIndex, pageSize, total)
- resp.List = make([]*models.ArticleReportBillboardResp, 0)
- resp.Paging = page
- br.Msg = "获取成功!"
- br.Ret = 200
- br.Success = true
- br.Data = resp
- return
- }
- list, err = services.HandleArticleCategoryImg(list, user)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "HandleArticleCategoryImg,Err:" + err.Error()
- return
- }
- page := paging.GetPaging(currentIndex, pageSize, total)
- for _, v := range list {
- item := models.ArticleReportBillboardResp{
- ArticleId: v.ArticleId,
- ArticleTypeId: v.ArticleTypeId,
- Title: v.Title,
- PublishDate: v.PublishDate,
- DepartmentId: v.DepartmentId,
- NickName: v.NickName,
- IsCollect: v.IsCollect,
- Pv: v.Pv,
- CollectNum: v.CollectNum,
- ImgUrlPc: v.ImgUrlPc,
- LabelKeywordImgLink: v.LabelKeywordImgLink,
- List: v.List,
- SpecialColumnId: v.SpecialColumnId,
- }
- if v.IsSpecial == 1 {
- item.IsSpecial = true
- item.ImgUrlPc = utils.CYGX_YANXUAN_SPECIAL_IMG_PC
- if v.CompanyTags != "" {
- item.CompanyTags = strings.Split(v.CompanyTags, ",")
- } else {
- item.CompanyTags = []string{}
- }
- if v.IndustryTags != "" {
- item.IndustryTags = strings.Split(v.IndustryTags, ",")
- } else {
- item.IndustryTags = []string{}
- }
- //item.ArticleTypeName = utils.CYGX_YANXUAN_SPECIAL
- //if v.SpecialType == 1 {
- // item.Title = "【笔记】" + item.Title
- //} else if v.SpecialType == 2 {
- // item.Title = "【观点】" + item.Title
- //}
- //if v.MyCollectNum > 0 {
- // item.IsCollect = true
- //}
- }
- resp.List = append(resp.List, &item)
- }
- //var condition string
- //var pars []interface{}
- //var articleIds []string
- //for _, v := range list {
- // articleIds = append(articleIds, strconv.Itoa(v.ArticleId))
- //}
- //articleIdStr := strings.Join(articleIds, ",")
- //
- ////获取文章关联的产业
- //pars = make([]interface{}, 0)
- //condition = ` AND mg.article_id IN ( ` + utils.GetOrmInReplace(len(articleIds)) + ` ) `
- //pars = append(pars, articleIds)
- //industrialList, err := models.GetIndustrialListByarticleId(pars, condition)
- //if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "获取失败,GetSubjectList Err:" + err.Error()
- // return
- //}
- //industrialMap := make(map[int][]*models.IndustrialManagementIdInt)
- //if len(industrialList) > 0 {
- // for _, v := range industrialList {
- // item := new(models.IndustrialManagementIdInt)
- // item.ArticleId = v.ArticleId
- // if v.ArticleId > utils.SummaryArticleId {
- // item.IsResearch = true
- // }
- // item.IndustrialManagementId = v.IndustrialManagementId
- // item.IndustryName = v.IndustryName
- // item.ChartPermissionId = v.ChartPermissionId
- // industrialMap[v.ArticleId] = append(industrialMap[v.ArticleId], item)
- // }
- //}
- //for k, v := range list {
- // if len(industrialMap[v.ArticleId]) > 0 {
- // list[k].List = industrialMap[v.ArticleId]
- // } else {
- // list[k].List = make([]*models.IndustrialManagementIdInt, 0)
- // }
- //}
- //
- //articleMap := make(map[int]*models.ArticleDetail)
- //if articleIdStr != "" {
- // articleList, err := models.GetArticleDetailByIdStr(articleIdStr)
- // if err != nil {
- // br.Msg = "获取数据失败"
- // br.ErrMsg = "获取报告详情信息失败,Err:" + err.Error()
- // return
- // }
- // for _, v := range articleList {
- // if _, ok := articleMap[v.ArticleId]; !ok {
- // articleMap[v.ArticleId] = v
- // }
- // }
- //}
- //
- ////处理文章PV收藏等数量
- //mapArticleCollectNum := make(map[int]*models.CygxArticleNum)
- //if len(articleIds) > 0 {
- // articleCollectNumList, err := models.GetArticleCollectNum(articleIds, userId)
- // if err != nil && err.Error() != utils.ErrNoRow() {
- // br.Msg = "获取失败"
- // br.ErrMsg = "获取失败,GetArticleCollectNum Err:" + err.Error()
- // return
- // }
- // for _, v := range articleCollectNumList {
- // mapArticleCollectNum[v.ArticleId] = v
- // }
- //}
- //
- ////研选的五张图片
- //detailResearch, err := models.GetConfigByCode("category_research_img_url")
- //if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "获取失败,GetConfigByCode Err:" + err.Error()
- // return
- //}
- //researchList := strings.Split(detailResearch.ConfigValue, "{|}")
- //
- //lenList := len(list)
- //for i := 0; i < lenList; i++ {
- // item := list[i]
- // knum := item.ArticleId % 5
- // list[i].ImgUrlPc = researchList[knum]
- //
- // article := articleMap[item.ArticleId]
- // if list[i].IsSpecialInt != 1 {
- // list[i].Title = article.Title
- // list[i].DepartmentId = article.DepartmentId
- // list[i].NickName = article.NickName
- // list[i].PublishDate = article.PublishDate
- // if article.ArticleTypeId == 0 {
- // list[i].Source = 1
- // } else {
- // list[i].Source = 2
- // list[i].IsResearch = true
- // }
- // if mapArticleCollectNum[article.ArticleId] != nil {
- // list[i].CollectNum = mapArticleCollectNum[article.ArticleId].CollectNum
- // list[i].Pv = mapArticleCollectNum[article.ArticleId].Pv
- // list[i].IsCollect = mapArticleCollectNum[article.ArticleId].IsCollect
- // }
- // } else {
- // //处理研选专栏
- // list[i].IsSpecial = true
- // if list[i].CompanyTagsStr != "" {
- // list[i].CompanyTags = strings.Split(list[i].CompanyTagsStr, ",")
- // } else {
- // list[i].CompanyTags = []string{}
- // }
- // if list[i].IndustryTagStr != "" {
- // list[i].IndustryTags = strings.Split(list[i].IndustryTagStr, ",")
- // } else {
- // list[i].IndustryTags = []string{}
- // }
- // list[i].IsResearch = true
- // }
- // if item.ArticleTypeId == -1 {
- // list[i].ArticleTypeName = utils.CYGX_YANXUAN_SPECIAL
- // }
- // if item.SpecialType == 1 {
- // list[i].Title = "【笔记】" + list[i].Title
- // } else if list[i].SpecialType == 2 {
- // list[i].Title = "【观点】" + list[i].Title
- // }
- // if item.MyCollectNum > 0 {
- // list[i].IsCollect = true
- // }
- //
- //}
- //page := paging.GetPaging(currentIndex, pageSize, total)
- //resp.List = list
- resp.Paging = page
- br.Msg = "获取成功!"
- br.Ret = 200
- br.Success = true
- br.Data = resp
- }
- // @Title 获取我的留言
- // @Description 获取我的留言列表
- // @Param PageSize query int true "PageSize"
- // @Param CurrentIndex query int true "CurrentIndex"
- // @Success 200 {object} models.CygxCommentListResp
- // @router /comment/list [get]
- func (this *UserController) CommnetList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- user := this.User
- if user == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,用户信息为空"
- br.Ret = 408
- return
- }
- var pageSize, currentIndex, startSize int
- pageSize, _ = this.GetInt("PageSize")
- currentIndex, _ = this.GetInt("CurrentIndex")
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = utils.StartIndex(currentIndex, pageSize)
- userId := this.User.UserId
- total, err := models.GetCommentListCount(userId)
- if err != nil {
- br.Msg = "获取数据失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- commentlist, err := models.GetCommentList(userId, startSize, pageSize)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取我的留言列表失败,Err:" + err.Error()
- return
- }
- resp := new(models.CygxCommentListResp)
- for _, comment := range commentlist {
- item := models.CygxArticleCommentResp{
- Id: comment.Id,
- UserId: comment.UserId,
- ArticleId: comment.ArticleId,
- IndustryId: comment.IndustryId,
- ActivityId: comment.ActivityId,
- VideoId: comment.VideoId,
- CreateTime: comment.CreateTime.Format(utils.FormatDateTime),
- Mobile: comment.Mobile,
- Email: comment.Email,
- CompanyId: comment.CompanyId,
- CompanyName: comment.CompanyName,
- Content: comment.Content,
- Title: comment.Title,
- }
- if comment.ArticleId > 0 {
- item.RedirectType = 1
- } else if comment.IndustryId > 0 {
- detail, err := models.GetIndustrialManagementDetail(comment.IndustryId)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取信息失败,Err:" + err.Error()
- return
- }
- item.RedirectType = 3
- item.ChartPermissionId = detail.ChartPermissionId
- } else if comment.ActivityId > 0 && comment.VideoId == 0 {
- item.RedirectType = 2
- } else if comment.IndustryId == 0 && comment.VideoId > 0 {
- item.RedirectType = 4
- }
- resp.List = append(resp.List, &item)
- }
- page := paging.GetPaging(currentIndex, pageSize, total)
- resp.Paging = page
- br.Msg = "获取成功!"
- br.Ret = 200
- br.Success = true
- br.Data = resp
- }
- // @Title 我的足迹
- // @Description 获取我的足迹列表
- // @Param PageSize query int true "PageSize"
- // @Param CurrentIndex query int true "CurrentIndex"
- // @Success 200 {object} models.ArticleBrowseHistoryListResp
- // @router /browse/history/list [get]
- func (this *UserController) BrowseHistoryList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- user := this.User
- if user == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,用户信息为空"
- br.Ret = 408
- return
- }
- userId := this.User.UserId
- var pageSize, currentIndex, startSize int
- pageSize, _ = this.GetInt("PageSize")
- currentIndex, _ = this.GetInt("CurrentIndex")
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = utils.StartIndex(currentIndex, pageSize)
- endDate := time.Now().AddDate(0, -1, 0).Format(utils.FormatDate)
- total, err := models.GetArticleUserBrowseHistoryCount(userId, endDate)
- if err != nil {
- br.Msg = "获取数据失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- list, err := models.GetArticleUserBrowseHistoryList(startSize, pageSize, userId, endDate)
- if err != nil {
- br.Msg = "获取数据失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- resp := new(models.ArticleReportBillboardLIstPageResp)
- if len(list) == 0 {
- page := paging.GetPaging(currentIndex, pageSize, total)
- resp.List = make([]*models.ArticleReportBillboardResp, 0)
- resp.Paging = page
- br.Msg = "获取成功!"
- br.Ret = 200
- br.Success = true
- br.Data = resp
- return
- }
- list, err = services.HandleArticleCategoryImg(list, user)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "HandleArticleCategoryImg,Err:" + err.Error()
- return
- }
- page := paging.GetPaging(currentIndex, pageSize, total)
- for _, v := range list {
- item := models.ArticleReportBillboardResp{
- ArticleId: v.ArticleId,
- ArticleTypeId: v.ArticleTypeId,
- Title: v.Title,
- PublishDate: v.PublishDate,
- DepartmentId: v.DepartmentId,
- NickName: v.NickName,
- IsCollect: v.IsCollect,
- Pv: v.Pv,
- CollectNum: v.CollectNum,
- ImgUrlPc: v.ImgUrlPc,
- LabelKeywordImgLink: v.LabelKeywordImgLink,
- List: v.List,
- SpecialColumnId: v.SpecialColumnId,
- }
- if v.IsSpecial == 1 {
- item.IsSpecial = true
- item.ImgUrlPc = utils.CYGX_YANXUAN_SPECIAL_IMG_PC
- if v.CompanyTags != "" {
- item.CompanyTags = strings.Split(v.CompanyTags, ",")
- } else {
- item.CompanyTags = []string{}
- }
- if v.IndustryTags != "" {
- item.IndustryTags = strings.Split(v.IndustryTags, ",")
- } else {
- item.IndustryTags = []string{}
- }
- //item.ArticleTypeName = utils.CYGX_YANXUAN_SPECIAL
- //if v.SpecialType == 1 {
- // item.Title = "【笔记】" + item.Title
- //} else if v.SpecialType == 2 {
- // item.Title = "【观点】" + item.Title
- //}
- //if v.MyCollectNum > 0 {
- // item.IsCollect = true
- //}
- }
- resp.List = append(resp.List, &item)
- }
- //var articleIds []string
- //var condition string
- //var pars []interface{}
- //for _, v := range list {
- // if v.IsSpecial == 1 {
- // //if v.CompanyTags != "" {
- // // v.CompanyTags = strings.Split(v.CompanyTags, ",")
- // //} else {
- // // v.CompanyTags = []string{}
- // //}
- // } else {
- // articleIds = append(articleIds, strconv.Itoa(v.ArticleId))
- // }
- //}
- //articleIdStr := strings.Join(articleIds, ",")
- //
- ////获取文章关联的产业
- //pars = make([]interface{}, 0)
- //condition = ` AND mg.article_id IN ( ` + utils.GetOrmInReplace(len(articleIds)) + ` ) `
- //pars = append(pars, articleIds)
- //industrialList, err := models.GetIndustrialListByarticleId(pars, condition)
- //if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "获取失败,GetSubjectList Err:" + err.Error()
- // return
- //}
- //industrialMap := make(map[int][]*models.IndustrialManagementIdInt)
- //if len(industrialList) > 0 {
- // for _, v := range industrialList {
- // item := new(models.IndustrialManagementIdInt)
- // item.ArticleId = v.ArticleId
- // item.IndustrialManagementId = v.IndustrialManagementId
- // item.IndustryName = v.IndustryName
- // item.ChartPermissionId = v.ChartPermissionId
- // industrialMap[v.ArticleId] = append(industrialMap[v.ArticleId], item)
- // }
- //}
- //for k, v := range list {
- // if len(industrialMap[v.ArticleId]) > 0 {
- // list[k].List = industrialMap[v.ArticleId]
- // } else {
- // list[k].List = make([]*models.IndustrialManagementIdInt, 0)
- // }
- //}
- //
- //articleMap := make(map[int]*models.ArticleDetail)
- //if articleIdStr != "" {
- // articleList, err := models.GetArticleDetailByIdStr(articleIdStr)
- // if err != nil {
- // br.Msg = "获取数据失败"
- // br.ErrMsg = "获取报告详情信息失败,Err:" + err.Error()
- // return
- // }
- // for _, v := range articleList {
- // if _, ok := articleMap[v.ArticleId]; !ok {
- // articleMap[v.ArticleId] = v
- // }
- // }
- //}
- //
- ////处理文章PV收藏等数量
- //mapArticleCollectNum := make(map[int]*models.CygxArticleNum)
- //if len(articleIds) > 0 {
- // articleCollectNumList, err := models.GetArticleCollectNum(articleIds, userId)
- // if err != nil && err.Error() != utils.ErrNoRow() {
- // br.Msg = "获取失败"
- // br.ErrMsg = "获取失败,GetArticleCollectNum Err:" + err.Error()
- // return
- // }
- // for _, v := range articleCollectNumList {
- // mapArticleCollectNum[v.ArticleId] = v
- // }
- //}
- //
- //lenList := len(list)
- //for i := 0; i < lenList; i++ {
- // item := list[i]
- // article := articleMap[item.ArticleId]
- // if article != nil {
- // list[i].Title = article.Title
- // list[i].PublishDate = utils.TimeRemoveHms2(article.PublishDate)
- // list[i].DepartmentId = article.DepartmentId
- // list[i].NickName = article.NickName
- // if mapArticleCollectNum[article.ArticleId] != nil {
- // list[i].CollectNum = mapArticleCollectNum[article.ArticleId].CollectNum
- // list[i].Pv = mapArticleCollectNum[article.ArticleId].Pv
- // list[i].IsCollect = mapArticleCollectNum[article.ArticleId].IsCollect
- // }
- // }
- //}
- //page := paging.GetPaging(currentIndex, pageSize, total)
- //
- //resp.List = list
- resp.Paging = page
- br.Msg = "获取成功!"
- br.Ret = 200
- br.Success = true
- br.Data = resp
- }
- // @Title 获取我的提问
- // @Description 获取我的提问列表
- // @Param PageSize query int true "PageSize"
- // @Param CurrentIndex query int true "CurrentIndex"
- // @Success 200 {object} models.CygxAskListResp
- // @router /ask/list [get]
- func (this *UserController) AskList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- user := this.User
- if user == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,用户信息为空"
- br.Ret = 408
- return
- }
- var pageSize, currentIndex, startSize int
- pageSize, _ = this.GetInt("PageSize")
- currentIndex, _ = this.GetInt("CurrentIndex")
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = utils.StartIndex(currentIndex, pageSize)
- userId := this.User.UserId
- total, err := models.GetActivityAskCount(userId)
- if err != nil {
- br.Msg = "获取数据失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- listActcivity, err := models.GetActivityAskList(userId, startSize, pageSize)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取活动问题失败,Err:" + err.Error()
- return
- }
- for _, v := range listActcivity {
- v.AskType = "Activity"
- }
- listArticle, err := models.GetArticleAskList(userId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取文章问题失败,Err:" + err.Error()
- return
- }
- for _, v := range listArticle {
- v.AskType = "Report"
- listActcivity = append(listActcivity, v)
- }
- resp := new(models.CygxAskListResp)
- page := paging.GetPaging(currentIndex, pageSize, total)
- resp.Paging = page
- resp.List = listActcivity
- br.Msg = "获取成功!"
- br.Ret = 200
- br.Success = true
- br.Data = resp
- }
- // @Title 我的收藏微路演列表
- // @Description 我的收藏微路演列表接口
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Success 200 {object} models.HomeListResp
- // @router /collect/microRoadShow [get]
- func (this *UserController) Mycollect() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- user := this.User
- if user == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,用户信息为空"
- br.Ret = 408
- return
- }
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- userId := user.UserId
- listMycollect, err := models.GetUserMicroRoadshowCollectList(userId)
- if err != nil {
- br.Msg = "获取数据失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- listAskserieVideoCollect, err := models.GetUserCygxAskserieVideoCollectList(userId)
- if err != nil {
- br.Msg = "获取数据失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- collectVoiceMap := make(map[int]time.Time, 0)
- collectVideoMap := make(map[int]time.Time, 0)
- collectActivityVideoMap := make(map[int]time.Time, 0)
- var audioIds []string
- var videoIds []string
- var activityVideoIds []string
- var askserieVideoIds []string //问答系列视频
- for _, item := range listMycollect {
- if item.ActivityVoiceId > 0 {
- audioIds = append(audioIds, strconv.Itoa(item.ActivityVoiceId))
- collectVoiceMap[item.ActivityVoiceId] = item.CreateTime
- } else if item.VideoId > 0 {
- videoIds = append(videoIds, strconv.Itoa(item.VideoId))
- collectVideoMap[item.VideoId] = item.CreateTime
- } else if item.ActivityVideoId > 0 {
- activityVideoIds = append(activityVideoIds, strconv.Itoa(item.ActivityVideoId))
- collectActivityVideoMap[item.ActivityVideoId] = item.CreateTime
- }
- }
- for _, item := range listAskserieVideoCollect {
- askserieVideoIds = append(askserieVideoIds, strconv.Itoa(item.AskserieVideoId))
- }
- if len(audioIds) == 0 && len(videoIds) == 0 && len(activityVideoIds) == 0 && len(askserieVideoIds) == 0 {
- resp := new(models.MicroRoadShowListResp)
- page := paging.GetPaging(currentIndex, pageSize, 0)
- resp.List = make([]*models.MicroRoadShowPageList, 0)
- resp.Paging = page
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- return
- }
- audioIdstr := strings.Join(audioIds, ",")
- ideoIdsStr := strings.Join(videoIds, ",")
- activityVideoIdsStr := strings.Join(activityVideoIds, ",")
- askserieVideoIdsStr := strings.Join(askserieVideoIds, ",")
- // 微路演列表
- list, total, e := services.GetMicroRoadShowMycollectV12(pageSize, currentIndex, audioIdstr, activityVideoIdsStr, ideoIdsStr, askserieVideoIdsStr, user)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取微路演列表失败, Err: " + e.Error()
- return
- }
- for _, item := range list {
- if item.Type == 1 {
- //音频
- count, err := models.GetVoiceCollectCount(user.UserId, item.Id)
- if err != nil {
- br.Msg = "获取数据失败!"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- if count > 0 {
- item.IsCollect = true
- }
- if v, ok := collectVoiceMap[item.Id]; ok {
- item.CollectTime = v
- }
- } else if item.Type == 2 {
- //活动视频
- count, err := models.GetActivityVideoCollectCount(user.UserId, item.Id)
- if err != nil {
- br.Msg = "获取数据失败!"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- if count > 0 {
- item.IsCollect = true
- }
- if v, ok := collectActivityVideoMap[item.Id]; ok {
- item.CollectTime = v
- }
- } else if item.Type == 3 {
- //微路演视频
- count, err := models.GetVideoCollectCount(user.UserId, item.Id)
- if err != nil {
- br.Msg = "获取数据失败!"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- if count > 0 {
- item.IsCollect = true
- }
- if v, ok := collectVideoMap[item.Id]; ok {
- item.CollectTime = v
- }
- }
- }
- // 用户权限
- authInfo, permissionArr, e := services.GetUserRaiPermissionInfo(user.UserId, user.CompanyId)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取用户权限失败, Err: " + e.Error()
- return
- }
- // 获取默认图配置
- audioMap, videoMap, audioShareMap, videoShareMap, e := services.GetMicroRoadShowDefaultImgConfig()
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取微路演列表失败, Err: " + e.Error()
- return
- }
- for i := range list {
- // 权限
- au := new(models.UserPermissionAuthInfo)
- au.SellerName = authInfo.SellerName
- au.SellerMobile = authInfo.SellerMobile
- au.HasPermission = authInfo.HasPermission
- au.OperationMode = authInfo.OperationMode
- if au.HasPermission == 1 {
- // 非宏观权限进一步判断是否有权限
- if list[i].ChartPermissionId != utils.HONG_GUAN_ID && !utils.InArrayByStr(permissionArr, list[i].ChartPermissionName) {
- au.HasPermission = 2
- }
- }
- // 无权限的弹框提示
- if au.HasPermission != 1 {
- if au.OperationMode == services.UserPermissionOperationModeCall {
- if list[i].Type == 1 {
- au.PopupMsg = services.UserPermissionPopupMsgCallActivity
- } else {
- au.PopupMsg = services.UserPermissionPopupMsgCallMicroVideo
- }
- } else {
- if list[i].Type == 1 {
- au.PopupMsg = services.UserPermissionPopupMsgApplyActivity
- } else {
- au.PopupMsg = services.UserPermissionPopupMsgApplyMicroVideo
- }
- }
- }
- list[i].AuthInfo = au
- list[i].PublishTime = utils.StrTimeToTime(list[i].PublishTime).Format(utils.FormatDate)
- // 默认图
- if list[i].BackgroundImg == "" {
- if list[i].Type == 1 {
- list[i].BackgroundImg = audioMap[list[i].ChartPermissionId]
- } else {
- list[i].BackgroundImg = videoMap[list[i].ChartPermissionId]
- }
- }
- // 分享图
- if list[i].ShareImg == "" {
- if list[i].Type == 1 {
- list[i].ShareImg = audioShareMap[list[i].ChartPermissionId]
- } else {
- list[i].ShareImg = videoShareMap[list[i].ChartPermissionId]
- }
- }
- }
- var sortList models.MicroList
- sortList = list
- sort.Sort(sortList)
- resp := new(models.MicroRoadShowListResp)
- page := paging.GetPaging(currentIndex, pageSize, total)
- resp.List = sortList
- resp.Paging = page
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
|