user.go 53 KB

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