user.go 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "eta/eta_mini_crm_ht/models"
  5. "eta/eta_mini_crm_ht/models/request"
  6. "eta/eta_mini_crm_ht/models/response"
  7. "eta/eta_mini_crm_ht/services"
  8. "eta/eta_mini_crm_ht/utils"
  9. "fmt"
  10. "github.com/rdlucklib/rdluck_tools/paging"
  11. "github.com/xuri/excelize/v2"
  12. "net/http"
  13. "net/url"
  14. "strconv"
  15. "strings"
  16. "time"
  17. )
  18. type UserController struct {
  19. BaseAuthController
  20. }
  21. var (
  22. templateCols = map[string]utils.ExcelColMapping{
  23. "A": {"手机号", "Mobile"},
  24. "B": {"最近一次阅读时间", "LastReadTime"},
  25. "C": {"累计阅读次数", "ReadCount"},
  26. "D": {"注册时间", "CreatedTime"},
  27. }
  28. userCols = map[string]utils.ExcelColMapping{
  29. "A": {"姓名", "RealName"},
  30. "B": {"手机号", "Mobile"},
  31. "C": {"公司名称", "CompanyName"},
  32. "D": {"注册时间", "CreatedTime"},
  33. "E": {"是否关注公众号", "FollowingGzhStr"},
  34. "F": {"最近一次阅读时间", "LastReadTime"},
  35. "G": {"累计阅读次数", "ReadCount"},
  36. }
  37. )
  38. // TemplateList
  39. // @Title 临时用户列表
  40. // @Description 临时用户列表
  41. // @Param PageSize query int true "每页数据条数"
  42. // @Param CurrentIndex query int true "当前页页码,从1开始"
  43. // @Param Keyword query string false "手机号"
  44. // @Param SortParam query string false "排序字段参数,用来排序的字段, 枚举值:0:注册时间,1:阅读数,2:最近一次阅读时间"
  45. // @Param SortType query string true "如何排序,是正序还是倒序,0:倒序,1:正序"
  46. // @Success 200 {object} response.TemplateUserListResp
  47. // @router /temporary/list [get]
  48. func (this *UserController) TemplateList() {
  49. br := new(models.BaseResponse).Init()
  50. defer func() {
  51. this.Data["json"] = br
  52. this.ServeJSON()
  53. }()
  54. pageSize, _ := this.GetInt("PageSize")
  55. currentIndex, _ := this.GetInt("CurrentIndex")
  56. keyword := this.GetString("Keyword")
  57. if pageSize <= 0 {
  58. pageSize = utils.PageSize20
  59. } else if pageSize > utils.PageSize100 {
  60. pageSize = utils.PageSize100
  61. }
  62. if currentIndex <= 0 {
  63. currentIndex = 1
  64. }
  65. if pageSize <= 0 {
  66. pageSize = utils.PageSize20
  67. } else if pageSize > utils.PageSize100 {
  68. pageSize = utils.PageSize100
  69. }
  70. if currentIndex <= 0 {
  71. currentIndex = 1
  72. }
  73. startSize := utils.StartIndex(currentIndex, pageSize)
  74. sortParamInt, _ := this.GetInt("SortParam", 0)
  75. sortTypeInt, _ := this.GetInt("SortType", 0)
  76. var sortCondtion string
  77. var condition string
  78. var pars []interface{}
  79. sortParamMap := map[int]string{0: "created_time", 1: "read_count", 2: "last_read_time"}
  80. sortTypeMap := map[int]string{0: "desc", 1: "asc"}
  81. sortParam, ok := sortParamMap[sortParamInt]
  82. if !ok {
  83. br.Msg = "错误的排序字段参数"
  84. br.ErrMsg = fmt.Sprint("错误的排序字段:", sortParamInt)
  85. return
  86. }
  87. sortType, ok := sortTypeMap[sortTypeInt]
  88. if !ok {
  89. br.Msg = "错误的排序字段"
  90. br.ErrMsg = fmt.Sprint("错误的排序字段:", sortTypeInt)
  91. return
  92. }
  93. sortCondtion = fmt.Sprintf("%s %s,updated_time desc ", sortParam, sortType)
  94. if keyword != "" {
  95. condition += ` AND mobile LIKE ? `
  96. pars = utils.GetLikeKeywordPars(pars, keyword, 1)
  97. }
  98. resp := new(response.TemplateUserListResp)
  99. total, userList, err := models.GetPageTemplateUserList(condition, pars, sortCondtion, startSize, pageSize)
  100. if err != nil {
  101. br.Msg = "查询用户失败"
  102. br.Msg = "查询用户失败,系统错误,Err:" + err.Error()
  103. return
  104. }
  105. list := make([]models.TemplateUsersItem, 0)
  106. for _, v := range userList {
  107. list = append(list, v.ToItem())
  108. }
  109. page := paging.GetPaging(currentIndex, pageSize, total)
  110. resp.Paging = page
  111. resp.List = list
  112. br.Data = resp
  113. br.Ret = 200
  114. br.Success = true
  115. br.Msg = "获取成功"
  116. }
  117. // OfficialList
  118. // @Title 正式用户列表
  119. // @Description 正式用户列表
  120. // @Param PageSize query int true "每页数据条数"
  121. // @Param CurrentIndex query int true "当前页页码,从1开始"
  122. // @Param Keyword query string false "手机号"
  123. // @Param SortParam query string false "排序字段参数,用来排序的字段, 枚举值:0:注册时间,1:阅读数,2:最近一次阅读时间"
  124. // @Param SortType query string true "如何排序,是正序还是倒序,0:倒序,1:正序"
  125. // @Success 200 {object} response.TemplateUserListResp
  126. // @router /official/list [get]
  127. func (this *UserController) OfficialList() {
  128. br := new(models.BaseResponse).Init()
  129. defer func() {
  130. this.Data["json"] = br
  131. this.ServeJSON()
  132. }()
  133. pageSize, _ := this.GetInt("PageSize")
  134. currentIndex, _ := this.GetInt("CurrentIndex")
  135. keyword := this.GetString("Keyword")
  136. FollowingGzh := this.GetString("FollowingGzh")
  137. RegisterBeginDate := this.GetString("RegisterBeginDate")
  138. RegisterEndDate := this.GetString("RegisterEndDate")
  139. if pageSize <= 0 {
  140. pageSize = utils.PageSize20
  141. } else if pageSize > utils.PageSize100 {
  142. pageSize = utils.PageSize100
  143. }
  144. if currentIndex <= 0 {
  145. currentIndex = 1
  146. }
  147. if pageSize <= 0 {
  148. pageSize = utils.PageSize20
  149. } else if pageSize > utils.PageSize100 {
  150. pageSize = utils.PageSize100
  151. }
  152. if currentIndex <= 0 {
  153. currentIndex = 1
  154. }
  155. startSize := utils.StartIndex(currentIndex, pageSize)
  156. sortParamInt, _ := this.GetInt("SortParam", 0)
  157. sortTypeInt, _ := this.GetInt("SortType", 0)
  158. var sortCondtion string
  159. var condition string
  160. var pars []interface{}
  161. sortParamMap := map[int]string{0: "created_time", 1: "read_count", 2: "last_read_time"}
  162. sortTypeMap := map[int]string{0: "desc", 1: "asc"}
  163. sortParam, ok := sortParamMap[sortParamInt]
  164. if !ok {
  165. br.Msg = "错误的排序字段参数"
  166. br.ErrMsg = fmt.Sprint("错误的排序字段:", sortParamInt)
  167. return
  168. }
  169. sortType, ok := sortTypeMap[sortTypeInt]
  170. if !ok {
  171. br.Msg = "错误的排序字段"
  172. br.ErrMsg = fmt.Sprintf("错误的排序字段:%v", sortTypeInt)
  173. return
  174. }
  175. sortCondtion = fmt.Sprintf("%s %s,updated_time desc ", sortParam, sortType)
  176. if FollowingGzh != "" {
  177. switch FollowingGzh {
  178. case "true":
  179. condition += ` AND following_gzh=1 `
  180. case "false":
  181. condition += ` AND following_gzh=0 `
  182. default:
  183. br.Msg = "关注公众号字段非法字段"
  184. br.ErrMsg = fmt.Sprintf("错误的关注公众号字段:%s", FollowingGzh)
  185. return
  186. }
  187. }
  188. if RegisterBeginDate != "" || RegisterEndDate != "" {
  189. var beginDate, endDate time.Time
  190. var parseErr error
  191. if RegisterBeginDate != "" {
  192. beginDate, parseErr = time.Parse(time.DateOnly, RegisterBeginDate)
  193. if parseErr != nil {
  194. br.Msg = "注册时间开始字段非法字段"
  195. br.ErrMsg = fmt.Sprintf("错误的注册时间开始字段:%s", RegisterBeginDate)
  196. return
  197. }
  198. }
  199. if RegisterEndDate != "" {
  200. endDate, parseErr = time.Parse(time.DateOnly, RegisterEndDate)
  201. if parseErr != nil {
  202. br.Msg = "注册时间结束字段非法字段"
  203. br.ErrMsg = fmt.Sprintf("错误的注册时间结束字段:%s", RegisterEndDate)
  204. return
  205. }
  206. }
  207. if RegisterBeginDate != "" {
  208. if RegisterEndDate != "" {
  209. if beginDate.After(endDate) {
  210. br.Msg = "结束时间不能早于开始时间"
  211. br.ErrMsg = fmt.Sprintf("错误的注册时间结束字段:开始时间:%s,结束时间:%s", RegisterBeginDate, RegisterEndDate)
  212. return
  213. }
  214. condition += ` AND DATE_FORMAT(created_time,'%Y-%m-%d') BETWEEN ? AND ?`
  215. pars = append(pars, RegisterBeginDate, RegisterEndDate)
  216. } else {
  217. condition += ` AND DATE_FORMAT(created_time,'%Y-%m-%d') >= ?`
  218. pars = append(pars, RegisterBeginDate)
  219. }
  220. } else {
  221. condition += ` AND DATE_FORMAT(created_time,'%Y-%m-%d') <= ?`
  222. pars = append(pars, RegisterEndDate)
  223. }
  224. }
  225. if keyword != "" {
  226. condition += ` AND ( mobile LIKE ? or real_name like ?)`
  227. pars = utils.GetLikeKeywordPars(pars, keyword, 2)
  228. }
  229. resp := new(response.UserListResp)
  230. total, userList, err := models.GetPageOfficialUserList(condition, pars, sortCondtion, startSize, pageSize)
  231. if err != nil {
  232. br.Msg = "查询用户失败"
  233. br.Msg = "查询用户失败,系统错误,Err:" + err.Error()
  234. return
  235. }
  236. //list := make([]*models.UserView, 0)
  237. //var wg sync.WaitGroup
  238. //wg.Add(len(userList))
  239. //for _, v := range userList {
  240. // go func(v *models.User) {
  241. // defer wg.Done()
  242. // tempUser, _ := models.GetTemplateUser(v.TemplateUserId)
  243. // userView := v.FillUserInfo(tempUser)
  244. // list = append(list, &userView)
  245. // }(&v)
  246. //}
  247. //wg.Wait()
  248. page := paging.GetPaging(currentIndex, pageSize, total)
  249. resp.Paging = page
  250. resp.List = userList
  251. br.Data = resp
  252. br.Ret = 200
  253. br.Success = true
  254. br.Msg = "获取成功"
  255. }
  256. // readRecordList
  257. // @Title 用户阅读记录
  258. // @Description 用户阅读记录
  259. // @Param PageSize query int true "每页数据条数"
  260. // @Param CurrentIndex query int true "当前页页码,从1开始"
  261. // @Param ChartPermissionIds query string true "品种列表"
  262. // @Param ClassifyIds query string true "品种列表"
  263. // @Success 200 {object} models.LoginResp
  264. // @router /readRecordList [get]
  265. func (this *UserController) ReadRecordList() {
  266. br := new(models.BaseResponse).Init()
  267. defer func() {
  268. this.Data["json"] = br
  269. this.ServeJSON()
  270. }()
  271. UserId, _ := this.GetInt("UserId")
  272. pageSize, _ := this.GetInt("PageSize")
  273. currentIndex, _ := this.GetInt("CurrentIndex")
  274. permissionIds := this.GetString("PermissionIds")
  275. productType := this.GetString("ProductType")
  276. if UserId <= 0 {
  277. br.Msg = "查询用户失败,用户id不合法"
  278. return
  279. }
  280. if pageSize <= 0 {
  281. pageSize = utils.PageSize20
  282. } else if pageSize > utils.PageSize100 {
  283. pageSize = utils.PageSize100
  284. }
  285. if currentIndex <= 0 {
  286. currentIndex = 1
  287. }
  288. startSize := utils.StartIndex(currentIndex, pageSize)
  289. user, err := models.GetTemplateUser(UserId)
  290. if err != nil {
  291. if err.Error() == utils.ErrNoRow() {
  292. br.Msg = "用户不存在或已删除,请刷新页面"
  293. return
  294. }
  295. br.Msg = "查询用户失败"
  296. br.ErrMsg = "查询用户失败,系统错误,Err:" + err.Error()
  297. return
  298. }
  299. if user == nil {
  300. br.Msg = "用户不存在或已删除,请刷新页面"
  301. return
  302. }
  303. var condition string
  304. var pars []interface{}
  305. var sourceType models.SourceType
  306. if productType != "" {
  307. sourceType = transSourceType(productType)
  308. if sourceType == "" {
  309. br.Msg = "错误的产品类型"
  310. br.ErrMsg = "错误的产品类型:" + productType
  311. return
  312. }
  313. condition += `and source_type= ?`
  314. pars = append(pars, sourceType)
  315. }
  316. var permissionIdList []int
  317. if permissionIds != "" {
  318. permissionIdStrList := strings.Split(permissionIds, ",")
  319. for _, permissionIdStr := range permissionIdStrList {
  320. permissionId, parseErr := strconv.Atoi(permissionIdStr)
  321. if parseErr != nil {
  322. continue
  323. }
  324. permissionIdList = append(permissionIdList, permissionId)
  325. }
  326. }
  327. total, condition, pars, err := services.GetUserSourceClickFlowListCountByUserId(UserId, condition, pars, permissionIdList, sourceType)
  328. if err != nil {
  329. br.Msg = "查询阅读记录失败"
  330. br.ErrMsg = "查询阅读记录失败,Err:" + err.Error()
  331. return
  332. }
  333. if total <= 0 {
  334. br.Msg = "暂无数据"
  335. br.Data = new(response.UserSourceClickFlowResp)
  336. br.Success = true
  337. br.Ret = 200
  338. return
  339. }
  340. readList, err := services.GetUserSourceClickFlowListByUserId(UserId, condition, pars, startSize, pageSize)
  341. if err != nil {
  342. br.Msg = "查询阅读记录失败"
  343. br.ErrMsg = "查询阅读记录失败,系统错误,Err:" + err.Error()
  344. return
  345. }
  346. page := paging.GetPaging(currentIndex, pageSize, total)
  347. resp := new(response.UserSourceClickFlowResp)
  348. resp.Paging = page
  349. resp.List = readList
  350. br.Msg = "获取成功"
  351. br.Data = resp
  352. br.Success = true
  353. br.Ret = 200
  354. }
  355. func transSourceType(productType string) (sourceType models.SourceType) {
  356. if productType == "" {
  357. return ""
  358. }
  359. switch productType {
  360. case Report:
  361. sourceType = models.ReportSourceType
  362. return
  363. case Video:
  364. sourceType = models.VideoSourceType
  365. return
  366. case Audio:
  367. sourceType = models.AudioSourceType
  368. return
  369. default:
  370. return ""
  371. }
  372. }
  373. // ExportTemplateUsers
  374. // @Title 临时用户列表
  375. // @Description 临时用户列表
  376. // @Param PageSize query int true "每页数据条数"
  377. // @Param CurrentIndex query int true "当前页页码,从1开始"
  378. // @Param Keyword query string false "手机号"
  379. // @Param SortParam query string false "排序字段参数,用来排序的字段, 枚举值:0:注册时间,1:阅读数,2:最近一次阅读时间"
  380. // @Param SortType query string true "如何排序,是正序还是倒序,0:倒序,1:正序"
  381. // @Success 200 {object} response.TemplateUserListResp
  382. // @router /temporary/export [get]
  383. func (this *UserController) ExportTemplateUsers() {
  384. br := new(models.BaseResponse).Init()
  385. defer func() {
  386. this.Data["json"] = br
  387. this.ServeJSON()
  388. }()
  389. keyword := this.GetString("Keyword")
  390. sortParamInt, _ := this.GetInt("SortParam", 0)
  391. sortTypeInt, _ := this.GetInt("SortType", 0)
  392. var sortStr = ``
  393. var condition string
  394. var pars []interface{}
  395. sortParamMap := map[int]string{0: "created_time", 1: "read_count", 2: "last_read_time"}
  396. sortTypeMap := map[int]string{0: "desc", 1: "asc"}
  397. sortParam, ok := sortParamMap[sortParamInt]
  398. if !ok {
  399. br.Msg = "错误的排序字段参数"
  400. br.ErrMsg = fmt.Sprint("错误的排序字段:", sortParamInt)
  401. return
  402. }
  403. sortType, ok := sortTypeMap[sortTypeInt]
  404. if !ok {
  405. br.Msg = "错误的排序字段"
  406. br.ErrMsg = fmt.Sprint("错误的排序字段:", sortTypeInt)
  407. return
  408. }
  409. sortStr = fmt.Sprintf("%s %s,updated_time desc ", sortParam, sortType)
  410. if keyword != "" {
  411. condition += ` AND mobile LIKE ? `
  412. pars = utils.GetLikeKeywordPars(pars, keyword, 1)
  413. }
  414. userList, err := models.GetTemplateUserListByCondition(condition, pars, sortStr)
  415. if err != nil {
  416. br.Msg = "查询用户失败"
  417. br.Msg = "查询用户失败,系统错误,Err:" + err.Error()
  418. return
  419. }
  420. list := make([]models.TemplateUsersItem, 0)
  421. for _, v := range userList {
  422. list = append(list, v.ToItem())
  423. }
  424. year, month, day := time.Now().Date()
  425. yearStr := strconv.Itoa(year)[2:]
  426. fileName := fmt.Sprintf("临时用户表%s.%d.%d.xlsx", yearStr, month, day)
  427. file, err := utils.ExportExcel("临时用户表", templateCols, list)
  428. _ = this.downloadExcelFile(file, fileName)
  429. br.Ret = 200
  430. br.Success = true
  431. br.Msg = "下载成功"
  432. }
  433. // encodeChineseFilename 将中文文件名编码为 ISO-8859-1
  434. func (this *UserController) downloadExcelFile(file *excelize.File, filename string) (err error) {
  435. // 对文件名进行 ISO-8859-1 编码
  436. fn := url.QueryEscape(filename)
  437. if filename == fn {
  438. fn = "filename=" + fn
  439. } else {
  440. fn = "filename=" + filename + "; filename*=utf-8''" + fn
  441. }
  442. this.Ctx.ResponseWriter.Header().Set("Access-Control-Expose-Headers", "Content-Disposition")
  443. this.Ctx.ResponseWriter.Header().Set("Content-Disposition", "attachment; "+fn)
  444. this.Ctx.ResponseWriter.Header().Set("Content-Description", "File Transfer")
  445. this.Ctx.ResponseWriter.Header().Set("Content-Type", "application/octet-stream")
  446. this.Ctx.ResponseWriter.Header().Set("Content-Transfer-Encoding", "binary")
  447. this.Ctx.ResponseWriter.Header().Set("Expires", "0")
  448. this.Ctx.ResponseWriter.Header().Set("Cache-Control", "must-revalidate")
  449. this.Ctx.ResponseWriter.Header().Set("Pragma", "public")
  450. this.Ctx.ResponseWriter.Header().Set("File-Name", filename)
  451. // 写入文件
  452. if err = file.Write(this.Ctx.ResponseWriter); err != nil {
  453. utils.FileLog.Error("导出excel文件失败:", err)
  454. http.Error(this.Ctx.ResponseWriter, "导出excel文件失败", http.StatusInternalServerError)
  455. }
  456. return
  457. }
  458. // ExportOfficialUsers
  459. // @Title 正式用户列表
  460. // @Description 正式用户列表
  461. // @Param PageSize query int true "每页数据条数"
  462. // @Param CurrentIndex query int true "当前页页码,从1开始"
  463. // @Param Keyword query string false "手机号"
  464. // @Param SortParam query string false "排序字段参数,用来排序的字段, 枚举值:0:注册时间,1:阅读数,2:最近一次阅读时间"
  465. // @Param SortType query string true "如何排序,是正序还是倒序,0:倒序,1:正序"
  466. // @Success 200 {object} response.TemplateUserListResp
  467. // @router /official/export [get]
  468. func (this *UserController) ExportOfficialUsers() {
  469. br := new(models.BaseResponse).Init()
  470. defer func() {
  471. this.Data["json"] = br
  472. this.ServeJSON()
  473. }()
  474. keyword := this.GetString("Keyword")
  475. FollowingGzh := this.GetString("FollowingGzh")
  476. RegisterBeginDate := this.GetString("RegisterBeginDate")
  477. RegisterEndDate := this.GetString("RegisterEndDate")
  478. sortParamInt, _ := this.GetInt("SortParam", 0)
  479. sortTypeInt, _ := this.GetInt("SortType", 0)
  480. var sortStr = ``
  481. var condition string
  482. var pars []interface{}
  483. sortParamMap := map[int]string{0: "created_time", 1: "read_count", 2: "last_read_time"}
  484. sortTypeMap := map[int]string{0: "desc", 1: "asc"}
  485. sortParam, ok := sortParamMap[sortParamInt]
  486. if !ok {
  487. br.Msg = "错误的排序字段参数"
  488. br.ErrMsg = fmt.Sprint("错误的排序字段:", sortParamInt)
  489. return
  490. }
  491. sortType, ok := sortTypeMap[sortTypeInt]
  492. if !ok {
  493. br.Msg = "错误的排序字段"
  494. br.ErrMsg = fmt.Sprintf("错误的排序字段:%v", sortTypeInt)
  495. return
  496. }
  497. sortStr = fmt.Sprintf("%s %s,updated_time desc ", sortParam, sortType)
  498. if FollowingGzh != "" {
  499. switch FollowingGzh {
  500. case "true":
  501. condition += ` AND following_gzh=1 `
  502. case "false":
  503. condition += ` AND following_gzh=0 `
  504. default:
  505. br.Msg = "关注公众号字段非法字段"
  506. br.ErrMsg = fmt.Sprintf("错误的关注公众号字段:%s", FollowingGzh)
  507. return
  508. }
  509. }
  510. if RegisterBeginDate != "" || RegisterEndDate != "" {
  511. var beginDate, endDate time.Time
  512. var parseErr error
  513. if RegisterBeginDate != "" {
  514. beginDate, parseErr = time.Parse(time.DateOnly, RegisterBeginDate)
  515. if parseErr != nil {
  516. br.Msg = "注册时间开始字段非法字段"
  517. br.ErrMsg = fmt.Sprintf("错误的注册时间开始字段:%s", RegisterBeginDate)
  518. return
  519. }
  520. }
  521. if RegisterEndDate != "" {
  522. endDate, parseErr = time.Parse(time.DateOnly, RegisterEndDate)
  523. if parseErr != nil {
  524. br.Msg = "注册时间结束字段非法字段"
  525. br.ErrMsg = fmt.Sprintf("错误的注册时间结束字段:%s", RegisterEndDate)
  526. return
  527. }
  528. }
  529. if RegisterBeginDate != "" {
  530. if RegisterEndDate != "" {
  531. if beginDate.After(endDate) {
  532. br.Msg = "结束时间不能早于开始时间"
  533. br.ErrMsg = fmt.Sprintf("错误的注册时间结束字段:开始时间:%s,结束时间:%s", RegisterBeginDate, RegisterEndDate)
  534. return
  535. }
  536. condition += ` AND DATE_FORMAT(created_time,'%Y-%m-%d') BETWEEN ? AND ?`
  537. pars = append(pars, RegisterBeginDate, RegisterEndDate)
  538. } else {
  539. condition += ` AND DATE_FORMAT(created_time,'%Y-%m-%d') >= ?`
  540. pars = append(pars, RegisterBeginDate)
  541. }
  542. } else {
  543. condition += ` AND DATE_FORMAT(created_time,'%Y-%m-%d') <= ?`
  544. pars = append(pars, RegisterEndDate)
  545. }
  546. }
  547. if keyword != "" {
  548. condition += ` AND ( mobile LIKE ? or real_name like ?)`
  549. pars = utils.GetLikeKeywordPars(pars, keyword, 2)
  550. }
  551. userList, err := models.GetPageOfficialUserByCondition(condition, pars, sortStr)
  552. if err != nil {
  553. br.Msg = "查询用户失败"
  554. br.Msg = "查询用户失败,系统错误,Err:" + err.Error()
  555. return
  556. }
  557. year, month, day := time.Now().Date()
  558. yearStr := strconv.Itoa(year)[2:]
  559. fileName := fmt.Sprintf("用户列表%s.%d.%d.xlsx", yearStr, month, day)
  560. file, err := utils.ExportExcel("用户列表", userCols, userList)
  561. _ = this.downloadExcelFile(file, fileName)
  562. br.Ret = 200
  563. br.Success = true
  564. br.Msg = "获取成功"
  565. }
  566. // MessageList 获取未读消息
  567. // @Summary 获取未读消息
  568. // @Description 获取未读消息
  569. // @Success 200 {object} controllers.BaseResponse
  570. // @router /message [get]
  571. func (u *UserController) MessageList() {
  572. br := new(models.BaseResponse).Init()
  573. defer func() {
  574. u.Data["json"] = br
  575. u.ServeJSON()
  576. }()
  577. pageSize, _ := u.GetInt("PageSize")
  578. currentIndex, _ := u.GetInt("CurrentIndex")
  579. if currentIndex <= 0 {
  580. currentIndex = 1
  581. }
  582. if pageSize <= 0 {
  583. pageSize = utils.PageSize20
  584. } else if pageSize > utils.PageSize100 {
  585. pageSize = utils.PageSize100
  586. }
  587. startSize := utils.StartIndex(currentIndex, pageSize)
  588. total, err := models.GetMessageListCount(u.SysUser.SysUserId)
  589. if err != nil {
  590. br.Msg = "查询退款通知失败"
  591. br.Msg = "查询退款通知失败,Err:" + err.Error()
  592. return
  593. }
  594. messages, err := models.GetMessageList(u.SysUser.SysUserId, startSize, pageSize)
  595. if err != nil {
  596. br.Msg = "查询退款通知失败"
  597. br.Msg = "查询退款通知失败,Err:" + err.Error()
  598. return
  599. }
  600. var list []*models.UserMessageView
  601. for _, message := range messages {
  602. list = append(list, message.ToView())
  603. }
  604. resp := new(response.MessageListResp)
  605. page := paging.GetPaging(currentIndex, pageSize, total)
  606. resp.Paging = page
  607. resp.List = list
  608. br.Ret = 200
  609. br.Success = true
  610. br.Data = resp
  611. br.Msg = "获取成功"
  612. }
  613. // ReadMessage 获取未读消息
  614. // @Summary 获取未读消息
  615. // @Description 获取未读消息
  616. // @Success 200 {object} controllers.BaseResponse
  617. // @router /readMessage [post]
  618. func (u *UserController) ReadMessage() {
  619. br := new(models.BaseResponse).Init()
  620. defer func() {
  621. u.Data["json"] = br
  622. u.ServeJSON()
  623. }()
  624. var req request.ReadMessageReq
  625. if err := json.Unmarshal(u.Ctx.Input.RequestBody, &req); err != nil {
  626. br.Msg = "参数解析失败"
  627. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  628. return
  629. }
  630. if req.MessageId <= 0 {
  631. br.Msg = "消息Id非法"
  632. br.Msg = "已读退款通知失败,消息Id非法"
  633. return
  634. }
  635. if models.ReadMessage(u.SysUser.SysUserId, req.MessageId) {
  636. br.Ret = 200
  637. br.Success = true
  638. br.Msg = "已读成功"
  639. return
  640. } else {
  641. br.Msg = "已读退款通知失败"
  642. br.ErrMsg = "已读退款通知失败"
  643. return
  644. }
  645. }
  646. // ReadMessages 获取未读消息
  647. // @Summary 获取未读消息
  648. // @Description 获取未读消息
  649. // @Success 200 {object} controllers.BaseResponse
  650. // @router /readMessages [post]
  651. func (u *UserController) ReadMessages() {
  652. br := new(models.BaseResponse).Init()
  653. defer func() {
  654. u.Data["json"] = br
  655. u.ServeJSON()
  656. }()
  657. if models.ReadMessages(u.SysUser.SysUserId) {
  658. br.Ret = 200
  659. br.Success = true
  660. br.Msg = "已读成功"
  661. return
  662. } else {
  663. br.Msg = "批量已读退款通知失败"
  664. br.ErrMsg = "批量已读退款通知失败"
  665. return
  666. }
  667. }