user.go 56 KB

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