user.go 42 KB

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