yanxuan_special.go 27 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012
  1. package cygx
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "github.com/rdlucklib/rdluck_tools/paging"
  6. "github.com/tealeg/xlsx"
  7. "hongze/hz_crm_api/controllers"
  8. "hongze/hz_crm_api/models"
  9. "hongze/hz_crm_api/models/company"
  10. "hongze/hz_crm_api/models/cygx"
  11. "hongze/hz_crm_api/services"
  12. cygxService "hongze/hz_crm_api/services/cygx"
  13. "hongze/hz_crm_api/services/elastic"
  14. "hongze/hz_crm_api/utils"
  15. "os"
  16. "path/filepath"
  17. "strconv"
  18. "strings"
  19. "time"
  20. )
  21. // YanxuanSpecialController 研选专栏
  22. type YanxuanSpecialController struct {
  23. controllers.BaseAuthController
  24. }
  25. // @Title 新增研选专栏作者
  26. // @Description 新增研选专栏作者
  27. // @Param request body help_doc.AddHelpDocReq true "type json string"
  28. // @Success 200 {object} models.AddEnglishReportResp
  29. // @router /yanxuan_special/author/add [post]
  30. func (this *YanxuanSpecialController) Add() {
  31. br := new(models.BaseResponse).Init()
  32. defer func() {
  33. this.Data["json"] = br
  34. this.ServeJSON()
  35. }()
  36. sysUser := this.SysUser
  37. if sysUser == nil {
  38. br.Msg = "请登录"
  39. br.ErrMsg = "请登录,SysUser Is Empty"
  40. br.Ret = 408
  41. return
  42. }
  43. var req cygx.AddCygxYanxuanSpecialAuthorReq
  44. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  45. if err != nil {
  46. br.Msg = "参数解析异常!"
  47. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  48. return
  49. }
  50. if req.UserId <= 0 {
  51. br.Msg = "请输入用户信息"
  52. return
  53. }
  54. if req.RealName == "" {
  55. br.Msg = "请输入真实姓名"
  56. return
  57. }
  58. if req.Mobile == "" {
  59. br.Msg = "请输入手机号"
  60. return
  61. }
  62. //获取关联公司的用户信息
  63. infoUser, err := cygx.GetUserAndCompanyNameList(req.UserId)
  64. if err != nil {
  65. br.Msg = "获取失败"
  66. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  67. return
  68. }
  69. rnd := utils.GetRandInt(1, 5)
  70. item := cygx.CygxYanxuanSpecialAuthor{
  71. UserId: req.UserId,
  72. RealName: req.RealName,
  73. Mobile: req.Mobile,
  74. MobileInit: infoUser.Mobile,
  75. CompanyName: infoUser.CompanyName,
  76. CompanyId: infoUser.CompanyId,
  77. InviteName: req.InviteName,
  78. Remark: req.Remark,
  79. CreateTime: time.Now(),
  80. ModifyTime: time.Now(),
  81. HeadImg: utils.CYGX_YANXUAN_SPECIAL_HEAD_IMG_URL + strconv.Itoa(rnd) + ".png",
  82. BgImg: utils.CYGX_YANXUAN_SPECIAL_BG_IMG_URL + strconv.Itoa(rnd) + "a.png",
  83. BgImgDown: utils.CYGX_YANXUAN_SPECIAL_BG_IMG_URL + strconv.Itoa(rnd) + "b.png",
  84. BgImgPc: utils.CYGX_YANXUAN_SPECIAL_BG_IMG_URL_PC + strconv.Itoa(rnd) + ".png",
  85. Status: 1,
  86. }
  87. _, err = cygx.AddCygxYanxuanSpecialAuthor(&item)
  88. if err != nil {
  89. br.Msg = "新增失败"
  90. br.ErrMsg = "新增失败,Err:" + err.Error()
  91. return
  92. }
  93. br.Ret = 200
  94. br.Success = true
  95. br.Msg = "新增成功"
  96. }
  97. // @Title 禁用/启用研选专栏作者
  98. // @Description 禁用/启用研选专栏作者
  99. // @Param request body help_doc.AddHelpDocReq true "type json string"
  100. // @Success 200 {object} models.AddEnglishReportResp
  101. // @router /yanxuan_special/author/enable [post]
  102. func (this *YanxuanSpecialController) AuthorEnable() {
  103. br := new(models.BaseResponse).Init()
  104. defer func() {
  105. this.Data["json"] = br
  106. this.ServeJSON()
  107. }()
  108. sysUser := this.SysUser
  109. if sysUser == nil {
  110. br.Msg = "请登录"
  111. br.ErrMsg = "请登录,SysUser Is Empty"
  112. br.Ret = 408
  113. return
  114. }
  115. var req cygx.EnableCygxYanxuanSpecialAuthorReq
  116. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  117. if err != nil {
  118. br.Msg = "参数解析异常!"
  119. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  120. return
  121. }
  122. if req.UserId <= 0 {
  123. br.Msg = "用户id错误"
  124. return
  125. }
  126. if req.Status <= 0 {
  127. br.Msg = "参数错误"
  128. return
  129. }
  130. if tmpErr := cygx.EnableYanxuanSpecialAuthor(req.UserId, req.Status); tmpErr != nil {
  131. br.Msg = "启用/禁用作者失败"
  132. br.ErrMsg = "启用/禁用作者失败, Err:" + tmpErr.Error()
  133. return
  134. }
  135. if req.Status == 1 {
  136. br.Msg = "启用成功"
  137. } else {
  138. br.Msg = "禁用成功"
  139. }
  140. br.Ret = 200
  141. br.Success = true
  142. }
  143. // @Title 作者列表
  144. // @Description 作者列表
  145. // @Param request body help_doc.AddHelpDocReq true "type json string"
  146. // @Param PageSize query int true "每页数据条数"
  147. // @Param CurrentIndex query int true "当前页页码,从1开始"
  148. // @Param Status query string true "状态: 1:启用 、 2:禁用 。传其他默认所有"
  149. // @Param KeyWord query string false "搜索关键词"
  150. // @Param NickName query string false "昵称"
  151. // @Param SortParam query string false "排序字段参数,用来排序的字段, 枚举值:'CreatTime':开通时间 、 'articleNum':已发布文章 、 'pv':总Pv/Uv "
  152. // @Param SortType query string true "如何排序,是正序还是倒序,枚举值:`asc 正序`,`desc 倒叙`"
  153. // @Success 200 {object} models.AddEnglishReportResp
  154. // @router /yanxuan_special/author/list [get]
  155. func (this *YanxuanSpecialController) AuthorList() {
  156. br := new(models.BaseResponse).Init()
  157. defer func() {
  158. this.Data["json"] = br
  159. this.ServeJSON()
  160. }()
  161. sysUser := this.SysUser
  162. if sysUser == nil {
  163. br.Msg = "请登录"
  164. br.ErrMsg = "请登录,SysUser Is Empty"
  165. br.Ret = 408
  166. return
  167. }
  168. pageSize, _ := this.GetInt("PageSize")
  169. currentIndex, _ := this.GetInt("CurrentIndex")
  170. status, _ := this.GetInt("Status")
  171. keyWord := this.GetString("KeyWord")
  172. //排序参数
  173. sortParam := this.GetString("SortParam")
  174. sortType := this.GetString("SortType")
  175. nickName := this.GetString("NickName")
  176. var startSize int
  177. if pageSize <= 0 {
  178. pageSize = utils.PageSize20
  179. }
  180. if currentIndex <= 0 {
  181. currentIndex = 1
  182. }
  183. startSize = utils.StartIndex(currentIndex, pageSize)
  184. var condition string
  185. var pars []interface{}
  186. //作者状态处理
  187. if status == 1 || status == 2 {
  188. condition += ` AND art.status = ? `
  189. pars = append(pars, status)
  190. }
  191. //关键词搜索
  192. if keyWord != "" {
  193. keyWord = "%" + keyWord + "%"
  194. condition += ` AND art.special_name like ? `
  195. pars = append(pars, keyWord)
  196. }
  197. //关键词搜索
  198. if nickName != "" {
  199. nickName = "%" + nickName + "%"
  200. condition += ` AND art.nick_name like ? `
  201. pars = append(pars, nickName)
  202. }
  203. //排序字段以及排序方式处理
  204. var sortStr string
  205. if sortParam != "" && sortType != "" {
  206. if sortParam == "CreateTime" {
  207. if sortType == "asc" {
  208. sortStr = " ORDER BY art.create_time ASC "
  209. } else {
  210. sortStr = " ORDER BY art.create_time DESC "
  211. }
  212. }
  213. if sortParam == "ArticleNum" {
  214. if sortType == "asc" {
  215. sortStr = " ORDER BY art.article_num ASC "
  216. } else {
  217. sortStr = " ORDER BY art.article_num DESC "
  218. }
  219. }
  220. if sortParam == "pv" {
  221. if sortType == "asc" {
  222. sortStr = " ORDER BY art.pv ASC "
  223. } else {
  224. sortStr = " ORDER BY art.pv DESC "
  225. }
  226. }
  227. if sortStr == "" {
  228. sortStr = " ORDER BY a.publish_time DESC " // 兼容前端老六乱传字段
  229. }
  230. } else {
  231. sortStr = " ORDER BY art.create_time DESC "
  232. }
  233. total, err := cygx.GetYanxuanSpecialAuthorCount(condition, pars)
  234. if err != nil {
  235. br.Msg = "获取失败"
  236. br.ErrMsg = "获取失败,Err:" + err.Error()
  237. return
  238. }
  239. list, tmpErr := cygx.GetYanxuanSpecialAuthorList(condition+sortStr, pars, startSize, pageSize)
  240. if tmpErr != nil {
  241. br.Msg = "获取失败"
  242. br.ErrMsg = "获取失败, Err:" + tmpErr.Error()
  243. return
  244. }
  245. var userIds []int
  246. var mobiles []string
  247. for _, v := range list {
  248. userIds = append(userIds, v.UserId)
  249. if v.MobileInit != "" {
  250. mobiles = append(mobiles, v.MobileInit)
  251. }
  252. }
  253. listUser, err := models.GetWxUserRaiSllerListByUserMobile(mobiles)
  254. if err != nil {
  255. br.Msg = "获取失败"
  256. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  257. return
  258. }
  259. //获取用户当前最新的公司信息
  260. mapWxUserSller := make(map[string]*models.WxUserSller)
  261. for _, v := range listUser {
  262. mapWxUserSller[v.Mobile] = v
  263. }
  264. //对权益管理员跟超管展示全部手机号
  265. var isShow bool
  266. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN || sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  267. isShow = true
  268. }
  269. //获取专栏用户最新的一篇文章信息
  270. mapNewTime := cygxService.GetBestNewYanxuanSpecialByUserId(userIds)
  271. for _, v := range list {
  272. v.SpecialAuthorId = v.Id
  273. v.ArticlePublishTime = mapNewTime[v.UserId]
  274. mapItem := mapWxUserSller[v.MobileInit]
  275. if mapItem != nil {
  276. v.CompanyName = mapItem.CompanyName
  277. v.CompanyId = mapItem.CompanyId
  278. }
  279. if isShow {
  280. v.Mobile = v.MobileInit
  281. }
  282. }
  283. resp := new(cygx.GetCygxYanxuanSpecialAuthorItemResp)
  284. page := paging.GetPaging(currentIndex, pageSize, total)
  285. resp.List = list
  286. resp.Paging = page
  287. br.Data = resp
  288. br.Ret = 200
  289. br.Success = true
  290. br.Msg = "获取成功"
  291. }
  292. // @Title 审核列表
  293. // @Description 审核列表
  294. // @Param PageSize query int true "每页数据条数"
  295. // @Param CurrentIndex query int true "当前页页码,从1开始"
  296. // @Param Status query string true "状态: 1:待审核 、 2:已发布 。默认待审核"
  297. // @Param Type query int true "文章类型,1:笔记、2:观点"
  298. // @Param KeyWord query string false "搜索关键词"
  299. // @Param NickName query string false "昵称"
  300. // @Param SortParam query string false "排序字段参数,用来排序的字段, 枚举值:'CreatTime':开通时间 、 'articleNum':已发布文章 、 'pv':总Pv/Uv "
  301. // @Param SortType query string true "如何排序,是正序还是倒序,枚举值:`asc 正序`,`desc 倒叙`"
  302. // @Param StartDate query string false "开始时间 ,列如2021-03-06 "
  303. // @Param EndDate query string false "结束时间,列如2021-03-06 "
  304. // @Success 200 {object} models.AddEnglishReportResp
  305. // @router /yanxuan_special/list [get]
  306. func (this *YanxuanSpecialController) List() {
  307. br := new(models.BaseResponse).Init()
  308. defer func() {
  309. this.Data["json"] = br
  310. this.ServeJSON()
  311. }()
  312. sysUser := this.SysUser
  313. if sysUser == nil {
  314. br.Msg = "请登录"
  315. br.ErrMsg = "请登录,SysUser Is Empty"
  316. br.Ret = 408
  317. return
  318. }
  319. userId, _ := this.GetInt("UserId", 0)
  320. pageSize, _ := this.GetInt("PageSize")
  321. currentIndex, _ := this.GetInt("CurrentIndex")
  322. status, _ := this.GetInt("Status", 1)
  323. specialType, _ := this.GetInt("Type")
  324. keyWord := this.GetString("KeyWord")
  325. //排序参数
  326. sortParam := this.GetString("SortParam")
  327. sortType := this.GetString("SortType")
  328. startDate := this.GetString("StartDate")
  329. endDate := this.GetString("EndDate")
  330. nickName := this.GetString("NickName")
  331. var startSize int
  332. if pageSize <= 0 {
  333. pageSize = utils.PageSize20
  334. }
  335. if currentIndex <= 0 {
  336. currentIndex = 1
  337. }
  338. startSize = utils.StartIndex(currentIndex, pageSize)
  339. var condition string
  340. var pars []interface{}
  341. if userId > 0 {
  342. condition += ` AND a.user_id = ? `
  343. pars = append(pars, userId)
  344. }
  345. if status == 1 {
  346. condition += ` AND a.status = 2 `
  347. }
  348. if status == 2 {
  349. condition += ` AND a.status = 3 `
  350. }
  351. if startDate != "" {
  352. condition += ` AND a.publish_time >= ` + "'" + startDate + " 00:00:00'"
  353. }
  354. if endDate != "" {
  355. condition += ` AND a.publish_time <= ` + "'" + endDate + " 23:59:59'"
  356. }
  357. //文章类型
  358. if specialType == 1 || specialType == 2 {
  359. condition += ` AND a.type = ? `
  360. pars = append(pars, specialType)
  361. }
  362. //关键词搜索
  363. if keyWord != "" {
  364. keyWord = "%" + keyWord + "%"
  365. condition += ` AND a.title like ? `
  366. pars = append(pars, keyWord)
  367. }
  368. //昵称搜索
  369. if nickName != "" {
  370. nickName = "%" + nickName + "%"
  371. condition += ` AND b.nick_name like ? `
  372. pars = append(pars, nickName)
  373. }
  374. //排序字段以及排序方式处理
  375. var sortStr string
  376. if sortParam != "" && sortType != "" {
  377. if sortParam == "pv" {
  378. if sortType == "asc" {
  379. sortStr = " ORDER BY a.pv ASC "
  380. } else {
  381. sortStr = " ORDER BY a.pv DESC "
  382. }
  383. }
  384. if sortStr == "" {
  385. sortStr = " ORDER BY a.publish_time DESC " // 兼容前端老六乱传字段
  386. }
  387. } else {
  388. sortStr = " ORDER BY a.publish_time DESC "
  389. }
  390. total, err := cygx.GetGetYanxuanSpecialCount(condition, pars)
  391. if err != nil {
  392. br.Msg = "获取失败"
  393. br.ErrMsg = "获取失败,Err:" + err.Error()
  394. return
  395. }
  396. list, tmpErr := cygx.GetYanxuanSpecialList(condition+sortStr, pars, startSize, pageSize)
  397. if tmpErr != nil {
  398. br.Msg = "获取失败"
  399. br.ErrMsg = "获取失败, Err:" + tmpErr.Error()
  400. return
  401. }
  402. pars = make([]interface{}, 0)
  403. listAuthor, tmpErr := cygx.GetYanxuanSpecialAuthorList("", pars, 0, 999)
  404. if tmpErr != nil {
  405. br.Msg = "获取失败"
  406. br.ErrMsg = "获取失败, Err:" + tmpErr.Error()
  407. return
  408. }
  409. mapUserId := make(map[int]int)
  410. for _, v := range listAuthor {
  411. mapUserId[v.UserId] = v.Id
  412. }
  413. for _, v := range list {
  414. v.SpecialAuthorId = mapUserId[v.UserId]
  415. hasImg, err := utils.ArticleHasImgUrl(v.Content)
  416. if err != nil {
  417. return
  418. }
  419. if hasImg {
  420. v.ContentHasImg = 1
  421. }
  422. if v.DocUrl != "" {
  423. var docs []cygx.Doc
  424. err := json.Unmarshal([]byte(v.DocUrl), &docs)
  425. if err != nil {
  426. br.Msg = "参数解析异常!"
  427. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  428. return
  429. }
  430. v.Docs = docs
  431. }
  432. if v.CompanyTags != "" {
  433. v.Tags += v.CompanyTags
  434. }
  435. if v.IndustryTags != "" {
  436. if v.Tags != "" {
  437. v.Tags += ","
  438. }
  439. v.Tags += v.IndustryTags
  440. }
  441. }
  442. resp := new(cygx.GetCygxYanxuanSpeciaResplItemResp)
  443. page := paging.GetPaging(currentIndex, pageSize, total)
  444. resp.List = list
  445. resp.Paging = page
  446. br.Data = resp
  447. br.Ret = 200
  448. br.Success = true
  449. br.Msg = "获取成功"
  450. }
  451. // @Title 审批研选专栏
  452. // @Description 审批研选专栏
  453. // @Param request body help_doc.AddHelpDocReq true "type json string"
  454. // @Success 200 {object} models.AddEnglishReportResp
  455. // @router /yanxuan_special/enable [post]
  456. func (this *YanxuanSpecialController) Enable() {
  457. br := new(models.BaseResponse).Init()
  458. defer func() {
  459. this.Data["json"] = br
  460. this.ServeJSON()
  461. }()
  462. sysUser := this.SysUser
  463. if sysUser == nil {
  464. br.Msg = "请登录"
  465. br.ErrMsg = "请登录,SysUser Is Empty"
  466. br.Ret = 408
  467. return
  468. }
  469. var req cygx.EnableCygxYanxuanSpecialReq
  470. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  471. if err != nil {
  472. br.Msg = "参数解析异常!"
  473. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  474. return
  475. }
  476. if req.Id <= 0 {
  477. br.Msg = "文章id错误"
  478. return
  479. }
  480. if req.Status <= 0 {
  481. br.Msg = "参数错误"
  482. return
  483. }
  484. status := 0
  485. if req.Status == 1 {
  486. status = 3
  487. } else {
  488. status = 4
  489. }
  490. if tmpErr := cygx.EnableYanxuanSpecial(req.Id, status, req.Reason, sysUser.RealName); tmpErr != nil {
  491. br.Msg = "审批失败"
  492. br.ErrMsg = "审批失败, Err:" + tmpErr.Error()
  493. return
  494. }
  495. if req.Status == 1 {
  496. go cygxService.SendWxMsgSpecialFollow(req.Id)
  497. go services.SendWxCategoryMsgSpecialFollow(req.Id)
  498. }
  499. go cygxService.SendWxMsgSpecialAuthor(req.Id, req.Status) // 研选专栏审核完成时,给提交人发送模板消息
  500. go services.SendWxCategoryMsgSpecialAuthor(req.Id, req.Status) // 研选专栏审核完成时,给提交人发送模板消息
  501. go cygxService.UpdateYanxuanSpecialResourceData(req.Id) // 写入首页最新 cygx_resource_data 表
  502. go elastic.EsAddYanxuanSpecial(req.Id) // 写入es 综合搜索
  503. br.Msg = "审批成功"
  504. br.Ret = 200
  505. br.Success = true
  506. }
  507. // @Title 收藏详情
  508. // @Description 收藏详情
  509. // @Param SpecialId query int true "每页数据条数"
  510. // @Success 200 {object} models.AddEnglishReportResp
  511. // @router /yanxuan_special/special_collect/list [get]
  512. func (this *YanxuanSpecialController) SpecialCollectList() {
  513. br := new(models.BaseResponse).Init()
  514. defer func() {
  515. this.Data["json"] = br
  516. this.ServeJSON()
  517. }()
  518. sysUser := this.SysUser
  519. if sysUser == nil {
  520. br.Msg = "请登录"
  521. br.ErrMsg = "请登录,SysUser Is Empty"
  522. br.Ret = 408
  523. return
  524. }
  525. specialId, _ := this.GetInt("SpecialId")
  526. var condition string
  527. var pars []interface{}
  528. condition += " AND yanxuan_special_id = ? ORDER BY art.create_time DESC "
  529. pars = append(pars, specialId)
  530. list, err := cygx.GetCygxYanxuanSpecialCollectList(condition, pars, 0, 100000)
  531. if err != nil {
  532. br.Msg = "获取失败"
  533. br.ErrMsg = "获取失败,Err:" + err.Error()
  534. return
  535. }
  536. resp := new(cygx.GetCygxYanxuanSpecialCollectResp)
  537. resp.List = list
  538. br.Data = resp
  539. br.Ret = 200
  540. br.Success = true
  541. br.Msg = "获取成功"
  542. }
  543. // @Title 下载PV
  544. // @Description 下载PV接口
  545. // @Param SpecialId query int true "每页数据条数"
  546. // @router /yanxuan_special/list_pv [get]
  547. func (this *YanxuanSpecialController) ListPv() {
  548. br := new(models.BaseResponse).Init()
  549. defer func() {
  550. this.Data["json"] = br
  551. this.ServeJSON()
  552. }()
  553. AdminUser := this.SysUser
  554. if AdminUser == nil {
  555. br.Msg = "请登录"
  556. br.ErrMsg = "请登录,用户信息为空"
  557. br.Ret = 408
  558. return
  559. }
  560. specialId, _ := this.GetInt("SpecialId")
  561. if specialId < 1 {
  562. br.Msg = "请输入专栏ID"
  563. return
  564. }
  565. var condition string
  566. var pars []interface{}
  567. condition = ` AND yanxuan_special_id = ? ORDER BY create_time DESC `
  568. pars = append(pars, specialId)
  569. list, err := cygx.GetCygxYanxuanSpecialRecordList(condition, pars)
  570. if err != nil {
  571. br.Msg = "获取失败"
  572. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  573. return
  574. }
  575. var companyIds []int
  576. for _, v := range list {
  577. companyIds = append(companyIds, v.CompanyId)
  578. }
  579. listCompanyProduct, err := company.GetCompanyProductListByCompanyIds(companyIds, 2)
  580. if err != nil && err.Error() != utils.ErrNoRow() {
  581. br.Msg = "获取失败"
  582. br.ErrMsg = "获取销售列表失败,Err:" + err.Error()
  583. return
  584. }
  585. mapsCompanyStatus := make(map[int]string)
  586. for _, v := range listCompanyProduct {
  587. mapsCompanyStatus[v.CompanyId] = v.Status
  588. }
  589. //创建excel
  590. dir, err := os.Executable()
  591. exPath := filepath.Dir(dir)
  592. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  593. xlsxFile := xlsx.NewFile()
  594. if err != nil {
  595. br.Msg = "生成文件失败"
  596. br.ErrMsg = "生成文件失败"
  597. return
  598. }
  599. style := xlsx.NewStyle()
  600. alignment := xlsx.Alignment{
  601. Horizontal: "center",
  602. Vertical: "center",
  603. WrapText: true,
  604. }
  605. style.Alignment = alignment
  606. style.ApplyAlignment = true
  607. sheet, err := xlsxFile.AddSheet("阅读明细")
  608. if err != nil {
  609. br.Msg = "新增Sheet失败"
  610. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  611. return
  612. }
  613. rowTitle := sheet.AddRow()
  614. cellA := rowTitle.AddCell()
  615. cellA.Value = "姓名"
  616. cellMobile := rowTitle.AddCell()
  617. cellMobile.Value = "手机号"
  618. cellB := rowTitle.AddCell()
  619. cellB.Value = "公司名称"
  620. cellCompanyStatus := rowTitle.AddCell()
  621. cellCompanyStatus.Value = "客户状态"
  622. cellC := rowTitle.AddCell()
  623. cellC.Value = "所属权益销售"
  624. cellD := rowTitle.AddCell()
  625. cellD.Value = "阅读时间"
  626. cellE := rowTitle.AddCell()
  627. cellE.Value = "阅读时长"
  628. for _, item := range list {
  629. row := sheet.AddRow()
  630. cellA := row.AddCell()
  631. cellA.Value = item.RealName
  632. cellMobile := row.AddCell()
  633. cellMobile.Value = item.Mobile
  634. cellB := row.AddCell()
  635. cellB.Value = item.CompanyName
  636. cellCompanyStatus := row.AddCell()
  637. cellCompanyStatus.Value = mapsCompanyStatus[item.CompanyId]
  638. cellC := row.AddCell()
  639. cellC.Value = item.SellerName
  640. cellD := row.AddCell()
  641. cellD.Value = item.CreateTime
  642. cellE := row.AddCell()
  643. cellE.Value = strconv.Itoa(item.StopTime)
  644. }
  645. err = xlsxFile.Save(downLoadnFilePath)
  646. if err != nil {
  647. br.Msg = "保存文件失败"
  648. br.ErrMsg = "保存文件失败"
  649. return
  650. }
  651. downloadFileName := time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  652. this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  653. defer func() {
  654. os.Remove(downLoadnFilePath)
  655. }()
  656. br.Ret = 200
  657. br.Success = true
  658. br.Msg = "导出成功"
  659. }
  660. // @Title 审批记录
  661. // @Description 审批记录接口
  662. // @Param PageSize query int true "每页数据条数"
  663. // @Param CurrentIndex query int true "当前页页码,从1开始"
  664. // @Success 200 {object} models.CygxYanxuanSpecialApprovalLogListResp
  665. // @router /yanxuan_special/approval_log_list [get]
  666. func (this *YanxuanSpecialController) ApprovalLogList() {
  667. br := new(models.BaseResponse).Init()
  668. defer func() {
  669. this.Data["json"] = br
  670. this.ServeJSON()
  671. }()
  672. sysUser := this.SysUser
  673. if sysUser == nil {
  674. br.Msg = "请登录"
  675. br.ErrMsg = "请登录,SysUser Is Empty"
  676. br.Ret = 408
  677. return
  678. }
  679. pageSize, _ := this.GetInt("PageSize")
  680. currentIndex, _ := this.GetInt("CurrentIndex")
  681. var startSize int
  682. if pageSize <= 0 {
  683. pageSize = utils.PageSize20
  684. }
  685. if currentIndex <= 0 {
  686. currentIndex = 1
  687. }
  688. startSize = utils.StartIndex(currentIndex, pageSize)
  689. var condition string
  690. var pars []interface{}
  691. //只是查询驳回状态的数据
  692. condition += ` AND a.approval_status = 2 `
  693. total, err := cygx.GetCygxYanxuanSpecialApprovalLogCount(condition, pars)
  694. if err != nil {
  695. br.Msg = "获取失败"
  696. br.ErrMsg = "获取失败,Err:" + err.Error()
  697. return
  698. }
  699. condition += ` ORDER BY create_time DESC `
  700. list, tmpErr := cygx.GetCygxYanxuanSpecialApprovalLogList(condition, pars, startSize, pageSize)
  701. if tmpErr != nil {
  702. br.Msg = "获取失败"
  703. br.ErrMsg = "获取失败, Err:" + tmpErr.Error()
  704. return
  705. }
  706. pars = make([]interface{}, 0)
  707. listAuthor, tmpErr := cygx.GetYanxuanSpecialAuthorList("", pars, 0, 999)
  708. if tmpErr != nil {
  709. br.Msg = "获取失败"
  710. br.ErrMsg = "获取失败, Err:" + tmpErr.Error()
  711. return
  712. }
  713. mapUserId := make(map[int]int)
  714. for _, v := range listAuthor {
  715. mapUserId[v.UserId] = v.Id
  716. }
  717. for _, v := range list {
  718. v.SpecialAuthorId = mapUserId[v.UserId]
  719. }
  720. resp := new(cygx.CygxYanxuanSpecialApprovalLogListResp)
  721. page := paging.GetPaging(currentIndex, pageSize, total)
  722. resp.List = list
  723. resp.Paging = page
  724. br.Data = resp
  725. br.Ret = 200
  726. br.Success = true
  727. br.Msg = "获取成功"
  728. }
  729. // @Title 按钮是否展示接口
  730. // @Description 按钮是否展示接口
  731. // @Success 200 {object} models.AddEnglishReportResp
  732. // @router /yanxuan_special/show_button [get]
  733. func (this *YanxuanSpecialController) ShowButton() {
  734. br := new(models.BaseResponse).Init()
  735. defer func() {
  736. this.Data["json"] = br
  737. this.ServeJSON()
  738. }()
  739. sysUser := this.SysUser
  740. if sysUser == nil {
  741. br.Msg = "请登录"
  742. br.ErrMsg = "请登录,SysUser Is Empty"
  743. br.Ret = 408
  744. return
  745. }
  746. resp := new(cygx.CygxYanxuanSpecialShowButton)
  747. //configCode := utils.TPL_MSG_NEI_RONG_ZU
  748. //cnfNeiRong, err := cygx.GetConfigByCode(configCode)
  749. //if err != nil {
  750. // br.Msg = "获取失败"
  751. // br.ErrMsg = "获取失败,Err:" + err.Error()
  752. // return
  753. //}
  754. ////汪洋王芳手机号
  755. //configCode = utils.TPL_MSG_WANG_FANG_WANG_YANG
  756. //cnfWang, err := cygx.GetConfigByCode(configCode)
  757. //if err != nil {
  758. // br.Msg = "获取失败"
  759. // br.ErrMsg = "获取失败,Err:" + err.Error()
  760. // return
  761. //}
  762. //文章管理专栏是否可见
  763. cnfArticle, err := cygx.GetConfigByCode(utils.YANXUAN_SPECIAL_ARTICLE_BUTTON_MOBILE)
  764. if err != nil {
  765. br.Msg = "获取失败"
  766. br.ErrMsg = "获取失败,Err:" + err.Error()
  767. return
  768. }
  769. articleMobileSlice := strings.Split(cnfArticle.ConfigValue, ",")
  770. if utils.InArrayByStr(articleMobileSlice, sysUser.Mobile) || sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  771. resp.IsShowYanXuanSpecial = true
  772. }
  773. //作者管理专栏是否可见
  774. cnfAuthor, err := cygx.GetConfigByCode(utils.YANXUAN_SPECIAL_AUTHOR_BUTTON_MOBILE)
  775. if err != nil {
  776. br.Msg = "获取失败"
  777. br.ErrMsg = "获取失败,Err:" + err.Error()
  778. return
  779. }
  780. authorMobileSlice := strings.Split(cnfAuthor.ConfigValue, ",")
  781. if utils.InArrayByStr(authorMobileSlice, sysUser.Mobile) || sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  782. resp.IsShowSpecialAuthor = true
  783. }
  784. br.Data = resp
  785. br.Ret = 200
  786. br.Success = true
  787. br.Msg = "获取成功"
  788. }
  789. // @Title 作者粉丝列表
  790. // @Description 作者粉丝列表
  791. // @Param SpecialAuthorId query int true "作者ID"
  792. // @Success 200 {object} models.AddEnglishReportResp
  793. // @router /yanxuan_special/special_author_fans_list [get]
  794. func (this *YanxuanSpecialController) SpecialAuthorFansList() {
  795. br := new(models.BaseResponse).Init()
  796. defer func() {
  797. this.Data["json"] = br
  798. this.ServeJSON()
  799. }()
  800. sysUser := this.SysUser
  801. if sysUser == nil {
  802. br.Msg = "请登录"
  803. br.ErrMsg = "请登录,SysUser Is Empty"
  804. br.Ret = 408
  805. return
  806. }
  807. specialAuthorId, _ := this.GetInt("SpecialAuthorId")
  808. detail, err := cygx.GetCygxYanxuanSpecialAuthorItemById(specialAuthorId)
  809. if err != nil {
  810. br.Msg = "获取失败"
  811. br.ErrMsg = "获取失败,Err:" + err.Error()
  812. return
  813. }
  814. var condition string
  815. var pars []interface{}
  816. condition += " AND follow_user_id = ? ORDER BY a.create_time DESC "
  817. pars = append(pars, detail.UserId)
  818. list, err := cygx.GetCygxYanxuanSpecialFollowList(condition, pars, 0, 100000)
  819. if err != nil {
  820. br.Msg = "获取失败"
  821. br.ErrMsg = "获取失败,Err:" + err.Error()
  822. return
  823. }
  824. resp := new(cygx.GetCygxYanxuanSpecialFollowResp)
  825. resp.List = list
  826. br.Data = resp
  827. br.Ret = 200
  828. br.Success = true
  829. br.Msg = "获取成功"
  830. }
  831. func init_928() {
  832. var condition string
  833. var pars []interface{}
  834. list, err := cygx.GetYanxuanSpecialAuthorList(condition, pars, 0, 999)
  835. if err != nil {
  836. fmt.Println(err)
  837. return
  838. }
  839. for k, v := range list {
  840. fmt.Println(k)
  841. //获取关联公司的用户信息
  842. infoUser, err := cygx.GetUserAndCompanyNameList(v.UserId)
  843. if err != nil && err.Error() != utils.ErrNoRow() {
  844. fmt.Println(err)
  845. return
  846. }
  847. if infoUser == nil {
  848. continue
  849. }
  850. err = cygx.UpdateSpecialAuthormobile_init(infoUser.Mobile, infoUser.UserId)
  851. if err != nil {
  852. fmt.Println(err)
  853. return
  854. }
  855. }
  856. return
  857. }
  858. // @Title 修改作者信息
  859. // @Description 修改作者信息接口
  860. // @Param request body help_doc.AddHelpDocReq true "type json string"
  861. // @router /yanxuan_special/author/update [post]
  862. func (this *YanxuanSpecialController) AuthorUpdate() {
  863. br := new(models.BaseResponse).Init()
  864. defer func() {
  865. this.Data["json"] = br
  866. this.ServeJSON()
  867. }()
  868. sysUser := this.SysUser
  869. if sysUser == nil {
  870. br.Msg = "请登录"
  871. br.ErrMsg = "请登录,SysUser Is Empty"
  872. br.Ret = 408
  873. return
  874. }
  875. var req cygx.AddCygxYanxuanSpecialAuthorReq
  876. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  877. if err != nil {
  878. br.Msg = "参数解析异常!"
  879. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  880. return
  881. }
  882. if req.UserId <= 0 {
  883. br.Msg = "请输入用户信息"
  884. return
  885. }
  886. err = cygx.UpdateYanxuanSpecialAuthorInviteName(req.InviteName, req.Remark, req.UserId)
  887. if err != nil {
  888. br.Msg = "新增失败"
  889. br.ErrMsg = "新增失败,Err:" + err.Error()
  890. return
  891. }
  892. br.Ret = 200
  893. br.Success = true
  894. br.Msg = "修改成功"
  895. }
  896. // @Title 作者列表
  897. // @Description 作者列表
  898. // @Param KeyWord query string false "搜索关键词"
  899. // @Success 200 {object} models.AddEnglishReportResp
  900. // @router /yanxuan_special/author/search [get]
  901. func (this *YanxuanSpecialController) AuthorSearch() {
  902. br := new(models.BaseResponse).Init()
  903. defer func() {
  904. this.Data["json"] = br
  905. this.ServeJSON()
  906. }()
  907. sysUser := this.SysUser
  908. if sysUser == nil {
  909. br.Msg = "请登录"
  910. br.ErrMsg = "请登录,SysUser Is Empty"
  911. br.Ret = 408
  912. return
  913. }
  914. keyWord := this.GetString("KeyWord")
  915. var condition string
  916. var pars []interface{}
  917. resp := new(cygx.CygxYanxuanSpecialKeyWordListReesp)
  918. //关键词搜索
  919. if keyWord != "" {
  920. keyWord = "%" + keyWord + "%"
  921. condition += ` AND art.nick_name like ? `
  922. pars = append(pars, keyWord)
  923. list, tmpErr := cygx.GetYanxuanSpecialAuthorList(condition, pars, 0, 99)
  924. if tmpErr != nil {
  925. br.Msg = "获取失败"
  926. br.ErrMsg = "获取失败, Err:" + tmpErr.Error()
  927. return
  928. }
  929. if len(list) > 0 {
  930. for _, v := range list {
  931. item := new(cygx.CygxYanxuanSpecialKeyWordReesp)
  932. item.KeyWord = v.NickName
  933. resp.List = append(resp.List, item)
  934. }
  935. } else {
  936. resp.List = make([]*cygx.CygxYanxuanSpecialKeyWordReesp, 0)
  937. }
  938. } else {
  939. resp.List = make([]*cygx.CygxYanxuanSpecialKeyWordReesp, 0)
  940. }
  941. br.Data = resp
  942. br.Ret = 200
  943. br.Success = true
  944. br.Msg = "获取成功"
  945. }