|
@@ -7,6 +7,7 @@ import (
|
|
|
"eta/eta_mini_crm_ht/utils"
|
|
|
"fmt"
|
|
|
"github.com/rdlucklib/rdluck_tools/paging"
|
|
|
+ "net/http"
|
|
|
"strconv"
|
|
|
"strings"
|
|
|
"time"
|
|
@@ -371,3 +372,230 @@ func transSourceType(productType string) (sourceType models.SourceType) {
|
|
|
return ""
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+// ExportTemplateUsers
|
|
|
+// @Title 临时用户列表
|
|
|
+// @Description 临时用户列表
|
|
|
+// @Param PageSize query int true "每页数据条数"
|
|
|
+// @Param CurrentIndex query int true "当前页页码,从1开始"
|
|
|
+// @Param Keyword query string false "手机号"
|
|
|
+// @Param SortParam query string false "排序字段参数,用来排序的字段, 枚举值:0:注册时间,1:阅读数,2:最近一次阅读时间"
|
|
|
+// @Param SortType query string true "如何排序,是正序还是倒序,0:倒序,1:正序"
|
|
|
+// @Success 200 {object} response.TemplateUserListResp
|
|
|
+// @router /temporary/export [get]
|
|
|
+func (this *UserController) ExportTemplateUsers() {
|
|
|
+ br := new(models.BaseResponse).Init()
|
|
|
+ defer func() {
|
|
|
+ this.Data["json"] = br
|
|
|
+ this.ServeJSON()
|
|
|
+ }()
|
|
|
+ keyword := this.GetString("Keyword")
|
|
|
+ sortParamInt, _ := this.GetInt("SortParam", 0)
|
|
|
+ sortTypeInt, _ := this.GetInt("SortType", 0)
|
|
|
+ var sortStr = ``
|
|
|
+ var condition string
|
|
|
+ var pars []interface{}
|
|
|
+
|
|
|
+ sortParamMap := map[int]string{0: "created_time", 1: "read_count", 2: "last_read_time"}
|
|
|
+ sortTypeMap := map[int]string{0: "desc", 1: "asc"}
|
|
|
+ sortParam, ok := sortParamMap[sortParamInt]
|
|
|
+ if !ok {
|
|
|
+ br.Msg = "错误的排序字段参数"
|
|
|
+ br.ErrMsg = fmt.Sprint("错误的排序字段:", sortParamInt)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ sortType, ok := sortTypeMap[sortTypeInt]
|
|
|
+ if !ok {
|
|
|
+ br.Msg = "错误的排序字段"
|
|
|
+ br.ErrMsg = fmt.Sprint("错误的排序字段:", sortTypeInt)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ sortStr = fmt.Sprintf("%s %s,updated_time desc ", sortParam, sortType)
|
|
|
+
|
|
|
+ if keyword != "" {
|
|
|
+ condition += ` AND mobile LIKE ? `
|
|
|
+ pars = utils.GetLikeKeywordPars(pars, keyword, 1)
|
|
|
+ }
|
|
|
+
|
|
|
+ userList, err := models.GetTemplateUserListByCondition(condition, pars, sortStr)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "查询用户失败"
|
|
|
+ br.Msg = "查询用户失败,系统错误,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ year, month, day := time.Now().Date()
|
|
|
+ yearStr := strconv.Itoa(year)[2:]
|
|
|
+ fileName := fmt.Sprintf("临时用户表%s.%d.%d.xlsx", yearStr, month, day)
|
|
|
+ encodedFilename := encodeChineseFilename(fileName)
|
|
|
+ this.Ctx.ResponseWriter.Header().Set("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
|
|
|
+ this.Ctx.ResponseWriter.Header().Set("Content-Disposition", encodedFilename)
|
|
|
+ this.Ctx.ResponseWriter.Header().Set("File-Name", fileName)
|
|
|
+ list := make([]models.TemplateUsersItem, 0)
|
|
|
+ for _, v := range userList {
|
|
|
+ list = append(list, v.ToItem())
|
|
|
+ }
|
|
|
+
|
|
|
+ file, err := utils.ExportExcel(fileName, "用户列表", map[string]string{"用户名": "UserName", "手机号": "Mobile"}, nil)
|
|
|
+ // 写入文件
|
|
|
+ if err = file.Write(this.Ctx.ResponseWriter); err != nil {
|
|
|
+ utils.FileLog.Error("导出excel文件失败:", err)
|
|
|
+ http.Error(this.Ctx.ResponseWriter, "导出excel文件失败", http.StatusInternalServerError)
|
|
|
+ }
|
|
|
+ br.Ret = 200
|
|
|
+ br.Success = true
|
|
|
+ br.Msg = "获取成功"
|
|
|
+}
|
|
|
+
|
|
|
+// encodeChineseFilename 将中文文件名编码为 ISO-8859-1
|
|
|
+func encodeChineseFilename(filename string) string {
|
|
|
+ // 对文件名进行 ISO-8859-1 编码
|
|
|
+ encodedFilename := fmt.Sprintf("attachment; filename=%s", filename)
|
|
|
+ return encodedFilename
|
|
|
+}
|
|
|
+
|
|
|
+// ExportOfficialUsers
|
|
|
+// @Title 正式用户列表
|
|
|
+// @Description 正式用户列表
|
|
|
+// @Param PageSize query int true "每页数据条数"
|
|
|
+// @Param CurrentIndex query int true "当前页页码,从1开始"
|
|
|
+// @Param Keyword query string false "手机号"
|
|
|
+// @Param SortParam query string false "排序字段参数,用来排序的字段, 枚举值:0:注册时间,1:阅读数,2:最近一次阅读时间"
|
|
|
+// @Param SortType query string true "如何排序,是正序还是倒序,0:倒序,1:正序"
|
|
|
+// @Success 200 {object} response.TemplateUserListResp
|
|
|
+// @router /official/export [get]
|
|
|
+func (this *UserController) ExportOfficialUsers() {
|
|
|
+ br := new(models.BaseResponse).Init()
|
|
|
+ defer func() {
|
|
|
+ this.Data["json"] = br
|
|
|
+ this.ServeJSON()
|
|
|
+ }()
|
|
|
+ pageSize, _ := this.GetInt("PageSize")
|
|
|
+ currentIndex, _ := this.GetInt("CurrentIndex")
|
|
|
+ keyword := this.GetString("Keyword")
|
|
|
+ FollowingGzh := this.GetString("FollowingGzh")
|
|
|
+ RegisterBeginDate := this.GetString("RegisterBeginDate")
|
|
|
+ RegisterEndDate := this.GetString("RegisterEndDate")
|
|
|
+ if pageSize <= 0 {
|
|
|
+ pageSize = utils.PageSize20
|
|
|
+ } else if pageSize > utils.PageSize100 {
|
|
|
+ pageSize = utils.PageSize100
|
|
|
+ }
|
|
|
+ if currentIndex <= 0 {
|
|
|
+ currentIndex = 1
|
|
|
+ }
|
|
|
+ if pageSize <= 0 {
|
|
|
+ pageSize = utils.PageSize20
|
|
|
+ } else if pageSize > utils.PageSize100 {
|
|
|
+ pageSize = utils.PageSize100
|
|
|
+ }
|
|
|
+ if currentIndex <= 0 {
|
|
|
+ currentIndex = 1
|
|
|
+ }
|
|
|
+ startSize := utils.StartIndex(currentIndex, pageSize)
|
|
|
+
|
|
|
+ sortParamInt, _ := this.GetInt("SortParam", 0)
|
|
|
+ sortTypeInt, _ := this.GetInt("SortType", 0)
|
|
|
+
|
|
|
+ var sortStr = ``
|
|
|
+ var condition string
|
|
|
+ var pars []interface{}
|
|
|
+
|
|
|
+ sortParamMap := map[int]string{0: "created_time", 1: "read_count", 2: "last_read_time"}
|
|
|
+ sortTypeMap := map[int]string{0: "desc", 1: "asc"}
|
|
|
+ sortParam, ok := sortParamMap[sortParamInt]
|
|
|
+ if !ok {
|
|
|
+ br.Msg = "错误的排序字段参数"
|
|
|
+ br.ErrMsg = fmt.Sprint("错误的排序字段:", sortParamInt)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ sortType, ok := sortTypeMap[sortTypeInt]
|
|
|
+ if !ok {
|
|
|
+ br.Msg = "错误的排序字段"
|
|
|
+ br.ErrMsg = fmt.Sprintf("错误的排序字段:%v", sortTypeInt)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ sortStr = fmt.Sprintf("%s %s,updated_time desc ", sortParam, sortType)
|
|
|
+ if FollowingGzh != "" {
|
|
|
+ switch FollowingGzh {
|
|
|
+ case "true":
|
|
|
+ condition += ` AND following_gzh=1 `
|
|
|
+ case "false":
|
|
|
+ condition += ` AND following_gzh=0 `
|
|
|
+ default:
|
|
|
+ br.Msg = "关注公众号字段非法字段"
|
|
|
+ br.ErrMsg = fmt.Sprintf("错误的关注公众号字段:%s", FollowingGzh)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if RegisterBeginDate != "" || RegisterEndDate != "" {
|
|
|
+ var beginDate, endDate time.Time
|
|
|
+ var parseErr error
|
|
|
+ if RegisterBeginDate != "" {
|
|
|
+ beginDate, parseErr = time.Parse(time.DateOnly, RegisterBeginDate)
|
|
|
+ if parseErr != nil {
|
|
|
+ br.Msg = "注册时间开始字段非法字段"
|
|
|
+ br.ErrMsg = fmt.Sprintf("错误的注册时间开始字段:%s", RegisterBeginDate)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if RegisterEndDate != "" {
|
|
|
+ endDate, parseErr = time.Parse(time.DateOnly, RegisterEndDate)
|
|
|
+ if parseErr != nil {
|
|
|
+ br.Msg = "注册时间结束字段非法字段"
|
|
|
+ br.ErrMsg = fmt.Sprintf("错误的注册时间结束字段:%s", RegisterEndDate)
|
|
|
+
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if RegisterBeginDate != "" {
|
|
|
+ if RegisterEndDate != "" {
|
|
|
+ if beginDate.After(endDate) {
|
|
|
+ br.Msg = "结束时间不能早于开始时间"
|
|
|
+ br.ErrMsg = fmt.Sprintf("错误的注册时间结束字段:开始时间:%s,结束时间:%s", RegisterBeginDate, RegisterEndDate)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ condition += ` AND DATE_FORMAT(created_time,'%Y-%m-%d') BETWEEN ? AND ?`
|
|
|
+ pars = append(pars, RegisterBeginDate, RegisterEndDate)
|
|
|
+ } else {
|
|
|
+ condition += ` AND DATE_FORMAT(created_time,'%Y-%m-%d') >= ?`
|
|
|
+ pars = append(pars, RegisterBeginDate)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ condition += ` AND DATE_FORMAT(created_time,'%Y-%m-%d') <= ?`
|
|
|
+ pars = append(pars, RegisterEndDate)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if keyword != "" {
|
|
|
+ condition += ` AND ( mobile LIKE ? or real_name like ?)`
|
|
|
+ pars = utils.GetLikeKeywordPars(pars, keyword, 2)
|
|
|
+ }
|
|
|
+
|
|
|
+ resp := new(response.UserListResp)
|
|
|
+ total, userList, err := models.GetPageOfficialUserList(condition, pars, sortStr, startSize, pageSize)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "查询用户失败"
|
|
|
+ br.Msg = "查询用户失败,系统错误,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ //list := make([]*models.UserView, 0)
|
|
|
+ //var wg sync.WaitGroup
|
|
|
+ //wg.Add(len(userList))
|
|
|
+ //for _, v := range userList {
|
|
|
+ // go func(v *models.User) {
|
|
|
+ // defer wg.Done()
|
|
|
+ // tempUser, _ := models.GetTemplateUser(v.TemplateUserId)
|
|
|
+ // userView := v.FillUserInfo(tempUser)
|
|
|
+ // list = append(list, &userView)
|
|
|
+ // }(&v)
|
|
|
+ //}
|
|
|
+ //wg.Wait()
|
|
|
+ page := paging.GetPaging(currentIndex, pageSize, total)
|
|
|
+ resp.Paging = page
|
|
|
+ resp.List = userList
|
|
|
+ br.Data = resp
|
|
|
+ br.Ret = 200
|
|
|
+ br.Success = true
|
|
|
+ br.Msg = "获取成功"
|
|
|
+}
|