瀏覽代碼

Merge branch 'master' of http://192.168.3.207:10080/group3/SwordFish_Interface_Service

jiaojiao7 4 年之前
父節點
當前提交
eb9b3c8abc
共有 3 個文件被更改,包括 79 次插入0 次删除
  1. 30 0
      manage/user/user.go
  2. 42 0
      service/user.go
  3. 7 0
      test/manage/user_test.go

+ 30 - 0
manage/user/user.go

@@ -6,12 +6,14 @@ import (
 	"go.uber.org/zap"
 	"go.uber.org/zap"
 	"io/ioutil"
 	"io/ioutil"
 	"log"
 	"log"
+	"net/http"
 	"sfbase/global"
 	"sfbase/global"
 	sutils "sfbase/utils"
 	sutils "sfbase/utils"
 	"sfis/model"
 	"sfis/model"
 	"sfis/model/response"
 	"sfis/model/response"
 	"sfis/service"
 	"sfis/service"
 	"sfis/utils"
 	"sfis/utils"
+	"strconv"
 	"time"
 	"time"
 )
 )
 
 
@@ -20,6 +22,7 @@ func DevUserManageRegister(router *gin.Engine) {
 	userGroup.Use()
 	userGroup.Use()
 	{
 	{
 		userGroup.POST("/create", userCreate)
 		userGroup.POST("/create", userCreate)
+		userGroup.POST("/list", userList)
 		userGroup.POST("/userProductChoose", userProductChoose)
 		userGroup.POST("/userProductChoose", userProductChoose)
 		userGroup.POST("/userProductList", userProductList)
 		userGroup.POST("/userProductList", userProductList)
 		userGroup.POST("/moneyRecharge", moneyRecharge)
 		userGroup.POST("/moneyRecharge", moneyRecharge)
@@ -49,6 +52,33 @@ func userCreate(c *gin.Context) {
 	}
 	}
 }
 }
 
 
+// 用户列表
+func userList(c *gin.Context) {
+	page, _ := strconv.Atoi(c.PostForm("page"))
+	limit, _ := strconv.Atoi(c.PostForm("limit"))
+	appId := c.PostForm("app_id")
+	name := c.PostForm("name")
+	phone := c.PostForm("phone")
+
+	condMap := map[string]interface{}{
+		"app_id": appId,
+		"name":   name,
+		"phone":  phone,
+	}
+	userList, totalCount, err := service.ListUser(condMap, page, limit)
+	if err != nil {
+		response.FailWithMessage(err.Error(), c)
+	} else {
+		c.JSON(http.StatusOK, gin.H{
+			"code":       response.SUCCESS,
+			"data":       userList,
+			"msg":        "查询成功",
+			"totalCount": totalCount,
+		})
+	}
+
+}
+
 func userProductChoose(c *gin.Context) {
 func userProductChoose(c *gin.Context) {
 	bs, err := ioutil.ReadAll(c.Request.Body)
 	bs, err := ioutil.ReadAll(c.Request.Body)
 	if err != nil {
 	if err != nil {

+ 42 - 0
service/user.go

@@ -2,6 +2,7 @@ package service
 
 
 import (
 import (
 	"errors"
 	"errors"
+	"fmt"
 	"github.com/gin-gonic/gin"
 	"github.com/gin-gonic/gin"
 	"go.uber.org/zap"
 	"go.uber.org/zap"
 	"gorm.io/gorm"
 	"gorm.io/gorm"
@@ -13,6 +14,7 @@ import (
 	"sfis/model"
 	"sfis/model"
 	"sfis/model/response"
 	"sfis/model/response"
 	"strconv"
 	"strconv"
+	"strings"
 	"sync"
 	"sync"
 	"time"
 	"time"
 )
 )
@@ -189,3 +191,43 @@ func CreateUser(user model.User) (model.User, error) {
 	}
 	}
 
 
 }
 }
+
+// 查询用户
+func ListUser(condMap map[string]interface{}, page int, limit int) ([]map[string]interface{}, int64, error) {
+	// 拼查询sql
+	var key []string
+	var param []interface{}
+	for k, v := range condMap {
+		if v == "" {
+			continue
+		}
+		var kStr string
+		kStr = fmt.Sprintf("%s like ?", k)
+		v = "%" + v.(string) + "%"
+		key = append(key, kStr)
+		param = append(param, v)
+	}
+	whereSql := strings.Join(key, " and ")
+	var totalCount int64
+	var userInfo []map[string]interface{}
+	err := db.GetSFISDB().Table("user").Where(whereSql, param...).Where("delete_at is null").Count(&totalCount).Error
+	if err != nil {
+		return nil, 0, errors.New("查询失败")
+	}
+	if totalCount == 0 {
+		return userInfo, 0, nil
+	}
+	if whereSql != ""{
+		whereSql = " and " + whereSql
+	}
+	sql := "select user.app_id,user.name,user.phone,user.secret_key,user.ip_white_list,user.create_at,money from user LEFT JOIN  user_account on user.app_id=user_account.app_id where user.delete_at is Null " + whereSql
+	if limit != 0 && page > 0 {
+		sql += fmt.Sprintf(" limit %d ,%d", (page-1)*limit, limit)
+	}
+	result := db.GetSFISDB().Raw(sql, param...).Scan(&userInfo)
+
+	if result.Error != nil {
+		return nil, 0, errors.New("查询失败")
+	}
+	return userInfo, totalCount, nil
+}

+ 7 - 0
test/manage/user_test.go

@@ -60,6 +60,13 @@ func Test_CreateUser(t *testing.T) {
 	//appID := ""
 	//appID := ""
 	//tradeMoney := 1 * 100 * 10000 //充值1万块钱
 	//tradeMoney := 1 * 100 * 10000 //充值1万块钱
 }
 }
+func Test_UserList(t *testing.T) {
+	data := make(url.Values)
+	data["name"] = []string{"拓普"}
+	bs, _ := sutil.HttpPostForm("http://localhost:8080/manage/user/list", map[string]string{}, data)
+	log.Print(string(bs))
+	//service.ListUser(nil,0,0)
+}
 func Test_UserProductChoose(t *testing.T) {
 func Test_UserProductChoose(t *testing.T) {
 	/*appId := "sfGSRYRQMABwMAAgcBHjQt"
 	/*appId := "sfGSRYRQMABwMAAgcBHjQt"
 	productIds := "1000"
 	productIds := "1000"