user.go 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "github.com/rdlucklib/rdluck_tools/paging"
  6. "hongze/hongze_cygx/models"
  7. "hongze/hongze_cygx/services"
  8. "hongze/hongze_cygx/utils"
  9. "strconv"
  10. "strings"
  11. "time"
  12. )
  13. //用户
  14. type UserController struct {
  15. BaseAuthController
  16. }
  17. // @Title 登录
  18. // @Description 登录接口
  19. // @Param request body models.LoginReq true "type json string"
  20. // @Success 200 {object} models.LoginResp
  21. // @router /login [post]
  22. func (this *UserController) Login() {
  23. br := new(models.BaseResponse).Init()
  24. defer func() {
  25. this.Data["json"] = br
  26. this.ServeJSON()
  27. }()
  28. var req models.LoginReq
  29. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  30. if err != nil {
  31. br.Msg = "参数解析异常!"
  32. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  33. return
  34. }
  35. user := this.User
  36. if user == nil {
  37. br.Msg = "请登录"
  38. br.ErrMsg = "请登录"
  39. br.Ret = 408
  40. return
  41. }
  42. unionId := this.User.UnionId
  43. openId := this.User.OpenId
  44. if unionId == "" {
  45. br.Msg = "参数错误"
  46. br.ErrMsg = "参数错误,unionId 为空"
  47. return
  48. }
  49. if req.LoginType == 1 || req.LoginType == 3 {
  50. if req.Mobile == "" {
  51. br.Msg = "参数错误"
  52. br.ErrMsg = "参数错误,手机号为空 为空"
  53. return
  54. }
  55. if req.LoginType == 3 {
  56. item, err := models.GetMsgCode(req.Mobile, req.VCode)
  57. if err != nil {
  58. if err.Error() == utils.ErrNoRow() {
  59. br.Msg = "验证码错误,请重新输入"
  60. br.ErrMsg = "校验验证码失败,Err:" + err.Error()
  61. return
  62. } else {
  63. br.Msg = "验证码错误,请重新输入"
  64. br.ErrMsg = "校验验证码失败,Err:" + err.Error()
  65. return
  66. }
  67. }
  68. if item == nil {
  69. br.Msg = "验证码错误,请重新输入"
  70. return
  71. }
  72. }
  73. req.Mobile = strings.Trim(req.Mobile, " ")
  74. } else if req.LoginType == 2 {
  75. if req.Email == "" {
  76. br.ErrMsg = "邮箱不能为空,请输入邮箱"
  77. br.Msg = "邮箱不能为空,请输入邮箱"
  78. return
  79. }
  80. if !utils.ValidateEmailFormatat(req.Email) {
  81. br.ErrMsg = "邮箱格式错误,请重新输入"
  82. br.Msg = "邮箱格式错误,请重新输入"
  83. return
  84. }
  85. item, err := models.GetMsgCode(req.Email, req.VCode)
  86. if err != nil {
  87. if err.Error() == utils.ErrNoRow() {
  88. br.Msg = "验证码错误,请重新输入"
  89. br.ErrMsg = "校验验证码失败,Err:" + err.Error()
  90. return
  91. } else {
  92. br.Msg = "验证码错误,请重新输入"
  93. br.ErrMsg = "校验验证码失败,Err:" + err.Error()
  94. return
  95. }
  96. }
  97. if item == nil {
  98. br.Msg = "验证码错误,请重新输入"
  99. return
  100. }
  101. } else {
  102. br.Msg = "无效的登录方式"
  103. br.ErrMsg = "无效的登录方式,Err:" + err.Error()
  104. return
  105. }
  106. if len(req.Mobile) >= 11 && req.CountryCode == "" {
  107. req.CountryCode = "86"
  108. }
  109. user, err = services.BindWxUser(openId, req.Mobile, req.Email, req.CountryCode)
  110. userId := user.UserId
  111. var token string
  112. tokenItem, err := models.GetTokenByOpenId(openId)
  113. if err != nil && err.Error() != utils.ErrNoRow() {
  114. br.Msg = "登录失败"
  115. br.ErrMsg = "登录失败,获取token失败:" + err.Error()
  116. return
  117. }
  118. if tokenItem == nil || (err != nil && err.Error() == utils.ErrNoRow()) {
  119. timeUnix := time.Now().Unix()
  120. timeUnixStr := strconv.FormatInt(timeUnix, 10)
  121. token = utils.MD5(openId) + utils.MD5(timeUnixStr)
  122. //新增session
  123. {
  124. session := new(models.CygxSession)
  125. session.OpenId = unionId
  126. session.UnionId = unionId
  127. session.UserId = userId
  128. session.CreatedTime = time.Now()
  129. session.LastUpdatedTime = time.Now()
  130. session.ExpireTime = time.Now().AddDate(0, 1, 0)
  131. session.AccessToken = token
  132. err = models.AddSession(session)
  133. if err != nil {
  134. br.Msg = "登录失败"
  135. br.ErrMsg = "登录失败,新增用户session信息失败:" + err.Error()
  136. return
  137. }
  138. }
  139. } else {
  140. token = tokenItem.AccessToken
  141. }
  142. //新增登录日志
  143. {
  144. loginLog := new(models.WxUserLog)
  145. loginLog.UserId = userId
  146. loginLog.OpenId = unionId
  147. loginLog.Mobile = req.Mobile
  148. loginLog.Email = req.Email
  149. loginLog.CreateTime = time.Now()
  150. loginLog.Handle = "wechat_user_login"
  151. loginLog.Remark = token
  152. go models.AddWxUserLog(loginLog)
  153. }
  154. //添加邀请绑定关系
  155. {
  156. if req.ShareUserCode != "" {
  157. count, _ := models.GetUserInviteeCount(userId)
  158. if count == 0 {
  159. userItem := new(models.UserInvitee)
  160. userItem.CreateTime = time.Now()
  161. userItem.InviteedUserId = strconv.Itoa(userId)
  162. userItem.InviteeUserId = req.ShareUserCode
  163. models.AddUserInvite(userItem)
  164. }
  165. }
  166. }
  167. resp := new(models.LoginResp)
  168. resp.UserId = userId
  169. resp.Authorization = token
  170. if user.CompanyId == 1 {
  171. resp.IsPotential = true
  172. }
  173. br.Ret = 200
  174. br.Success = true
  175. br.Data = resp
  176. br.Msg = "登录成功"
  177. }
  178. // @Title 获取用户详情
  179. // @Description 获取用户详情接口
  180. // @Success 200 {object} models.UserDetail
  181. // @router /detail [get]
  182. func (this *UserController) Detail() {
  183. br := new(models.BaseResponse).Init()
  184. defer func() {
  185. this.Data["json"] = br
  186. this.ServeJSON()
  187. }()
  188. user := this.User
  189. if user == nil {
  190. br.Msg = "请登录"
  191. br.ErrMsg = "请登录,用户信息为空"
  192. br.Ret = 408
  193. return
  194. }
  195. uid := user.UserId
  196. var hasPermission int
  197. detail := new(models.UserDetail)
  198. if uid > 0 {
  199. var err error
  200. detail, err = models.GetUserDetailByUserId(uid)
  201. if err != nil && err.Error() != utils.ErrNoRow() {
  202. br.Msg = "获取信息失败"
  203. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  204. return
  205. }
  206. userRecord, _ := models.GetUserRecordByUserId(uid, utils.WxPlatform)
  207. if userRecord != nil {
  208. detail.NickName = userRecord.NickName
  209. detail.Headimgurl = userRecord.Headimgurl
  210. if detail.Headimgurl == "" {
  211. userRecord, _ = models.GetUserRecordByUserId(uid, 1)
  212. if userRecord != nil {
  213. detail.NickName = userRecord.NickName
  214. detail.Headimgurl = userRecord.Headimgurl
  215. }
  216. }
  217. }
  218. if user.CompanyId > 1 {
  219. companyItem, err := models.GetCompanyDetailById(user.CompanyId)
  220. if err != nil && err.Error() != utils.ErrNoRow() {
  221. br.Msg = "获取信息失败"
  222. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  223. return
  224. }
  225. if companyItem != nil && companyItem.CompanyId > 0 {
  226. detail.CompanyName = companyItem.CompanyName
  227. if companyItem.Status == "试用" || companyItem.Status == "永续" || companyItem.Status == "正式" {
  228. permissionStr, err := models.GetCompanyPermissionByUser(companyItem.CompanyId)
  229. if err != nil {
  230. br.Msg = "获取信息失败"
  231. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  232. return
  233. }
  234. permissionStrOld, err := models.GetCompanyPermission(companyItem.CompanyId)
  235. if err != nil {
  236. br.Msg = "获取信息失败"
  237. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  238. return
  239. }
  240. permissionStrListOld := strings.Split(permissionStrOld, ",")
  241. for _, v := range permissionStrListOld {
  242. if strings.Count(permissionStr, v) > 1 {
  243. permissionStr = strings.Replace(permissionStr, v+"(主观)", v, -1)
  244. permissionStr = strings.Replace(permissionStr, v+"(客观),", "", -1)
  245. }
  246. }
  247. detail.PermissionName = permissionStr
  248. } else {
  249. hasPermission = 1
  250. }
  251. detail.SellerName = companyItem.SellerName
  252. detail.SellerMobile = companyItem.Mobile
  253. } else {
  254. hasPermission = 1
  255. }
  256. } else {
  257. //判断是否已经申请过
  258. applyCount, err := models.GetApplyRecordCount(uid)
  259. if err != nil && err.Error() != utils.ErrNoRow() {
  260. br.Msg = "获取信息失败"
  261. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  262. return
  263. }
  264. if applyCount > 0 {
  265. hasPermission = 3
  266. } else {
  267. hasPermission = 2
  268. }
  269. detail.CompanyName = detail.Note
  270. }
  271. detail.HasPermission = hasPermission
  272. } else {
  273. ur, _ := models.GetUserRecordByOpenId(user.OpenId)
  274. if ur != nil {
  275. detail.NickName = ur.NickName
  276. detail.Email = ur.BindAccount
  277. detail.Mobile = ur.BindAccount
  278. detail.NickName = ur.NickName
  279. detail.Headimgurl = ur.Headimgurl
  280. }
  281. hasPermission = 2
  282. detail.HasPermission = hasPermission
  283. }
  284. if detail.Headimgurl == "" {
  285. detail.Headimgurl = "https://hongze.oss-cn-shanghai.aliyuncs.com/static/images/202204/20220425/uYF0So2tSwAudlscqQhEzREGTwak.png"
  286. }
  287. br.Ret = 200
  288. br.Success = true
  289. br.Msg = "获取成功"
  290. br.Data = detail
  291. }
  292. // @Title 校验用户状态信息
  293. // @Description 校验用户状态信息
  294. // @Success 200 {object} models.CheckStatusResp
  295. // @router /check/status [get]
  296. func (this *UserController) CheckLogin() {
  297. br := new(models.BaseResponse).Init()
  298. defer func() {
  299. this.Data["json"] = br
  300. this.ServeJSON()
  301. }()
  302. user := this.User
  303. if user == nil {
  304. br.Msg = "请登录"
  305. br.ErrMsg = "请登录"
  306. br.Ret = 408
  307. return
  308. }
  309. uid := user.UserId
  310. resp := new(models.CheckStatusResp)
  311. if uid > 0 {
  312. //判断token是否过期
  313. userRecord, err := models.GetUserRecordByUserId(uid, utils.WxPlatform)
  314. if err != nil {
  315. br.Msg = "获取用户信息失败"
  316. br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
  317. return
  318. }
  319. permissionStr, err := models.GetCompanyPermission(user.CompanyId)
  320. if err != nil {
  321. br.Msg = "获取信息失败"
  322. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  323. return
  324. }
  325. resp.PermissionName = permissionStr
  326. if user.Mobile == "" && user.Email == "" {
  327. resp.IsBind = true
  328. }
  329. if userRecord.UnionId == "" {
  330. resp.IsAuth = true
  331. }
  332. } else {
  333. resp.IsBind = true
  334. if user.UnionId == "" {
  335. resp.IsAuth = true
  336. }
  337. resp.PermissionName = ""
  338. }
  339. br.Success = true
  340. br.Msg = "获取成功"
  341. br.Data = resp
  342. br.Ret = 200
  343. }
  344. // @Title 获取我的收藏
  345. // @Description 获取我的收藏列表
  346. // @Param PageSize query int true "PageSize"
  347. // @Param CurrentIndex query int true "CurrentIndex"
  348. // @Success 200 {object} models.ArticleCollectListResp
  349. // @router /collect/list [get]
  350. func (this *UserController) CollectList() {
  351. br := new(models.BaseResponse).Init()
  352. defer func() {
  353. this.Data["json"] = br
  354. this.ServeJSON()
  355. }()
  356. userId := this.User.UserId
  357. var pageSize, currentIndex, startSize int
  358. pageSize, _ = this.GetInt("PageSize")
  359. currentIndex, _ = this.GetInt("CurrentIndex")
  360. if pageSize <= 0 {
  361. pageSize = utils.PageSize20
  362. }
  363. if currentIndex <= 0 {
  364. currentIndex = 1
  365. }
  366. startSize = utils.StartIndex(currentIndex, pageSize)
  367. total, err := models.GetArticleUserCollectCount(userId)
  368. if err != nil {
  369. br.Msg = "获取数据失败"
  370. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  371. return
  372. }
  373. list, err := models.GetArticleUserCollectList(startSize, pageSize, userId)
  374. if err != nil {
  375. br.Msg = "获取数据失败"
  376. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  377. return
  378. }
  379. var articleIds []string
  380. for _, v := range list {
  381. articleIds = append(articleIds, strconv.Itoa(v.ArticleId))
  382. }
  383. articleIdStr := strings.Join(articleIds, ",")
  384. articleMap := make(map[int]*models.ArticleDetail)
  385. if articleIdStr != "" {
  386. articleList, err := models.GetArticleDetailByIdStr(articleIdStr)
  387. if err != nil {
  388. br.Msg = "获取数据失败"
  389. br.ErrMsg = "获取报告详情信息失败,Err:" + err.Error()
  390. return
  391. }
  392. for _, v := range articleList {
  393. if _, ok := articleMap[v.ArticleId]; !ok {
  394. articleMap[v.ArticleId] = v
  395. }
  396. }
  397. }
  398. lenList := len(list)
  399. for i := 0; i < lenList; i++ {
  400. item := list[i]
  401. article := articleMap[item.ArticleId]
  402. list[i].Title = article.Title
  403. list[i].TitleEn = article.TitleEn
  404. list[i].UpdateFrequency = article.UpdateFrequency
  405. list[i].CreateDate = article.CreateDate
  406. list[i].PublishDate = article.PublishDate
  407. list[i].Body, _ = services.GetReportContentTextSub(article.Body)
  408. list[i].Abstract = article.Abstract
  409. list[i].CategoryName = article.CategoryName
  410. list[i].SubCategoryName = article.SubCategoryName
  411. }
  412. page := paging.GetPaging(currentIndex, pageSize, total)
  413. resp := new(models.ArticleCollectListResp)
  414. resp.List = list
  415. resp.Paging = page
  416. br.Msg = "获取成功!"
  417. br.Ret = 200
  418. br.Success = true
  419. br.Data = resp
  420. }
  421. // @Title 获取申请访谈列表
  422. // @Description 获取申请访谈列表
  423. // @Param PageSize query int true "PageSize"
  424. // @Param CurrentIndex query int true "CurrentIndex"
  425. // @Success 200 {object} models.ArticleInterviewApplyListResp
  426. // @router /interview/apply/list [get]
  427. func (this *UserController) InterviewApplyList() {
  428. br := new(models.BaseResponse).Init()
  429. defer func() {
  430. this.Data["json"] = br
  431. this.ServeJSON()
  432. }()
  433. userId := this.User.UserId
  434. var pageSize, currentIndex, startSize int
  435. pageSize, _ = this.GetInt("PageSize")
  436. currentIndex, _ = this.GetInt("CurrentIndex")
  437. if pageSize <= 0 {
  438. pageSize = utils.PageSize20
  439. }
  440. if currentIndex <= 0 {
  441. currentIndex = 1
  442. }
  443. startSize = utils.StartIndex(currentIndex, pageSize)
  444. total, err := models.GetArticleUserInterviewApplyCount(userId)
  445. if err != nil {
  446. br.Msg = "获取数据失败"
  447. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  448. return
  449. }
  450. list, err := models.GetArticleUserInterviewApplyList(startSize, pageSize, userId)
  451. if err != nil {
  452. br.Msg = "获取数据失败"
  453. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  454. return
  455. }
  456. var articleIds []string
  457. for _, v := range list {
  458. articleIds = append(articleIds, strconv.Itoa(v.ArticleId))
  459. }
  460. articleIdStr := strings.Join(articleIds, ",")
  461. articleMap := make(map[int]*models.ArticleDetail)
  462. if articleIdStr != "" {
  463. articleList, err := models.GetArticleDetailByIdStr(articleIdStr)
  464. if err != nil {
  465. br.Msg = "获取数据失败"
  466. br.ErrMsg = "获取报告详情信息失败,Err:" + err.Error()
  467. return
  468. }
  469. for _, v := range articleList {
  470. if _, ok := articleMap[v.ArticleId]; !ok {
  471. articleMap[v.ArticleId] = v
  472. }
  473. }
  474. }
  475. lenList := len(list)
  476. for i := 0; i < lenList; i++ {
  477. item := list[i]
  478. article := articleMap[item.ArticleId]
  479. bodySub, _ := services.GetReportContentTextSub(article.Body)
  480. list[i].Title = article.Title
  481. list[i].TitleEn = article.TitleEn
  482. list[i].UpdateFrequency = article.UpdateFrequency
  483. list[i].CreateDate = article.CreateDate
  484. list[i].PublishDate = article.PublishDate
  485. list[i].Body = bodySub
  486. list[i].Abstract = article.Abstract
  487. list[i].CategoryName = article.CategoryName
  488. list[i].SubCategoryName = article.SubCategoryName
  489. list[i].ExpertBackground = article.ExpertBackground
  490. list[i].ExpertNumber = article.ExpertNumber
  491. }
  492. page := paging.GetPaging(currentIndex, pageSize, total)
  493. resp := new(models.ArticleInterviewApplyListResp)
  494. resp.List = list
  495. resp.Paging = page
  496. br.Msg = "获取成功!"
  497. br.Ret = 200
  498. br.Success = true
  499. br.Data = resp
  500. }
  501. // @Title 获取浏览历史列表
  502. // @Description 获取浏览历史列表
  503. // @Param PageSize query int true "PageSize"
  504. // @Param CurrentIndex query int true "CurrentIndex"
  505. // @Success 200 {object} models.ArticleBrowseHistoryListResp
  506. // @router /browse/history/list [get]
  507. func (this *UserController) BrowseHistoryList() {
  508. br := new(models.BaseResponse).Init()
  509. defer func() {
  510. this.Data["json"] = br
  511. this.ServeJSON()
  512. }()
  513. userId := this.User.UserId
  514. var pageSize, currentIndex, startSize int
  515. pageSize, _ = this.GetInt("PageSize")
  516. currentIndex, _ = this.GetInt("CurrentIndex")
  517. if pageSize <= 0 {
  518. pageSize = utils.PageSize20
  519. }
  520. if currentIndex <= 0 {
  521. currentIndex = 1
  522. }
  523. startSize = utils.StartIndex(currentIndex, pageSize)
  524. endDate := time.Now().AddDate(0, -1, 0).Format(utils.FormatDate)
  525. total, err := models.GetArticleUserBrowseHistoryCount(userId, endDate)
  526. if err != nil {
  527. br.Msg = "获取数据失败"
  528. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  529. return
  530. }
  531. list, err := models.GetArticleUserBrowseHistoryList(startSize, pageSize, userId, endDate)
  532. if err != nil {
  533. br.Msg = "获取数据失败"
  534. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  535. return
  536. }
  537. var articleIds []string
  538. for _, v := range list {
  539. articleIds = append(articleIds, strconv.Itoa(v.ArticleId))
  540. }
  541. articleIdStr := strings.Join(articleIds, ",")
  542. articleMap := make(map[int]*models.ArticleDetail)
  543. if articleIdStr != "" {
  544. articleList, err := models.GetArticleDetailByIdStr(articleIdStr)
  545. if err != nil {
  546. br.Msg = "获取数据失败"
  547. br.ErrMsg = "获取报告详情信息失败,Err:" + err.Error()
  548. return
  549. }
  550. for _, v := range articleList {
  551. if _, ok := articleMap[v.ArticleId]; !ok {
  552. articleMap[v.ArticleId] = v
  553. }
  554. }
  555. }
  556. lenList := len(list)
  557. for i := 0; i < lenList; i++ {
  558. item := list[i]
  559. article := articleMap[item.ArticleId]
  560. if article != nil {
  561. list[i].Title = article.Title
  562. list[i].TitleEn = article.TitleEn
  563. list[i].UpdateFrequency = article.UpdateFrequency
  564. list[i].CreateDate = article.CreateDate
  565. list[i].PublishDate = article.PublishDate
  566. list[i].Body, _ = services.GetReportContentTextSub(article.Body)
  567. list[i].Abstract = article.Abstract
  568. list[i].CategoryName = article.CategoryName
  569. list[i].SubCategoryName = article.SubCategoryName
  570. }
  571. }
  572. page := paging.GetPaging(currentIndex, pageSize, total)
  573. resp := new(models.ArticleBrowseHistoryListResp)
  574. resp.List = list
  575. resp.Paging = page
  576. br.Msg = "获取成功!"
  577. br.Ret = 200
  578. br.Success = true
  579. br.Data = resp
  580. }
  581. // @Title 未付费申请试用
  582. // @Description 未付费申请试用
  583. // @Param request body models.ApplyTryReq true "type json string"
  584. // @Success 200
  585. // @router /apply/try [post]
  586. func (this *UserController) ApplyTryOut() {
  587. br := new(models.BaseResponse).Init()
  588. defer func() {
  589. this.Data["json"] = br
  590. this.ServeJSON()
  591. }()
  592. user := this.User
  593. if user == nil {
  594. br.Msg = "请登录"
  595. br.ErrMsg = "请登录,SysUser Is Empty"
  596. br.Ret = 408
  597. return
  598. }
  599. mobile := user.Mobile
  600. var req models.ApplyTryReq
  601. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  602. if err != nil {
  603. br.Msg = "参数解析异常!"
  604. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  605. return
  606. }
  607. if req.RealName == "" {
  608. req.RealName = user.RealName
  609. }
  610. if req.CompanyName == "" {
  611. req.CompanyName = user.CompanyName
  612. }
  613. uid := user.UserId
  614. var title string
  615. tryType := req.TryType
  616. detailId := req.DetailId
  617. if tryType == "Article" {
  618. detail, err := models.GetArticleDetailById(detailId)
  619. if err != nil {
  620. br.Msg = "获取信息失败"
  621. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  622. return
  623. }
  624. title = detail.Title
  625. } else if tryType == "Activity" {
  626. detail, err := models.GetAddActivityInfoById(detailId)
  627. if err != nil {
  628. br.Msg = "操作失败"
  629. br.ErrMsg = "活动ID错误,不存在activityId:" + strconv.Itoa(detailId)
  630. return
  631. }
  632. title = detail.ActivityName
  633. }
  634. fmt.Println(title)
  635. //缓存校验
  636. cacheKey := fmt.Sprint("xygx:apply_record:add:", uid)
  637. ttlTime := utils.Rc.GetRedisTTL(cacheKey)
  638. if ttlTime > 0 {
  639. br.Msg = "申请失败,申请过于频繁"
  640. br.ErrMsg = "申请失败,申请过于频繁"
  641. return
  642. }
  643. utils.Rc.SetNX(cacheKey, user.Mobile, time.Second*10)
  644. //判断是否已经申请过
  645. applyCount, err := models.GetApplyRecordCount(uid)
  646. if err != nil && err.Error() != utils.ErrNoRow() {
  647. br.Msg = "获取信息失败"
  648. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  649. return
  650. }
  651. if applyCount > 0 {
  652. br.Msg = "您已提交申请,请耐心等待。"
  653. br.IsSendEmail = false
  654. return
  655. }
  656. //判断是否存在申请
  657. var sellerMobile string
  658. if req.ApplyMethod == 2 {
  659. if req.BusinessCardUrl == "" {
  660. br.Msg = "请上传名片"
  661. return
  662. }
  663. if req.RealName == "" {
  664. br.Msg = "请输入姓名"
  665. return
  666. }
  667. if req.CompanyName == "" {
  668. br.Msg = "请输入公司名称"
  669. return
  670. }
  671. if req.BusinessCardUrl != "" && utils.RunMode == "release" {
  672. card, err := services.GetBusinessCard(req.BusinessCardUrl)
  673. if err != nil {
  674. br.Msg = "名片识别失败"
  675. br.ErrMsg = "名片识别失败,Err:" + err.Error()
  676. return
  677. }
  678. mobileStr := strings.Join(card.WordsResult.MOBILE, ",")
  679. isFlag := true
  680. if mobile != "" {
  681. if strings.Contains(mobileStr, mobile) || mobileStr == "" {
  682. isFlag = true
  683. } else {
  684. isFlag = false
  685. }
  686. }
  687. if !isFlag {
  688. //阿里云识别
  689. if utils.RunMode == "release" {
  690. aliyunResult, err := services.AliyunBusinessCard(req.BusinessCardUrl)
  691. if err != nil {
  692. br.Msg = "识别失败"
  693. br.ErrMsg = "识别失败,Err:" + err.Error()
  694. return
  695. }
  696. if !aliyunResult.Success {
  697. br.Msg = "识别失败"
  698. br.ErrMsg = "识别失败"
  699. return
  700. }
  701. mobileStr := strings.Join(aliyunResult.TelCell, ",")
  702. if mobile != "" {
  703. if strings.Contains(mobileStr, mobile) {
  704. isFlag = true
  705. } else {
  706. isFlag = false
  707. }
  708. }
  709. }
  710. }
  711. if !isFlag {
  712. br.Msg = "名片手机号与所填手机号不匹配,请重新填写"
  713. br.ErrMsg = "mobile:" + mobile
  714. return
  715. }
  716. }
  717. }
  718. //获取销售信息
  719. sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  720. if err != nil && err.Error() != utils.ErrNoRow() {
  721. br.Msg = "申请失败"
  722. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  723. return
  724. }
  725. if sellerItem != nil {
  726. sellerMobile = sellerItem.Mobile
  727. //推送模板消息
  728. mobile := user.Mobile
  729. if mobile == "" {
  730. mobile = user.Email
  731. }
  732. }
  733. applyMethod := ""
  734. cnf, _ := models.GetConfigByCode("tpl_msg")
  735. if cnf != nil {
  736. if sellerItem != nil {
  737. cnf.ConfigValue = sellerItem.Mobile
  738. companyItem, err := models.GetCompanyDetailById(user.CompanyId)
  739. if err != nil && err.Error() != utils.ErrNoRow() {
  740. br.Msg = "获取信息失败"
  741. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  742. return
  743. }
  744. if companyItem != nil && companyItem.CompanyId > 0 {
  745. applyMethod = companyItem.Status + "客户申请"
  746. if detailId > 0 {
  747. companyProduct, err := models.GetCompanyProductDetail(user.CompanyId, 2)
  748. if err != nil && err.Error() != utils.ErrNoRow() {
  749. br.Msg = "获取信息失败"
  750. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  751. return
  752. }
  753. if companyProduct != nil && companyProduct.IsSuspend == 1 {
  754. applyMethod = "试用暂停客户"
  755. } else {
  756. if companyItem.Status == "正式" || companyItem.Status == "试用" {
  757. applyMethod = companyItem.Status + "客户申请,无对应权限"
  758. } else if companyItem.Status == "冻结" || companyItem.Status == "流失" {
  759. applyMethod = companyItem.Status + "客户"
  760. }
  761. }
  762. applyMethod = applyMethod + "," + title
  763. }
  764. }
  765. } else {
  766. //获取销售信息
  767. sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 1)
  768. if err != nil && err.Error() != utils.ErrNoRow() {
  769. br.Msg = "申请失败"
  770. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  771. return
  772. }
  773. if sellerItem != nil {
  774. applyMethod = "FICC客户"
  775. } else {
  776. applyMethod = "潜在客户"
  777. }
  778. if detailId > 0 {
  779. applyMethod = applyMethod + "," + title
  780. }
  781. }
  782. openIpItem, _ := models.GetUserRecordByMobile(4, cnf.ConfigValue)
  783. if openIpItem != nil && openIpItem.OpenId != "" {
  784. if req.ApplyMethod != 2 {
  785. req.RealName = user.RealName
  786. req.CompanyName = user.CompanyName
  787. }
  788. fmt.Println("推送消息", req.RealName, req.CompanyName, mobile, openIpItem.OpenId, applyMethod)
  789. utils.FileLog.Info("推送消息 %s %s,%s,%s,%s", req.RealName, req.CompanyName, mobile, openIpItem.OpenId, applyMethod)
  790. go services.SendPermissionApplyTemplateMsg(req.RealName, req.CompanyName, mobile, openIpItem.OpenId, applyMethod)
  791. }
  792. }
  793. err = models.AddApplyRecord(&req, user.Mobile, user.CompanyName, uid, user.CompanyId)
  794. if err != nil {
  795. br.Msg = "申请失败"
  796. br.ErrMsg = "申请失败,Err:" + err.Error()
  797. return
  798. }
  799. //添加成功后,设置5分钟缓存,不允许重复添加
  800. //utils.Rc.SetNX(cacheKey, user.Mobile, time.Second*60)
  801. br.Msg = "申请成功!"
  802. br.Ret = 200
  803. br.Success = true
  804. br.Data = sellerMobile
  805. }
  806. // @Title 是否需要填写区号
  807. // @Description 获取是否需要填写区号接口
  808. // @Success 200 {object} models.CountryCode
  809. // @router /countryCcode/isNeedAdd [get]
  810. func (this *UserController) CountryCcode() {
  811. br := new(models.BaseResponse).Init()
  812. defer func() {
  813. this.Data["json"] = br
  814. this.ServeJSON()
  815. }()
  816. user := this.User
  817. uid := user.UserId
  818. if user == nil {
  819. br.Msg = "请登录"
  820. br.ErrMsg = "请登录,用户信息为空"
  821. br.Ret = 408
  822. return
  823. }
  824. if uid == 0 {
  825. br.Msg = "请登录"
  826. br.ErrMsg = "请登录,用户信息为空"
  827. br.Ret = 408
  828. return
  829. }
  830. resp := new(models.CountryCode)
  831. if user.CountryCode == "" && len(user.Mobile) >= 11 {
  832. err := models.ChangeUserOutboundMobileByMobile(uid)
  833. if err != nil {
  834. br.Msg = "操作失败"
  835. br.ErrMsg = "操作失败,Err:" + err.Error()
  836. return
  837. }
  838. }
  839. if user.CountryCode == "" && user.Mobile != "" && len(user.Mobile) < 11 {
  840. resp.IsNeedAddCountryCode = true
  841. }
  842. if user.OutboundMobile != "" {
  843. resp.IsNeedAddCountryCode = false
  844. }
  845. br.Ret = 200
  846. br.Success = true
  847. br.Msg = "获取成功"
  848. br.Data = resp
  849. }
  850. // @Title 上传用户区号
  851. // @Description 上传用户区号接口
  852. // @Param request body models.CountryCodeItem true "type json string"
  853. // @Success Ret=200 新增成功
  854. // @router /countryCcode/Add [POST]
  855. func (this *UserController) AddCountryCcode() {
  856. br := new(models.BaseResponse).Init()
  857. defer func() {
  858. this.Data["json"] = br
  859. this.ServeJSON()
  860. }()
  861. user := this.User
  862. if user == nil {
  863. br.Msg = "请登录"
  864. br.ErrMsg = "请登录,用户信息为空"
  865. br.Ret = 408
  866. return
  867. }
  868. var req models.CountryCodeItem
  869. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  870. if err != nil {
  871. br.Msg = "参数解析异常!"
  872. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  873. return
  874. }
  875. err = models.AddCountryCode(req.CountryCode, user)
  876. if err != nil {
  877. br.Msg = "获取信息失败"
  878. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  879. return
  880. }
  881. br.Ret = 200
  882. br.Success = true
  883. br.Msg = "新增成功"
  884. }
  885. // @Title 用户修改外呼手机号以及区号
  886. // @Description 用户修改外呼手机号以及区号接口
  887. // @Param request body models.OutboundMobileItem true "type json string"
  888. // @Success Ret=200 操作成功
  889. // @router /countryCcode/addOutboundMobile [POST]
  890. func (this *UserController) AddOutboundMobile() {
  891. br := new(models.BaseResponse).Init()
  892. defer func() {
  893. this.Data["json"] = br
  894. this.ServeJSON()
  895. }()
  896. user := this.User
  897. uid := user.UserId
  898. if user == nil {
  899. br.Msg = "请登录"
  900. br.ErrMsg = "请登录,用户信息为空"
  901. br.Ret = 408
  902. return
  903. }
  904. var req models.OutboundMobileItem
  905. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  906. if err != nil {
  907. br.Msg = "参数解析异常!"
  908. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  909. return
  910. }
  911. if !utils.ValidateFixedTelephoneFormatatEasy(req.OutboundMobile) {
  912. br.Msg = "号码格式有误,请重新填写!"
  913. br.ErrMsg = "号码格式有误,请重新填写" + req.OutboundMobile
  914. return
  915. }
  916. if req.OutboundMobile == "" {
  917. br.Msg = "请填写区号!"
  918. return
  919. }
  920. item := new(models.OutboundMobileItem)
  921. item.OutboundMobile = req.OutboundMobile
  922. item.OutboundCountryCode = req.OutboundCountryCode
  923. item.ActivityId = req.ActivityId
  924. if req.ActivityId == 0 {
  925. err = models.AddOutboundMobile(item, uid)
  926. } else {
  927. if user.Mobile == "" && user.OutboundMobile == "" {
  928. items := new(models.CygxActivitySignup)
  929. items.UserId = uid
  930. items.ActivityId = req.ActivityId
  931. items.CreateTime = time.Now()
  932. items.Mobile = user.Mobile
  933. items.Email = user.Email
  934. items.CompanyId = user.CompanyId
  935. items.CompanyName = user.CompanyName
  936. items.SignupType = 1
  937. items.FailType = 0
  938. items.DoFailType = 0
  939. items.OutboundMobile = req.OutboundMobile
  940. items.CountryCode = req.OutboundCountryCode
  941. _, err = models.AddActivitySignupFromEmail(items)
  942. } else {
  943. total, err := models.GetActivityCountByIdWithUid(item.ActivityId, uid)
  944. if total == 0 {
  945. br.Msg = "报名信息不存在"
  946. br.ErrMsg = "报名信息不存在,Err:" + "活动ActivityId:" + strconv.Itoa(item.ActivityId) + "用户Uid:" + strconv.Itoa(uid)
  947. return
  948. }
  949. if err != nil {
  950. br.Msg = "操作失败"
  951. br.ErrMsg = "操作失败,Err:" + err.Error()
  952. return
  953. }
  954. err = models.AddOutboundMobile(item, uid)
  955. }
  956. }
  957. if err != nil {
  958. br.Msg = "操作失败"
  959. br.ErrMsg = "操作失败,Err:" + err.Error()
  960. return
  961. }
  962. br.Ret = 200
  963. br.Success = true
  964. br.Msg = "操作成功"
  965. }
  966. // @Title 获取我的提问
  967. // @Description 获取我的提问列表
  968. // @Success 200 {object} models.CygxAskListResp
  969. // @router /ask/list [get]
  970. func (this *UserController) AskList() {
  971. br := new(models.BaseResponse).Init()
  972. defer func() {
  973. this.Data["json"] = br
  974. this.ServeJSON()
  975. }()
  976. user := this.User
  977. if user == nil {
  978. br.Msg = "请登录"
  979. br.ErrMsg = "请登录,用户信息为空"
  980. br.Ret = 408
  981. return
  982. }
  983. userId := this.User.UserId
  984. listActcivity, err := models.GetActivityAskList(userId)
  985. if err != nil && err.Error() != utils.ErrNoRow() {
  986. br.Msg = "获取失败"
  987. br.ErrMsg = "获取活动问题失败,Err:" + err.Error()
  988. return
  989. }
  990. for _, v := range listActcivity {
  991. v.AskType = "Activity"
  992. }
  993. listArticle, err := models.GetArticleAskList(userId)
  994. if err != nil && err.Error() != utils.ErrNoRow() {
  995. br.Msg = "获取失败"
  996. br.ErrMsg = "获取文章问题失败,Err:" + err.Error()
  997. return
  998. }
  999. for _, v := range listArticle {
  1000. v.AskType = "Report"
  1001. listActcivity = append(listActcivity, v)
  1002. }
  1003. resp := new(models.CygxAskListResp)
  1004. resp.List = listActcivity
  1005. br.Msg = "获取成功!"
  1006. br.Ret = 200
  1007. br.Success = true
  1008. br.Data = resp
  1009. }
  1010. // @Title 是否展示免费试用按钮
  1011. // @Description 获取是否展示免费试用按钮接口
  1012. // @Param request body models.IsShow true "type json string"
  1013. // @Success 200
  1014. // @router /isShow/freeButton [get]
  1015. func (this *UserController) IsShow() {
  1016. br := new(models.BaseResponse).Init()
  1017. defer func() {
  1018. this.Data["json"] = br
  1019. this.ServeJSON()
  1020. }()
  1021. user := this.User
  1022. if user == nil {
  1023. br.Msg = "请重新登录"
  1024. br.Ret = 408
  1025. return
  1026. }
  1027. var resp models.IsShow
  1028. detail, err := models.GetConfigByCode("free_trial_card")
  1029. if err != nil {
  1030. br.Msg = "获取数据失败"
  1031. br.ErrMsg = "城市配置信息失败,Err:" + err.Error()
  1032. return
  1033. }
  1034. companyDetail, err := models.GetCompanyDetailByIdGroup(user.CompanyId)
  1035. if err != nil && err.Error() != utils.ErrNoRow() {
  1036. br.Msg = "获取数据失败!"
  1037. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  1038. return
  1039. }
  1040. count, err := models.CountCygxUserFreeeButton(user.UserId)
  1041. if err != nil && err.Error() != utils.ErrNoRow() {
  1042. br.Msg = "获取数据失败!"
  1043. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  1044. return
  1045. }
  1046. if companyDetail != nil {
  1047. if detail.ConfigValue == "1" && (companyDetail.Status == "正式" || companyDetail.Status == "试用" || companyDetail.Status == "永续") && count == 0 {
  1048. resp.IsShow = true
  1049. }
  1050. }
  1051. br.Ret = 200
  1052. br.Success = true
  1053. br.Data = resp
  1054. }
  1055. // @Title 隐藏当天的按钮
  1056. // @Description 隐藏当天的按钮接口
  1057. // @Success 200
  1058. // @router /freeButton/update [post]
  1059. func (this *UserController) FreeButtonUpdate() {
  1060. br := new(models.BaseResponse).Init()
  1061. defer func() {
  1062. this.Data["json"] = br
  1063. this.ServeJSON()
  1064. }()
  1065. user := this.User
  1066. if user == nil {
  1067. br.Msg = "请重新登录"
  1068. br.Ret = 408
  1069. return
  1070. }
  1071. count, err := models.CountCygxUserFreeeButtonByUser(user.UserId)
  1072. if err != nil {
  1073. br.Msg = "获取数据失败!"
  1074. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  1075. return
  1076. }
  1077. if count == 0 {
  1078. item := new(models.CygxUserFreeeButton)
  1079. item.UserId = user.UserId
  1080. item.CompanyId = user.CompanyId
  1081. item.CreateTime = time.Now()
  1082. item.ModifyTime = time.Now()
  1083. item.EffectiveTime = time.Now().Format(utils.FormatDate)
  1084. _, err := models.AddCygxUserFreeeButton(item)
  1085. if err != nil {
  1086. br.Msg = "操作失败!"
  1087. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  1088. return
  1089. }
  1090. } else {
  1091. err := models.UpdateCygxUserFreeeButton(user.UserId)
  1092. if err != nil {
  1093. br.Msg = "操作失败!"
  1094. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  1095. return
  1096. }
  1097. }
  1098. br.Ret = 200
  1099. br.Success = true
  1100. br.Msg = "操作成功!"
  1101. }
  1102. // @Title 权限弹窗是否展示免费月卡
  1103. // @Description 获取权限弹窗是否展示免费月卡接口
  1104. // @Param request body models.IsShow true "type json string"
  1105. // @Success 200
  1106. // @router /isShow/alert [get]
  1107. func (this *UserController) AlertIsShow() {
  1108. br := new(models.BaseResponse).Init()
  1109. defer func() {
  1110. this.Data["json"] = br
  1111. this.ServeJSON()
  1112. }()
  1113. user := this.User
  1114. if user == nil {
  1115. br.Msg = "请重新登录"
  1116. br.Ret = 408
  1117. return
  1118. }
  1119. var resp models.IsShow
  1120. detail, err := models.GetConfigByCode("free_trial_card")
  1121. if err != nil {
  1122. br.Msg = "获取数据失败"
  1123. br.ErrMsg = "城市配置信息失败,Err:" + err.Error()
  1124. return
  1125. }
  1126. if user.CompanyId == 1 && detail.ConfigValue == "1" {
  1127. resp.IsShow = true
  1128. }
  1129. br.Ret = 200
  1130. br.Success = true
  1131. br.Data = resp
  1132. }
  1133. // @Title 分享的时候是否展示免费月卡
  1134. // @Description 获取权限弹窗是否展示免费月卡接口
  1135. // @Param request body models.IsShow true "type json string"
  1136. // @Success 200
  1137. // @router /isShow/share [get]
  1138. func (this *UserController) ShareIsShow() {
  1139. br := new(models.BaseResponse).Init()
  1140. defer func() {
  1141. this.Data["json"] = br
  1142. this.ServeJSON()
  1143. }()
  1144. user := this.User
  1145. if user == nil {
  1146. br.Msg = "请重新登录"
  1147. br.Ret = 408
  1148. return
  1149. }
  1150. var resp models.IsShow
  1151. detail, err := models.GetConfigByCode("free_trial_card")
  1152. if err != nil {
  1153. br.Msg = "获取数据失败"
  1154. br.ErrMsg = "城市配置信息失败,Err:" + err.Error()
  1155. return
  1156. }
  1157. if user.CompanyId != 16 && detail.ConfigValue == "1" {
  1158. resp.IsShow = true
  1159. }
  1160. br.Ret = 200
  1161. br.Success = true
  1162. br.Data = resp
  1163. }