user.go 41 KB

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