user.go 42 KB

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