user.go 53 KB

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