user.go 55 KB

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