拆分模块
This commit is contained in:
parent
5f2c9f0f64
commit
c8a129d34e
@ -33,15 +33,3 @@ func (b *BundleProvider) ValueAddServiceList(_ context.Context, req *bundle.Valu
|
||||
func (b *BundleProvider) ValueAddServiceDetail(_ context.Context, req *bundle.ValueAddServiceDetailRequest) (res *bundle.ValueAddServiceDetailResponse, err error) {
|
||||
return logic.ValueAddServiceDetail(req)
|
||||
}
|
||||
|
||||
func (b *BundleProvider) BundleExtend(_ context.Context, req *bundle.BundleExtendRequest) (*bundle.BundleExtendResponse, error) {
|
||||
return logic.BundleExtend(req)
|
||||
}
|
||||
|
||||
func (b *BundleProvider) BundleExtendRecordsList(_ context.Context, req *bundle.BundleExtendRecordsListRequest) (*bundle.BundleExtendRecordsListResponse, error) {
|
||||
return logic.BundleExtendRecordsList(req)
|
||||
}
|
||||
|
||||
func (b *BundleProvider) GetBundleBalance(_ context.Context, req *bundle.GetBundleBalanceReq) (*bundle.GetBundleBalanceResp, error) {
|
||||
return logic.GetBundleBalance(req)
|
||||
}
|
||||
|
19
internal/controller/bundle_extend.go
Normal file
19
internal/controller/bundle_extend.go
Normal file
@ -0,0 +1,19 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"context"
|
||||
"micro-bundle/internal/logic"
|
||||
"micro-bundle/pb/bundle"
|
||||
)
|
||||
|
||||
func (b *BundleProvider) BundleExtend(_ context.Context, req *bundle.BundleExtendRequest) (*bundle.BundleExtendResponse, error) {
|
||||
return logic.BundleExtend(req)
|
||||
}
|
||||
|
||||
func (b *BundleProvider) BundleExtendRecordsList(_ context.Context, req *bundle.BundleExtendRecordsListRequest) (*bundle.BundleExtendRecordsListResponse, error) {
|
||||
return logic.BundleExtendRecordsList(req)
|
||||
}
|
||||
|
||||
func (b *BundleProvider) GetBundleBalance(_ context.Context, req *bundle.GetBundleBalanceReq) (*bundle.GetBundleBalanceResp, error) {
|
||||
return logic.GetBundleBalance(req)
|
||||
}
|
@ -8,8 +8,6 @@ import (
|
||||
"micro-bundle/pkg/app"
|
||||
commonErr "micro-bundle/pkg/err"
|
||||
"micro-bundle/pkg/msg"
|
||||
"micro-bundle/pkg/utils"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
@ -387,201 +385,3 @@ func GetBundleLangsByUuid(uuid string) ([]*model.BundleProfileLang, error) {
|
||||
Find(&result).Error
|
||||
return result, err
|
||||
}
|
||||
|
||||
func AddBundleExtendRecord(data model.BundleExtensionRecords) error {
|
||||
return app.ModuleClients.BundleDB.Create(&data).Error
|
||||
}
|
||||
|
||||
func GetBundleExtendRecordList(req *bundle.BundleExtendRecordsListRequest) (data []model.BundleExtendRecordItemPo, total int64, err error) {
|
||||
var berConditions []string
|
||||
var berArgs []any
|
||||
var bovaConditions []string
|
||||
var bovaArgs []any
|
||||
// 动态条件拼接示例
|
||||
if req.User != "" {
|
||||
if utils.IsPhoneNumber(req.User) {
|
||||
berConditions = append(berConditions, "u.tel_num = ?")
|
||||
berArgs = append(berArgs, req.User)
|
||||
} else {
|
||||
berConditions = append(berConditions, "u.nickname LIKE ?")
|
||||
berArgs = append(berArgs, "%"+req.User+"%")
|
||||
}
|
||||
}
|
||||
if req.Operator != "" {
|
||||
if utils.IsPhoneNumber(req.Operator) {
|
||||
berConditions = append(berConditions, "operator_phone_number = ?")
|
||||
berArgs = append(berArgs, "%"+req.User+"%")
|
||||
} else {
|
||||
berConditions = append(berConditions, "operator_name LIKE ?")
|
||||
berArgs = append(berArgs, "%"+req.User+"%")
|
||||
}
|
||||
}
|
||||
if req.Type != 0 {
|
||||
switch req.Type {
|
||||
case 1: // 手动创建
|
||||
{
|
||||
bovaConditions = append(berConditions, "bova_uuid IS NULL")
|
||||
}
|
||||
case 2: // 自行购买
|
||||
{
|
||||
berConditions = append(berConditions, "operator_name IS NULL")
|
||||
}
|
||||
}
|
||||
}
|
||||
if req.AssociatedOrderNumber != "" {
|
||||
bovaConditions = append(bovaConditions, "order_uuid LIKE ?")
|
||||
bovaArgs = append(bovaArgs, "%"+req.AssociatedOrderNumber+"%")
|
||||
}
|
||||
if req.StartTime != 0 {
|
||||
berConditions = append(berConditions, "ber.created_at >= ?")
|
||||
berArgs = append(berArgs, time.UnixMilli(int64(req.StartTime)))
|
||||
bovaConditions = append(bovaConditions, "bova.created_at >= ?")
|
||||
bovaArgs = append(bovaArgs, time.UnixMilli(int64(req.StartTime)))
|
||||
}
|
||||
if req.EndTime != 0 {
|
||||
berConditions = append(berConditions, "ber.created_at <= ?")
|
||||
berArgs = append(berArgs, time.UnixMilli(int64(req.EndTime)))
|
||||
bovaConditions = append(bovaConditions, "bova.created_at <= ?")
|
||||
bovaArgs = append(bovaArgs, time.UnixMilli(int64(req.EndTime)))
|
||||
}
|
||||
berCWhereClause := ""
|
||||
if len(berConditions) > 0 {
|
||||
berCWhereClause = " WHERE " + strings.Join(berConditions, " AND ")
|
||||
}
|
||||
bovaCWhereClause := ""
|
||||
if len(berConditions) > 0 {
|
||||
bovaCWhereClause = " WHERE " + strings.Join(bovaConditions, " AND ")
|
||||
}
|
||||
// 拼接数据查询SQL
|
||||
sql := `
|
||||
SELECT
|
||||
u.nickname AS user_name,
|
||||
u.tel_num AS user_phone_number,
|
||||
bova.num AS service_num,
|
||||
bova.service_type AS service_type,
|
||||
bova.order_uuid,
|
||||
bova.uuid AS bova_uuid,
|
||||
NULL AS account_additional,
|
||||
NULL AS images_additional,
|
||||
NULL AS data_additional,
|
||||
NULL AS video_additional,
|
||||
NULL AS operator_name,
|
||||
NULL AS operator_phone_number,
|
||||
bova.created_at as created_at
|
||||
FROM
|
||||
fiee_bundle.bundle_order_value_add AS bova
|
||||
LEFT JOIN ` + "`micro-account`.`user`" + ` u ON u.id = bova.customer_id
|
||||
` + bovaCWhereClause + `
|
||||
UNION ALL
|
||||
|
||||
SELECT
|
||||
u.nickname AS user_name,
|
||||
u.tel_num AS user_phone_number,
|
||||
NULL AS service_num,
|
||||
NULL AS service_type,
|
||||
NULL AS order_uuid,
|
||||
NULL AS bova_uuid,
|
||||
ber.account_additional,
|
||||
ber.images_additional,
|
||||
ber.data_additional,
|
||||
ber.video_additional,
|
||||
ber.operator_name,
|
||||
ber.operator_phone_number,
|
||||
ber.created_at as created_at
|
||||
FROM
|
||||
fiee_bundle.bundle_extension_records ber
|
||||
LEFT JOIN ` + "`micro-account`.`user`" + ` u ON u.id = ber.user_id
|
||||
` + berCWhereClause + `
|
||||
ORDER BY created_at DESC
|
||||
LIMIT ? OFFSET ?;
|
||||
`
|
||||
|
||||
// 拼接总数查询SQL
|
||||
countSql := `
|
||||
SELECT COUNT(*) AS total_count FROM (
|
||||
SELECT bova.created_at as created_at
|
||||
FROM fiee_bundle.bundle_order_value_add AS bova
|
||||
LEFT JOIN ` + "`micro-account`.`user`" + ` u ON u.id = bova.customer_id
|
||||
` + bovaCWhereClause + `
|
||||
UNION ALL
|
||||
SELECT ber.created_at as created_at
|
||||
FROM fiee_bundle.bundle_extension_records ber
|
||||
LEFT JOIN ` + "`micro-account`.`user`" + ` u ON u.id = ber.user_id
|
||||
` + berCWhereClause + `
|
||||
) AS total_table;
|
||||
`
|
||||
|
||||
if req.Page == 0 {
|
||||
req.Page = 1
|
||||
}
|
||||
if req.PageSize == 0 {
|
||||
req.PageSize = 100
|
||||
}
|
||||
offset := (req.Page - 1) * req.PageSize
|
||||
|
||||
// 查询总数
|
||||
err = app.ModuleClients.BundleDB.Raw(countSql, append(bovaArgs, berArgs...)...).Scan(&total).Error
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
// 查询数据
|
||||
argsWithPage := append(append(bovaArgs, berArgs...), req.PageSize, offset)
|
||||
err = app.ModuleClients.BundleDB.Raw(sql, argsWithPage...).Scan(&data).Error
|
||||
return
|
||||
}
|
||||
|
||||
func GetBundleBalance(req *bundle.GetBundleBalanceReq) (data []model.BundleBalancePo, total int64, err error) {
|
||||
subQuery := app.ModuleClients.BundleDB.Table("fiee_bundle.bundle_order_records").
|
||||
Select("customer_id, MAX(created_at) as max_created_at").
|
||||
Group("customer_id")
|
||||
err = subQuery.Count(&total).Error
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if req.PageSize != 0 && req.Page != 0 {
|
||||
subQuery = subQuery.Limit(int(req.PageSize)).Offset(int(req.Page-1) * int(req.PageSize))
|
||||
}
|
||||
session := app.ModuleClients.BundleDB.Table("fiee_bundle.bundle_order_records AS bor").
|
||||
Select(`
|
||||
bor.customer_id as user_id,
|
||||
u.nickname as user_name,
|
||||
u.tel_num as user_phone_number,
|
||||
bor.bundle_name as bundle_name,
|
||||
bor.expiration_time as expiration_time,
|
||||
bor.status as bundle_status,
|
||||
bova.num as service_num,
|
||||
bova.service_type as service_type,
|
||||
cw.work_category as work_category,
|
||||
cw.uuid as cw_uuid,
|
||||
bova.uuid as bova_uuid,
|
||||
cma.user_id as cma_uuid,
|
||||
ber.id as ber_id,
|
||||
bova.source as oder_source,
|
||||
ber.account_additional,
|
||||
ber.images_additional,
|
||||
ber.data_additional,
|
||||
ber.video_additional
|
||||
`).
|
||||
Joins("JOIN (?) t ON bor.customer_id = t.customer_id AND bor.created_at = t.max_created_at", subQuery).
|
||||
Joins("LEFT JOIN fiee_bundle.bundle_order_value_add bova ON bova.order_uuid = bor.uuid").
|
||||
Joins("LEFT JOIN fiee_bundle.cast_work cw ON cw.artist_uuid = bor.customer_id AND cw.created_at > UNIX_TIMESTAMP(bor.created_at)").
|
||||
Joins("LEFT JOIN `micro-account`.`user` u ON u.id = bor.customer_id").
|
||||
Joins("LEFT JOIN fiee_bundle.cast_media_account cma ON cma.artist_uuid = u.id").
|
||||
Joins("LEFT JOIN fiee_bundle.bundle_extension_records ber ON ber.user_id = bor.customer_id").
|
||||
Where("bor.customer_id != ?", "")
|
||||
if req.BundleName != "" {
|
||||
session.Where("bor.bundle_name like ?", "%"+req.BundleName+"%")
|
||||
}
|
||||
if req.UserName != "" {
|
||||
session.Where("u.nickname like ?", "%"+req.UserName+"%")
|
||||
}
|
||||
if req.ExpiredTimeStart != 0 {
|
||||
session.Where("bor.expiration_time >= ?", req.ExpiredTimeStart)
|
||||
}
|
||||
if req.ExpiredTimeEnd != 0 {
|
||||
session.Where("bor.expiration_time <= ?", req.ExpiredTimeEnd)
|
||||
}
|
||||
err = session.Scan(&data).Error
|
||||
return
|
||||
}
|
||||
|
208
internal/dao/bundleExtend.go
Normal file
208
internal/dao/bundleExtend.go
Normal file
@ -0,0 +1,208 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"micro-bundle/internal/model"
|
||||
"micro-bundle/pb/bundle"
|
||||
"micro-bundle/pkg/app"
|
||||
"micro-bundle/pkg/utils"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
func AddBundleExtendRecord(data model.BundleExtensionRecords) error {
|
||||
return app.ModuleClients.BundleDB.Create(&data).Error
|
||||
}
|
||||
|
||||
func GetBundleExtendRecordList(req *bundle.BundleExtendRecordsListRequest) (data []model.BundleExtendRecordItemPo, total int64, err error) {
|
||||
var berConditions []string
|
||||
var berArgs []any
|
||||
var bovaConditions []string
|
||||
var bovaArgs []any
|
||||
// 动态条件拼接示例
|
||||
if req.User != "" {
|
||||
if utils.IsPhoneNumber(req.User) {
|
||||
berConditions = append(berConditions, "u.tel_num = ?")
|
||||
berArgs = append(berArgs, req.User)
|
||||
} else {
|
||||
berConditions = append(berConditions, "u.nickname LIKE ?")
|
||||
berArgs = append(berArgs, "%"+req.User+"%")
|
||||
}
|
||||
}
|
||||
if req.Operator != "" {
|
||||
if utils.IsPhoneNumber(req.Operator) {
|
||||
berConditions = append(berConditions, "operator_phone_number = ?")
|
||||
berArgs = append(berArgs, "%"+req.User+"%")
|
||||
} else {
|
||||
berConditions = append(berConditions, "operator_name LIKE ?")
|
||||
berArgs = append(berArgs, "%"+req.User+"%")
|
||||
}
|
||||
}
|
||||
if req.Type != 0 {
|
||||
switch req.Type {
|
||||
case 1: // 手动创建
|
||||
{
|
||||
bovaConditions = append(berConditions, "bova_uuid IS NULL")
|
||||
}
|
||||
case 2: // 自行购买
|
||||
{
|
||||
berConditions = append(berConditions, "operator_name IS NULL")
|
||||
}
|
||||
}
|
||||
}
|
||||
if req.AssociatedOrderNumber != "" {
|
||||
bovaConditions = append(bovaConditions, "order_uuid LIKE ?")
|
||||
bovaArgs = append(bovaArgs, "%"+req.AssociatedOrderNumber+"%")
|
||||
}
|
||||
if req.StartTime != 0 {
|
||||
berConditions = append(berConditions, "ber.created_at >= ?")
|
||||
berArgs = append(berArgs, time.UnixMilli(int64(req.StartTime)))
|
||||
bovaConditions = append(bovaConditions, "bova.created_at >= ?")
|
||||
bovaArgs = append(bovaArgs, time.UnixMilli(int64(req.StartTime)))
|
||||
}
|
||||
if req.EndTime != 0 {
|
||||
berConditions = append(berConditions, "ber.created_at <= ?")
|
||||
berArgs = append(berArgs, time.UnixMilli(int64(req.EndTime)))
|
||||
bovaConditions = append(bovaConditions, "bova.created_at <= ?")
|
||||
bovaArgs = append(bovaArgs, time.UnixMilli(int64(req.EndTime)))
|
||||
}
|
||||
berCWhereClause := ""
|
||||
if len(berConditions) > 0 {
|
||||
berCWhereClause = " WHERE " + strings.Join(berConditions, " AND ")
|
||||
}
|
||||
bovaCWhereClause := ""
|
||||
if len(berConditions) > 0 {
|
||||
bovaCWhereClause = " WHERE " + strings.Join(bovaConditions, " AND ")
|
||||
}
|
||||
// 拼接数据查询SQL
|
||||
sql := `
|
||||
SELECT
|
||||
u.nickname AS user_name,
|
||||
u.tel_num AS user_phone_number,
|
||||
bova.num AS service_num,
|
||||
bova.service_type AS service_type,
|
||||
bova.order_uuid,
|
||||
bova.uuid AS bova_uuid,
|
||||
NULL AS account_additional,
|
||||
NULL AS images_additional,
|
||||
NULL AS data_additional,
|
||||
NULL AS video_additional,
|
||||
NULL AS operator_name,
|
||||
NULL AS operator_phone_number,
|
||||
bova.created_at as created_at
|
||||
FROM
|
||||
fiee_bundle.bundle_order_value_add AS bova
|
||||
LEFT JOIN ` + "`micro-account`.`user`" + ` u ON u.id = bova.customer_id
|
||||
` + bovaCWhereClause + `
|
||||
UNION ALL
|
||||
|
||||
SELECT
|
||||
u.nickname AS user_name,
|
||||
u.tel_num AS user_phone_number,
|
||||
NULL AS service_num,
|
||||
NULL AS service_type,
|
||||
NULL AS order_uuid,
|
||||
NULL AS bova_uuid,
|
||||
ber.account_additional,
|
||||
ber.images_additional,
|
||||
ber.data_additional,
|
||||
ber.video_additional,
|
||||
ber.operator_name,
|
||||
ber.operator_phone_number,
|
||||
ber.created_at as created_at
|
||||
FROM
|
||||
fiee_bundle.bundle_extension_records ber
|
||||
LEFT JOIN ` + "`micro-account`.`user`" + ` u ON u.id = ber.user_id
|
||||
` + berCWhereClause + `
|
||||
ORDER BY created_at DESC
|
||||
LIMIT ? OFFSET ?;
|
||||
`
|
||||
|
||||
// 拼接总数查询SQL
|
||||
countSql := `
|
||||
SELECT COUNT(*) AS total_count FROM (
|
||||
SELECT bova.created_at as created_at
|
||||
FROM fiee_bundle.bundle_order_value_add AS bova
|
||||
LEFT JOIN ` + "`micro-account`.`user`" + ` u ON u.id = bova.customer_id
|
||||
` + bovaCWhereClause + `
|
||||
UNION ALL
|
||||
SELECT ber.created_at as created_at
|
||||
FROM fiee_bundle.bundle_extension_records ber
|
||||
LEFT JOIN ` + "`micro-account`.`user`" + ` u ON u.id = ber.user_id
|
||||
` + berCWhereClause + `
|
||||
) AS total_table;
|
||||
`
|
||||
|
||||
if req.Page == 0 {
|
||||
req.Page = 1
|
||||
}
|
||||
if req.PageSize == 0 {
|
||||
req.PageSize = 100
|
||||
}
|
||||
offset := (req.Page - 1) * req.PageSize
|
||||
|
||||
// 查询总数
|
||||
err = app.ModuleClients.BundleDB.Raw(countSql, append(bovaArgs, berArgs...)...).Scan(&total).Error
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
// 查询数据
|
||||
argsWithPage := append(append(bovaArgs, berArgs...), req.PageSize, offset)
|
||||
err = app.ModuleClients.BundleDB.Raw(sql, argsWithPage...).Scan(&data).Error
|
||||
return
|
||||
}
|
||||
|
||||
func GetBundleBalance(req *bundle.GetBundleBalanceReq) (data []model.BundleBalancePo, total int64, err error) {
|
||||
subQuery := app.ModuleClients.BundleDB.Table("fiee_bundle.bundle_order_records").
|
||||
Select("customer_id, MAX(created_at) as max_created_at").
|
||||
Group("customer_id")
|
||||
err = subQuery.Count(&total).Error
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if req.PageSize != 0 && req.Page != 0 {
|
||||
subQuery = subQuery.Limit(int(req.PageSize)).Offset(int(req.Page-1) * int(req.PageSize))
|
||||
}
|
||||
session := app.ModuleClients.BundleDB.Table("fiee_bundle.bundle_order_records AS bor").
|
||||
Select(`
|
||||
bor.customer_id as user_id,
|
||||
u.nickname as user_name,
|
||||
u.tel_num as user_phone_number,
|
||||
bor.bundle_name as bundle_name,
|
||||
bor.expiration_time as expiration_time,
|
||||
bor.status as bundle_status,
|
||||
bova.num as service_num,
|
||||
bova.service_type as service_type,
|
||||
cw.work_category as work_category,
|
||||
cw.uuid as cw_uuid,
|
||||
bova.uuid as bova_uuid,
|
||||
cma.user_id as cma_uuid,
|
||||
ber.id as ber_id,
|
||||
bova.source as oder_source,
|
||||
ber.account_additional,
|
||||
ber.images_additional,
|
||||
ber.data_additional,
|
||||
ber.video_additional
|
||||
`).
|
||||
Joins("JOIN (?) t ON bor.customer_id = t.customer_id AND bor.created_at = t.max_created_at", subQuery).
|
||||
Joins("LEFT JOIN fiee_bundle.bundle_order_value_add bova ON bova.order_uuid = bor.uuid").
|
||||
Joins("LEFT JOIN fiee_bundle.cast_work cw ON cw.artist_uuid = bor.customer_id AND cw.created_at > UNIX_TIMESTAMP(bor.created_at)").
|
||||
Joins("LEFT JOIN `micro-account`.`user` u ON u.id = bor.customer_id").
|
||||
Joins("LEFT JOIN fiee_bundle.cast_media_account cma ON cma.artist_uuid = u.id").
|
||||
Joins("LEFT JOIN fiee_bundle.bundle_extension_records ber ON ber.user_id = bor.customer_id").
|
||||
Where("bor.customer_id != ?", "")
|
||||
if req.BundleName != "" {
|
||||
session.Where("bor.bundle_name like ?", "%"+req.BundleName+"%")
|
||||
}
|
||||
if req.UserName != "" {
|
||||
session.Where("u.nickname like ?", "%"+req.UserName+"%")
|
||||
}
|
||||
if req.ExpiredTimeStart != 0 {
|
||||
session.Where("bor.expiration_time >= ?", req.ExpiredTimeStart)
|
||||
}
|
||||
if req.ExpiredTimeEnd != 0 {
|
||||
session.Where("bor.expiration_time <= ?", req.ExpiredTimeEnd)
|
||||
}
|
||||
err = session.Scan(&data).Error
|
||||
return
|
||||
}
|
182
internal/logic/bundleExtendLogic.go
Normal file
182
internal/logic/bundleExtendLogic.go
Normal file
@ -0,0 +1,182 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"micro-bundle/internal/dao"
|
||||
"micro-bundle/internal/model"
|
||||
"micro-bundle/pb/bundle"
|
||||
"time"
|
||||
|
||||
"github.com/dubbogo/gost/log/logger"
|
||||
"github.com/jinzhu/copier"
|
||||
"github.com/samber/lo"
|
||||
)
|
||||
|
||||
func BundleExtend(req *bundle.BundleExtendRequest) (*bundle.BundleExtendResponse, error) {
|
||||
data := model.BundleExtensionRecords{}
|
||||
if err := copier.CopyWithOption(&data, req, copier.Option{DeepCopy: true}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil, dao.AddBundleExtendRecord(data)
|
||||
}
|
||||
|
||||
func BundleExtendRecordsList(req *bundle.BundleExtendRecordsListRequest) (*bundle.BundleExtendRecordsListResponse, error) {
|
||||
data, total, err := dao.GetBundleExtendRecordList(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var result = &bundle.BundleExtendRecordsListResponse{}
|
||||
result.Data = lo.Map(data, func(data model.BundleExtendRecordItemPo, _ int) (ber *bundle.BundleExtendRecordItem) {
|
||||
ber = &bundle.BundleExtendRecordItem{}
|
||||
ber.CreatedAt = uint64(data.CreatedAt.UnixMilli())
|
||||
ber.UserName = data.UserName
|
||||
ber.UserPhoneNumber = data.UserPhoneNumber
|
||||
if data.ServiceType == 0 {
|
||||
ber.AccountAdditional += uint32(data.AccountAdditional)
|
||||
ber.VideoAdditional += uint32(data.VideoAdditional)
|
||||
ber.ImagesAdditional += uint32(data.ImagesAdditional)
|
||||
ber.DataAdditional += uint32(data.DataAdditional)
|
||||
ber.OperatorName = data.OperatorName
|
||||
ber.OperatorPhoneNumber = data.OperatorPhoneNumber
|
||||
} else {
|
||||
switch data.ServiceType {
|
||||
case 1:
|
||||
ber.VideoAdditional += uint32(data.ServiceNum)
|
||||
case 2:
|
||||
ber.ImagesAdditional += uint32(data.ServiceNum)
|
||||
case 3:
|
||||
ber.DataAdditional += uint32(data.ServiceNum)
|
||||
case 4:
|
||||
ber.AccountAdditional += uint32(data.ServiceNum)
|
||||
}
|
||||
ber.AssociatedOrderNumber = data.OrderUUID
|
||||
}
|
||||
return
|
||||
})
|
||||
result.Total = total
|
||||
return result, err
|
||||
}
|
||||
|
||||
func GetBundleBalance(req *bundle.GetBundleBalanceReq) (*bundle.GetBundleBalanceResp, error) {
|
||||
// start := time.Now()
|
||||
// defer func() {
|
||||
// fmt.Printf("(time.Now().UnixMilli() - start.UnixMilli()): %v\n", (time.Now().UnixMilli() - start.UnixMilli()))
|
||||
// }()
|
||||
data, total, err := dao.GetBundleBalance(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
type userDataDto struct {
|
||||
UserID int
|
||||
UserName string
|
||||
UserPhoneNumber string
|
||||
BundleName string
|
||||
ExpirationTime time.Time
|
||||
BundleStatus int
|
||||
VideoCap int
|
||||
ImageCap int
|
||||
DataAnalysisCap int
|
||||
AccountCap int
|
||||
VideoUsed int
|
||||
ImageUsed int
|
||||
DataAnalysisUsed int
|
||||
AccountUsed int
|
||||
ExpansionPacksNumber int
|
||||
}
|
||||
usersMap := map[int]*userDataDto{}
|
||||
lo.ForEach(data, func(data model.BundleBalancePo, index int) {
|
||||
_, ok := usersMap[data.UserID]
|
||||
if !ok {
|
||||
usersMap[data.UserID] = &userDataDto{
|
||||
UserID: data.UserID,
|
||||
UserName: data.UserName,
|
||||
UserPhoneNumber: data.UserPhoneNumber,
|
||||
BundleStatus: data.BundleStatus,
|
||||
ExpirationTime: data.ExpirationTime,
|
||||
}
|
||||
}
|
||||
})
|
||||
for _, user := range usersMap {
|
||||
userData := lo.Filter(data, func(data model.BundleBalancePo, _ int) bool {
|
||||
return data.UserID == user.UserID
|
||||
})
|
||||
// 去重bundle_order_value_add.uuid 计算可用量
|
||||
lo.ForEach(lo.UniqBy(lo.Filter(userData, func(data model.BundleBalancePo, _ int) bool {
|
||||
return data.BovaUUID != nil
|
||||
}), func(data model.BundleBalancePo) string {
|
||||
return *data.BovaUUID
|
||||
}), func(data model.BundleBalancePo, index int) {
|
||||
if data.OderSource == 3 {
|
||||
user.ExpansionPacksNumber++
|
||||
}
|
||||
logger.Infof("增加数据类型%v(%v),user_id:%v,uuid:%v", data.ServiceType, data.ServiceNum, data.UserID, *data.BovaUUID)
|
||||
switch data.ServiceType {
|
||||
case 1:
|
||||
user.VideoCap += data.ServiceNum
|
||||
case 2:
|
||||
user.ImageCap += data.ServiceNum
|
||||
case 3:
|
||||
user.DataAnalysisCap += data.ServiceNum
|
||||
case 4:
|
||||
user.AccountCap += data.ServiceNum
|
||||
default:
|
||||
logger.Warn("不存在的数据类型:", data.ServiceType)
|
||||
}
|
||||
})
|
||||
|
||||
// 去重work_category.uuid 统计绑定的发布数
|
||||
lo.ForEach(lo.UniqBy(lo.Filter(userData, func(data model.BundleBalancePo, _ int) bool {
|
||||
return data.CwUUID != nil
|
||||
}), func(data model.BundleBalancePo) string {
|
||||
return *data.CwUUID
|
||||
}), func(data model.BundleBalancePo, index int) {
|
||||
logger.Infof("减少数据类型%v,user_id:%v,uuid:%v", data.ServiceType, data.UserID, *data.CwUUID)
|
||||
switch data.WorkCategory {
|
||||
case 1:
|
||||
user.ImageUsed++
|
||||
case 2:
|
||||
user.VideoUsed++
|
||||
default:
|
||||
logger.Warn("不存在的数据类型:", data.WorkCategory)
|
||||
}
|
||||
})
|
||||
|
||||
// 去重cast_media_account.uuid 统计绑定的账号数
|
||||
user.AccountUsed += len(lo.UniqBy(lo.Filter(userData, func(data model.BundleBalancePo, _ int) bool {
|
||||
return data.CmaUUID != nil
|
||||
}), func(data model.BundleBalancePo) string {
|
||||
return *data.CmaUUID
|
||||
}))
|
||||
|
||||
// 去重bundle_extension_records.id 统计绑定的账号数
|
||||
lo.ForEach(lo.UniqBy(userData, func(data model.BundleBalancePo) int {
|
||||
return data.BerID
|
||||
}), func(data model.BundleBalancePo, index int) {
|
||||
user.ExpansionPacksNumber++
|
||||
user.AccountCap += data.AccountAdditional
|
||||
user.VideoCap += data.VideAadditiona
|
||||
user.DataAnalysisCap += data.DataAdditional
|
||||
user.ImageCap += data.ImagesAdditional
|
||||
})
|
||||
}
|
||||
result := &bundle.GetBundleBalanceResp{}
|
||||
result.Total = total
|
||||
result.Data = lo.MapToSlice(usersMap, func(_ int, user *userDataDto) *bundle.BundleBalanceItem {
|
||||
return &bundle.BundleBalanceItem{
|
||||
UserName: user.UserName,
|
||||
UserPhoneNumber: user.UserPhoneNumber,
|
||||
BundleName: user.BundleName,
|
||||
Status: int32(user.BundleStatus),
|
||||
ExpiredTime: user.ExpirationTime.UnixMilli(),
|
||||
AccountNumber: int32(user.AccountCap),
|
||||
AccountConsumptionNumber: int32(user.AccountUsed),
|
||||
ImageNumber: int32(user.ImageCap),
|
||||
ImageConsumptionNumber: int32(user.ImageUsed),
|
||||
VideoNumber: int32(user.VideoCap),
|
||||
VideoConsumptionNumber: int32(user.VideoUsed),
|
||||
DataAnalysisNumber: int32(user.DataAnalysisCap),
|
||||
DataAnalysisConsumptionNumber: int32(user.DataAnalysisUsed),
|
||||
ExpansionPacksNumber: int32(user.ExpansionPacksNumber),
|
||||
}
|
||||
})
|
||||
return result, nil
|
||||
}
|
@ -6,15 +6,12 @@ import (
|
||||
"micro-bundle/internal/dao"
|
||||
"micro-bundle/pkg/app"
|
||||
"micro-bundle/pkg/msg"
|
||||
"time"
|
||||
|
||||
"micro-bundle/internal/model"
|
||||
"micro-bundle/pb/bundle"
|
||||
|
||||
"dubbo.apache.org/dubbo-go/v3/common/logger"
|
||||
"github.com/aliyun/alibaba-cloud-sdk-go/sdk/utils"
|
||||
"github.com/jinzhu/copier"
|
||||
"github.com/samber/lo"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
@ -365,173 +362,3 @@ func diffUpdateBundleToValueAddService(tx *gorm.DB, bundleUuid string, selectSer
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func BundleExtend(req *bundle.BundleExtendRequest) (*bundle.BundleExtendResponse, error) {
|
||||
data := model.BundleExtensionRecords{}
|
||||
if err := copier.CopyWithOption(&data, req, copier.Option{DeepCopy: true}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil, dao.AddBundleExtendRecord(data)
|
||||
}
|
||||
|
||||
func BundleExtendRecordsList(req *bundle.BundleExtendRecordsListRequest) (*bundle.BundleExtendRecordsListResponse, error) {
|
||||
data, total, err := dao.GetBundleExtendRecordList(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var result = &bundle.BundleExtendRecordsListResponse{}
|
||||
result.Data = lo.Map(data, func(data model.BundleExtendRecordItemPo, _ int) (ber *bundle.BundleExtendRecordItem) {
|
||||
ber = &bundle.BundleExtendRecordItem{}
|
||||
ber.CreatedAt = uint64(data.CreatedAt.UnixMilli())
|
||||
ber.UserName = data.UserName
|
||||
ber.UserPhoneNumber = data.UserPhoneNumber
|
||||
if data.ServiceType == 0 {
|
||||
ber.AccountAdditional += uint32(data.AccountAdditional)
|
||||
ber.VideoAdditional += uint32(data.VideoAdditional)
|
||||
ber.ImagesAdditional += uint32(data.ImagesAdditional)
|
||||
ber.DataAdditional += uint32(data.DataAdditional)
|
||||
ber.OperatorName = data.OperatorName
|
||||
ber.OperatorPhoneNumber = data.OperatorPhoneNumber
|
||||
} else {
|
||||
switch data.ServiceType {
|
||||
case 1:
|
||||
ber.VideoAdditional += uint32(data.ServiceNum)
|
||||
case 2:
|
||||
ber.ImagesAdditional += uint32(data.ServiceNum)
|
||||
case 3:
|
||||
ber.DataAdditional += uint32(data.ServiceNum)
|
||||
case 4:
|
||||
ber.AccountAdditional += uint32(data.ServiceNum)
|
||||
}
|
||||
ber.AssociatedOrderNumber = data.OrderUUID
|
||||
}
|
||||
return
|
||||
})
|
||||
result.Total = total
|
||||
return result, err
|
||||
}
|
||||
|
||||
func GetBundleBalance(req *bundle.GetBundleBalanceReq) (*bundle.GetBundleBalanceResp, error) {
|
||||
// start := time.Now()
|
||||
// defer func() {
|
||||
// fmt.Printf("(time.Now().UnixMilli() - start.UnixMilli()): %v\n", (time.Now().UnixMilli() - start.UnixMilli()))
|
||||
// }()
|
||||
data, total, err := dao.GetBundleBalance(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
type userDataDto struct {
|
||||
UserID int
|
||||
UserName string
|
||||
UserPhoneNumber string
|
||||
BundleName string
|
||||
ExpirationTime time.Time
|
||||
BundleStatus int
|
||||
VideoCap int
|
||||
ImageCap int
|
||||
DataAnalysisCap int
|
||||
AccountCap int
|
||||
VideoUsed int
|
||||
ImageUsed int
|
||||
DataAnalysisUsed int
|
||||
AccountUsed int
|
||||
ExpansionPacksNumber int
|
||||
}
|
||||
usersMap := map[int]*userDataDto{}
|
||||
lo.ForEach(data, func(data model.BundleBalancePo, index int) {
|
||||
_, ok := usersMap[data.UserID]
|
||||
if !ok {
|
||||
usersMap[data.UserID] = &userDataDto{
|
||||
UserID: data.UserID,
|
||||
UserName: data.UserName,
|
||||
UserPhoneNumber: data.UserPhoneNumber,
|
||||
BundleStatus: data.BundleStatus,
|
||||
ExpirationTime: data.ExpirationTime,
|
||||
}
|
||||
}
|
||||
})
|
||||
for _, user := range usersMap {
|
||||
userData := lo.Filter(data, func(data model.BundleBalancePo, _ int) bool {
|
||||
return data.UserID == user.UserID
|
||||
})
|
||||
// 去重bundle_order_value_add.uuid 计算可用量
|
||||
lo.ForEach(lo.UniqBy(lo.Filter(userData, func(data model.BundleBalancePo, _ int) bool {
|
||||
return data.BovaUUID != nil
|
||||
}), func(data model.BundleBalancePo) string {
|
||||
return *data.BovaUUID
|
||||
}), func(data model.BundleBalancePo, index int) {
|
||||
if data.OderSource == 3 {
|
||||
user.ExpansionPacksNumber++
|
||||
}
|
||||
logger.Infof("增加数据类型%v(%v),user_id:%v,uuid:%v", data.ServiceType, data.ServiceNum, data.UserID, *data.BovaUUID)
|
||||
switch data.ServiceType {
|
||||
case 1:
|
||||
user.VideoCap += data.ServiceNum
|
||||
case 2:
|
||||
user.ImageCap += data.ServiceNum
|
||||
case 3:
|
||||
user.DataAnalysisCap += data.ServiceNum
|
||||
case 4:
|
||||
user.AccountCap += data.ServiceNum
|
||||
default:
|
||||
logger.Warn("不存在的数据类型:", data.ServiceType)
|
||||
}
|
||||
})
|
||||
|
||||
// 去重work_category.uuid 统计绑定的发布数
|
||||
lo.ForEach(lo.UniqBy(lo.Filter(userData, func(data model.BundleBalancePo, _ int) bool {
|
||||
return data.CwUUID != nil
|
||||
}), func(data model.BundleBalancePo) string {
|
||||
return *data.CwUUID
|
||||
}), func(data model.BundleBalancePo, index int) {
|
||||
logger.Infof("减少数据类型%v,user_id:%v,uuid:%v", data.ServiceType, data.UserID, *data.CwUUID)
|
||||
switch data.WorkCategory {
|
||||
case 1:
|
||||
user.ImageUsed++
|
||||
case 2:
|
||||
user.VideoUsed++
|
||||
default:
|
||||
logger.Warn("不存在的数据类型:", data.WorkCategory)
|
||||
}
|
||||
})
|
||||
|
||||
// 去重cast_media_account.uuid 统计绑定的账号数
|
||||
user.AccountUsed += len(lo.UniqBy(lo.Filter(userData, func(data model.BundleBalancePo, _ int) bool {
|
||||
return data.CmaUUID != nil
|
||||
}), func(data model.BundleBalancePo) string {
|
||||
return *data.CmaUUID
|
||||
}))
|
||||
|
||||
// 去重bundle_extension_records.id 统计绑定的账号数
|
||||
lo.ForEach(lo.UniqBy(userData, func(data model.BundleBalancePo) int {
|
||||
return data.BerID
|
||||
}), func(data model.BundleBalancePo, index int) {
|
||||
user.ExpansionPacksNumber++
|
||||
user.AccountCap += data.AccountAdditional
|
||||
user.VideoCap += data.VideAadditiona
|
||||
user.DataAnalysisCap += data.DataAdditional
|
||||
user.ImageCap += data.ImagesAdditional
|
||||
})
|
||||
}
|
||||
result := &bundle.GetBundleBalanceResp{}
|
||||
result.Total = total
|
||||
result.Data = lo.MapToSlice(usersMap, func(_ int, user *userDataDto) *bundle.BundleBalanceItem {
|
||||
return &bundle.BundleBalanceItem{
|
||||
UserName: user.UserName,
|
||||
UserPhoneNumber: user.UserPhoneNumber,
|
||||
BundleName: user.BundleName,
|
||||
Status: int32(user.BundleStatus),
|
||||
ExpiredTime: user.ExpirationTime.UnixMilli(),
|
||||
AccountNumber: int32(user.AccountCap),
|
||||
AccountConsumptionNumber: int32(user.AccountUsed),
|
||||
ImageNumber: int32(user.ImageCap),
|
||||
ImageConsumptionNumber: int32(user.ImageUsed),
|
||||
VideoNumber: int32(user.VideoCap),
|
||||
VideoConsumptionNumber: int32(user.VideoUsed),
|
||||
DataAnalysisNumber: int32(user.DataAnalysisCap),
|
||||
DataAnalysisConsumptionNumber: int32(user.DataAnalysisUsed),
|
||||
ExpansionPacksNumber: int32(user.ExpansionPacksNumber),
|
||||
}
|
||||
})
|
||||
return result, nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user