user.go 50 KB

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