urbanu 1 месяц назад
Родитель
Сommit
ba7d7098d7
7 измененных файлов с 68 добавлено и 75 удалено
  1. 2 0
      .gitignore
  2. 1 1
      apis/daytask/auth.go
  3. 16 15
      apis/daytask/material.go
  4. 4 4
      apis/daytask/rank.go
  5. 17 52
      apis/daytask/sign.go
  6. 22 0
      cmds/migrate.go
  7. 6 3
      commons/model/entity/dt_user.go

+ 2 - 0
.gitignore

@@ -3,6 +3,8 @@
 *.o
 *.a
 *.so
+go.mod
+go.sum
 # Folders
 _obj
 _test

+ 1 - 1
apis/daytask/auth.go

@@ -450,7 +450,7 @@ func (s *Server) OAuthLogin(c *gin.Context) {
 	social = entity.DtUserSocial{
 		UserId:   user.Id,
 		Platform: req.Provider,
-		OpenId:   req.OpenId,
+		Account:  req.OpenId,
 		Nickname: req.Nickname,
 		Avatar:   req.Avatar,
 	}

+ 16 - 15
apis/daytask/material.go

@@ -45,18 +45,19 @@ func (s *Server) MaterialList(c *gin.Context) {
 	type MaterialInfo struct {
 		Id          int64  `json:"id"`
 		Title       string `json:"title"`
-		Cover       string `json:"cover"`
+		TitleVi     string `json:"titleVi"`
 		Type        string `json:"type"`
-		Url         string `json:"url"`
-		Description string `json:"description"`
+		Icon        string `json:"icon"`
+		Images      string `json:"images"`
+		Videos      string `json:"videos"`
+		TextContent string `json:"textContent"`
 		ViewCount   int    `json:"viewCount"`
-		LikeCount   int    `json:"likeCount"`
 		CreatedAt   int64  `json:"createdAt"`
 	}
 
 	materials := make([]*MaterialInfo, 0)
-	query.Select("id, title, cover, type, url, description, view_count, like_count, created_at").
-		Order("id DESC").
+	query.Select("id, title, title_vi, type, icon, images, videos, text_content, view_count, created_at").
+		Order("sort ASC, id DESC").
 		Offset(int(paging.Start)).
 		Limit(int(paging.Size)).
 		Scan(&materials)
@@ -94,18 +95,18 @@ func (s *Server) MaterialDetail(c *gin.Context) {
 	ctx.OK(gin.H{
 		"id":          material.Id,
 		"title":       material.Title,
-		"cover":       material.Cover,
+		"titleVi":     material.TitleVi,
 		"type":        material.Type,
-		"url":         material.Url,
-		"description": material.Description,
-		"content":     material.Content,
+		"icon":        material.Icon,
+		"images":      material.Images,
+		"videos":      material.Videos,
+		"textContent": material.TextContent,
 		"viewCount":   material.ViewCount + 1,
-		"likeCount":   material.LikeCount,
 		"createdAt":   material.CreatedAt,
 	})
 }
 
-// MaterialLike 素材点赞
+// MaterialLike 素材点赞 - 由于实体没有likeCount字段,改为增加浏览次数
 func (s *Server) MaterialLike(c *gin.Context) {
 	ctx := s.FromContext(c)
 	db := s.DB()
@@ -125,11 +126,11 @@ func (s *Server) MaterialLike(c *gin.Context) {
 		return
 	}
 
-	// 更新点赞次数
+	// 更新浏览次数(用作点赞计数)
 	db.Model(&entity.DtMaterial{}).Where("id = ?", req.Id).
-		Update("like_count", material.LikeCount+1)
+		Update("view_count", material.ViewCount+1)
 
 	ctx.OK(gin.H{
-		"likeCount": material.LikeCount + 1,
+		"viewCount": material.ViewCount + 1,
 	})
 }

+ 4 - 4
apis/daytask/rank.go

@@ -53,7 +53,7 @@ func (s *Server) RankList(c *gin.Context) {
 			HAVING amount > 0
 			ORDER BY amount DESC
 			LIMIT ?
-		`, entity.BalanceLogTypeTask, entity.BalanceLogTypeCommission, today, limit).Scan(&ranks)
+		`, entity.BalanceLogTypeTaskIncome, entity.BalanceLogTypeCommission, today, limit).Scan(&ranks)
 
 	case "weekly":
 		// 本周收益排行
@@ -76,7 +76,7 @@ func (s *Server) RankList(c *gin.Context) {
 			HAVING amount > 0
 			ORDER BY amount DESC
 			LIMIT ?
-		`, entity.BalanceLogTypeTask, entity.BalanceLogTypeCommission, weekStart, limit).Scan(&ranks)
+		`, entity.BalanceLogTypeTaskIncome, entity.BalanceLogTypeCommission, weekStart, limit).Scan(&ranks)
 
 	case "monthly":
 		// 本月收益排行
@@ -99,7 +99,7 @@ func (s *Server) RankList(c *gin.Context) {
 			HAVING amount > 0
 			ORDER BY amount DESC
 			LIMIT ?
-		`, entity.BalanceLogTypeTask, entity.BalanceLogTypeCommission, month, limit).Scan(&ranks)
+		`, entity.BalanceLogTypeTaskIncome, entity.BalanceLogTypeCommission, month, limit).Scan(&ranks)
 
 	case "total":
 		// 累计收益排行
@@ -158,7 +158,7 @@ func (s *Server) RankReward(c *gin.Context) {
 	ctx := s.FromContext(c)
 	db := s.DB()
 
-	var configs []entity.DtLeaderboard
+	var configs []entity.DtLeaderboardReward
 	db.Where("status = ?", 1).
 		Order("rank_start ASC").
 		Find(&configs)

+ 17 - 52
apis/daytask/sign.go

@@ -30,7 +30,7 @@ func (s *Server) SignInfo(c *gin.Context) {
 	// 获取本月签到记录
 	month := time.Now().Format("2006-01")
 	var monthSigns []entity.DtUserSign
-	db.Where("user_id = ? AND sign_date LIKE ?", userId, month+"%").
+	db.Where("user_id = ? AND month = ?", userId, month).
 		Order("sign_date ASC").
 		Find(&monthSigns)
 
@@ -40,27 +40,11 @@ func (s *Server) SignInfo(c *gin.Context) {
 		signDates = append(signDates, sign.SignDate)
 	}
 
-	// 获取签到配置
-	var signConfigs []entity.DtUserSign
-	db.Model(&entity.DtUserSign{}).
-		Select("DISTINCT day, reward").
-		Where("day > 0").
-		Order("day ASC").
-		Limit(7).
-		Find(&signConfigs)
-
 	// 构建奖励配置
 	rewards := make([]gin.H, 0)
-	for i := 1; i <= 7; i++ {
-		reward := 0.0
-		for _, config := range signConfigs {
-			if config.Day == i {
-				reward = config.Reward
-				break
-			}
-		}
+	for i, reward := range entity.SignRewardConfig {
 		rewards = append(rewards, gin.H{
-			"day":    i,
+			"day":    i + 1,
 			"reward": reward,
 		})
 	}
@@ -82,6 +66,7 @@ func (s *Server) SignDo(c *gin.Context) {
 
 	// 检查今日是否已签到
 	today := time.Now().Format("2006-01-02")
+	month := time.Now().Format("2006-01")
 	var existSign entity.DtUserSign
 	if err := db.Where("user_id = ? AND sign_date = ?", userId, today).First(&existSign).Error; err == nil {
 		ctx.Fail("already_signed")
@@ -109,40 +94,20 @@ func (s *Server) SignDo(c *gin.Context) {
 		continuousDays = user.ContinuousSignDays + 1
 	}
 
-	// 根据连续天数获取奖励(7天循环)
-	day := ((continuousDays - 1) % 7) + 1
-	reward := 0.0
-
-	// 从配置获取奖励
-	var config entity.DtConfig
-	if err := db.Where("`group` = ? AND `key` = ?", "sign", "rewards").First(&config).Error; err == nil {
-		// 可以解析JSON配置获取每天奖励
-		// 这里简化处理,使用默认值
-	}
-
-	// 默认奖励配置
-	defaultRewards := map[int]float64{
-		1: 0.1,
-		2: 0.2,
-		3: 0.3,
-		4: 0.5,
-		5: 0.8,
-		6: 1.0,
-		7: 2.0,
-	}
-	if r, ok := defaultRewards[day]; ok {
-		reward = r
-	}
+	// 根据连续天数获取奖励(8天循环)
+	dayIndex := (continuousDays - 1) % len(entity.SignRewardConfig)
+	reward := entity.SignRewardConfig[dayIndex]
 
 	// 开启事务
 	tx := db.Begin()
 
 	// 创建签到记录
 	sign := &entity.DtUserSign{
-		UserId:   userId,
-		SignDate: today,
-		Day:      day,
-		Reward:   reward,
+		UserId:       userId,
+		SignDate:     today,
+		SignDay:      continuousDays,
+		RewardAmount: reward,
+		Month:        month,
 	}
 	if err := tx.Create(sign).Error; err != nil {
 		tx.Rollback()
@@ -164,11 +129,11 @@ func (s *Server) SignDo(c *gin.Context) {
 
 	// 记录余额变动
 	balanceLog := &entity.DtBalanceLog{
-		UserId:      userId,
-		Type:        entity.BalanceLogTypeSign,
-		Amount:      reward,
-		Balance:     user.Balance + reward,
-		Description: "签到奖励",
+		UserId:       userId,
+		Type:         entity.BalanceLogTypeSignReward,
+		Amount:       reward,
+		AfterBalance: user.Balance + reward,
+		Remark:       "签到奖励",
 	}
 	if err := tx.Create(balanceLog).Error; err != nil {
 		tx.Rollback()

+ 22 - 0
cmds/migrate.go

@@ -75,6 +75,28 @@ var allTables = []MigrateTable{
 	// 促销活动模块
 	entity.NewPromotionUpgradeLevel(), // 升级奖
 
+	// DayTask模块
+	entity.NewDtUser(),
+	entity.NewDtUserLevel(),
+	entity.NewDtUserSocial(),
+	entity.NewDtUserPayment(),
+	entity.NewDtTaskCategory(),
+	entity.NewDtTask(),
+	entity.NewDtTaskStep(),
+	entity.NewDtUserTask(),
+	entity.NewDtBalanceLog(),
+	entity.NewDtWithdrawOrder(),
+	entity.NewDtUserSign(),
+	entity.NewDtNotice(),
+	entity.NewDtBanner(),
+	entity.NewDtMaterial(),
+	entity.NewDtMaterialCategory(),
+	entity.NewDtLeaderboardStats(),
+	entity.NewDtLeaderboardReward(),
+	entity.NewDtConfig(),
+	entity.NewDtHelpCategory(),
+	entity.NewDtHelp(),
+	entity.NewDtCustomerService(),
 }
 
 func migrateMain(db *gorm.DB) {

+ 6 - 3
commons/model/entity/dt_user.go

@@ -29,9 +29,12 @@ type DtUser struct {
 	IdCard           string  `json:"idCard" gorm:"type:varchar(64);comment:身份证号"`
 	RegisterIp       string  `json:"registerIp" gorm:"type:varchar(64);comment:注册IP"`
 	RegisterDevice   string  `json:"registerDevice" gorm:"type:varchar(255);comment:注册设备"`
-	LastLoginTime    int64   `json:"lastLoginTime" gorm:"comment:最后登录时间"`
-	LastLoginIp      string  `json:"lastLoginIp" gorm:"type:varchar(64);comment:最后登录IP"`
-	Remark           string  `json:"remark" gorm:"type:varchar(255);comment:备注"`
+	LastLoginTime      int64   `json:"lastLoginTime" gorm:"comment:最后登录时间"`
+	LastLoginIp        string  `json:"lastLoginIp" gorm:"type:varchar(64);comment:最后登录IP"`
+	Remark             string  `json:"remark" gorm:"type:varchar(255);comment:备注"`
+	ContinuousSignDays int     `json:"continuousSignDays" gorm:"default:0;comment:连续签到天数"`
+	TotalSignDays      int     `json:"totalSignDays" gorm:"default:0;comment:累计签到天数"`
+	TotalIncome        float64 `json:"totalIncome" gorm:"type:decimal(18,2);default:0.00;comment:累计收益"`
 }
 
 func (*DtUser) TableName() string {