user.go 54 KB

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