user.go 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948
  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. }
  968. //缓存校验
  969. cacheKey := fmt.Sprint("xygx:apply_record:add:", uid)
  970. ttlTime := utils.Rc.GetRedisTTL(cacheKey)
  971. if ttlTime > 0 {
  972. br.Msg = "申请失败,申请过于频繁"
  973. br.ErrMsg = "申请失败,申请过于频繁"
  974. return
  975. }
  976. utils.Rc.SetNX(cacheKey, user.Mobile, time.Second*10)
  977. //判断是否已经申请过
  978. applyCount, err := models.GetApplyRecordCount(uid)
  979. if err != nil && err.Error() != utils.ErrNoRow() {
  980. br.Msg = "获取信息失败"
  981. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  982. return
  983. }
  984. if applyCount > 0 {
  985. br.Msg = "您已提交申请,请耐心等待。"
  986. br.IsSendEmail = false
  987. return
  988. }
  989. //判断是否存在申请
  990. var sellerMobile string
  991. if req.ApplyMethod == 2 {
  992. if req.BusinessCardUrl == "" {
  993. br.Msg = "请上传名片"
  994. return
  995. }
  996. if req.RealName == "" {
  997. br.Msg = "请输入姓名"
  998. return
  999. }
  1000. if req.CompanyName == "" {
  1001. br.Msg = "请输入公司名称"
  1002. return
  1003. }
  1004. if req.BusinessCardUrl != "" && utils.RunMode == "release" {
  1005. card, err := services.GetBusinessCard(req.BusinessCardUrl)
  1006. if err != nil {
  1007. br.Msg = "名片识别失败"
  1008. br.ErrMsg = "名片识别失败,Err:" + err.Error()
  1009. return
  1010. }
  1011. mobileStr := strings.Join(card.WordsResult.MOBILE, ",")
  1012. isFlag := true
  1013. if mobile != "" {
  1014. if strings.Contains(mobileStr, mobile) || mobileStr == "" {
  1015. isFlag = true
  1016. } else {
  1017. isFlag = false
  1018. }
  1019. }
  1020. if !isFlag {
  1021. //阿里云识别
  1022. if utils.RunMode == "release" {
  1023. aliyunResult, err := services.AliyunBusinessCard(req.BusinessCardUrl)
  1024. if err != nil {
  1025. br.Msg = "识别失败"
  1026. br.ErrMsg = "识别失败,Err:" + err.Error()
  1027. return
  1028. }
  1029. if !aliyunResult.Success {
  1030. br.Msg = "识别失败"
  1031. br.ErrMsg = "识别失败"
  1032. return
  1033. }
  1034. mobileStr := strings.Join(aliyunResult.TelCell, ",")
  1035. if mobile != "" {
  1036. if strings.Contains(mobileStr, mobile) {
  1037. isFlag = true
  1038. } else {
  1039. isFlag = false
  1040. }
  1041. }
  1042. }
  1043. }
  1044. if !isFlag {
  1045. br.Msg = "名片手机号与所填手机号不匹配,请重新填写"
  1046. br.ErrMsg = "mobile:" + mobile
  1047. return
  1048. }
  1049. }
  1050. }
  1051. //获取销售信息
  1052. sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  1053. if err != nil && err.Error() != utils.ErrNoRow() {
  1054. br.Msg = "申请失败"
  1055. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  1056. return
  1057. }
  1058. //用户状态,1:潜在客户 、2:现有客户 、3:FICC客户 、4:现有客户(正式,无对应权限) 、5:现有客户(试用,无对应权限) 、6:现有客户(试用暂停) 、7:现有客户(冻结) 、8:现有客户(流失)?
  1059. CompanyIdType := 1
  1060. applyMethod := ""
  1061. if sellerItem != nil {
  1062. companyItem, err := models.GetCompanyDetailById(user.CompanyId)
  1063. if err != nil && err.Error() != utils.ErrNoRow() {
  1064. br.Msg = "获取信息失败"
  1065. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  1066. return
  1067. }
  1068. if companyItem != nil && companyItem.CompanyId > 0 {
  1069. companyProduct, err := models.GetCompanyProductDetail(user.CompanyId, 2)
  1070. if err != nil && err.Error() != utils.ErrNoRow() {
  1071. br.Msg = "获取信息失败"
  1072. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  1073. return
  1074. }
  1075. if companyProduct != nil && companyProduct.IsSuspend == 1 {
  1076. CompanyIdType = 6
  1077. } else {
  1078. switch companyItem.Status {
  1079. case "正式":
  1080. CompanyIdType = 4
  1081. case "试用":
  1082. CompanyIdType = 5
  1083. case "冻结":
  1084. CompanyIdType = 7
  1085. case "流失":
  1086. CompanyIdType = 8
  1087. }
  1088. }
  1089. applyMethod = companyItem.Status + "客户申请"
  1090. if detailId > 0 {
  1091. if companyProduct != nil && companyProduct.IsSuspend == 1 {
  1092. applyMethod = "试用暂停客户"
  1093. } else {
  1094. if companyItem.Status == "正式" || companyItem.Status == "试用" {
  1095. applyMethod = companyItem.Status + "客户申请,无对应权限"
  1096. } else if companyItem.Status == "冻结" || companyItem.Status == "流失" {
  1097. applyMethod = companyItem.Status + "客户"
  1098. }
  1099. }
  1100. applyMethod = applyMethod + "," + title
  1101. }
  1102. openIpItem, _ := models.GetUserRecordByMobile(4, sellerItem.Mobile)
  1103. if openIpItem != nil && openIpItem.OpenId != "" {
  1104. if req.ApplyMethod != 2 {
  1105. req.RealName = user.RealName
  1106. req.CompanyName = user.CompanyName
  1107. }
  1108. //go services.SendPermissionApplyTemplateMsg(req.RealName, req.CompanyName, mobile, applyMethod, openIpItem)
  1109. }
  1110. }
  1111. } else {
  1112. //获取销售信息
  1113. sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 1)
  1114. if err != nil && err.Error() != utils.ErrNoRow() {
  1115. br.Msg = "申请失败"
  1116. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  1117. return
  1118. }
  1119. if sellerItem != nil {
  1120. CompanyIdType = 3
  1121. applyMethod = "FICC客户"
  1122. } else {
  1123. CompanyIdType = 1
  1124. applyMethod = "潜在客户"
  1125. }
  1126. if detailId > 0 {
  1127. applyMethod = applyMethod + "," + title
  1128. }
  1129. }
  1130. item := new(models.CygxApplyRecord)
  1131. item.UserId = user.UserId
  1132. item.BusinessCardUrl = req.BusinessCardUrl
  1133. item.RealName = req.RealName
  1134. item.CompanyName = req.CompanyName
  1135. item.Mobile = user.Mobile
  1136. item.CreateTime = time.Now()
  1137. item.ApplyMethod = req.ApplyMethod
  1138. item.CompanyIdPay = user.CompanyId
  1139. item.CompanyNamePay = user.CompanyName
  1140. item.CompanyIdType = CompanyIdType
  1141. if user.InviteCompany == utils.LUODING_CODE && user.CompanyId == 1 {
  1142. //如果是潜在客户就标记来源
  1143. item.InviteCompanySource = 2
  1144. }
  1145. item.Title = title
  1146. item.SourceId = sourceId
  1147. item.Source = strings.ToLower(source)
  1148. item.RegisterPlatform = utils.REGISTER_PLATFORM
  1149. err = models.AddApplyRecord(item)
  1150. if err != nil {
  1151. br.Msg = "申请失败"
  1152. br.ErrMsg = "申请失败,Err:" + err.Error()
  1153. return
  1154. }
  1155. if sellerItem == nil {
  1156. go services.SendPermissionApplyTemplateMsgAdmin(req, mobile, applyMethod, isResearch)
  1157. } else {
  1158. openIpItem, _ := models.GetUserRecordByMobile(4, sellerItem.Mobile)
  1159. if openIpItem != nil && openIpItem.OpenId != "" {
  1160. go services.SendPermissionApplyTemplateMsg(req.RealName, req.CompanyName, mobile, applyMethod, openIpItem)
  1161. }
  1162. }
  1163. //添加成功后,设置5分钟缓存,不允许重复添加
  1164. //utils.Rc.SetNX(cacheKey, user.Mobile, time.Second*60)
  1165. br.Msg = "申请成功!"
  1166. br.Ret = 200
  1167. br.Success = true
  1168. br.Data = sellerMobile
  1169. }
  1170. // @Title 是否需要填写区号
  1171. // @Description 获取是否需要填写区号接口
  1172. // @Success 200 {object} models.CountryCode
  1173. // @router /countryCcode/isNeedAdd [get]
  1174. func (this *UserController) CountryCcode() {
  1175. br := new(models.BaseResponse).Init()
  1176. defer func() {
  1177. this.Data["json"] = br
  1178. this.ServeJSON()
  1179. }()
  1180. user := this.User
  1181. uid := user.UserId
  1182. if user == nil {
  1183. br.Msg = "请登录"
  1184. br.ErrMsg = "请登录,用户信息为空"
  1185. br.Ret = 408
  1186. return
  1187. }
  1188. //if uid == 0 {
  1189. // br.Msg = "请登录"
  1190. // br.ErrMsg = "请登录,用户信息为空"
  1191. // br.Ret = 408
  1192. // return
  1193. //}
  1194. resp := new(models.CountryCode)
  1195. if user.CountryCode == "" && len(user.Mobile) >= 11 {
  1196. err := models.ChangeUserOutboundMobileByMobile(uid)
  1197. if err != nil {
  1198. br.Msg = "操作失败"
  1199. br.ErrMsg = "操作失败,Err:" + err.Error()
  1200. return
  1201. }
  1202. }
  1203. if user.CountryCode == "" && user.Mobile != "" && len(user.Mobile) < 11 {
  1204. resp.IsNeedAddCountryCode = true
  1205. }
  1206. if user.OutboundMobile != "" {
  1207. resp.IsNeedAddCountryCode = false
  1208. }
  1209. br.Ret = 200
  1210. br.Success = true
  1211. br.Msg = "获取成功"
  1212. br.Data = resp
  1213. }
  1214. // @Title 上传用户区号
  1215. // @Description 上传用户区号接口
  1216. // @Param request body models.CountryCodeItem true "type json string"
  1217. // @Success Ret=200 新增成功
  1218. // @router /countryCcode/Add [POST]
  1219. func (this *UserController) AddCountryCcode() {
  1220. br := new(models.BaseResponse).Init()
  1221. defer func() {
  1222. this.Data["json"] = br
  1223. this.ServeJSON()
  1224. }()
  1225. user := this.User
  1226. if user == nil {
  1227. br.Msg = "请登录"
  1228. br.ErrMsg = "请登录,用户信息为空"
  1229. br.Ret = 408
  1230. return
  1231. }
  1232. var req models.CountryCodeItem
  1233. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1234. if err != nil {
  1235. br.Msg = "参数解析异常!"
  1236. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1237. return
  1238. }
  1239. err = models.AddCountryCode(req.CountryCode, user)
  1240. if err != nil {
  1241. br.Msg = "获取信息失败"
  1242. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  1243. return
  1244. }
  1245. br.Ret = 200
  1246. br.Success = true
  1247. br.Msg = "新增成功"
  1248. }
  1249. // @Title 用户修改外呼手机号以及区号
  1250. // @Description 用户修改外呼手机号以及区号接口
  1251. // @Param request body models.OutboundMobileItem true "type json string"
  1252. // @Success Ret=200 操作成功
  1253. // @router /countryCcode/addOutboundMobile [POST]
  1254. func (this *UserController) AddOutboundMobile() {
  1255. br := new(models.BaseResponse).Init()
  1256. defer func() {
  1257. this.Data["json"] = br
  1258. this.ServeJSON()
  1259. }()
  1260. user := this.User
  1261. uid := user.UserId
  1262. if user == nil {
  1263. br.Msg = "请登录"
  1264. br.ErrMsg = "请登录,用户信息为空"
  1265. br.Ret = 408
  1266. return
  1267. }
  1268. var req models.OutboundMobileItem
  1269. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1270. if err != nil {
  1271. br.Msg = "参数解析异常!"
  1272. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1273. return
  1274. }
  1275. if !utils.ValidateFixedTelephoneFormatatEasy(req.OutboundMobile) {
  1276. br.Msg = "号码格式有误,请重新填写!"
  1277. br.ErrMsg = "号码格式有误,请重新填写" + req.OutboundMobile
  1278. return
  1279. }
  1280. if req.OutboundMobile == "" {
  1281. br.Msg = "请填写区号!"
  1282. return
  1283. }
  1284. item := new(models.OutboundMobileItem)
  1285. item.OutboundMobile = req.OutboundMobile
  1286. item.OutboundCountryCode = req.OutboundCountryCode
  1287. item.ActivityId = req.ActivityId
  1288. if req.ActivityId == 0 {
  1289. err = models.AddOutboundMobile(item, uid)
  1290. } else {
  1291. if user.Mobile == "" && user.OutboundMobile == "" {
  1292. items := new(models.CygxActivitySignup)
  1293. items.UserId = uid
  1294. items.ActivityId = req.ActivityId
  1295. items.CreateTime = time.Now()
  1296. items.Mobile = user.Mobile
  1297. items.Email = user.Email
  1298. items.CompanyId = user.CompanyId
  1299. items.CompanyName = user.CompanyName
  1300. items.SignupType = 1
  1301. items.FailType = 0
  1302. items.DoFailType = 0
  1303. items.OutboundMobile = req.OutboundMobile
  1304. items.CountryCode = req.OutboundCountryCode
  1305. _, err = models.AddActivitySignupFromEmail(items)
  1306. } else {
  1307. total, err := models.GetActivityCountByIdWithUid(item.ActivityId, uid)
  1308. if total == 0 {
  1309. br.Msg = "报名信息不存在"
  1310. br.ErrMsg = "报名信息不存在,Err:" + "活动ActivityId:" + strconv.Itoa(item.ActivityId) + "用户Uid:" + strconv.Itoa(uid)
  1311. return
  1312. }
  1313. if err != nil {
  1314. br.Msg = "操作失败"
  1315. br.ErrMsg = "操作失败,Err:" + err.Error()
  1316. return
  1317. }
  1318. err = models.AddOutboundMobile(item, uid)
  1319. }
  1320. }
  1321. if err != nil {
  1322. br.Msg = "操作失败"
  1323. br.ErrMsg = "操作失败,Err:" + err.Error()
  1324. return
  1325. }
  1326. br.Ret = 200
  1327. br.Success = true
  1328. br.Msg = "操作成功"
  1329. }
  1330. // @Title 获取我的提问
  1331. // @Description 获取我的提问列表
  1332. // @Success 200 {object} models.CygxAskListResp
  1333. // @router /ask/list [get]
  1334. func (this *UserController) AskList() {
  1335. br := new(models.BaseResponse).Init()
  1336. defer func() {
  1337. this.Data["json"] = br
  1338. this.ServeJSON()
  1339. }()
  1340. user := this.User
  1341. if user == nil {
  1342. br.Msg = "请登录"
  1343. br.ErrMsg = "请登录,用户信息为空"
  1344. br.Ret = 408
  1345. return
  1346. }
  1347. userId := this.User.UserId
  1348. listActcivity, err := models.GetActivityAskList(userId)
  1349. if err != nil && err.Error() != utils.ErrNoRow() {
  1350. br.Msg = "获取失败"
  1351. br.ErrMsg = "获取活动问题失败,Err:" + err.Error()
  1352. return
  1353. }
  1354. for _, v := range listActcivity {
  1355. v.AskType = "Activity"
  1356. }
  1357. listArticle, err := models.GetArticleAskList(userId)
  1358. if err != nil && err.Error() != utils.ErrNoRow() {
  1359. br.Msg = "获取失败"
  1360. br.ErrMsg = "获取文章问题失败,Err:" + err.Error()
  1361. return
  1362. }
  1363. for _, v := range listArticle {
  1364. v.AskType = "Report"
  1365. listActcivity = append(listActcivity, v)
  1366. }
  1367. resp := new(models.CygxAskListResp)
  1368. resp.List = listActcivity
  1369. br.Msg = "获取成功!"
  1370. br.Ret = 200
  1371. br.Success = true
  1372. br.Data = resp
  1373. }
  1374. // @Title 是否展示免费试用按钮
  1375. // @Description 获取是否展示免费试用按钮接口
  1376. // @Param request body models.IsShow true "type json string"
  1377. // @Success 200
  1378. // @router /isShow/freeButton [get]
  1379. func (this *UserController) IsShow() {
  1380. br := new(models.BaseResponse).Init()
  1381. defer func() {
  1382. this.Data["json"] = br
  1383. this.ServeJSON()
  1384. }()
  1385. user := this.User
  1386. if user == nil {
  1387. br.Msg = "请重新登录"
  1388. br.Ret = 408
  1389. return
  1390. }
  1391. var resp models.IsShow
  1392. detail, err := models.GetConfigByCode("free_trial_card")
  1393. if err != nil {
  1394. br.Msg = "获取数据失败"
  1395. br.ErrMsg = "城市配置信息失败,Err:" + err.Error()
  1396. return
  1397. }
  1398. companyDetail, err := models.GetCompanyDetailByIdGroup(user.CompanyId)
  1399. if err != nil && err.Error() != utils.ErrNoRow() {
  1400. br.Msg = "获取数据失败!"
  1401. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  1402. return
  1403. }
  1404. count, err := models.CountCygxUserFreeeButton(user.UserId)
  1405. if err != nil && err.Error() != utils.ErrNoRow() {
  1406. br.Msg = "获取数据失败!"
  1407. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  1408. return
  1409. }
  1410. if companyDetail != nil && companyDetail.IsSuspend == 0 {
  1411. if detail.ConfigValue == "1" && (companyDetail.Status == "正式" || companyDetail.Status == "试用" || companyDetail.Status == "永续") && count == 0 {
  1412. resp.IsShow = true
  1413. }
  1414. }
  1415. br.Ret = 200
  1416. br.Success = true
  1417. br.Data = resp
  1418. }
  1419. // @Title 隐藏当天的按钮
  1420. // @Description 隐藏当天的按钮接口
  1421. // @Success 200
  1422. // @router /freeButton/update [post]
  1423. func (this *UserController) FreeButtonUpdate() {
  1424. br := new(models.BaseResponse).Init()
  1425. defer func() {
  1426. this.Data["json"] = br
  1427. this.ServeJSON()
  1428. }()
  1429. user := this.User
  1430. if user == nil {
  1431. br.Msg = "请重新登录"
  1432. br.Ret = 408
  1433. return
  1434. }
  1435. count, err := models.CountCygxUserFreeeButtonByUser(user.UserId)
  1436. if err != nil {
  1437. br.Msg = "获取数据失败!"
  1438. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  1439. return
  1440. }
  1441. if count == 0 {
  1442. item := new(models.CygxUserFreeeButton)
  1443. item.UserId = user.UserId
  1444. item.CompanyId = user.CompanyId
  1445. item.CreateTime = time.Now()
  1446. item.ModifyTime = time.Now()
  1447. item.EffectiveTime = time.Now().Format(utils.FormatDate)
  1448. _, err := models.AddCygxUserFreeeButton(item)
  1449. if err != nil {
  1450. br.Msg = "操作失败!"
  1451. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  1452. return
  1453. }
  1454. } else {
  1455. err := models.UpdateCygxUserFreeeButton(user.UserId)
  1456. if err != nil {
  1457. br.Msg = "操作失败!"
  1458. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  1459. return
  1460. }
  1461. }
  1462. br.Ret = 200
  1463. br.Success = true
  1464. br.Msg = "操作成功!"
  1465. }
  1466. // @Title 权限弹窗是否展示免费月卡
  1467. // @Description 获取权限弹窗是否展示免费月卡接口
  1468. // @Param request body models.IsShow true "type json string"
  1469. // @Success 200
  1470. // @router /isShow/alert [get]
  1471. func (this *UserController) AlertIsShow() {
  1472. br := new(models.BaseResponse).Init()
  1473. defer func() {
  1474. this.Data["json"] = br
  1475. this.ServeJSON()
  1476. }()
  1477. user := this.User
  1478. if user == nil {
  1479. br.Msg = "请重新登录"
  1480. br.Ret = 408
  1481. return
  1482. }
  1483. var resp models.IsShow
  1484. detail, err := models.GetConfigByCode("free_trial_card")
  1485. if err != nil {
  1486. br.Msg = "获取数据失败"
  1487. br.ErrMsg = "城市配置信息失败,Err:" + err.Error()
  1488. return
  1489. }
  1490. if user.CompanyId == 1 && detail.ConfigValue == "1" {
  1491. resp.IsShow = true
  1492. }
  1493. br.Ret = 200
  1494. br.Success = true
  1495. br.Data = resp
  1496. }
  1497. // @Title 分享的时候是否展示免费月卡
  1498. // @Description 获取权限弹窗是否展示免费月卡接口
  1499. // @Param request body models.IsShow true "type json string"
  1500. // @Success 200
  1501. // @router /isShow/share [get]
  1502. func (this *UserController) ShareIsShow() {
  1503. br := new(models.BaseResponse).Init()
  1504. defer func() {
  1505. this.Data["json"] = br
  1506. this.ServeJSON()
  1507. }()
  1508. user := this.User
  1509. if user == nil {
  1510. br.Msg = "请重新登录"
  1511. br.Ret = 408
  1512. return
  1513. }
  1514. var resp models.IsShow
  1515. detail, err := models.GetConfigByCode("free_trial_card")
  1516. if err != nil {
  1517. br.Msg = "获取数据失败"
  1518. br.ErrMsg = "城市配置信息失败,Err:" + err.Error()
  1519. return
  1520. }
  1521. if user.CompanyId != 16 && detail.ConfigValue == "1" {
  1522. resp.IsShow = true
  1523. }
  1524. resp.LinkWxExplain = utils.LINK_WX_EXPLAIN
  1525. br.Ret = 200
  1526. br.Success = true
  1527. br.Data = resp
  1528. }
  1529. // @Title 更改用户微信头像
  1530. // @Description 更改用户微信头像
  1531. // @Param request body models.Headimgurl true "type json string"
  1532. // @Success 200 {object} models.ArticleDetailFileLink
  1533. // @router /headimgurl/update [post]
  1534. func (this *UserController) HeadimgurlUpdate() {
  1535. br := new(models.BaseResponse).Init()
  1536. defer func() {
  1537. this.Data["json"] = br
  1538. this.ServeJSON()
  1539. }()
  1540. user := this.User
  1541. if user == nil {
  1542. br.Msg = "请登录"
  1543. br.ErrMsg = "请登录,用户信息为空"
  1544. br.Ret = 408
  1545. return
  1546. }
  1547. var req models.Headimgurl
  1548. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1549. if err != nil {
  1550. br.Msg = "参数解析异常!"
  1551. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1552. return
  1553. }
  1554. uid := user.UserId
  1555. headimgurl := req.Headimgurl
  1556. if headimgurl == "" {
  1557. br.Msg = "操作失败"
  1558. br.ErrMsg = "头像信息不能为空"
  1559. return
  1560. }
  1561. err = models.UpdateUserHeadimgurl(headimgurl, uid)
  1562. if err != nil {
  1563. br.Msg = "操作失败"
  1564. br.ErrMsg = "头像信息不能为空"
  1565. }
  1566. br.Ret = 200
  1567. br.Success = true
  1568. br.Msg = "操作成功"
  1569. }
  1570. // @Title 登录 (无需token)
  1571. // @Description 登录接口 (无需token)
  1572. // @Param request body models.LoginReq true "type json string"
  1573. // @Success 200 {object} models.LoginResp
  1574. // @router /loginPublic [post]
  1575. func (this *UserCommonController) LoginPublic() {
  1576. br := new(models.BaseResponse).Init()
  1577. defer func() {
  1578. this.Data["json"] = br
  1579. this.ServeJSON()
  1580. }()
  1581. var req models.LoginReq
  1582. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1583. if err != nil {
  1584. br.Msg = "参数解析异常!"
  1585. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1586. return
  1587. }
  1588. mobile := strings.Trim(req.Mobile, " ")
  1589. if req.Mobile == "" {
  1590. br.Msg = "参数错误"
  1591. br.ErrMsg = "参数错误,手机号为空 为空"
  1592. return
  1593. }
  1594. item, err := models.GetMsgCode(req.Mobile, req.VCode)
  1595. if err != nil {
  1596. if err.Error() == utils.ErrNoRow() {
  1597. br.Msg = "验证码错误,请重新输入"
  1598. br.ErrMsg = "校验验证码失败,Err:" + err.Error()
  1599. return
  1600. } else {
  1601. br.Msg = "验证码错误,请重新输入"
  1602. br.ErrMsg = "校验验证码失败,Err:" + err.Error()
  1603. return
  1604. }
  1605. }
  1606. if item == nil {
  1607. br.Msg = "验证码错误,请重新输入"
  1608. return
  1609. }
  1610. if len(req.Mobile) >= 11 && req.CountryCode == "" {
  1611. req.CountryCode = "86"
  1612. }
  1613. var token string
  1614. tokenItem, err := models.GetSessionMobileTokenByOpenId(mobile)
  1615. if err != nil && err.Error() != utils.ErrNoRow() {
  1616. br.Msg = "登录失败"
  1617. br.ErrMsg = "登录失败,获取token失败:" + err.Error()
  1618. return
  1619. }
  1620. if tokenItem == nil || (err != nil && err.Error() == utils.ErrNoRow()) {
  1621. timeUnix := time.Now().Unix()
  1622. timeUnixStr := strconv.FormatInt(timeUnix, 10)
  1623. token = utils.MD5(mobile) + utils.MD5(timeUnixStr)
  1624. //新增session
  1625. {
  1626. session := new(models.CygxSessionMobile)
  1627. session.Mobile = mobile
  1628. session.CreatedTime = time.Now()
  1629. session.LastUpdatedTime = time.Now()
  1630. session.ExpireTime = time.Now().AddDate(0, 1, 0)
  1631. session.AccessToken = token
  1632. err = models.AddCygxSessionMobile(session)
  1633. if err != nil {
  1634. br.Msg = "登录失败"
  1635. br.ErrMsg = "登录失败,新增用户session信息失败:" + err.Error()
  1636. return
  1637. }
  1638. }
  1639. } else {
  1640. token = tokenItem.AccessToken
  1641. }
  1642. resp := new(models.LoginResp)
  1643. resp.Authorization = token
  1644. br.Ret = 200
  1645. br.Success = true
  1646. br.Data = resp
  1647. br.Msg = "登录成功"
  1648. }
  1649. // @Title 获取我的留言
  1650. // @Description 获取我的留言列表
  1651. // @Success 200 {object} models.CygxCommentListResp
  1652. // @router /comment/list [get]
  1653. func (this *UserController) CommnetList() {
  1654. br := new(models.BaseResponse).Init()
  1655. defer func() {
  1656. this.Data["json"] = br
  1657. this.ServeJSON()
  1658. }()
  1659. user := this.User
  1660. if user == nil {
  1661. br.Msg = "请登录"
  1662. br.ErrMsg = "请登录,用户信息为空"
  1663. br.Ret = 408
  1664. return
  1665. }
  1666. userId := this.User.UserId
  1667. commentlist, err := models.GetCommentList(userId)
  1668. if err != nil && err.Error() != utils.ErrNoRow() {
  1669. br.Msg = "获取失败"
  1670. br.ErrMsg = "获取我的留言列表失败,Err:" + err.Error()
  1671. return
  1672. }
  1673. articleLyjhMap, _ := services.GetLyjhArticleMap()
  1674. articleCollectMap, _ := services.GetCygxArticleCollectMap(user.UserId)
  1675. resp := new(models.CygxCommentListResp)
  1676. for _, comment := range commentlist {
  1677. item := models.CygxArticleCommentResp{
  1678. Id: comment.Id,
  1679. UserId: comment.UserId,
  1680. ArticleId: comment.ArticleId,
  1681. IndustryId: comment.IndustryId,
  1682. ActivityId: comment.ActivityId,
  1683. CreateTime: comment.CreateTime,
  1684. Mobile: comment.Mobile,
  1685. Email: comment.Email,
  1686. CompanyId: comment.CompanyId,
  1687. CompanyName: comment.CompanyName,
  1688. Content: comment.Content,
  1689. Title: comment.Title,
  1690. }
  1691. if comment.ArticleId > 0 {
  1692. item.RedirectType = 1
  1693. } else if comment.IndustryId > 0 {
  1694. item.RedirectType = 3
  1695. } else if comment.ActivityId > 0 {
  1696. item.RedirectType = 2
  1697. }
  1698. item.IsCollect = articleCollectMap[comment.ArticleId]
  1699. item.IsRoadShow = articleLyjhMap[comment.ArticleId]
  1700. resp.List = append(resp.List, &item)
  1701. }
  1702. br.Msg = "获取成功!"
  1703. br.Ret = 200
  1704. br.Success = true
  1705. br.Data = resp
  1706. }
  1707. // @Title 获取我的收藏
  1708. // @Description 获取我的收藏列表
  1709. // @Success 200 {object} models.ArticleCollectListResp
  1710. // @router /collect/list/microRoadshow [get]
  1711. func (this *UserController) MicroRoadshowCollectList() {
  1712. br := new(models.BaseResponse).Init()
  1713. defer func() {
  1714. this.Data["json"] = br
  1715. this.ServeJSON()
  1716. }()
  1717. userId := this.User.UserId
  1718. list, err := models.GetUserMicroRoadshowCollectList(userId)
  1719. if err != nil {
  1720. br.Msg = "获取数据失败"
  1721. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1722. return
  1723. }
  1724. resp := new(models.MicroRoadshowCollectList)
  1725. var audioIds []string
  1726. var videoIds []string
  1727. var activityVideoIds []string
  1728. for _, item := range list {
  1729. if item.ActivityVoiceId > 0 {
  1730. audioIds = append(audioIds, strconv.Itoa(item.ActivityVoiceId))
  1731. } else if item.VideoId > 0 {
  1732. videoIds = append(videoIds, strconv.Itoa(item.VideoId))
  1733. } else if item.ActivityVideoId > 0 {
  1734. activityVideoIds = append(activityVideoIds, strconv.Itoa(item.ActivityVideoId))
  1735. }
  1736. }
  1737. resp.AudioIds = strings.Join(audioIds, ",")
  1738. resp.VideoIds = strings.Join(videoIds, ",")
  1739. resp.ActivityVideoIds = strings.Join(activityVideoIds, ",")
  1740. br.Msg = "获取成功!"
  1741. br.Ret = 200
  1742. br.Success = true
  1743. br.Data = resp
  1744. }
  1745. // @Title 新增埋点
  1746. // @Description 新增埋点接口
  1747. // @Success 200 "新增成功!"
  1748. // @router /tracking [get]
  1749. func (this *UserController) Tracking() {
  1750. br := new(models.BaseResponse).Init()
  1751. defer func() {
  1752. this.Data["json"] = br
  1753. this.ServeJSON()
  1754. }()
  1755. user := this.User
  1756. if user == nil {
  1757. br.Msg = "请登录"
  1758. br.ErrMsg = "请登录,用户信息为空"
  1759. br.Ret = 408
  1760. return
  1761. }
  1762. //item := new(models.CygxPageHistoryRecord)
  1763. //item.UserId = user.UserId
  1764. //item.CreateTime = time.Now()
  1765. //item.Mobile = user.Mobile
  1766. //item.Email = user.Email
  1767. //item.CompanyId = user.CompanyId
  1768. //item.CompanyName = user.CompanyName
  1769. //item.Router = this.Ctx.Request.RequestURI
  1770. //item.PageRouter = this.Ctx.Input.Query("PageRouter")
  1771. //
  1772. //go models.AddCygxPageHistoryRecord(item)
  1773. //
  1774. br.Msg = "新增成功!"
  1775. br.Ret = 200
  1776. br.Success = true
  1777. }
  1778. // @Title 未付费申请试用详情
  1779. // @Description 未付费申请试用详情接口
  1780. // @Param ApplyRecordId query int true "申请ID"
  1781. // @Success 200 {object} models.ArticleCollectListResp
  1782. // @Success 200
  1783. // @router /apply/detail [get]
  1784. func (this *UserController) ApplyDetail() {
  1785. br := new(models.BaseResponse).Init()
  1786. defer func() {
  1787. this.Data["json"] = br
  1788. this.ServeJSON()
  1789. }()
  1790. user := this.User
  1791. if user == nil {
  1792. br.Msg = "请登录"
  1793. br.ErrMsg = "请登录,SysUser Is Empty"
  1794. br.Ret = 408
  1795. return
  1796. }
  1797. resp := new(models.CygxApplyRecordDetialResp)
  1798. applyRecordId, _ := this.GetInt("ApplyRecordId")
  1799. detail, err := models.GetCygxApplyRecordById(applyRecordId)
  1800. if err != nil {
  1801. br.Msg = "获取数据失败"
  1802. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1803. return
  1804. }
  1805. switch detail.RegisterPlatform {
  1806. case 1:
  1807. detail.ApplicationSource = "小程序"
  1808. case 2:
  1809. detail.ApplicationSource = "网页版"
  1810. }
  1811. switch detail.InviteCompanySource {
  1812. case 2:
  1813. detail.ApplicationSource += "(络町)"
  1814. }
  1815. resp.Detail = detail
  1816. br.Msg = "申请成功!"
  1817. br.Ret = 200
  1818. br.Success = true
  1819. br.Data = resp
  1820. }
  1821. // @Title 更改绑定邮箱
  1822. // @Description 更改绑定邮箱接口
  1823. // @Param request body models.Headimgurl true "type json string"
  1824. // @Success 200 {object} models.ArticleDetailFileLink
  1825. // @router /email/binding [post]
  1826. func (this *UserController) EmailBinding() {
  1827. br := new(models.BaseResponse).Init()
  1828. defer func() {
  1829. this.Data["json"] = br
  1830. this.ServeJSON()
  1831. }()
  1832. user := this.User
  1833. if user == nil {
  1834. br.Msg = "请登录"
  1835. br.ErrMsg = "请登录,用户信息为空"
  1836. br.Ret = 408
  1837. return
  1838. }
  1839. var req models.UserEmail
  1840. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1841. if err != nil {
  1842. br.Msg = "参数解析异常!"
  1843. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1844. return
  1845. }
  1846. uid := user.UserId
  1847. if user.Email != "" {
  1848. br.Msg = "邮箱号已存在,请勿重复绑定"
  1849. br.ErrMsg = "邮箱格式错误,请重新输入 Email:" + user.Email
  1850. return
  1851. }
  1852. email := req.Email
  1853. if !utils.ValidateEmailFormatat(req.Email) {
  1854. br.Msg = "邮箱格式错误,请重新输入"
  1855. br.ErrMsg = "邮箱格式错误,请重新输入"
  1856. return
  1857. }
  1858. err = models.UpdateUserEmail(email, uid)
  1859. if err != nil {
  1860. br.Msg = "操作失败"
  1861. br.ErrMsg = "头像信息不能为空"
  1862. }
  1863. br.Ret = 200
  1864. br.Success = true
  1865. br.Msg = "操作成功"
  1866. }