user.go 53 KB

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