user.go 33 KB

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