user.go 44 KB

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