user.go 42 KB

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