user.go 41 KB

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