1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008 |
- package controllers
- import (
- "encoding/json"
- "fmt"
- "github.com/rdlucklib/rdluck_tools/paging"
- "hongze/hongze_cygx/models"
- "hongze/hongze_cygx/services"
- "hongze/hongze_cygx/utils"
- "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 *UserController) Login() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req models.LoginReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- user := this.User
- if user == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录"
- br.Ret = 408
- return
- }
- unionId := this.User.UnionId
- openId := this.User.OpenId
- if unionId == "" {
- br.Msg = "参数错误"
- br.ErrMsg = "参数错误,unionId 为空"
- return
- }
- if req.LoginType == 1 || req.LoginType == 3 {
- if req.Mobile == "" {
- br.Msg = "参数错误"
- br.ErrMsg = "参数错误,手机号为空 为空"
- return
- }
- if req.LoginType == 3 {
- 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
- }
- }
- req.Mobile = strings.Trim(req.Mobile, " ")
- } else if req.LoginType == 2 {
- if req.Email == "" {
- br.ErrMsg = "邮箱不能为空,请输入邮箱"
- br.Msg = "邮箱不能为空,请输入邮箱"
- return
- }
- if !utils.ValidateEmailFormatat(req.Email) {
- br.ErrMsg = "邮箱格式错误,请重新输入"
- br.Msg = "邮箱格式错误,请重新输入"
- return
- }
- item, err := models.GetMsgCode(req.Email, 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
- }
- } else {
- br.Msg = "无效的登录方式"
- br.ErrMsg = "无效的登录方式,Err:"
- return
- }
- if len(req.Mobile) >= 11 && req.CountryCode == "" {
- req.CountryCode = "86"
- }
- user, err = services.BindWxUser(openId, req.Mobile, req.Email, req.CountryCode)
- if err != nil {
- br.Msg = "登录失败"
- br.ErrMsg = "绑定手机号失败:" + err.Error()
- return
- }
- userId := user.UserId
- var token string
- tokenItem, err := models.GetTokenByOpenId(openId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "登录失败"
- br.ErrMsg = "登录失败,获取token失败:" + err.Error()
- return
- }
- if tokenItem == nil || (err != nil && err.Error() == utils.ErrNoRow()) {
- timeUnix := time.Now().Unix()
- timeUnixStr := strconv.FormatInt(timeUnix, 10)
- token = utils.MD5(openId) + utils.MD5(timeUnixStr)
- //新增session
- {
- session := new(models.CygxSession)
- session.OpenId = unionId
- session.UnionId = unionId
- session.UserId = userId
- session.CreatedTime = time.Now()
- session.LastUpdatedTime = time.Now()
- session.ExpireTime = time.Now().AddDate(0, 1, 0)
- session.AccessToken = token
- err = models.AddSession(session)
- if err != nil {
- br.Msg = "登录失败"
- br.ErrMsg = "登录失败,新增用户session信息失败:" + err.Error()
- return
- }
- }
- } else {
- token = tokenItem.AccessToken
- }
- //新增登录日志
- {
- loginLog := new(models.WxUserLog)
- loginLog.UserId = userId
- loginLog.OpenId = openId
- loginLog.Mobile = req.Mobile
- loginLog.Email = req.Email
- loginLog.CreateTime = time.Now()
- loginLog.Handle = "wechat_user_login"
- loginLog.Remark = token
- go models.AddWxUserLog(loginLog)
- }
- //添加邀请绑定关系
- {
- if req.ShareUserCode != "" {
- count, _ := models.GetUserInviteeCount(userId)
- if count == 0 {
- userItem := new(models.UserInvitee)
- userItem.CreateTime = time.Now()
- userItem.InviteedUserId = strconv.Itoa(userId)
- userItem.InviteeUserId = req.ShareUserCode
- shareUserId, _ := strconv.Atoi(req.ShareUserCode)
- inviteeUser, _ := models.GetWxUserItemByUserId(shareUserId)
- if inviteeUser != nil {
- userItem.InviteeMobile = inviteeUser.Mobile
- userItem.InviteeCompany = inviteeUser.CompanyName
- userItem.InviteeCompanyId = inviteeUser.CompanyId
- userItem.InviteeEmail = inviteeUser.Email
- }
- models.AddUserInvite(userItem)
- }
- }
- }
- //先关注后登录,更新用户是否关注过查研观向小助手公众号
- {
- services.UpdateCygxSubscribe(userId, unionId)
- }
- //记录通过三方合作机构过来的公司
- {
- services.AddInviteCompany(user)
- }
- resp := new(models.LoginResp)
- resp.UserId = userId
- resp.Authorization = token
- if user.CompanyId == 1 {
- resp.IsPotential = true
- }
- br.Ret = 200
- br.Success = true
- br.Data = resp
- br.Msg = "登录成功"
- }
- // @Title 获取用户详情
- // @Description 获取用户详情接口
- // @Success 200 {object} models.UserDetail
- // @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
- }
- uid := user.UserId
- var hasPermission int
- detail := new(models.UserDetail)
- if uid > 0 {
- var err error
- detail, err = models.GetUserDetailByUserId(uid)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取信息失败,Err:" + err.Error()
- return
- }
- if detail == nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取信息失败,Err:用户不存在"
- return
- }
- totalCollect, err := models.GetArticleUserCollectCount(uid) // 文章收藏数量
- if err != nil {
- br.Msg = "获取数据失败"
- br.ErrMsg = "GetArticleUserCollectCount,Err:" + err.Error()
- return
- }
- totalHistory, err := models.GetArticleUserHistoryNum(uid) // 足迹数量
- if err != nil {
- br.Msg = "获取数据失败"
- br.ErrMsg = "GetArticleUserHistoryNum,Err:" + err.Error()
- return
- }
- totalSchedule, err := models.GetArticleUserScheduleNum(uid) // 我的日程数量
- if err != nil {
- br.Msg = "获取数据失败"
- br.ErrMsg = "GetArticleUserScheduleNum,Err:" + err.Error()
- return
- }
- detail.ConNum = totalCollect
- detail.HistoryNum = totalHistory
- detail.ScheduleNum = totalSchedule
- userRecord, _ := models.GetUserRecordByUserId(uid, utils.WxPlatform)
- if userRecord != nil {
- detail.NickName = userRecord.NickName
- if detail.Headimgurl == "" {
- detail.Headimgurl = userRecord.Headimgurl
- }
- if detail.Headimgurl == "" {
- userRecord, _ = models.GetUserRecordByUserId(uid, 1)
- if userRecord != nil {
- detail.NickName = userRecord.NickName
- detail.Headimgurl = userRecord.Headimgurl
- }
- }
- }
- 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 {
- detail.CompanyName = companyItem.CompanyName
- //if companyItem.Status == "试用" || companyItem.Status == "永续" || companyItem.Status == "正式" {
- //permissionStr, err := models.GetCompanyPermissionByUser(companyItem.CompanyId)
- //if err != nil {
- // br.Msg = "获取信息失败"
- // br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
- // return
- //}
- var permissionStr string
- permissionList, err := models.GetCompanyPermissionList(companyItem.CompanyId)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
- return
- }
- mapIsUpgrade := make(map[string]string)
- mapZhukKeGuan := make(map[string]int)
- for _, v := range permissionList {
- mapZhukKeGuan[v.PermissionName] += 1
- if v.IsUpgrade == 1 {
- mapIsUpgrade[v.PermissionName] = v.PermissionName + "(升级)"
- }
- }
- mapPermissionName := make(map[string]string)
- //处理升级,并且合并主客观
- for _, v := range permissionList {
- if _, ok := mapPermissionName[v.PermissionName]; ok {
- continue
- }
- if _, ok := mapIsUpgrade[v.PermissionName]; ok {
- permissionStr += mapIsUpgrade[v.PermissionName] + ","
- } else {
- if mapZhukKeGuan[v.PermissionName] == 1 {
- permissionStr += v.Remark + ","
- } else {
- permissionStr += v.PermissionName + ","
- }
- }
- mapPermissionName[v.PermissionName] = v.PermissionName
- }
- permissionStr = strings.TrimRight(permissionStr, ",")
- //permissionStrOld, err := models.GetCompanyPermission(companyItem.CompanyId)
- //if err != nil {
- // br.Msg = "获取信息失败"
- // br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
- // return
- //}
- //permissionStrListOld := strings.Split(permissionStrOld, ",")
- //for _, v := range permissionStrListOld {
- // if strings.Count(permissionStr, v) > 1 {
- // permissionStr = strings.Replace(permissionStr, v+"(主观)", v, -1)
- // permissionStr = strings.Replace(permissionStr, v+"(客观),", "", -1)
- // }
- //}
- detail.PermissionName = permissionStr
- //} else {
- if permissionStr == "" {
- hasPermission = 1
- }
- //}
- detail.SellerName = companyItem.SellerName
- detail.SellerMobile = companyItem.Mobile
- tatolSpecil, err := services.GetSpecialTripUserSchedule(user.UserId)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
- return
- }
- detail.ScheduleNum += tatolSpecil
- microRoadshowCollectcount, err := models.GetUserMicroRoadshowCollectcount(user.UserId)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取微路演收藏信息失败,GetUserMicroRoadshowCollectcount Err:" + err.Error()
- return
- }
- detail.ConNum += microRoadshowCollectcount
- } else {
- hasPermission = 1
- }
- } else {
- //判断是否已经申请过
- applyCount, err := models.GetApplyRecordCount(uid)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取信息失败"
- br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
- return
- }
- if applyCount > 0 {
- hasPermission = 3
- } else {
- hasPermission = 2
- }
- detail.CompanyName = detail.Note
- }
- detail.HasPermission = hasPermission
- } else {
- ur, _ := models.GetUserRecordByOpenId(user.OpenId)
- if ur != nil {
- detail.NickName = ur.NickName
- detail.Email = ur.BindAccount
- detail.Mobile = ur.BindAccount
- detail.NickName = ur.NickName
- detail.Headimgurl = ur.Headimgurl
- }
- hasPermission = 2
- detail.HasPermission = hasPermission
- }
- if detail.Headimgurl == "" {
- detail.Headimgurl = utils.DefaultHeadimgurl
- }
- 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 {
- detail.MfyxStatus = userYanxunaDetail.Status
- detail.MfyxStartDate = userYanxunaDetail.StartDate
- detail.MfyxEndDate = userYanxunaDetail.EndDate
- if !strings.Contains(detail.PermissionName, utils.CHART_PERMISSION_NAME_MF_YANXUAN) {
- detail.PermissionName += "," + utils.CHART_PERMISSION_NAME_MF_YANXUAN
- }
- } else {
- detail.MfyxHasPermission = 1
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = detail
- }
- // @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.GetUserRecordByUserId(uid, utils.WxPlatform)
- 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 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()
- }()
- 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 = list
- resp.Paging = page
- br.Msg = "获取成功!"
- br.Ret = 200
- br.Success = true
- br.Data = resp
- return
- }
- 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
- 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
- }
- }
- lyjhTypeMap, _ := services.GetLyjhTypeMap()
- lenList := len(list)
- for i := 0; i < lenList; i++ {
- item := list[i]
- article := articleMap[item.ArticleId]
- if list[i].IsSpecial != 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
- }
- if _, ok := lyjhTypeMap[item.CategoryId]; ok && list[i].ArticleId >= utils.SummaryArticleId {
- list[i].IsRoadShow = true
- }
- }
- if item.ArticleTypeId == -1 {
- list[i].ArticleTypeName = utils.CYGX_YANXUAN_SPECIAL
- } else if item.ArticleTypeId > 0 {
- list[i].ArticleTypeName = utils.CYGX_YANXUAN_ARTICLE
- }
- 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.ArticleInterviewApplyListResp
- // @router /interview/apply/list [get]
- func (this *UserController) InterviewApplyList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- 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.GetArticleUserInterviewApplyCount(userId)
- if err != nil {
- br.Msg = "获取数据失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- list, err := models.GetArticleUserInterviewApplyList(startSize, pageSize, userId)
- if err != nil {
- br.Msg = "获取数据失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- var articleIds []string
- for _, v := range list {
- articleIds = append(articleIds, strconv.Itoa(v.ArticleId))
- }
- articleIdStr := strings.Join(articleIds, ",")
- 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
- }
- }
- }
- lenList := len(list)
- for i := 0; i < lenList; i++ {
- item := list[i]
- if articleMap[item.ArticleId] == nil {
- continue
- }
- article := articleMap[item.ArticleId]
- bodySub, _ := services.GetReportContentTextSub(article.Body)
- list[i].Title = article.Title
- list[i].TitleEn = article.TitleEn
- list[i].UpdateFrequency = article.UpdateFrequency
- list[i].CreateDate = article.CreateDate
- list[i].PublishDate = article.PublishDate
- list[i].Body = bodySub
- list[i].Abstract = article.Abstract
- list[i].CategoryName = article.CategoryName
- list[i].SubCategoryName = article.SubCategoryName
- list[i].ExpertBackground = article.ExpertBackground
- list[i].ExpertNumber = article.ExpertNumber
- }
- page := paging.GetPaging(currentIndex, pageSize, total)
- resp := new(models.ArticleInterviewApplyListResp)
- 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.ArticleBrowseHistoryListResp
- // @router /browse/history/list [get]
- func (this *UserController) BrowseHistoryList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- 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 = list
- resp.Paging = page
- br.Msg = "获取成功!"
- br.Ret = 200
- br.Success = true
- br.Data = resp
- return
- }
- var articleIds []string
- var condition string
- var pars []interface{}
- 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
- 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 article.ArticleId < utils.SummaryArticleId {
- list[i].Source = 1
- } else {
- list[i].Source = 2
- }
- 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
- }
- //list[i].TitleEn = article.TitleEn
- //list[i].UpdateFrequency = article.UpdateFrequency
- //list[i].CreateDate = article.CreateDate
- //list[i].Body, _ = services.GetReportContentTextSub(article.Body)
- //list[i].Abstract = article.Abstract
- //list[i].CategoryName = article.CategoryName
- //list[i].SubCategoryName = article.SubCategoryName
- }
- }
- 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 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
- redirectUrl := ""
- redirectUrlYx := ""
- 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
- }
- redirectUrl = utils.WX_MSG_PATH_ARTICLE_DETAIL + strconv.Itoa(detailId)
- redirectUrlYx = utils.WX_MSG_PATH_YX_ARTICLE_DETAIL + strconv.Itoa(detailId)
- } 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
- }
- redirectUrl = utils.WX_MSG_PATH_ACTIVITY_DETAIL + strconv.Itoa(detailId)
- redirectUrlYx = utils.WX_MSG_PATH_YX_ACTIVITY_DETAIL + strconv.Itoa(detailId)
- } 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.VideoName
- 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
- } else if tryType == utils.CYGX_OBJ_FICC_REPORT {
- // FICC研报小程序
- detailFiccReport, err := models.GetArticleDetailByReportId(detailId)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取研报信息失败,Err:" + err.Error()
- return
- }
- title = detailFiccReport.Title
- source = utils.CYGX_OBJ_FICC_REPORT
- if utils.RunMode == "release" {
- redirectUrl = utils.WX_MSG_PATH_FICC_REPORT_DETAIL + strconv.Itoa(detailId)
- }
- } else if tryType == utils.CYGX_OBJ_FICC_REPORT_XCX {
- // FICC研报小程序弹窗
- title = "周期股语音播报"
- detailId = 1
- source = utils.CYGX_OBJ_FICC_REPORT_XCX
- }
- //缓存校验
- 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
- }
- //用户状态,1:潜在客户 、2:现有客户 、3:FICC客户 、4:现有客户(正式,无对应权限) 、5:现有客户(试用,无对应权限) 、6:现有客户(试用暂停) 、7:现有客户(冻结) 、8:现有客户(流失)?
- 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
- }
- }
- 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)
- ficcCount, err := models.GetCompanyProductCount(user.CompanyId, utils.COMPANY_PRODUCT_FICC_ID)
- if err != nil {
- br.Msg = "申请失败"
- br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
- return
- }
- if ficcCount > 0 {
- CompanyIdType = 3
- applyMethod = "FICC客户"
- } else {
- CompanyIdType = 1
- applyMethod = "潜在客户"
- }
- //if detailId > 0 {
- // applyMethod = applyMethod + "," + title
- //}
- }
- 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 = 2
- }
- 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 isResearch {
- //如果是研选的报告走研选的类目模版消息
- go services.SendPermissionApplyTemplateMsgAdminByYxCategory(req, user.CompanyId, mobile, applyMethod, redirectUrlYx)
- }
- if detailId > 0 {
- applyMethod = applyMethod + "," + title
- }
- go services.SendPermissionApplyTemplateMsg(req.RealName, req.CompanyName, mobile, applyMethod, redirectUrl, user) //权限申请模板消息推送
- //添加成功后,设置5分钟缓存,不允许重复添加
- //utils.Rc.SetNX(cacheKey, user.Mobile, time.Second*60)
- br.Msg = "申请成功!"
- br.Ret = 200
- br.Success = true
- br.Data = sellerMobile
- }
- // @Title 是否需要填写区号
- // @Description 获取是否需要填写区号接口
- // @Success 200 {object} models.CountryCode
- // @router /countryCcode/isNeedAdd [get]
- func (this *UserController) CountryCcode() {
- 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
- }
- //if uid == 0 {
- // br.Msg = "请登录"
- // br.ErrMsg = "请登录,用户信息为空"
- // br.Ret = 408
- // return
- //}
- resp := new(models.CountryCode)
- if user.CountryCode == "" && len(user.Mobile) >= 11 {
- err := models.ChangeUserOutboundMobileByMobile(uid)
- if err != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "操作失败,Err:" + err.Error()
- return
- }
- }
- if user.CountryCode == "" && user.Mobile != "" && len(user.Mobile) < 11 {
- resp.IsNeedAddCountryCode = true
- }
- if user.OutboundMobile != "" {
- resp.IsNeedAddCountryCode = false
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // @Title 上传用户区号
- // @Description 上传用户区号接口
- // @Param request body models.CountryCodeItem true "type json string"
- // @Success Ret=200 新增成功
- // @router /countryCcode/Add [POST]
- func (this *UserController) AddCountryCcode() {
- 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.CountryCodeItem
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- err = models.AddCountryCode(req.CountryCode, user)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取信息失败,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "新增成功"
- }
- // @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 !utils.ValidateFixedTelephoneFormatatEasy(req.OutboundMobile) {
- br.Msg = "号码格式有误,请重新填写!"
- br.ErrMsg = "号码格式有误,请重新填写" + req.OutboundMobile
- 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)
- }
- }
- 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.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
- }
- userId := this.User.UserId
- listActcivity, err := models.GetActivityAskList(userId)
- 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)
- resp.List = listActcivity
- br.Msg = "获取成功!"
- br.Ret = 200
- br.Success = true
- br.Data = resp
- }
- // @Title 是否展示免费试用按钮
- // @Description 获取是否展示免费试用按钮接口
- // @Param request body models.IsShow true "type json string"
- // @Success 200
- // @router /isShow/freeButton [get]
- func (this *UserController) IsShow() {
- 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 resp models.IsShow
- detail, err := models.GetConfigByCode("free_trial_card")
- if err != nil {
- br.Msg = "获取数据失败"
- br.ErrMsg = "城市配置信息失败,Err:" + err.Error()
- return
- }
- companyDetail, err := models.GetCompanyDetailByIdGroup(user.CompanyId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取数据失败!"
- br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
- return
- }
- count, err := models.CountCygxUserFreeeButton(user.UserId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取数据失败!"
- br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
- return
- }
- if companyDetail != nil && companyDetail.IsSuspend == 0 {
- if detail.ConfigValue == "1" && (companyDetail.Status == "正式" || companyDetail.Status == "试用" || companyDetail.Status == "永续") && count == 0 {
- resp.IsShow = true
- }
- }
- br.Ret = 200
- br.Success = true
- br.Data = resp
- }
- // @Title 隐藏当天的按钮
- // @Description 隐藏当天的按钮接口
- // @Success 200
- // @router /freeButton/update [post]
- func (this *UserController) FreeButtonUpdate() {
- 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
- }
- count, err := models.CountCygxUserFreeeButtonByUser(user.UserId)
- if err != nil {
- br.Msg = "获取数据失败!"
- br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
- return
- }
- if count == 0 {
- item := new(models.CygxUserFreeeButton)
- item.UserId = user.UserId
- item.CompanyId = user.CompanyId
- item.CreateTime = time.Now()
- item.ModifyTime = time.Now()
- item.EffectiveTime = time.Now().Format(utils.FormatDate)
- _, err := models.AddCygxUserFreeeButton(item)
- if err != nil {
- br.Msg = "操作失败!"
- br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
- return
- }
- } else {
- err := models.UpdateCygxUserFreeeButton(user.UserId)
- if err != nil {
- br.Msg = "操作失败!"
- br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
- return
- }
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功!"
- }
- // @Title 权限弹窗是否展示免费月卡
- // @Description 获取权限弹窗是否展示免费月卡接口
- // @Param request body models.IsShow true "type json string"
- // @Success 200
- // @router /isShow/alert [get]
- func (this *UserController) AlertIsShow() {
- 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 resp models.IsShow
- detail, err := models.GetConfigByCode("free_trial_card")
- if err != nil {
- br.Msg = "获取数据失败"
- br.ErrMsg = "城市配置信息失败,Err:" + err.Error()
- return
- }
- if user.CompanyId == 1 && detail.ConfigValue == "1" {
- resp.IsShow = true
- }
- br.Ret = 200
- br.Success = true
- br.Data = resp
- }
- // @Title 分享的时候是否展示免费月卡
- // @Description 获取权限弹窗是否展示免费月卡接口
- // @Param request body models.IsShow true "type json string"
- // @Success 200
- // @router /isShow/share [get]
- func (this *UserController) ShareIsShow() {
- 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 resp models.IsShow
- detail, err := models.GetConfigByCode("free_trial_card")
- if err != nil {
- br.Msg = "获取数据失败"
- br.ErrMsg = "城市配置信息失败,Err:" + err.Error()
- return
- }
- if user.CompanyId != 16 && detail.ConfigValue == "1" {
- resp.IsShow = true
- }
- resp.LinkWxExplain = utils.LINK_WX_EXPLAIN
- br.Ret = 200
- br.Success = true
- br.Data = resp
- }
- // @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 登录 (无需token)
- // @Description 登录接口 (无需token)
- // @Param request body models.LoginReq true "type json string"
- // @Success 200 {object} models.LoginResp
- // @router /loginPublic [post]
- func (this *UserCommonController) LoginPublic() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req models.LoginReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- mobile := strings.Trim(req.Mobile, " ")
- if req.Mobile == "" {
- br.Msg = "参数错误"
- br.ErrMsg = "参数错误,手机号为空 为空"
- return
- }
- 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
- }
- if len(req.Mobile) >= 11 && req.CountryCode == "" {
- req.CountryCode = "86"
- }
- var token string
- tokenItem, err := models.GetSessionMobileTokenByOpenId(mobile)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "登录失败"
- br.ErrMsg = "登录失败,获取token失败:" + err.Error()
- return
- }
- if tokenItem == nil || (err != nil && err.Error() == utils.ErrNoRow()) {
- timeUnix := time.Now().Unix()
- timeUnixStr := strconv.FormatInt(timeUnix, 10)
- token = utils.MD5(mobile) + utils.MD5(timeUnixStr)
- //新增session
- {
- session := new(models.CygxSessionMobile)
- session.Mobile = mobile
- session.CreatedTime = time.Now()
- session.LastUpdatedTime = time.Now()
- session.ExpireTime = time.Now().AddDate(0, 1, 0)
- session.AccessToken = token
- err = models.AddCygxSessionMobile(session)
- if err != nil {
- br.Msg = "登录失败"
- br.ErrMsg = "登录失败,新增用户session信息失败:" + err.Error()
- return
- }
- }
- } else {
- token = tokenItem.AccessToken
- }
- resp := new(models.LoginResp)
- resp.Authorization = token
- br.Ret = 200
- br.Success = true
- br.Data = resp
- br.Msg = "登录成功"
- }
- // @Title 获取我的留言
- // @Description 获取我的留言列表
- // @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
- }
- userId := this.User.UserId
- commentlist, err := models.GetCommentList(userId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取我的留言列表失败,Err:" + err.Error()
- return
- }
- articleLyjhMap, _ := services.GetLyjhArticleMap()
- articleCollectMap, _ := services.GetCygxArticleCollectMap(user.UserId)
- 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,
- CreateTime: comment.CreateTime,
- 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 {
- item.RedirectType = 3
- } else if comment.ActivityId > 0 {
- item.RedirectType = 2
- }
- item.IsCollect = articleCollectMap[comment.ArticleId]
- item.IsRoadShow = articleLyjhMap[comment.ArticleId]
- resp.List = append(resp.List, &item)
- }
- br.Msg = "获取成功!"
- br.Ret = 200
- br.Success = true
- br.Data = resp
- }
- // @Title 获取我的收藏
- // @Description 获取我的收藏列表
- // @Success 200 {object} models.ArticleCollectListResp
- // @router /collect/list/microRoadshow [get]
- func (this *UserController) MicroRoadshowCollectList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- userId := this.User.UserId
- list, err := models.GetUserMicroRoadshowCollectList(userId)
- if err != nil {
- br.Msg = "获取数据失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- resp := new(models.MicroRoadshowCollectList)
- var audioIds []string
- var videoIds []string
- var activityVideoIds []string
- for _, item := range list {
- if item.ActivityVoiceId > 0 {
- audioIds = append(audioIds, strconv.Itoa(item.ActivityVoiceId))
- } else if item.VideoId > 0 {
- videoIds = append(videoIds, strconv.Itoa(item.VideoId))
- } else if item.ActivityVideoId > 0 {
- activityVideoIds = append(activityVideoIds, strconv.Itoa(item.ActivityVideoId))
- }
- }
- resp.AudioIds = strings.Join(audioIds, ",")
- resp.VideoIds = strings.Join(videoIds, ",")
- resp.ActivityVideoIds = strings.Join(activityVideoIds, ",")
- br.Msg = "获取成功!"
- br.Ret = 200
- br.Success = true
- br.Data = resp
- }
- // @Title 新增埋点
- // @Description 新增埋点接口
- // @Success 200 "新增成功!"
- // @router /tracking [get]
- func (this *UserController) Tracking() {
- 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
- }
- //item := new(models.CygxPageHistoryRecord)
- //item.UserId = user.UserId
- //item.CreateTime = time.Now()
- //item.Mobile = user.Mobile
- //item.Email = user.Email
- //item.CompanyId = user.CompanyId
- //item.CompanyName = user.CompanyName
- //item.Router = this.Ctx.Request.RequestURI
- //item.PageRouter = this.Ctx.Input.Query("PageRouter")
- //
- //go models.AddCygxPageHistoryRecord(item)
- //
- br.Msg = "新增成功!"
- br.Ret = 200
- br.Success = true
- }
- // @Title 未付费申请试用详情
- // @Description 未付费申请试用详情接口
- // @Param ApplyRecordId query int true "申请ID"
- // @Success 200 {object} models.ArticleCollectListResp
- // @Success 200
- // @router /apply/detail [get]
- func (this *UserController) ApplyDetail() {
- 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
- }
- resp := new(models.CygxApplyRecordDetialResp)
- applyRecordId, _ := this.GetInt("ApplyRecordId")
- detail, err := models.GetCygxApplyRecordById(applyRecordId)
- if err != nil {
- br.Msg = "获取数据失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- switch detail.RegisterPlatform {
- case 1:
- detail.ApplicationSource = "查研观向小程序"
- case 2:
- detail.ApplicationSource = "查研观向网页版"
- case 5:
- detail.ApplicationSource = "买方研选小程序"
- case 6:
- detail.ApplicationSource = "买方研选网页版"
- }
- switch detail.InviteCompanySource {
- case 2:
- detail.ApplicationSource += "(络町)"
- }
- resp.Detail = detail
- br.Msg = "申请成功!"
- br.Ret = 200
- br.Success = true
- br.Data = resp
- }
- // @Title 更改绑定邮箱
- // @Description 更改绑定邮箱接口
- // @Param request body models.Headimgurl true "type json string"
- // @Success 200 {object} models.ArticleDetailFileLink
- // @router /email/binding [post]
- func (this *UserController) EmailBinding() {
- 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.UserEmail
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- uid := user.UserId
- if user.Email != "" {
- br.Msg = "邮箱号已存在,请勿重复绑定"
- br.ErrMsg = "邮箱格式错误,请重新输入 Email:" + user.Email
- return
- }
- email := req.Email
- if !utils.ValidateEmailFormatat(req.Email) {
- br.Msg = "邮箱格式错误,请重新输入"
- br.ErrMsg = "邮箱格式错误,请重新输入"
- return
- }
- err = models.UpdateUserEmail(email, uid)
- if err != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "头像信息不能为空"
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- }
|