user.go 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "github.com/rdlucklib/rdluck_tools/paging"
  6. "hongze/hongze_clpt/models"
  7. "hongze/hongze_clpt/services"
  8. "hongze/hongze_clpt/utils"
  9. "sort"
  10. "strconv"
  11. "strings"
  12. "time"
  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 *UserCommonController) Login() {
  26. br := new(models.BaseResponse).Init()
  27. defer func() {
  28. this.Data["json"] = br
  29. this.ServeJSON()
  30. }()
  31. var token string
  32. var req models.LoginReq
  33. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  34. if err != nil {
  35. br.Msg = "参数解析异常!"
  36. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  37. return
  38. }
  39. mobile := req.Mobile
  40. req.Mobile = strings.Trim(req.Mobile, " ")
  41. if req.Mobile == "" {
  42. br.Msg = "参数错误"
  43. br.ErrMsg = "参数错误,手机号为空"
  44. return
  45. }
  46. code := req.VCode
  47. if code == "" {
  48. br.Msg = "参数错误"
  49. br.ErrMsg = "Code 为空"
  50. return
  51. }
  52. authorization := req.Token
  53. item, err := models.GetMsgCode(req.Mobile, req.VCode)
  54. if err != nil {
  55. if err.Error() == utils.ErrNoRow() {
  56. br.Msg = "验证码错误,请重新输入"
  57. br.ErrMsg = "校验验证码失败,Err:" + err.Error()
  58. return
  59. } else {
  60. br.Msg = "验证码错误,请重新输入"
  61. br.ErrMsg = "校验验证码失败,Err:" + err.Error()
  62. return
  63. }
  64. }
  65. if item == nil {
  66. br.Msg = "验证码错误,请重新输入"
  67. return
  68. }
  69. user, err := services.BindWxUser(mobile, "86")
  70. //user, err := models.GetWxUserItemByMobile(mobile)
  71. if err != nil {
  72. br.Msg = "登录失败"
  73. br.ErrMsg = "获取用户信息失败,GetUserDetailByMobile Err:" + err.Error()
  74. return
  75. }
  76. if authorization != "" {
  77. session, err := models.GetSessionByToken(authorization)
  78. if err != nil {
  79. br.Msg = "登录失败"
  80. br.ErrMsg = "绑定失败,GetSessionByToken err:" + err.Error()
  81. return
  82. }
  83. openid := session.OpenId
  84. if openid == "" {
  85. br.Msg = "登录失败"
  86. br.ErrMsg = "获取用户信息失败,绑定用户openid失败,OpenId不能为空 "
  87. return
  88. }
  89. err = models.BindSessionMobile(mobile, authorization)
  90. if err != nil {
  91. br.Msg = "登录失败"
  92. br.ErrMsg = "获取用户信息失败,BindSessionMobile Err:" + err.Error()
  93. return
  94. }
  95. err = models.BindUserRecordByOpenid(user.UserId, openid, mobile)
  96. if err != nil {
  97. br.Msg = "登录失败"
  98. br.ErrMsg = "获取用户信息失败,BindUserRecordByOpenid Err:" + err.Error()
  99. return
  100. }
  101. token = authorization
  102. } else {
  103. timeUnix := time.Now().Unix()
  104. timeUnixStr := strconv.FormatInt(timeUnix, 10)
  105. token = utils.MD5(mobile) + utils.MD5(timeUnixStr)
  106. itemsSession := new(models.CygxClptSession)
  107. itemsSession.UserId = user.UserId
  108. itemsSession.Mobile = mobile
  109. itemsSession.AccessToken = token
  110. itemsSession.CreatedTime = time.Now()
  111. itemsSession.LastUpdatedTime = time.Now()
  112. itemsSession.ExpireTime = time.Now().AddDate(0, 3, 0)
  113. err = models.AddCygxClptSession(itemsSession)
  114. if err != nil {
  115. br.Msg = "获取用户信息失败"
  116. br.ErrMsg = "添加Token失败,Err:" + err.Error()
  117. return
  118. }
  119. }
  120. resp := new(models.LoginResp)
  121. resp.UserId = user.UserId
  122. resp.Headimgurl = user.Headimgurl
  123. resp.Mobile = user.Mobile
  124. resp.Email = user.Email
  125. resp.CompanyName = user.CompanyName
  126. resp.Authorization = token
  127. br.Ret = 200
  128. br.Success = true
  129. br.Msg = "获取成功"
  130. br.Data = resp
  131. }
  132. // @Title 获取用户详情
  133. // @Description 获取用户详情接口
  134. // @Success 200 {object} models.UserDetailResp
  135. // @router /detail [get]
  136. func (this *UserController) Detail() {
  137. br := new(models.BaseResponse).Init()
  138. defer func() {
  139. this.Data["json"] = br
  140. this.ServeJSON()
  141. }()
  142. user := this.User
  143. if user == nil {
  144. br.Msg = "请登录"
  145. br.ErrMsg = "请登录,用户信息为空"
  146. br.Ret = 408
  147. return
  148. }
  149. resp := new(models.UserDetailResp)
  150. resp.UserId = user.UserId
  151. resp.UserName = user.RealName
  152. resp.Headimgurl = user.Headimgurl
  153. resp.Mobile = user.Mobile
  154. resp.Email = user.Email
  155. resp.CompanyName = user.CompanyName
  156. userDetail, err := models.GetUserDetailByUserId(user.UserId)
  157. if err != nil {
  158. br.Msg = "获取用户信息失败"
  159. br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
  160. return
  161. }
  162. resp.OutboundCountryCode = userDetail.OutboundCountryCode
  163. resp.OutboundMobile = userDetail.OutboundMobile
  164. if user.CompanyId > 1 {
  165. companyItem, err := models.GetCompanyDetailById(user.CompanyId)
  166. if err != nil && err.Error() != utils.ErrNoRow() {
  167. br.Msg = "获取信息失败"
  168. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  169. return
  170. }
  171. if companyItem != nil && companyItem.CompanyId > 0 {
  172. resp.CompanyName = companyItem.CompanyName
  173. //if companyItem.Status == "试用" || companyItem.Status == "永续" || companyItem.Status == "正式" {
  174. //permissionStr, err := models.GetCompanyPermissionByUser(companyItem.CompanyId)
  175. //if err != nil {
  176. // br.Msg = "获取信息失败"
  177. // br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  178. // return
  179. //}
  180. var permissionStr string
  181. permissionList, err := models.GetCompanyPermissionList(companyItem.CompanyId)
  182. if err != nil {
  183. br.Msg = "获取信息失败"
  184. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  185. return
  186. }
  187. mapIsUpgrade := make(map[string]string)
  188. mapZhukKeGuan := make(map[string]int)
  189. for _, v := range permissionList {
  190. mapZhukKeGuan[v.PermissionName] += 1
  191. if v.IsUpgrade == 1 {
  192. mapIsUpgrade[v.PermissionName] = v.PermissionName + "(升级)"
  193. }
  194. }
  195. mapPermissionName := make(map[string]string)
  196. //处理升级,并且合并主客观
  197. for _, v := range permissionList {
  198. if _, ok := mapPermissionName[v.PermissionName]; ok {
  199. continue
  200. }
  201. if _, ok := mapIsUpgrade[v.PermissionName]; ok {
  202. permissionStr += mapIsUpgrade[v.PermissionName] + ","
  203. } else {
  204. if mapZhukKeGuan[v.PermissionName] == 1 {
  205. permissionStr += v.Remark + ","
  206. } else {
  207. permissionStr += v.PermissionName + ","
  208. }
  209. }
  210. mapPermissionName[v.PermissionName] = v.PermissionName
  211. }
  212. permissionStr = strings.TrimRight(permissionStr, ",")
  213. //permissionStrOld, err := models.GetCompanyPermission(companyItem.CompanyId)
  214. //if err != nil {
  215. // br.Msg = "获取信息失败"
  216. // br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  217. // return
  218. //}
  219. //permissionStrListOld := strings.Split(permissionStrOld, ",")
  220. //for _, v := range permissionStrListOld {
  221. // if strings.Count(permissionStr, v) > 1 {
  222. // permissionStr = strings.Replace(permissionStr, v+"(主观)", v, -1)
  223. // permissionStr = strings.Replace(permissionStr, v+"(客观),", "", -1)
  224. // }
  225. //}
  226. finalPermissionList := strings.Split(permissionStr, ",")
  227. for _, per := range finalPermissionList {
  228. resp.PermissionName = append(resp.PermissionName, per)
  229. }
  230. }
  231. }
  232. if resp.Headimgurl == "" {
  233. resp.Headimgurl = utils.DefaultHeadimgurl
  234. }
  235. br.Ret = 200
  236. br.Success = true
  237. br.Msg = "获取成功"
  238. br.Data = resp
  239. }
  240. // @Title 未付费申请试用
  241. // @Description 未付费申请试用
  242. // @Param request body models.ApplyTryReq true "type json string"
  243. // @Success 200
  244. // @router /apply/try [post]
  245. func (this *UserController) ApplyTryOut() {
  246. br := new(models.BaseResponse).Init()
  247. defer func() {
  248. this.Data["json"] = br
  249. this.ServeJSON()
  250. }()
  251. user := this.User
  252. if user == nil {
  253. br.Msg = "请登录"
  254. br.ErrMsg = "请登录,SysUser Is Empty"
  255. br.Ret = 408
  256. return
  257. }
  258. mobile := user.Mobile
  259. var req models.ApplyTryReq
  260. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  261. if err != nil {
  262. br.Msg = "参数解析异常!"
  263. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  264. return
  265. }
  266. if req.RealName == "" {
  267. req.RealName = user.RealName
  268. }
  269. if req.CompanyName == "" {
  270. req.CompanyName = user.CompanyName
  271. }
  272. uid := user.UserId
  273. var title string
  274. tryType := req.TryType
  275. detailId := req.DetailId
  276. if tryType == "Article" {
  277. detail, err := models.GetArticleDetailById(detailId)
  278. if err != nil {
  279. br.Msg = "获取信息失败"
  280. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  281. return
  282. }
  283. title = detail.Title
  284. } else if tryType == "Activity" {
  285. detail, err := models.GetAddActivityInfoById(detailId)
  286. if err != nil {
  287. br.Msg = "操作失败"
  288. br.ErrMsg = "活动ID错误,不存在activityId:" + strconv.Itoa(detailId)
  289. return
  290. }
  291. title = detail.ActivityName
  292. } else if tryType == "MicroAudio" {
  293. // 微路演音频
  294. microAudio, e := models.GetCygxActivityVoiceById(detailId)
  295. if e != nil {
  296. br.Msg = "操作失败"
  297. br.ErrMsg = "微路演音频信息有误, 不存在的VoiceId: " + strconv.Itoa(detailId)
  298. return
  299. }
  300. title = microAudio.VoiceName
  301. } else if tryType == "MicroVideo" {
  302. // 微路演视频
  303. microVideo, e := models.GetMicroRoadshowVideoById(detailId)
  304. if e != nil {
  305. br.Msg = "操作失败"
  306. br.ErrMsg = "微路演视频信息有误, 不存在的VideoId: " + strconv.Itoa(detailId)
  307. return
  308. }
  309. title = microVideo.VideoName
  310. } else if tryType == "Researchsummary" {
  311. // 本周研究汇总
  312. ResearchSummaryInfo, e := models.GetCygxResearchSummaryInfoById(detailId)
  313. if e != nil {
  314. br.Msg = "操作失败"
  315. br.ErrMsg = "本周研究汇总信息有误, 不存在的detailId: " + strconv.Itoa(detailId)
  316. return
  317. }
  318. title = ResearchSummaryInfo.Title
  319. } else if tryType == "Minutessummary" {
  320. // 上周纪要汇总
  321. MinutesSummaryInfo, e := models.GetCygxMinutesSummaryInfoById(detailId)
  322. if e != nil {
  323. br.Msg = "操作失败"
  324. br.ErrMsg = "上周纪要汇总信息有误, 不存在的detailId: " + strconv.Itoa(detailId)
  325. return
  326. }
  327. title = MinutesSummaryInfo.Title
  328. } else if tryType == "ReportSelection" {
  329. // 报告精选
  330. ReportSelectionInfo, e := models.GetCygxReportSelectionInfoById(detailId)
  331. if e != nil {
  332. br.Msg = "操作失败"
  333. br.ErrMsg = "报告精选信息有误, 不存在的detailId: " + strconv.Itoa(detailId)
  334. return
  335. }
  336. title = ReportSelectionInfo.Title
  337. } else if tryType == "ProductInterior" {
  338. // 产品内测
  339. ProductInteriorDetail, e := models.GetCygxProductInteriorDetail(detailId)
  340. if e != nil {
  341. br.Msg = "操作失败"
  342. br.ErrMsg = "产品内测信息有误, 不存在的detailId: " + strconv.Itoa(detailId)
  343. return
  344. }
  345. title = ProductInteriorDetail.Title
  346. }
  347. //缓存校验
  348. cacheKey := fmt.Sprint("xygx:apply_record:add:", uid)
  349. ttlTime := utils.Rc.GetRedisTTL(cacheKey)
  350. if ttlTime > 0 {
  351. br.Msg = "申请失败,申请过于频繁"
  352. br.ErrMsg = "申请失败,申请过于频繁"
  353. return
  354. }
  355. utils.Rc.SetNX(cacheKey, user.Mobile, time.Second*10)
  356. //判断是否已经申请过
  357. applyCount, err := models.GetApplyRecordCount(uid)
  358. if err != nil && err.Error() != utils.ErrNoRow() {
  359. br.Msg = "获取信息失败"
  360. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  361. return
  362. }
  363. if applyCount > 0 {
  364. br.Msg = "您已提交申请,请耐心等待。"
  365. br.IsSendEmail = false
  366. return
  367. }
  368. //判断是否存在申请
  369. var sellerMobile string
  370. if req.ApplyMethod == 2 {
  371. if req.BusinessCardUrl == "" {
  372. br.Msg = "请上传名片"
  373. return
  374. }
  375. if req.RealName == "" {
  376. br.Msg = "请输入姓名"
  377. return
  378. }
  379. if req.CompanyName == "" {
  380. br.Msg = "请输入公司名称"
  381. return
  382. }
  383. if req.BusinessCardUrl != "" && utils.RunMode == "release" {
  384. card, err := services.GetBusinessCard(req.BusinessCardUrl)
  385. if err != nil {
  386. br.Msg = "名片识别失败"
  387. br.ErrMsg = "名片识别失败,Err:" + err.Error()
  388. return
  389. }
  390. mobileStr := strings.Join(card.WordsResult.MOBILE, ",")
  391. isFlag := true
  392. if mobile != "" {
  393. if strings.Contains(mobileStr, mobile) || mobileStr == "" {
  394. isFlag = true
  395. } else {
  396. isFlag = false
  397. }
  398. }
  399. if !isFlag {
  400. //阿里云识别
  401. if utils.RunMode == "release" {
  402. aliyunResult, err := services.AliyunBusinessCard(req.BusinessCardUrl)
  403. if err != nil {
  404. br.Msg = "识别失败"
  405. br.ErrMsg = "识别失败,Err:" + err.Error()
  406. return
  407. }
  408. if !aliyunResult.Success {
  409. br.Msg = "识别失败"
  410. br.ErrMsg = "识别失败"
  411. return
  412. }
  413. mobileStr := strings.Join(aliyunResult.TelCell, ",")
  414. if mobile != "" {
  415. if strings.Contains(mobileStr, mobile) {
  416. isFlag = true
  417. } else {
  418. isFlag = false
  419. }
  420. }
  421. }
  422. }
  423. if !isFlag {
  424. br.Msg = "名片手机号与所填手机号不匹配,请重新填写"
  425. br.ErrMsg = "mobile:" + mobile
  426. return
  427. }
  428. }
  429. }
  430. //获取销售信息
  431. sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  432. if err != nil && err.Error() != utils.ErrNoRow() {
  433. br.Msg = "申请失败"
  434. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  435. return
  436. }
  437. if sellerItem != nil {
  438. sellerMobile = sellerItem.Mobile
  439. //推送模板消息
  440. mobile := user.Mobile
  441. if mobile == "" {
  442. mobile = user.Email
  443. }
  444. }
  445. //用户状态,1:潜在客户 、2:现有客户 、3:FICC客户 、4:现有客户(正式,无对应权限) 、5:现有客户(试用,无对应权限) 、6:现有客户(试用暂停) 、7:现有客户(冻结) 、8:现有客户(流失)?
  446. CompanyIdType := 1
  447. applyMethod := ""
  448. cnf, _ := models.GetConfigByCode("tpl_msg")
  449. if cnf != nil {
  450. if sellerItem != nil {
  451. cnf.ConfigValue = sellerItem.Mobile
  452. companyItem, err := models.GetCompanyDetailById(user.CompanyId)
  453. if err != nil && err.Error() != utils.ErrNoRow() {
  454. br.Msg = "获取信息失败"
  455. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  456. return
  457. }
  458. if companyItem != nil && companyItem.CompanyId > 0 {
  459. companyProduct, err := models.GetCompanyProductDetail(user.CompanyId, 2)
  460. if err != nil && err.Error() != utils.ErrNoRow() {
  461. br.Msg = "获取信息失败"
  462. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  463. return
  464. }
  465. if companyProduct != nil && companyProduct.IsSuspend == 1 {
  466. CompanyIdType = 6
  467. } else {
  468. switch companyItem.Status {
  469. case "正式":
  470. CompanyIdType = 4
  471. case "试用":
  472. CompanyIdType = 5
  473. case "冻结":
  474. CompanyIdType = 7
  475. case "流失":
  476. CompanyIdType = 8
  477. }
  478. }
  479. applyMethod = companyItem.Status + "客户申请"
  480. if detailId > 0 {
  481. if companyProduct != nil && companyProduct.IsSuspend == 1 {
  482. applyMethod = "试用暂停客户"
  483. } else {
  484. if companyItem.Status == "正式" || companyItem.Status == "试用" {
  485. applyMethod = companyItem.Status + "客户申请,无对应权限"
  486. } else if companyItem.Status == "冻结" || companyItem.Status == "流失" {
  487. applyMethod = companyItem.Status + "客户"
  488. }
  489. }
  490. applyMethod = applyMethod + "," + title
  491. }
  492. }
  493. } else {
  494. //获取销售信息
  495. sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 1)
  496. if err != nil && err.Error() != utils.ErrNoRow() {
  497. br.Msg = "申请失败"
  498. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  499. return
  500. }
  501. if sellerItem != nil {
  502. CompanyIdType = 3
  503. applyMethod = "FICC客户"
  504. } else {
  505. CompanyIdType = 1
  506. applyMethod = "潜在客户"
  507. }
  508. if detailId > 0 {
  509. applyMethod = applyMethod + "," + title
  510. }
  511. }
  512. openIpItem, _ := models.GetUserRecordByMobile(4, cnf.ConfigValue)
  513. if openIpItem != nil && openIpItem.OpenId != "" {
  514. if req.ApplyMethod != 2 {
  515. req.RealName = user.RealName
  516. req.CompanyName = user.CompanyName
  517. }
  518. utils.FileLog.Info("推送消息 %s %s,%s,%s,%s", req.RealName, req.CompanyName, mobile, openIpItem.OpenId, applyMethod)
  519. go services.SendPermissionApplyTemplateMsg(req.RealName, req.CompanyName, mobile, applyMethod, openIpItem)
  520. }
  521. }
  522. err = models.AddApplyRecord(&req, user.Mobile, user.CompanyName, uid, user.CompanyId, CompanyIdType)
  523. if err != nil {
  524. br.Msg = "申请失败"
  525. br.ErrMsg = "申请失败,Err:" + err.Error()
  526. return
  527. }
  528. //添加成功后,设置5分钟缓存,不允许重复添加
  529. //utils.Rc.SetNX(cacheKey, user.Mobile, time.Second*60)
  530. br.Msg = "申请成功!"
  531. br.Ret = 200
  532. br.Success = true
  533. br.Data = sellerMobile
  534. }
  535. // @Title 用户修改外呼手机号以及区号
  536. // @Description 用户修改外呼手机号以及区号接口
  537. // @Param request body models.OutboundMobileItem true "type json string"
  538. // @Success Ret=200 操作成功
  539. // @router /countryCcode/addOutboundMobile [POST]
  540. func (this *UserController) AddOutboundMobile() {
  541. br := new(models.BaseResponse).Init()
  542. defer func() {
  543. this.Data["json"] = br
  544. this.ServeJSON()
  545. }()
  546. user := this.User
  547. uid := user.UserId
  548. if user == nil {
  549. br.Msg = "请登录"
  550. br.ErrMsg = "请登录,用户信息为空"
  551. br.Ret = 408
  552. return
  553. }
  554. var req models.OutboundMobileItem
  555. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  556. if err != nil {
  557. br.Msg = "参数解析异常!"
  558. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  559. return
  560. }
  561. if req.OutboundMobile == "" {
  562. br.Msg = "请填写区号!"
  563. return
  564. }
  565. item := new(models.OutboundMobileItem)
  566. item.OutboundMobile = req.OutboundMobile
  567. item.OutboundCountryCode = req.OutboundCountryCode
  568. //item.ActivityId = req.ActivityId
  569. //if req.ActivityId == 0 {
  570. // err = models.AddOutboundMobile(item, uid)
  571. //} else {
  572. // if user.Mobile == "" && user.OutboundMobile == "" {
  573. // items := new(models.CygxActivitySignup)
  574. // items.UserId = uid
  575. // items.ActivityId = req.ActivityId
  576. // items.CreateTime = time.Now()
  577. // items.Mobile = user.Mobile
  578. // items.Email = user.Email
  579. // items.CompanyId = user.CompanyId
  580. // items.CompanyName = user.CompanyName
  581. // items.SignupType = 1
  582. // items.FailType = 0
  583. // items.DoFailType = 0
  584. // items.OutboundMobile = req.OutboundMobile
  585. // items.CountryCode = req.OutboundCountryCode
  586. // _, err = models.AddActivitySignupFromEmail(items)
  587. // } else {
  588. // total, err := models.GetActivityCountByIdWithUid(item.ActivityId, uid)
  589. // if total == 0 {
  590. // br.Msg = "报名信息不存在"
  591. // br.ErrMsg = "报名信息不存在,Err:" + "活动ActivityId:" + strconv.Itoa(item.ActivityId) + "用户Uid:" + strconv.Itoa(uid)
  592. // return
  593. // }
  594. // if err != nil {
  595. // br.Msg = "操作失败"
  596. // br.ErrMsg = "操作失败,Err:" + err.Error()
  597. // return
  598. // }
  599. // err = models.AddOutboundMobile(item, uid)
  600. // }
  601. //}
  602. err = models.AddOutboundMobile(item, uid)
  603. if err != nil {
  604. br.Msg = "操作失败"
  605. br.ErrMsg = "操作失败,Err:" + err.Error()
  606. return
  607. }
  608. br.Ret = 200
  609. br.Success = true
  610. br.Msg = "操作成功"
  611. }
  612. // @Title 校验用户状态信息
  613. // @Description 校验用户状态信息
  614. // @Success 200 {object} models.CheckStatusResp
  615. // @router /check/status [get]
  616. func (this *UserController) CheckLogin() {
  617. br := new(models.BaseResponse).Init()
  618. defer func() {
  619. this.Data["json"] = br
  620. this.ServeJSON()
  621. }()
  622. user := this.User
  623. if user == nil {
  624. br.Msg = "请登录"
  625. br.ErrMsg = "请登录"
  626. br.Ret = 408
  627. return
  628. }
  629. uid := user.UserId
  630. resp := new(models.CheckStatusResp)
  631. if uid > 0 {
  632. //判断token是否过期
  633. userRecord, err := models.GetUserSessionByUserId(uid)
  634. if err != nil {
  635. br.Msg = "获取用户信息失败"
  636. br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
  637. return
  638. }
  639. permissionStr, err := models.GetCompanyPermission(user.CompanyId)
  640. if err != nil {
  641. br.Msg = "获取信息失败"
  642. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  643. return
  644. }
  645. resp.PermissionName = permissionStr
  646. if user.Mobile == "" && user.Email == "" {
  647. resp.IsBind = true
  648. }
  649. if userRecord.UnionId == "" {
  650. resp.IsAuth = true
  651. }
  652. } else {
  653. resp.IsBind = true
  654. if user.UnionId == "" {
  655. resp.IsAuth = true
  656. }
  657. resp.PermissionName = ""
  658. }
  659. br.Success = true
  660. br.Msg = "获取成功"
  661. br.Data = resp
  662. br.Ret = 200
  663. }
  664. // @Title 更改用户微信头像
  665. // @Description 更改用户微信头像
  666. // @Param request body models.Headimgurl true "type json string"
  667. // @Success 200 {object} models.ArticleDetailFileLink
  668. // @router /headimgurl/update [post]
  669. func (this *UserController) HeadimgurlUpdate() {
  670. br := new(models.BaseResponse).Init()
  671. defer func() {
  672. this.Data["json"] = br
  673. this.ServeJSON()
  674. }()
  675. user := this.User
  676. if user == nil {
  677. br.Msg = "请登录"
  678. br.ErrMsg = "请登录,用户信息为空"
  679. br.Ret = 408
  680. return
  681. }
  682. var req models.Headimgurl
  683. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  684. if err != nil {
  685. br.Msg = "参数解析异常!"
  686. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  687. return
  688. }
  689. uid := user.UserId
  690. headimgurl := req.Headimgurl
  691. if headimgurl == "" {
  692. br.Msg = "操作失败"
  693. br.ErrMsg = "头像信息不能为空"
  694. return
  695. }
  696. err = models.UpdateUserHeadimgurl(headimgurl, uid)
  697. if err != nil {
  698. br.Msg = "操作失败"
  699. br.ErrMsg = "头像信息不能为空"
  700. }
  701. br.Ret = 200
  702. br.Success = true
  703. br.Msg = "操作成功"
  704. }
  705. // @Title 获取我的收藏
  706. // @Description 获取我的收藏列表
  707. // @Param PageSize query int true "PageSize"
  708. // @Param CurrentIndex query int true "CurrentIndex"
  709. // @Success 200 {object} models.ArticleCollectListResp
  710. // @router /collect/list [get]
  711. func (this *UserController) CollectList() {
  712. br := new(models.BaseResponse).Init()
  713. defer func() {
  714. this.Data["json"] = br
  715. this.ServeJSON()
  716. }()
  717. userId := this.User.UserId
  718. var pageSize, currentIndex, startSize int
  719. pageSize, _ = this.GetInt("PageSize")
  720. currentIndex, _ = this.GetInt("CurrentIndex")
  721. if pageSize <= 0 {
  722. pageSize = utils.PageSize20
  723. }
  724. if currentIndex <= 0 {
  725. currentIndex = 1
  726. }
  727. startSize = utils.StartIndex(currentIndex, pageSize)
  728. total, err := models.GetArticleUserCollectCount(userId)
  729. if err != nil {
  730. br.Msg = "获取数据失败"
  731. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  732. return
  733. }
  734. list, err := models.GetArticleUserCollectList(startSize, pageSize, userId)
  735. if err != nil {
  736. br.Msg = "获取数据失败"
  737. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  738. return
  739. }
  740. resp := new(models.ArticleReportBillboardLIstPageResp)
  741. if len(list) == 0 {
  742. page := paging.GetPaging(currentIndex, pageSize, total)
  743. resp.List = list
  744. resp.Paging = page
  745. br.Msg = "获取成功!"
  746. br.Ret = 200
  747. br.Success = true
  748. br.Data = resp
  749. return
  750. }
  751. var condition string
  752. var pars []interface{}
  753. var articleIds []string
  754. for _, v := range list {
  755. articleIds = append(articleIds, strconv.Itoa(v.ArticleId))
  756. }
  757. articleIdStr := strings.Join(articleIds, ",")
  758. //获取文章关联的产业
  759. pars = make([]interface{}, 0)
  760. condition = ` AND mg.article_id IN ( ` + utils.GetOrmInReplace(len(articleIds)) + ` ) `
  761. pars = append(pars, articleIds)
  762. industrialList, err := models.GetIndustrialListByarticleId(pars, condition)
  763. if err != nil {
  764. br.Msg = "获取失败"
  765. br.ErrMsg = "获取失败,GetSubjectList Err:" + err.Error()
  766. return
  767. }
  768. industrialMap := make(map[int][]*models.IndustrialManagementIdInt)
  769. if len(industrialList) > 0 {
  770. for _, v := range industrialList {
  771. item := new(models.IndustrialManagementIdInt)
  772. item.ArticleId = v.ArticleId
  773. if v.ArticleId > utils.SummaryArticleId {
  774. item.IsResearch = true
  775. }
  776. item.IndustrialManagementId = v.IndustrialManagementId
  777. item.IndustryName = v.IndustryName
  778. item.ChartPermissionId = v.ChartPermissionId
  779. industrialMap[v.ArticleId] = append(industrialMap[v.ArticleId], item)
  780. }
  781. }
  782. for k, v := range list {
  783. if len(industrialMap[v.ArticleId]) > 0 {
  784. list[k].List = industrialMap[v.ArticleId]
  785. } else {
  786. list[k].List = make([]*models.IndustrialManagementIdInt, 0)
  787. }
  788. }
  789. articleMap := make(map[int]*models.ArticleDetail)
  790. if articleIdStr != "" {
  791. articleList, err := models.GetArticleDetailByIdStr(articleIdStr)
  792. if err != nil {
  793. br.Msg = "获取数据失败"
  794. br.ErrMsg = "获取报告详情信息失败,Err:" + err.Error()
  795. return
  796. }
  797. for _, v := range articleList {
  798. if _, ok := articleMap[v.ArticleId]; !ok {
  799. articleMap[v.ArticleId] = v
  800. }
  801. }
  802. }
  803. //处理文章PV收藏等数量
  804. mapArticleCollectNum := make(map[int]*models.CygxArticleNum)
  805. if len(articleIds) > 0 {
  806. articleCollectNumList, err := models.GetArticleCollectNum(articleIds, userId)
  807. if err != nil && err.Error() != utils.ErrNoRow() {
  808. br.Msg = "获取失败"
  809. br.ErrMsg = "获取失败,GetArticleCollectNum Err:" + err.Error()
  810. return
  811. }
  812. for _, v := range articleCollectNumList {
  813. mapArticleCollectNum[v.ArticleId] = v
  814. }
  815. }
  816. lenList := len(list)
  817. for i := 0; i < lenList; i++ {
  818. item := list[i]
  819. article := articleMap[item.ArticleId]
  820. list[i].Title = article.Title
  821. list[i].DepartmentId = article.DepartmentId
  822. list[i].NickName = article.NickName
  823. list[i].PublishDate = article.PublishDate
  824. if article.ArticleId < utils.SummaryArticleId {
  825. list[i].Source = 1
  826. } else {
  827. list[i].Source = 2
  828. }
  829. if mapArticleCollectNum[article.ArticleId] != nil {
  830. list[i].CollectNum = mapArticleCollectNum[article.ArticleId].CollectNum
  831. list[i].Pv = mapArticleCollectNum[article.ArticleId].Pv
  832. list[i].IsCollect = mapArticleCollectNum[article.ArticleId].IsCollect
  833. }
  834. //list[i].TitleEn = article.TitleEn
  835. //list[i].UpdateFrequency = article.UpdateFrequency
  836. //list[i].CreateDate = article.CreateDate
  837. //list[i].Body, _ = services.GetReportContentTextSub(article.Body)
  838. //list[i].Abstract = article.Abstract
  839. //list[i].CategoryName = article.CategoryName
  840. //list[i].SubCategoryName = article.SubCategoryName
  841. }
  842. page := paging.GetPaging(currentIndex, pageSize, total)
  843. resp.List = list
  844. resp.Paging = page
  845. br.Msg = "获取成功!"
  846. br.Ret = 200
  847. br.Success = true
  848. br.Data = resp
  849. }
  850. // @Title 获取我的留言
  851. // @Description 获取我的留言列表
  852. // @Param PageSize query int true "PageSize"
  853. // @Param CurrentIndex query int true "CurrentIndex"
  854. // @Success 200 {object} models.CygxCommentListResp
  855. // @router /comment/list [get]
  856. func (this *UserController) CommnetList() {
  857. br := new(models.BaseResponse).Init()
  858. defer func() {
  859. this.Data["json"] = br
  860. this.ServeJSON()
  861. }()
  862. user := this.User
  863. if user == nil {
  864. br.Msg = "请登录"
  865. br.ErrMsg = "请登录,用户信息为空"
  866. br.Ret = 408
  867. return
  868. }
  869. var pageSize, currentIndex, startSize int
  870. pageSize, _ = this.GetInt("PageSize")
  871. currentIndex, _ = this.GetInt("CurrentIndex")
  872. if pageSize <= 0 {
  873. pageSize = utils.PageSize20
  874. }
  875. if currentIndex <= 0 {
  876. currentIndex = 1
  877. }
  878. startSize = utils.StartIndex(currentIndex, pageSize)
  879. userId := this.User.UserId
  880. total, err := models.GetCommentListCount(userId)
  881. if err != nil {
  882. br.Msg = "获取数据失败"
  883. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  884. return
  885. }
  886. commentlist, err := models.GetCommentList(userId, startSize, pageSize)
  887. if err != nil && err.Error() != utils.ErrNoRow() {
  888. br.Msg = "获取失败"
  889. br.ErrMsg = "获取我的留言列表失败,Err:" + err.Error()
  890. return
  891. }
  892. resp := new(models.CygxCommentListResp)
  893. for _, comment := range commentlist {
  894. item := models.CygxArticleCommentResp{
  895. Id: comment.Id,
  896. UserId: comment.UserId,
  897. ArticleId: comment.ArticleId,
  898. IndustryId: comment.IndustryId,
  899. ActivityId: comment.ActivityId,
  900. VideoId: comment.VideoId,
  901. CreateTime: comment.CreateTime.Format(utils.FormatDateTime),
  902. Mobile: comment.Mobile,
  903. Email: comment.Email,
  904. CompanyId: comment.CompanyId,
  905. CompanyName: comment.CompanyName,
  906. Content: comment.Content,
  907. Title: comment.Title,
  908. }
  909. if comment.ArticleId > 0 {
  910. item.RedirectType = 1
  911. } else if comment.IndustryId > 0 {
  912. detail, err := models.GetIndustrialManagementDetail(comment.IndustryId)
  913. if err != nil {
  914. br.Msg = "获取信息失败"
  915. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  916. return
  917. }
  918. item.RedirectType = 3
  919. item.ChartPermissionId = detail.ChartPermissionId
  920. } else if comment.ActivityId > 0 && comment.VideoId == 0 {
  921. item.RedirectType = 2
  922. } else if comment.IndustryId == 0 && comment.VideoId > 0 {
  923. item.RedirectType = 4
  924. }
  925. resp.List = append(resp.List, &item)
  926. }
  927. page := paging.GetPaging(currentIndex, pageSize, total)
  928. resp.Paging = page
  929. br.Msg = "获取成功!"
  930. br.Ret = 200
  931. br.Success = true
  932. br.Data = resp
  933. }
  934. // @Title 我的足迹
  935. // @Description 获取我的足迹列表
  936. // @Param PageSize query int true "PageSize"
  937. // @Param CurrentIndex query int true "CurrentIndex"
  938. // @Success 200 {object} models.ArticleBrowseHistoryListResp
  939. // @router /browse/history/list [get]
  940. func (this *UserController) BrowseHistoryList() {
  941. br := new(models.BaseResponse).Init()
  942. defer func() {
  943. this.Data["json"] = br
  944. this.ServeJSON()
  945. }()
  946. userId := this.User.UserId
  947. var pageSize, currentIndex, startSize int
  948. pageSize, _ = this.GetInt("PageSize")
  949. currentIndex, _ = this.GetInt("CurrentIndex")
  950. if pageSize <= 0 {
  951. pageSize = utils.PageSize20
  952. }
  953. if currentIndex <= 0 {
  954. currentIndex = 1
  955. }
  956. startSize = utils.StartIndex(currentIndex, pageSize)
  957. endDate := time.Now().AddDate(0, -1, 0).Format(utils.FormatDate)
  958. total, err := models.GetArticleUserBrowseHistoryCount(userId, endDate)
  959. if err != nil {
  960. br.Msg = "获取数据失败"
  961. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  962. return
  963. }
  964. list, err := models.GetArticleUserBrowseHistoryList(startSize, pageSize, userId, endDate)
  965. if err != nil {
  966. br.Msg = "获取数据失败"
  967. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  968. return
  969. }
  970. resp := new(models.ArticleReportBillboardLIstPageResp)
  971. if len(list) == 0 {
  972. page := paging.GetPaging(currentIndex, pageSize, total)
  973. resp.List = list
  974. resp.Paging = page
  975. br.Msg = "获取成功!"
  976. br.Ret = 200
  977. br.Success = true
  978. br.Data = resp
  979. return
  980. }
  981. var articleIds []string
  982. var condition string
  983. var pars []interface{}
  984. for _, v := range list {
  985. articleIds = append(articleIds, strconv.Itoa(v.ArticleId))
  986. }
  987. articleIdStr := strings.Join(articleIds, ",")
  988. //获取文章关联的产业
  989. pars = make([]interface{}, 0)
  990. condition = ` AND mg.article_id IN ( ` + utils.GetOrmInReplace(len(articleIds)) + ` ) `
  991. pars = append(pars, articleIds)
  992. industrialList, err := models.GetIndustrialListByarticleId(pars, condition)
  993. if err != nil {
  994. br.Msg = "获取失败"
  995. br.ErrMsg = "获取失败,GetSubjectList Err:" + err.Error()
  996. return
  997. }
  998. industrialMap := make(map[int][]*models.IndustrialManagementIdInt)
  999. if len(industrialList) > 0 {
  1000. for _, v := range industrialList {
  1001. item := new(models.IndustrialManagementIdInt)
  1002. item.ArticleId = v.ArticleId
  1003. if v.ArticleId > utils.SummaryArticleId {
  1004. item.IsResearch = true
  1005. }
  1006. item.IndustrialManagementId = v.IndustrialManagementId
  1007. item.IndustryName = v.IndustryName
  1008. item.ChartPermissionId = v.ChartPermissionId
  1009. industrialMap[v.ArticleId] = append(industrialMap[v.ArticleId], item)
  1010. }
  1011. }
  1012. for k, v := range list {
  1013. if len(industrialMap[v.ArticleId]) > 0 {
  1014. list[k].List = industrialMap[v.ArticleId]
  1015. } else {
  1016. list[k].List = make([]*models.IndustrialManagementIdInt, 0)
  1017. }
  1018. }
  1019. articleMap := make(map[int]*models.ArticleDetail)
  1020. if articleIdStr != "" {
  1021. articleList, err := models.GetArticleDetailByIdStr(articleIdStr)
  1022. if err != nil {
  1023. br.Msg = "获取数据失败"
  1024. br.ErrMsg = "获取报告详情信息失败,Err:" + err.Error()
  1025. return
  1026. }
  1027. for _, v := range articleList {
  1028. if _, ok := articleMap[v.ArticleId]; !ok {
  1029. articleMap[v.ArticleId] = v
  1030. }
  1031. }
  1032. }
  1033. //处理文章PV收藏等数量
  1034. mapArticleCollectNum := make(map[int]*models.CygxArticleNum)
  1035. if len(articleIds) > 0 {
  1036. articleCollectNumList, err := models.GetArticleCollectNum(articleIds, userId)
  1037. if err != nil && err.Error() != utils.ErrNoRow() {
  1038. br.Msg = "获取失败"
  1039. br.ErrMsg = "获取失败,GetArticleCollectNum Err:" + err.Error()
  1040. return
  1041. }
  1042. for _, v := range articleCollectNumList {
  1043. mapArticleCollectNum[v.ArticleId] = v
  1044. }
  1045. }
  1046. lenList := len(list)
  1047. for i := 0; i < lenList; i++ {
  1048. item := list[i]
  1049. article := articleMap[item.ArticleId]
  1050. if article != nil {
  1051. list[i].Title = article.Title
  1052. list[i].PublishDate = utils.TimeRemoveHms2(article.PublishDate)
  1053. list[i].DepartmentId = article.DepartmentId
  1054. list[i].NickName = article.NickName
  1055. if article.ArticleId < utils.SummaryArticleId {
  1056. list[i].Source = 1
  1057. } else {
  1058. list[i].Source = 2
  1059. }
  1060. if mapArticleCollectNum[article.ArticleId] != nil {
  1061. list[i].CollectNum = mapArticleCollectNum[article.ArticleId].CollectNum
  1062. list[i].Pv = mapArticleCollectNum[article.ArticleId].Pv
  1063. list[i].IsCollect = mapArticleCollectNum[article.ArticleId].IsCollect
  1064. }
  1065. //list[i].TitleEn = article.TitleEn
  1066. //list[i].UpdateFrequency = article.UpdateFrequency
  1067. //list[i].CreateDate = article.CreateDate
  1068. //list[i].Body, _ = services.GetReportContentTextSub(article.Body)
  1069. //list[i].Abstract = article.Abstract
  1070. //list[i].CategoryName = article.CategoryName
  1071. //list[i].SubCategoryName = article.SubCategoryName
  1072. }
  1073. }
  1074. page := paging.GetPaging(currentIndex, pageSize, total)
  1075. resp.List = list
  1076. resp.Paging = page
  1077. br.Msg = "获取成功!"
  1078. br.Ret = 200
  1079. br.Success = true
  1080. br.Data = resp
  1081. }
  1082. // @Title 获取我的提问
  1083. // @Description 获取我的提问列表
  1084. // @Param PageSize query int true "PageSize"
  1085. // @Param CurrentIndex query int true "CurrentIndex"
  1086. // @Success 200 {object} models.CygxAskListResp
  1087. // @router /ask/list [get]
  1088. func (this *UserController) AskList() {
  1089. br := new(models.BaseResponse).Init()
  1090. defer func() {
  1091. this.Data["json"] = br
  1092. this.ServeJSON()
  1093. }()
  1094. user := this.User
  1095. if user == nil {
  1096. br.Msg = "请登录"
  1097. br.ErrMsg = "请登录,用户信息为空"
  1098. br.Ret = 408
  1099. return
  1100. }
  1101. var pageSize, currentIndex, startSize int
  1102. pageSize, _ = this.GetInt("PageSize")
  1103. currentIndex, _ = this.GetInt("CurrentIndex")
  1104. if pageSize <= 0 {
  1105. pageSize = utils.PageSize20
  1106. }
  1107. if currentIndex <= 0 {
  1108. currentIndex = 1
  1109. }
  1110. startSize = utils.StartIndex(currentIndex, pageSize)
  1111. userId := this.User.UserId
  1112. total, err := models.GetActivityAskCount(userId)
  1113. if err != nil {
  1114. br.Msg = "获取数据失败"
  1115. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1116. return
  1117. }
  1118. listActcivity, err := models.GetActivityAskList(userId, startSize, pageSize)
  1119. if err != nil && err.Error() != utils.ErrNoRow() {
  1120. br.Msg = "获取失败"
  1121. br.ErrMsg = "获取活动问题失败,Err:" + err.Error()
  1122. return
  1123. }
  1124. for _, v := range listActcivity {
  1125. v.AskType = "Activity"
  1126. }
  1127. listArticle, err := models.GetArticleAskList(userId)
  1128. if err != nil && err.Error() != utils.ErrNoRow() {
  1129. br.Msg = "获取失败"
  1130. br.ErrMsg = "获取文章问题失败,Err:" + err.Error()
  1131. return
  1132. }
  1133. for _, v := range listArticle {
  1134. v.AskType = "Report"
  1135. listActcivity = append(listActcivity, v)
  1136. }
  1137. resp := new(models.CygxAskListResp)
  1138. page := paging.GetPaging(currentIndex, pageSize, total)
  1139. resp.Paging = page
  1140. resp.List = listActcivity
  1141. br.Msg = "获取成功!"
  1142. br.Ret = 200
  1143. br.Success = true
  1144. br.Data = resp
  1145. }
  1146. // @Title 我的收藏微路演列表
  1147. // @Description 我的收藏微路演列表接口
  1148. // @Param PageSize query int true "每页数据条数"
  1149. // @Param CurrentIndex query int true "当前页页码,从1开始"
  1150. // @Success 200 {object} models.HomeListResp
  1151. // @router /collect/microRoadShow [get]
  1152. func (this *UserController) Mycollect() {
  1153. br := new(models.BaseResponse).Init()
  1154. defer func() {
  1155. this.Data["json"] = br
  1156. this.ServeJSON()
  1157. }()
  1158. user := this.User
  1159. if user == nil {
  1160. br.Msg = "请登录"
  1161. br.ErrMsg = "请登录,用户信息为空"
  1162. br.Ret = 408
  1163. return
  1164. }
  1165. pageSize, _ := this.GetInt("PageSize")
  1166. currentIndex, _ := this.GetInt("CurrentIndex")
  1167. if pageSize <= 0 {
  1168. pageSize = utils.PageSize20
  1169. }
  1170. if currentIndex <= 0 {
  1171. currentIndex = 1
  1172. }
  1173. userId := user.UserId
  1174. listMycollect, err := models.GetUserMicroRoadshowCollectList(userId)
  1175. if err != nil {
  1176. br.Msg = "获取数据失败"
  1177. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1178. return
  1179. }
  1180. collectVoiceMap := make(map[int]time.Time, 0)
  1181. collectVideoMap := make(map[int]time.Time, 0)
  1182. collectActivityVideoMap := make(map[int]time.Time, 0)
  1183. var audioIds []string
  1184. var videoIds []string
  1185. var activityVideoIds []string
  1186. for _, item := range listMycollect {
  1187. if item.ActivityVoiceId > 0 {
  1188. audioIds = append(audioIds, strconv.Itoa(item.ActivityVoiceId))
  1189. collectVoiceMap[item.ActivityVoiceId] = item.CreateTime
  1190. } else if item.VideoId > 0 {
  1191. videoIds = append(videoIds, strconv.Itoa(item.VideoId))
  1192. collectVideoMap[item.VideoId] = item.CreateTime
  1193. } else if item.ActivityVideoId > 0 {
  1194. activityVideoIds = append(activityVideoIds, strconv.Itoa(item.ActivityVideoId))
  1195. collectActivityVideoMap[item.ActivityVideoId] = item.CreateTime
  1196. }
  1197. }
  1198. if len(audioIds) == 0 && len(videoIds) == 0 && len(activityVideoIds) == 0 {
  1199. resp := new(models.MicroRoadShowListResp)
  1200. page := paging.GetPaging(currentIndex, pageSize, 0)
  1201. resp.List = make([]*models.MicroRoadShowPageList, 0)
  1202. resp.Paging = page
  1203. br.Ret = 200
  1204. br.Success = true
  1205. br.Msg = "获取成功"
  1206. br.Data = resp
  1207. return
  1208. }
  1209. audioIdstr := strings.Join(audioIds, ",")
  1210. ideoIdsStr := strings.Join(videoIds, ",")
  1211. activityVideoIdsStr := strings.Join(activityVideoIds, ",")
  1212. // 微路演列表
  1213. list, total, e := services.GetMicroRoadShowMycollect(pageSize, currentIndex, audioIdstr, ideoIdsStr, activityVideoIdsStr)
  1214. if e != nil {
  1215. br.Msg = "获取失败"
  1216. br.ErrMsg = "获取微路演列表失败, Err: " + e.Error()
  1217. return
  1218. }
  1219. for _, item := range list {
  1220. if item.Type == 1 {
  1221. //音频
  1222. count, err := models.GetVoiceCollectCount(user.UserId, item.Id)
  1223. if err != nil {
  1224. br.Msg = "获取数据失败!"
  1225. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1226. return
  1227. }
  1228. if count > 0 {
  1229. item.IsCollect = true
  1230. }
  1231. if v, ok := collectVoiceMap[item.Id]; ok {
  1232. item.CollectTime = v
  1233. }
  1234. } else if item.Type == 2 {
  1235. //活动视频
  1236. count, err := models.GetActivityVideoCollectCount(user.UserId, item.Id)
  1237. if err != nil {
  1238. br.Msg = "获取数据失败!"
  1239. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1240. return
  1241. }
  1242. if count > 0 {
  1243. item.IsCollect = true
  1244. }
  1245. if v, ok := collectActivityVideoMap[item.Id]; ok {
  1246. item.CollectTime = v
  1247. }
  1248. } else if item.Type == 3 {
  1249. //微路演视频
  1250. count, err := models.GetVideoCollectCount(user.UserId, item.Id)
  1251. if err != nil {
  1252. br.Msg = "获取数据失败!"
  1253. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1254. return
  1255. }
  1256. if count > 0 {
  1257. item.IsCollect = true
  1258. }
  1259. if v, ok := collectVideoMap[item.Id]; ok {
  1260. item.CollectTime = v
  1261. }
  1262. }
  1263. }
  1264. // 用户权限
  1265. authInfo, permissionArr, e := services.GetUserRaiPermissionInfo(user.UserId, user.CompanyId)
  1266. if e != nil {
  1267. br.Msg = "获取失败"
  1268. br.ErrMsg = "获取用户权限失败, Err: " + e.Error()
  1269. return
  1270. }
  1271. // 获取默认图配置
  1272. audioMap, videoMap, audioShareMap, videoShareMap, e := services.GetMicroRoadShowDefaultImgConfig()
  1273. if e != nil {
  1274. br.Msg = "获取失败"
  1275. br.ErrMsg = "获取微路演列表失败, Err: " + e.Error()
  1276. return
  1277. }
  1278. for i := range list {
  1279. // 权限
  1280. au := new(models.UserPermissionAuthInfo)
  1281. au.SellerName = authInfo.SellerName
  1282. au.SellerMobile = authInfo.SellerMobile
  1283. au.HasPermission = authInfo.HasPermission
  1284. au.OperationMode = authInfo.OperationMode
  1285. if au.HasPermission == 1 {
  1286. // 非宏观权限进一步判断是否有权限
  1287. if list[i].ChartPermissionId != utils.HONG_GUAN_ID && !utils.InArrayByStr(permissionArr, list[i].ChartPermissionName) {
  1288. au.HasPermission = 2
  1289. }
  1290. }
  1291. // 无权限的弹框提示
  1292. if au.HasPermission != 1 {
  1293. if au.OperationMode == services.UserPermissionOperationModeCall {
  1294. if list[i].Type == 1 {
  1295. au.PopupMsg = services.UserPermissionPopupMsgCallActivity
  1296. } else {
  1297. au.PopupMsg = services.UserPermissionPopupMsgCallMicroVideo
  1298. }
  1299. } else {
  1300. if list[i].Type == 1 {
  1301. au.PopupMsg = services.UserPermissionPopupMsgApplyActivity
  1302. } else {
  1303. au.PopupMsg = services.UserPermissionPopupMsgApplyMicroVideo
  1304. }
  1305. }
  1306. }
  1307. list[i].AuthInfo = au
  1308. list[i].PublishTime = utils.StrTimeToTime(list[i].PublishTime).Format(utils.FormatDate)
  1309. // 默认图
  1310. if list[i].BackgroundImg == "" {
  1311. if list[i].Type == 1 {
  1312. list[i].BackgroundImg = audioMap[list[i].ChartPermissionId]
  1313. } else {
  1314. list[i].BackgroundImg = videoMap[list[i].ChartPermissionId]
  1315. }
  1316. }
  1317. // 分享图
  1318. if list[i].ShareImg == "" {
  1319. if list[i].Type == 1 {
  1320. list[i].ShareImg = audioShareMap[list[i].ChartPermissionId]
  1321. } else {
  1322. list[i].ShareImg = videoShareMap[list[i].ChartPermissionId]
  1323. }
  1324. }
  1325. }
  1326. var sortList models.MicroList
  1327. sortList = list
  1328. sort.Sort(sortList)
  1329. resp := new(models.MicroRoadShowListResp)
  1330. page := paging.GetPaging(currentIndex, pageSize, total)
  1331. resp.List = sortList
  1332. resp.Paging = page
  1333. br.Ret = 200
  1334. br.Success = true
  1335. br.Msg = "获取成功"
  1336. br.Data = resp
  1337. }