user.go 55 KB

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