12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250 |
- package controllers
- import (
- "encoding/json"
- "fmt"
- "hongze/hongze_cygx/models"
- "hongze/hongze_cygx/services"
- "hongze/hongze_cygx/utils"
- "rdluck_tools/paging"
- "strconv"
- "strings"
- "time"
- )
- //用户
- type UserController struct {
- BaseAuthController
- }
- /*
- // @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
- userId := this.User.UserId
- if unionId == "" {
- br.Msg = "参数错误"
- br.ErrMsg = "参数错误,unionId 为空"
- return
- }
- newUserId := 0
- 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
- }
- }
- //BindMobile(openId, mobile string, userId, loginType int) (err error) {
- req.Mobile = strings.Trim(req.Mobile, " ")
- req.LoginType = 1
- newUserId, err = models.PcBindMobile(unionId, req.Mobile, userId, req.LoginType)
- } 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
- }
- newUserId, err = models.PcBindMobile(unionId, req.Email, userId, req.LoginType)
- } else {
- br.Msg = "无效的登录方式"
- br.ErrMsg = "无效的登录方式,Err:" + err.Error()
- return
- }
- var token string
- tokenItem, err := models.GetTokenByUid(newUserId)
- 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(strconv.Itoa(userId)) + 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 = unionId
- loginLog.Mobile = req.Mobile
- loginLog.Email = req.Email
- loginLog.CreateTime = time.Now()
- loginLog.Handle = "wechat_user_login"
- loginLog.Remark = token
- go models.AddWxUserLog(loginLog)
- }
- resp := new(models.LoginResp)
- resp.UserId = newUserId
- resp.Authorization = token
- br.Ret = 200
- br.Success = true
- br.Data = resp
- br.Msg = "登录成功"
- }
- */
- // @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:" + err.Error()
- return
- }
- user, err = services.BindWxUser(openId, req.Mobile, req.Email, req.CountryCode)
- 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 = unionId
- loginLog.Mobile = req.Mobile
- loginLog.Email = req.Email
- loginLog.CreateTime = time.Now()
- loginLog.Handle = "wechat_user_login"
- loginLog.Remark = token
- go models.AddWxUserLog(loginLog)
- }
- resp := new(models.LoginResp)
- resp.UserId = userId
- resp.Authorization = token
- 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
- fmt.Println("uid:", uid)
- 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
- }
- userRecord, _ := models.GetUserRecordByUserId(uid, utils.WxPlatform)
- if userRecord != nil {
- detail.NickName = userRecord.NickName
- 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.GetCompanyDetailAllById(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.GetCompanyPermission(companyItem.CompanyId)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
- return
- }
- detail.PermissionName = permissionStr
- } else {
- hasPermission = 1
- }
- detail.SellerName = companyItem.SellerName
- detail.SellerMobile = companyItem.Mobile
- } 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
- }
- 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 request body models.WxGetPhoneNumberReq true "type json string"
- //// @Success 200 {object} models.WxGetPhoneNumberResp
- //// @router /bind [post]
- //func (this *WechatController) Bind() {
- // br := new(models.BaseResponse).Init()
- // defer func() {
- // this.Data["json"] = br
- // this.ServeJSON()
- // }()
- // var req models.WxGetPhoneNumberReq
- // err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- // if err != nil {
- // br.Msg = "参数解析异常!"
- // br.ErrMsg = "参数解析失败,Err:" + err.Error()
- // return
- // }
- // if req.EncryptedData == "" || req.Iv == "" {
- // br.Msg = "参数错误"
- // return
- // }
- // user := this.User
- // if user == nil {
- // br.Msg = "请登陆"
- // br.Ret = 408
- // return
- // }
- // sessionKey := user.SessionKey
- // wxMobile, err := weapp.DecryptMobile(sessionKey, req.EncryptedData, req.Iv)
- // if err != nil {
- // br.Msg = "解析用户手机号信息失败"
- // br.ErrMsg = "解析用户手机号信息失败,Err:" + err.Error()
- // return
- // }
- // err = models.ModifyUsersMobile(user.UserId, wxMobile.PurePhoneNumber)
- // if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "获取失败,Err:" + err.Error()
- // return
- // }
- // resp := new(models.WxGetPhoneNumberResp)
- // resp.Authorization = this.Token
- // resp.PhoneNumber = wxMobile.PhoneNumber
- // resp.PurePhoneNumber = wxMobile.PurePhoneNumber
- // resp.CountryCode = wxMobile.CountryCode
- // 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.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
- }
- 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]
- article := articleMap[item.ArticleId]
- 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, _ = 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 := new(models.ArticleCollectListResp)
- 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]
- 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
- }
- 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]
- article := articleMap[item.ArticleId]
- if article != nil {
- 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, _ = 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 := new(models.ArticleBrowseHistoryListResp)
- 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
- //缓存校验
- 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.GetSellerByCompanyId(user.CompanyId)
- 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
- }
- }
- applyMethod := ""
- if req.ApplyMethod == 1 {
- applyMethod = "已有客户申请"
- } else {
- applyMethod = "潜在客户申请"
- }
- cnf, _ := models.GetConfigByCode("tpl_msg")
- if cnf != nil {
- openIpItem, _ := models.GetUserRecordByMobile(1, cnf.ConfigValue)
- if openIpItem != nil && openIpItem.OpenId != "" {
- fmt.Println("推送消息", req.RealName, req.CompanyName, mobile, openIpItem.OpenId, applyMethod)
- utils.FileLog.Info("推送消息 %s %s,%s,%s,%s", req.RealName, req.CompanyName, mobile, openIpItem.OpenId, applyMethod)
- go services.SendPermissionApplyTemplateMsg(req.RealName, req.CompanyName, mobile, openIpItem.OpenId, applyMethod)
- }
- }
- err = models.AddApplyRecord(&req, user.Mobile, user.CompanyName, uid, user.CompanyId)
- if err != nil {
- br.Msg = "申请失败"
- br.ErrMsg = "申请失败,Err:" + err.Error()
- return
- }
- //添加成功后,设置5分钟缓存,不允许重复添加
- //utils.Rc.SetNX(cacheKey, user.Mobile, time.Second*60)
- br.Msg = "申请成功!"
- br.Ret = 200
- br.Success = true
- br.Data = sellerMobile
- }
- func sentMsgToSeller() {
- }
- //func init() {
- // fmt.Println("start")
- // realName:="沈涛"
- // companyName:="弘则研究"
- // mobile:="18767183922"
- // openId:="oN0jD1eTfIAf68Y2n24RrvIGXFw4"
- // applyMethod:="xxx"
- // services.SendPermissionApplyTemplateMsg(realName, companyName, mobile, openId, applyMethod)
- // return
- // fmt.Println("end")
- //}
- // @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 获取是否需要填写外呼手机号接口
- //// @Success 200 {object} models.CountryCode
- //// @router /countryCcode/isNeedAddOutbound [get]
- //func (this *UserController) OutboundMobile() {
- // 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.OutboundMobile)
- // if user.OutboundMobile == "" && user.CountryCode == "" {
- // resp.IsNeedAddOutboundMobile = true
- // }
- // br.Ret = 200
- // br.Success = true
- // br.Msg = "获取成功"
- // br.Data = resp
- //}
- // @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.ValidateFixedTelephoneFormatat(req.OutboundMobile) && !utils.ValidateMobileFormatat(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 获取是否需要填写区号接口
- // @Param Keypd query string false "搜索主题 多个用 , 隔开 (空为活动主题,非空为更多主题)"
- // @Success 200 {object} models.CountryCode
- // @router /whiteUser [get]
- func (this *UserController) WhiteUser() {
- 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
- }
- keypd := this.GetString("Keypd")
- if keypd != "888" {
- br.Msg = "密码错误"
- return
- }
- item := new(models.WxUserWhite)
- fmt.Println(item)
- var fieldStr string
- var condition string
- fieldStr = ` u.mobile,u.country_code,u.real_name,c.company_name,u.company_id,cp.seller_name,u.created_time,cp.status,`
- condition = ` AND cp.status IN ( '正式', '试用' ) AND u.mobile != '' `
- list1, err := models.GetFormalUserWhiteList(fieldStr, condition)
- if err != nil {
- br.Msg = "获取失败,Err:" + err.Error()
- return
- }
- fieldStr = ` u.outbound_mobile as mobile,u.outbound_country_code as country_code,u.real_name,c.company_name,u.company_id,u.created_time,cp.status,`
- condition = ` AND u.mobile != u.outbound_mobile AND cp.status IN ( '正式', '试用' ) AND u.outbound_mobile != '' `
- list2, err := models.GetFormalUserWhiteList(fieldStr, condition)
- if err != nil {
- br.Msg = "获取失败,Err:" + err.Error()
- return
- }
- fmt.Println(len(list1))
- for k, v := range list1 {
- item.Mobile = v.Mobile
- item.CountryCode = v.CountryCode
- item.CompanyName = v.CompanyName
- item.PermissionName = v.Permission
- item.CreatedTime = time.Now()
- item.UserCreatedTime = v.CreatedTime
- item.RealName = v.RealName
- item.SellerName = v.SellerName
- item.Status = v.Status
- _, err := models.AddWxUserWhite(item)
- if err != nil {
- br.Msg = "获取失败,Err:" + err.Error()
- return
- }
- fmt.Println(k)
- }
- item = new(models.WxUserWhite)
- fmt.Println(len(list2))
- for _, v := range list2 {
- item.OutboundMobile = v.Mobile
- item.OutboundCountryCode = v.CountryCode
- item.CreatedTime = time.Now()
- item.CompanyName = v.CompanyName
- item.PermissionName = v.Permission
- item.UserCreatedTime = v.CreatedTime
- item.RealName = v.RealName
- item.SellerName = v.SellerName
- item.Status = v.Status
- _, err := models.AddWxUserWhite(item)
- if err != nil {
- br.Msg = "获取失败,Err:" + err.Error()
- return
- }
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- }
|