Selaa lähdekoodia

近期改动上传

wucan 5 kuukautta sitten
vanhempi
commit
bdebfc2020

+ 1 - 0
.gitignore

@@ -0,0 +1 @@
+storage

+ 0 - 8
.idea/.gitignore

@@ -1,8 +0,0 @@
-# Default ignored files
-/shelf/
-/workspace.xml
-# Editor-based HTTP Client requests
-/httpRequests/
-# Datasource local storage ignored files
-/dataSources/
-/dataSources.local.xml

+ 0 - 9
.idea/chunhao_admin.iml

@@ -1,9 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<module type="WEB_MODULE" version="4">
-  <component name="Go" enabled="true" />
-  <component name="NewModuleRootManager">
-    <content url="file://$MODULE_DIR$" />
-    <orderEntry type="inheritedJdk" />
-    <orderEntry type="sourceFolder" forTests="false" />
-  </component>
-</module>

+ 0 - 8
.idea/modules.xml

@@ -1,8 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project version="4">
-  <component name="ProjectModuleManager">
-    <modules>
-      <module fileurl="file://$PROJECT_DIR$/.idea/chunhao_admin.iml" filepath="$PROJECT_DIR$/.idea/chunhao_admin.iml" />
-    </modules>
-  </component>
-</project>

+ 0 - 6
.idea/vcs.xml

@@ -1,6 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project version="4">
-  <component name="VcsDirectoryMappings">
-    <mapping directory="" vcs="Git" />
-  </component>
-</project>

+ 74 - 36
controller/v1/file.go

@@ -60,6 +60,11 @@ func DirDownload(c *gin.Context) {
 		return
 	}
 
+	res := make(map[string]interface{})
+	dirName := filepath.Base(form.Dir)
+	res[dirName] = data
+	data = res
+
 	response.Success(c, gin.H{
 		"data": data,
 	})
