12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213 |
- package controllers
- import (
- "encoding/json"
- "fmt"
- "github.com/rdlucklib/rdluck_tools/paging"
- "hongze/hongze_web_mfyx/models"
- "hongze/hongze_web_mfyx/models/order"
- "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
- }
- resp := new(models.LoginResp)
- mobile := req.Mobile
- req.Mobile = strings.Trim(req.Mobile, " ")
- if req.Mobile == "" {
- br.Msg = "参数错误"
- br.ErrMsg = "参数错误,手机号为空"
- return
- }
- authorization := req.Token
- inviteShareCode := req.InviteShareCode
- password := req.Password
- loginType := req.LoginType
- if !utils.ValidateMobileFormatat(mobile) {
- br.Msg = "格式错误,请输入正确的手机号码。"
- return
- }
- if loginType == "2" { // 单独处理密码登录
- if password == "" {
- br.Msg = "参数错误"
- br.ErrMsg = "Password 为空"
- return
- }
- userByps, err := models.GetWxUserItemByMobile(mobile)
- if err != nil {
- br.Msg = "该账号不是专栏作者,请使用验证码登录。"
- br.ErrMsg = "获取信息失败,Err:" + err.Error()
- return
- }
- specialAuthorCheck := services.GetYanxuanSpecialAuthorInfo(userByps) //用户是否没开通研选专栏以及,专栏信息是否完善
- if !specialAuthorCheck.IsAuthor {
- br.Msg = "该账号不是专栏作者,请使用验证码登录。"
- return
- }
- //专栏作者,但是还没设置登录密码,弹窗提示如下:
- isSetPassword := services.GetIsSetPassword(mobile)
- if !isSetPassword {
- resp.LoginErrCode = 1
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- return
- }
- total, err := models.GetCygxUserPasswordCountByMobileAdnPss(mobile, password)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取信息失败 GetCygxUserPasswordCountByMobileAdnPss err" + err.Error()
- }
- if total == 0 {
- br.Msg = "密码错误,请重新输入"
- return
- }
- } else {
- code := req.VCode
- if code == "" {
- br.Msg = "参数错误"
- br.ErrMsg = "Code 为空"
- 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
- }
- }
- 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, 0, 30)
- err = services.HandleCygxMfyxWebSession(itemsSession)
- if err != nil {
- br.Msg = "获取用户信息失败"
- br.ErrMsg = "添加Token失败,Err:" + err.Error()
- return
- }
- }
- {
- services.AddInviteCompany(user) //记录通过三方合作机构过来的公司
- }
- 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
- resp.IsShowWxPaySet = utils.IS_SHOW_WX_PAY
- 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 && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
- return
- }
- var isSuspend int
- if companyProduct == nil {
- isSuspend = 1
- } else {
- isSuspend = companyProduct.IsSuspend
- }
- if companyReportPermissionDetail == nil || 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 {
- hasPermission, err = services.GetUserDetailPermissionCode(user.UserId, user.CompanyId)
- }
- } 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
- }
- if user.Mobile != "" {
- userCard, err := order.GetCygxOrderUserCardDetailByMobile(user.Mobile)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取信息失败"
- br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
- return
- }
- if userCard != nil {
- if userCard.CardType == "日卡" {
- resp.UserCardType = 1 //权益卡类型
- resp.UserCardEndDate = userCard.EndDate.Format(utils.FormatDateTime)
- } else {
- resp.UserCardType = 2
- resp.UserCardEndDate = userCard.EndDate.Format(utils.FormatDate)
- }
- }
- }
- specialAuthorCheck := services.GetYanxuanSpecialAuthorInfo(user) //用户是否没开通研选专栏以及,专栏信息是否完善
- resp.IsAuthor = specialAuthorCheck.IsAuthor
- resp.SpecialColumnId = specialAuthorCheck.SpecialColumnId
- resp.IsImproveInformation = specialAuthorCheck.IsImproveInformation
- resp.HasPermission = hasPermission
- resp.IsSetPassword = services.GetIsSetPassword(user.Mobile)
- 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 // 是否属于研选
- redirectUrl := ""
- redirectUrlYx := ""
- 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.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 := ""
- categoryApplyMethod := ""
- 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
- categoryApplyMethod = "冻结客户"
- case "流失":
- CompanyIdType = 8
- categoryApplyMethod = "流失客户"
- case "永续":
- CompanyIdType = 9
- }
- }
- applyMethod = companyItem.Status + "客户申请"
- if detailId > 0 {
- if companyProduct != nil && companyProduct.IsSuspend == 1 {
- applyMethod = "试用暂停客户"
- categoryApplyMethod = "试用暂停客户"
- } else {
- if companyItem.Status == "正式" || companyItem.Status == "试用" {
- applyMethod = companyItem.Status + "客户申请,无对应权限"
- categoryApplyMethod = 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
- }
- }
- }
- } 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客户"
- categoryApplyMethod = "FICC客户"
- } else {
- CompanyIdType = 1
- applyMethod = "潜在客户"
- categoryApplyMethod = "潜在客户"
- }
- //if detailId > 0 {
- // applyMethod = applyMethod + "," + title
- //}
- }
- if categoryApplyMethod == "" {
- categoryApplyMethod = applyMethod
- }
- 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
- }
- isResearch = true
- //fmt.Println(isResearch)
- if isResearch {
- //如果是研选的报告走研选的类目模版消息
- go services.SendPermissionApplyTemplateMsgAdminByYxCategory(req, user.CompanyId, mobile, categoryApplyMethod, 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 用户修改外呼手机号以及区号接口
- // @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
- }
- // @Title 上传名片信息
- // @Description 上传名片信息接口
- // @Param request body order.CygxUserBusinessCardReq true "type json string"
- // @Success Ret=200 {object} models.SignupStatus
- // @router /upload/UserBusinessCard [post]
- func (this *UserController) UploadUserBusinessCard() {
- 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
- }
- isNeedBusinessCard := services.GetCygxUserBusinessCardCount(user.UserId, user.CompanyId) //是否需要上传名片
- if !isNeedBusinessCard {
- br.Msg = "您已上传名片,请勿重复上传"
- return
- }
- var req order.CygxUserBusinessCardReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- uid := user.UserId
- businessCardUrl := req.BusinessCardUrl
- if businessCardUrl == "" {
- br.Msg = "名片信息错误"
- return
- }
- companyName := user.CompanyName
- if companyName == "" {
- br.Msg = "请填写公司姓名"
- return
- }
- realName := req.RealName
- if realName == "" {
- br.Msg = "请填写姓名"
- return
- }
- mobile := req.Mobile
- key := "check_ocr_business_card"
- conf, e := models.GetConfigByCode(key)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取首页头部导航失败, Err: " + e.Error()
- return
- }
- if conf.ConfigValue == "" {
- br.Msg = "获取失败"
- br.ErrMsg = "首页头部导航配置值有误"
- return
- }
- checkItem := new(models.CheckOcrBusinessCard)
- //list := new(*models.BannerUrlYxResp)
- if e = json.Unmarshal([]byte(conf.ConfigValue), &checkItem); e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "首页头部导航配置值解析失败, Err: " + e.Error()
- return
- }
- if checkItem.CheckMobile || checkItem.CheckCompany {
- aliyunResult, err := services.AliyunOcrBusinessCard(req.BusinessCardUrl)
- if err != nil {
- br.Msg = "识别失败"
- br.ErrMsg = "识别失败,Err:" + err.Error()
- return
- }
- //校验手机号
- if checkItem.CheckMobile {
- mobileStr := strings.Join(aliyunResult.TelCell, ",")
- if !strings.Contains(mobileStr, mobile) {
- br.Msg = "名片手机号和绑定手机号不一致,请重新上传"
- br.ErrMsg = "手机号不一致"
- return
- }
- }
- //校验公司
- if checkItem.CheckCompany {
- companyNameStr := strings.Join(aliyunResult.Company, ",")
- if !strings.Contains(companyNameStr, companyName) {
- br.Msg = "名片手机号和绑定手机号不一致,请重新上传"
- br.ErrMsg = "公司信息不一致"
- return
- }
- }
- }
- item := new(order.CygxUserBusinessCard)
- item.BusinessCardUrl = businessCardUrl
- item.UserId = uid
- item.RealName = realName
- item.Mobile = req.Mobile
- item.CompanyName = companyName
- item.RegisterPlatform = utils.REGISTER_PLATFORM
- item.CreateTime = time.Now()
- item.ModifyTime = time.Now()
- item.InviteName = req.InviteName
- err = order.AddCygxUserBusinessCard(item)
- if err != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "操作失败,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- }
- // @Title 更改绑定邮箱
- // @Description 更改绑定邮箱接口
- // @Param request body 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 = "操作成功"
- }
- // @Title 设置密码接口
- // @Description 设置密码接口
- // @Param request body models.SetUserPasswordReq true "type json string"
- // @Success 200 {object}
- // @router /set_pass [post]
- func (this *UserController) SetPass() {
- 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.SetUserPasswordReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- mobile := req.Mobile
- mobile = strings.Trim(mobile, " ")
- if mobile == "" {
- br.Msg = "参数错误"
- br.ErrMsg = "参数错误,手机号为空"
- return
- }
- code := req.VCode
- if code == "" {
- br.Msg = "参数错误"
- br.ErrMsg = "Code 为空"
- return
- }
- password := req.Password
- if password == "" {
- br.Msg = "参数错误"
- br.ErrMsg = "Password 为空"
- return
- }
- if !utils.ValidateMobileFormatat(mobile) {
- br.Msg = "格式错误,请输入正确的手机号码。"
- 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
- }
- specialAuthorCheck := services.GetYanxuanSpecialAuthorInfo(user) //用户是否没开通研选专栏以及,专栏信息是否完善
- if !specialAuthorCheck.IsAuthor {
- br.Msg = "该账号不是专栏作者,请使用验证码登录。"
- return
- }
- isSetPassword := services.GetIsSetPassword(mobile)
- if isSetPassword {
- err = models.UpdateCygxUserPassword(mobile, password)
- } else {
- itemps := new(models.CygxUserPassword)
- itemps.UserId = user.UserId
- itemps.Mobile = mobile
- itemps.RealName = user.RealName
- itemps.Password = password
- itemps.CreateTime = time.Now()
- itemps.ModifyTime = time.Now()
- err = models.AddCygxUserPassword(itemps)
- }
- if err != nil {
- br.Msg = "设置失败"
- br.ErrMsg = "设置失败 err" + err.Error()
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- }
- // @Title 修改密码接口
- // @Description 修改密码接口
- // @Param request body models.UpdateUserPasswordReq true "type json string"
- // @Success 200 {object}
- // @router /update_pass [post]
- func (this *UserController) UpdatePass() {
- 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
- }
- mobile := user.Mobile
- var req models.UpdateUserPasswordReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- oldPassword := req.OldPassword
- newPassword := req.NewPassword
- if !utils.ValidateMobileFormatat(mobile) {
- br.Msg = "格式错误,请输入正确的手机号码。"
- return
- }
- total, err := models.GetCygxUserPasswordCountByMobileAdnPss(mobile, oldPassword)
- if err != nil {
- br.Msg = "设置失败"
- br.ErrMsg = "设置失败 err" + err.Error()
- }
- if total == 0 {
- br.Msg = "原密码错误"
- return
- }
- specialAuthorCheck := services.GetYanxuanSpecialAuthorInfo(user) //用户是否没开通研选专栏以及,专栏信息是否完善
- if !specialAuthorCheck.IsAuthor {
- br.Msg = "非专栏作者无法设置登录密码"
- return
- }
- err = models.UpdateCygxUserPassword(mobile, newPassword)
- if err != nil {
- br.Msg = "设置失败"
- br.ErrMsg = "设置失败 err" + err.Error()
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "操作成功"
- }
- // @Title 重置密码接口(忘记密码)
- // @Description 设置密码接口
- // @Param request body models.SetUserPasswordReq true "type json string"
- // @Success 200 {object} models.LoginResp
- // @router /reset_pass [post]
- func (this *UserCommonController) ReSetPass() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var req models.SetUserPasswordReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- mobile := req.Mobile
- mobile = strings.Trim(mobile, " ")
- if mobile == "" {
- br.Msg = "参数错误"
- br.ErrMsg = "参数错误,手机号为空"
- return
- }
- code := req.VCode
- if code == "" {
- br.Msg = "参数错误"
- br.ErrMsg = "Code 为空"
- return
- }
- password := req.Password
- if password == "" {
- br.Msg = "参数错误"
- br.ErrMsg = "Password 为空"
- return
- }
- if !utils.ValidateMobileFormatat(mobile) {
- br.Msg = "格式错误,请输入正确的手机号码。"
- 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
- }
- user, err := models.GetWxUserItemByMobile(mobile)
- if err != nil {
- br.Msg = "该账号不是专栏作者,请使用验证码登录。"
- br.ErrMsg = "获取信息失败,Err:" + err.Error()
- return
- }
- specialAuthorCheck := services.GetYanxuanSpecialAuthorInfo(user) //用户是否没开通研选专栏以及,专栏信息是否完善
- if !specialAuthorCheck.IsAuthor {
- br.Msg = "该账号不是专栏作者,请使用验证码登录。"
- return
- }
- isSetPassword := services.GetIsSetPassword(mobile)
- if isSetPassword {
- err = models.UpdateCygxUserPassword(mobile, password)
- } else {
- itemps := new(models.CygxUserPassword)
- itemps.UserId = user.UserId
- itemps.Mobile = mobile
- itemps.RealName = user.RealName
- itemps.Password = password
- itemps.CreateTime = time.Now()
- itemps.ModifyTime = time.Now()
- err = models.AddCygxUserPassword(itemps)
- }
- var token string
- 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, 0, 30)
- err = services.HandleCygxMfyxWebSession(itemsSession)
- if err != nil {
- br.Msg = "获取用户信息失败"
- br.ErrMsg = "添加Token失败,Err:" + err.Error()
- return
- }
- 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
- }
|