user.go 44 KB

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