user.go 52 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883
  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.ArticleId < utils.SummaryArticleId {
  544. list[i].Source = 1
  545. } else {
  546. list[i].Source = 2
  547. }
  548. if mapArticleCollectNum[article.ArticleId] != nil {
  549. list[i].CollectNum = mapArticleCollectNum[article.ArticleId].CollectNum
  550. list[i].Pv = mapArticleCollectNum[article.ArticleId].Pv
  551. list[i].IsCollect = mapArticleCollectNum[article.ArticleId].IsCollect
  552. }
  553. if _, ok := lyjhTypeMap[item.CategoryId]; ok && list[i].ArticleId >= utils.SummaryArticleId {
  554. list[i].IsRoadShow = true
  555. }
  556. }
  557. page := paging.GetPaging(currentIndex, pageSize, total)
  558. resp.List = list
  559. resp.Paging = page
  560. br.Msg = "获取成功!"
  561. br.Ret = 200
  562. br.Success = true
  563. br.Data = resp
  564. }
  565. // @Title 获取申请访谈列表
  566. // @Description 获取申请访谈列表
  567. // @Param PageSize query int true "PageSize"
  568. // @Param CurrentIndex query int true "CurrentIndex"
  569. // @Success 200 {object} models.ArticleInterviewApplyListResp
  570. // @router /interview/apply/list [get]
  571. func (this *UserController) InterviewApplyList() {
  572. br := new(models.BaseResponse).Init()
  573. defer func() {
  574. this.Data["json"] = br
  575. this.ServeJSON()
  576. }()
  577. userId := this.User.UserId
  578. var pageSize, currentIndex, startSize int
  579. pageSize, _ = this.GetInt("PageSize")
  580. currentIndex, _ = this.GetInt("CurrentIndex")
  581. if pageSize <= 0 {
  582. pageSize = utils.PageSize20
  583. }
  584. if currentIndex <= 0 {
  585. currentIndex = 1
  586. }
  587. startSize = utils.StartIndex(currentIndex, pageSize)
  588. total, err := models.GetArticleUserInterviewApplyCount(userId)
  589. if err != nil {
  590. br.Msg = "获取数据失败"
  591. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  592. return
  593. }
  594. list, err := models.GetArticleUserInterviewApplyList(startSize, pageSize, userId)
  595. if err != nil {
  596. br.Msg = "获取数据失败"
  597. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  598. return
  599. }
  600. var articleIds []string
  601. for _, v := range list {
  602. articleIds = append(articleIds, strconv.Itoa(v.ArticleId))
  603. }
  604. articleIdStr := strings.Join(articleIds, ",")
  605. articleMap := make(map[int]*models.ArticleDetail)
  606. if articleIdStr != "" {
  607. articleList, err := models.GetArticleDetailByIdStr(articleIdStr)
  608. if err != nil {
  609. br.Msg = "获取数据失败"
  610. br.ErrMsg = "获取报告详情信息失败,Err:" + err.Error()
  611. return
  612. }
  613. for _, v := range articleList {
  614. if _, ok := articleMap[v.ArticleId]; !ok {
  615. articleMap[v.ArticleId] = v
  616. }
  617. }
  618. }
  619. lenList := len(list)
  620. for i := 0; i < lenList; i++ {
  621. item := list[i]
  622. if articleMap[item.ArticleId] == nil {
  623. continue
  624. }
  625. article := articleMap[item.ArticleId]
  626. bodySub, _ := services.GetReportContentTextSub(article.Body)
  627. list[i].Title = article.Title
  628. list[i].TitleEn = article.TitleEn
  629. list[i].UpdateFrequency = article.UpdateFrequency
  630. list[i].CreateDate = article.CreateDate
  631. list[i].PublishDate = article.PublishDate
  632. list[i].Body = bodySub
  633. list[i].Abstract = article.Abstract
  634. list[i].CategoryName = article.CategoryName
  635. list[i].SubCategoryName = article.SubCategoryName
  636. list[i].ExpertBackground = article.ExpertBackground
  637. list[i].ExpertNumber = article.ExpertNumber
  638. }
  639. page := paging.GetPaging(currentIndex, pageSize, total)
  640. resp := new(models.ArticleInterviewApplyListResp)
  641. resp.List = list
  642. resp.Paging = page
  643. br.Msg = "获取成功!"
  644. br.Ret = 200
  645. br.Success = true
  646. br.Data = resp
  647. }
  648. // @Title 获取浏览历史列表
  649. // @Description 获取浏览历史列表
  650. // @Param PageSize query int true "PageSize"
  651. // @Param CurrentIndex query int true "CurrentIndex"
  652. // @Success 200 {object} models.ArticleBrowseHistoryListResp
  653. // @router /browse/history/list [get]
  654. func (this *UserController) BrowseHistoryList() {
  655. br := new(models.BaseResponse).Init()
  656. defer func() {
  657. this.Data["json"] = br
  658. this.ServeJSON()
  659. }()
  660. userId := this.User.UserId
  661. var pageSize, currentIndex, startSize int
  662. pageSize, _ = this.GetInt("PageSize")
  663. currentIndex, _ = this.GetInt("CurrentIndex")
  664. if pageSize <= 0 {
  665. pageSize = utils.PageSize20
  666. }
  667. if currentIndex <= 0 {
  668. currentIndex = 1
  669. }
  670. startSize = utils.StartIndex(currentIndex, pageSize)
  671. endDate := time.Now().AddDate(0, -1, 0).Format(utils.FormatDate)
  672. total, err := models.GetArticleUserBrowseHistoryCount(userId, endDate)
  673. if err != nil {
  674. br.Msg = "获取数据失败"
  675. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  676. return
  677. }
  678. list, err := models.GetArticleUserBrowseHistoryList(startSize, pageSize, userId, endDate)
  679. if err != nil {
  680. br.Msg = "获取数据失败"
  681. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  682. return
  683. }
  684. resp := new(models.ArticleReportBillboardLIstPageResp)
  685. if len(list) == 0 {
  686. page := paging.GetPaging(currentIndex, pageSize, total)
  687. resp.List = list
  688. resp.Paging = page
  689. br.Msg = "获取成功!"
  690. br.Ret = 200
  691. br.Success = true
  692. br.Data = resp
  693. return
  694. }
  695. var articleIds []string
  696. var condition string
  697. var pars []interface{}
  698. for _, v := range list {
  699. articleIds = append(articleIds, strconv.Itoa(v.ArticleId))
  700. }
  701. articleIdStr := strings.Join(articleIds, ",")
  702. //获取文章关联的产业
  703. pars = make([]interface{}, 0)
  704. condition = ` AND mg.article_id IN ( ` + utils.GetOrmInReplace(len(articleIds)) + ` ) `
  705. pars = append(pars, articleIds)
  706. industrialList, err := models.GetIndustrialListByarticleId(pars, condition)
  707. if err != nil {
  708. br.Msg = "获取失败"
  709. br.ErrMsg = "获取失败,GetSubjectList Err:" + err.Error()
  710. return
  711. }
  712. industrialMap := make(map[int][]*models.IndustrialManagementIdInt)
  713. if len(industrialList) > 0 {
  714. for _, v := range industrialList {
  715. item := new(models.IndustrialManagementIdInt)
  716. item.ArticleId = v.ArticleId
  717. if v.ArticleId > utils.SummaryArticleId {
  718. item.IsResearch = true
  719. }
  720. item.IndustrialManagementId = v.IndustrialManagementId
  721. item.IndustryName = v.IndustryName
  722. industrialMap[v.ArticleId] = append(industrialMap[v.ArticleId], item)
  723. }
  724. }
  725. for k, v := range list {
  726. if len(industrialMap[v.ArticleId]) > 0 {
  727. list[k].List = industrialMap[v.ArticleId]
  728. } else {
  729. list[k].List = make([]*models.IndustrialManagementIdInt, 0)
  730. }
  731. }
  732. articleMap := make(map[int]*models.ArticleDetail)
  733. if articleIdStr != "" {
  734. articleList, err := models.GetArticleDetailByIdStr(articleIdStr)
  735. if err != nil {
  736. br.Msg = "获取数据失败"
  737. br.ErrMsg = "获取报告详情信息失败,Err:" + err.Error()
  738. return
  739. }
  740. for _, v := range articleList {
  741. if _, ok := articleMap[v.ArticleId]; !ok {
  742. articleMap[v.ArticleId] = v
  743. }
  744. }
  745. }
  746. //处理文章PV收藏等数量
  747. mapArticleCollectNum := make(map[int]*models.CygxArticleNum)
  748. if len(articleIds) > 0 {
  749. articleCollectNumList, err := models.GetArticleCollectNum(articleIds, userId)
  750. if err != nil && err.Error() != utils.ErrNoRow() {
  751. br.Msg = "获取失败"
  752. br.ErrMsg = "获取失败,GetArticleCollectNum Err:" + err.Error()
  753. return
  754. }
  755. for _, v := range articleCollectNumList {
  756. mapArticleCollectNum[v.ArticleId] = v
  757. }
  758. }
  759. lenList := len(list)
  760. for i := 0; i < lenList; i++ {
  761. item := list[i]
  762. article := articleMap[item.ArticleId]
  763. if article != nil {
  764. list[i].Title = article.Title
  765. list[i].PublishDate = utils.TimeRemoveHms2(article.PublishDate)
  766. list[i].DepartmentId = article.DepartmentId
  767. list[i].NickName = article.NickName
  768. if article.ArticleId < utils.SummaryArticleId {
  769. list[i].Source = 1
  770. } else {
  771. list[i].Source = 2
  772. }
  773. if mapArticleCollectNum[article.ArticleId] != nil {
  774. list[i].CollectNum = mapArticleCollectNum[article.ArticleId].CollectNum
  775. list[i].Pv = mapArticleCollectNum[article.ArticleId].Pv
  776. list[i].IsCollect = mapArticleCollectNum[article.ArticleId].IsCollect
  777. }
  778. //list[i].TitleEn = article.TitleEn
  779. //list[i].UpdateFrequency = article.UpdateFrequency
  780. //list[i].CreateDate = article.CreateDate
  781. //list[i].Body, _ = services.GetReportContentTextSub(article.Body)
  782. //list[i].Abstract = article.Abstract
  783. //list[i].CategoryName = article.CategoryName
  784. //list[i].SubCategoryName = article.SubCategoryName
  785. }
  786. }
  787. page := paging.GetPaging(currentIndex, pageSize, total)
  788. resp.List = list
  789. resp.Paging = page
  790. br.Msg = "获取成功!"
  791. br.Ret = 200
  792. br.Success = true
  793. br.Data = resp
  794. }
  795. // @Title 未付费申请试用
  796. // @Description 未付费申请试用
  797. // @Param request body models.ApplyTryReq true "type json string"
  798. // @Success 200
  799. // @router /apply/try [post]
  800. func (this *UserController) ApplyTryOut() {
  801. br := new(models.BaseResponse).Init()
  802. defer func() {
  803. this.Data["json"] = br
  804. this.ServeJSON()
  805. }()
  806. user := this.User
  807. if user == nil {
  808. br.Msg = "请登录"
  809. br.ErrMsg = "请登录,SysUser Is Empty"
  810. br.Ret = 408
  811. return
  812. }
  813. mobile := user.Mobile
  814. var req models.ApplyTryReq
  815. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  816. if err != nil {
  817. br.Msg = "参数解析异常!"
  818. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  819. return
  820. }
  821. if req.RealName == "" {
  822. req.RealName = user.RealName
  823. }
  824. if req.CompanyName == "" {
  825. req.CompanyName = user.CompanyName
  826. }
  827. uid := user.UserId
  828. var title string
  829. tryType := req.TryType
  830. detailId := req.DetailId
  831. var isResearch bool // 是否属于研选
  832. if tryType == "Article" {
  833. detail, err := models.GetArticleDetailById(detailId)
  834. if err != nil {
  835. br.Msg = "获取信息失败"
  836. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  837. return
  838. }
  839. title = detail.Title
  840. if detail.ArticleTypeId > 0 {
  841. isResearch = true
  842. }
  843. } else if tryType == "Activity" {
  844. detail, err := models.GetAddActivityInfoById(detailId)
  845. if err != nil {
  846. br.Msg = "操作失败"
  847. br.ErrMsg = "活动ID错误,不存在activityId:" + strconv.Itoa(detailId)
  848. return
  849. }
  850. title = detail.ActivityName
  851. if strings.Contains(detail.ChartPermissionName, utils.CHART_PERMISSION_NAME_YANXUAN) {
  852. isResearch = true
  853. }
  854. } else if tryType == "MicroAudio" {
  855. // 微路演音频
  856. microAudio, e := models.GetCygxActivityVoiceById(detailId)
  857. if e != nil {
  858. br.Msg = "操作失败"
  859. br.ErrMsg = "微路演音频信息有误, 不存在的VoiceId: " + strconv.Itoa(detailId)
  860. return
  861. }
  862. title = microAudio.VoiceName
  863. } else if tryType == "MicroVideo" {
  864. // 微路演视频
  865. microVideo, e := models.GetMicroRoadshowVideoById(detailId)
  866. if e != nil {
  867. br.Msg = "操作失败"
  868. br.ErrMsg = "微路演视频信息有误, 不存在的VideoId: " + strconv.Itoa(detailId)
  869. return
  870. }
  871. title = microVideo.VideoName
  872. } else if tryType == "Researchsummary" {
  873. // 本周研究汇总
  874. ResearchSummaryInfo, e := models.GetCygxResearchSummaryInfoById(detailId)
  875. if e != nil {
  876. br.Msg = "操作失败"
  877. br.ErrMsg = "本周研究汇总信息有误, 不存在的detailId: " + strconv.Itoa(detailId)
  878. return
  879. }
  880. title = ResearchSummaryInfo.Title
  881. } else if tryType == "Minutessummary" {
  882. // 上周纪要汇总
  883. MinutesSummaryInfo, e := models.GetCygxMinutesSummaryInfoById(detailId)
  884. if e != nil {
  885. br.Msg = "操作失败"
  886. br.ErrMsg = "上周纪要汇总信息有误, 不存在的detailId: " + strconv.Itoa(detailId)
  887. return
  888. }
  889. title = MinutesSummaryInfo.Title
  890. } else if tryType == "ReportSelection" {
  891. // 报告精选
  892. ReportSelectionInfo, e := models.GetCygxReportSelectionInfoById(detailId)
  893. if e != nil {
  894. br.Msg = "操作失败"
  895. br.ErrMsg = "报告精选信息有误, 不存在的detailId: " + strconv.Itoa(detailId)
  896. return
  897. }
  898. title = ReportSelectionInfo.Title
  899. } else if tryType == "ProductInterior" {
  900. // 产品内测
  901. ProductInteriorDetail, e := models.GetCygxProductInteriorDetail(detailId)
  902. if e != nil {
  903. br.Msg = "操作失败"
  904. br.ErrMsg = "产品内测信息有误, 不存在的detailId: " + strconv.Itoa(detailId)
  905. return
  906. }
  907. title = ProductInteriorDetail.Title
  908. }
  909. fmt.Println(title)
  910. //缓存校验
  911. cacheKey := fmt.Sprint("xygx:apply_record:add:", uid)
  912. ttlTime := utils.Rc.GetRedisTTL(cacheKey)
  913. if ttlTime > 0 {
  914. br.Msg = "申请失败,申请过于频繁"
  915. br.ErrMsg = "申请失败,申请过于频繁"
  916. return
  917. }
  918. utils.Rc.SetNX(cacheKey, user.Mobile, time.Second*10)
  919. //判断是否已经申请过
  920. applyCount, err := models.GetApplyRecordCount(uid)
  921. if err != nil && err.Error() != utils.ErrNoRow() {
  922. br.Msg = "获取信息失败"
  923. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  924. return
  925. }
  926. if applyCount > 0 {
  927. br.Msg = "您已提交申请,请耐心等待。"
  928. br.IsSendEmail = false
  929. return
  930. }
  931. //判断是否存在申请
  932. var sellerMobile string
  933. if req.ApplyMethod == 2 {
  934. if req.BusinessCardUrl == "" {
  935. br.Msg = "请上传名片"
  936. return
  937. }
  938. if req.RealName == "" {
  939. br.Msg = "请输入姓名"
  940. return
  941. }
  942. if req.CompanyName == "" {
  943. br.Msg = "请输入公司名称"
  944. return
  945. }
  946. if req.BusinessCardUrl != "" && utils.RunMode == "release" {
  947. card, err := services.GetBusinessCard(req.BusinessCardUrl)
  948. if err != nil {
  949. br.Msg = "名片识别失败"
  950. br.ErrMsg = "名片识别失败,Err:" + err.Error()
  951. return
  952. }
  953. mobileStr := strings.Join(card.WordsResult.MOBILE, ",")
  954. isFlag := true
  955. if mobile != "" {
  956. if strings.Contains(mobileStr, mobile) || mobileStr == "" {
  957. isFlag = true
  958. } else {
  959. isFlag = false
  960. }
  961. }
  962. if !isFlag {
  963. //阿里云识别
  964. if utils.RunMode == "release" {
  965. aliyunResult, err := services.AliyunBusinessCard(req.BusinessCardUrl)
  966. if err != nil {
  967. br.Msg = "识别失败"
  968. br.ErrMsg = "识别失败,Err:" + err.Error()
  969. return
  970. }
  971. if !aliyunResult.Success {
  972. br.Msg = "识别失败"
  973. br.ErrMsg = "识别失败"
  974. return
  975. }
  976. mobileStr := strings.Join(aliyunResult.TelCell, ",")
  977. if mobile != "" {
  978. if strings.Contains(mobileStr, mobile) {
  979. isFlag = true
  980. } else {
  981. isFlag = false
  982. }
  983. }
  984. }
  985. }
  986. if !isFlag {
  987. br.Msg = "名片手机号与所填手机号不匹配,请重新填写"
  988. br.ErrMsg = "mobile:" + mobile
  989. return
  990. }
  991. }
  992. }
  993. //获取销售信息
  994. sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  995. if err != nil && err.Error() != utils.ErrNoRow() {
  996. br.Msg = "申请失败"
  997. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  998. return
  999. }
  1000. //用户状态,1:潜在客户 、2:现有客户 、3:FICC客户 、4:现有客户(正式,无对应权限) 、5:现有客户(试用,无对应权限) 、6:现有客户(试用暂停) 、7:现有客户(冻结) 、8:现有客户(流失)?
  1001. CompanyIdType := 1
  1002. applyMethod := ""
  1003. if sellerItem != nil {
  1004. companyItem, err := models.GetCompanyDetailById(user.CompanyId)
  1005. if err != nil && err.Error() != utils.ErrNoRow() {
  1006. br.Msg = "获取信息失败"
  1007. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  1008. return
  1009. }
  1010. if companyItem != nil && companyItem.CompanyId > 0 {
  1011. companyProduct, err := models.GetCompanyProductDetail(user.CompanyId, 2)
  1012. if err != nil && err.Error() != utils.ErrNoRow() {
  1013. br.Msg = "获取信息失败"
  1014. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  1015. return
  1016. }
  1017. if companyProduct != nil && companyProduct.IsSuspend == 1 {
  1018. CompanyIdType = 6
  1019. } else {
  1020. switch companyItem.Status {
  1021. case "正式":
  1022. CompanyIdType = 4
  1023. case "试用":
  1024. CompanyIdType = 5
  1025. case "冻结":
  1026. CompanyIdType = 7
  1027. case "流失":
  1028. CompanyIdType = 8
  1029. }
  1030. }
  1031. applyMethod = companyItem.Status + "客户申请"
  1032. if detailId > 0 {
  1033. if companyProduct != nil && companyProduct.IsSuspend == 1 {
  1034. applyMethod = "试用暂停客户"
  1035. } else {
  1036. if companyItem.Status == "正式" || companyItem.Status == "试用" {
  1037. applyMethod = companyItem.Status + "客户申请,无对应权限"
  1038. } else if companyItem.Status == "冻结" || companyItem.Status == "流失" {
  1039. applyMethod = companyItem.Status + "客户"
  1040. }
  1041. }
  1042. applyMethod = applyMethod + "," + title
  1043. }
  1044. openIpItem, _ := models.GetUserRecordByMobile(4, sellerItem.Mobile)
  1045. if openIpItem != nil && openIpItem.OpenId != "" {
  1046. if req.ApplyMethod != 2 {
  1047. req.RealName = user.RealName
  1048. req.CompanyName = user.CompanyName
  1049. }
  1050. //go services.SendPermissionApplyTemplateMsg(req.RealName, req.CompanyName, mobile, applyMethod, openIpItem)
  1051. }
  1052. }
  1053. } else {
  1054. //获取销售信息
  1055. sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 1)
  1056. if err != nil && err.Error() != utils.ErrNoRow() {
  1057. br.Msg = "申请失败"
  1058. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  1059. return
  1060. }
  1061. if sellerItem != nil {
  1062. CompanyIdType = 3
  1063. applyMethod = "FICC客户"
  1064. } else {
  1065. CompanyIdType = 1
  1066. applyMethod = "潜在客户"
  1067. }
  1068. if detailId > 0 {
  1069. applyMethod = applyMethod + "," + title
  1070. }
  1071. }
  1072. item := new(models.CygxApplyRecord)
  1073. item.UserId = user.UserId
  1074. item.BusinessCardUrl = req.BusinessCardUrl
  1075. item.RealName = req.RealName
  1076. item.CompanyName = req.CompanyName
  1077. item.Mobile = user.Mobile
  1078. item.CreateTime = time.Now()
  1079. item.ApplyMethod = req.ApplyMethod
  1080. item.CompanyIdPay = user.CompanyId
  1081. item.CompanyNamePay = user.CompanyName
  1082. item.CompanyIdType = CompanyIdType
  1083. if user.InviteCompany == utils.LUODING_CODE && user.CompanyId == 1 {
  1084. //如果是潜在客户就标记来源
  1085. item.InviteCompanySource = 2
  1086. }
  1087. item.RegisterPlatform = utils.REGISTER_PLATFORM
  1088. err = models.AddApplyRecord(item)
  1089. if err != nil {
  1090. br.Msg = "申请失败"
  1091. br.ErrMsg = "申请失败,Err:" + err.Error()
  1092. return
  1093. }
  1094. if sellerItem == nil {
  1095. go services.SendPermissionApplyTemplateMsgAdmin(req, mobile, applyMethod, isResearch)
  1096. } else {
  1097. openIpItem, _ := models.GetUserRecordByMobile(4, sellerItem.Mobile)
  1098. if openIpItem != nil && openIpItem.OpenId != "" {
  1099. go services.SendPermissionApplyTemplateMsg(req.RealName, req.CompanyName, mobile, applyMethod, openIpItem)
  1100. }
  1101. }
  1102. //添加成功后,设置5分钟缓存,不允许重复添加
  1103. //utils.Rc.SetNX(cacheKey, user.Mobile, time.Second*60)
  1104. br.Msg = "申请成功!"
  1105. br.Ret = 200
  1106. br.Success = true
  1107. br.Data = sellerMobile
  1108. }
  1109. // @Title 是否需要填写区号
  1110. // @Description 获取是否需要填写区号接口
  1111. // @Success 200 {object} models.CountryCode
  1112. // @router /countryCcode/isNeedAdd [get]
  1113. func (this *UserController) CountryCcode() {
  1114. br := new(models.BaseResponse).Init()
  1115. defer func() {
  1116. this.Data["json"] = br
  1117. this.ServeJSON()
  1118. }()
  1119. user := this.User
  1120. uid := user.UserId
  1121. if user == nil {
  1122. br.Msg = "请登录"
  1123. br.ErrMsg = "请登录,用户信息为空"
  1124. br.Ret = 408
  1125. return
  1126. }
  1127. //if uid == 0 {
  1128. // br.Msg = "请登录"
  1129. // br.ErrMsg = "请登录,用户信息为空"
  1130. // br.Ret = 408
  1131. // return
  1132. //}
  1133. resp := new(models.CountryCode)
  1134. if user.CountryCode == "" && len(user.Mobile) >= 11 {
  1135. err := models.ChangeUserOutboundMobileByMobile(uid)
  1136. if err != nil {
  1137. br.Msg = "操作失败"
  1138. br.ErrMsg = "操作失败,Err:" + err.Error()
  1139. return
  1140. }
  1141. }
  1142. if user.CountryCode == "" && user.Mobile != "" && len(user.Mobile) < 11 {
  1143. resp.IsNeedAddCountryCode = true
  1144. }
  1145. if user.OutboundMobile != "" {
  1146. resp.IsNeedAddCountryCode = false
  1147. }
  1148. br.Ret = 200
  1149. br.Success = true
  1150. br.Msg = "获取成功"
  1151. br.Data = resp
  1152. }
  1153. // @Title 上传用户区号
  1154. // @Description 上传用户区号接口
  1155. // @Param request body models.CountryCodeItem true "type json string"
  1156. // @Success Ret=200 新增成功
  1157. // @router /countryCcode/Add [POST]
  1158. func (this *UserController) AddCountryCcode() {
  1159. br := new(models.BaseResponse).Init()
  1160. defer func() {
  1161. this.Data["json"] = br
  1162. this.ServeJSON()
  1163. }()
  1164. user := this.User
  1165. if user == nil {
  1166. br.Msg = "请登录"
  1167. br.ErrMsg = "请登录,用户信息为空"
  1168. br.Ret = 408
  1169. return
  1170. }
  1171. var req models.CountryCodeItem
  1172. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1173. if err != nil {
  1174. br.Msg = "参数解析异常!"
  1175. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1176. return
  1177. }
  1178. err = models.AddCountryCode(req.CountryCode, user)
  1179. if err != nil {
  1180. br.Msg = "获取信息失败"
  1181. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  1182. return
  1183. }
  1184. br.Ret = 200
  1185. br.Success = true
  1186. br.Msg = "新增成功"
  1187. }
  1188. // @Title 用户修改外呼手机号以及区号
  1189. // @Description 用户修改外呼手机号以及区号接口
  1190. // @Param request body models.OutboundMobileItem true "type json string"
  1191. // @Success Ret=200 操作成功
  1192. // @router /countryCcode/addOutboundMobile [POST]
  1193. func (this *UserController) AddOutboundMobile() {
  1194. br := new(models.BaseResponse).Init()
  1195. defer func() {
  1196. this.Data["json"] = br
  1197. this.ServeJSON()
  1198. }()
  1199. user := this.User
  1200. uid := user.UserId
  1201. if user == nil {
  1202. br.Msg = "请登录"
  1203. br.ErrMsg = "请登录,用户信息为空"
  1204. br.Ret = 408
  1205. return
  1206. }
  1207. var req models.OutboundMobileItem
  1208. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1209. if err != nil {
  1210. br.Msg = "参数解析异常!"
  1211. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1212. return
  1213. }
  1214. if !utils.ValidateFixedTelephoneFormatatEasy(req.OutboundMobile) {
  1215. br.Msg = "号码格式有误,请重新填写!"
  1216. br.ErrMsg = "号码格式有误,请重新填写" + req.OutboundMobile
  1217. return
  1218. }
  1219. if req.OutboundMobile == "" {
  1220. br.Msg = "请填写区号!"
  1221. return
  1222. }
  1223. item := new(models.OutboundMobileItem)
  1224. item.OutboundMobile = req.OutboundMobile
  1225. item.OutboundCountryCode = req.OutboundCountryCode
  1226. item.ActivityId = req.ActivityId
  1227. if req.ActivityId == 0 {
  1228. err = models.AddOutboundMobile(item, uid)
  1229. } else {
  1230. if user.Mobile == "" && user.OutboundMobile == "" {
  1231. items := new(models.CygxActivitySignup)
  1232. items.UserId = uid
  1233. items.ActivityId = req.ActivityId
  1234. items.CreateTime = time.Now()
  1235. items.Mobile = user.Mobile
  1236. items.Email = user.Email
  1237. items.CompanyId = user.CompanyId
  1238. items.CompanyName = user.CompanyName
  1239. items.SignupType = 1
  1240. items.FailType = 0
  1241. items.DoFailType = 0
  1242. items.OutboundMobile = req.OutboundMobile
  1243. items.CountryCode = req.OutboundCountryCode
  1244. _, err = models.AddActivitySignupFromEmail(items)
  1245. } else {
  1246. total, err := models.GetActivityCountByIdWithUid(item.ActivityId, uid)
  1247. if total == 0 {
  1248. br.Msg = "报名信息不存在"
  1249. br.ErrMsg = "报名信息不存在,Err:" + "活动ActivityId:" + strconv.Itoa(item.ActivityId) + "用户Uid:" + strconv.Itoa(uid)
  1250. return
  1251. }
  1252. if err != nil {
  1253. br.Msg = "操作失败"
  1254. br.ErrMsg = "操作失败,Err:" + err.Error()
  1255. return
  1256. }
  1257. err = models.AddOutboundMobile(item, uid)
  1258. }
  1259. }
  1260. if err != nil {
  1261. br.Msg = "操作失败"
  1262. br.ErrMsg = "操作失败,Err:" + err.Error()
  1263. return
  1264. }
  1265. br.Ret = 200
  1266. br.Success = true
  1267. br.Msg = "操作成功"
  1268. }
  1269. // @Title 获取我的提问
  1270. // @Description 获取我的提问列表
  1271. // @Success 200 {object} models.CygxAskListResp
  1272. // @router /ask/list [get]
  1273. func (this *UserController) AskList() {
  1274. br := new(models.BaseResponse).Init()
  1275. defer func() {
  1276. this.Data["json"] = br
  1277. this.ServeJSON()
  1278. }()
  1279. user := this.User
  1280. if user == nil {
  1281. br.Msg = "请登录"
  1282. br.ErrMsg = "请登录,用户信息为空"
  1283. br.Ret = 408
  1284. return
  1285. }
  1286. userId := this.User.UserId
  1287. listActcivity, err := models.GetActivityAskList(userId)
  1288. if err != nil && err.Error() != utils.ErrNoRow() {
  1289. br.Msg = "获取失败"
  1290. br.ErrMsg = "获取活动问题失败,Err:" + err.Error()
  1291. return
  1292. }
  1293. for _, v := range listActcivity {
  1294. v.AskType = "Activity"
  1295. }
  1296. listArticle, err := models.GetArticleAskList(userId)
  1297. if err != nil && err.Error() != utils.ErrNoRow() {
  1298. br.Msg = "获取失败"
  1299. br.ErrMsg = "获取文章问题失败,Err:" + err.Error()
  1300. return
  1301. }
  1302. for _, v := range listArticle {
  1303. v.AskType = "Report"
  1304. listActcivity = append(listActcivity, v)
  1305. }
  1306. resp := new(models.CygxAskListResp)
  1307. resp.List = listActcivity
  1308. br.Msg = "获取成功!"
  1309. br.Ret = 200
  1310. br.Success = true
  1311. br.Data = resp
  1312. }
  1313. // @Title 是否展示免费试用按钮
  1314. // @Description 获取是否展示免费试用按钮接口
  1315. // @Param request body models.IsShow true "type json string"
  1316. // @Success 200
  1317. // @router /isShow/freeButton [get]
  1318. func (this *UserController) IsShow() {
  1319. br := new(models.BaseResponse).Init()
  1320. defer func() {
  1321. this.Data["json"] = br
  1322. this.ServeJSON()
  1323. }()
  1324. user := this.User
  1325. if user == nil {
  1326. br.Msg = "请重新登录"
  1327. br.Ret = 408
  1328. return
  1329. }
  1330. var resp models.IsShow
  1331. detail, err := models.GetConfigByCode("free_trial_card")
  1332. if err != nil {
  1333. br.Msg = "获取数据失败"
  1334. br.ErrMsg = "城市配置信息失败,Err:" + err.Error()
  1335. return
  1336. }
  1337. companyDetail, err := models.GetCompanyDetailByIdGroup(user.CompanyId)
  1338. if err != nil && err.Error() != utils.ErrNoRow() {
  1339. br.Msg = "获取数据失败!"
  1340. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  1341. return
  1342. }
  1343. count, err := models.CountCygxUserFreeeButton(user.UserId)
  1344. if err != nil && err.Error() != utils.ErrNoRow() {
  1345. br.Msg = "获取数据失败!"
  1346. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  1347. return
  1348. }
  1349. if companyDetail != nil && companyDetail.IsSuspend == 0 {
  1350. if detail.ConfigValue == "1" && (companyDetail.Status == "正式" || companyDetail.Status == "试用" || companyDetail.Status == "永续") && count == 0 {
  1351. resp.IsShow = true
  1352. }
  1353. }
  1354. br.Ret = 200
  1355. br.Success = true
  1356. br.Data = resp
  1357. }
  1358. // @Title 隐藏当天的按钮
  1359. // @Description 隐藏当天的按钮接口
  1360. // @Success 200
  1361. // @router /freeButton/update [post]
  1362. func (this *UserController) FreeButtonUpdate() {
  1363. br := new(models.BaseResponse).Init()
  1364. defer func() {
  1365. this.Data["json"] = br
  1366. this.ServeJSON()
  1367. }()
  1368. user := this.User
  1369. if user == nil {
  1370. br.Msg = "请重新登录"
  1371. br.Ret = 408
  1372. return
  1373. }
  1374. count, err := models.CountCygxUserFreeeButtonByUser(user.UserId)
  1375. if err != nil {
  1376. br.Msg = "获取数据失败!"
  1377. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  1378. return
  1379. }
  1380. if count == 0 {
  1381. item := new(models.CygxUserFreeeButton)
  1382. item.UserId = user.UserId
  1383. item.CompanyId = user.CompanyId
  1384. item.CreateTime = time.Now()
  1385. item.ModifyTime = time.Now()
  1386. item.EffectiveTime = time.Now().Format(utils.FormatDate)
  1387. _, err := models.AddCygxUserFreeeButton(item)
  1388. if err != nil {
  1389. br.Msg = "操作失败!"
  1390. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  1391. return
  1392. }
  1393. } else {
  1394. err := models.UpdateCygxUserFreeeButton(user.UserId)
  1395. if err != nil {
  1396. br.Msg = "操作失败!"
  1397. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  1398. return
  1399. }
  1400. }
  1401. br.Ret = 200
  1402. br.Success = true
  1403. br.Msg = "操作成功!"
  1404. }
  1405. // @Title 权限弹窗是否展示免费月卡
  1406. // @Description 获取权限弹窗是否展示免费月卡接口
  1407. // @Param request body models.IsShow true "type json string"
  1408. // @Success 200
  1409. // @router /isShow/alert [get]
  1410. func (this *UserController) AlertIsShow() {
  1411. br := new(models.BaseResponse).Init()
  1412. defer func() {
  1413. this.Data["json"] = br
  1414. this.ServeJSON()
  1415. }()
  1416. user := this.User
  1417. if user == nil {
  1418. br.Msg = "请重新登录"
  1419. br.Ret = 408
  1420. return
  1421. }
  1422. var resp models.IsShow
  1423. detail, err := models.GetConfigByCode("free_trial_card")
  1424. if err != nil {
  1425. br.Msg = "获取数据失败"
  1426. br.ErrMsg = "城市配置信息失败,Err:" + err.Error()
  1427. return
  1428. }
  1429. if user.CompanyId == 1 && detail.ConfigValue == "1" {
  1430. resp.IsShow = true
  1431. }
  1432. br.Ret = 200
  1433. br.Success = true
  1434. br.Data = resp
  1435. }
  1436. // @Title 分享的时候是否展示免费月卡
  1437. // @Description 获取权限弹窗是否展示免费月卡接口
  1438. // @Param request body models.IsShow true "type json string"
  1439. // @Success 200
  1440. // @router /isShow/share [get]
  1441. func (this *UserController) ShareIsShow() {
  1442. br := new(models.BaseResponse).Init()
  1443. defer func() {
  1444. this.Data["json"] = br
  1445. this.ServeJSON()
  1446. }()
  1447. user := this.User
  1448. if user == nil {
  1449. br.Msg = "请重新登录"
  1450. br.Ret = 408
  1451. return
  1452. }
  1453. var resp models.IsShow
  1454. detail, err := models.GetConfigByCode("free_trial_card")
  1455. if err != nil {
  1456. br.Msg = "获取数据失败"
  1457. br.ErrMsg = "城市配置信息失败,Err:" + err.Error()
  1458. return
  1459. }
  1460. if user.CompanyId != 16 && detail.ConfigValue == "1" {
  1461. resp.IsShow = true
  1462. }
  1463. resp.LinkWxExplain = utils.LINK_WX_EXPLAIN
  1464. br.Ret = 200
  1465. br.Success = true
  1466. br.Data = resp
  1467. }
  1468. // @Title 更改用户微信头像
  1469. // @Description 更改用户微信头像
  1470. // @Param request body models.Headimgurl true "type json string"
  1471. // @Success 200 {object} models.ArticleDetailFileLink
  1472. // @router /headimgurl/update [post]
  1473. func (this *UserController) HeadimgurlUpdate() {
  1474. br := new(models.BaseResponse).Init()
  1475. defer func() {
  1476. this.Data["json"] = br
  1477. this.ServeJSON()
  1478. }()
  1479. user := this.User
  1480. if user == nil {
  1481. br.Msg = "请登录"
  1482. br.ErrMsg = "请登录,用户信息为空"
  1483. br.Ret = 408
  1484. return
  1485. }
  1486. var req models.Headimgurl
  1487. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1488. if err != nil {
  1489. br.Msg = "参数解析异常!"
  1490. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1491. return
  1492. }
  1493. uid := user.UserId
  1494. headimgurl := req.Headimgurl
  1495. if headimgurl == "" {
  1496. br.Msg = "操作失败"
  1497. br.ErrMsg = "头像信息不能为空"
  1498. return
  1499. }
  1500. err = models.UpdateUserHeadimgurl(headimgurl, uid)
  1501. if err != nil {
  1502. br.Msg = "操作失败"
  1503. br.ErrMsg = "头像信息不能为空"
  1504. }
  1505. br.Ret = 200
  1506. br.Success = true
  1507. br.Msg = "操作成功"
  1508. }
  1509. // @Title 登录 (无需token)
  1510. // @Description 登录接口 (无需token)
  1511. // @Param request body models.LoginReq true "type json string"
  1512. // @Success 200 {object} models.LoginResp
  1513. // @router /loginPublic [post]
  1514. func (this *UserCommonController) LoginPublic() {
  1515. br := new(models.BaseResponse).Init()
  1516. defer func() {
  1517. this.Data["json"] = br
  1518. this.ServeJSON()
  1519. }()
  1520. var req models.LoginReq
  1521. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1522. if err != nil {
  1523. br.Msg = "参数解析异常!"
  1524. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1525. return
  1526. }
  1527. mobile := strings.Trim(req.Mobile, " ")
  1528. if req.Mobile == "" {
  1529. br.Msg = "参数错误"
  1530. br.ErrMsg = "参数错误,手机号为空 为空"
  1531. return
  1532. }
  1533. item, err := models.GetMsgCode(req.Mobile, req.VCode)
  1534. if err != nil {
  1535. if err.Error() == utils.ErrNoRow() {
  1536. br.Msg = "验证码错误,请重新输入"
  1537. br.ErrMsg = "校验验证码失败,Err:" + err.Error()
  1538. return
  1539. } else {
  1540. br.Msg = "验证码错误,请重新输入"
  1541. br.ErrMsg = "校验验证码失败,Err:" + err.Error()
  1542. return
  1543. }
  1544. }
  1545. if item == nil {
  1546. br.Msg = "验证码错误,请重新输入"
  1547. return
  1548. }
  1549. if len(req.Mobile) >= 11 && req.CountryCode == "" {
  1550. req.CountryCode = "86"
  1551. }
  1552. var token string
  1553. tokenItem, err := models.GetSessionMobileTokenByOpenId(mobile)
  1554. if err != nil && err.Error() != utils.ErrNoRow() {
  1555. br.Msg = "登录失败"
  1556. br.ErrMsg = "登录失败,获取token失败:" + err.Error()
  1557. return
  1558. }
  1559. if tokenItem == nil || (err != nil && err.Error() == utils.ErrNoRow()) {
  1560. timeUnix := time.Now().Unix()
  1561. timeUnixStr := strconv.FormatInt(timeUnix, 10)
  1562. token = utils.MD5(mobile) + utils.MD5(timeUnixStr)
  1563. //新增session
  1564. {
  1565. session := new(models.CygxSessionMobile)
  1566. session.Mobile = mobile
  1567. session.CreatedTime = time.Now()
  1568. session.LastUpdatedTime = time.Now()
  1569. session.ExpireTime = time.Now().AddDate(0, 1, 0)
  1570. session.AccessToken = token
  1571. err = models.AddCygxSessionMobile(session)
  1572. if err != nil {
  1573. br.Msg = "登录失败"
  1574. br.ErrMsg = "登录失败,新增用户session信息失败:" + err.Error()
  1575. return
  1576. }
  1577. }
  1578. } else {
  1579. token = tokenItem.AccessToken
  1580. }
  1581. resp := new(models.LoginResp)
  1582. resp.Authorization = token
  1583. br.Ret = 200
  1584. br.Success = true
  1585. br.Data = resp
  1586. br.Msg = "登录成功"
  1587. }
  1588. // @Title 获取我的留言
  1589. // @Description 获取我的留言列表
  1590. // @Success 200 {object} models.CygxCommentListResp
  1591. // @router /comment/list [get]
  1592. func (this *UserController) CommnetList() {
  1593. br := new(models.BaseResponse).Init()
  1594. defer func() {
  1595. this.Data["json"] = br
  1596. this.ServeJSON()
  1597. }()
  1598. user := this.User
  1599. if user == nil {
  1600. br.Msg = "请登录"
  1601. br.ErrMsg = "请登录,用户信息为空"
  1602. br.Ret = 408
  1603. return
  1604. }
  1605. userId := this.User.UserId
  1606. commentlist, err := models.GetCommentList(userId)
  1607. if err != nil && err.Error() != utils.ErrNoRow() {
  1608. br.Msg = "获取失败"
  1609. br.ErrMsg = "获取我的留言列表失败,Err:" + err.Error()
  1610. return
  1611. }
  1612. articleLyjhMap, _ := services.GetLyjhArticleMap()
  1613. articleCollectMap, _ := services.GetCygxArticleCollectMap(user.UserId)
  1614. resp := new(models.CygxCommentListResp)
  1615. for _, comment := range commentlist {
  1616. item := models.CygxArticleCommentResp{
  1617. Id: comment.Id,
  1618. UserId: comment.UserId,
  1619. ArticleId: comment.ArticleId,
  1620. IndustryId: comment.IndustryId,
  1621. ActivityId: comment.ActivityId,
  1622. CreateTime: comment.CreateTime,
  1623. Mobile: comment.Mobile,
  1624. Email: comment.Email,
  1625. CompanyId: comment.CompanyId,
  1626. CompanyName: comment.CompanyName,
  1627. Content: comment.Content,
  1628. Title: comment.Title,
  1629. }
  1630. if comment.ArticleId > 0 {
  1631. item.RedirectType = 1
  1632. } else if comment.IndustryId > 0 {
  1633. item.RedirectType = 3
  1634. } else if comment.ActivityId > 0 {
  1635. item.RedirectType = 2
  1636. }
  1637. item.IsCollect = articleCollectMap[comment.ArticleId]
  1638. item.IsRoadShow = articleLyjhMap[comment.ArticleId]
  1639. resp.List = append(resp.List, &item)
  1640. }
  1641. br.Msg = "获取成功!"
  1642. br.Ret = 200
  1643. br.Success = true
  1644. br.Data = resp
  1645. }
  1646. // @Title 获取我的收藏
  1647. // @Description 获取我的收藏列表
  1648. // @Success 200 {object} models.ArticleCollectListResp
  1649. // @router /collect/list/microRoadshow [get]
  1650. func (this *UserController) MicroRoadshowCollectList() {
  1651. br := new(models.BaseResponse).Init()
  1652. defer func() {
  1653. this.Data["json"] = br
  1654. this.ServeJSON()
  1655. }()
  1656. userId := this.User.UserId
  1657. list, err := models.GetUserMicroRoadshowCollectList(userId)
  1658. if err != nil {
  1659. br.Msg = "获取数据失败"
  1660. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1661. return
  1662. }
  1663. resp := new(models.MicroRoadshowCollectList)
  1664. var audioIds []string
  1665. var videoIds []string
  1666. var activityVideoIds []string
  1667. for _, item := range list {
  1668. if item.ActivityVoiceId > 0 {
  1669. audioIds = append(audioIds, strconv.Itoa(item.ActivityVoiceId))
  1670. } else if item.VideoId > 0 {
  1671. videoIds = append(videoIds, strconv.Itoa(item.VideoId))
  1672. } else if item.ActivityVideoId > 0 {
  1673. activityVideoIds = append(activityVideoIds, strconv.Itoa(item.ActivityVideoId))
  1674. }
  1675. }
  1676. resp.AudioIds = strings.Join(audioIds, ",")
  1677. resp.VideoIds = strings.Join(videoIds, ",")
  1678. resp.ActivityVideoIds = strings.Join(activityVideoIds, ",")
  1679. br.Msg = "获取成功!"
  1680. br.Ret = 200
  1681. br.Success = true
  1682. br.Data = resp
  1683. }
  1684. // @Title 新增埋点
  1685. // @Description 新增埋点接口
  1686. // @Success 200 "新增成功!"
  1687. // @router /tracking [get]
  1688. func (this *UserController) Tracking() {
  1689. br := new(models.BaseResponse).Init()
  1690. defer func() {
  1691. this.Data["json"] = br
  1692. this.ServeJSON()
  1693. }()
  1694. user := this.User
  1695. if user == nil {
  1696. br.Msg = "请登录"
  1697. br.ErrMsg = "请登录,用户信息为空"
  1698. br.Ret = 408
  1699. return
  1700. }
  1701. //item := new(models.CygxPageHistoryRecord)
  1702. //item.UserId = user.UserId
  1703. //item.CreateTime = time.Now()
  1704. //item.Mobile = user.Mobile
  1705. //item.Email = user.Email
  1706. //item.CompanyId = user.CompanyId
  1707. //item.CompanyName = user.CompanyName
  1708. //item.Router = this.Ctx.Request.RequestURI
  1709. //item.PageRouter = this.Ctx.Input.Query("PageRouter")
  1710. //
  1711. //go models.AddCygxPageHistoryRecord(item)
  1712. //
  1713. br.Msg = "新增成功!"
  1714. br.Ret = 200
  1715. br.Success = true
  1716. }
  1717. // @Title 未付费申请试用详情
  1718. // @Description 未付费申请试用详情接口
  1719. // @Param ApplyRecordId query int true "申请ID"
  1720. // @Success 200 {object} models.ArticleCollectListResp
  1721. // @Success 200
  1722. // @router /apply/detail [get]
  1723. func (this *UserController) ApplyDetail() {
  1724. br := new(models.BaseResponse).Init()
  1725. defer func() {
  1726. this.Data["json"] = br
  1727. this.ServeJSON()
  1728. }()
  1729. user := this.User
  1730. if user == nil {
  1731. br.Msg = "请登录"
  1732. br.ErrMsg = "请登录,SysUser Is Empty"
  1733. br.Ret = 408
  1734. return
  1735. }
  1736. resp := new(models.CygxApplyRecordDetialResp)
  1737. applyRecordId, _ := this.GetInt("ApplyRecordId")
  1738. detail, err := models.GetCygxApplyRecordById(applyRecordId)
  1739. if err != nil {
  1740. br.Msg = "获取数据失败"
  1741. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1742. return
  1743. }
  1744. switch detail.RegisterPlatform {
  1745. case 1:
  1746. detail.ApplicationSource = "小程序"
  1747. case 2:
  1748. detail.ApplicationSource = "网页版"
  1749. }
  1750. switch detail.InviteCompanySource {
  1751. case 2:
  1752. detail.ApplicationSource += "(络町)"
  1753. }
  1754. resp.Detail = detail
  1755. br.Msg = "申请成功!"
  1756. br.Ret = 200
  1757. br.Success = true
  1758. br.Data = resp
  1759. }
  1760. // @Title 更改绑定邮箱
  1761. // @Description 更改绑定邮箱接口
  1762. // @Param request body models.Headimgurl true "type json string"
  1763. // @Success 200 {object} models.ArticleDetailFileLink
  1764. // @router /email/binding [post]
  1765. func (this *UserController) EmailBinding() {
  1766. br := new(models.BaseResponse).Init()
  1767. defer func() {
  1768. this.Data["json"] = br
  1769. this.ServeJSON()
  1770. }()
  1771. user := this.User
  1772. if user == nil {
  1773. br.Msg = "请登录"
  1774. br.ErrMsg = "请登录,用户信息为空"
  1775. br.Ret = 408
  1776. return
  1777. }
  1778. var req models.UserEmail
  1779. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1780. if err != nil {
  1781. br.Msg = "参数解析异常!"
  1782. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1783. return
  1784. }
  1785. uid := user.UserId
  1786. if user.Email != "" {
  1787. br.Msg = "邮箱号已存在,请勿重复绑定"
  1788. br.ErrMsg = "邮箱格式错误,请重新输入 Email:" + user.Email
  1789. return
  1790. }
  1791. email := req.Email
  1792. if !utils.ValidateEmailFormatat(req.Email) {
  1793. br.Msg = "邮箱格式错误,请重新输入"
  1794. br.ErrMsg = "邮箱格式错误,请重新输入"
  1795. return
  1796. }
  1797. err = models.UpdateUserEmail(email, uid)
  1798. if err != nil {
  1799. br.Msg = "操作失败"
  1800. br.ErrMsg = "头像信息不能为空"
  1801. }
  1802. br.Ret = 200
  1803. br.Success = true
  1804. br.Msg = "操作成功"
  1805. }