user.go 44 KB

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