You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

196 lines
4.8 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package user
import (
"recook/internal/dbc"
user3 "recook/internal/model/user"
"recook/internal/v2/lib/back"
"recook/internal/v2/lib/common"
"recook/internal/v2/logic/app/user"
"recook/internal/v2/model/http/profile"
"recook/tools"
"time"
"github.com/gin-gonic/gin"
"github.com/golangkit/formatime"
"github.com/shopspring/decimal"
)
type Income struct {
}
type argsMonthIncome struct {
Year int `json:"year" form:"year"`
}
// PurchaseAccumulate @Style 累计自购收益
func (i *Income) PurchaseAccumulate(c *gin.Context) {
userId, _ := common.GetAppUserId(c)
accumulate := user.IncomeLogic.PurchaseAccumulate(userId)
back.Suc(c, "获取成功", accumulate)
}
// GuideAccumulate @Style 累计导购收益
func (i *Income) GuideAccumulate(c *gin.Context) {
userId, _ := common.GetAppUserId(c)
accumulate := user.IncomeLogic.GuideAccumulate(userId)
back.Suc(c, "获取成功", accumulate)
}
func (i *Income) Profit(c *gin.Context) {
userId, _ := common.GetAppUserId(c)
res := user.IncomeLogic.Profit(userId)
back.Suc(c, "获取成功", res)
}
func (i *Income) ProfitCard(c *gin.Context) {
userId, _ := common.GetAppUserId(c)
var args user.EntryDate
if err := tools.ParseParams(&args, c); err != nil {
back.Fail(c, err.Error())
return
}
args.UserID = userId
res := user.IncomeLogic.ProfitCard(args)
back.Suc(c, "获取成功", res)
}
func (i *Income) Team(c *gin.Context) {
args := keyword{}
if err := tools.ParseParams(&args, c); err != nil {
back.Fail(c, err.Error())
return
}
userId, _ := common.GetAppUserId(c)
res := user.IncomeLogic.Team(userId, args.Keyword)
back.Suc(c, "获取成功", res)
}
type argsDayIncome struct {
Month string `json:"month" form:"month"`
}
type argsMonth struct {
Month string `json:"month" form:"month"`
}
type argsDayIncomes struct {
Day string `json:"day" form:"day"`
}
type respIncomeHistory struct {
Total decimal.Decimal `json:"total"`
Purchase decimal.Decimal `json:"purchase"`
Guide decimal.Decimal `json:"guide"`
Team decimal.Decimal `json:"team"`
}
// @Style 历史收益数据
func (i *Income) History(c *gin.Context) {
userId, _ := common.GetAppUserId(c)
// --- 获取用户信息
var userInfo user3.Information
if err := dbc.DB.Find(&userInfo, userId).Error; err != nil {
return
}
// --- 角色信息
// --- 累计收益
var accAll decimal.Decimal
var accSelfShopping decimal.Decimal
var accShare decimal.Decimal
//var accTeam decimal.Decimal
var coinHis []user3.CoinHistory
dbc.DB.Where("user_id = ? and coin_type in (1,2,3) and created_at < ?", userId, time.Date(2021, 3, 31, 23, 59, 59, 0, time.Local)).Find(&coinHis)
for _, val := range coinHis {
accAll = accAll.Add(val.CoinNum)
switch val.CoinType {
case user3.RoleTypeForCoinHistory:
accShare = accShare.Add(val.CoinNum)
//case user3.TeamTypeForCoinHistory:
// accTeam = accTeam.Add(val.CoinNum)
case user3.SelfShoppingTypeForCoinHistory:
accSelfShopping = accSelfShopping.Add(val.CoinNum)
}
}
back.Suc(c, "操作成功", respIncomeHistory{
Total: accAll, // 总的累计收益
Purchase: accSelfShopping, // 自购省钱
Guide: accShare, // 分享即下级第一笔shopping role
})
}
// IncomeNotRecvDetail 未到账收益.
func (i *Income) IncomeNotRecvDetail(c *gin.Context) {
uid, _ := common.GetAppUserId(c)
var args profile.IncomeDetailReq
if err := tools.ParseParams(&args, c); err != nil {
back.Fail(c, err.Error())
return
}
args.UID = uid
switch len(args.DateStr) {
case 4:
args.DateType = profile.YearType
case 6:
args.DateType = profile.MonthType
}
format := args.DateType.GetFormat()
if t, err := time.ParseInLocation(format, args.DateStr, time.Local); err != nil {
back.Fail(c, err.Error())
return
} else {
args.Date = formatime.NewDateFrom(t)
}
var result profile.IncomeDetail
switch args.DateType {
case profile.MonthType:
result = user.IncomeLogic.IncomeDetailOfMonthNotRecv(&args)
case profile.YearType:
result = user.IncomeLogic.IncomeDetailOfYearNotRecv(&args)
}
back.Suc(c, "操作成功", result)
}
// 自购已经到账收益
func (i *Income) IncomeDetail(c *gin.Context) {
uid, _ := common.GetAppUserId(c)
var args profile.IncomeDetailReq
if err := tools.ParseParams(&args, c); err != nil {
back.Fail(c, err.Error())
return
}
args.UID = uid
switch len(args.DateStr) {
case 4:
args.DateType = profile.YearType
case 6:
args.DateType = profile.MonthType
}
format := args.DateType.GetFormat()
if t, err := time.ParseInLocation(format, args.DateStr, time.Local); err != nil {
back.Fail(c, err.Error())
return
} else {
args.Date = formatime.NewDateFrom(t)
}
var result profile.IncomeDetail
switch args.DateType {
case profile.MonthType:
result = user.IncomeLogic.IncomeDetailOfMonth(&args)
case profile.YearType:
result = user.IncomeLogic.IncomeDetailOfYear(&args)
}
back.Suc(c, "操作成功", result)
}