yanxuan_special.go 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929
  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 SortParam query string false "排序字段参数,用来排序的字段, 枚举值:'CreatTime':开通时间 、 'articleNum':已发布文章 、 'pv':总Pv/Uv "
  300. // @Param SortType query string true "如何排序,是正序还是倒序,枚举值:`asc 正序`,`desc 倒叙`"
  301. // @Param StartDate query string false "开始时间 ,列如2021-03-06 "
  302. // @Param EndDate query string false "结束时间,列如2021-03-06 "
  303. // @Success 200 {object} models.AddEnglishReportResp
  304. // @router /yanxuan_special/list [get]
  305. func (this *YanxuanSpecialController) List() {
  306. br := new(models.BaseResponse).Init()
  307. defer func() {
  308. this.Data["json"] = br
  309. this.ServeJSON()
  310. }()
  311. sysUser := this.SysUser
  312. if sysUser == nil {
  313. br.Msg = "请登录"
  314. br.ErrMsg = "请登录,SysUser Is Empty"
  315. br.Ret = 408
  316. return
  317. }
  318. userId, _ := this.GetInt("UserId", 0)
  319. pageSize, _ := this.GetInt("PageSize")
  320. currentIndex, _ := this.GetInt("CurrentIndex")
  321. status, _ := this.GetInt("Status", 1)
  322. specialType, _ := this.GetInt("Type")
  323. keyWord := this.GetString("KeyWord")
  324. //排序参数
  325. sortParam := this.GetString("SortParam")
  326. sortType := this.GetString("SortType")
  327. startDate := this.GetString("StartDate")
  328. endDate := this.GetString("EndDate")
  329. var startSize int
  330. if pageSize <= 0 {
  331. pageSize = utils.PageSize20
  332. }
  333. if currentIndex <= 0 {
  334. currentIndex = 1
  335. }
  336. startSize = utils.StartIndex(currentIndex, pageSize)
  337. var condition string
  338. var pars []interface{}
  339. if userId > 0 {
  340. condition += ` AND a.user_id = ? `
  341. pars = append(pars, userId)
  342. }
  343. if status == 1 {
  344. condition += ` AND a.status = 2 `
  345. }
  346. if status == 2 {
  347. condition += ` AND a.status = 3 `
  348. }
  349. if startDate != "" {
  350. condition += ` AND a.publish_time >= ` + "'" + startDate + " 00:00:00'"
  351. }
  352. if endDate != "" {
  353. condition += ` AND a.publish_time <= ` + "'" + endDate + " 23:59:59'"
  354. }
  355. //文章类型
  356. if specialType == 1 || specialType == 2 {
  357. condition += ` AND a.type = ? `
  358. pars = append(pars, specialType)
  359. }
  360. //关键词搜索
  361. if keyWord != "" {
  362. keyWord = "%" + keyWord + "%"
  363. condition += ` AND a.title like ? `
  364. pars = append(pars, keyWord)
  365. }
  366. //排序字段以及排序方式处理
  367. var sortStr string
  368. if sortParam != "" && sortType != "" {
  369. if sortParam == "pv" {
  370. if sortType == "asc" {
  371. sortStr = " ORDER BY a.pv ASC "
  372. } else {
  373. sortStr = " ORDER BY a.pv DESC "
  374. }
  375. }
  376. if sortStr == "" {
  377. sortStr = " ORDER BY a.publish_time DESC " // 兼容前端老六乱传字段
  378. }
  379. } else {
  380. sortStr = " ORDER BY a.publish_time DESC "
  381. }
  382. total, err := cygx.GetGetYanxuanSpecialCount(condition, pars)
  383. if err != nil {
  384. br.Msg = "获取失败"
  385. br.ErrMsg = "获取失败,Err:" + err.Error()
  386. return
  387. }
  388. list, tmpErr := cygx.GetYanxuanSpecialList(condition+sortStr, pars, startSize, pageSize)
  389. if tmpErr != nil {
  390. br.Msg = "获取失败"
  391. br.ErrMsg = "获取失败, Err:" + tmpErr.Error()
  392. return
  393. }
  394. pars = make([]interface{}, 0)
  395. listAuthor, tmpErr := cygx.GetYanxuanSpecialAuthorList("", pars, 0, 999)
  396. if tmpErr != nil {
  397. br.Msg = "获取失败"
  398. br.ErrMsg = "获取失败, Err:" + tmpErr.Error()
  399. return
  400. }
  401. mapUserId := make(map[int]int)
  402. for _, v := range listAuthor {
  403. mapUserId[v.UserId] = v.Id
  404. }
  405. for _, v := range list {
  406. v.SpecialAuthorId = mapUserId[v.UserId]
  407. hasImg, err := utils.ArticleHasImgUrl(v.Content)
  408. if err != nil {
  409. return
  410. }
  411. if hasImg {
  412. v.ContentHasImg = 1
  413. }
  414. if v.DocUrl != "" {
  415. var docs []cygx.Doc
  416. err := json.Unmarshal([]byte(v.DocUrl), &docs)
  417. if err != nil {
  418. br.Msg = "参数解析异常!"
  419. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  420. return
  421. }
  422. v.Docs = docs
  423. }
  424. if v.CompanyTags != "" {
  425. v.Tags += v.CompanyTags
  426. }
  427. if v.IndustryTags != "" {
  428. if v.Tags != "" {
  429. v.Tags += ","
  430. }
  431. v.Tags += v.IndustryTags
  432. }
  433. }
  434. resp := new(cygx.GetCygxYanxuanSpeciaResplItemResp)
  435. page := paging.GetPaging(currentIndex, pageSize, total)
  436. resp.List = list
  437. resp.Paging = page
  438. br.Data = resp
  439. br.Ret = 200
  440. br.Success = true
  441. br.Msg = "获取成功"
  442. }
  443. // @Title 审批研选专栏
  444. // @Description 审批研选专栏
  445. // @Param request body help_doc.AddHelpDocReq true "type json string"
  446. // @Success 200 {object} models.AddEnglishReportResp
  447. // @router /yanxuan_special/enable [post]
  448. func (this *YanxuanSpecialController) Enable() {
  449. br := new(models.BaseResponse).Init()
  450. defer func() {
  451. this.Data["json"] = br
  452. this.ServeJSON()
  453. }()
  454. sysUser := this.SysUser
  455. if sysUser == nil {
  456. br.Msg = "请登录"
  457. br.ErrMsg = "请登录,SysUser Is Empty"
  458. br.Ret = 408
  459. return
  460. }
  461. var req cygx.EnableCygxYanxuanSpecialReq
  462. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  463. if err != nil {
  464. br.Msg = "参数解析异常!"
  465. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  466. return
  467. }
  468. if req.Id <= 0 {
  469. br.Msg = "文章id错误"
  470. return
  471. }
  472. if req.Status <= 0 {
  473. br.Msg = "参数错误"
  474. return
  475. }
  476. status := 0
  477. if req.Status == 1 {
  478. status = 3
  479. } else {
  480. status = 4
  481. }
  482. if tmpErr := cygx.EnableYanxuanSpecial(req.Id, status, req.Reason, sysUser.RealName); tmpErr != nil {
  483. br.Msg = "审批失败"
  484. br.ErrMsg = "审批失败, Err:" + tmpErr.Error()
  485. return
  486. }
  487. if req.Status == 1 {
  488. go cygxService.SendWxMsgSpecialFollow(req.Id)
  489. go services.SendWxCategoryMsgSpecialFollow(req.Id)
  490. }
  491. go cygxService.SendWxMsgSpecialAuthor(req.Id, req.Status) // 研选专栏审核完成时,给提交人发送模板消息
  492. go services.SendWxCategoryMsgSpecialAuthor(req.Id, req.Status) // 研选专栏审核完成时,给提交人发送模板消息
  493. go cygxService.UpdateYanxuanSpecialResourceData(req.Id) // 写入首页最新 cygx_resource_data 表
  494. go elastic.EsAddYanxuanSpecial(req.Id) // 写入es 综合搜索
  495. br.Msg = "审批成功"
  496. br.Ret = 200
  497. br.Success = true
  498. }
  499. // @Title 收藏详情
  500. // @Description 收藏详情
  501. // @Param SpecialId query int true "每页数据条数"
  502. // @Success 200 {object} models.AddEnglishReportResp
  503. // @router /yanxuan_special/special_collect/list [get]
  504. func (this *YanxuanSpecialController) SpecialCollectList() {
  505. br := new(models.BaseResponse).Init()
  506. defer func() {
  507. this.Data["json"] = br
  508. this.ServeJSON()
  509. }()
  510. sysUser := this.SysUser
  511. if sysUser == nil {
  512. br.Msg = "请登录"
  513. br.ErrMsg = "请登录,SysUser Is Empty"
  514. br.Ret = 408
  515. return
  516. }
  517. specialId, _ := this.GetInt("SpecialId")
  518. var condition string
  519. var pars []interface{}
  520. condition += " AND yanxuan_special_id = ? ORDER BY art.create_time DESC "
  521. pars = append(pars, specialId)
  522. list, err := cygx.GetCygxYanxuanSpecialCollectList(condition, pars, 0, 100000)
  523. if err != nil {
  524. br.Msg = "获取失败"
  525. br.ErrMsg = "获取失败,Err:" + err.Error()
  526. return
  527. }
  528. resp := new(cygx.GetCygxYanxuanSpecialCollectResp)
  529. resp.List = list
  530. br.Data = resp
  531. br.Ret = 200
  532. br.Success = true
  533. br.Msg = "获取成功"
  534. }
  535. // @Title 下载PV
  536. // @Description 下载PV接口
  537. // @Param SpecialId query int true "每页数据条数"
  538. // @router /yanxuan_special/list_pv [get]
  539. func (this *YanxuanSpecialController) ListPv() {
  540. br := new(models.BaseResponse).Init()
  541. defer func() {
  542. this.Data["json"] = br
  543. this.ServeJSON()
  544. }()
  545. AdminUser := this.SysUser
  546. if AdminUser == nil {
  547. br.Msg = "请登录"
  548. br.ErrMsg = "请登录,用户信息为空"
  549. br.Ret = 408
  550. return
  551. }
  552. specialId, _ := this.GetInt("SpecialId")
  553. if specialId < 1 {
  554. br.Msg = "请输入专栏ID"
  555. return
  556. }
  557. var condition string
  558. var pars []interface{}
  559. condition = ` AND yanxuan_special_id = ? ORDER BY create_time DESC `
  560. pars = append(pars, specialId)
  561. list, err := cygx.GetCygxYanxuanSpecialRecordList(condition, pars)
  562. if err != nil {
  563. br.Msg = "获取失败"
  564. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  565. return
  566. }
  567. var companyIds []int
  568. for _, v := range list {
  569. companyIds = append(companyIds, v.CompanyId)
  570. }
  571. listCompanyProduct, err := company.GetCompanyProductListByCompanyIds(companyIds, 2)
  572. if err != nil && err.Error() != utils.ErrNoRow() {
  573. br.Msg = "获取失败"
  574. br.ErrMsg = "获取销售列表失败,Err:" + err.Error()
  575. return
  576. }
  577. mapsCompanyStatus := make(map[int]string)
  578. for _, v := range listCompanyProduct {
  579. mapsCompanyStatus[v.CompanyId] = v.Status
  580. }
  581. //创建excel
  582. dir, err := os.Executable()
  583. exPath := filepath.Dir(dir)
  584. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  585. xlsxFile := xlsx.NewFile()
  586. if err != nil {
  587. br.Msg = "生成文件失败"
  588. br.ErrMsg = "生成文件失败"
  589. return
  590. }
  591. style := xlsx.NewStyle()
  592. alignment := xlsx.Alignment{
  593. Horizontal: "center",
  594. Vertical: "center",
  595. WrapText: true,
  596. }
  597. style.Alignment = alignment
  598. style.ApplyAlignment = true
  599. sheet, err := xlsxFile.AddSheet("阅读明细")
  600. if err != nil {
  601. br.Msg = "新增Sheet失败"
  602. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  603. return
  604. }
  605. rowTitle := sheet.AddRow()
  606. cellA := rowTitle.AddCell()
  607. cellA.Value = "姓名"
  608. cellMobile := rowTitle.AddCell()
  609. cellMobile.Value = "手机号"
  610. cellB := rowTitle.AddCell()
  611. cellB.Value = "公司名称"
  612. cellCompanyStatus := rowTitle.AddCell()
  613. cellCompanyStatus.Value = "客户状态"
  614. cellC := rowTitle.AddCell()
  615. cellC.Value = "所属权益销售"
  616. cellD := rowTitle.AddCell()
  617. cellD.Value = "阅读时间"
  618. cellE := rowTitle.AddCell()
  619. cellE.Value = "阅读时长"
  620. for _, item := range list {
  621. row := sheet.AddRow()
  622. cellA := row.AddCell()
  623. cellA.Value = item.RealName
  624. cellMobile := row.AddCell()
  625. cellMobile.Value = item.Mobile
  626. cellB := row.AddCell()
  627. cellB.Value = item.CompanyName
  628. cellCompanyStatus := row.AddCell()
  629. cellCompanyStatus.Value = mapsCompanyStatus[item.CompanyId]
  630. cellC := row.AddCell()
  631. cellC.Value = item.SellerName
  632. cellD := row.AddCell()
  633. cellD.Value = item.CreateTime
  634. cellE := row.AddCell()
  635. cellE.Value = strconv.Itoa(item.StopTime)
  636. }
  637. err = xlsxFile.Save(downLoadnFilePath)
  638. if err != nil {
  639. br.Msg = "保存文件失败"
  640. br.ErrMsg = "保存文件失败"
  641. return
  642. }
  643. downloadFileName := time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  644. this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  645. defer func() {
  646. os.Remove(downLoadnFilePath)
  647. }()
  648. br.Ret = 200
  649. br.Success = true
  650. br.Msg = "导出成功"
  651. }
  652. // @Title 审批记录
  653. // @Description 审批记录接口
  654. // @Param PageSize query int true "每页数据条数"
  655. // @Param CurrentIndex query int true "当前页页码,从1开始"
  656. // @Success 200 {object} models.CygxYanxuanSpecialApprovalLogListResp
  657. // @router /yanxuan_special/approval_log_list [get]
  658. func (this *YanxuanSpecialController) ApprovalLogList() {
  659. br := new(models.BaseResponse).Init()
  660. defer func() {
  661. this.Data["json"] = br
  662. this.ServeJSON()
  663. }()
  664. sysUser := this.SysUser
  665. if sysUser == nil {
  666. br.Msg = "请登录"
  667. br.ErrMsg = "请登录,SysUser Is Empty"
  668. br.Ret = 408
  669. return
  670. }
  671. pageSize, _ := this.GetInt("PageSize")
  672. currentIndex, _ := this.GetInt("CurrentIndex")
  673. var startSize int
  674. if pageSize <= 0 {
  675. pageSize = utils.PageSize20
  676. }
  677. if currentIndex <= 0 {
  678. currentIndex = 1
  679. }
  680. startSize = utils.StartIndex(currentIndex, pageSize)
  681. var condition string
  682. var pars []interface{}
  683. //只是查询驳回状态的数据
  684. condition += ` AND a.approval_status = 2 `
  685. total, err := cygx.GetCygxYanxuanSpecialApprovalLogCount(condition, pars)
  686. if err != nil {
  687. br.Msg = "获取失败"
  688. br.ErrMsg = "获取失败,Err:" + err.Error()
  689. return
  690. }
  691. condition += ` ORDER BY create_time DESC `
  692. list, tmpErr := cygx.GetCygxYanxuanSpecialApprovalLogList(condition, pars, startSize, pageSize)
  693. if tmpErr != nil {
  694. br.Msg = "获取失败"
  695. br.ErrMsg = "获取失败, Err:" + tmpErr.Error()
  696. return
  697. }
  698. pars = make([]interface{}, 0)
  699. listAuthor, tmpErr := cygx.GetYanxuanSpecialAuthorList("", pars, 0, 999)
  700. if tmpErr != nil {
  701. br.Msg = "获取失败"
  702. br.ErrMsg = "获取失败, Err:" + tmpErr.Error()
  703. return
  704. }
  705. mapUserId := make(map[int]int)
  706. for _, v := range listAuthor {
  707. mapUserId[v.UserId] = v.Id
  708. }
  709. for _, v := range list {
  710. v.SpecialAuthorId = mapUserId[v.UserId]
  711. }
  712. resp := new(cygx.CygxYanxuanSpecialApprovalLogListResp)
  713. page := paging.GetPaging(currentIndex, pageSize, total)
  714. resp.List = list
  715. resp.Paging = page
  716. br.Data = resp
  717. br.Ret = 200
  718. br.Success = true
  719. br.Msg = "获取成功"
  720. }
  721. // @Title 按钮是否展示接口
  722. // @Description 按钮是否展示接口
  723. // @Success 200 {object} models.AddEnglishReportResp
  724. // @router /yanxuan_special/show_button [get]
  725. func (this *YanxuanSpecialController) ShowButton() {
  726. br := new(models.BaseResponse).Init()
  727. defer func() {
  728. this.Data["json"] = br
  729. this.ServeJSON()
  730. }()
  731. sysUser := this.SysUser
  732. if sysUser == nil {
  733. br.Msg = "请登录"
  734. br.ErrMsg = "请登录,SysUser Is Empty"
  735. br.Ret = 408
  736. return
  737. }
  738. resp := new(cygx.CygxYanxuanSpecialShowButton)
  739. configCode := utils.TPL_MSG_NEI_RONG_ZU
  740. cnfNeiRong, err := cygx.GetConfigByCode(configCode)
  741. if err != nil {
  742. br.Msg = "获取失败"
  743. br.ErrMsg = "获取失败,Err:" + err.Error()
  744. return
  745. }
  746. //汪洋王芳手机号
  747. configCode = utils.TPL_MSG_WANG_FANG_WANG_YANG
  748. cnfWang, err := cygx.GetConfigByCode(configCode)
  749. if err != nil {
  750. br.Msg = "获取失败"
  751. br.ErrMsg = "获取失败,Err:" + err.Error()
  752. return
  753. }
  754. //作者管理栏,只有内容组、汪洋、王芳、超管可见
  755. if strings.Contains(cnfNeiRong.ConfigValue, sysUser.Mobile) || strings.Contains(cnfWang.ConfigValue, sysUser.Mobile) || sysUser.Role == utils.ROLE_TYPE_CODE_ADMIN {
  756. resp.IsShowSpecialAuthor = true
  757. }
  758. br.Data = resp
  759. br.Ret = 200
  760. br.Success = true
  761. br.Msg = "获取成功"
  762. }
  763. // @Title 作者粉丝列表
  764. // @Description 作者粉丝列表
  765. // @Param SpecialAuthorId query int true "作者ID"
  766. // @Success 200 {object} models.AddEnglishReportResp
  767. // @router /yanxuan_special/special_author_fans_list [get]
  768. func (this *YanxuanSpecialController) SpecialAuthorFansList() {
  769. br := new(models.BaseResponse).Init()
  770. defer func() {
  771. this.Data["json"] = br
  772. this.ServeJSON()
  773. }()
  774. sysUser := this.SysUser
  775. if sysUser == nil {
  776. br.Msg = "请登录"
  777. br.ErrMsg = "请登录,SysUser Is Empty"
  778. br.Ret = 408
  779. return
  780. }
  781. specialAuthorId, _ := this.GetInt("SpecialAuthorId")
  782. detail, err := cygx.GetCygxYanxuanSpecialAuthorItemById(specialAuthorId)
  783. if err != nil {
  784. br.Msg = "获取失败"
  785. br.ErrMsg = "获取失败,Err:" + err.Error()
  786. return
  787. }
  788. var condition string
  789. var pars []interface{}
  790. condition += " AND follow_user_id = ? ORDER BY a.create_time DESC "
  791. pars = append(pars, detail.UserId)
  792. list, err := cygx.GetCygxYanxuanSpecialFollowList(condition, pars, 0, 100000)
  793. if err != nil {
  794. br.Msg = "获取失败"
  795. br.ErrMsg = "获取失败,Err:" + err.Error()
  796. return
  797. }
  798. resp := new(cygx.GetCygxYanxuanSpecialFollowResp)
  799. resp.List = list
  800. br.Data = resp
  801. br.Ret = 200
  802. br.Success = true
  803. br.Msg = "获取成功"
  804. }
  805. func init_928() {
  806. var condition string
  807. var pars []interface{}
  808. list, err := cygx.GetYanxuanSpecialAuthorList(condition, pars, 0, 999)
  809. if err != nil {
  810. fmt.Println(err)
  811. return
  812. }
  813. for k, v := range list {
  814. fmt.Println(k)
  815. //获取关联公司的用户信息
  816. infoUser, err := cygx.GetUserAndCompanyNameList(v.UserId)
  817. if err != nil && err.Error() != utils.ErrNoRow() {
  818. fmt.Println(err)
  819. return
  820. }
  821. if infoUser == nil {
  822. continue
  823. }
  824. err = cygx.UpdateSpecialAuthormobile_init(infoUser.Mobile, infoUser.UserId)
  825. if err != nil {
  826. fmt.Println(err)
  827. return
  828. }
  829. }
  830. return
  831. }
  832. // @Title 修改作者信息
  833. // @Description 修改作者信息接口
  834. // @Param request body help_doc.AddHelpDocReq true "type json string"
  835. // @router /yanxuan_special/author/update [post]
  836. func (this *YanxuanSpecialController) AuthorUpdate() {
  837. br := new(models.BaseResponse).Init()
  838. defer func() {
  839. this.Data["json"] = br
  840. this.ServeJSON()
  841. }()
  842. sysUser := this.SysUser
  843. if sysUser == nil {
  844. br.Msg = "请登录"
  845. br.ErrMsg = "请登录,SysUser Is Empty"
  846. br.Ret = 408
  847. return
  848. }
  849. var req cygx.AddCygxYanxuanSpecialAuthorReq
  850. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  851. if err != nil {
  852. br.Msg = "参数解析异常!"
  853. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  854. return
  855. }
  856. if req.UserId <= 0 {
  857. br.Msg = "请输入用户信息"
  858. return
  859. }
  860. err = cygx.UpdateYanxuanSpecialAuthorInviteName(req.InviteName, req.Remark, req.UserId)
  861. if err != nil {
  862. br.Msg = "新增失败"
  863. br.ErrMsg = "新增失败,Err:" + err.Error()
  864. return
  865. }
  866. br.Ret = 200
  867. br.Success = true
  868. br.Msg = "修改成功"
  869. }