| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- package daytask
- import (
- "app/commons/model/entity"
- "app/commons/services"
- "github.com/gin-gonic/gin"
- "time"
- )
- // TeamInfo 团队信息
- func (s *Server) TeamInfo(c *gin.Context) {
- ctx := s.FromContext(c)
- db := s.DB()
- userId := ctx.UserId()
- user := &entity.DtUser{}
- if err := db.Where("id = ?", userId).First(user).Error; err != nil {
- ctx.Fail("user_not_found")
- return
- }
- // 今日新增
- today := time.Now().Format("2006-01-02")
- var todayCount int64
- db.Model(&entity.DtUser{}).
- Where("parent_id = ? AND DATE(FROM_UNIXTIME(created_at)) = ?", userId, today).
- Count(&todayCount)
- // 本月新增
- month := time.Now().Format("2006-01")
- var monthCount int64
- db.Model(&entity.DtUser{}).
- Where("parent_id = ? AND DATE_FORMAT(FROM_UNIXTIME(created_at), '%Y-%m') = ?", userId, month).
- Count(&monthCount)
- // 今日佣金
- var todayCommission float64
- db.Model(&entity.DtBalanceLog{}).
- Where("user_id = ? AND type = ? AND DATE(FROM_UNIXTIME(created_at)) = ?", userId, entity.BalanceLogTypeCommission, today).
- Select("COALESCE(SUM(amount), 0)").
- Scan(&todayCommission)
- ctx.OK(gin.H{
- "directInviteCount": user.DirectInviteCount,
- "teamCount": user.TeamCount,
- "todayNewCount": todayCount,
- "monthNewCount": monthCount,
- "todayCommission": todayCommission,
- "totalInviteIncome": user.TotalInviteIncome,
- "inviteCode": user.InviteCode,
- })
- }
- // TeamMembers 团队成员
- func (s *Server) TeamMembers(c *gin.Context) {
- ctx := s.FromContext(c)
- db := s.DB()
- userId := ctx.UserId()
- paging := &services.Pagination{
- Current: ctx.QueryInt64("current", 1),
- Size: ctx.QueryInt64("size", 20),
- }
- query := db.Model(&entity.DtUser{}).Where("parent_id = ?", userId)
- query.Count(&paging.Total)
- paging.Computer()
- type MemberInfo struct {
- Id int64 `json:"id"`
- Uid string `json:"uid"`
- Nickname string `json:"nickname"`
- Avatar string `json:"avatar"`
- Phone string `json:"phone"`
- CreatedAt int64 `json:"createdAt"`
- }
- members := make([]*MemberInfo, 0)
- query.Select("id, uid, nickname, avatar, CONCAT(LEFT(phone, 3), '****', RIGHT(phone, 4)) as phone, created_at").
- Order("created_at DESC").
- Offset(int(paging.Start)).
- Limit(int(paging.Size)).
- Scan(&members)
- ctx.OK(gin.H{
- "list": members,
- "paging": paging,
- })
- }
- // TeamIncome 团队收益
- func (s *Server) TeamIncome(c *gin.Context) {
- ctx := s.FromContext(c)
- db := s.DB()
- userId := ctx.UserId()
- // 今日返佣
- today := time.Now().Format("2006-01-02")
- var todayIncome float64
- db.Model(&entity.DtBalanceLog{}).
- Where("user_id = ? AND type = ? AND DATE(FROM_UNIXTIME(created_at)) = ?", userId, entity.BalanceLogTypeCommission, today).
- Select("COALESCE(SUM(amount), 0)").
- Scan(&todayIncome)
- // 本月返佣
- month := time.Now().Format("2006-01")
- var monthIncome float64
- db.Model(&entity.DtBalanceLog{}).
- Where("user_id = ? AND type = ? AND DATE_FORMAT(FROM_UNIXTIME(created_at), '%Y-%m') = ?", userId, entity.BalanceLogTypeCommission, month).
- Select("COALESCE(SUM(amount), 0)").
- Scan(&monthIncome)
- // 累计返佣
- var totalIncome float64
- db.Model(&entity.DtBalanceLog{}).
- Where("user_id = ? AND type = ?", userId, entity.BalanceLogTypeCommission).
- Select("COALESCE(SUM(amount), 0)").
- Scan(&totalIncome)
- // 返佣记录
- paging := &services.Pagination{
- Current: ctx.QueryInt64("current", 1),
- Size: ctx.QueryInt64("size", 20),
- }
- query := db.Model(&entity.DtBalanceLog{}).
- Where("user_id = ? AND type = ?", userId, entity.BalanceLogTypeCommission)
- query.Count(&paging.Total)
- paging.Computer()
- logs := make([]*entity.DtBalanceLog, 0)
- query.Order("created_at DESC").
- Offset(int(paging.Start)).
- Limit(int(paging.Size)).
- Find(&logs)
- ctx.OK(gin.H{
- "todayIncome": todayIncome,
- "monthIncome": monthIncome,
- "totalIncome": totalIncome,
- "list": logs,
- "paging": paging,
- })
- }
|