user.go 54 KB

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