user.go 44 KB

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