Compare commits

...

10 Commits

Author SHA1 Message Date
jiaji.H
c0bfd322a8 Merge branch 'feat-hjj-ExportManager' 2026-01-14 09:22:06 +08:00
jiaji.H
e9bef82968 Updata:更新sql 2026-01-14 09:21:51 +08:00
jiaji.H
aae7aa077b Updata:更新sql 2026-01-14 09:16:34 +08:00
jiaji.H
61e5a69484 Updata:更新sql 2026-01-14 09:12:17 +08:00
jiaji.H
0524d503f3 Updata:增加套餐过期过虑 2026-01-14 09:08:06 +08:00
jiaji.H
36a751b8ac Updata:解决冲突 2026-01-13 16:39:08 +08:00
jiaji.H
7f5384c935 fix:修正bug 2026-01-13 14:44:18 +08:00
jiaji.H
137e752c1b Updata:导出支持选择多个月份进行导出 2026-01-13 13:50:58 +08:00
JNG
8b85aeee28 11 2026-01-12 18:08:45 +08:00
JNG
bbe0c0390c 11 2026-01-12 14:36:20 +08:00
9 changed files with 2273 additions and 2128 deletions

View File

@ -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 {

View File

@ -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)
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 {
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())
}
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).
Select(`tiktok.platform_user_id as tiktok_account,
tiktok.platform_user_name as tiktok_nickname,
@ -1351,21 +1368,18 @@ func MetricsArtistAccountExport(req *bundle.MetricsArtistAccountExportReq) (*bun
cma.artist_name,
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_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 = 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_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_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_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_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 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 {
// 构建多个月份的时间范围参数
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 {
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`).
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")
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

View File

@ -539,6 +539,7 @@ func OrderRecordsListV2(req *bundle.OrderRecordsRequestV2) (res *bundle.OrderRec
Amount: record.Amount,
CustomerId: customerID,
PayTime: record.PayTime,
InviterId: record.InviterID,
}
// 聚合子订单

View File

@ -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

View File

@ -69,6 +69,7 @@ func CreateOrderRecord(req *bundle.OrderCreateRecord) (res *bundle.CommonRespons
Language: req.Language,
BundleOrderValueAdd: addRecords,
PlatformIds: req.PlatformIds,
InviterID: req.InviterId,
}
res, err = dao.CreateOrderRecord(orderRecord)
return

View File

@ -45,6 +45,7 @@ type BundleOrderRecords struct {
BundleOrderValueAdd []BundleOrderValueAdd `gorm:"foreignKey:OrderUUID;references:UUID" json:"bundleOrderValueAdd"`
ReSignature int `json:"reSignature" gorm:"column:re_signature;default:2;type:int;comment:是否重新签 1:是 2:否"`
PlatformIds PlatformIDs `gorm:"column:platform_ids;type:json;NOT NULL;comment:发布平台ID集合 TIKTOK= 1, YOUTUBE = 2, INS = 3 , DM = 4, BL = 5;" json:"platformIDs"`
InviterID uint64 `gorm:"column:inviter_id;type:bigint;comment:邀请人ID" json:"inviterID"`
}
type BundleOrderValueAdd struct {
gorm.Model

View File

@ -218,6 +218,7 @@ message OrderCreateRecord{
repeated OrderCreateAddRecord addRecords = 20 [json_name = "addRecords"]; //
string orderNo = 21 [json_name = "orderNo"];
repeated uint32 platformIds = 22; // ID集合 (json )
uint64 inviterId = 23; // ID
}
message OrderCreateAddRecord{
int32 serviceType = 1 [json_name = "serviceType"];
@ -270,6 +271,9 @@ message OrderBundleRecordInfo{
int64 customerId = 9;
string payTime = 10;
string subNum = 11;
uint64 inviterId = 12;
string inviterCode = 13;
string inviterName = 14;
}
message OrderAddBundleRecordInfo{
string orderAddNo = 1;
@ -727,7 +731,7 @@ message GetBundleBalanceListReq{
int64 expiredTimeEnd = 8;
int32 page = 9;
int32 pageSize = 10;
string month = 11;
repeated string month = 11;
int32 statusType = 12;
}
@ -911,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;
@ -1762,7 +1770,7 @@ message MetricsBundlePurchaseItem{
}
message MetricsArtistAccountExportReq{
string month = 1;
repeated string month = 1;
}
message MetricsArtistAccountExportResp{
@ -1792,7 +1800,7 @@ message MetricsArtistAccountExportItem{
message MetricsVideoSubmitExportReq{
string month = 1;
repeated string month = 1;
}
message MetricsVideoSubmitExportResp{

File diff suppressed because it is too large Load Diff

View File

@ -68,6 +68,11 @@ func loadMysqlConn(conn string) *gorm.DB {
fmt.Println(err)
}
}
if db.Migrator().HasColumn(&model.BundleOrderRecords{}, "inviter_id") == false {
if err := db.Migrator().AddColumn(&model.BundleOrderRecords{}, "inviter_id"); err != nil {
fmt.Println(err)
}
}
if err != nil {
// return nil
panic(err)