user.go 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199
  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. br.Ret = 200
  285. br.Success = true
  286. br.Msg = "获取成功"
  287. br.Data = detail
  288. }
  289. // @Title 校验用户状态信息
  290. // @Description 校验用户状态信息
  291. // @Success 200 {object} models.CheckStatusResp
  292. // @router /check/status [get]
  293. func (this *UserController) CheckLogin() {
  294. br := new(models.BaseResponse).Init()
  295. defer func() {
  296. this.Data["json"] = br
  297. this.ServeJSON()
  298. }()
  299. user := this.User
  300. if user == nil {
  301. br.Msg = "请登录"
  302. br.ErrMsg = "请登录"
  303. br.Ret = 408
  304. return
  305. }
  306. uid := user.UserId
  307. resp := new(models.CheckStatusResp)
  308. if uid > 0 {
  309. //判断token是否过期
  310. userRecord, err := models.GetUserRecordByUserId(uid, utils.WxPlatform)
  311. if err != nil {
  312. br.Msg = "获取用户信息失败"
  313. br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
  314. return
  315. }
  316. permissionStr, err := models.GetCompanyPermission(user.CompanyId)
  317. if err != nil {
  318. br.Msg = "获取信息失败"
  319. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  320. return
  321. }
  322. resp.PermissionName = permissionStr
  323. if user.Mobile == "" && user.Email == "" {
  324. resp.IsBind = true
  325. }
  326. if userRecord.UnionId == "" {
  327. resp.IsAuth = true
  328. }
  329. } else {
  330. resp.IsBind = true
  331. if user.UnionId == "" {
  332. resp.IsAuth = true
  333. }
  334. resp.PermissionName = ""
  335. }
  336. br.Success = true
  337. br.Msg = "获取成功"
  338. br.Data = resp
  339. br.Ret = 200
  340. }
  341. // @Title 获取我的收藏
  342. // @Description 获取我的收藏列表
  343. // @Param PageSize query int true "PageSize"
  344. // @Param CurrentIndex query int true "CurrentIndex"
  345. // @Success 200 {object} models.ArticleCollectListResp
  346. // @router /collect/list [get]
  347. func (this *UserController) CollectList() {
  348. br := new(models.BaseResponse).Init()
  349. defer func() {
  350. this.Data["json"] = br
  351. this.ServeJSON()
  352. }()
  353. userId := this.User.UserId
  354. var pageSize, currentIndex, startSize int
  355. pageSize, _ = this.GetInt("PageSize")
  356. currentIndex, _ = this.GetInt("CurrentIndex")
  357. if pageSize <= 0 {
  358. pageSize = utils.PageSize20
  359. }
  360. if currentIndex <= 0 {
  361. currentIndex = 1
  362. }
  363. startSize = utils.StartIndex(currentIndex, pageSize)
  364. total, err := models.GetArticleUserCollectCount(userId)
  365. if err != nil {
  366. br.Msg = "获取数据失败"
  367. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  368. return
  369. }
  370. list, err := models.GetArticleUserCollectList(startSize, pageSize, userId)
  371. if err != nil {
  372. br.Msg = "获取数据失败"
  373. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  374. return
  375. }
  376. var articleIds []string
  377. for _, v := range list {
  378. articleIds = append(articleIds, strconv.Itoa(v.ArticleId))
  379. }
  380. articleIdStr := strings.Join(articleIds, ",")
  381. articleMap := make(map[int]*models.ArticleDetail)
  382. if articleIdStr != "" {
  383. articleList, err := models.GetArticleDetailByIdStr(articleIdStr)
  384. if err != nil {
  385. br.Msg = "获取数据失败"
  386. br.ErrMsg = "获取报告详情信息失败,Err:" + err.Error()
  387. return
  388. }
  389. for _, v := range articleList {
  390. if _, ok := articleMap[v.ArticleId]; !ok {
  391. articleMap[v.ArticleId] = v
  392. }
  393. }
  394. }
  395. lenList := len(list)
  396. for i := 0; i < lenList; i++ {
  397. item := list[i]
  398. article := articleMap[item.ArticleId]
  399. list[i].Title = article.Title
  400. list[i].TitleEn = article.TitleEn
  401. list[i].UpdateFrequency = article.UpdateFrequency
  402. list[i].CreateDate = article.CreateDate
  403. list[i].PublishDate = article.PublishDate
  404. list[i].Body, _ = services.GetReportContentTextSub(article.Body)
  405. list[i].Abstract = article.Abstract
  406. list[i].CategoryName = article.CategoryName
  407. list[i].SubCategoryName = article.SubCategoryName
  408. }
  409. page := paging.GetPaging(currentIndex, pageSize, total)
  410. resp := new(models.ArticleCollectListResp)
  411. resp.List = list
  412. resp.Paging = page
  413. br.Msg = "获取成功!"
  414. br.Ret = 200
  415. br.Success = true
  416. br.Data = resp
  417. }
  418. // @Title 获取申请访谈列表
  419. // @Description 获取申请访谈列表
  420. // @Param PageSize query int true "PageSize"
  421. // @Param CurrentIndex query int true "CurrentIndex"
  422. // @Success 200 {object} models.ArticleInterviewApplyListResp
  423. // @router /interview/apply/list [get]
  424. func (this *UserController) InterviewApplyList() {
  425. br := new(models.BaseResponse).Init()
  426. defer func() {
  427. this.Data["json"] = br
  428. this.ServeJSON()
  429. }()
  430. userId := this.User.UserId
  431. var pageSize, currentIndex, startSize int
  432. pageSize, _ = this.GetInt("PageSize")
  433. currentIndex, _ = this.GetInt("CurrentIndex")
  434. if pageSize <= 0 {
  435. pageSize = utils.PageSize20
  436. }
  437. if currentIndex <= 0 {
  438. currentIndex = 1
  439. }
  440. startSize = utils.StartIndex(currentIndex, pageSize)
  441. total, err := models.GetArticleUserInterviewApplyCount(userId)
  442. if err != nil {
  443. br.Msg = "获取数据失败"
  444. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  445. return
  446. }
  447. list, err := models.GetArticleUserInterviewApplyList(startSize, pageSize, userId)
  448. if err != nil {
  449. br.Msg = "获取数据失败"
  450. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  451. return
  452. }
  453. var articleIds []string
  454. for _, v := range list {
  455. articleIds = append(articleIds, strconv.Itoa(v.ArticleId))
  456. }
  457. articleIdStr := strings.Join(articleIds, ",")
  458. articleMap := make(map[int]*models.ArticleDetail)
  459. if articleIdStr != "" {
  460. articleList, err := models.GetArticleDetailByIdStr(articleIdStr)
  461. if err != nil {
  462. br.Msg = "获取数据失败"
  463. br.ErrMsg = "获取报告详情信息失败,Err:" + err.Error()
  464. return
  465. }
  466. for _, v := range articleList {
  467. if _, ok := articleMap[v.ArticleId]; !ok {
  468. articleMap[v.ArticleId] = v
  469. }
  470. }
  471. }
  472. lenList := len(list)
  473. for i := 0; i < lenList; i++ {
  474. item := list[i]
  475. article := articleMap[item.ArticleId]
  476. bodySub, _ := services.GetReportContentTextSub(article.Body)
  477. list[i].Title = article.Title
  478. list[i].TitleEn = article.TitleEn
  479. list[i].UpdateFrequency = article.UpdateFrequency
  480. list[i].CreateDate = article.CreateDate
  481. list[i].PublishDate = article.PublishDate
  482. list[i].Body = bodySub
  483. list[i].Abstract = article.Abstract
  484. list[i].CategoryName = article.CategoryName
  485. list[i].SubCategoryName = article.SubCategoryName
  486. list[i].ExpertBackground = article.ExpertBackground
  487. list[i].ExpertNumber = article.ExpertNumber
  488. }
  489. page := paging.GetPaging(currentIndex, pageSize, total)
  490. resp := new(models.ArticleInterviewApplyListResp)
  491. resp.List = list
  492. resp.Paging = page
  493. br.Msg = "获取成功!"
  494. br.Ret = 200
  495. br.Success = true
  496. br.Data = resp
  497. }
  498. // @Title 获取浏览历史列表
  499. // @Description 获取浏览历史列表
  500. // @Param PageSize query int true "PageSize"
  501. // @Param CurrentIndex query int true "CurrentIndex"
  502. // @Success 200 {object} models.ArticleBrowseHistoryListResp
  503. // @router /browse/history/list [get]
  504. func (this *UserController) BrowseHistoryList() {
  505. br := new(models.BaseResponse).Init()
  506. defer func() {
  507. this.Data["json"] = br
  508. this.ServeJSON()
  509. }()
  510. userId := this.User.UserId
  511. var pageSize, currentIndex, startSize int
  512. pageSize, _ = this.GetInt("PageSize")
  513. currentIndex, _ = this.GetInt("CurrentIndex")
  514. if pageSize <= 0 {
  515. pageSize = utils.PageSize20
  516. }
  517. if currentIndex <= 0 {
  518. currentIndex = 1
  519. }
  520. startSize = utils.StartIndex(currentIndex, pageSize)
  521. endDate := time.Now().AddDate(0, -1, 0).Format(utils.FormatDate)
  522. total, err := models.GetArticleUserBrowseHistoryCount(userId, endDate)
  523. if err != nil {
  524. br.Msg = "获取数据失败"
  525. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  526. return
  527. }
  528. list, err := models.GetArticleUserBrowseHistoryList(startSize, pageSize, userId, endDate)
  529. if err != nil {
  530. br.Msg = "获取数据失败"
  531. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  532. return
  533. }
  534. var articleIds []string
  535. for _, v := range list {
  536. articleIds = append(articleIds, strconv.Itoa(v.ArticleId))
  537. }
  538. articleIdStr := strings.Join(articleIds, ",")
  539. articleMap := make(map[int]*models.ArticleDetail)
  540. if articleIdStr != "" {
  541. articleList, err := models.GetArticleDetailByIdStr(articleIdStr)
  542. if err != nil {
  543. br.Msg = "获取数据失败"
  544. br.ErrMsg = "获取报告详情信息失败,Err:" + err.Error()
  545. return
  546. }
  547. for _, v := range articleList {
  548. if _, ok := articleMap[v.ArticleId]; !ok {
  549. articleMap[v.ArticleId] = v
  550. }
  551. }
  552. }
  553. lenList := len(list)
  554. for i := 0; i < lenList; i++ {
  555. item := list[i]
  556. article := articleMap[item.ArticleId]
  557. if article != nil {
  558. list[i].Title = article.Title
  559. list[i].TitleEn = article.TitleEn
  560. list[i].UpdateFrequency = article.UpdateFrequency
  561. list[i].CreateDate = article.CreateDate
  562. list[i].PublishDate = article.PublishDate
  563. list[i].Body, _ = services.GetReportContentTextSub(article.Body)
  564. list[i].Abstract = article.Abstract
  565. list[i].CategoryName = article.CategoryName
  566. list[i].SubCategoryName = article.SubCategoryName
  567. }
  568. }
  569. page := paging.GetPaging(currentIndex, pageSize, total)
  570. resp := new(models.ArticleBrowseHistoryListResp)
  571. resp.List = list
  572. resp.Paging = page
  573. br.Msg = "获取成功!"
  574. br.Ret = 200
  575. br.Success = true
  576. br.Data = resp
  577. }
  578. // @Title 未付费申请试用
  579. // @Description 未付费申请试用
  580. // @Param request body models.ApplyTryReq true "type json string"
  581. // @Success 200
  582. // @router /apply/try [post]
  583. func (this *UserController) ApplyTryOut() {
  584. br := new(models.BaseResponse).Init()
  585. defer func() {
  586. this.Data["json"] = br
  587. this.ServeJSON()
  588. }()
  589. user := this.User
  590. if user == nil {
  591. br.Msg = "请登录"
  592. br.ErrMsg = "请登录,SysUser Is Empty"
  593. br.Ret = 408
  594. return
  595. }
  596. mobile := user.Mobile
  597. var req models.ApplyTryReq
  598. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  599. if err != nil {
  600. br.Msg = "参数解析异常!"
  601. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  602. return
  603. }
  604. if req.RealName == "" {
  605. req.RealName = user.RealName
  606. }
  607. if req.CompanyName == "" {
  608. req.CompanyName = user.CompanyName
  609. }
  610. uid := user.UserId
  611. var title string
  612. tryType := req.TryType
  613. detailId := req.DetailId
  614. if tryType == "Article" {
  615. detail, err := models.GetArticleDetailById(detailId)
  616. if err != nil {
  617. br.Msg = "获取信息失败"
  618. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  619. return
  620. }
  621. title = detail.Title
  622. } else if tryType == "Activity" {
  623. detail, err := models.GetAddActivityInfoById(detailId)
  624. if err != nil {
  625. br.Msg = "操作失败"
  626. br.ErrMsg = "活动ID错误,不存在activityId:" + strconv.Itoa(detailId)
  627. return
  628. }
  629. title = detail.ActivityName
  630. }
  631. fmt.Println(title)
  632. //缓存校验
  633. cacheKey := fmt.Sprint("xygx:apply_record:add:", uid)
  634. ttlTime := utils.Rc.GetRedisTTL(cacheKey)
  635. if ttlTime > 0 {
  636. br.Msg = "申请失败,申请过于频繁"
  637. br.ErrMsg = "申请失败,申请过于频繁"
  638. return
  639. }
  640. utils.Rc.SetNX(cacheKey, user.Mobile, time.Second*10)
  641. //判断是否已经申请过
  642. applyCount, err := models.GetApplyRecordCount(uid)
  643. if err != nil && err.Error() != utils.ErrNoRow() {
  644. br.Msg = "获取信息失败"
  645. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  646. return
  647. }
  648. if applyCount > 0 {
  649. br.Msg = "您已提交申请,请耐心等待。"
  650. br.IsSendEmail = false
  651. return
  652. }
  653. //判断是否存在申请
  654. var sellerMobile string
  655. if req.ApplyMethod == 2 {
  656. if req.BusinessCardUrl == "" {
  657. br.Msg = "请上传名片"
  658. return
  659. }
  660. if req.RealName == "" {
  661. br.Msg = "请输入姓名"
  662. return
  663. }
  664. if req.CompanyName == "" {
  665. br.Msg = "请输入公司名称"
  666. return
  667. }
  668. if req.BusinessCardUrl != "" && utils.RunMode == "release" {
  669. card, err := services.GetBusinessCard(req.BusinessCardUrl)
  670. if err != nil {
  671. br.Msg = "名片识别失败"
  672. br.ErrMsg = "名片识别失败,Err:" + err.Error()
  673. return
  674. }
  675. mobileStr := strings.Join(card.WordsResult.MOBILE, ",")
  676. isFlag := true
  677. if mobile != "" {
  678. if strings.Contains(mobileStr, mobile) || mobileStr == "" {
  679. isFlag = true
  680. } else {
  681. isFlag = false
  682. }
  683. }
  684. if !isFlag {
  685. //阿里云识别
  686. if utils.RunMode == "release" {
  687. aliyunResult, err := services.AliyunBusinessCard(req.BusinessCardUrl)
  688. if err != nil {
  689. br.Msg = "识别失败"
  690. br.ErrMsg = "识别失败,Err:" + err.Error()
  691. return
  692. }
  693. if !aliyunResult.Success {
  694. br.Msg = "识别失败"
  695. br.ErrMsg = "识别失败"
  696. return
  697. }
  698. mobileStr := strings.Join(aliyunResult.TelCell, ",")
  699. if mobile != "" {
  700. if strings.Contains(mobileStr, mobile) {
  701. isFlag = true
  702. } else {
  703. isFlag = false
  704. }
  705. }
  706. }
  707. }
  708. if !isFlag {
  709. br.Msg = "名片手机号与所填手机号不匹配,请重新填写"
  710. br.ErrMsg = "mobile:" + mobile
  711. return
  712. }
  713. }
  714. }
  715. //获取销售信息
  716. sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  717. if err != nil && err.Error() != utils.ErrNoRow() {
  718. br.Msg = "申请失败"
  719. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  720. return
  721. }
  722. if sellerItem != nil {
  723. sellerMobile = sellerItem.Mobile
  724. //推送模板消息
  725. mobile := user.Mobile
  726. if mobile == "" {
  727. mobile = user.Email
  728. }
  729. }
  730. applyMethod := ""
  731. cnf, _ := models.GetConfigByCode("tpl_msg")
  732. if cnf != nil {
  733. if sellerItem != nil {
  734. cnf.ConfigValue = sellerItem.Mobile
  735. companyItem, err := models.GetCompanyDetailById(user.CompanyId)
  736. if err != nil && err.Error() != utils.ErrNoRow() {
  737. br.Msg = "获取信息失败"
  738. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  739. return
  740. }
  741. if companyItem != nil && companyItem.CompanyId > 0 {
  742. applyMethod = companyItem.Status + "客户申请"
  743. if detailId > 0 {
  744. companyProduct, err := models.GetCompanyProductDetail(user.CompanyId, 2)
  745. if err != nil && err.Error() != utils.ErrNoRow() {
  746. br.Msg = "获取信息失败"
  747. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  748. return
  749. }
  750. if companyProduct != nil && companyProduct.IsSuspend == 1 {
  751. applyMethod = "试用暂停客户"
  752. } else {
  753. if companyItem.Status == "正式" || companyItem.Status == "试用" {
  754. applyMethod = companyItem.Status + "客户申请,无对应权限"
  755. } else if companyItem.Status == "冻结" || companyItem.Status == "流失" {
  756. applyMethod = companyItem.Status + "客户"
  757. }
  758. }
  759. applyMethod = applyMethod + "," + title
  760. }
  761. }
  762. } else {
  763. //获取销售信息
  764. sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 1)
  765. if err != nil && err.Error() != utils.ErrNoRow() {
  766. br.Msg = "申请失败"
  767. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  768. return
  769. }
  770. if sellerItem != nil {
  771. applyMethod = "FICC客户"
  772. } else {
  773. applyMethod = "潜在客户"
  774. }
  775. if detailId > 0 {
  776. applyMethod = applyMethod + "," + title
  777. }
  778. }
  779. openIpItem, _ := models.GetUserRecordByMobile(4, cnf.ConfigValue)
  780. if openIpItem != nil && openIpItem.OpenId != "" {
  781. if req.ApplyMethod != 2 {
  782. req.RealName = user.RealName
  783. req.CompanyName = user.CompanyName
  784. }
  785. fmt.Println("推送消息", req.RealName, req.CompanyName, mobile, openIpItem.OpenId, applyMethod)
  786. utils.FileLog.Info("推送消息 %s %s,%s,%s,%s", req.RealName, req.CompanyName, mobile, openIpItem.OpenId, applyMethod)
  787. go services.SendPermissionApplyTemplateMsg(req.RealName, req.CompanyName, mobile, openIpItem.OpenId, applyMethod)
  788. }
  789. }
  790. err = models.AddApplyRecord(&req, user.Mobile, user.CompanyName, uid, user.CompanyId)
  791. if err != nil {
  792. br.Msg = "申请失败"
  793. br.ErrMsg = "申请失败,Err:" + err.Error()
  794. return
  795. }
  796. //添加成功后,设置5分钟缓存,不允许重复添加
  797. //utils.Rc.SetNX(cacheKey, user.Mobile, time.Second*60)
  798. br.Msg = "申请成功!"
  799. br.Ret = 200
  800. br.Success = true
  801. br.Data = sellerMobile
  802. }
  803. // @Title 是否需要填写区号
  804. // @Description 获取是否需要填写区号接口
  805. // @Success 200 {object} models.CountryCode
  806. // @router /countryCcode/isNeedAdd [get]
  807. func (this *UserController) CountryCcode() {
  808. br := new(models.BaseResponse).Init()
  809. defer func() {
  810. this.Data["json"] = br
  811. this.ServeJSON()
  812. }()
  813. user := this.User
  814. uid := user.UserId
  815. if user == nil {
  816. br.Msg = "请登录"
  817. br.ErrMsg = "请登录,用户信息为空"
  818. br.Ret = 408
  819. return
  820. }
  821. if uid == 0 {
  822. br.Msg = "请登录"
  823. br.ErrMsg = "请登录,用户信息为空"
  824. br.Ret = 408
  825. return
  826. }
  827. resp := new(models.CountryCode)
  828. if user.CountryCode == "" && len(user.Mobile) >= 11 {
  829. err := models.ChangeUserOutboundMobileByMobile(uid)
  830. if err != nil {
  831. br.Msg = "操作失败"
  832. br.ErrMsg = "操作失败,Err:" + err.Error()
  833. return
  834. }
  835. }
  836. if user.CountryCode == "" && user.Mobile != "" && len(user.Mobile) < 11 {
  837. resp.IsNeedAddCountryCode = true
  838. }
  839. if user.OutboundMobile != "" {
  840. resp.IsNeedAddCountryCode = false
  841. }
  842. br.Ret = 200
  843. br.Success = true
  844. br.Msg = "获取成功"
  845. br.Data = resp
  846. }
  847. // @Title 上传用户区号
  848. // @Description 上传用户区号接口
  849. // @Param request body models.CountryCodeItem true "type json string"
  850. // @Success Ret=200 新增成功
  851. // @router /countryCcode/Add [POST]
  852. func (this *UserController) AddCountryCcode() {
  853. br := new(models.BaseResponse).Init()
  854. defer func() {
  855. this.Data["json"] = br
  856. this.ServeJSON()
  857. }()
  858. user := this.User
  859. if user == nil {
  860. br.Msg = "请登录"
  861. br.ErrMsg = "请登录,用户信息为空"
  862. br.Ret = 408
  863. return
  864. }
  865. var req models.CountryCodeItem
  866. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  867. if err != nil {
  868. br.Msg = "参数解析异常!"
  869. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  870. return
  871. }
  872. err = models.AddCountryCode(req.CountryCode, user)
  873. if err != nil {
  874. br.Msg = "获取信息失败"
  875. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  876. return
  877. }
  878. br.Ret = 200
  879. br.Success = true
  880. br.Msg = "新增成功"
  881. }
  882. // @Title 用户修改外呼手机号以及区号
  883. // @Description 用户修改外呼手机号以及区号接口
  884. // @Param request body models.OutboundMobileItem true "type json string"
  885. // @Success Ret=200 操作成功
  886. // @router /countryCcode/addOutboundMobile [POST]
  887. func (this *UserController) AddOutboundMobile() {
  888. br := new(models.BaseResponse).Init()
  889. defer func() {
  890. this.Data["json"] = br
  891. this.ServeJSON()
  892. }()
  893. user := this.User
  894. uid := user.UserId
  895. if user == nil {
  896. br.Msg = "请登录"
  897. br.ErrMsg = "请登录,用户信息为空"
  898. br.Ret = 408
  899. return
  900. }
  901. var req models.OutboundMobileItem
  902. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  903. if err != nil {
  904. br.Msg = "参数解析异常!"
  905. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  906. return
  907. }
  908. if !utils.ValidateFixedTelephoneFormatatEasy(req.OutboundMobile) {
  909. br.Msg = "号码格式有误,请重新填写!"
  910. br.ErrMsg = "号码格式有误,请重新填写" + req.OutboundMobile
  911. return
  912. }
  913. if req.OutboundMobile == "" {
  914. br.Msg = "请填写区号!"
  915. return
  916. }
  917. item := new(models.OutboundMobileItem)
  918. item.OutboundMobile = req.OutboundMobile
  919. item.OutboundCountryCode = req.OutboundCountryCode
  920. item.ActivityId = req.ActivityId
  921. if req.ActivityId == 0 {
  922. err = models.AddOutboundMobile(item, uid)
  923. } else {
  924. if user.Mobile == "" && user.OutboundMobile == "" {
  925. items := new(models.CygxActivitySignup)
  926. items.UserId = uid
  927. items.ActivityId = req.ActivityId
  928. items.CreateTime = time.Now()
  929. items.Mobile = user.Mobile
  930. items.Email = user.Email
  931. items.CompanyId = user.CompanyId
  932. items.CompanyName = user.CompanyName
  933. items.SignupType = 1
  934. items.FailType = 0
  935. items.DoFailType = 0
  936. items.OutboundMobile = req.OutboundMobile
  937. items.CountryCode = req.OutboundCountryCode
  938. _, err = models.AddActivitySignupFromEmail(items)
  939. } else {
  940. total, err := models.GetActivityCountByIdWithUid(item.ActivityId, uid)
  941. if total == 0 {
  942. br.Msg = "报名信息不存在"
  943. br.ErrMsg = "报名信息不存在,Err:" + "活动ActivityId:" + strconv.Itoa(item.ActivityId) + "用户Uid:" + strconv.Itoa(uid)
  944. return
  945. }
  946. if err != nil {
  947. br.Msg = "操作失败"
  948. br.ErrMsg = "操作失败,Err:" + err.Error()
  949. return
  950. }
  951. err = models.AddOutboundMobile(item, uid)
  952. }
  953. }
  954. if err != nil {
  955. br.Msg = "操作失败"
  956. br.ErrMsg = "操作失败,Err:" + err.Error()
  957. return
  958. }
  959. br.Ret = 200
  960. br.Success = true
  961. br.Msg = "操作成功"
  962. }
  963. // @Title 获取我的提问
  964. // @Description 获取我的提问列表
  965. // @Success 200 {object} models.CygxAskListResp
  966. // @router /ask/list [get]
  967. func (this *UserController) AskList() {
  968. br := new(models.BaseResponse).Init()
  969. defer func() {
  970. this.Data["json"] = br
  971. this.ServeJSON()
  972. }()
  973. user := this.User
  974. if user == nil {
  975. br.Msg = "请登录"
  976. br.ErrMsg = "请登录,用户信息为空"
  977. br.Ret = 408
  978. return
  979. }
  980. userId := this.User.UserId
  981. listActcivity, err := models.GetActivityAskList(userId)
  982. if err != nil && err.Error() != utils.ErrNoRow() {
  983. br.Msg = "获取失败"
  984. br.ErrMsg = "获取活动问题失败,Err:" + err.Error()
  985. return
  986. }
  987. for _, v := range listActcivity {
  988. v.AskType = "Activity"
  989. }
  990. listArticle, err := models.GetArticleAskList(userId)
  991. if err != nil && err.Error() != utils.ErrNoRow() {
  992. br.Msg = "获取失败"
  993. br.ErrMsg = "获取文章问题失败,Err:" + err.Error()
  994. return
  995. }
  996. for _, v := range listArticle {
  997. v.AskType = "Report"
  998. listActcivity = append(listActcivity, v)
  999. }
  1000. resp := new(models.CygxAskListResp)
  1001. resp.List = listActcivity
  1002. br.Msg = "获取成功!"
  1003. br.Ret = 200
  1004. br.Success = true
  1005. br.Data = resp
  1006. }
  1007. // @Title 是否展示免费试用按钮
  1008. // @Description 获取是否展示免费试用按钮接口
  1009. // @Param request body models.IsShow true "type json string"
  1010. // @Success 200
  1011. // @router /isShow/freeButton [get]
  1012. func (this *UserController) IsShow() {
  1013. br := new(models.BaseResponse).Init()
  1014. defer func() {
  1015. this.Data["json"] = br
  1016. this.ServeJSON()
  1017. }()
  1018. user := this.User
  1019. if user == nil {
  1020. br.Msg = "请重新登录"
  1021. br.Ret = 408
  1022. return
  1023. }
  1024. var resp models.IsShow
  1025. detail, err := models.GetConfigByCode("free_trial_card")
  1026. if err != nil {
  1027. br.Msg = "获取数据失败"
  1028. br.ErrMsg = "城市配置信息失败,Err:" + err.Error()
  1029. return
  1030. }
  1031. companyDetail, err := models.GetCompanyDetailByIdGroup(user.CompanyId)
  1032. if err != nil && err.Error() != utils.ErrNoRow() {
  1033. br.Msg = "获取数据失败!"
  1034. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  1035. return
  1036. }
  1037. count, err := models.CountCygxUserFreeeButton(user.UserId)
  1038. if err != nil && err.Error() != utils.ErrNoRow() {
  1039. br.Msg = "获取数据失败!"
  1040. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  1041. return
  1042. }
  1043. if companyDetail != nil {
  1044. if detail.ConfigValue == "1" && (companyDetail.Status == "正式" || companyDetail.Status == "试用" || companyDetail.Status == "永续") && count == 0 {
  1045. resp.IsShow = true
  1046. }
  1047. }
  1048. br.Ret = 200
  1049. br.Success = true
  1050. br.Data = resp
  1051. }
  1052. // @Title 隐藏当天的按钮
  1053. // @Description 隐藏当天的按钮接口
  1054. // @Success 200
  1055. // @router /freeButton/update [post]
  1056. func (this *UserController) FreeButtonUpdate() {
  1057. br := new(models.BaseResponse).Init()
  1058. defer func() {
  1059. this.Data["json"] = br
  1060. this.ServeJSON()
  1061. }()
  1062. user := this.User
  1063. if user == nil {
  1064. br.Msg = "请重新登录"
  1065. br.Ret = 408
  1066. return
  1067. }
  1068. count, err := models.CountCygxUserFreeeButtonByUser(user.UserId)
  1069. if err != nil {
  1070. br.Msg = "获取数据失败!"
  1071. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  1072. return
  1073. }
  1074. if count == 0 {
  1075. item := new(models.CygxUserFreeeButton)
  1076. item.UserId = user.UserId
  1077. item.CompanyId = user.CompanyId
  1078. item.CreateTime = time.Now()
  1079. item.ModifyTime = time.Now()
  1080. item.EffectiveTime = time.Now().Format(utils.FormatDate)
  1081. _, err := models.AddCygxUserFreeeButton(item)
  1082. if err != nil {
  1083. br.Msg = "操作失败!"
  1084. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  1085. return
  1086. }
  1087. } else {
  1088. err := models.UpdateCygxUserFreeeButton(user.UserId)
  1089. if err != nil {
  1090. br.Msg = "操作失败!"
  1091. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  1092. return
  1093. }
  1094. }
  1095. br.Ret = 200
  1096. br.Success = true
  1097. br.Msg = "操作成功!"
  1098. }
  1099. // @Title 权限弹窗是否展示免费月卡
  1100. // @Description 获取权限弹窗是否展示免费月卡接口
  1101. // @Param request body models.IsShow true "type json string"
  1102. // @Success 200
  1103. // @router /isShow/alert [get]
  1104. func (this *UserController) AlertIsShow() {
  1105. br := new(models.BaseResponse).Init()
  1106. defer func() {
  1107. this.Data["json"] = br
  1108. this.ServeJSON()
  1109. }()
  1110. user := this.User
  1111. if user == nil {
  1112. br.Msg = "请重新登录"
  1113. br.Ret = 408
  1114. return
  1115. }
  1116. var resp models.IsShow
  1117. detail, err := models.GetConfigByCode("free_trial_card")
  1118. if err != nil {
  1119. br.Msg = "获取数据失败"
  1120. br.ErrMsg = "城市配置信息失败,Err:" + err.Error()
  1121. return
  1122. }
  1123. if user.CompanyId == 1 && detail.ConfigValue == "1" {
  1124. resp.IsShow = true
  1125. }
  1126. br.Ret = 200
  1127. br.Success = true
  1128. br.Data = resp
  1129. }
  1130. // @Title 分享的时候是否展示免费月卡
  1131. // @Description 获取权限弹窗是否展示免费月卡接口
  1132. // @Param request body models.IsShow true "type json string"
  1133. // @Success 200
  1134. // @router /isShow/share [get]
  1135. func (this *UserController) ShareIsShow() {
  1136. br := new(models.BaseResponse).Init()
  1137. defer func() {
  1138. this.Data["json"] = br
  1139. this.ServeJSON()
  1140. }()
  1141. user := this.User
  1142. if user == nil {
  1143. br.Msg = "请重新登录"
  1144. br.Ret = 408
  1145. return
  1146. }
  1147. var resp models.IsShow
  1148. detail, err := models.GetConfigByCode("free_trial_card")
  1149. if err != nil {
  1150. br.Msg = "获取数据失败"
  1151. br.ErrMsg = "城市配置信息失败,Err:" + err.Error()
  1152. return
  1153. }
  1154. if user.CompanyId != 16 && detail.ConfigValue == "1" {
  1155. resp.IsShow = true
  1156. }
  1157. br.Ret = 200
  1158. br.Success = true
  1159. br.Data = resp
  1160. }