user.go 44 KB

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