添加扩展列表支持
This commit is contained in:
parent
961dfe7a8e
commit
a631cccb13
@ -4,7 +4,6 @@ import (
|
||||
bundleConfig "micro-bundle/config"
|
||||
"micro-bundle/internal/controller"
|
||||
_ "micro-bundle/internal/handler"
|
||||
"micro-bundle/internal/logic"
|
||||
"micro-bundle/pkg/app"
|
||||
"micro-bundle/pkg/tracing"
|
||||
|
||||
@ -32,8 +31,6 @@ func main() {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
logic.GetBundleBalance(nil)
|
||||
return
|
||||
//l, err := net.Listen("tcp", ":8883")
|
||||
//if err != nil {
|
||||
// fmt.Printf("failed to listen: %v", err)
|
||||
|
@ -8,7 +8,6 @@ import (
|
||||
"micro-bundle/pkg/app"
|
||||
commonErr "micro-bundle/pkg/err"
|
||||
"micro-bundle/pkg/msg"
|
||||
"micro-bundle/pkg/utils"
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
@ -391,40 +390,76 @@ func AddBundleExtendRecord(data model.BundleExtensionRecords) error {
|
||||
return app.ModuleClients.BundleDB.Create(&data).Error
|
||||
}
|
||||
|
||||
func GetBundleExtendRecordList(req *bundle.BundleExtendRecordsListRequest) ([]model.BundleExtendRecordItemPo, int64, error) {
|
||||
session := app.ModuleClients.BundleDB.Select("*,mu.nickname as user_name,mu.tel_num as user_phone_number,fu.tel_num as operator_phone_number,fu.nickname as operator_name").
|
||||
Model(&model.BundleExtensionRecords{}).
|
||||
Joins("left join `fontree-account`.`user` fu on operator_id = fu.id left join `micro-account`.`user` mu on user_id = mu.id ")
|
||||
if req.EndTime != 0 {
|
||||
session = session.Where("bundle_extension_records.created_at < ?", time.Unix(int64(req.EndTime), 0))
|
||||
func GetBundleExtendRecordList(req *bundle.BundleExtendRecordsListRequest) (data []model.BundleExtendRecordItemPo, total int64, err error) {
|
||||
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
|
||||
FROM
|
||||
fiee_bundle.bundle_order_value_add AS bova
|
||||
` + "LEFT JOIN `micro-account`.`user` u ON u.id = bova.customer_id" + `
|
||||
|
||||
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
|
||||
FROM
|
||||
fiee_bundle.bundle_extension_records ber
|
||||
` + "LEFT JOIN `micro-account`.`user` u ON u.id = ber.user_id" + `
|
||||
ORDER BY created_at DESC
|
||||
LIMIT ? OFFSET ?;
|
||||
`
|
||||
countSql := `
|
||||
SELECT COUNT(*) AS total_count FROM (
|
||||
SELECT bova.created_at
|
||||
FROM fiee_bundle.bundle_order_value_add AS bova
|
||||
` + "LEFT JOIN `micro-account`.`user` u ON u.id = bova.customer_id" + `
|
||||
UNION ALL
|
||||
SELECT ber.created_at
|
||||
FROM fiee_bundle.bundle_extension_records ber
|
||||
` + "LEFT JOIN `micro-account`.`user` u ON u.id = ber.user_id" + `
|
||||
) AS total_table;
|
||||
`
|
||||
|
||||
// 查询总数
|
||||
err = app.ModuleClients.BundleDB.Raw(countSql).Scan(&total).Error
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
if req.StartTime != 0 {
|
||||
session = session.Where("bundle_extension_records.created_at > ?", time.Unix(int64(req.StartTime), 0))
|
||||
if req.Page == 0 {
|
||||
req.Page = 1
|
||||
}
|
||||
if req.Operator != "" {
|
||||
if utils.IsPhoneNumber(req.Operator) {
|
||||
session = session.Where("fu.tel_num = ?", req.Operator)
|
||||
} else {
|
||||
session = session.Where("fu.nickname = ?", req.Operator)
|
||||
}
|
||||
if req.PageSize == 0 {
|
||||
req.PageSize = 100
|
||||
}
|
||||
if req.User != "" {
|
||||
if utils.IsPhoneNumber(req.User) {
|
||||
session = session.Where("mu.tel_num = ?", req.User)
|
||||
} else {
|
||||
session = session.Where("mu.nickname = ?", req.User)
|
||||
}
|
||||
}
|
||||
if req.AssociatedOrderNumber != "" {
|
||||
session = session.Where("associated_order_number = ?", req.AssociatedOrderNumber)
|
||||
}
|
||||
if req.Type != 0 {
|
||||
session = session.Where("`type` = ?", req.Type)
|
||||
}
|
||||
var total int64
|
||||
res := []model.BundleExtendRecordItemPo{}
|
||||
session.Limit(int(req.PageSize)).Offset(int(req.Page-1) * int(req.PageSize)).Find(&res).Count(&total)
|
||||
return res, total, session.Error
|
||||
offset := (req.Page - 1) * req.PageSize
|
||||
|
||||
// 查询数据
|
||||
err = app.ModuleClients.BundleDB.Raw(sql, req.PageSize, offset).Scan(&data).Error
|
||||
return
|
||||
}
|
||||
|
||||
func GetBundleBalance(req *bundle.GetBundleBalanceReq) (data []model.BundleBalancePo, total int64, err error) {
|
||||
@ -453,7 +488,11 @@ func GetBundleBalance(req *bundle.GetBundleBalanceReq) (data []model.BundleBalan
|
||||
bova.uuid as bova_uuid,
|
||||
cma.user_id as cma_uuid,
|
||||
ber.id as ber_id,
|
||||
bova.source as oder_source
|
||||
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").
|
||||
@ -466,23 +505,3 @@ func GetBundleBalance(req *bundle.GetBundleBalanceReq) (data []model.BundleBalan
|
||||
Scan(&data)
|
||||
return
|
||||
}
|
||||
|
||||
// func GetBundleCapacity(tx *gorm.DB) {
|
||||
// // 子查询: 每个 customer_id 的最新 created_at
|
||||
// subQuery := tx.Table("fiee_bundle.bundle_order_records").
|
||||
// Select("customer_id, MAX(created_at) as max_created_at").
|
||||
// Group("customer_id")
|
||||
|
||||
// // 主查询
|
||||
// tx.Table("fiee_bundle.bundle_order_records AS bor").
|
||||
// Select("bor.*, bova.*").
|
||||
// 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").
|
||||
// Where("bor.created_at < bova.created_at").
|
||||
// Where("bor.expiration_time > NOW()").
|
||||
// Scan(&results)
|
||||
// }
|
||||
|
||||
// func GetBundleUsage(tx *gorm.DB, userIds []int){
|
||||
|
||||
// }
|
||||
|
@ -379,9 +379,35 @@ func BundleExtendRecordsList(req *bundle.BundleExtendRecordsListRequest) (*bundl
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result := new(bundle.BundleExtendRecordsListResponse)
|
||||
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
|
||||
err = copier.Copy(result.Data, &data)
|
||||
return result, err
|
||||
}
|
||||
|
||||
@ -477,9 +503,15 @@ func GetBundleBalance(req *bundle.GetBundleBalanceReq) (*bundle.GetBundleBalance
|
||||
}))
|
||||
|
||||
// 去重bundle_extension_records.id 统计绑定的账号数
|
||||
user.ExpansionPacksNumber += len(lo.UniqBy(userData, func(data model.BundleBalancePo) int {
|
||||
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
|
||||
|
@ -85,7 +85,6 @@ type BundleExtensionRecords struct {
|
||||
AvailableDurationAdditional uint `gorm:"column:available_duration_additional;type:int(11) unsigned;comment:可用时长增加" json:"available_duration_additional"`
|
||||
Type int `gorm:"column:type;type:tinyint(4);comment:类型 0:手动操作" json:"type"`
|
||||
Remark string `gorm:"column:remark;type:text;comment:备注" json:"remark"`
|
||||
AssociatedOrderNumber string `gorm:"column:associated_order_number;type:varchar(256);comment:关联增值服务订单号" json:"associated_order_number"`
|
||||
OperatorId int `gorm:"column:operator_id;type:int(11);comment:操作人id" json:"operator_id"`
|
||||
OperatorName string `gorm:"column:operator_name;type:varchar(256)" json:"operatorName"`
|
||||
OperatorPhoneNumber string `gorm:"column:operator_phone_number;type:varchar(256)" json:"operatorPhoneNumber"`
|
||||
@ -97,24 +96,59 @@ func (*BundleExtensionRecords) TableName() string {
|
||||
}
|
||||
|
||||
type BundleExtendRecordItemPo struct {
|
||||
BundleExtensionRecords
|
||||
UserName string `json:"userName" gorm:"column:user_name"`
|
||||
UserPhoneNumber int64 `json:"userPhoneNumber" gorm:"column:user_phone_number"`
|
||||
UserID uint
|
||||
UserName string
|
||||
UserPhoneNumber string
|
||||
ServiceNum int
|
||||
ServiceType int
|
||||
AccountAdditional int
|
||||
ImagesAdditional int
|
||||
DataAdditional int
|
||||
VideoAdditional int
|
||||
OperatorName string
|
||||
OperatorPhoneNumber string
|
||||
OrderUUID string
|
||||
CreatedAt time.Time
|
||||
}
|
||||
|
||||
type BundleExtendRecordItemDto struct {
|
||||
ID uint `gorm:"primarykey"`
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
DeletedAt soft_delete.DeletedAt
|
||||
UserId int `gorm:"column:user_id;type:int(11);comment:艺人id;NOT NULL" json:"user_id"`
|
||||
AccountAdditional uint `gorm:"column:account_additional;type:int(11) unsigned;comment:账号额外增加" json:"account_additional"`
|
||||
VideoAdditional uint `gorm:"column:video_additional;type:int(11) unsigned;comment:图文额外增加" json:"video_additional"`
|
||||
ImagesAdditional uint `gorm:"column:images_additional;type:int(11) unsigned;comment:图文额外增加" json:"images_additional"`
|
||||
DataAdditional uint `gorm:"column:data_additional;type:int(11) unsigned;comment:数据额外增加" json:"data_additional"`
|
||||
AvailableDurationAdditional uint `gorm:"column:available_duration_additional;type:int(11) unsigned;comment:可用时长增加" json:"available_duration_additional"`
|
||||
Type int `gorm:"column:type;type:tinyint(4);comment:类型 0:手动操作" json:"type"`
|
||||
Remark string `gorm:"column:remark;type:text;comment:备注" json:"remark"`
|
||||
AssociatedOrderNumber string `gorm:"column:associated_order_number;type:varchar(256);comment:关联增值服务订单号" json:"associated_order_number"`
|
||||
OperatorId int `gorm:"column:operator_id;type:int(11);comment:操作人id" json:"operator_id"`
|
||||
OperatorName string `gorm:"column:operator_name;type:varchar(256)" json:"operatorName"`
|
||||
OperatorPhoneNumber string `gorm:"column:operator_phone_number;type:varchar(256)" json:"operatorPhoneNumber"`
|
||||
UserName string `json:"userName" gorm:"column:user_name"`
|
||||
UserPhoneNumber string `json:"userPhoneNumber" gorm:"column:user_phone_number"`
|
||||
}
|
||||
|
||||
type BundleBalancePo struct {
|
||||
UserID int `gorm:"column:user_id"`
|
||||
UserName string `gorm:"column:user_name"`
|
||||
UserPhoneNumber string `gorm:"column:user_phone_nmber"`
|
||||
BundleName string `gorm:"column:bundle_name"`
|
||||
ExpirationTime time.Time `gorm:"column:expired_time"`
|
||||
BundleStatus int `gorm:"column:bundle_status"`
|
||||
ServiceNum int `gorm:"column:service_num"`
|
||||
ServiceType int `gorm:"column:service_type"`
|
||||
WorkCategory int `gorm:"column:work_category"`
|
||||
CwUUID *string `gorm:"column:cw_uuid"`
|
||||
BovaUUID *string `gorm:"column:bova_uuid"`
|
||||
CmaUUID *string `gorm:"column:cma_uuid"`
|
||||
BerID int `gorm:"column:ber_id"`
|
||||
OderSource int `gorm:"column:oder_source"`
|
||||
UserID int `gorm:"column:user_id"`
|
||||
UserName string `gorm:"column:user_name"`
|
||||
UserPhoneNumber string `gorm:"column:user_phone_nmber"`
|
||||
BundleName string `gorm:"column:bundle_name"`
|
||||
ExpirationTime time.Time `gorm:"column:expired_time"`
|
||||
BundleStatus int `gorm:"column:bundle_status"`
|
||||
ServiceNum int `gorm:"column:service_num"`
|
||||
ServiceType int `gorm:"column:service_type"`
|
||||
WorkCategory int `gorm:"column:work_category"`
|
||||
CwUUID *string `gorm:"column:cw_uuid"`
|
||||
BovaUUID *string `gorm:"column:bova_uuid"`
|
||||
CmaUUID *string `gorm:"column:cma_uuid"`
|
||||
BerID int `gorm:"column:ber_id"`
|
||||
OderSource int `gorm:"column:oder_source"`
|
||||
AccountAdditional int `gorm:"column:account_additional"`
|
||||
ImagesAdditional int `gorm:"column:images_additional"`
|
||||
DataAdditional int `gorm:"column:data_additional"`
|
||||
VideAadditiona int `gorm:"column:video_additional"`
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user