Updata:解决冲突
This commit is contained in:
commit
36a751b8ac
@ -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")
|
||||
session.Joins("LEFT JOIN (?) as newest_month on newest_month.user_id = bb.user_id", newestMonthQuery).Where("")
|
||||
} else {
|
||||
session = session.Where("bb.month = ?", req.Month)
|
||||
session = session.Where("bb.month in (?)", req.Month)
|
||||
}
|
||||
err = session.Count(&total).Error
|
||||
if err != nil {
|
||||
|
||||
@ -6,6 +6,7 @@ import (
|
||||
"micro-bundle/internal/model"
|
||||
"micro-bundle/pb/bundle"
|
||||
"micro-bundle/pkg/app"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/duke-git/lancet/v2/datetime"
|
||||
@ -1316,22 +1317,38 @@ func MetricsArtistAccountExport(req *bundle.MetricsArtistAccountExportReq) (*bun
|
||||
var start time.Time
|
||||
var end time.Time
|
||||
var err error
|
||||
if req.Month != "" {
|
||||
t, err := time.Parse("2006-01", req.Month)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
start = datetime.BeginOfMonth(t)
|
||||
end = datetime.EndOfMonth(t)
|
||||
} else {
|
||||
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) // 设置一个很远的未来日期
|
||||
}
|
||||
|
||||
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")
|
||||
//如果选择了月份
|
||||
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 {
|
||||
return nil, err
|
||||
}
|
||||
start = datetime.BeginOfMonth(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 {
|
||||
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) // 设置一个很远的未来日期
|
||||
subQuery = subQuery.Where("created_at >= ?", start.Unix()).
|
||||
Where("created_at <= ?", end.Unix())
|
||||
}
|
||||
|
||||
query := app.ModuleClients.BundleDB.Table("( ? ) cma", subQuery).
|
||||
Select(`tiktok.platform_user_id as tiktok_account,
|
||||
tiktok.platform_user_name as tiktok_nickname,
|
||||
@ -1363,9 +1380,6 @@ func MetricsArtistAccountExport(req *bundle.MetricsArtistAccountExportReq) (*bun
|
||||
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`).
|
||||
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
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -1376,7 +1390,7 @@ func MetricsArtistAccountExport(req *bundle.MetricsArtistAccountExportReq) (*bun
|
||||
func MetricsVideoSubmitExport(req *bundle.MetricsVideoSubmitExportReq) (result *bundle.MetricsVideoSubmitExportResp, err error) {
|
||||
result = &bundle.MetricsVideoSubmitExportResp{}
|
||||
var query *gorm.DB
|
||||
if req.Month == "" {
|
||||
if len(req.Month) == 0 {
|
||||
query = app.ModuleClients.BundleDB.Table("cast_work AS cw").
|
||||
Select(`cw.artist_name ,
|
||||
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 = ''").
|
||||
Order("cw.artist_name")
|
||||
} else {
|
||||
|
||||
t, err := time.Parse("2006-01", req.Month)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
// 构建多个月份的时间范围参数
|
||||
var timeRanges []struct {
|
||||
Start int64
|
||||
End int64
|
||||
}
|
||||
start := datetime.BeginOfMonth(t)
|
||||
end := datetime.EndOfMonth(t)
|
||||
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`).
|
||||
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")
|
||||
|
||||
for _, month := range req.Month {
|
||||
t, err := time.Parse("2006-01", month)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
start := datetime.BeginOfMonth(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").
|
||||
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`)
|
||||
|
||||
// 为每个平台添加时间筛选条件
|
||||
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
|
||||
return
|
||||
|
||||
@ -16,6 +16,7 @@ import (
|
||||
"dubbo.apache.org/dubbo-go/v3/common/logger"
|
||||
"github.com/jinzhu/copier"
|
||||
"github.com/samber/lo"
|
||||
"github.com/shopspring/decimal"
|
||||
)
|
||||
|
||||
func BundleExtend(req *bundle.BundleExtendRequest) (*bundle.BundleExtendResponse, error) {
|
||||
@ -544,6 +545,14 @@ func BundleBalanceExport(req *bundle.BundleBalanceExportReq) (*bundle.BundleBala
|
||||
} else {
|
||||
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)
|
||||
}
|
||||
return &bundle.BundleBalanceExportResp{Total: int64(len(items)), Data: items}, nil
|
||||
|
||||
@ -731,7 +731,7 @@ message GetBundleBalanceListReq{
|
||||
int64 expiredTimeEnd = 8;
|
||||
int32 page = 9;
|
||||
int32 pageSize = 10;
|
||||
string month = 11;
|
||||
repeated string month = 11;
|
||||
int32 statusType = 12;
|
||||
}
|
||||
|
||||
@ -915,11 +915,15 @@ message BundleBalanceExportItem {
|
||||
int32 monthlyManualVideoConsumptionNumber = 65; // 当月手动扩展视频使用数
|
||||
int32 monthlyManualImageConsumptionNumber = 66; // 当月手动扩展图文使用数
|
||||
int32 monthlyManualDataAnalysisConsumptionNumber = 67; // 当月手动扩展数据分析使用数
|
||||
|
||||
//视频当月消耗金额
|
||||
string monthlyBundleVideoConsumptionPrice = 68;//当月套餐消耗总金额
|
||||
string monthlyIncreaseVideoConsumptionPrice = 69;//当月增值消耗总金额
|
||||
}
|
||||
|
||||
|
||||
message BundleBalanceExportReq{
|
||||
string month = 1;
|
||||
repeated string month = 1;
|
||||
string userName = 2;
|
||||
uint64 expiredTimeStart = 3;
|
||||
uint64 expiredTimeEnd = 4;
|
||||
@ -1766,7 +1770,7 @@ message MetricsBundlePurchaseItem{
|
||||
}
|
||||
|
||||
message MetricsArtistAccountExportReq{
|
||||
string month = 1;
|
||||
repeated string month = 1;
|
||||
}
|
||||
|
||||
message MetricsArtistAccountExportResp{
|
||||
@ -1796,7 +1800,7 @@ message MetricsArtistAccountExportItem{
|
||||
|
||||
|
||||
message MetricsVideoSubmitExportReq{
|
||||
string month = 1;
|
||||
repeated string month = 1;
|
||||
}
|
||||
|
||||
message MetricsVideoSubmitExportResp{
|
||||
|
||||
11278
pb/bundle/bundle.pb.go
11278
pb/bundle/bundle.pb.go
File diff suppressed because it is too large
Load Diff
@ -1,7 +1,7 @@
|
||||
// Code generated by protoc-gen-go-triple. DO NOT EDIT.
|
||||
// versions:
|
||||
// - protoc-gen-go-triple v1.0.5
|
||||
// - protoc v6.32.0
|
||||
// - protoc v5.26.0
|
||||
// source: pb/bundle.proto
|
||||
|
||||
package bundle
|
||||
|
||||
Loading…
Reference in New Issue
Block a user