user.go 53 KB

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