user.go 49 KB

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