user.go 43 KB

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