user.go 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963
  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. inviteShareCode := req.InviteShareCode
  46. unionId := this.User.UnionId
  47. openId := this.User.OpenId
  48. if unionId == "" {
  49. br.Msg = "参数错误"
  50. br.ErrMsg = "参数错误,unionId 为空"
  51. return
  52. }
  53. if req.LoginType == 1 || req.LoginType == 3 {
  54. if req.Mobile == "" {
  55. br.Msg = "参数错误"
  56. br.ErrMsg = "参数错误,手机号为空 为空"
  57. return
  58. }
  59. if req.LoginType == 3 {
  60. item, err := models.GetMsgCode(req.Mobile, req.VCode)
  61. if err != nil {
  62. if err.Error() == utils.ErrNoRow() {
  63. br.Msg = "验证码错误,请重新输入"
  64. br.ErrMsg = "校验验证码失败,Err:" + err.Error()
  65. return
  66. } else {
  67. br.Msg = "验证码错误,请重新输入"
  68. br.ErrMsg = "校验验证码失败,Err:" + err.Error()
  69. return
  70. }
  71. }
  72. if item == nil {
  73. br.Msg = "验证码错误,请重新输入"
  74. return
  75. }
  76. }
  77. req.Mobile = strings.Trim(req.Mobile, " ")
  78. } else if req.LoginType == 2 {
  79. if req.Email == "" {
  80. br.ErrMsg = "邮箱不能为空,请输入邮箱"
  81. br.Msg = "邮箱不能为空,请输入邮箱"
  82. return
  83. }
  84. if !utils.ValidateEmailFormatat(req.Email) {
  85. br.ErrMsg = "邮箱格式错误,请重新输入"
  86. br.Msg = "邮箱格式错误,请重新输入"
  87. return
  88. }
  89. item, err := models.GetMsgCode(req.Email, req.VCode)
  90. if err != nil {
  91. if err.Error() == utils.ErrNoRow() {
  92. br.Msg = "验证码错误,请重新输入"
  93. br.ErrMsg = "校验验证码失败,Err:" + err.Error()
  94. return
  95. } else {
  96. br.Msg = "验证码错误,请重新输入"
  97. br.ErrMsg = "校验验证码失败,Err:" + err.Error()
  98. return
  99. }
  100. }
  101. if item == nil {
  102. br.Msg = "验证码错误,请重新输入"
  103. return
  104. }
  105. } else {
  106. br.Msg = "无效的登录方式"
  107. br.ErrMsg = "无效的登录方式,Err:"
  108. return
  109. }
  110. if len(req.Mobile) >= 11 && req.CountryCode == "" {
  111. req.CountryCode = "86"
  112. }
  113. user, err = services.BindWxUser(openId, req.Mobile, req.Email, req.CountryCode)
  114. if err != nil {
  115. br.Msg = "登录失败"
  116. br.ErrMsg = "绑定手机号失败:" + err.Error()
  117. return
  118. }
  119. userId := user.UserId
  120. var token string
  121. tokenItem, err := models.GetTokenByOpenId(openId)
  122. if err != nil && err.Error() != utils.ErrNoRow() {
  123. br.Msg = "登录失败"
  124. br.ErrMsg = "登录失败,获取token失败:" + err.Error()
  125. return
  126. }
  127. if tokenItem == nil || (err != nil && err.Error() == utils.ErrNoRow()) {
  128. timeUnix := time.Now().Unix()
  129. timeUnixStr := strconv.FormatInt(timeUnix, 10)
  130. token = utils.MD5(openId) + utils.MD5(timeUnixStr)
  131. //新增session
  132. {
  133. session := new(models.CygxSession)
  134. session.OpenId = unionId
  135. session.UnionId = unionId
  136. session.UserId = userId
  137. session.CreatedTime = time.Now()
  138. session.LastUpdatedTime = time.Now()
  139. session.ExpireTime = time.Now().AddDate(0, 1, 0)
  140. session.AccessToken = token
  141. err = models.AddSession(session)
  142. if err != nil {
  143. br.Msg = "登录失败"
  144. br.ErrMsg = "登录失败,新增用户session信息失败:" + err.Error()
  145. return
  146. }
  147. }
  148. } else {
  149. token = tokenItem.AccessToken
  150. }
  151. //新增登录日志
  152. {
  153. loginLog := new(models.WxUserLog)
  154. loginLog.UserId = userId
  155. loginLog.OpenId = openId
  156. loginLog.Mobile = req.Mobile
  157. loginLog.Email = req.Email
  158. loginLog.CreateTime = time.Now()
  159. loginLog.Handle = "wechat_user_login"
  160. loginLog.Remark = token
  161. go models.AddWxUserLog(loginLog)
  162. }
  163. //添加邀请绑定关系
  164. {
  165. if req.ShareUserCode != "" {
  166. count, _ := models.GetUserInviteeCount(userId)
  167. if count == 0 {
  168. userItem := new(models.UserInvitee)
  169. userItem.CreateTime = time.Now()
  170. userItem.InviteedUserId = strconv.Itoa(userId)
  171. userItem.InviteeUserId = req.ShareUserCode
  172. shareUserId, _ := strconv.Atoi(req.ShareUserCode)
  173. inviteeUser, _ := models.GetWxUserItemByUserId(shareUserId)
  174. if inviteeUser != nil {
  175. userItem.InviteeMobile = inviteeUser.Mobile
  176. userItem.InviteeCompany = inviteeUser.CompanyName
  177. userItem.InviteeCompanyId = inviteeUser.CompanyId
  178. userItem.InviteeEmail = inviteeUser.Email
  179. }
  180. models.AddUserInvite(userItem)
  181. }
  182. }
  183. }
  184. {
  185. services.UpdateCygxSubscribe(userId, unionId) //先关注后登录,更新用户是否关注过查研观向小助手公众号
  186. if inviteShareCode != "" { //记录分享来源
  187. go services.AddCygxUserAdminShareHistory(user, "login", "", inviteShareCode, 0) //记录分享来源
  188. }
  189. }
  190. resp := new(models.LoginResp)
  191. resp.UserId = userId
  192. resp.Authorization = token
  193. if user.CompanyId == 1 {
  194. resp.IsPotential = true
  195. }
  196. br.Ret = 200
  197. br.Success = true
  198. br.Data = resp
  199. br.Msg = "登录成功"
  200. }
  201. // @Title 获取用户详情
  202. // @Description 获取用户详情接口
  203. // @Success 200 {object} models.UserDetail
  204. // @router /detail [get]
  205. func (this *UserController) Detail() {
  206. br := new(models.BaseResponse).Init()
  207. defer func() {
  208. this.Data["json"] = br
  209. this.ServeJSON()
  210. }()
  211. user := this.User
  212. if user == nil {
  213. br.Msg = "请登录"
  214. br.ErrMsg = "请登录,用户信息为空"
  215. br.Ret = 408
  216. return
  217. }
  218. uid := user.UserId
  219. var hasPermission int
  220. detail := new(models.UserDetail)
  221. if uid > 0 {
  222. var err error
  223. detail, err = models.GetUserDetailByUserId(uid)
  224. if err != nil && err.Error() != utils.ErrNoRow() {
  225. br.Msg = "获取信息失败"
  226. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  227. return
  228. }
  229. if detail == nil {
  230. br.Msg = "获取信息失败"
  231. br.ErrMsg = "获取信息失败,Err:用户不存在"
  232. return
  233. }
  234. totalCollect, err := models.GetArticleUserCollectCount(uid) // 文章收藏数量
  235. if err != nil {
  236. br.Msg = "获取数据失败"
  237. br.ErrMsg = "GetArticleUserCollectCount,Err:" + err.Error()
  238. return
  239. }
  240. endDate := time.Now().AddDate(0, -1, 0).Format(utils.FormatDate)
  241. totalHistory, err := models.GetArticleUserBrowseHistoryCount(uid, endDate) //足迹数量
  242. if err != nil {
  243. br.Msg = "获取数据失败"
  244. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  245. return
  246. }
  247. totalSchedule, err := models.GetArticleUserScheduleNum(uid) // 我的日程数量
  248. if err != nil {
  249. br.Msg = "获取数据失败"
  250. br.ErrMsg = "GetArticleUserScheduleNum,Err:" + err.Error()
  251. return
  252. }
  253. detail.ConNum = totalCollect
  254. detail.HistoryNum = totalHistory
  255. detail.ScheduleNum = totalSchedule
  256. userRecord, _ := models.GetUserRecordByUserId(uid, utils.WxPlatform)
  257. if userRecord != nil {
  258. detail.NickName = userRecord.NickName
  259. if detail.Headimgurl == "" {
  260. detail.Headimgurl = userRecord.Headimgurl
  261. }
  262. //if detail.Headimgurl == "" {
  263. // userRecord, _ = models.GetUserRecordByUserId(uid, 1)
  264. // if userRecord != nil {
  265. // detail.NickName = userRecord.NickName
  266. // detail.Headimgurl = userRecord.Headimgurl
  267. // }
  268. //}
  269. }
  270. if user.CompanyId > 1 {
  271. companyItem, err := models.GetCompanyDetailById(user.CompanyId)
  272. if err != nil && err.Error() != utils.ErrNoRow() {
  273. br.Msg = "获取信息失败"
  274. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  275. return
  276. }
  277. if companyItem != nil && companyItem.CompanyId > 1 {
  278. detail.CompanyName = companyItem.CompanyName
  279. detail.SellerName = companyItem.SellerName
  280. detail.SellerMobile = companyItem.Mobile
  281. microRoadshowCollectcount, err := models.GetUserMicroRoadshowCollectcount(user.UserId)
  282. if err != nil {
  283. br.Msg = "获取信息失败"
  284. br.ErrMsg = "获取微路演收藏信息失败,GetUserMicroRoadshowCollectcount Err:" + err.Error()
  285. return
  286. }
  287. detail.ConNum += microRoadshowCollectcount
  288. // 获取用户所在公司剩余的点
  289. companyPointsNum, err := models.GetCompanyPoints(user.CompanyId)
  290. if err != nil && err.Error() != utils.ErrNoRow() {
  291. br.Msg = "获取信息失败"
  292. br.ErrMsg = "获取用户所在公司剩余的点失败,Err:" + err.Error()
  293. return
  294. }
  295. detail.CompanyPointsNum = companyPointsNum
  296. userYanxunaDetail, err := models.GetCygxUserYanxuanPermissionDetailByUserId(user.UserId)
  297. if err != nil && err.Error() != utils.ErrNoRow() {
  298. br.Msg = "获取信息失败"
  299. br.ErrMsg = "获取信息失败,GetCygxUserYanxuanPermissionDetailByUserId Err:" + err.Error()
  300. return
  301. }
  302. if userYanxunaDetail != nil {
  303. detail.PermissionStatus = userYanxunaDetail.Status
  304. detail.StartDate = userYanxunaDetail.StartDate
  305. detail.EndDate = userYanxunaDetail.EndDate
  306. detail.PermissionName = utils.CHART_PERMISSION_NAME_MF_YANXUAN
  307. } else {
  308. //查询研选的权限状态
  309. var condition string
  310. var pars []interface{}
  311. condition += " AND company_id = ? AND status IN ('正式','试用') AND chart_permission_id IN (31,52) "
  312. pars = append(pars, user.CompanyId)
  313. //companyReportPermissionDetail, err := models.GetCompanyReportPermissionDetailByCondition(condition, pars)
  314. //if err != nil && err.Error() != utils.ErrNoRow() {
  315. // br.Msg = "获取信息失败"
  316. // br.ErrMsg = "获取用户所在公司剩余的点失败,Err:" + err.Error()
  317. // return
  318. //}
  319. companyReportPermissionList, err := models.GetCompanyReportPermissionList(condition, pars)
  320. if err != nil && err.Error() != utils.ErrNoRow() {
  321. br.Msg = "获取信息失败"
  322. br.ErrMsg = "获取用户所在公司剩余的点失败,Err:" + err.Error()
  323. return
  324. }
  325. companyProduct, err := models.GetCompanyProductDetail(user.CompanyId, 2)
  326. if err != nil {
  327. br.Msg = "获取信息失败"
  328. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  329. return
  330. }
  331. if len(companyReportPermissionList) == 0 || companyProduct.IsSuspend == 1 {
  332. hasPermission = 1
  333. } else {
  334. //有研选订阅或研选扣点包任意一项试用权限,即为试用客户,期限显示两项合并之后的最长时间
  335. minDate := time.Now()
  336. maxDate := time.Now()
  337. var permissionStatus string
  338. for _, v := range companyReportPermissionList {
  339. if utils.StrDateToDate(v.StartDate).Before(minDate) {
  340. minDate = utils.StrDateToDate(v.StartDate)
  341. }
  342. if utils.StrDateToDate(v.EndDate).After(maxDate) {
  343. maxDate = utils.StrDateToDate(v.EndDate)
  344. }
  345. if permissionStatus != "正式" {
  346. permissionStatus = v.Status
  347. }
  348. }
  349. detail.PermissionStatus = permissionStatus
  350. detail.StartDate = minDate.Format(utils.FormatDate)
  351. detail.EndDate = maxDate.Format(utils.FormatDate)
  352. }
  353. }
  354. } else {
  355. hasPermission = 1
  356. }
  357. } else {
  358. //判断是否已经申请过
  359. applyCount, err := models.GetApplyRecordCount(uid)
  360. if err != nil && err.Error() != utils.ErrNoRow() {
  361. br.Msg = "获取信息失败"
  362. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  363. return
  364. }
  365. if applyCount > 0 {
  366. hasPermission = 3
  367. } else {
  368. hasPermission = 2
  369. }
  370. detail.CompanyName = detail.Note
  371. }
  372. detail.HasPermission = hasPermission
  373. } else {
  374. ur, _ := models.GetUserRecordByOpenId(user.OpenId)
  375. if ur != nil {
  376. detail.NickName = ur.NickName
  377. detail.Email = ur.BindAccount
  378. detail.Mobile = ur.BindAccount
  379. detail.NickName = ur.NickName
  380. detail.Headimgurl = ur.Headimgurl
  381. }
  382. hasPermission = 2
  383. detail.HasPermission = hasPermission
  384. }
  385. if detail.Headimgurl == "" {
  386. detail.Headimgurl = utils.DefaultHeadimgurl
  387. }
  388. if detail.Mobile != "" {
  389. detail.InviteShareCode = services.GetInviteShareCode(detail.Mobile) //判断用户是否属于销售,并且获取对应加密的分享码
  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. }