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