user.go 44 KB

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