Browse Source

Merge branch 'feature/eta2.3.4_business_user' into debug

xyxie 1 month ago
parent
commit
08b8538a57
2 changed files with 17 additions and 4 deletions
  1. 10 2
      controllers/eta_business/user.go
  2. 7 2
      models/user.go

+ 10 - 2
controllers/eta_business/user.go

@@ -55,6 +55,9 @@ func (this *EtaBusinessUserController) List() {
 	businessCode := this.GetString("BusinessCode")
 	keyword := utils.TrimStr(this.GetString("Keyword"))
 
+	sortType := this.GetString("SortType")
+	sortParam := this.GetString("SortParam")
+
 	/*if businessCode <= 0 {
 		br.Msg = "请选择客户"
 		br.ErrMsg = "客户参数错误"
@@ -90,7 +93,12 @@ func (this *EtaBusinessUserController) List() {
 		condition += ` AND enabled = ? `
 		pars = append(pars, enabled)
 	}
-
+	order := ""
+	if sortParam == "LastLoginTime" {
+		if sortType == "desc" || sortType == "asc" {
+			order = " last_login_time " + sortType
+		}
+	}
 	total, err := models.GetUserCountByCondition(condition, pars)
 	if err != nil {
 		br.Msg = "获取失败"
@@ -98,7 +106,7 @@ func (this *EtaBusinessUserController) List() {
 		return
 	}
 
-	list, err := models.GetUserPageListByCondition(condition, pars, startSize, pageSize)
+	list, err := models.GetUserPageListByCondition(condition, pars, order, startSize, pageSize)
 	if err != nil {
 		br.Msg = "获取失败"
 		br.ErrMsg = "获取数据失败,Err:" + err.Error()

+ 7 - 2
models/user.go

@@ -95,7 +95,7 @@ func GetUserCountByCondition(condition string, pars []interface{}) (count int, e
 }
 
 // 获取该用户列表
-func GetUserPageListByCondition(condition string, pars []interface{}, startSize, pageSize int) (items []*User, err error) {
+func GetUserPageListByCondition(condition string, pars []interface{}, order string, startSize, pageSize int) (items []*User, err error) {
 	o := orm.NewOrm()
 	tmpSql := `SELECT *
 			FROM
@@ -105,7 +105,12 @@ func GetUserPageListByCondition(condition string, pars []interface{}, startSize,
 	if condition != "" {
 		tmpSql += condition
 	}
-	tmpSql += ` ORDER BY user_id DESC Limit ?,?`
+	if order != "" {
+		tmpSql += ` ORDER BY ` + order + ", user_id DESC"
+	} else {
+		tmpSql += ` ORDER BY user_id DESC`
+	}
+	tmpSql += ` Limit ?,?`
 	_, err = o.Raw(tmpSql, pars, startSize, pageSize).QueryRows(&items)
 	return
 }