user.go 38 KB

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