user.go 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630
  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. type UserCommonController struct {
  18. BaseCommonController
  19. }
  20. // @Title 登录
  21. // @Description 登录接口
  22. // @Param request body models.LoginReq true "type json string"
  23. // @Success 200 {object} models.LoginResp
  24. // @router /login [post]
  25. func (this *UserController) Login() {
  26. br := new(models.BaseResponse).Init()
  27. defer func() {
  28. this.Data["json"] = br
  29. this.ServeJSON()
  30. }()
  31. var req models.LoginReq
  32. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  33. if err != nil {
  34. br.Msg = "参数解析异常!"
  35. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  36. return
  37. }
  38. user := this.User
  39. if user == nil {
  40. br.Msg = "请登录"
  41. br.ErrMsg = "请登录"
  42. br.Ret = 408
  43. return
  44. }
  45. unionId := this.User.UnionId
  46. openId := this.User.OpenId
  47. if unionId == "" {
  48. br.Msg = "参数错误"
  49. br.ErrMsg = "参数错误,unionId 为空"
  50. return
  51. }
  52. if req.LoginType == 1 || req.LoginType == 3 {
  53. if req.Mobile == "" {
  54. br.Msg = "参数错误"
  55. br.ErrMsg = "参数错误,手机号为空 为空"
  56. return
  57. }
  58. if req.LoginType == 3 {
  59. item, err := models.GetMsgCode(req.Mobile, req.VCode)
  60. if err != nil {
  61. if err.Error() == utils.ErrNoRow() {
  62. br.Msg = "验证码错误,请重新输入"
  63. br.ErrMsg = "校验验证码失败,Err:" + err.Error()
  64. return
  65. } else {
  66. br.Msg = "验证码错误,请重新输入"
  67. br.ErrMsg = "校验验证码失败,Err:" + err.Error()
  68. return
  69. }
  70. }
  71. if item == nil {
  72. br.Msg = "验证码错误,请重新输入"
  73. return
  74. }
  75. }
  76. req.Mobile = strings.Trim(req.Mobile, " ")
  77. } else if req.LoginType == 2 {
  78. if req.Email == "" {
  79. br.ErrMsg = "邮箱不能为空,请输入邮箱"
  80. br.Msg = "邮箱不能为空,请输入邮箱"
  81. return
  82. }
  83. if !utils.ValidateEmailFormatat(req.Email) {
  84. br.ErrMsg = "邮箱格式错误,请重新输入"
  85. br.Msg = "邮箱格式错误,请重新输入"
  86. return
  87. }
  88. item, err := models.GetMsgCode(req.Email, req.VCode)
  89. if err != nil {
  90. if err.Error() == utils.ErrNoRow() {
  91. br.Msg = "验证码错误,请重新输入"
  92. br.ErrMsg = "校验验证码失败,Err:" + err.Error()
  93. return
  94. } else {
  95. br.Msg = "验证码错误,请重新输入"
  96. br.ErrMsg = "校验验证码失败,Err:" + err.Error()
  97. return
  98. }
  99. }
  100. if item == nil {
  101. br.Msg = "验证码错误,请重新输入"
  102. return
  103. }
  104. } else {
  105. br.Msg = "无效的登录方式"
  106. br.ErrMsg = "无效的登录方式,Err:"
  107. return
  108. }
  109. if len(req.Mobile) >= 11 && req.CountryCode == "" {
  110. req.CountryCode = "86"
  111. }
  112. user, err = services.BindWxUser(openId, req.Mobile, req.Email, req.CountryCode)
  113. if err != nil {
  114. br.Msg = "登录失败"
  115. br.ErrMsg = "绑定手机号失败:" + err.Error()
  116. return
  117. }
  118. userId := user.UserId
  119. var token string
  120. tokenItem, err := models.GetTokenByOpenId(openId)
  121. if err != nil && err.Error() != utils.ErrNoRow() {
  122. br.Msg = "登录失败"
  123. br.ErrMsg = "登录失败,获取token失败:" + err.Error()
  124. return
  125. }
  126. if tokenItem == nil || (err != nil && err.Error() == utils.ErrNoRow()) {
  127. timeUnix := time.Now().Unix()
  128. timeUnixStr := strconv.FormatInt(timeUnix, 10)
  129. token = utils.MD5(openId) + utils.MD5(timeUnixStr)
  130. //新增session
  131. {
  132. session := new(models.CygxSession)
  133. session.OpenId = unionId
  134. session.UnionId = unionId
  135. session.UserId = userId
  136. session.CreatedTime = time.Now()
  137. session.LastUpdatedTime = time.Now()
  138. session.ExpireTime = time.Now().AddDate(0, 1, 0)
  139. session.AccessToken = token
  140. err = models.AddSession(session)
  141. if err != nil {
  142. br.Msg = "登录失败"
  143. br.ErrMsg = "登录失败,新增用户session信息失败:" + err.Error()
  144. return
  145. }
  146. }
  147. } else {
  148. token = tokenItem.AccessToken
  149. }
  150. //新增登录日志
  151. {
  152. loginLog := new(models.WxUserLog)
  153. loginLog.UserId = userId
  154. loginLog.OpenId = unionId
  155. loginLog.Mobile = req.Mobile
  156. loginLog.Email = req.Email
  157. loginLog.CreateTime = time.Now()
  158. loginLog.Handle = "wechat_user_login"
  159. loginLog.Remark = token
  160. go models.AddWxUserLog(loginLog)
  161. }
  162. //添加邀请绑定关系
  163. {
  164. if req.ShareUserCode != "" {
  165. count, _ := models.GetUserInviteeCount(userId)
  166. if count == 0 {
  167. userItem := new(models.UserInvitee)
  168. userItem.CreateTime = time.Now()
  169. userItem.InviteedUserId = strconv.Itoa(userId)
  170. userItem.InviteeUserId = req.ShareUserCode
  171. shareUserId, _ := strconv.Atoi(req.ShareUserCode)
  172. inviteeUser, _ := models.GetWxUserItemByUserId(shareUserId)
  173. if inviteeUser != nil {
  174. userItem.InviteeMobile = inviteeUser.Mobile
  175. userItem.InviteeCompany = inviteeUser.CompanyName
  176. userItem.InviteeCompanyId = inviteeUser.CompanyId
  177. userItem.InviteeEmail = inviteeUser.Email
  178. }
  179. models.AddUserInvite(userItem)
  180. }
  181. }
  182. }
  183. resp := new(models.LoginResp)
  184. resp.UserId = userId
  185. resp.Authorization = token
  186. if user.CompanyId == 1 {
  187. resp.IsPotential = true
  188. }
  189. br.Ret = 200
  190. br.Success = true
  191. br.Data = resp
  192. br.Msg = "登录成功"
  193. }
  194. // @Title 获取用户详情
  195. // @Description 获取用户详情接口
  196. // @Success 200 {object} models.UserDetail
  197. // @router /detail [get]
  198. func (this *UserController) Detail() {
  199. br := new(models.BaseResponse).Init()
  200. defer func() {
  201. this.Data["json"] = br
  202. this.ServeJSON()
  203. }()
  204. user := this.User
  205. if user == nil {
  206. br.Msg = "请登录"
  207. br.ErrMsg = "请登录,用户信息为空"
  208. br.Ret = 408
  209. return
  210. }
  211. uid := user.UserId
  212. var hasPermission int
  213. detail := new(models.UserDetail)
  214. if uid > 0 {
  215. var err error
  216. detail, err = models.GetUserDetailByUserId(uid)
  217. if err != nil && err.Error() != utils.ErrNoRow() {
  218. br.Msg = "获取信息失败"
  219. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  220. return
  221. }
  222. userRecord, _ := models.GetUserRecordByUserId(uid, utils.WxPlatform)
  223. if userRecord != nil {
  224. detail.NickName = userRecord.NickName
  225. if detail.Headimgurl == "" {
  226. detail.Headimgurl = userRecord.Headimgurl
  227. }
  228. if detail.Headimgurl == "" {
  229. userRecord, _ = models.GetUserRecordByUserId(uid, 1)
  230. if userRecord != nil {
  231. detail.NickName = userRecord.NickName
  232. detail.Headimgurl = userRecord.Headimgurl
  233. }
  234. }
  235. }
  236. if user.CompanyId > 1 {
  237. companyItem, err := models.GetCompanyDetailById(user.CompanyId)
  238. if err != nil && err.Error() != utils.ErrNoRow() {
  239. br.Msg = "获取信息失败"
  240. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  241. return
  242. }
  243. if companyItem != nil && companyItem.CompanyId > 0 {
  244. detail.CompanyName = companyItem.CompanyName
  245. //if companyItem.Status == "试用" || companyItem.Status == "永续" || companyItem.Status == "正式" {
  246. permissionStr, err := models.GetCompanyPermissionByUser(companyItem.CompanyId)
  247. if err != nil {
  248. br.Msg = "获取信息失败"
  249. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  250. return
  251. }
  252. permissionStrOld, err := models.GetCompanyPermission(companyItem.CompanyId)
  253. if err != nil {
  254. br.Msg = "获取信息失败"
  255. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  256. return
  257. }
  258. permissionStrListOld := strings.Split(permissionStrOld, ",")
  259. for _, v := range permissionStrListOld {
  260. if strings.Count(permissionStr, v) > 1 {
  261. permissionStr = strings.Replace(permissionStr, v+"(主观)", v, -1)
  262. permissionStr = strings.Replace(permissionStr, v+"(客观),", "", -1)
  263. }
  264. }
  265. detail.PermissionName = permissionStr
  266. //} else {
  267. if permissionStr == "" {
  268. hasPermission = 1
  269. }
  270. //}
  271. detail.SellerName = companyItem.SellerName
  272. detail.SellerMobile = companyItem.Mobile
  273. } else {
  274. hasPermission = 1
  275. }
  276. } else {
  277. //判断是否已经申请过
  278. applyCount, err := models.GetApplyRecordCount(uid)
  279. if err != nil && err.Error() != utils.ErrNoRow() {
  280. br.Msg = "获取信息失败"
  281. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  282. return
  283. }
  284. if applyCount > 0 {
  285. hasPermission = 3
  286. } else {
  287. hasPermission = 2
  288. }
  289. detail.CompanyName = detail.Note
  290. }
  291. detail.HasPermission = hasPermission
  292. } else {
  293. ur, _ := models.GetUserRecordByOpenId(user.OpenId)
  294. if ur != nil {
  295. detail.NickName = ur.NickName
  296. detail.Email = ur.BindAccount
  297. detail.Mobile = ur.BindAccount
  298. detail.NickName = ur.NickName
  299. detail.Headimgurl = ur.Headimgurl
  300. }
  301. hasPermission = 2
  302. detail.HasPermission = hasPermission
  303. }
  304. if detail.Headimgurl == "" {
  305. detail.Headimgurl = utils.DefaultHeadimgurl
  306. }
  307. br.Ret = 200
  308. br.Success = true
  309. br.Msg = "获取成功"
  310. br.Data = detail
  311. }
  312. // @Title 校验用户状态信息
  313. // @Description 校验用户状态信息
  314. // @Success 200 {object} models.CheckStatusResp
  315. // @router /check/status [get]
  316. func (this *UserController) CheckLogin() {
  317. br := new(models.BaseResponse).Init()
  318. defer func() {
  319. this.Data["json"] = br
  320. this.ServeJSON()
  321. }()
  322. user := this.User
  323. if user == nil {
  324. br.Msg = "请登录"
  325. br.ErrMsg = "请登录"
  326. br.Ret = 408
  327. return
  328. }
  329. uid := user.UserId
  330. resp := new(models.CheckStatusResp)
  331. if uid > 0 {
  332. //判断token是否过期
  333. userRecord, err := models.GetUserRecordByUserId(uid, utils.WxPlatform)
  334. if err != nil {
  335. br.Msg = "获取用户信息失败"
  336. br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
  337. return
  338. }
  339. permissionStr, err := models.GetCompanyPermission(user.CompanyId)
  340. if err != nil {
  341. br.Msg = "获取信息失败"
  342. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  343. return
  344. }
  345. resp.PermissionName = permissionStr
  346. if user.Mobile == "" && user.Email == "" {
  347. resp.IsBind = true
  348. }
  349. if userRecord.UnionId == "" {
  350. resp.IsAuth = true
  351. }
  352. } else {
  353. resp.IsBind = true
  354. if user.UnionId == "" {
  355. resp.IsAuth = true
  356. }
  357. resp.PermissionName = ""
  358. }
  359. br.Success = true
  360. br.Msg = "获取成功"
  361. br.Data = resp
  362. br.Ret = 200
  363. }
  364. // @Title 获取我的收藏
  365. // @Description 获取我的收藏列表
  366. // @Param PageSize query int true "PageSize"
  367. // @Param CurrentIndex query int true "CurrentIndex"
  368. // @Success 200 {object} models.ArticleCollectListResp
  369. // @router /collect/list [get]
  370. func (this *UserController) CollectList() {
  371. br := new(models.BaseResponse).Init()
  372. defer func() {
  373. this.Data["json"] = br
  374. this.ServeJSON()
  375. }()
  376. userId := this.User.UserId
  377. var pageSize, currentIndex, startSize int
  378. pageSize, _ = this.GetInt("PageSize")
  379. currentIndex, _ = this.GetInt("CurrentIndex")
  380. if pageSize <= 0 {
  381. pageSize = utils.PageSize20
  382. }
  383. if currentIndex <= 0 {
  384. currentIndex = 1
  385. }
  386. startSize = utils.StartIndex(currentIndex, pageSize)
  387. total, err := models.GetArticleUserCollectCount(userId)
  388. if err != nil {
  389. br.Msg = "获取数据失败"
  390. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  391. return
  392. }
  393. list, err := models.GetArticleUserCollectList(startSize, pageSize, userId)
  394. if err != nil {
  395. br.Msg = "获取数据失败"
  396. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  397. return
  398. }
  399. resp := new(models.ArticleReportBillboardLIstPageResp)
  400. if len(list) == 0 {
  401. page := paging.GetPaging(currentIndex, pageSize, total)
  402. resp.List = list
  403. resp.Paging = page
  404. br.Msg = "获取成功!"
  405. br.Ret = 200
  406. br.Success = true
  407. br.Data = resp
  408. return
  409. }
  410. var condition string
  411. var pars []interface{}
  412. var articleIds []string
  413. for _, v := range list {
  414. articleIds = append(articleIds, strconv.Itoa(v.ArticleId))
  415. }
  416. articleIdStr := strings.Join(articleIds, ",")
  417. //获取文章关联的产业
  418. pars = make([]interface{}, 0)
  419. condition = ` AND mg.article_id IN ( ` + utils.GetOrmInReplace(len(articleIds)) + ` ) `
  420. pars = append(pars, articleIds)
  421. industrialList, err := models.GetIndustrialListByarticleId(pars, condition)
  422. if err != nil {
  423. br.Msg = "获取失败"
  424. br.ErrMsg = "获取失败,GetSubjectList Err:" + err.Error()
  425. return
  426. }
  427. industrialMap := make(map[int][]*models.IndustrialManagementIdInt)
  428. if len(industrialList) > 0 {
  429. for _, v := range industrialList {
  430. item := new(models.IndustrialManagementIdInt)
  431. item.ArticleId = v.ArticleId
  432. if v.ArticleId > utils.SummaryArticleId {
  433. item.IsResearch = true
  434. }
  435. item.IndustrialManagementId = v.IndustrialManagementId
  436. item.IndustryName = v.IndustryName
  437. industrialMap[v.ArticleId] = append(industrialMap[v.ArticleId], item)
  438. }
  439. }
  440. for k, v := range list {
  441. if len(industrialMap[v.ArticleId]) > 0 {
  442. list[k].List = industrialMap[v.ArticleId]
  443. } else {
  444. list[k].List = make([]*models.IndustrialManagementIdInt, 0)
  445. }
  446. }
  447. articleMap := make(map[int]*models.ArticleDetail)
  448. if articleIdStr != "" {
  449. articleList, err := models.GetArticleDetailByIdStr(articleIdStr)
  450. if err != nil {
  451. br.Msg = "获取数据失败"
  452. br.ErrMsg = "获取报告详情信息失败,Err:" + err.Error()
  453. return
  454. }
  455. for _, v := range articleList {
  456. if _, ok := articleMap[v.ArticleId]; !ok {
  457. articleMap[v.ArticleId] = v
  458. }
  459. }
  460. }
  461. //处理文章PV收藏等数量
  462. mapArticleCollectNum := make(map[int]*models.CygxArticleNum)
  463. if len(articleIds) > 0 {
  464. articleCollectNumList, err := models.GetArticleCollectNum(articleIds, userId)
  465. if err != nil && err.Error() != utils.ErrNoRow() {
  466. br.Msg = "获取失败"
  467. br.ErrMsg = "获取失败,GetArticleCollectNum Err:" + err.Error()
  468. return
  469. }
  470. for _, v := range articleCollectNumList {
  471. mapArticleCollectNum[v.ArticleId] = v
  472. }
  473. }
  474. lenList := len(list)
  475. for i := 0; i < lenList; i++ {
  476. item := list[i]
  477. article := articleMap[item.ArticleId]
  478. list[i].Title = article.Title
  479. list[i].DepartmentId = article.DepartmentId
  480. list[i].NickName = article.NickName
  481. list[i].PublishDate = article.PublishDate
  482. if article.ArticleId < utils.SummaryArticleId {
  483. list[i].Source = 1
  484. } else {
  485. list[i].Source = 2
  486. }
  487. if mapArticleCollectNum[article.ArticleId] != nil {
  488. list[i].CollectNum = mapArticleCollectNum[article.ArticleId].CollectNum
  489. list[i].Pv = mapArticleCollectNum[article.ArticleId].Pv
  490. list[i].IsCollect = mapArticleCollectNum[article.ArticleId].IsCollect
  491. }
  492. //list[i].TitleEn = article.TitleEn
  493. //list[i].UpdateFrequency = article.UpdateFrequency
  494. //list[i].CreateDate = article.CreateDate
  495. //list[i].Body, _ = services.GetReportContentTextSub(article.Body)
  496. //list[i].Abstract = article.Abstract
  497. //list[i].CategoryName = article.CategoryName
  498. //list[i].SubCategoryName = article.SubCategoryName
  499. }
  500. page := paging.GetPaging(currentIndex, pageSize, total)
  501. resp.List = list
  502. resp.Paging = page
  503. br.Msg = "获取成功!"
  504. br.Ret = 200
  505. br.Success = true
  506. br.Data = resp
  507. }
  508. // @Title 获取申请访谈列表
  509. // @Description 获取申请访谈列表
  510. // @Param PageSize query int true "PageSize"
  511. // @Param CurrentIndex query int true "CurrentIndex"
  512. // @Success 200 {object} models.ArticleInterviewApplyListResp
  513. // @router /interview/apply/list [get]
  514. func (this *UserController) InterviewApplyList() {
  515. br := new(models.BaseResponse).Init()
  516. defer func() {
  517. this.Data["json"] = br
  518. this.ServeJSON()
  519. }()
  520. userId := this.User.UserId
  521. var pageSize, currentIndex, startSize int
  522. pageSize, _ = this.GetInt("PageSize")
  523. currentIndex, _ = this.GetInt("CurrentIndex")
  524. if pageSize <= 0 {
  525. pageSize = utils.PageSize20
  526. }
  527. if currentIndex <= 0 {
  528. currentIndex = 1
  529. }
  530. startSize = utils.StartIndex(currentIndex, pageSize)
  531. total, err := models.GetArticleUserInterviewApplyCount(userId)
  532. if err != nil {
  533. br.Msg = "获取数据失败"
  534. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  535. return
  536. }
  537. list, err := models.GetArticleUserInterviewApplyList(startSize, pageSize, userId)
  538. if err != nil {
  539. br.Msg = "获取数据失败"
  540. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  541. return
  542. }
  543. var articleIds []string
  544. for _, v := range list {
  545. articleIds = append(articleIds, strconv.Itoa(v.ArticleId))
  546. }
  547. articleIdStr := strings.Join(articleIds, ",")
  548. articleMap := make(map[int]*models.ArticleDetail)
  549. if articleIdStr != "" {
  550. articleList, err := models.GetArticleDetailByIdStr(articleIdStr)
  551. if err != nil {
  552. br.Msg = "获取数据失败"
  553. br.ErrMsg = "获取报告详情信息失败,Err:" + err.Error()
  554. return
  555. }
  556. for _, v := range articleList {
  557. if _, ok := articleMap[v.ArticleId]; !ok {
  558. articleMap[v.ArticleId] = v
  559. }
  560. }
  561. }
  562. lenList := len(list)
  563. for i := 0; i < lenList; i++ {
  564. item := list[i]
  565. article := articleMap[item.ArticleId]
  566. bodySub, _ := services.GetReportContentTextSub(article.Body)
  567. list[i].Title = article.Title
  568. list[i].TitleEn = article.TitleEn
  569. list[i].UpdateFrequency = article.UpdateFrequency
  570. list[i].CreateDate = article.CreateDate
  571. list[i].PublishDate = article.PublishDate
  572. list[i].Body = bodySub
  573. list[i].Abstract = article.Abstract
  574. list[i].CategoryName = article.CategoryName
  575. list[i].SubCategoryName = article.SubCategoryName
  576. list[i].ExpertBackground = article.ExpertBackground
  577. list[i].ExpertNumber = article.ExpertNumber
  578. }
  579. page := paging.GetPaging(currentIndex, pageSize, total)
  580. resp := new(models.ArticleInterviewApplyListResp)
  581. resp.List = list
  582. resp.Paging = page
  583. br.Msg = "获取成功!"
  584. br.Ret = 200
  585. br.Success = true
  586. br.Data = resp
  587. }
  588. // @Title 获取浏览历史列表
  589. // @Description 获取浏览历史列表
  590. // @Param PageSize query int true "PageSize"
  591. // @Param CurrentIndex query int true "CurrentIndex"
  592. // @Success 200 {object} models.ArticleBrowseHistoryListResp
  593. // @router /browse/history/list [get]
  594. func (this *UserController) BrowseHistoryList() {
  595. br := new(models.BaseResponse).Init()
  596. defer func() {
  597. this.Data["json"] = br
  598. this.ServeJSON()
  599. }()
  600. userId := this.User.UserId
  601. var pageSize, currentIndex, startSize int
  602. pageSize, _ = this.GetInt("PageSize")
  603. currentIndex, _ = this.GetInt("CurrentIndex")
  604. if pageSize <= 0 {
  605. pageSize = utils.PageSize20
  606. }
  607. if currentIndex <= 0 {
  608. currentIndex = 1
  609. }
  610. startSize = utils.StartIndex(currentIndex, pageSize)
  611. endDate := time.Now().AddDate(0, -1, 0).Format(utils.FormatDate)
  612. total, err := models.GetArticleUserBrowseHistoryCount(userId, endDate)
  613. if err != nil {
  614. br.Msg = "获取数据失败"
  615. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  616. return
  617. }
  618. list, err := models.GetArticleUserBrowseHistoryList(startSize, pageSize, userId, endDate)
  619. if err != nil {
  620. br.Msg = "获取数据失败"
  621. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  622. return
  623. }
  624. resp := new(models.ArticleReportBillboardLIstPageResp)
  625. if len(list) == 0 {
  626. page := paging.GetPaging(currentIndex, pageSize, total)
  627. resp.List = list
  628. resp.Paging = page
  629. br.Msg = "获取成功!"
  630. br.Ret = 200
  631. br.Success = true
  632. br.Data = resp
  633. return
  634. }
  635. var articleIds []string
  636. var condition string
  637. var pars []interface{}
  638. for _, v := range list {
  639. articleIds = append(articleIds, strconv.Itoa(v.ArticleId))
  640. }
  641. articleIdStr := strings.Join(articleIds, ",")
  642. //获取文章关联的产业
  643. pars = make([]interface{}, 0)
  644. condition = ` AND mg.article_id IN ( ` + utils.GetOrmInReplace(len(articleIds)) + ` ) `
  645. pars = append(pars, articleIds)
  646. industrialList, err := models.GetIndustrialListByarticleId(pars, condition)
  647. if err != nil {
  648. br.Msg = "获取失败"
  649. br.ErrMsg = "获取失败,GetSubjectList Err:" + err.Error()
  650. return
  651. }
  652. industrialMap := make(map[int][]*models.IndustrialManagementIdInt)
  653. if len(industrialList) > 0 {
  654. for _, v := range industrialList {
  655. item := new(models.IndustrialManagementIdInt)
  656. item.ArticleId = v.ArticleId
  657. if v.ArticleId > utils.SummaryArticleId {
  658. item.IsResearch = true
  659. }
  660. item.IndustrialManagementId = v.IndustrialManagementId
  661. item.IndustryName = v.IndustryName
  662. industrialMap[v.ArticleId] = append(industrialMap[v.ArticleId], item)
  663. }
  664. }
  665. for k, v := range list {
  666. if len(industrialMap[v.ArticleId]) > 0 {
  667. list[k].List = industrialMap[v.ArticleId]
  668. } else {
  669. list[k].List = make([]*models.IndustrialManagementIdInt, 0)
  670. }
  671. }
  672. articleMap := make(map[int]*models.ArticleDetail)
  673. if articleIdStr != "" {
  674. articleList, err := models.GetArticleDetailByIdStr(articleIdStr)
  675. if err != nil {
  676. br.Msg = "获取数据失败"
  677. br.ErrMsg = "获取报告详情信息失败,Err:" + err.Error()
  678. return
  679. }
  680. for _, v := range articleList {
  681. if _, ok := articleMap[v.ArticleId]; !ok {
  682. articleMap[v.ArticleId] = v
  683. }
  684. }
  685. }
  686. //处理文章PV收藏等数量
  687. mapArticleCollectNum := make(map[int]*models.CygxArticleNum)
  688. if len(articleIds) > 0 {
  689. articleCollectNumList, err := models.GetArticleCollectNum(articleIds, userId)
  690. if err != nil && err.Error() != utils.ErrNoRow() {
  691. br.Msg = "获取失败"
  692. br.ErrMsg = "获取失败,GetArticleCollectNum Err:" + err.Error()
  693. return
  694. }
  695. for _, v := range articleCollectNumList {
  696. mapArticleCollectNum[v.ArticleId] = v
  697. }
  698. }
  699. lenList := len(list)
  700. for i := 0; i < lenList; i++ {
  701. item := list[i]
  702. article := articleMap[item.ArticleId]
  703. if article != nil {
  704. list[i].Title = article.Title
  705. list[i].PublishDate = utils.TimeRemoveHms2(article.PublishDate)
  706. list[i].DepartmentId = article.DepartmentId
  707. list[i].NickName = article.NickName
  708. if article.ArticleId < utils.SummaryArticleId {
  709. list[i].Source = 1
  710. } else {
  711. list[i].Source = 2
  712. }
  713. if mapArticleCollectNum[article.ArticleId] != nil {
  714. list[i].CollectNum = mapArticleCollectNum[article.ArticleId].CollectNum
  715. list[i].Pv = mapArticleCollectNum[article.ArticleId].Pv
  716. list[i].IsCollect = mapArticleCollectNum[article.ArticleId].IsCollect
  717. }
  718. //list[i].TitleEn = article.TitleEn
  719. //list[i].UpdateFrequency = article.UpdateFrequency
  720. //list[i].CreateDate = article.CreateDate
  721. //list[i].Body, _ = services.GetReportContentTextSub(article.Body)
  722. //list[i].Abstract = article.Abstract
  723. //list[i].CategoryName = article.CategoryName
  724. //list[i].SubCategoryName = article.SubCategoryName
  725. }
  726. }
  727. page := paging.GetPaging(currentIndex, pageSize, total)
  728. resp.List = list
  729. resp.Paging = page
  730. br.Msg = "获取成功!"
  731. br.Ret = 200
  732. br.Success = true
  733. br.Data = resp
  734. }
  735. // @Title 未付费申请试用
  736. // @Description 未付费申请试用
  737. // @Param request body models.ApplyTryReq true "type json string"
  738. // @Success 200
  739. // @router /apply/try [post]
  740. func (this *UserController) ApplyTryOut() {
  741. br := new(models.BaseResponse).Init()
  742. defer func() {
  743. this.Data["json"] = br
  744. this.ServeJSON()
  745. }()
  746. user := this.User
  747. if user == nil {
  748. br.Msg = "请登录"
  749. br.ErrMsg = "请登录,SysUser Is Empty"
  750. br.Ret = 408
  751. return
  752. }
  753. mobile := user.Mobile
  754. var req models.ApplyTryReq
  755. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  756. if err != nil {
  757. br.Msg = "参数解析异常!"
  758. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  759. return
  760. }
  761. if req.RealName == "" {
  762. req.RealName = user.RealName
  763. }
  764. if req.CompanyName == "" {
  765. req.CompanyName = user.CompanyName
  766. }
  767. uid := user.UserId
  768. var title string
  769. tryType := req.TryType
  770. detailId := req.DetailId
  771. if tryType == "Article" {
  772. detail, err := models.GetArticleDetailById(detailId)
  773. if err != nil {
  774. br.Msg = "获取信息失败"
  775. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  776. return
  777. }
  778. title = detail.Title
  779. } else if tryType == "Activity" {
  780. detail, err := models.GetAddActivityInfoById(detailId)
  781. if err != nil {
  782. br.Msg = "操作失败"
  783. br.ErrMsg = "活动ID错误,不存在activityId:" + strconv.Itoa(detailId)
  784. return
  785. }
  786. title = detail.ActivityName
  787. } else if tryType == "MicroAudio" {
  788. // 微路演音频
  789. microAudio, e := models.GetCygxActivityVoiceById(detailId)
  790. if e != nil {
  791. br.Msg = "操作失败"
  792. br.ErrMsg = "微路演音频信息有误, 不存在的VoiceId: " + strconv.Itoa(detailId)
  793. return
  794. }
  795. title = microAudio.VoiceName
  796. } else if tryType == "MicroVideo" {
  797. // 微路演视频
  798. microVideo, e := models.GetMicroRoadshowVideoById(detailId)
  799. if e != nil {
  800. br.Msg = "操作失败"
  801. br.ErrMsg = "微路演视频信息有误, 不存在的VideoId: " + strconv.Itoa(detailId)
  802. return
  803. }
  804. title = microVideo.VideoName
  805. }
  806. fmt.Println(title)
  807. //缓存校验
  808. cacheKey := fmt.Sprint("xygx:apply_record:add:", uid)
  809. ttlTime := utils.Rc.GetRedisTTL(cacheKey)
  810. if ttlTime > 0 {
  811. br.Msg = "申请失败,申请过于频繁"
  812. br.ErrMsg = "申请失败,申请过于频繁"
  813. return
  814. }
  815. utils.Rc.SetNX(cacheKey, user.Mobile, time.Second*10)
  816. //判断是否已经申请过
  817. applyCount, err := models.GetApplyRecordCount(uid)
  818. if err != nil && err.Error() != utils.ErrNoRow() {
  819. br.Msg = "获取信息失败"
  820. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  821. return
  822. }
  823. if applyCount > 0 {
  824. br.Msg = "您已提交申请,请耐心等待。"
  825. br.IsSendEmail = false
  826. return
  827. }
  828. //判断是否存在申请
  829. var sellerMobile string
  830. if req.ApplyMethod == 2 {
  831. if req.BusinessCardUrl == "" {
  832. br.Msg = "请上传名片"
  833. return
  834. }
  835. if req.RealName == "" {
  836. br.Msg = "请输入姓名"
  837. return
  838. }
  839. if req.CompanyName == "" {
  840. br.Msg = "请输入公司名称"
  841. return
  842. }
  843. if req.BusinessCardUrl != "" && utils.RunMode == "release" {
  844. card, err := services.GetBusinessCard(req.BusinessCardUrl)
  845. if err != nil {
  846. br.Msg = "名片识别失败"
  847. br.ErrMsg = "名片识别失败,Err:" + err.Error()
  848. return
  849. }
  850. mobileStr := strings.Join(card.WordsResult.MOBILE, ",")
  851. isFlag := true
  852. if mobile != "" {
  853. if strings.Contains(mobileStr, mobile) || mobileStr == "" {
  854. isFlag = true
  855. } else {
  856. isFlag = false
  857. }
  858. }
  859. if !isFlag {
  860. //阿里云识别
  861. if utils.RunMode == "release" {
  862. aliyunResult, err := services.AliyunBusinessCard(req.BusinessCardUrl)
  863. if err != nil {
  864. br.Msg = "识别失败"
  865. br.ErrMsg = "识别失败,Err:" + err.Error()
  866. return
  867. }
  868. if !aliyunResult.Success {
  869. br.Msg = "识别失败"
  870. br.ErrMsg = "识别失败"
  871. return
  872. }
  873. mobileStr := strings.Join(aliyunResult.TelCell, ",")
  874. if mobile != "" {
  875. if strings.Contains(mobileStr, mobile) {
  876. isFlag = true
  877. } else {
  878. isFlag = false
  879. }
  880. }
  881. }
  882. }
  883. if !isFlag {
  884. br.Msg = "名片手机号与所填手机号不匹配,请重新填写"
  885. br.ErrMsg = "mobile:" + mobile
  886. return
  887. }
  888. }
  889. }
  890. //获取销售信息
  891. sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  892. if err != nil && err.Error() != utils.ErrNoRow() {
  893. br.Msg = "申请失败"
  894. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  895. return
  896. }
  897. if sellerItem != nil {
  898. sellerMobile = sellerItem.Mobile
  899. //推送模板消息
  900. mobile := user.Mobile
  901. if mobile == "" {
  902. mobile = user.Email
  903. }
  904. }
  905. //用户状态,1:潜在客户 、2:现有客户 、3:FICC客户 、4:现有客户(正式,无对应权限) 、5:现有客户(试用,无对应权限) 、6:现有客户(试用暂停) 、7:现有客户(冻结) 、8:现有客户(流失)?
  906. CompanyIdType := 1
  907. applyMethod := ""
  908. cnf, _ := models.GetConfigByCode("tpl_msg")
  909. if cnf != nil {
  910. if sellerItem != nil {
  911. cnf.ConfigValue = sellerItem.Mobile
  912. companyItem, err := models.GetCompanyDetailById(user.CompanyId)
  913. if err != nil && err.Error() != utils.ErrNoRow() {
  914. br.Msg = "获取信息失败"
  915. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  916. return
  917. }
  918. if companyItem != nil && companyItem.CompanyId > 0 {
  919. companyProduct, err := models.GetCompanyProductDetail(user.CompanyId, 2)
  920. if err != nil && err.Error() != utils.ErrNoRow() {
  921. br.Msg = "获取信息失败"
  922. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  923. return
  924. }
  925. if companyProduct != nil && companyProduct.IsSuspend == 1 {
  926. CompanyIdType = 6
  927. } else {
  928. switch companyItem.Status {
  929. case "正式":
  930. CompanyIdType = 4
  931. case "试用":
  932. CompanyIdType = 5
  933. case "冻结":
  934. CompanyIdType = 7
  935. case "流失":
  936. CompanyIdType = 8
  937. }
  938. }
  939. applyMethod = companyItem.Status + "客户申请"
  940. if detailId > 0 {
  941. if companyProduct != nil && companyProduct.IsSuspend == 1 {
  942. applyMethod = "试用暂停客户"
  943. } else {
  944. if companyItem.Status == "正式" || companyItem.Status == "试用" {
  945. applyMethod = companyItem.Status + "客户申请,无对应权限"
  946. } else if companyItem.Status == "冻结" || companyItem.Status == "流失" {
  947. applyMethod = companyItem.Status + "客户"
  948. }
  949. }
  950. applyMethod = applyMethod + "," + title
  951. }
  952. }
  953. } else {
  954. //获取销售信息
  955. sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 1)
  956. if err != nil && err.Error() != utils.ErrNoRow() {
  957. br.Msg = "申请失败"
  958. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  959. return
  960. }
  961. if sellerItem != nil {
  962. CompanyIdType = 3
  963. applyMethod = "FICC客户"
  964. } else {
  965. CompanyIdType = 1
  966. applyMethod = "潜在客户"
  967. }
  968. if detailId > 0 {
  969. applyMethod = applyMethod + "," + title
  970. }
  971. }
  972. openIpItem, _ := models.GetUserRecordByMobile(4, cnf.ConfigValue)
  973. if openIpItem != nil && openIpItem.OpenId != "" {
  974. if req.ApplyMethod != 2 {
  975. req.RealName = user.RealName
  976. req.CompanyName = user.CompanyName
  977. }
  978. utils.FileLog.Info("推送消息 %s %s,%s,%s,%s", req.RealName, req.CompanyName, mobile, openIpItem.OpenId, applyMethod)
  979. go services.SendPermissionApplyTemplateMsg(req.RealName, req.CompanyName, mobile, applyMethod, openIpItem)
  980. }
  981. }
  982. err = models.AddApplyRecord(&req, user.Mobile, user.CompanyName, uid, user.CompanyId, CompanyIdType)
  983. if err != nil {
  984. br.Msg = "申请失败"
  985. br.ErrMsg = "申请失败,Err:" + err.Error()
  986. return
  987. }
  988. //添加成功后,设置5分钟缓存,不允许重复添加
  989. //utils.Rc.SetNX(cacheKey, user.Mobile, time.Second*60)
  990. br.Msg = "申请成功!"
  991. br.Ret = 200
  992. br.Success = true
  993. br.Data = sellerMobile
  994. }
  995. // @Title 是否需要填写区号
  996. // @Description 获取是否需要填写区号接口
  997. // @Success 200 {object} models.CountryCode
  998. // @router /countryCcode/isNeedAdd [get]
  999. func (this *UserController) CountryCcode() {
  1000. br := new(models.BaseResponse).Init()
  1001. defer func() {
  1002. this.Data["json"] = br
  1003. this.ServeJSON()
  1004. }()
  1005. user := this.User
  1006. uid := user.UserId
  1007. if user == nil {
  1008. br.Msg = "请登录"
  1009. br.ErrMsg = "请登录,用户信息为空"
  1010. br.Ret = 408
  1011. return
  1012. }
  1013. //if uid == 0 {
  1014. // br.Msg = "请登录"
  1015. // br.ErrMsg = "请登录,用户信息为空"
  1016. // br.Ret = 408
  1017. // return
  1018. //}
  1019. resp := new(models.CountryCode)
  1020. if user.CountryCode == "" && len(user.Mobile) >= 11 {
  1021. err := models.ChangeUserOutboundMobileByMobile(uid)
  1022. if err != nil {
  1023. br.Msg = "操作失败"
  1024. br.ErrMsg = "操作失败,Err:" + err.Error()
  1025. return
  1026. }
  1027. }
  1028. if user.CountryCode == "" && user.Mobile != "" && len(user.Mobile) < 11 {
  1029. resp.IsNeedAddCountryCode = true
  1030. }
  1031. if user.OutboundMobile != "" {
  1032. resp.IsNeedAddCountryCode = false
  1033. }
  1034. br.Ret = 200
  1035. br.Success = true
  1036. br.Msg = "获取成功"
  1037. br.Data = resp
  1038. }
  1039. // @Title 上传用户区号
  1040. // @Description 上传用户区号接口
  1041. // @Param request body models.CountryCodeItem true "type json string"
  1042. // @Success Ret=200 新增成功
  1043. // @router /countryCcode/Add [POST]
  1044. func (this *UserController) AddCountryCcode() {
  1045. br := new(models.BaseResponse).Init()
  1046. defer func() {
  1047. this.Data["json"] = br
  1048. this.ServeJSON()
  1049. }()
  1050. user := this.User
  1051. if user == nil {
  1052. br.Msg = "请登录"
  1053. br.ErrMsg = "请登录,用户信息为空"
  1054. br.Ret = 408
  1055. return
  1056. }
  1057. var req models.CountryCodeItem
  1058. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1059. if err != nil {
  1060. br.Msg = "参数解析异常!"
  1061. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1062. return
  1063. }
  1064. err = models.AddCountryCode(req.CountryCode, user)
  1065. if err != nil {
  1066. br.Msg = "获取信息失败"
  1067. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  1068. return
  1069. }
  1070. br.Ret = 200
  1071. br.Success = true
  1072. br.Msg = "新增成功"
  1073. }
  1074. // @Title 用户修改外呼手机号以及区号
  1075. // @Description 用户修改外呼手机号以及区号接口
  1076. // @Param request body models.OutboundMobileItem true "type json string"
  1077. // @Success Ret=200 操作成功
  1078. // @router /countryCcode/addOutboundMobile [POST]
  1079. func (this *UserController) AddOutboundMobile() {
  1080. br := new(models.BaseResponse).Init()
  1081. defer func() {
  1082. this.Data["json"] = br
  1083. this.ServeJSON()
  1084. }()
  1085. user := this.User
  1086. uid := user.UserId
  1087. if user == nil {
  1088. br.Msg = "请登录"
  1089. br.ErrMsg = "请登录,用户信息为空"
  1090. br.Ret = 408
  1091. return
  1092. }
  1093. var req models.OutboundMobileItem
  1094. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1095. if err != nil {
  1096. br.Msg = "参数解析异常!"
  1097. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1098. return
  1099. }
  1100. if !utils.ValidateFixedTelephoneFormatatEasy(req.OutboundMobile) {
  1101. br.Msg = "号码格式有误,请重新填写!"
  1102. br.ErrMsg = "号码格式有误,请重新填写" + req.OutboundMobile
  1103. return
  1104. }
  1105. if req.OutboundMobile == "" {
  1106. br.Msg = "请填写区号!"
  1107. return
  1108. }
  1109. item := new(models.OutboundMobileItem)
  1110. item.OutboundMobile = req.OutboundMobile
  1111. item.OutboundCountryCode = req.OutboundCountryCode
  1112. item.ActivityId = req.ActivityId
  1113. if req.ActivityId == 0 {
  1114. err = models.AddOutboundMobile(item, uid)
  1115. } else {
  1116. if user.Mobile == "" && user.OutboundMobile == "" {
  1117. items := new(models.CygxActivitySignup)
  1118. items.UserId = uid
  1119. items.ActivityId = req.ActivityId
  1120. items.CreateTime = time.Now()
  1121. items.Mobile = user.Mobile
  1122. items.Email = user.Email
  1123. items.CompanyId = user.CompanyId
  1124. items.CompanyName = user.CompanyName
  1125. items.SignupType = 1
  1126. items.FailType = 0
  1127. items.DoFailType = 0
  1128. items.OutboundMobile = req.OutboundMobile
  1129. items.CountryCode = req.OutboundCountryCode
  1130. _, err = models.AddActivitySignupFromEmail(items)
  1131. } else {
  1132. total, err := models.GetActivityCountByIdWithUid(item.ActivityId, uid)
  1133. if total == 0 {
  1134. br.Msg = "报名信息不存在"
  1135. br.ErrMsg = "报名信息不存在,Err:" + "活动ActivityId:" + strconv.Itoa(item.ActivityId) + "用户Uid:" + strconv.Itoa(uid)
  1136. return
  1137. }
  1138. if err != nil {
  1139. br.Msg = "操作失败"
  1140. br.ErrMsg = "操作失败,Err:" + err.Error()
  1141. return
  1142. }
  1143. err = models.AddOutboundMobile(item, uid)
  1144. }
  1145. }
  1146. if err != nil {
  1147. br.Msg = "操作失败"
  1148. br.ErrMsg = "操作失败,Err:" + err.Error()
  1149. return
  1150. }
  1151. br.Ret = 200
  1152. br.Success = true
  1153. br.Msg = "操作成功"
  1154. }
  1155. // @Title 获取我的提问
  1156. // @Description 获取我的提问列表
  1157. // @Success 200 {object} models.CygxAskListResp
  1158. // @router /ask/list [get]
  1159. func (this *UserController) AskList() {
  1160. br := new(models.BaseResponse).Init()
  1161. defer func() {
  1162. this.Data["json"] = br
  1163. this.ServeJSON()
  1164. }()
  1165. user := this.User
  1166. if user == nil {
  1167. br.Msg = "请登录"
  1168. br.ErrMsg = "请登录,用户信息为空"
  1169. br.Ret = 408
  1170. return
  1171. }
  1172. userId := this.User.UserId
  1173. listActcivity, err := models.GetActivityAskList(userId)
  1174. if err != nil && err.Error() != utils.ErrNoRow() {
  1175. br.Msg = "获取失败"
  1176. br.ErrMsg = "获取活动问题失败,Err:" + err.Error()
  1177. return
  1178. }
  1179. for _, v := range listActcivity {
  1180. v.AskType = "Activity"
  1181. }
  1182. listArticle, err := models.GetArticleAskList(userId)
  1183. if err != nil && err.Error() != utils.ErrNoRow() {
  1184. br.Msg = "获取失败"
  1185. br.ErrMsg = "获取文章问题失败,Err:" + err.Error()
  1186. return
  1187. }
  1188. for _, v := range listArticle {
  1189. v.AskType = "Report"
  1190. listActcivity = append(listActcivity, v)
  1191. }
  1192. resp := new(models.CygxAskListResp)
  1193. resp.List = listActcivity
  1194. br.Msg = "获取成功!"
  1195. br.Ret = 200
  1196. br.Success = true
  1197. br.Data = resp
  1198. }
  1199. // @Title 是否展示免费试用按钮
  1200. // @Description 获取是否展示免费试用按钮接口
  1201. // @Param request body models.IsShow true "type json string"
  1202. // @Success 200
  1203. // @router /isShow/freeButton [get]
  1204. func (this *UserController) IsShow() {
  1205. br := new(models.BaseResponse).Init()
  1206. defer func() {
  1207. this.Data["json"] = br
  1208. this.ServeJSON()
  1209. }()
  1210. user := this.User
  1211. if user == nil {
  1212. br.Msg = "请重新登录"
  1213. br.Ret = 408
  1214. return
  1215. }
  1216. var resp models.IsShow
  1217. detail, err := models.GetConfigByCode("free_trial_card")
  1218. if err != nil {
  1219. br.Msg = "获取数据失败"
  1220. br.ErrMsg = "城市配置信息失败,Err:" + err.Error()
  1221. return
  1222. }
  1223. companyDetail, err := models.GetCompanyDetailByIdGroup(user.CompanyId)
  1224. if err != nil && err.Error() != utils.ErrNoRow() {
  1225. br.Msg = "获取数据失败!"
  1226. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  1227. return
  1228. }
  1229. count, err := models.CountCygxUserFreeeButton(user.UserId)
  1230. if err != nil && err.Error() != utils.ErrNoRow() {
  1231. br.Msg = "获取数据失败!"
  1232. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  1233. return
  1234. }
  1235. if companyDetail != nil && companyDetail.IsSuspend == 0 {
  1236. if detail.ConfigValue == "1" && (companyDetail.Status == "正式" || companyDetail.Status == "试用" || companyDetail.Status == "永续") && count == 0 {
  1237. resp.IsShow = true
  1238. }
  1239. }
  1240. br.Ret = 200
  1241. br.Success = true
  1242. br.Data = resp
  1243. }
  1244. // @Title 隐藏当天的按钮
  1245. // @Description 隐藏当天的按钮接口
  1246. // @Success 200
  1247. // @router /freeButton/update [post]
  1248. func (this *UserController) FreeButtonUpdate() {
  1249. br := new(models.BaseResponse).Init()
  1250. defer func() {
  1251. this.Data["json"] = br
  1252. this.ServeJSON()
  1253. }()
  1254. user := this.User
  1255. if user == nil {
  1256. br.Msg = "请重新登录"
  1257. br.Ret = 408
  1258. return
  1259. }
  1260. count, err := models.CountCygxUserFreeeButtonByUser(user.UserId)
  1261. if err != nil {
  1262. br.Msg = "获取数据失败!"
  1263. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  1264. return
  1265. }
  1266. if count == 0 {
  1267. item := new(models.CygxUserFreeeButton)
  1268. item.UserId = user.UserId
  1269. item.CompanyId = user.CompanyId
  1270. item.CreateTime = time.Now()
  1271. item.ModifyTime = time.Now()
  1272. item.EffectiveTime = time.Now().Format(utils.FormatDate)
  1273. _, err := models.AddCygxUserFreeeButton(item)
  1274. if err != nil {
  1275. br.Msg = "操作失败!"
  1276. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  1277. return
  1278. }
  1279. } else {
  1280. err := models.UpdateCygxUserFreeeButton(user.UserId)
  1281. if err != nil {
  1282. br.Msg = "操作失败!"
  1283. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  1284. return
  1285. }
  1286. }
  1287. br.Ret = 200
  1288. br.Success = true
  1289. br.Msg = "操作成功!"
  1290. }
  1291. // @Title 权限弹窗是否展示免费月卡
  1292. // @Description 获取权限弹窗是否展示免费月卡接口
  1293. // @Param request body models.IsShow true "type json string"
  1294. // @Success 200
  1295. // @router /isShow/alert [get]
  1296. func (this *UserController) AlertIsShow() {
  1297. br := new(models.BaseResponse).Init()
  1298. defer func() {
  1299. this.Data["json"] = br
  1300. this.ServeJSON()
  1301. }()
  1302. user := this.User
  1303. if user == nil {
  1304. br.Msg = "请重新登录"
  1305. br.Ret = 408
  1306. return
  1307. }
  1308. var resp models.IsShow
  1309. detail, err := models.GetConfigByCode("free_trial_card")
  1310. if err != nil {
  1311. br.Msg = "获取数据失败"
  1312. br.ErrMsg = "城市配置信息失败,Err:" + err.Error()
  1313. return
  1314. }
  1315. if user.CompanyId == 1 && detail.ConfigValue == "1" {
  1316. resp.IsShow = true
  1317. }
  1318. br.Ret = 200
  1319. br.Success = true
  1320. br.Data = resp
  1321. }
  1322. // @Title 分享的时候是否展示免费月卡
  1323. // @Description 获取权限弹窗是否展示免费月卡接口
  1324. // @Param request body models.IsShow true "type json string"
  1325. // @Success 200
  1326. // @router /isShow/share [get]
  1327. func (this *UserController) ShareIsShow() {
  1328. br := new(models.BaseResponse).Init()
  1329. defer func() {
  1330. this.Data["json"] = br
  1331. this.ServeJSON()
  1332. }()
  1333. user := this.User
  1334. if user == nil {
  1335. br.Msg = "请重新登录"
  1336. br.Ret = 408
  1337. return
  1338. }
  1339. var resp models.IsShow
  1340. detail, err := models.GetConfigByCode("free_trial_card")
  1341. if err != nil {
  1342. br.Msg = "获取数据失败"
  1343. br.ErrMsg = "城市配置信息失败,Err:" + err.Error()
  1344. return
  1345. }
  1346. if user.CompanyId != 16 && detail.ConfigValue == "1" {
  1347. resp.IsShow = true
  1348. }
  1349. resp.LinkWxExplain = utils.LINK_WX_EXPLAIN
  1350. br.Ret = 200
  1351. br.Success = true
  1352. br.Data = resp
  1353. }
  1354. // @Title 更改用户微信头像
  1355. // @Description 更改用户微信头像
  1356. // @Param request body models.Headimgurl true "type json string"
  1357. // @Success 200 {object} models.ArticleDetailFileLink
  1358. // @router /headimgurl/update [post]
  1359. func (this *UserController) HeadimgurlUpdate() {
  1360. br := new(models.BaseResponse).Init()
  1361. defer func() {
  1362. this.Data["json"] = br
  1363. this.ServeJSON()
  1364. }()
  1365. user := this.User
  1366. if user == nil {
  1367. br.Msg = "请登录"
  1368. br.ErrMsg = "请登录,用户信息为空"
  1369. br.Ret = 408
  1370. return
  1371. }
  1372. var req models.Headimgurl
  1373. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1374. if err != nil {
  1375. br.Msg = "参数解析异常!"
  1376. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1377. return
  1378. }
  1379. uid := user.UserId
  1380. headimgurl := req.Headimgurl
  1381. if headimgurl == "" {
  1382. br.Msg = "操作失败"
  1383. br.ErrMsg = "头像信息不能为空"
  1384. return
  1385. }
  1386. err = models.UpdateUserHeadimgurl(headimgurl, uid)
  1387. if err != nil {
  1388. br.Msg = "操作失败"
  1389. br.ErrMsg = "头像信息不能为空"
  1390. }
  1391. br.Ret = 200
  1392. br.Success = true
  1393. br.Msg = "操作成功"
  1394. }
  1395. // @Title 登录 (无需token)
  1396. // @Description 登录接口 (无需token)
  1397. // @Param request body models.LoginReq true "type json string"
  1398. // @Success 200 {object} models.LoginResp
  1399. // @router /loginPublic [post]
  1400. func (this *UserCommonController) LoginPublic() {
  1401. br := new(models.BaseResponse).Init()
  1402. defer func() {
  1403. this.Data["json"] = br
  1404. this.ServeJSON()
  1405. }()
  1406. var req models.LoginReq
  1407. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1408. if err != nil {
  1409. br.Msg = "参数解析异常!"
  1410. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1411. return
  1412. }
  1413. mobile := strings.Trim(req.Mobile, " ")
  1414. if req.Mobile == "" {
  1415. br.Msg = "参数错误"
  1416. br.ErrMsg = "参数错误,手机号为空 为空"
  1417. return
  1418. }
  1419. item, err := models.GetMsgCode(req.Mobile, req.VCode)
  1420. if err != nil {
  1421. if err.Error() == utils.ErrNoRow() {
  1422. br.Msg = "验证码错误,请重新输入"
  1423. br.ErrMsg = "校验验证码失败,Err:" + err.Error()
  1424. return
  1425. } else {
  1426. br.Msg = "验证码错误,请重新输入"
  1427. br.ErrMsg = "校验验证码失败,Err:" + err.Error()
  1428. return
  1429. }
  1430. }
  1431. if item == nil {
  1432. br.Msg = "验证码错误,请重新输入"
  1433. return
  1434. }
  1435. if len(req.Mobile) >= 11 && req.CountryCode == "" {
  1436. req.CountryCode = "86"
  1437. }
  1438. var token string
  1439. tokenItem, err := models.GetSessionMobileTokenByOpenId(mobile)
  1440. if err != nil && err.Error() != utils.ErrNoRow() {
  1441. br.Msg = "登录失败"
  1442. br.ErrMsg = "登录失败,获取token失败:" + err.Error()
  1443. return
  1444. }
  1445. if tokenItem == nil || (err != nil && err.Error() == utils.ErrNoRow()) {
  1446. timeUnix := time.Now().Unix()
  1447. timeUnixStr := strconv.FormatInt(timeUnix, 10)
  1448. token = utils.MD5(mobile) + utils.MD5(timeUnixStr)
  1449. //新增session
  1450. {
  1451. session := new(models.CygxSessionMobile)
  1452. session.Mobile = mobile
  1453. session.CreatedTime = time.Now()
  1454. session.LastUpdatedTime = time.Now()
  1455. session.ExpireTime = time.Now().AddDate(0, 1, 0)
  1456. session.AccessToken = token
  1457. err = models.AddCygxSessionMobile(session)
  1458. if err != nil {
  1459. br.Msg = "登录失败"
  1460. br.ErrMsg = "登录失败,新增用户session信息失败:" + err.Error()
  1461. return
  1462. }
  1463. }
  1464. } else {
  1465. token = tokenItem.AccessToken
  1466. }
  1467. resp := new(models.LoginResp)
  1468. resp.Authorization = token
  1469. br.Ret = 200
  1470. br.Success = true
  1471. br.Data = resp
  1472. br.Msg = "登录成功"
  1473. }
  1474. // @Title 获取我的留言
  1475. // @Description 获取我的留言列表
  1476. // @Param CommentType query int true "留言种类,1报告 2微路演"
  1477. // @Success 200 {object} models.CygxCommentListResp
  1478. // @router /comment/list [get]
  1479. func (this *UserController) CommnetList() {
  1480. br := new(models.BaseResponse).Init()
  1481. defer func() {
  1482. this.Data["json"] = br
  1483. this.ServeJSON()
  1484. }()
  1485. user := this.User
  1486. if user == nil {
  1487. br.Msg = "请登录"
  1488. br.ErrMsg = "请登录,用户信息为空"
  1489. br.Ret = 408
  1490. return
  1491. }
  1492. commentType, _ := this.GetInt("CommentType", 1)
  1493. userId := this.User.UserId
  1494. commentlist, err := models.GetCommentList(userId, commentType)
  1495. if err != nil && err.Error() != utils.ErrNoRow() {
  1496. br.Msg = "获取失败"
  1497. br.ErrMsg = "获取我的留言列表失败,Err:" + err.Error()
  1498. return
  1499. }
  1500. resp := new(models.CygxCommentListResp)
  1501. for _, comment := range commentlist {
  1502. item := models.CygxArticleCommentResp{
  1503. Id: comment.Id,
  1504. UserId: comment.UserId,
  1505. ArticleId: comment.ArticleId,
  1506. IndustryId: comment.IndustryId,
  1507. ActivityId: comment.ActivityId,
  1508. CreateTime: comment.CreateTime,
  1509. Mobile: comment.Mobile,
  1510. Email: comment.Email,
  1511. CompanyId: comment.CompanyId,
  1512. CompanyName: comment.CompanyName,
  1513. Content: comment.Content,
  1514. Title: comment.Title,
  1515. }
  1516. if comment.ArticleId > 0 {
  1517. item.RedirectType = 1
  1518. } else if comment.IndustryId > 0{
  1519. item.RedirectType = 2
  1520. }else if comment.ActivityId > 0 {
  1521. item.RedirectType = 3
  1522. }
  1523. resp.List = append(resp.List, &item)
  1524. }
  1525. br.Msg = "获取成功!"
  1526. br.Ret = 200
  1527. br.Success = true
  1528. br.Data = resp
  1529. }
  1530. // @Title 获取我的收藏
  1531. // @Description 获取我的收藏列表
  1532. // @Success 200 {object} models.ArticleCollectListResp
  1533. // @router /collect/list/microRoadshow [get]
  1534. func (this *UserController) MicroRoadshowCollectList() {
  1535. br := new(models.BaseResponse).Init()
  1536. defer func() {
  1537. this.Data["json"] = br
  1538. this.ServeJSON()
  1539. }()
  1540. userId := this.User.UserId
  1541. list, err := models.GetUserMicroRoadshowCollectList(userId)
  1542. if err != nil {
  1543. br.Msg = "获取数据失败"
  1544. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1545. return
  1546. }
  1547. resp := new(models.MicroRoadshowCollectList)
  1548. var audioIds []string
  1549. var videoIds []string
  1550. for _, item := range list {
  1551. if item.ActivityVoiceId > 0 {
  1552. audioIds = append(audioIds, strconv.Itoa(item.ActivityVoiceId))
  1553. } else if item.VideoId > 0 {
  1554. videoIds = append(videoIds, strconv.Itoa(item.VideoId))
  1555. }
  1556. }
  1557. resp.AudioIds = strings.Join(audioIds, ",")
  1558. resp.VideoIds = strings.Join(videoIds, ",")
  1559. br.Msg = "获取成功!"
  1560. br.Ret = 200
  1561. br.Success = true
  1562. br.Data = resp
  1563. }