Browse Source

修改部分bug

wucan 7 tháng trước cách đây
mục cha
commit
b730ebb9eb

+ 1 - 1
bootstrap/mongodb.go

@@ -10,7 +10,7 @@ import (
 import mongoOption "go.mongodb.org/mongo-driver/v2/mongo/options"
 
 func InitializeMongo() *mongo.Client {
-	client, _ := mongo.Connect(mongoOption.Client().ApplyURI("mongodb://localhost:27017"))
+	client, _ := mongo.Connect(mongoOption.Client().ApplyURI("mongodb://admin:admin@localhost:27017"))
 
 	err := client.Ping(context.Background(), readpref.Primary())
 	if err != nil {

+ 9 - 10
controller/v1/gameAction.go

@@ -23,9 +23,7 @@ func UserActionList(c *gin.Context) {
 	var actionList []model.GameAction
 
 	query := global.App.DB.Table("game_action")
-	if len(form.Pf) > 0 {
-		query = query.WhereIn("gid", form.Pf)
-	}
+
 	err := query.
 		Where("gid", form.Gid).
 		Select("id", "actionId", "actionName").
@@ -38,7 +36,7 @@ func UserActionList(c *gin.Context) {
 	var userLogin []model.UserLogin
 	query1 := global.App.DB.Table("user_login")
 	if len(form.Pf) > 0 {
-		query1 = query1.WhereIn("gid", form.Pf)
+		query1 = query1.WhereIn("pf", form.Pf)
 	}
 	err = query1.
 		Where("gid", form.Gid).
@@ -56,7 +54,7 @@ func UserActionList(c *gin.Context) {
 	var userAction []model.UserAction
 	query2 := global.App.DB.Table("user_action")
 	if len(form.Pf) > 0 {
-		query2 = query2.WhereIn("gid", form.Pf)
+		query2 = query2.WhereIn("pf", form.Pf)
 	}
 	err = query2.
 		Where("gid", form.Gid).
@@ -71,7 +69,7 @@ func UserActionList(c *gin.Context) {
 	//计算事件的触发总数和触发用户数
 	actionSumMap := make(map[string]int)
 	actionUserSumMap := make(map[string][]int)
-	fmt.Println(userAction)
+	//fmt.Println(userAction)
 	for _, action := range userAction {
 		actionSumMap[action.ActionId]++
 		actionUserSumMap[action.ActionId] = append(actionUserSumMap[action.ActionId], action.UserId)
@@ -236,7 +234,7 @@ func UserActionDetailDistribution(c *gin.Context) {
 		}
 		query := global.App.DB.Table("user_action")
 		if len(form.Pf) > 0 {
-			query = query.WhereIn("gid", form.Pf)
+			query = query.WhereIn("pf", form.Pf)
 		}
 		err = query.
 			Where("gid", action.Gid).
@@ -308,7 +306,7 @@ func UserActionDetailDistribution(c *gin.Context) {
 		var userAction []string
 		query := global.App.DB.Table("user_action")
 		if len(form.Pf) > 0 {
-			query = query.WhereIn("gid", form.Pf)
+			query = query.WhereIn("pf", form.Pf)
 		}
 		err = query.
 			Where("gid", action.Gid).
@@ -345,7 +343,7 @@ func UserActionDetailDistribution(c *gin.Context) {
 		var userLogin []string
 		query := global.App.DB.Table("user_login")
 		if len(form.Pf) > 0 {
-			query = query.WhereIn("gid", form.Pf)
+			query = query.WhereIn("pf", form.Pf)
 		}
 		err = query.
 			Where("gid", action.Gid).
@@ -361,7 +359,7 @@ func UserActionDetailDistribution(c *gin.Context) {
 		var userAction []string
 		query = global.App.DB.Table("user_action")
 		if len(form.Pf) > 0 {
-			query = query.WhereIn("gid", form.Pf)
+			query = query.WhereIn("pf", form.Pf)
 		}
 		err = query.
 			Where("gid", action.Gid).
@@ -383,6 +381,7 @@ func UserActionDetailDistribution(c *gin.Context) {
 				res[v] = 0
 			}
 		}
+
 	} else {
 		response.Fail(c, 1003, errors.New("type 错误"))
 		return

+ 2 - 1
controller/v1/gameConfig.go

@@ -247,7 +247,7 @@ func GameActionList(c *gin.Context) {
 
 	query := global.App.DB.Table("game_action").Where("gid", form.Gid)
 	if form.Search != "" {
-		query = query.WhereRaw(global.App.DB.Where("actionId", "like", "%"+form.Search+"%").Where("actionName", "like", "%"+form.Search+"%").SubQuery())
+		query = query.WhereRaw(global.App.DB.Where("actionId", "like", "%"+form.Search+"%").Or("actionName like ?", "%"+form.Search+"%").SubQuery())
 	}
 	if form.Status != "" {
 		status, _ := strconv.Atoi(form.Status)
@@ -256,6 +256,7 @@ func GameActionList(c *gin.Context) {
 	if form.Order != "" {
 		query = query.Order("id " + form.Order)
 	}
+
 	var count int64
 	err := query.Count(&count).Error
 	if err != nil {

+ 5 - 5
controller/v1/user.go

@@ -7,6 +7,7 @@ import (
 	"designs/common"
 	"designs/config"
 	"designs/global"
+	"designs/model"
 	"designs/service"
 	"designs/utils"
 	"fmt"
@@ -62,11 +63,10 @@ func Login(c *gin.Context) {
 	}{})
 
 	//验证
-	adminUser := config.Get("app.admin_user")
-	adminSecret := config.Get("app.admin_secret")
-
-	if form.UserName != adminUser || form.Password != adminSecret {
-		response.Fail(c, 1000, "账号密码错误")
+	var admin model.Admin
+	global.App.DB.Table("admin").Where("account", form.UserName).First(&admin)
+	if admin.Password != "" && admin.Password != form.Password {
+		response.Fail(c, 1003, "账户密码错误")
 		return
 	}
 

+ 9 - 0
model/user.go

@@ -49,6 +49,15 @@ type UserOnline struct {
 	LogTime time.Time `json:"logTime" gorm:"column:logTime;"`
 }
 
+type Admin struct {
+	ID        int       `json:"id" gorm:"not null;"`
+	Account   string    `json:"account" gorm:"not null;"`
+	Password  string    `json:"password" gorm:"not null;"`
+	Name      string    `json:"name" gorm:"not null;"`
+	CreatedAt time.Time `json:"createdAt" gorm:"column:createdAt;"`
+	UpdatedAt time.Time `json:"updatedAt" gorm:"column:updatedAt;"`
+}
+
 // 1. 创建 time.Time 类型的副本 XTime;
 type XTime struct {
 	time.Time

+ 6 - 3
service/UserOnlineService.go

@@ -62,9 +62,12 @@ func UserOnlineSummaryByDay(gid string, pf string, startTime string, endTime str
 		totalTime = totalTime + userTotalTime
 	}
 	//统计平均值
-	avg := float64(totalTime) / float64(total)
-	totalAvg = int(math.Round(avg))
-
+	if total <= 0 {
+		totalAvg = 0
+	} else {
+		avg := float64(totalTime) / float64(total)
+		totalAvg = int(math.Round(avg))
+	}
 	return daysAvg, total, totalAvg, nil
 
 }