Przeglądaj źródła

fix:临时用户添加排序字段

Roc 8 miesięcy temu
rodzic
commit
3196df70fe
4 zmienionych plików z 35 dodań i 11 usunięć
  1. 26 3
      controllers/user.go
  2. 2 5
      go.mod
  3. 6 2
      models/template_users.go
  4. 1 1
      routers/commentsRouter.go

+ 26 - 3
controllers/user.go

@@ -7,6 +7,7 @@ import (
 	"eta/eta_mini_crm_ht/models/response"
 	"eta/eta_mini_crm_ht/services"
 	"eta/eta_mini_crm_ht/utils"
+	"fmt"
 	"github.com/rdlucklib/rdluck_tools/paging"
 	"math"
 	"strings"
@@ -1262,15 +1263,17 @@ func (this *UserController) GlobalSearch() {
 	br.Ret = 200
 }
 
-// TemplateList
+// TemporaryList
 // @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/list [get]
-func (this *UserController) TemplateList() {
+func (this *UserController) TemporaryList() {
 	br := new(models.BaseResponse).Init()
 	defer func() {
 		this.Data["json"] = br
@@ -1297,16 +1300,36 @@ func (this *UserController) TemplateList() {
 	}
 	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: "read_cnt", 2: "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)
 	}
 
 	resp := new(response.TemplateUserListResp)
-	total, userList, err := models.GetPageTemplateUserList(condition, pars, startSize, pageSize)
+	total, userList, err := models.GetPageTemplateUserList(condition, pars, sortStr, startSize, pageSize)
 	if err != nil {
 		br.Msg = "查询用户失败"
 		br.Msg = "查询用户失败,系统错误,Err:" + err.Error()

+ 2 - 5
go.mod

@@ -7,27 +7,25 @@ require github.com/beego/beego/v2 v2.1.0
 require (
 	github.com/aliyun/alibaba-cloud-sdk-go v1.62.807
 	github.com/aliyun/aliyun-oss-go-sdk v3.0.2+incompatible
-	github.com/astaxie/beego v1.12.3
 	github.com/beego/bee/v2 v2.1.0
 	github.com/dgrijalva/jwt-go v3.2.0+incompatible
 	github.com/go-redis/redis/v8 v8.11.5
 	github.com/go-sql-driver/mysql v1.7.0
+	github.com/google/uuid v1.6.0
 	github.com/minio/minio-go/v7 v7.0.74
 	github.com/olivere/elastic/v7 v7.0.32
 	github.com/rdlucklib/rdluck_tools v1.0.3
+	github.com/tcolgate/mp3 v0.0.0-20170426193717-e79c5a46d300
 )
 
 require (
 	github.com/beorn7/perks v1.0.1 // indirect
-	github.com/bogem/id3v2 v1.2.0 // indirect
 	github.com/cespare/xxhash/v2 v2.2.0 // indirect
 	github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
 	github.com/dustin/go-humanize v1.0.1 // indirect
 	github.com/go-ini/ini v1.67.0 // indirect
 	github.com/goccy/go-json v0.10.3 // indirect
 	github.com/golang/protobuf v1.5.3 // indirect
-	github.com/google/uuid v1.6.0 // indirect
-	github.com/hajimehoshi/go-mp3 v0.3.4 // indirect
 	github.com/hashicorp/golang-lru v0.5.4 // indirect
 	github.com/jmespath/go-jmespath v0.4.0 // indirect
 	github.com/josharian/intern v1.0.0 // indirect
@@ -48,7 +46,6 @@ require (
 	github.com/prometheus/procfs v0.9.0 // indirect
 	github.com/rs/xid v1.5.0 // indirect
 	github.com/shiena/ansicolor v0.0.0-20200904210342-c7312218db18 // indirect
-	github.com/tcolgate/mp3 v0.0.0-20170426193717-e79c5a46d300 // indirect
 	golang.org/x/crypto v0.24.0 // indirect
 	golang.org/x/net v0.26.0 // indirect
 	golang.org/x/sys v0.21.0 // indirect

+ 6 - 2
models/template_users.go

@@ -48,7 +48,7 @@ type TemplateUsersItem struct {
 // @return total int
 // @return items []*TemplateUsers
 // @return err error
-func GetPageTemplateUserList(condition string, pars []interface{}, startSize, pageSize int) (total int, items []*TemplateUsers, err error) {
+func GetPageTemplateUserList(condition string, pars []interface{}, sortStr string, startSize, pageSize int) (total int, items []*TemplateUsers, err error) {
 	o := orm.NewOrm()
 	totalSql := `SELECT count(1) ct FROM template_users AS a WHERE is_deleted = 0 `
 	if condition != "" {
@@ -63,7 +63,11 @@ func GetPageTemplateUserList(condition string, pars []interface{}, startSize, pa
 	if condition != "" {
 		sql += condition
 	}
-	sql += ` ORDER BY id DESC LIMIT ?,? `
+	if sortStr != `` {
+		sql += ` ORDER BY ` + sortStr
+	}
+
+	sql += ` LIMIT ?,? `
 	_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
 
 	return

+ 1 - 1
routers/commentsRouter.go

@@ -515,7 +515,7 @@ func init() {
 
     beego.GlobalControllerRouter["eta/eta_mini_crm_ht/controllers:UserController"] = append(beego.GlobalControllerRouter["eta/eta_mini_crm_ht/controllers:UserController"],
         beego.ControllerComments{
-            Method: "TemplateList",
+            Method: "TemporaryList",
             Router: `/temporary/list`,
             AllowHTTPMethods: []string{"get"},
             MethodParams: param.Make(),