@@ -78,7 +83,7 @@ func DirExplode(dir string) (map[string]interface{}, error) {
 
 	for _, file := range files {
 		if file.Type == 2 {
-			data[file.FileName], _ = DirExplode(file.Dir)
+			data[file.FileName], _ = DirExplode(file.Dir + file.FileName + "/")
 		} else {
 			data[file.FileName] = file.CosPath
 		}
@@ -89,25 +94,33 @@ func DirExplode(dir string) (map[string]interface{}, error) {
 
 func FileDelete(c *gin.Context) {
 	form := request.Check(c, &struct {
-		FileId int `form:"fileId" json:"fileId" binding:"required"`
+		FileId []int `form:"fileId" json:"fileId" binding:"required"`
 	}{})
-	var file model.File
-	global.App.DB.Table("file").Where("id", form.FileId).Find(&file)
 
-	if file.Type == 1 {
-		//删除本地文件和云端文件  (本地文件暂时不删除,作为备份)
-		err := ServiceFileDelete(file.CosPath)
+	for _, fileId := range form.FileId {
+		var file model.File
+		global.App.DB.Table("file").Where("id", fileId).Find(&file)
+		var d interface{}
+
+		err := global.App.DB.Table("file").Where("id", fileId).Delete(d).Error
 		if err != nil {
-			response.Fail(c, 2001, "云端文件删除失败"+err.Error())
+			response.Fail(c, 2001, err.Error())
 			return
 		}
-	}
 
-	var d interface{}
-	err := global.App.DB.Table("file").Where("id", form.FileId).Delete(d).Error
-	if err != nil {
-		response.Fail(c, 2001, err.Error())
-		return
+		if file.Type == 1 {
+			//删除本地文件和云端文件  (本地文件暂时不删除,作为备份)
+			err := ServiceFileDelete(file.CosPath)
+			if err != nil {
+				response.Fail(c, 2001, "云端文件删除失败"+err.Error())
+				return
+			}
+		} else if file.Type == 2 {
+			//文件夹需要删除关联的文件
+			dirName := file.Dir + file.FileName + "/"
+
+			global.App.DB.Table("file").Where("dir", "like", dirName+"%").Delete(d)
+		}
 	}
 
 	response.Success(c, gin.H{})
@@ -187,28 +200,25 @@ func UploadToCos(c *gin.Context) {
 	}
 
 	//存储文件夹
-	var dirFile model.File
-
-	base := filepath.Base(dir)
-	dirPath := strings.TrimSuffix(dir, base+"/")
-
-	fmt.Println("dirPath", dirPath)
-	global.App.DB.Table("file").Where("type", 2).Where("fileName", base).Where("dir", dirPath).First(&dirFile)
-	if dirFile.Id == 0 {
-		err := global.App.DB.Table("file").Create(&model.File{
-			CreatedAt: now,
-			UpdatedAt: now,
-			FileName:  base,
-			Dir:       dirPath,
-			LocalPath: "",
-			Type:      2,
-			CosPath:   "",
-		}).Error
-		if err != nil {
-			response.Fail(c, 2001, err.Error())
-			return
-		}
-	}
+	CreateDirs(dir)
+	//var dirFile model.File
+	//
+	//base := filepath.Base(dir)
+	//dirPath := strings.TrimSuffix(dir, base+"/")
+	//
+	//global.App.DB.Table("file").Where("type", 2).Where("fileName", base).Where("dir", dirPath).First(&dirFile)
+	//if dirFile.Id == 0 {
+	//	global.App.DB.Table("file").Create(&model.File{
+	//		CreatedAt: now,
+	//		UpdatedAt: now,
+	//		FileName:  base,
+	//		Dir:       dirPath,
+	//		LocalPath: "",
+	//		Type:      2,
+	//		CosPath:   "",
+	//	})
+	//
+	//}
 
 	//存储到mysql
 	var files model.File
@@ -244,6 +254,34 @@ func UploadToCos(c *gin.Context) {
 	})
 }
 
+func CreateDirs(dir string) {
+	if dir == "/" || dir == "" {
+		return
+	}
+
+	base := filepath.Base(dir)
+	dirPath := strings.TrimSuffix(dir, base+"/")
+
+	now := model.XTime{
+		Time: time.Now(),
+	}
+	var dirFile model.File
+	global.App.DB.Table("file").Where("type", 2).Where("fileName", base).Where("dir", dirPath).First(&dirFile)
+	if dirFile.Id == 0 {
+		global.App.DB.Table("file").Create(&model.File{
+			CreatedAt: now,
+			UpdatedAt: now,
+			FileName:  base,
+			Dir:       dirPath,
+			LocalPath: "",
+			Type:      2,
+			CosPath:   "",
+		})
+	}
+
+	CreateDirs(dirPath)
+}
+
 func CreateDir(c *gin.Context) {
 	form := request.Check(c, &struct {
 		Dir     string `form:"dir" json:"dir" binding:"required"`

+ 41 - 1
controller/v1/gameAction.go

@@ -585,7 +585,7 @@ func CopyGameAction(c *gin.Context) {
 		//查询出有无对应的option
 		var actionOption []model.GameActionOption
 		global.App.DB.Table("game_action_option").Where("actionId", v.ID).Scan(&actionOption)
-		fmt.Println(actionOption, v.ID)
+		//fmt.Println(actionOption, v.ID)
 		if actionOption != nil {
 			for _, option := range actionOption {
 				newActionOption := model.GameActionOption{
@@ -605,3 +605,43 @@ func CopyGameAction(c *gin.Context) {
 
 	response.Success(c, gin.H{})
 }
+
+func GetDefaultGameAction(c *gin.Context) {
+	response.Success(c, gin.H{
+		"data": []interface{}{
+			map[string]interface{}{
+				"actionId":   "pass",
+				"actionName": "通过关卡",
+				"status":     1,
+				"remark":     "",
+				"options": []map[string]interface{}{
+					map[string]interface{}{
+						"optionName": "关卡",
+						"optionId":   "lv",
+						"optionType": "int",
+					},
+				},
+			},
+			map[string]interface{}{
+				"actionId":   "enter",
+				"actionName": "进入关卡",
+				"status":     1,
+				"remark":     "",
+				"options": []map[string]interface{}{
+					map[string]interface{}{
+						"optionName": "关卡",
+						"optionId":   "lv",
+						"optionType": "int",
+					},
+				},
+			},
+			map[string]interface{}{
+				"actionId":   "reward",
+				"actionName": "领取奖励",
+				"status":     1,
+				"remark":     "",
+				"options":    make([]map[string]interface{}, 0),
+			},
+		},
+	})
+}

+ 64 - 43
controller/v1/gameConfig.go

@@ -9,10 +9,9 @@ import (
 	"designs/model"
 	"designs/utils"
 	"encoding/json"
+	"fmt"
 	"github.com/gin-gonic/gin"
 	"github.com/go-playground/validator/v10"
-	"os"
-	"path/filepath"
 	"strconv"
 	"strings"
 	"time"
@@ -185,8 +184,8 @@ func GetGidConfig(c *gin.Context) {
 
 func GidList(c *gin.Context) {
 	form := request.Check(c, &struct {
-		Search string `form:"search" binding:"" json:"search"`
-		Active bool   `form:"active" binding:"" json:"active"`
+		Search string `form:"search" binding:""`
+		Active bool   `form:"active" binding:"" `
 	}{})
 
 	var gameList []struct {
@@ -203,6 +202,17 @@ func GidList(c *gin.Context) {
 			Or("gameName LIKE ?", "%"+form.Search+"%")
 	}
 
+	//验证gid权限
+	permission := c.GetString("permission")
+	var PermissionSlice []string
+	json.Unmarshal([]byte(permission), &PermissionSlice)
+
+	if !utils.InArray("all", PermissionSlice) {
+		fmt.Println(PermissionSlice)
+		//需要验证gid权限
+		query = query.WhereIn("gid", PermissionSlice)
+	}
+
 	if form.Active == true {
 		//获取近七天有数据的gid
 		ActiveGid := GetActiveGid()
@@ -231,43 +241,49 @@ func GetActiveGid() []string {
 	activeGidList = strings.Split(activeGid, ",")
 
 	if len(activeGidList) <= 2 {
+		//if true {
 		var gidList []string
-
-		//重新读取数据
-		var dir string
-		if config.Get("app.local") == "local" {
-			//url = "mongodb://localhost:27017"
-			dir = "storage"
-		} else {
-			dir = "/www/wwwroot/chunhao_receive/storage"
-		}
-
-		now := time.Now()
-
-		for i := 0; i <= 7; i++ {
-			date := now.AddDate(0, 0, -i).Format("2006-01-02")
-			//读取对应的文件夹
-			dirPath := filepath.Join(dir, date)
-			dateDir, _ := os.ReadDir(dirPath)
-			//fmt.Println(dirPath, dateDir)
-
-			for _, v := range dateDir {
-
-				fileName := v.Name()
-
-				fileNameSplit := strings.Split(fileName, "_")
-
-				if len(fileNameSplit) < 2 {
-					continue
-				}
-				last := fileNameSplit[len(fileNameSplit)-1]
-				gid := strings.TrimRight(fileName, "_"+last)
-
-				if !utils.InArray(gid, gidList) {
-					gidList = append(gidList, gid)
-				}
-			}
-		}
+		//
+		////重新读取数据
+		//var dir string
+		//if config.Get("app.local") == "local" {
+		//	//url = "mongodb://localhost:27017"
+		//	dir = "storage"
+		//} else {
+		//	dir = "/www/wwwroot/chunhao_receive/storage"
+		//}
+		//
+		//now := time.Now()
+		//
+		//for i := 0; i <= 7; i++ {
+		//	date := now.AddDate(0, 0, -i).Format("2006-01-02")
+		//	//读取对应的文件夹
+		//	dirPath := filepath.Join(dir, date)
+		//	dateDir, _ := os.ReadDir(dirPath)
+		//	//fmt.Println(dirPath, dateDir)
+		//
+		//	for _, v := range dateDir {
+		//
+		//		fileName := v.Name()
+		//
+		//		fileNameSplit := strings.Split(fileName, "_")
+		//
+		//		if len(fileNameSplit) < 2 {
+		//			continue
+		//		}
+		//		last := fileNameSplit[len(fileNameSplit)-1]
+		//		gid := strings.TrimRight(fileName, "_"+last)
+		//
+		//		if !utils.InArray(gid, gidList) {
+		//			gidList = append(gidList, gid)
+		//		}
+		//	}
+		//}
+		//
+
+		global.App.DB.Table("user").
+			Where("createdAt", ">=", time.Now().AddDate(0, 0, -3)).
+			Distinct("gid").Pluck("gid", &gidList)
 
 		if len(gidList) > 0 {
 
@@ -278,7 +294,6 @@ func GetActiveGid() []string {
 			global.App.Redis.Set(context.Background(), key, gidString, time.Second*3600)
 			activeGidList = gidList
 		}
-
 	}
 
 	return activeGidList
@@ -314,8 +329,10 @@ func SetGameAction(c *gin.Context) {
 
 	//存入数据库
 	now := time.Now()
+
+	var gameAction model.GameAction
 	err := global.App.DB.Transaction(func(tx *utils.WtDB) error {
-		gameAction := model.GameAction{
+		gameAction = model.GameAction{
 			Gid:        form.Gid,
 			ActionId:   form.ActionId,
 			ActionName: form.ActionName,
@@ -352,7 +369,11 @@ func SetGameAction(c *gin.Context) {
 		return
 	}
 
-	response.Success(c, gin.H{})
+	response.Success(c, gin.H{
+		"data": map[string]interface{}{
+			"id": gameAction.ID,
+		},
+	})
 }
 
 // 更新游戏中的事件

+ 2 - 3
controller/v1/permission.go

@@ -84,9 +84,8 @@ func RandomString(length int) (string, error) {
 
 func SetAdmin(c *gin.Context) {
 	form := request.Check(c, &struct {
-		Account string `form:"account" binding:"required"`
-		Name    string `form:"name" binding:"required"`
-		//Password   string   `form:"password" binding:"required"`
+		Account    string   `form:"account" binding:"required"`
+		Name       string   `form:"name" binding:"required"`
 		Permission []string `form:"permission" binding:"required"`
 	}{})
 

+ 142 - 0
controller/v1/test.go

@@ -6,6 +6,7 @@ import (
 	"designs/global"
 	"designs/model"
 	"designs/response"
+	"designs/service"
 	"fmt"
 	"github.com/gin-gonic/gin"
 	"go.mongodb.org/mongo-driver/v2/bson"
@@ -227,3 +228,144 @@ func WriteDBDataToFile(c *gin.Context) {
 
 	response.Success(c, gin.H{})
 }
+
+// 对打点数据进行汇算
+func ActionDataSummary(c *gin.Context) {
+
+	now := time.Now()
+	for i := 1; i <= 30; i++ {
+		lastDay := now.AddDate(0, 0, -i).Format("20060102")
+
+		service.SeeAdsSummary(lastDay)
+
+		fmt.Println("用时", time.Since(now))
+	}
+
+	response.Success(c, gin.H{})
+}
+
+func BehaviorSummary(c *gin.Context) {
+
+	//先查出所有gid
+	ActiveGid := GetActiveGid()
+
+	now := time.Now()
+	start := now.AddDate(0, 0, -30)
+
+	pf := "wx"
+	//循环一下,查出userId 跟相关的在线数据
+	for _, gid := range ActiveGid {
+
+		start1 := time.Now()
+		fmt.Println("处理数据开始,gid :", gid)
+
+		//查询 30天内的在线数据
+
+		SummaryData, err := service.UserOnlineSummary(gid, pf, "", start.Format("2006-01-02 15:04:05"), now.Format("2006-01-02 15:04:05"))
+		if err != nil {
+			response.Fail(c, 1001, err.Error())
+			return
+		}
+
+		//aaa, _ := json.Marshal(SummaryData)
+		//global.App.Log.Error(string(aaa))
+		//
+		//return
+
+		fmt.Println("查询在线数据完成:", time.Since(start1))
+		//查询用户的登录次数
+		var loginData []struct {
+			UserId     int `json:"userId" gorm:"not null;column:userId;"`
+			LoginCount int `json:"loginCount" gorm:"not null;column:loginCount;"`
+		}
+		loginDataMap := make(map[int]int)
+
+		err = global.App.DB.Table("user_login").
+			Where("gid", gid).
+			Where("pf", pf).
+			Group("userId").
+			Select("count(*) as loginCount", "userId").
+			Scan(&loginData).Error
+		if err != nil {
+			response.Fail(c, 1002, err.Error())
+			return
+		}
+
+		for _, login := range loginData {
+			loginDataMap[login.UserId] = login.LoginCount
+		}
+
+		fmt.Println("查询登录数据完成:", time.Since(start1))
+
+		//查询用户的看广告次数,广告看完次数
+		var seeAdsData []struct {
+			UserId      int `json:"userId" gorm:"not null;column:userId;"`
+			SeeAdsCount int `json:"seeAdsCount" gorm:"not null;column:seeAdsCount;"`
+			State2Count int `json:"state2Count" gorm:"not null;column:state2Count;"`
+		}
+
+		seeAdsDataMap := make(map[int]int)
+		seeAdsDataMap2 := make(map[int]int)
+		err = global.App.DB.Table("user_see_ads").
+			Where("gid", gid).
+			Where("pf", pf).
+			Group("userId").
+			Select("count(*) as seeAdsCount", "SUM(CASE WHEN adsState = 2 THEN 1 ELSE 0 END) AS state2Count", "userId").
+			Scan(&seeAdsData).Error
+		if err != nil {
+			response.Fail(c, 1003, err.Error())
+			return
+		}
+
+		for _, ads := range seeAdsData {
+			seeAdsDataMap[ads.UserId] = ads.SeeAdsCount
+			seeAdsDataMap2[ads.UserId] = ads.State2Count
+		}
+
+		fmt.Println("查询广告数据完成:", time.Since(start1))
+
+		//格式化,存入数据库
+		var userIdList []model.User
+		err = global.App.DB.Table("user").Where("gid", gid).
+			Select("id", "userId").
+			Where("pf", pf).Scan(&userIdList).Error
+		if err != nil {
+			response.Fail(c, 1004, err.Error())
+			return
+		}
+
+		//fmt.Println(len(userIdList))
+
+		userBehavior := make(map[int]model.UserBehavior)
+		for _, users := range userIdList {
+			userBehavior[users.UserId] = model.UserBehavior{
+				ID:         users.ID,
+				Duration:   int(SummaryData[users.UserId]),
+				StartNum:   loginDataMap[users.UserId],
+				AdCount:    seeAdsDataMap[users.UserId],
+				AdExpCount: seeAdsDataMap2[users.UserId],
+			}
+		}
+
+		//aaa, _ := json.Marshal(userBehavior)
+		//global.App.Log.Error(string(aaa))
+		//
+		//return
+
+		var userBehaviorList []model.UserBehavior
+		for _, Behavior := range userBehavior {
+			userBehaviorList = append(userBehaviorList, Behavior)
+		}
+
+		err = global.App.DB.Table("user_behavior").CreateInBatches(&userBehaviorList, 1000).Error
+		if err != nil {
+			//global.App.Log.Error(userBehavior)
+			response.Fail(c, 1005, err.Error())
+			return
+		}
+
+		fmt.Println("存入汇总完成:", time.Since(start1))
+
+	}
+
+}

+ 2 - 2
controller/v1/user.go

@@ -72,8 +72,8 @@ func Login(c *gin.Context) {
 
 	//验证
 	var admin model.Admin
-	global.App.DB.Table("admin").Where("account", form.UserName).First(&admin)
-	if admin.Password != "" && admin.Password != form.Password {
+	global.App.DB.Table("admin").Where("account", form.UserName).Where("password", form.Password).First(&admin)
+	if admin.ID == 0 {
 		response.Fail(c, 1003, "账户密码错误")
 		return
 	}

+ 30 - 7
controller/v1/userAds.go

@@ -93,12 +93,32 @@ func UserAdsOverview(c *gin.Context) {
 		avgUserAds = float64(adsTotal) / float64(userTotal)
 	}
 
+	//当日变现人数
+	var todayCashCount int64
+
+	query := global.App.DB.Table("user").
+		Where("gid", form.Gid).
+		Where("pf", form.Pf).
+		WhereRaw("DATE_FORMAT(createdAt, '%Y%m%d') = ?", now.Format("20060102")).Select("userId").SubQuery()
+	err = global.App.DB.Table("user_see_ads").
+		Where("gid", form.Gid).
+		Where("pf", form.Pf).
+		Where("date", "=", now.Format("20060102")).
+		WhereRaw("userId in (?)", query).
+		Distinct("userId").
+		Count(&todayCashCount).Error
+	if err != nil {
+		response.Fail(c, 1001, err.Error())
+		return
+	}
+
 	response.Success(c, gin.H{
 		"data": map[string]interface{}{
-			"adsCount7":   adsCount7,
-			"adsCount30":  adsCount30,
-			"avgUserAds":  math.Round(avgUserAds*100) / 100,
-			"avgUserAds7": math.Round(avgUserAds7*100) / 100,
+			"adsCount7":      adsCount7,
+			"adsCount30":     adsCount30,
+			"todayCashCount": todayCashCount,
+			"avgUserAds":     math.Round(avgUserAds*100) / 100,
+			"avgUserAds7":    math.Round(avgUserAds7*100) / 100,
 		},
 	})
 
@@ -129,17 +149,20 @@ func UserAdsDaily(c *gin.Context) {
 	}
 
 	res := make(map[string]int)
+	resToday := make(map[string]int)
 	for _, v := range summary {
 		newDate := v.Date[:4] + "-" + v.Date[4:6] + "-" + v.Date[6:]
 
 		res[newDate] = v.Count
+		resToday[newDate] = v.TodayCount
 	}
 
 	response.Success(c, gin.H{
 		"data": map[string]interface{}{
-			"userAdsDaily": res,
-			"count":        0,
-			"avg":          0,
+			"userAdsDaily":      res,
+			"userAdsDailyToday": resToday,
+			"count":             0,
+			"avg":               0,
 		},
 	})
 

+ 58 - 180
controller/v1/userBehavior.go

@@ -813,11 +813,11 @@ func BehaviorList(c *gin.Context) {
 
 func AdRelatedList(c *gin.Context) {
 	form := request.Check(c, &struct {
-		//Gid    string `form:"gid" json:"gid" binding:"required"`
-		//Pf     string `form:"pf" json:"pf" binding:"required"`
-		//OpenId string `form:"search" json:"search" binding:""`
-		Offset int `form:"offset" json:"offset" binding:""`
-		Limit  int `form:"limit" json:"limit" binding:""`
+		Gid    string `form:"gid" json:"gid" binding:"required"`
+		Pf     string `form:"pf" json:"pf" binding:"required"`
+		OpenId string `form:"search" json:"search" binding:""`
+		Offset int    `form:"offset" json:"offset" binding:""`
+		Limit  int    `form:"limit" json:"limit" binding:""`
 
 		Pid string `form:"pid" json:"pid" binding:""`
 		Aid string `form:"aid" json:"aid" binding:""`
@@ -825,217 +825,95 @@ func AdRelatedList(c *gin.Context) {
 
 		CreateTime interface{} `form:"createTime" json:"createTime" binding:""`
 		StartNum   interface{} `form:"startNum" json:"startNum" binding:""`
-		Revenue    interface{} `form:"revenue" json:"revenue" binding:""`
 		Duration   interface{} `form:"duration" json:"duration" binding:""`
 		ReqCount   interface{} `form:"reqCount" json:"reqCount" binding:""`
 		ExpCount   interface{} `form:"expCount" json:"expCount" binding:""`
 	}{})
 
-	collection := global.App.MongoDB.Database("chunhao").Collection("adRelated")
+	query := global.App.DB.Table("user").
+		LeftJoin("user_behavior", "user.id = user_behavior.id").
+		Where("gid", form.Gid).Where("pf", form.Pf)
 
-	ctx := context.Background()
-	filter := bson.M{}
-	if form.Pid != "" {
-		filter["pid"] = form.Pid
-	}
-	if form.Aid != "" {
-		filter["aid"] = form.Aid
+	if form.OpenId != "" {
+		query = query.Where("open_id", form.OpenId)
 	}
-	if form.Cid != "" {
-		filter["cid"] = form.Cid
+
+	if form.Pid != "" {
+		query = query.Where("pid", form.Pid)
 	}
 
 	if form.CreateTime != nil {
-		marsh, _ := json.Marshal(form.CreateTime)
-		var totalAdEposedCount BehaviorFilter
-		json.Unmarshal(marsh, &totalAdEposedCount)
-
-		filters := bson.M{}
-		if totalAdEposedCount.Gt != 0 {
-			filters["$gt"] = totalAdEposedCount.Gt
-		}
-		if totalAdEposedCount.Gte != 0 {
-			filters["$gte"] = totalAdEposedCount.Gte
-		}
-		if totalAdEposedCount.Lte != 0 {
-			filters["$lte"] = totalAdEposedCount.Lte
-		}
-		if totalAdEposedCount.Lt != 0 {
-			filters["$lt"] = totalAdEposedCount.Lt
-		}
-		if totalAdEposedCount.Ne != 0 {
-			filters["$ne"] = totalAdEposedCount.Ne
-		}
-
-		if len(filters) > 0 {
-			filter["createTime"] = filters
-		}
+		query = BuildBehaviorQuery(query, form.CreateTime, "createdAt")
 	}
-
 	if form.StartNum != nil {
-		marsh, _ := json.Marshal(form.StartNum)
-		var totalAdEposedCount BehaviorFilter
-		json.Unmarshal(marsh, &totalAdEposedCount)
-
-		filters := bson.M{}
-		if totalAdEposedCount.Gt != 0 {
-			filters["$gt"] = totalAdEposedCount.Gt
-		}
-		if totalAdEposedCount.Gte != 0 {
-			filters["$gte"] = totalAdEposedCount.Gte
-		}
-		if totalAdEposedCount.Lte != 0 {
-			filters["$lte"] = totalAdEposedCount.Lte
-		}
-		if totalAdEposedCount.Lt != 0 {
-			filters["$lt"] = totalAdEposedCount.Lt
-		}
-		if totalAdEposedCount.Ne != 0 {
-			filters["$ne"] = totalAdEposedCount.Ne
-		}
-
-		if len(filters) > 0 {
-			filter["startNum"] = filters
-		}
-	}
-
-	if form.Revenue != nil {
-		marsh, _ := json.Marshal(form.Revenue)
-		var totalAdEposedCount BehaviorFilter
-		json.Unmarshal(marsh, &totalAdEposedCount)
-
-		filters := bson.M{}
-		if totalAdEposedCount.Gt != 0 {
-			filters["$gt"] = totalAdEposedCount.Gt
-		}
-		if totalAdEposedCount.Gte != 0 {
-			filters["$gte"] = totalAdEposedCount.Gte
-		}
-		if totalAdEposedCount.Lte != 0 {
-			filters["$lte"] = totalAdEposedCount.Lte
-		}
-		if totalAdEposedCount.Lt != 0 {
-			filters["$lt"] = totalAdEposedCount.Lt
-		}
-		if totalAdEposedCount.Ne != 0 {
-			filters["$ne"] = totalAdEposedCount.Ne
-		}
-
-		if len(filters) > 0 {
-			filter["revenue"] = filters
-		}
+		query = BuildBehaviorQuery(query, form.CreateTime, "startNum")
 	}
-
 	if form.Duration != nil {
-		marsh, _ := json.Marshal(form.Duration)
-		var totalAdEposedCount BehaviorFilter
-		json.Unmarshal(marsh, &totalAdEposedCount)
-
-		filters := bson.M{}
-		if totalAdEposedCount.Gt != 0 {
-			filters["$gt"] = totalAdEposedCount.Gt
-		}
-		if totalAdEposedCount.Gte != 0 {
-			filters["$gte"] = totalAdEposedCount.Gte
-		}
-		if totalAdEposedCount.Lte != 0 {
-			filters["$lte"] = totalAdEposedCount.Lte
-		}
-		if totalAdEposedCount.Lt != 0 {
-			filters["$lt"] = totalAdEposedCount.Lt
-		}
-		if totalAdEposedCount.Ne != 0 {
-			filters["$ne"] = totalAdEposedCount.Ne
-		}
-
-		if len(filters) > 0 {
-			filter["duration"] = filters
-		}
+		query = BuildBehaviorQuery(query, form.CreateTime, "duration")
 	}
-
 	if form.ReqCount != nil {
-		marsh, _ := json.Marshal(form.ReqCount)
-		var totalAdEposedCount BehaviorFilter
-		json.Unmarshal(marsh, &totalAdEposedCount)
-
-		filters := bson.M{}
-		if totalAdEposedCount.Gt != 0 {
-			filters["$gt"] = totalAdEposedCount.Gt
-		}
-		if totalAdEposedCount.Gte != 0 {
-			filters["$gte"] = totalAdEposedCount.Gte
-		}
-		if totalAdEposedCount.Lte != 0 {
-			filters["$lte"] = totalAdEposedCount.Lte
-		}
-		if totalAdEposedCount.Lt != 0 {
-			filters["$lt"] = totalAdEposedCount.Lt
-		}
-		if totalAdEposedCount.Ne != 0 {
-			filters["$ne"] = totalAdEposedCount.Ne
-		}
-
-		if len(filters) > 0 {
-			filter["reqCount"] = filters
-		}
+		query = BuildBehaviorQuery(query, form.CreateTime, "adCount")
 	}
-
 	if form.ExpCount != nil {
-		marsh, _ := json.Marshal(form.ExpCount)
-		var totalAdEposedCount BehaviorFilter
-		json.Unmarshal(marsh, &totalAdEposedCount)
-
-		filters := bson.M{}
-		if totalAdEposedCount.Gt != 0 {
-			filters["$gt"] = totalAdEposedCount.Gt
-		}
-		if totalAdEposedCount.Gte != 0 {
-			filters["$gte"] = totalAdEposedCount.Gte
-		}
-		if totalAdEposedCount.Lte != 0 {
-			filters["$lte"] = totalAdEposedCount.Lte
-		}
-		if totalAdEposedCount.Lt != 0 {
-			filters["$lt"] = totalAdEposedCount.Lt
-		}
-		if totalAdEposedCount.Ne != 0 {
-			filters["$ne"] = totalAdEposedCount.Ne
-		}
-
-		if len(filters) > 0 {
-			filter["expCount"] = filters
-		}
+		query = BuildBehaviorQuery(query, form.CreateTime, "adExpCount")
 	}
 
-	option := options.Find()
-	option.SetLimit(int64(form.Limit))
-	option.SetSkip(int64(form.Offset))
-
-	cur, err := collection.Find(ctx, filter, option)
+	var count int64
+	err := query.Count(&count).Error
 	if err != nil {
 		response.Fail(c, 1001, err.Error())
 		return
 	}
 
-	count, err := collection.CountDocuments(ctx, filter)
-	if err != nil {
-		response.Fail(c, 1001, err.Error())
-		return
+	var res []struct {
+		ID         int       `json:"id" gorm:"not null;"`
+		Pf         string    `json:"pf" gorm:"not null;"`
+		Gid        string    `json:"gid" gorm:"not null;"`
+		UserId     int       `json:"userId" gorm:"not null;column:userId;"`
+		OpenId     string    `json:"openId" gorm:"not null;column:openId;"`
+		CreatedAt  time.Time `json:"createdAt" gorm:"column:createdAt;"`
+		Duration   int       `json:"duration" gorm:"not null;"`
+		StartNum   int       `json:"startNum" gorm:"not null;column:startNum;"`
+		AdCount    int       `json:"adCount" gorm:"not null;column:adCount;"`
+		AdExpCount int       `json:"adExpCount" gorm:"not null;column:adExpCount;"`
 	}
 
-	var data []AdRelated
-	err = cur.All(ctx, &data)
+	err = query.Offset(form.Offset).Limit(form.Limit).Scan(&res).Error
 	if err != nil {
-		response.Fail(c, 1001, err.Error())
+		response.Fail(c, 1002, err.Error())
 		return
 	}
 
 	response.Success(c, gin.H{
-		"data":  data,
+		"data":  res,
 		"count": count,
 	})
 }
 
+func BuildBehaviorQuery(query *utils.WtDB, filters interface{}, field string) *utils.WtDB {
+	marsh, _ := json.Marshal(filters)
+	var filter BehaviorFilter
+	json.Unmarshal(marsh, &filter)
+
+	if filter.Gt > 0 {
+		query = query.Where(field, ">", filter.Gt)
+	}
+	if filter.Gte > 0 {
+		query = query.Where(field, ">=", filter.Gte)
+	}
+	if filter.Lt > 0 {
+		query = query.Where(field, "<", filter.Lt)
+	}
+	if filter.Lte > 0 {
+		query = query.Where(field, "<=", filter.Lte)
+	}
+	if filter.Ne > 0 {
+		query = query.Where(field, "!=", filter.Ne)
+	}
+
+	return query
+}
+
 // ConversionCondition 转化条件
 type ConversionCondition struct {
 	Id               string   `bson:"_id" json:"id"`

+ 4 - 51
crons/userAction.go

@@ -2,7 +2,7 @@ package crons
 
 import (
 	"designs/global"
-	"designs/model"
+	"designs/service"
 	"fmt"
 	"os"
 	"time"
@@ -72,62 +72,15 @@ func OnlineDatabaseDelete() {
 func AdsDataSummary() {
 	lastDay := time.Now().AddDate(0, 0, -1).Format("20060102")
 
-	//计算出上一日的广告数据汇总
-	var adsSummary []struct {
-		Count    int    `json:"count" gorm:"column:count"`
-		Pf       string `json:"pf" gorm:"column:pf"`
-		Gid      string `json:"gid" gorm:"column:gid"`
-		SumType1 string `json:"sumType1" gorm:"column:sumType1"`
-		SumType2 string `json:"sumType2" gorm:"column:sumType2"`
-		SumType0 string `json:"sumType0" gorm:"column:sumType0"`
-	}
-
-	err := global.App.DB.Table("user_see_ads").
-		Where("date", lastDay).
-		Group("gid,pf").
-		Select("count(*) as count", "pf", "gid",
-			"SUM(adsState = 1) AS sumType1",
-			"SUM(adsState = 2) AS sumType2",
-			"SUM(adsState = 0) AS sumType0").
-		Scan(&adsSummary).Error
-
-	fmt.Println(adsSummary)
-	if err != nil {
-		global.App.Log.Error("查询广告汇总数据报错:", err)
-		return
-	}
-	var SummaryUserSeeAds []model.SummaryUserSeeAds
-
-	now := model.XTime{
-		Time: time.Now(),
-	}
-	for _, summary := range adsSummary {
-		SummaryUserSeeAds = append(SummaryUserSeeAds, model.SummaryUserSeeAds{
-			Date:      lastDay,
-			Count:     summary.Count,
-			Pf:        summary.Pf,
-			Gid:       summary.Gid,
-			SumType1:  summary.SumType1,
-			SumType2:  summary.SumType2,
-			SumType0:  summary.SumType0,
-			CreatedAt: now,
-		})
-	}
-
-	//将汇总数据存入数据库中
-	err = global.App.DB.Table("summary_user_see_ads").CreateInBatches(&SummaryUserSeeAds, 100).Error
-	if err != nil {
-		global.App.Log.Error("存入统计数据失败", err.Error())
-		fmt.Println(err.Error())
-		return
-	}
+	service.SeeAdsSummary(lastDay)
 
 	return
 }
 
+//
 //// 对打点数据进行汇算
 //func ActionDataSummary() {
 //	lastDay := time.Now().AddDate(0, 0, -1).Format("2006-01-02")
 //
-//	//
+//	//获取
 //}

+ 65 - 2
middleware/isSuper.go

@@ -1,9 +1,72 @@
 package middleware
 
-import "github.com/gin-gonic/gin"
+import (
+	"bytes"
+	"designs/global"
+	"designs/model"
+	"designs/response"
+	"designs/utils"
+	"encoding/json"
+	"github.com/gin-gonic/gin"
+	"io"
+)
+
+func CheckAuth() gin.HandlerFunc {
+	return func(c *gin.Context) {
+		//查询出权限
+		userName := c.GetString("userName")
+		if userName == "chunhao" {
+			//超级权限
+			c.Set("permission", "[\"all\"]")
+			c.Next()
+			return
+		}
+
+		data, _ := c.GetRawData()
+		form := struct {
+			Gid string `form:"gid" json:"gid"`
+		}{}
+		json.Unmarshal(data, &form)
+
+		// 3. 重置请求体,以便后续绑定使用
+		c.Request.Body = io.NopCloser(bytes.NewBuffer(data))
+
+		var admin model.Admin
+		global.App.DB.Table("admin").Where("account", userName).Find(&admin)
+
+		var PermissionSlice []string
+		json.Unmarshal([]byte(admin.Permission), &PermissionSlice)
+
+		if form.Gid == "" {
+			//这个接口不验证gid
+			c.Set("permission", admin.Permission)
+			c.Next()
+			return
+		}
+		if utils.InArray("all", PermissionSlice) || utils.InArray(form.Gid, PermissionSlice) {
+			//能够使用gid
+			c.Set("permission", admin.Permission)
+			c.Next()
+			return
+		} else {
+			response.Fail(c, -1, "gid权限不足,不能查看该数据!")
+			c.Abort()
+			return
+		}
+	}
+}
 
 func CheckSuper() gin.HandlerFunc {
 	return func(c *gin.Context) {
-		//
+		//查询出权限
+		userName := c.GetString("userName")
+
+		if userName == "chunhao" {
+			c.Next()
+		} else {
+			response.Fail(c, -1, "权限不足,只有超级管理员可以访问!")
+			c.Abort()
+			return
+		}
 	}
 }

+ 15 - 9
model/summary.go

@@ -1,13 +1,19 @@
 package model
 
 type SummaryUserSeeAds struct {
-	Id        int    `json:"id" gorm:"primary_key;"`
-	Date      string `json:"date" gorm:"column:date;"`
-	Count     int    `json:"count" gorm:"column:count"`
-	Pf        string `json:"pf" gorm:"column:pf"`
-	Gid       string `json:"gid" gorm:"column:gid"`
-	SumType1  string `json:"sumType1" gorm:"column:sumType1"`
-	SumType2  string `json:"sumType2" gorm:"column:sumType2"`
-	SumType0  string `json:"sumType0" gorm:"column:sumType0"`
-	CreatedAt XTime  `json:"createdAt" gorm:"column:createdAt;type:date;"`
+	Id       int    `json:"id" gorm:"primary_key;"`
+	Date     string `json:"date" gorm:"column:date;"`
+	Count    int    `json:"count" gorm:"column:count"`
+	Pf       string `json:"pf" gorm:"column:pf"`
+	Gid      string `json:"gid" gorm:"column:gid"`
+	SumType1 int    `json:"sumType1" gorm:"column:sumType1"`
+	SumType2 int    `json:"sumType2" gorm:"column:sumType2"`
+	SumType0 int    `json:"sumType0" gorm:"column:sumType0"`
+
+	TodayCount    int `json:"todayCount" gorm:"column:todayCount"`
+	TodaySumType1 int `json:"todaySumType1" gorm:"column:todaySumType1"`
+	TodaySumType2 int `json:"todaySumType2" gorm:"column:todaySumType2"`
+	TodaySumType0 int `json:"todaySumType0" gorm:"column:todaySumType0"`
+
+	CreatedAt XTime `json:"createdAt" gorm:"column:createdAt;type:date;"`
 }

+ 8 - 0
model/user.go

@@ -59,6 +59,14 @@ type UserOnlineSplit struct {
 	LogTime time.Time `json:"logTime" gorm:"column:logTime;"`
 }
 
+type UserBehavior struct {
+	ID         int `json:"id" gorm:"not null;"`
+	Duration   int `json:"duration" gorm:"not null;"`
+	StartNum   int `json:"startNum" gorm:"not null;column:startNum;"`
+	AdCount    int `json:"adCount" gorm:"not null;column:adCount;"`
+	AdExpCount int `json:"adExpCount" gorm:"not null;column:adExpCount;"`
+}
+
 type Admin struct {
 	ID         int    `json:"id" gorm:"not null;"`
 	Account    string `json:"account" gorm:"not null;"`

+ 35 - 25
route/api.go

@@ -19,12 +19,8 @@ func SetApiGroupRoutes(router *gin.RouterGroup) {
 	router.POST("/uploadToCos", v1.UploadToCos)
 
 	GroupV1 := router.Group("")
-	GroupV1.Use(middleware.TokenAuthMiddleware()).Use()
+	GroupV1.Use(middleware.TokenAuthMiddleware()).Use(middleware.CheckAuth()).Use()
 	{
-		GroupV1.POST("/user/userList", v1.UserList)
-
-		GroupV1.POST("/user/addGidConfig", v1.AddGidConfig)
-		GroupV1.POST("/user/getGidConfig", v1.GetGidConfig)
 		GroupV1.POST("/user/gidList", v1.GidList)
 
 		GroupV1.POST("/user/addUserToBlackList", v1.AddUserToBlackList)
@@ -50,17 +46,6 @@ func SetApiGroupRoutes(router *gin.RouterGroup) {
 		GroupV1.POST("/user/dataTradesDetail", v1.DataTradesDetail)
 		GroupV1.POST("/user/remainDataBydDay", v1.RemainDataBydDay)
 
-		//游戏自定义事件管理
-		GroupV1.POST("/user/setGameAction", v1.SetGameAction)
-		GroupV1.POST("/user/updateGameAction", v1.UpdateGameAction)
-		GroupV1.POST("/user/copyGameAction", v1.CopyGameAction)
-		GroupV1.POST("/user/updateGameActionOption", v1.UpdateGameActionOption)
-		GroupV1.POST("/user/addGameActionOption", v1.AddGameActionOption)
-		GroupV1.POST("/user/deleteGameActionOption", v1.DeleteGameActionOption)
-		GroupV1.POST("/user/gameActionList", v1.GameActionList)
-		GroupV1.POST("/user/gameActionDetail", v1.GameActionDetail)
-		GroupV1.POST("/user/gameActionOptionList", v1.GameActionOptionList)
-
 		//游戏自定义事件统计
 		GroupV1.POST("/user/userActionDetail", v1.UserActionDetail)
 		GroupV1.POST("/user/userActionList", v1.UserActionList)
@@ -79,19 +64,42 @@ func SetApiGroupRoutes(router *gin.RouterGroup) {
 
 		GroupV1.POST("/user/userAdsCake", v1.UserAdsCake)
 		GroupV1.POST("/user/behaviorListCake", v1.BehaviorListCake)
+	}
+
+	GroupSuper := router.Group("")
+	GroupSuper.Use(middleware.TokenAuthMiddleware()).Use(middleware.CheckSuper()).Use()
+	{
+
+		//游戏管理
+		GroupSuper.POST("/user/addGidConfig", v1.AddGidConfig)
+		GroupSuper.POST("/user/getGidConfig", v1.GetGidConfig)
+		//玩家管理
+		GroupSuper.POST("/user/userList", v1.UserList)
+
+		//游戏自定义事件管理
+		GroupSuper.POST("/user/setGameAction", v1.SetGameAction)
+		GroupSuper.POST("/user/updateGameAction", v1.UpdateGameAction)
+		GroupSuper.POST("/user/copyGameAction", v1.CopyGameAction)
+		GroupSuper.POST("/user/getDefaultGameAction", v1.GetDefaultGameAction) //获取预设打点
+		GroupSuper.POST("/user/updateGameActionOption", v1.UpdateGameActionOption)
+		GroupSuper.POST("/user/addGameActionOption", v1.AddGameActionOption)
+		GroupSuper.POST("/user/deleteGameActionOption", v1.DeleteGameActionOption)
+		GroupSuper.POST("/user/gameActionList", v1.GameActionList)
+		GroupSuper.POST("/user/gameActionDetail", v1.GameActionDetail)
+		GroupSuper.POST("/user/gameActionOptionList", v1.GameActionOptionList)
 
 		//文件上传
-		GroupV1.POST("/file/localFileToService", v1.LocalFileToService)
-		GroupV1.POST("/file/fileList", v1.FileList)
-		GroupV1.POST("/file/fileDelete", v1.FileDelete)
-		GroupV1.POST("/file/createDir", v1.CreateDir)
-		GroupV1.POST("/file/dirDownload", v1.DirDownload)
+		GroupSuper.POST("/file/localFileToService", v1.LocalFileToService)
+		GroupSuper.POST("/file/fileList", v1.FileList)
+		GroupSuper.POST("/file/fileDelete", v1.FileDelete)
+		GroupSuper.POST("/file/createDir", v1.CreateDir)
+		GroupSuper.POST("/file/dirDownload", v1.DirDownload)
 
 		//管理员管理
-		GroupV1.POST("/admin/adminList", v1.AdminList)
-		GroupV1.POST("/admin/setAdmin", v1.SetAdmin)
-		GroupV1.POST("/admin/deleteAdmin", v1.DeleteAdmin)
-		GroupV1.POST("/admin/updateAdmin", v1.UpdateAdmin)
+		GroupSuper.POST("/admin/adminList", v1.AdminList)
+		GroupSuper.POST("/admin/setAdmin", v1.SetAdmin)
+		GroupSuper.POST("/admin/deleteAdmin", v1.DeleteAdmin)
+		GroupSuper.POST("/admin/updateAdmin", v1.UpdateAdmin)
 	}
 
 	router.POST("/SetUserBehaviorBak", v1.SetUserBehaviorBak)       //测试接口
@@ -104,5 +112,7 @@ func SetApiGroupRoutes(router *gin.RouterGroup) {
 	router.POST("/OnlineToFile", v1.OnlineToFile)                   //测试接口
 	router.POST("/SplitOnlineData", v1.SplitOnlineData)             //迁移数据到online拆分表
 	router.POST("/InitGidConfig", v1.InitGidConfig)
+	//router.POST("/test", v1.ActionDataSummary)
+	router.POST("/test", v1.BehaviorSummary)
 
 }

+ 9 - 0
service/UserOnlineService.go

@@ -8,6 +8,7 @@ import (
 	"math"
 	"os"
 	"path/filepath"
+	"sort"
 	"strconv"
 	"strings"
 	"time"
@@ -125,6 +126,8 @@ func UserOnlineSummary(gid string, pf string, date string, startTime string, end
 	userLogMsg := make(map[int]int64)
 	//分组后对于每个用户的数据进行处理,得到他们的具体在线时长
 	for k, v := range userOnlineData {
+		//aaa, _ := json.Marshal(v)
+		//global.App.Log.Error(string(aaa))
 		userLogMsg[k] = calculateUserOnlineTime(v)
 	}
 	userOnlineData = nil
@@ -134,11 +137,17 @@ func UserOnlineSummary(gid string, pf string, date string, startTime string, end
 
 func calculateUserOnlineTime(logData []logData) int64 {
 
+	sort.Slice(logData, func(i, j int) bool {
+		return logData[i].LogTime.Before(logData[j].LogTime)
+	})
+
 	var lastLog int64
 	var isStart bool
 	var onlineTimeTotal int64
+
 	for k, v := range logData {
 		logTime := v.LogTime.Unix()
+
 		//如果跟上一次的记录隔的时间超过6分钟,就认为是之前断线了,属于无效数据
 		if k > 0 && logData[k-1].LogTime.Unix()+60*6 < logTime {
 			isStart = false

+ 99 - 0
service/userSeeAds.go

@@ -0,0 +1,99 @@
+package service
+
+import (
+	"designs/global"
+	"designs/model"
+	"fmt"
+	"time"
+)
+
+// 汇总每日的广告数据
+func SeeAdsSummary(lastDay string) {
+	//计算出上一日的广告数据汇总
+	var adsSummary []struct {
+		Count    int    `json:"count" gorm:"column:count"`
+		Pf       string `json:"pf" gorm:"column:pf"`
+		Gid      string `json:"gid" gorm:"column:gid"`
+		SumType1 int    `json:"sumType1" gorm:"column:sumType1"`
+		SumType2 int    `json:"sumType2" gorm:"column:sumType2"`
+		SumType0 int    `json:"sumType0" gorm:"column:sumType0"`
+	}
+
+	err := global.App.DB.Table("user_see_ads").
+		Where("date", lastDay).
+		Group("user_see_ads.gid,user_see_ads.pf").
+		Select("count(*) as count", "user_see_ads.pf", "user_see_ads.gid",
+			"SUM(adsState = 1) AS sumType1",
+			"SUM(adsState = 2) AS sumType2",
+			"SUM(adsState = 0) AS sumType0").
+		Scan(&adsSummary).Error
+
+	if err != nil {
+		global.App.Log.Error("查询广告汇总数据报错:", err)
+		return
+	}
+
+	var adsSummaryToday []struct {
+		TodayCount    int    `json:"todayCount" gorm:"column:todayCount"`
+		Pf            string `json:"pf" gorm:"column:pf"`
+		Gid           string `json:"gid" gorm:"column:gid"`
+		TodaySumType1 int    `json:"todaySumType1" gorm:"column:todaySumType1"`
+		TodaySumType2 int    `json:"todaySumType2" gorm:"column:todaySumType2"`
+		TodaySumType0 int    `json:"todaySumType0" gorm:"column:todaySumType0"`
+	}
+
+	query := global.App.DB.Table("user").WhereRaw("DATE_FORMAT(createdAt, '%Y%m%d') = ?", lastDay).Select("id").SubQuery()
+	err = global.App.DB.Table("user_see_ads").
+		Where("date", lastDay).
+		Group("user_see_ads.gid,user_see_ads.pf").
+		LeftJoin("user", "user.pf = user_see_ads.pf and user.gid = user_see_ads.gid and user.userId = user_see_ads.userId").
+		WhereRaw("user.id in (?)", query).
+		Select("count(*) as todayCount", "user_see_ads.pf", "user_see_ads.gid",
+			"SUM(adsState = 1) AS todaySumType1",
+			"SUM(adsState = 2) AS todaySumType2",
+			"SUM(adsState = 0) AS todaySumType0").
+		Scan(&adsSummaryToday).Error
+
+	if err != nil {
+		global.App.Log.Error("查询当日注册广告汇总数据报错:", err)
+		return
+	}
+	var SummaryUserSeeAds []model.SummaryUserSeeAds
+
+	now := model.XTime{
+		Time: time.Now(),
+	}
+	for _, summary := range adsSummary {
+		ds := model.SummaryUserSeeAds{
+			Date:      lastDay,
+			Count:     summary.Count,
+			Pf:        summary.Pf,
+			Gid:       summary.Gid,
+			SumType1:  summary.SumType1,
+			SumType2:  summary.SumType2,
+			SumType0:  summary.SumType0,
+			CreatedAt: now,
+		}
+
+		for _, SummaryToday := range adsSummaryToday {
+			if SummaryToday.Pf == ds.Pf && SummaryToday.Gid == ds.Gid {
+				ds.TodaySumType1 = SummaryToday.TodaySumType1
+				ds.TodaySumType2 = SummaryToday.TodaySumType2
+				ds.TodaySumType0 = SummaryToday.TodaySumType0
+				ds.TodayCount = SummaryToday.TodayCount
+
+				break
+			}
+		}
+
+		SummaryUserSeeAds = append(SummaryUserSeeAds, ds)
+	}
+
+	//将汇总数据存入数据库中
+	err = global.App.DB.Table("summary_user_see_ads").CreateInBatches(&SummaryUserSeeAds, 100).Error
+	if err != nil {
+		global.App.Log.Error("存入统计数据失败", err.Error())
+		fmt.Println(err.Error())
+		return
+	}
+}