user.go 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723
  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. }
  855. fmt.Println(title)
  856. //缓存校验
  857. cacheKey := fmt.Sprint("xygx:apply_record:add:", uid)
  858. ttlTime := utils.Rc.GetRedisTTL(cacheKey)
  859. if ttlTime > 0 {
  860. br.Msg = "申请失败,申请过于频繁"
  861. br.ErrMsg = "申请失败,申请过于频繁"
  862. return
  863. }
  864. utils.Rc.SetNX(cacheKey, user.Mobile, time.Second*10)
  865. //判断是否已经申请过
  866. applyCount, err := models.GetApplyRecordCount(uid)
  867. if err != nil && err.Error() != utils.ErrNoRow() {
  868. br.Msg = "获取信息失败"
  869. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  870. return
  871. }
  872. if applyCount > 0 {
  873. br.Msg = "您已提交申请,请耐心等待。"
  874. br.IsSendEmail = false
  875. return
  876. }
  877. //判断是否存在申请
  878. var sellerMobile string
  879. if req.ApplyMethod == 2 {
  880. if req.BusinessCardUrl == "" {
  881. br.Msg = "请上传名片"
  882. return
  883. }
  884. if req.RealName == "" {
  885. br.Msg = "请输入姓名"
  886. return
  887. }
  888. if req.CompanyName == "" {
  889. br.Msg = "请输入公司名称"
  890. return
  891. }
  892. if req.BusinessCardUrl != "" && utils.RunMode == "release" {
  893. card, err := services.GetBusinessCard(req.BusinessCardUrl)
  894. if err != nil {
  895. br.Msg = "名片识别失败"
  896. br.ErrMsg = "名片识别失败,Err:" + err.Error()
  897. return
  898. }
  899. mobileStr := strings.Join(card.WordsResult.MOBILE, ",")
  900. isFlag := true
  901. if mobile != "" {
  902. if strings.Contains(mobileStr, mobile) || mobileStr == "" {
  903. isFlag = true
  904. } else {
  905. isFlag = false
  906. }
  907. }
  908. if !isFlag {
  909. //阿里云识别
  910. if utils.RunMode == "release" {
  911. aliyunResult, err := services.AliyunBusinessCard(req.BusinessCardUrl)
  912. if err != nil {
  913. br.Msg = "识别失败"
  914. br.ErrMsg = "识别失败,Err:" + err.Error()
  915. return
  916. }
  917. if !aliyunResult.Success {
  918. br.Msg = "识别失败"
  919. br.ErrMsg = "识别失败"
  920. return
  921. }
  922. mobileStr := strings.Join(aliyunResult.TelCell, ",")
  923. if mobile != "" {
  924. if strings.Contains(mobileStr, mobile) {
  925. isFlag = true
  926. } else {
  927. isFlag = false
  928. }
  929. }
  930. }
  931. }
  932. if !isFlag {
  933. br.Msg = "名片手机号与所填手机号不匹配,请重新填写"
  934. br.ErrMsg = "mobile:" + mobile
  935. return
  936. }
  937. }
  938. }
  939. //获取销售信息
  940. sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  941. if err != nil && err.Error() != utils.ErrNoRow() {
  942. br.Msg = "申请失败"
  943. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  944. return
  945. }
  946. if sellerItem != nil {
  947. sellerMobile = sellerItem.Mobile
  948. //推送模板消息
  949. mobile := user.Mobile
  950. if mobile == "" {
  951. mobile = user.Email
  952. }
  953. }
  954. //用户状态,1:潜在客户 、2:现有客户 、3:FICC客户 、4:现有客户(正式,无对应权限) 、5:现有客户(试用,无对应权限) 、6:现有客户(试用暂停) 、7:现有客户(冻结) 、8:现有客户(流失)?
  955. CompanyIdType := 1
  956. applyMethod := ""
  957. cnf, _ := models.GetConfigByCode("tpl_msg")
  958. if cnf != nil {
  959. if sellerItem != nil {
  960. cnf.ConfigValue = sellerItem.Mobile
  961. companyItem, err := models.GetCompanyDetailById(user.CompanyId)
  962. if err != nil && err.Error() != utils.ErrNoRow() {
  963. br.Msg = "获取信息失败"
  964. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  965. return
  966. }
  967. if companyItem != nil && companyItem.CompanyId > 0 {
  968. companyProduct, err := models.GetCompanyProductDetail(user.CompanyId, 2)
  969. if err != nil && err.Error() != utils.ErrNoRow() {
  970. br.Msg = "获取信息失败"
  971. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  972. return
  973. }
  974. if companyProduct != nil && companyProduct.IsSuspend == 1 {
  975. CompanyIdType = 6
  976. } else {
  977. switch companyItem.Status {
  978. case "正式":
  979. CompanyIdType = 4
  980. case "试用":
  981. CompanyIdType = 5
  982. case "冻结":
  983. CompanyIdType = 7
  984. case "流失":
  985. CompanyIdType = 8
  986. }
  987. }
  988. applyMethod = companyItem.Status + "客户申请"
  989. if detailId > 0 {
  990. if companyProduct != nil && companyProduct.IsSuspend == 1 {
  991. applyMethod = "试用暂停客户"
  992. } else {
  993. if companyItem.Status == "正式" || companyItem.Status == "试用" {
  994. applyMethod = companyItem.Status + "客户申请,无对应权限"
  995. } else if companyItem.Status == "冻结" || companyItem.Status == "流失" {
  996. applyMethod = companyItem.Status + "客户"
  997. }
  998. }
  999. applyMethod = applyMethod + "," + title
  1000. }
  1001. }
  1002. } else {
  1003. //获取销售信息
  1004. sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 1)
  1005. if err != nil && err.Error() != utils.ErrNoRow() {
  1006. br.Msg = "申请失败"
  1007. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  1008. return
  1009. }
  1010. if sellerItem != nil {
  1011. CompanyIdType = 3
  1012. applyMethod = "FICC客户"
  1013. } else {
  1014. CompanyIdType = 1
  1015. applyMethod = "潜在客户"
  1016. }
  1017. if detailId > 0 {
  1018. applyMethod = applyMethod + "," + title
  1019. }
  1020. }
  1021. openIpItem, _ := models.GetUserRecordByMobile(4, cnf.ConfigValue)
  1022. if openIpItem != nil && openIpItem.OpenId != "" {
  1023. if req.ApplyMethod != 2 {
  1024. req.RealName = user.RealName
  1025. req.CompanyName = user.CompanyName
  1026. }
  1027. utils.FileLog.Info("推送消息 %s %s,%s,%s,%s", req.RealName, req.CompanyName, mobile, openIpItem.OpenId, applyMethod)
  1028. go services.SendPermissionApplyTemplateMsg(req.RealName, req.CompanyName, mobile, applyMethod, openIpItem)
  1029. }
  1030. }
  1031. err = models.AddApplyRecord(&req, user.Mobile, user.CompanyName, uid, user.CompanyId, CompanyIdType)
  1032. if err != nil {
  1033. br.Msg = "申请失败"
  1034. br.ErrMsg = "申请失败,Err:" + err.Error()
  1035. return
  1036. }
  1037. //添加成功后,设置5分钟缓存,不允许重复添加
  1038. //utils.Rc.SetNX(cacheKey, user.Mobile, time.Second*60)
  1039. br.Msg = "申请成功!"
  1040. br.Ret = 200
  1041. br.Success = true
  1042. br.Data = sellerMobile
  1043. }
  1044. // @Title 是否需要填写区号
  1045. // @Description 获取是否需要填写区号接口
  1046. // @Success 200 {object} models.CountryCode
  1047. // @router /countryCcode/isNeedAdd [get]
  1048. func (this *UserController) CountryCcode() {
  1049. br := new(models.BaseResponse).Init()
  1050. defer func() {
  1051. this.Data["json"] = br
  1052. this.ServeJSON()
  1053. }()
  1054. user := this.User
  1055. uid := user.UserId
  1056. if user == nil {
  1057. br.Msg = "请登录"
  1058. br.ErrMsg = "请登录,用户信息为空"
  1059. br.Ret = 408
  1060. return
  1061. }
  1062. //if uid == 0 {
  1063. // br.Msg = "请登录"
  1064. // br.ErrMsg = "请登录,用户信息为空"
  1065. // br.Ret = 408
  1066. // return
  1067. //}
  1068. resp := new(models.CountryCode)
  1069. if user.CountryCode == "" && len(user.Mobile) >= 11 {
  1070. err := models.ChangeUserOutboundMobileByMobile(uid)
  1071. if err != nil {
  1072. br.Msg = "操作失败"
  1073. br.ErrMsg = "操作失败,Err:" + err.Error()
  1074. return
  1075. }
  1076. }
  1077. if user.CountryCode == "" && user.Mobile != "" && len(user.Mobile) < 11 {
  1078. resp.IsNeedAddCountryCode = true
  1079. }
  1080. if user.OutboundMobile != "" {
  1081. resp.IsNeedAddCountryCode = false
  1082. }
  1083. br.Ret = 200
  1084. br.Success = true
  1085. br.Msg = "获取成功"
  1086. br.Data = resp
  1087. }
  1088. // @Title 上传用户区号
  1089. // @Description 上传用户区号接口
  1090. // @Param request body models.CountryCodeItem true "type json string"
  1091. // @Success Ret=200 新增成功
  1092. // @router /countryCcode/Add [POST]
  1093. func (this *UserController) AddCountryCcode() {
  1094. br := new(models.BaseResponse).Init()
  1095. defer func() {
  1096. this.Data["json"] = br
  1097. this.ServeJSON()
  1098. }()
  1099. user := this.User
  1100. if user == nil {
  1101. br.Msg = "请登录"
  1102. br.ErrMsg = "请登录,用户信息为空"
  1103. br.Ret = 408
  1104. return
  1105. }
  1106. var req models.CountryCodeItem
  1107. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1108. if err != nil {
  1109. br.Msg = "参数解析异常!"
  1110. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1111. return
  1112. }
  1113. err = models.AddCountryCode(req.CountryCode, user)
  1114. if err != nil {
  1115. br.Msg = "获取信息失败"
  1116. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  1117. return
  1118. }
  1119. br.Ret = 200
  1120. br.Success = true
  1121. br.Msg = "新增成功"
  1122. }
  1123. // @Title 用户修改外呼手机号以及区号
  1124. // @Description 用户修改外呼手机号以及区号接口
  1125. // @Param request body models.OutboundMobileItem true "type json string"
  1126. // @Success Ret=200 操作成功
  1127. // @router /countryCcode/addOutboundMobile [POST]
  1128. func (this *UserController) AddOutboundMobile() {
  1129. br := new(models.BaseResponse).Init()
  1130. defer func() {
  1131. this.Data["json"] = br
  1132. this.ServeJSON()
  1133. }()
  1134. user := this.User
  1135. uid := user.UserId
  1136. if user == nil {
  1137. br.Msg = "请登录"
  1138. br.ErrMsg = "请登录,用户信息为空"
  1139. br.Ret = 408
  1140. return
  1141. }
  1142. var req models.OutboundMobileItem
  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. if !utils.ValidateFixedTelephoneFormatatEasy(req.OutboundMobile) {
  1150. br.Msg = "号码格式有误,请重新填写!"
  1151. br.ErrMsg = "号码格式有误,请重新填写" + req.OutboundMobile
  1152. return
  1153. }
  1154. if req.OutboundMobile == "" {
  1155. br.Msg = "请填写区号!"
  1156. return
  1157. }
  1158. item := new(models.OutboundMobileItem)
  1159. item.OutboundMobile = req.OutboundMobile
  1160. item.OutboundCountryCode = req.OutboundCountryCode
  1161. item.ActivityId = req.ActivityId
  1162. if req.ActivityId == 0 {
  1163. err = models.AddOutboundMobile(item, uid)
  1164. } else {
  1165. if user.Mobile == "" && user.OutboundMobile == "" {
  1166. items := new(models.CygxActivitySignup)
  1167. items.UserId = uid
  1168. items.ActivityId = req.ActivityId
  1169. items.CreateTime = time.Now()
  1170. items.Mobile = user.Mobile
  1171. items.Email = user.Email
  1172. items.CompanyId = user.CompanyId
  1173. items.CompanyName = user.CompanyName
  1174. items.SignupType = 1
  1175. items.FailType = 0
  1176. items.DoFailType = 0
  1177. items.OutboundMobile = req.OutboundMobile
  1178. items.CountryCode = req.OutboundCountryCode
  1179. _, err = models.AddActivitySignupFromEmail(items)
  1180. } else {
  1181. total, err := models.GetActivityCountByIdWithUid(item.ActivityId, uid)
  1182. if total == 0 {
  1183. br.Msg = "报名信息不存在"
  1184. br.ErrMsg = "报名信息不存在,Err:" + "活动ActivityId:" + strconv.Itoa(item.ActivityId) + "用户Uid:" + strconv.Itoa(uid)
  1185. return
  1186. }
  1187. if err != nil {
  1188. br.Msg = "操作失败"
  1189. br.ErrMsg = "操作失败,Err:" + err.Error()
  1190. return
  1191. }
  1192. err = models.AddOutboundMobile(item, uid)
  1193. }
  1194. }
  1195. if err != nil {
  1196. br.Msg = "操作失败"
  1197. br.ErrMsg = "操作失败,Err:" + err.Error()
  1198. return
  1199. }
  1200. br.Ret = 200
  1201. br.Success = true
  1202. br.Msg = "操作成功"
  1203. }
  1204. // @Title 获取我的提问
  1205. // @Description 获取我的提问列表
  1206. // @Success 200 {object} models.CygxAskListResp
  1207. // @router /ask/list [get]
  1208. func (this *UserController) AskList() {
  1209. br := new(models.BaseResponse).Init()
  1210. defer func() {
  1211. this.Data["json"] = br
  1212. this.ServeJSON()
  1213. }()
  1214. user := this.User
  1215. if user == nil {
  1216. br.Msg = "请登录"
  1217. br.ErrMsg = "请登录,用户信息为空"
  1218. br.Ret = 408
  1219. return
  1220. }
  1221. userId := this.User.UserId
  1222. listActcivity, err := models.GetActivityAskList(userId)
  1223. if err != nil && err.Error() != utils.ErrNoRow() {
  1224. br.Msg = "获取失败"
  1225. br.ErrMsg = "获取活动问题失败,Err:" + err.Error()
  1226. return
  1227. }
  1228. for _, v := range listActcivity {
  1229. v.AskType = "Activity"
  1230. }
  1231. listArticle, err := models.GetArticleAskList(userId)
  1232. if err != nil && err.Error() != utils.ErrNoRow() {
  1233. br.Msg = "获取失败"
  1234. br.ErrMsg = "获取文章问题失败,Err:" + err.Error()
  1235. return
  1236. }
  1237. for _, v := range listArticle {
  1238. v.AskType = "Report"
  1239. listActcivity = append(listActcivity, v)
  1240. }
  1241. resp := new(models.CygxAskListResp)
  1242. resp.List = listActcivity
  1243. br.Msg = "获取成功!"
  1244. br.Ret = 200
  1245. br.Success = true
  1246. br.Data = resp
  1247. }
  1248. // @Title 是否展示免费试用按钮
  1249. // @Description 获取是否展示免费试用按钮接口
  1250. // @Param request body models.IsShow true "type json string"
  1251. // @Success 200
  1252. // @router /isShow/freeButton [get]
  1253. func (this *UserController) IsShow() {
  1254. br := new(models.BaseResponse).Init()
  1255. defer func() {
  1256. this.Data["json"] = br
  1257. this.ServeJSON()
  1258. }()
  1259. user := this.User
  1260. if user == nil {
  1261. br.Msg = "请重新登录"
  1262. br.Ret = 408
  1263. return
  1264. }
  1265. var resp models.IsShow
  1266. detail, err := models.GetConfigByCode("free_trial_card")
  1267. if err != nil {
  1268. br.Msg = "获取数据失败"
  1269. br.ErrMsg = "城市配置信息失败,Err:" + err.Error()
  1270. return
  1271. }
  1272. companyDetail, err := models.GetCompanyDetailByIdGroup(user.CompanyId)
  1273. if err != nil && err.Error() != utils.ErrNoRow() {
  1274. br.Msg = "获取数据失败!"
  1275. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  1276. return
  1277. }
  1278. count, err := models.CountCygxUserFreeeButton(user.UserId)
  1279. if err != nil && err.Error() != utils.ErrNoRow() {
  1280. br.Msg = "获取数据失败!"
  1281. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  1282. return
  1283. }
  1284. if companyDetail != nil && companyDetail.IsSuspend == 0 {
  1285. if detail.ConfigValue == "1" && (companyDetail.Status == "正式" || companyDetail.Status == "试用" || companyDetail.Status == "永续") && count == 0 {
  1286. resp.IsShow = true
  1287. }
  1288. }
  1289. br.Ret = 200
  1290. br.Success = true
  1291. br.Data = resp
  1292. }
  1293. // @Title 隐藏当天的按钮
  1294. // @Description 隐藏当天的按钮接口
  1295. // @Success 200
  1296. // @router /freeButton/update [post]
  1297. func (this *UserController) FreeButtonUpdate() {
  1298. br := new(models.BaseResponse).Init()
  1299. defer func() {
  1300. this.Data["json"] = br
  1301. this.ServeJSON()
  1302. }()
  1303. user := this.User
  1304. if user == nil {
  1305. br.Msg = "请重新登录"
  1306. br.Ret = 408
  1307. return
  1308. }
  1309. count, err := models.CountCygxUserFreeeButtonByUser(user.UserId)
  1310. if err != nil {
  1311. br.Msg = "获取数据失败!"
  1312. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  1313. return
  1314. }
  1315. if count == 0 {
  1316. item := new(models.CygxUserFreeeButton)
  1317. item.UserId = user.UserId
  1318. item.CompanyId = user.CompanyId
  1319. item.CreateTime = time.Now()
  1320. item.ModifyTime = time.Now()
  1321. item.EffectiveTime = time.Now().Format(utils.FormatDate)
  1322. _, err := models.AddCygxUserFreeeButton(item)
  1323. if err != nil {
  1324. br.Msg = "操作失败!"
  1325. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  1326. return
  1327. }
  1328. } else {
  1329. err := models.UpdateCygxUserFreeeButton(user.UserId)
  1330. if err != nil {
  1331. br.Msg = "操作失败!"
  1332. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  1333. return
  1334. }
  1335. }
  1336. br.Ret = 200
  1337. br.Success = true
  1338. br.Msg = "操作成功!"
  1339. }
  1340. // @Title 权限弹窗是否展示免费月卡
  1341. // @Description 获取权限弹窗是否展示免费月卡接口
  1342. // @Param request body models.IsShow true "type json string"
  1343. // @Success 200
  1344. // @router /isShow/alert [get]
  1345. func (this *UserController) AlertIsShow() {
  1346. br := new(models.BaseResponse).Init()
  1347. defer func() {
  1348. this.Data["json"] = br
  1349. this.ServeJSON()
  1350. }()
  1351. user := this.User
  1352. if user == nil {
  1353. br.Msg = "请重新登录"
  1354. br.Ret = 408
  1355. return
  1356. }
  1357. var resp models.IsShow
  1358. detail, err := models.GetConfigByCode("free_trial_card")
  1359. if err != nil {
  1360. br.Msg = "获取数据失败"
  1361. br.ErrMsg = "城市配置信息失败,Err:" + err.Error()
  1362. return
  1363. }
  1364. if user.CompanyId == 1 && detail.ConfigValue == "1" {
  1365. resp.IsShow = true
  1366. }
  1367. br.Ret = 200
  1368. br.Success = true
  1369. br.Data = resp
  1370. }
  1371. // @Title 分享的时候是否展示免费月卡
  1372. // @Description 获取权限弹窗是否展示免费月卡接口
  1373. // @Param request body models.IsShow true "type json string"
  1374. // @Success 200
  1375. // @router /isShow/share [get]
  1376. func (this *UserController) ShareIsShow() {
  1377. br := new(models.BaseResponse).Init()
  1378. defer func() {
  1379. this.Data["json"] = br
  1380. this.ServeJSON()
  1381. }()
  1382. user := this.User
  1383. if user == nil {
  1384. br.Msg = "请重新登录"
  1385. br.Ret = 408
  1386. return
  1387. }
  1388. var resp models.IsShow
  1389. detail, err := models.GetConfigByCode("free_trial_card")
  1390. if err != nil {
  1391. br.Msg = "获取数据失败"
  1392. br.ErrMsg = "城市配置信息失败,Err:" + err.Error()
  1393. return
  1394. }
  1395. if user.CompanyId != 16 && detail.ConfigValue == "1" {
  1396. resp.IsShow = true
  1397. }
  1398. resp.LinkWxExplain = utils.LINK_WX_EXPLAIN
  1399. br.Ret = 200
  1400. br.Success = true
  1401. br.Data = resp
  1402. }
  1403. // @Title 更改用户微信头像
  1404. // @Description 更改用户微信头像
  1405. // @Param request body models.Headimgurl true "type json string"
  1406. // @Success 200 {object} models.ArticleDetailFileLink
  1407. // @router /headimgurl/update [post]
  1408. func (this *UserController) HeadimgurlUpdate() {
  1409. br := new(models.BaseResponse).Init()
  1410. defer func() {
  1411. this.Data["json"] = br
  1412. this.ServeJSON()
  1413. }()
  1414. user := this.User
  1415. if user == nil {
  1416. br.Msg = "请登录"
  1417. br.ErrMsg = "请登录,用户信息为空"
  1418. br.Ret = 408
  1419. return
  1420. }
  1421. var req models.Headimgurl
  1422. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1423. if err != nil {
  1424. br.Msg = "参数解析异常!"
  1425. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1426. return
  1427. }
  1428. uid := user.UserId
  1429. headimgurl := req.Headimgurl
  1430. if headimgurl == "" {
  1431. br.Msg = "操作失败"
  1432. br.ErrMsg = "头像信息不能为空"
  1433. return
  1434. }
  1435. err = models.UpdateUserHeadimgurl(headimgurl, uid)
  1436. if err != nil {
  1437. br.Msg = "操作失败"
  1438. br.ErrMsg = "头像信息不能为空"
  1439. }
  1440. br.Ret = 200
  1441. br.Success = true
  1442. br.Msg = "操作成功"
  1443. }
  1444. // @Title 登录 (无需token)
  1445. // @Description 登录接口 (无需token)
  1446. // @Param request body models.LoginReq true "type json string"
  1447. // @Success 200 {object} models.LoginResp
  1448. // @router /loginPublic [post]
  1449. func (this *UserCommonController) LoginPublic() {
  1450. br := new(models.BaseResponse).Init()
  1451. defer func() {
  1452. this.Data["json"] = br
  1453. this.ServeJSON()
  1454. }()
  1455. var req models.LoginReq
  1456. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1457. if err != nil {
  1458. br.Msg = "参数解析异常!"
  1459. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1460. return
  1461. }
  1462. mobile := strings.Trim(req.Mobile, " ")
  1463. if req.Mobile == "" {
  1464. br.Msg = "参数错误"
  1465. br.ErrMsg = "参数错误,手机号为空 为空"
  1466. return
  1467. }
  1468. item, err := models.GetMsgCode(req.Mobile, req.VCode)
  1469. if err != nil {
  1470. if err.Error() == utils.ErrNoRow() {
  1471. br.Msg = "验证码错误,请重新输入"
  1472. br.ErrMsg = "校验验证码失败,Err:" + err.Error()
  1473. return
  1474. } else {
  1475. br.Msg = "验证码错误,请重新输入"
  1476. br.ErrMsg = "校验验证码失败,Err:" + err.Error()
  1477. return
  1478. }
  1479. }
  1480. if item == nil {
  1481. br.Msg = "验证码错误,请重新输入"
  1482. return
  1483. }
  1484. if len(req.Mobile) >= 11 && req.CountryCode == "" {
  1485. req.CountryCode = "86"
  1486. }
  1487. var token string
  1488. tokenItem, err := models.GetSessionMobileTokenByOpenId(mobile)
  1489. if err != nil && err.Error() != utils.ErrNoRow() {
  1490. br.Msg = "登录失败"
  1491. br.ErrMsg = "登录失败,获取token失败:" + err.Error()
  1492. return
  1493. }
  1494. if tokenItem == nil || (err != nil && err.Error() == utils.ErrNoRow()) {
  1495. timeUnix := time.Now().Unix()
  1496. timeUnixStr := strconv.FormatInt(timeUnix, 10)
  1497. token = utils.MD5(mobile) + utils.MD5(timeUnixStr)
  1498. //新增session
  1499. {
  1500. session := new(models.CygxSessionMobile)
  1501. session.Mobile = mobile
  1502. session.CreatedTime = time.Now()
  1503. session.LastUpdatedTime = time.Now()
  1504. session.ExpireTime = time.Now().AddDate(0, 1, 0)
  1505. session.AccessToken = token
  1506. err = models.AddCygxSessionMobile(session)
  1507. if err != nil {
  1508. br.Msg = "登录失败"
  1509. br.ErrMsg = "登录失败,新增用户session信息失败:" + err.Error()
  1510. return
  1511. }
  1512. }
  1513. } else {
  1514. token = tokenItem.AccessToken
  1515. }
  1516. resp := new(models.LoginResp)
  1517. resp.Authorization = token
  1518. br.Ret = 200
  1519. br.Success = true
  1520. br.Data = resp
  1521. br.Msg = "登录成功"
  1522. }
  1523. // @Title 获取我的留言
  1524. // @Description 获取我的留言列表
  1525. // @Success 200 {object} models.CygxCommentListResp
  1526. // @router /comment/list [get]
  1527. func (this *UserController) CommnetList() {
  1528. br := new(models.BaseResponse).Init()
  1529. defer func() {
  1530. this.Data["json"] = br
  1531. this.ServeJSON()
  1532. }()
  1533. user := this.User
  1534. if user == nil {
  1535. br.Msg = "请登录"
  1536. br.ErrMsg = "请登录,用户信息为空"
  1537. br.Ret = 408
  1538. return
  1539. }
  1540. userId := this.User.UserId
  1541. commentlist, err := models.GetCommentList(userId)
  1542. if err != nil && err.Error() != utils.ErrNoRow() {
  1543. br.Msg = "获取失败"
  1544. br.ErrMsg = "获取我的留言列表失败,Err:" + err.Error()
  1545. return
  1546. }
  1547. articleLyjhMap, _ := services.GetLyjhArticleMap()
  1548. articleCollectMap, _ := services.GetCygxArticleCollectMap(user.UserId)
  1549. resp := new(models.CygxCommentListResp)
  1550. for _, comment := range commentlist {
  1551. item := models.CygxArticleCommentResp{
  1552. Id: comment.Id,
  1553. UserId: comment.UserId,
  1554. ArticleId: comment.ArticleId,
  1555. IndustryId: comment.IndustryId,
  1556. ActivityId: comment.ActivityId,
  1557. CreateTime: comment.CreateTime,
  1558. Mobile: comment.Mobile,
  1559. Email: comment.Email,
  1560. CompanyId: comment.CompanyId,
  1561. CompanyName: comment.CompanyName,
  1562. Content: comment.Content,
  1563. Title: comment.Title,
  1564. }
  1565. if comment.ArticleId > 0 {
  1566. item.RedirectType = 1
  1567. } else if comment.IndustryId > 0 {
  1568. item.RedirectType = 3
  1569. } else if comment.ActivityId > 0 {
  1570. item.RedirectType = 2
  1571. }
  1572. item.IsCollect = articleCollectMap[comment.ArticleId]
  1573. item.IsRoadShow = articleLyjhMap[comment.ArticleId]
  1574. resp.List = append(resp.List, &item)
  1575. }
  1576. br.Msg = "获取成功!"
  1577. br.Ret = 200
  1578. br.Success = true
  1579. br.Data = resp
  1580. }
  1581. // @Title 获取我的收藏
  1582. // @Description 获取我的收藏列表
  1583. // @Success 200 {object} models.ArticleCollectListResp
  1584. // @router /collect/list/microRoadshow [get]
  1585. func (this *UserController) MicroRoadshowCollectList() {
  1586. br := new(models.BaseResponse).Init()
  1587. defer func() {
  1588. this.Data["json"] = br
  1589. this.ServeJSON()
  1590. }()
  1591. userId := this.User.UserId
  1592. list, err := models.GetUserMicroRoadshowCollectList(userId)
  1593. if err != nil {
  1594. br.Msg = "获取数据失败"
  1595. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1596. return
  1597. }
  1598. resp := new(models.MicroRoadshowCollectList)
  1599. var audioIds []string
  1600. var videoIds []string
  1601. var activityVideoIds []string
  1602. for _, item := range list {
  1603. if item.ActivityVoiceId > 0 {
  1604. audioIds = append(audioIds, strconv.Itoa(item.ActivityVoiceId))
  1605. } else if item.VideoId > 0 {
  1606. videoIds = append(videoIds, strconv.Itoa(item.VideoId))
  1607. } else if item.ActivityVideoId > 0 {
  1608. activityVideoIds = append(activityVideoIds, strconv.Itoa(item.ActivityVideoId))
  1609. }
  1610. }
  1611. resp.AudioIds = strings.Join(audioIds, ",")
  1612. resp.VideoIds = strings.Join(videoIds, ",")
  1613. resp.ActivityVideoIds = strings.Join(activityVideoIds, ",")
  1614. br.Msg = "获取成功!"
  1615. br.Ret = 200
  1616. br.Success = true
  1617. br.Data = resp
  1618. }
  1619. // @Title 新增埋点
  1620. // @Description 新增埋点接口
  1621. // @Success 200 "新增成功!"
  1622. // @router /tracking [get]
  1623. func (this *UserController) Tracking() {
  1624. br := new(models.BaseResponse).Init()
  1625. defer func() {
  1626. this.Data["json"] = br
  1627. this.ServeJSON()
  1628. }()
  1629. user := this.User
  1630. if user == nil {
  1631. br.Msg = "请登录"
  1632. br.ErrMsg = "请登录,用户信息为空"
  1633. br.Ret = 408
  1634. return
  1635. }
  1636. //item := new(models.CygxPageHistoryRecord)
  1637. //item.UserId = user.UserId
  1638. //item.CreateTime = time.Now()
  1639. //item.Mobile = user.Mobile
  1640. //item.Email = user.Email
  1641. //item.CompanyId = user.CompanyId
  1642. //item.CompanyName = user.CompanyName
  1643. //item.Router = this.Ctx.Request.RequestURI
  1644. //item.PageRouter = this.Ctx.Input.Query("PageRouter")
  1645. //
  1646. //go models.AddCygxPageHistoryRecord(item)
  1647. //
  1648. br.Msg = "新增成功!"
  1649. br.Ret = 200
  1650. br.Success = true
  1651. }