Updata:解决冲突
This commit is contained in:
commit
3abd57aa9a
@ -135,11 +135,11 @@ func GetBundleBalanceList(req *bundle.GetBundleBalanceListReq) (data []model.Bun
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if req.Month == "" {
|
if len(req.Month) == 0 {
|
||||||
newestMonthQuery := app.ModuleClients.BundleDB.Model(&model.BundleBalance{}).Select("max(month) as month,user_id").Group("user_id")
|
newestMonthQuery := app.ModuleClients.BundleDB.Model(&model.BundleBalance{}).Select("max(month) as month,user_id").Group("user_id")
|
||||||
session.Joins("LEFT JOIN (?) as newest_month on newest_month.user_id = bb.user_id", newestMonthQuery).Where("")
|
session.Joins("LEFT JOIN (?) as newest_month on newest_month.user_id = bb.user_id", newestMonthQuery).Where("")
|
||||||
} else {
|
} else {
|
||||||
session = session.Where("bb.month = ?", req.Month)
|
session = session.Where("bb.month in (?)", req.Month)
|
||||||
}
|
}
|
||||||
err = session.Count(&total).Error
|
err = session.Count(&total).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@ -6,6 +6,7 @@ import (
|
|||||||
"micro-bundle/internal/model"
|
"micro-bundle/internal/model"
|
||||||
"micro-bundle/pb/bundle"
|
"micro-bundle/pb/bundle"
|
||||||
"micro-bundle/pkg/app"
|
"micro-bundle/pkg/app"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/duke-git/lancet/v2/datetime"
|
"github.com/duke-git/lancet/v2/datetime"
|
||||||
@ -1316,22 +1317,38 @@ func MetricsArtistAccountExport(req *bundle.MetricsArtistAccountExportReq) (*bun
|
|||||||
var start time.Time
|
var start time.Time
|
||||||
var end time.Time
|
var end time.Time
|
||||||
var err error
|
var err error
|
||||||
if req.Month != "" {
|
|
||||||
t, err := time.Parse("2006-01", req.Month)
|
subQuery := app.ModuleClients.BundleDB.Table("cast_media_account").
|
||||||
|
Select("artist_uuid,any_value(artist_name) as artist_name,any_value(created_at) as created_at").
|
||||||
|
Group("artist_uuid").
|
||||||
|
Where("deleted_at = 0 and expired != 2")
|
||||||
|
//如果选择了月份
|
||||||
|
if len(req.Month) > 0 {
|
||||||
|
// 构建多个月份的时间范围条件(使用 OR 连接)
|
||||||
|
var conditions []string
|
||||||
|
var args []interface{}
|
||||||
|
for _, month := range req.Month {
|
||||||
|
t, err := time.Parse("2006-01", month)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
start = datetime.BeginOfMonth(t)
|
start = datetime.BeginOfMonth(t)
|
||||||
end = datetime.EndOfMonth(t)
|
end = datetime.EndOfMonth(t)
|
||||||
|
// 为每个月添加时间范围条件
|
||||||
|
conditions = append(conditions, "(created_at >= ? AND created_at <= ?)")
|
||||||
|
args = append(args, start.Unix(), end.Unix())
|
||||||
|
}
|
||||||
|
// 使用 OR 连接所有月份条件
|
||||||
|
if len(conditions) > 0 {
|
||||||
|
subQuery = subQuery.Where(strings.Join(conditions, " OR "), args...)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
start = time.Date(1970, 1, 1, 0, 0, 0, 0, time.UTC) // Unix 时间戳起始时间
|
start = time.Date(1970, 1, 1, 0, 0, 0, 0, time.UTC) // Unix 时间戳起始时间
|
||||||
end = time.Date(2099, 12, 31, 23, 59, 59, 0, time.UTC) // 设置一个很远的未来日期
|
end = time.Date(2099, 12, 31, 23, 59, 59, 0, time.UTC) // 设置一个很远的未来日期
|
||||||
|
subQuery = subQuery.Where("created_at >= ?", start.Unix()).
|
||||||
|
Where("created_at <= ?", end.Unix())
|
||||||
}
|
}
|
||||||
subQuery := app.ModuleClients.BundleDB.Table("cast_media_account").
|
|
||||||
Select("artist_uuid,any_value(artist_name) as artist_name,any_value(created_at) as created_at").
|
|
||||||
Group("artist_uuid").
|
|
||||||
Where("created_at >= ?", start.Unix()).Where("created_at <= ?", end.Unix()).
|
|
||||||
Where("deleted_at = 0")
|
|
||||||
query := app.ModuleClients.BundleDB.Table("( ? ) cma", subQuery).
|
query := app.ModuleClients.BundleDB.Table("( ? ) cma", subQuery).
|
||||||
Select(`tiktok.platform_user_id as tiktok_account,
|
Select(`tiktok.platform_user_id as tiktok_account,
|
||||||
tiktok.platform_user_name as tiktok_nickname,
|
tiktok.platform_user_name as tiktok_nickname,
|
||||||
@ -1351,21 +1368,18 @@ func MetricsArtistAccountExport(req *bundle.MetricsArtistAccountExportReq) (*bun
|
|||||||
cma.artist_name,
|
cma.artist_name,
|
||||||
bor.customer_num as user_num
|
bor.customer_num as user_num
|
||||||
`).
|
`).
|
||||||
Joins(`left join (SELECT * FROM cast_media_account where platform_id = 1 and deleted_at = 0) tiktok on tiktok.artist_uuid = cma.artist_uuid`).
|
Joins(`left join (SELECT * FROM cast_media_account where platform_id = 1 and deleted_at = 0 and expired != 2) tiktok on tiktok.artist_uuid = cma.artist_uuid`).
|
||||||
Joins(`left join (Select * from cast_media_auth where platform_id = 1 and deleted_at = 0 ) tiktok_auth on tiktok_auth.user_id = tiktok.user_id`).
|
Joins(`left join (Select * from cast_media_auth where platform_id = 1 and deleted_at = 0 ) tiktok_auth on tiktok_auth.user_id = tiktok.user_id`).
|
||||||
Joins(`left join (SELECT * FROM cast_media_account where platform_id = 4 and deleted_at = 0) dm on dm.artist_uuid = cma.artist_uuid`).
|
Joins(`left join (SELECT * FROM cast_media_account where platform_id = 4 and deleted_at = 0 and expired != 2) dm on dm.artist_uuid = cma.artist_uuid`).
|
||||||
Joins(`left join (Select * from cast_media_auth where platform_id = 4 and deleted_at = 0) dm_auth on dm_auth.user_id = dm.user_id`).
|
Joins(`left join (Select * from cast_media_auth where platform_id = 4 and deleted_at = 0) dm_auth on dm_auth.user_id = dm.user_id`).
|
||||||
Joins(`left join (SELECT * FROM cast_media_account where platform_id = 3 and deleted_at = 0) ins on ins.artist_uuid = cma.artist_uuid`).
|
Joins(`left join (SELECT * FROM cast_media_account where platform_id = 3 and deleted_at = 0 and expired != 2) ins on ins.artist_uuid = cma.artist_uuid`).
|
||||||
Joins(`left join (Select * from cast_media_auth where platform_id = 3 and deleted_at = 0) ins_auth on ins_auth.user_id = ins.user_id`).
|
Joins(`left join (Select * from cast_media_auth where platform_id = 3 and deleted_at = 0) ins_auth on ins_auth.user_id = ins.user_id`).
|
||||||
Joins(`left join (Select * from cast_media_account where platform_id = 2 and deleted_at = 0) youtube on youtube.artist_uuid = cma.artist_uuid`).
|
Joins(`left join (Select * from cast_media_account where platform_id = 2 and deleted_at = 0 and expired != 2) youtube on youtube.artist_uuid = cma.artist_uuid`).
|
||||||
Joins(`left join (Select * from cast_media_auth where platform_id = 2 and deleted_at = 0) youtube_auth on youtube_auth.user_id = youtube.user_id`).
|
Joins(`left join (Select * from cast_media_auth where platform_id = 2 and deleted_at = 0) youtube_auth on youtube_auth.user_id = youtube.user_id`).
|
||||||
Joins(`left join (Select * from cast_media_account where platform_id = 5 and deleted_at = 0) bluesky on bluesky.artist_uuid = cma.artist_uuid`).
|
Joins(`left join (Select * from cast_media_account where platform_id = 5 and deleted_at = 0 and expired != 2) bluesky on bluesky.artist_uuid = cma.artist_uuid`).
|
||||||
Joins(`left join (Select * from cast_media_auth where platform_id = 5 and deleted_at = 0) bluesky_auth on bluesky_auth.user_id = bluesky.user_id`).
|
Joins(`left join (Select * from cast_media_auth where platform_id = 5 and deleted_at = 0) bluesky_auth on bluesky_auth.user_id = bluesky.user_id`).
|
||||||
Joins(`left join bundle_order_records bor on bor.customer_id COLLATE utf8mb4_general_ci= cma.artist_uuid COLLATE utf8mb4_general_ci`).
|
Joins(`left join bundle_order_records bor on bor.customer_id COLLATE utf8mb4_general_ci= cma.artist_uuid COLLATE utf8mb4_general_ci`).
|
||||||
Where("bor.deleted_at is null")
|
Where("bor.deleted_at is null")
|
||||||
if req.Month != "" {
|
|
||||||
query = query.Where("cma.created_at >= ?", start.Unix()).Where("cma.created_at <= ?", end.Unix())
|
|
||||||
}
|
|
||||||
err = query.Find(&data.Data).Error
|
err = query.Find(&data.Data).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -1376,7 +1390,7 @@ func MetricsArtistAccountExport(req *bundle.MetricsArtistAccountExportReq) (*bun
|
|||||||
func MetricsVideoSubmitExport(req *bundle.MetricsVideoSubmitExportReq) (result *bundle.MetricsVideoSubmitExportResp, err error) {
|
func MetricsVideoSubmitExport(req *bundle.MetricsVideoSubmitExportReq) (result *bundle.MetricsVideoSubmitExportResp, err error) {
|
||||||
result = &bundle.MetricsVideoSubmitExportResp{}
|
result = &bundle.MetricsVideoSubmitExportResp{}
|
||||||
var query *gorm.DB
|
var query *gorm.DB
|
||||||
if req.Month == "" {
|
if len(req.Month) == 0 {
|
||||||
query = app.ModuleClients.BundleDB.Table("cast_work AS cw").
|
query = app.ModuleClients.BundleDB.Table("cast_work AS cw").
|
||||||
Select(`cw.artist_name ,
|
Select(`cw.artist_name ,
|
||||||
cw.title as video_title,
|
cw.title as video_title,
|
||||||
@ -1391,22 +1405,61 @@ func MetricsVideoSubmitExport(req *bundle.MetricsVideoSubmitExportReq) (result *
|
|||||||
Where("(tiktok.created_at is not null or dm.created_at is not null or ins.created_at is not null) and cw.deleted_at = 0 and bor.deleted_at is null and cw.origin_uuid = ''").
|
Where("(tiktok.created_at is not null or dm.created_at is not null or ins.created_at is not null) and cw.deleted_at = 0 and bor.deleted_at is null and cw.origin_uuid = ''").
|
||||||
Order("cw.artist_name")
|
Order("cw.artist_name")
|
||||||
} else {
|
} else {
|
||||||
|
// 构建多个月份的时间范围参数
|
||||||
|
var timeRanges []struct {
|
||||||
|
Start int64
|
||||||
|
End int64
|
||||||
|
}
|
||||||
|
|
||||||
t, err := time.Parse("2006-01", req.Month)
|
for _, month := range req.Month {
|
||||||
|
t, err := time.Parse("2006-01", month)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
start := datetime.BeginOfMonth(t)
|
start := datetime.BeginOfMonth(t)
|
||||||
end := datetime.EndOfMonth(t)
|
end := datetime.EndOfMonth(t)
|
||||||
|
timeRanges = append(timeRanges, struct {
|
||||||
|
Start int64
|
||||||
|
End int64
|
||||||
|
}{Start: start.Unix(), End: end.Unix()})
|
||||||
|
}
|
||||||
|
// 构建时间筛选 SQL 条件的辅助函数
|
||||||
|
buildTimeFilterSQL := func(tableAlias string) (string, []interface{}) {
|
||||||
|
if len(timeRanges) == 0 {
|
||||||
|
return "", nil
|
||||||
|
}
|
||||||
|
var conditions []string
|
||||||
|
var args []interface{}
|
||||||
|
for _, tr := range timeRanges {
|
||||||
|
// 明确指定表别名,避免字段歧义
|
||||||
|
conditions = append(conditions, fmt.Sprintf("(%s.created_at >= ? AND %s.created_at <= ?)", tableAlias, tableAlias))
|
||||||
|
args = append(args, tr.Start, tr.End)
|
||||||
|
}
|
||||||
|
return "(" + strings.Join(conditions, " OR ") + ")", args
|
||||||
|
}
|
||||||
query = app.ModuleClients.BundleDB.Table("cast_work AS cw").
|
query = app.ModuleClients.BundleDB.Table("cast_work AS cw").
|
||||||
Select(`cw.artist_name, cw.title AS video_title, tiktok.created_at AS tiktok_upload_time, dm.created_at AS dm_upload_time, ins.created_at AS instagram_upload_time, bor.customer_num AS user_num`).
|
Select(`cw.artist_name, cw.title AS video_title, tiktok.created_at AS tiktok_upload_time, dm.created_at AS dm_upload_time, ins.created_at AS instagram_upload_time, bor.customer_num AS user_num`)
|
||||||
Joins(`LEFT JOIN cast_work_platform_info tiktok ON tiktok.work_uuid = cw.uuid AND tiktok.platform_id = 1 AND tiktok.created_at >= ? AND tiktok.created_at <= ?`, start.Unix(), end.Unix()).
|
|
||||||
Joins(`LEFT JOIN cast_work_platform_info dm ON dm.work_uuid = cw.uuid AND dm.platform_id = 4 AND dm.created_at >= ? AND dm.created_at <= ?`, start.Unix(), end.Unix()).
|
|
||||||
Joins(`LEFT JOIN cast_work_platform_info ins ON ins.work_uuid = cw.uuid AND ins.platform_id = 3 AND ins.created_at >= ? AND ins.created_at <= ?`, start.Unix(), end.Unix()).
|
|
||||||
Joins(`LEFT JOIN bundle_order_records bor ON bor.customer_id COLLATE utf8mb4_general_ci = cw.artist_uuid COLLATE utf8mb4_general_ci AND bor.deleted_at IS NULL`).
|
|
||||||
Where(`cw.origin_uuid = '' and cw.deleted_at = 0 AND (tiktok.created_at IS NOT NULL OR dm.created_at IS NOT NULL OR ins.created_at IS NOT NULL)`).
|
|
||||||
Order("cw.artist_name")
|
|
||||||
|
|
||||||
|
// 为每个平台添加时间筛选条件
|
||||||
|
if len(timeRanges) > 0 {
|
||||||
|
// TikTok JOIN
|
||||||
|
tiktokTimeSQL, tiktokArgs := buildTimeFilterSQL("tiktok")
|
||||||
|
joinSQL := `LEFT JOIN cast_work_platform_info tiktok ON tiktok.work_uuid = cw.uuid AND tiktok.platform_id = 1 AND ` + tiktokTimeSQL
|
||||||
|
query = query.Joins(joinSQL, tiktokArgs...)
|
||||||
|
|
||||||
|
// DM JOIN
|
||||||
|
dmTimeSQL, dmArgs := buildTimeFilterSQL("dm")
|
||||||
|
joinSQL = `LEFT JOIN cast_work_platform_info dm ON dm.work_uuid = cw.uuid AND dm.platform_id = 4 AND ` + dmTimeSQL
|
||||||
|
query = query.Joins(joinSQL, dmArgs...)
|
||||||
|
|
||||||
|
// Instagram JOIN
|
||||||
|
insTimeSQL, insArgs := buildTimeFilterSQL("ins")
|
||||||
|
joinSQL = `LEFT JOIN cast_work_platform_info ins ON ins.work_uuid = cw.uuid AND ins.platform_id = 3 AND ` + insTimeSQL
|
||||||
|
query = query.Joins(joinSQL, insArgs...)
|
||||||
|
}
|
||||||
|
query = query.Joins(`LEFT JOIN bundle_order_records bor ON bor.customer_id COLLATE utf8mb4_general_ci = cw.artist_uuid COLLATE utf8mb4_general_ci AND bor.deleted_at IS NULL`).
|
||||||
|
Where(`cw.deleted_at = 0 AND (tiktok.created_at IS NOT NULL OR dm.created_at IS NOT NULL OR ins.created_at IS NOT NULL)`).
|
||||||
|
Order("cw.artist_name")
|
||||||
}
|
}
|
||||||
err = query.Find(&result.Data).Error
|
err = query.Find(&result.Data).Error
|
||||||
return
|
return
|
||||||
|
|||||||
@ -16,6 +16,7 @@ import (
|
|||||||
"dubbo.apache.org/dubbo-go/v3/common/logger"
|
"dubbo.apache.org/dubbo-go/v3/common/logger"
|
||||||
"github.com/jinzhu/copier"
|
"github.com/jinzhu/copier"
|
||||||
"github.com/samber/lo"
|
"github.com/samber/lo"
|
||||||
|
"github.com/shopspring/decimal"
|
||||||
)
|
)
|
||||||
|
|
||||||
func BundleExtend(req *bundle.BundleExtendRequest) (*bundle.BundleExtendResponse, error) {
|
func BundleExtend(req *bundle.BundleExtendRequest) (*bundle.BundleExtendResponse, error) {
|
||||||
@ -598,6 +599,14 @@ func BundleBalanceExport(req *bundle.BundleBalanceExportReq) (*bundle.BundleBala
|
|||||||
} else {
|
} else {
|
||||||
item.IncreaseVideoUnitPrice = float32(math.Round(float64(item.IncreaseAmount/float32(v.IncreaseVideoNumber))*100) / 100)
|
item.IncreaseVideoUnitPrice = float32(math.Round(float64(item.IncreaseAmount/float32(v.IncreaseVideoNumber))*100) / 100)
|
||||||
}
|
}
|
||||||
|
bundleUnitPrice := decimal.NewFromFloat32(item.BundleVideoUnitPrice)
|
||||||
|
increaseUnitPrice := decimal.NewFromFloat32(item.IncreaseVideoUnitPrice)
|
||||||
|
|
||||||
|
bundlePriceTotal := bundleUnitPrice.Mul(decimal.NewFromInt32(v.MonthBundleVideoConsumptionNumber))
|
||||||
|
increasePriceTotal := increaseUnitPrice.Mul(decimal.NewFromInt32(v.MonthIncreaseVideoConsumptionNumber))
|
||||||
|
|
||||||
|
item.MonthlyBundleVideoConsumptionPrice = bundlePriceTotal.StringFixed(2)
|
||||||
|
item.MonthlyIncreaseVideoConsumptionPrice = increasePriceTotal.StringFixed(2)
|
||||||
items = append(items, item)
|
items = append(items, item)
|
||||||
}
|
}
|
||||||
return &bundle.BundleBalanceExportResp{Total: int64(len(items)), Data: items}, nil
|
return &bundle.BundleBalanceExportResp{Total: int64(len(items)), Data: items}, nil
|
||||||
|
|||||||
@ -728,7 +728,7 @@ message GetBundleBalanceListReq{
|
|||||||
int64 expiredTimeEnd = 8;
|
int64 expiredTimeEnd = 8;
|
||||||
int32 page = 9;
|
int32 page = 9;
|
||||||
int32 pageSize = 10;
|
int32 pageSize = 10;
|
||||||
string month = 11;
|
repeated string month = 11;
|
||||||
int32 statusType = 12;
|
int32 statusType = 12;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -950,11 +950,15 @@ message BundleBalanceExportItem {
|
|||||||
int32 monthlyManualImageConsumptionNumber = 81; // 当月手动扩展图文使用数
|
int32 monthlyManualImageConsumptionNumber = 81; // 当月手动扩展图文使用数
|
||||||
int32 monthlyManualDataAnalysisConsumptionNumber = 82; // 当月手动扩展数据分析使用数
|
int32 monthlyManualDataAnalysisConsumptionNumber = 82; // 当月手动扩展数据分析使用数
|
||||||
int32 monthlyManualCompetitiveConsumptionNumber = 83; // 当月手动扩展竞品使用数
|
int32 monthlyManualCompetitiveConsumptionNumber = 83; // 当月手动扩展竞品使用数
|
||||||
|
|
||||||
|
//视频当月消耗金额
|
||||||
|
string monthlyBundleVideoConsumptionPrice = 84;//当月套餐消耗总金额
|
||||||
|
string monthlyIncreaseVideoConsumptionPrice = 85;//当月增值消耗总金额
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
message BundleBalanceExportReq{
|
message BundleBalanceExportReq{
|
||||||
string month = 1;
|
repeated string month = 1;
|
||||||
string userName = 2;
|
string userName = 2;
|
||||||
uint64 expiredTimeStart = 3;
|
uint64 expiredTimeStart = 3;
|
||||||
uint64 expiredTimeEnd = 4;
|
uint64 expiredTimeEnd = 4;
|
||||||
@ -1808,7 +1812,7 @@ message MetricsBundlePurchaseItem{
|
|||||||
}
|
}
|
||||||
|
|
||||||
message MetricsArtistAccountExportReq{
|
message MetricsArtistAccountExportReq{
|
||||||
string month = 1;
|
repeated string month = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
message MetricsArtistAccountExportResp{
|
message MetricsArtistAccountExportResp{
|
||||||
@ -1838,7 +1842,7 @@ message MetricsArtistAccountExportItem{
|
|||||||
|
|
||||||
|
|
||||||
message MetricsVideoSubmitExportReq{
|
message MetricsVideoSubmitExportReq{
|
||||||
string month = 1;
|
repeated string month = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
message MetricsVideoSubmitExportResp{
|
message MetricsVideoSubmitExportResp{
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user