user.go 38 KB

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