by Robin at 20240515

This commit is contained in:
Leufolium 2024-05-15 12:13:02 +08:00
parent 7107bb0393
commit 0e6368fc0c
9 changed files with 230 additions and 23 deletions

View File

@ -66,3 +66,17 @@ type OpListResp struct {
base.BaseResponse
Data *OpListData `json:"data"`
}
// op 批量创建
type OpCreateBatchReq struct {
base.BaseRequest
DailyStatementZoneInfos []*dbstruct.DailyStatementZoneInfo
}
type OpCreateBatchData struct {
}
type OpCreateBatchResp struct {
base.BaseResponse
Data *OpCreateData `json:"data"`
}

View File

@ -5142,3 +5142,9 @@ func (m *Mongo) GetDailyStatementZoneInfoList(ctx *gin.Context, req *daily_state
}
return list, err
}
func (m *Mongo) CreateBatchDailyStatementZoneInfo(ctx *gin.Context, dlyStmtZoneInfos []*dbstruct.DailyStatementZoneInfo) error {
col := m.getColDailyStatementZoneInfo()
_, err := col.InsertMany(ctx, dlyStmtZoneInfos)
return err
}

View File

@ -6,6 +6,7 @@ import (
"service/bizcommon/util"
"service/dbstruct"
"service/library/logger"
"strings"
"time"
"github.com/gin-gonic/gin"
@ -500,7 +501,38 @@ func (m *Mysql) GetZoneRefundHisList(ctx *gin.Context, tx *sqlx.Tx, mid, zid int
return
}
// 获取时段内空间进入人数、总入账金额、各业务分入账金额、退款金额、退款人数
func (m *MySql) GetDailyStatementZoneInfoFromVasOrder(ctx *gin.Context, tx *sqlx.Tx, st, et int64, offset, limit int) {
// 获取时段内空间进入人数、总入账金额、各业务分入账金额
func (m *Mysql) GetLastHourZoneProfit(ctx *gin.Context, tx *sqlx.Tx, st, et int64) (list []*dbstruct.ZoneProfit, err error) {
var sql strings.Builder
sql.WriteString(fmt.Sprintf("select uid as mid, oid1 as zid, product_id, count(1) as num, sum(pay_amount) as amount from %s", TableOrder))
sql.WriteString(fmt.Sprintf(" where ct >=%d and ct<=%d and product_id in(%s,%s,%s,%s) and order_status = 1 group by product_id, uid, oid1", st, et,
dbstruct.ProductIdH5ZoneMoment, dbstruct.ProductIdH5ZoneAdmission, dbstruct.ProductIdH5ZoneIronfanship, dbstruct.ProductIdH5ZoneSuperfanship))
list = make([]*dbstruct.ZoneProfit, 0)
if tx != nil {
err = tx.SelectContext(ctx, &list, sql.String())
} else {
db := m.getDBVas()
err = db.SelectContext(ctx, &list, sql.String())
}
if err != nil {
return
}
return
}
func (m *Mysql) GetLastHourZoneRefund(ctx *gin.Context, tx *sqlx.Tx, st, et int64) (list []*dbstruct.ZoneProfit, err error) {
var sql strings.Builder
sql.WriteString(fmt.Sprintf("t1.uid as mid, t1.oid1 as zid, count(1) as num, sum(t1.pay_amount) as amount from %s t1 join %s t2 on t1.id = t2.order_id", TableOrder, TableVasZoneRefundHis))
sql.WriteString(fmt.Sprintf(" where t2.ct >=%d and t2.ct<=%d and t1.ct <%d group by t1.uid, t1.oid1", st, et, st))
list = make([]*dbstruct.ZoneProfit, 0)
if tx != nil {
err = tx.SelectContext(ctx, &list, sql.String())
} else {
db := m.getDBVas()
err = db.SelectContext(ctx, &list, sql.String())
}
if err != nil {
return
}
return
}

View File

@ -63,3 +63,25 @@ func (p *DailyStatementZoneInfo) OpList(ctx *gin.Context, req *daily_statement_z
}
return list, nil
}
func (p *DailyStatementZoneInfo) OpCreateBatch(ctx *gin.Context, req *daily_statement_zone_infoproto.OpCreateBatchReq) error {
lastDailyStatementZoneInfoId := idgenerator.GenDailyStatementZoneInfoId()
for _, dailyStatementZoneInfo := range req.DailyStatementZoneInfos {
//GenDailyStatementZoneInfoId()有可能发生碰撞先记录上一次的id如果发生碰撞则新ID=旧ID+1并刷新旧ID
curDailyStatementZoneInfoId := idgenerator.GenDailyStatementZoneInfoId()
if lastDailyStatementZoneInfoId >= curDailyStatementZoneInfoId {
curDailyStatementZoneInfoId = lastDailyStatementZoneInfoId + 1
}
lastDailyStatementZoneInfoId = curDailyStatementZoneInfoId
dailyStatementZoneInfo.Id = goproto.Int64(curDailyStatementZoneInfoId)
dailyStatementZoneInfo.Ct = goproto.Int64(time.Now().Unix())
dailyStatementZoneInfo.Ut = goproto.Int64(time.Now().Unix())
dailyStatementZoneInfo.DelFlag = goproto.Int64(consts.Exist)
}
err := p.store.CreateBatchDailyStatementZoneInfo(ctx, req.DailyStatementZoneInfos)
if err != nil {
logger.Error("CreateDailyStatementZoneInfo fail, err: %v", err)
return err
}
return nil
}

View File

@ -3,9 +3,6 @@ package logic
import (
"database/sql"
"fmt"
"github.com/gin-gonic/gin"
"github.com/jmoiron/sqlx"
goproto "google.golang.org/protobuf/proto"
"service/api/base"
"service/api/errs"
vasproto "service/api/proto/vas/proto"
@ -15,6 +12,10 @@ import (
"service/dbstruct"
"service/library/logger"
"time"
"github.com/gin-gonic/gin"
"github.com/jmoiron/sqlx"
goproto "google.golang.org/protobuf/proto"
)
// 检查mid对空间的解锁是否存在
@ -1184,3 +1185,20 @@ func (v *Vas) ZoneExit(ctx *gin.Context, mid, zid int64) error {
return nil
}
// 统计时段内空间报表信息
func (v *Vas) GetLastHourZoneProfit(ctx *gin.Context, st, et int64) ([]*dbstruct.ZoneProfit, []*dbstruct.ZoneProfit, error) {
zoneprofits, err := v.store.GetLastHourZoneProfit(ctx, nil, st, et)
if err != nil {
logger.Error("GetLastHourZoneProfit fail err: %v", err)
return make([]*dbstruct.ZoneProfit, 0), make([]*dbstruct.ZoneProfit, 0), err
}
zonerefunds, err := v.store.GetLastHourZoneRefund(ctx, nil, st, et)
if err != nil {
logger.Error("GetLastHourZoneRefund fail err: %v", err)
return make([]*dbstruct.ZoneProfit, 0), make([]*dbstruct.ZoneProfit, 0), err
}
return zoneprofits, zonerefunds, nil
}

View File

@ -1961,3 +1961,47 @@ func (s *Service) utilFillZoneMomentsWithOpVOInfo(ctx *gin.Context, list []*dbst
return
}
func (s *Service) utilAssembleDailyStatementZoneInfo(zoneprofits, zonerefunds []*dbstruct.ZoneProfit, st, et int64) (list []*dbstruct.DailyStatementZoneInfo) {
list = make([]*dbstruct.DailyStatementZoneInfo, 0)
zidDlystmtMp := make(map[int64]*dbstruct.DailyStatementZoneInfo)
// 先写入退款相关的信息
zidZrMp := make(map[int64]*dbstruct.ZoneProfit)
for _, zonerefund := range zonerefunds {
zidZrMp[zonerefund.GetZid()] = zonerefund
dlystmt := &dbstruct.DailyStatementZoneInfo{
Zid: zonerefund.Zid,
RefundAmount: zonerefund.Amount,
RefunderAmount: zonerefund.Num,
}
zidDlystmtMp[zonerefund.GetZid()] = dlystmt
list = append(list, dlystmt)
}
// 再写入收入相关的信息
for _, zoneprofit := range zoneprofits {
dlystmt, ok := zidDlystmtMp[zoneprofit.GetZid()]
if !ok {
//没有相关信息,写入一个
dlystmt = &dbstruct.DailyStatementZoneInfo{
Zid: zoneprofit.Zid,
}
zidDlystmtMp[zoneprofit.GetZid()] = dlystmt
list = append(list, dlystmt)
}
switch zoneprofit.GetProductId() {
case dbstruct.ProductIdH5ZoneMoment:
dlystmt.ZoneMomentAmount = zoneprofit.Amount
case dbstruct.ProductIdH5ZoneAdmission:
dlystmt.AdmissionAmount = zoneprofit.Amount
dlystmt.EntrantNum = goproto.Int64(dlystmt.GetEntrantNum() + zoneprofit.GetNum())
case dbstruct.ProductIdH5ZoneSuperfanship:
dlystmt.SuperfanshipAmount = zoneprofit.Amount
}
dlystmt.TotalAmount = goproto.Int64(dlystmt.GetTotalAmount() + zoneprofit.GetAmount())
}
return
}

View File

@ -8,6 +8,7 @@ import (
account_cancellationproto "service/api/proto/account_cancellation/proto"
contact_customer_service_proto "service/api/proto/contact_customer_service/proto"
daily_statementproto "service/api/proto/daily_statement/proto"
daily_statement_zone_infoproto "service/api/proto/daily_statement_zone_info/proto"
momentproto "service/api/proto/moment/proto"
streamerproto "service/api/proto/streamer/proto"
vasproto "service/api/proto/vas/proto"
@ -141,8 +142,6 @@ func (s *CronService) CreateDailyStatement(ctx context.Context, param *xxl.RunRe
allOrderCount += util.DerefInt32(orderCount.Count)
}
//获取空间相关信息
dailyStatement := &dbstruct.DailyStatement{
H5CallCount: goproto.Int64(int64(count)),
RegisteredUserCount: goproto.Int64(accountCount),
@ -163,6 +162,21 @@ func (s *CronService) CreateDailyStatement(ctx context.Context, param *xxl.RunRe
return fmt.Sprintf("_DefaultDailyStatement OpCreate fail : %v", err)
}
//获取空间相关信息
zoneprofits, zonerefunds, err := _DefaultVas.GetLastHourZoneProfit(&gin.Context{}, startTimeStamp, endTimeStamp)
if err != nil {
logger.Error("_DefaultVas GetLastHourZoneProfit fail : %v", err)
return fmt.Sprintf("_DefaultDailyStatementZoneInfo OpCreateBatch fail : %v", err)
}
dailyStatementZoneInfos := DefaultService.utilAssembleDailyStatementZoneInfo(zoneprofits, zonerefunds, startTimeStamp, endTimeStamp)
err = _DefaultDailyStatementZoneInfo.OpCreateBatch(&gin.Context{}, &daily_statement_zone_infoproto.OpCreateBatchReq{
DailyStatementZoneInfos: dailyStatementZoneInfos,
})
if err != nil {
logger.Error("_DefaultDailyStatementZoneInfo OpCreateBatch fail : %v", err)
return fmt.Sprintf("_DefaultDailyStatementZoneInfo OpCreateBatch fail : %v", err)
}
logger.Info("%v - %v statement data has created...", starttime, endtime)
return fmt.Sprintf("%v - %v statement data has created...", starttime, endtime)
}

View File

@ -1,19 +1,32 @@
package dbstruct
type DailyStatementZoneInfo struct {
Id *int64 `json:"id" bson:"_id"` // 每日报表id
Zid *int64 `json:"zid" bson:"zid"` // 空间id
EntrantNum *int64 `json:"entrant_num" bson:"entrant_num"` // 上小时新增空间进入人数(不含退款)
TotalAmount *int64 `json:"total_amount" bson:"total_amount"` // 上小时总入账
AdmissionAmount *int64 `json:"admission_amount" bson:"admission_amount"` // 成员入账
ZoneMomentAmount *int64 `json:"zone_moment_amount" bson:"zone_moment_amount"` // 帖子入账
SuperfanshipAmount *int64 `json:"superfanship_amount" bson:"superfanship_amount"` // 超粉入账
RefundAmount *int64 `json:"refund_amount" bson:"refund_amount"` // 退款金额
RefunderAmount *int64 `json:"refunder_amount" bson:"refunder_amount"` // 退款人数
StartTime *int64 `json:"start_time" bson:"start_time"` // 起始时间
EndTime *int64 `json:"end_time" bson:"end_time"` // 结束时间
Ct *int64 `json:"ct" bson:"ct"` // 创建时间
Ut *int64 `json:"ut" bson:"ut"` // 更新时间
DelFlag *int64 `json:"del_flag" bson:"del_flag"` // 删除标记
Id *int64 `json:"id" bson:"_id"` // 每日报表id
Zid *int64 `json:"zid" bson:"zid"` // 空间id
EntrantNum *int64 `json:"entrant_num" bson:"entrant_num"` // 上小时新增空间进入人数(不含退款)
TotalAmount *int64 `json:"total_amount" bson:"total_amount"` // 上小时总入账
AdmissionAmount *int64 `json:"admission_amount" bson:"admission_amount"` // 成员入账
ZoneMomentAmount *int64 `json:"zone_moment_amount" bson:"zone_moment_amount"` // 帖子入账
SuperfanshipAmount *int64 `json:"superfanship_amount" bson:"superfanship_amount"` // 超粉入账
RefundAmount *int64 `json:"refund_amount" bson:"refund_amount"` // 退款金额
RefunderAmount *int64 `json:"refunder_amount" bson:"refunder_amount"` // 退款人数
StartTime *int64 `json:"start_time" bson:"start_time"` // 起始时间
EndTime *int64 `json:"end_time" bson:"end_time"` // 结束时间
Ct *int64 `json:"ct" bson:"ct"` // 创建时间
Ut *int64 `json:"ut" bson:"ut"` // 更新时间
DelFlag *int64 `json:"del_flag" bson:"del_flag"` // 删除标记
}
func (p *DailyStatementZoneInfo) GetTotalAmount() int64 {
if p != nil && p.TotalAmount != nil {
return *p.TotalAmount
}
return 0
}
func (p *DailyStatementZoneInfo) GetEntrantNum() int64 {
if p != nil && p.EntrantNum != nil {
return *p.EntrantNum
}
return 0
}

View File

@ -1379,3 +1379,47 @@ func (p *ZoneRefundHis) GetProductId() string {
}
return ""
}
// 时段空间收入信息
type ZoneProfit struct {
Mid *int64 `json:"mid" db:"mid"` // 用户id
Zid *int64 `json:"zid" db:"zid"` // 空间id
ProductId *string `json:"product_id" db:"product_id"` // 商品id
Amount *int64 `json:"amount" db:"amount"` // 支付总金额
Num *int64 `json:"num" db:"num"` // 支付总人数
}
func (p *ZoneProfit) GetMid() int64 {
if p != nil && p.Mid != nil {
return *p.Mid
}
return 0
}
func (p *ZoneProfit) GetZid() int64 {
if p != nil && p.Zid != nil {
return *p.Zid
}
return 0
}
func (p *ZoneProfit) GetProductId() string {
if p != nil && p.ProductId != nil {
return *p.ProductId
}
return ""
}
func (p *ZoneProfit) GetAmount() int64 {
if p != nil && p.Amount != nil {
return *p.Amount
}
return 0
}
func (p *ZoneProfit) GetNum() int64 {
if p != nil && p.Num != nil {
return *p.Num
}
return 0
}