user.go 48 KB

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