user.go 48 KB

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