user.go 56 KB

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