user.go 52 KB

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