user.go 41 KB

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