fix analysis
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
package admin_agent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"tydata-server/app/main/api/internal/svc"
|
||||
"tydata-server/app/main/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type AdminGetWithdrawalStatisticsLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewAdminGetWithdrawalStatisticsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AdminGetWithdrawalStatisticsLogic {
|
||||
return &AdminGetWithdrawalStatisticsLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *AdminGetWithdrawalStatisticsLogic) AdminGetWithdrawalStatistics(req *types.AdminGetWithdrawalStatisticsReq) (resp *types.AdminGetWithdrawalStatisticsResp, err error) {
|
||||
// 获取今日的开始和结束时间
|
||||
today := time.Now()
|
||||
startOfDay := time.Date(today.Year(), today.Month(), today.Day(), 0, 0, 0, 0, today.Location())
|
||||
endOfDay := startOfDay.Add(24 * time.Hour)
|
||||
|
||||
// 构建查询条件
|
||||
builder := l.svcCtx.AgentWithdrawalModel.SelectBuilder()
|
||||
|
||||
// 查询总提现金额(status=2表示成功)
|
||||
totalBuilder := builder.Where("status = ?", 2)
|
||||
totalWithdrawalAmount, err := l.svcCtx.AgentWithdrawalModel.FindSum(l.ctx, totalBuilder, "amount")
|
||||
if err != nil {
|
||||
logx.Errorf("查询总提现金额失败: %v", err)
|
||||
return nil, fmt.Errorf("查询总提现金额失败: %w", err)
|
||||
}
|
||||
|
||||
// 查询今日提现金额(status=2表示成功)
|
||||
todayBuilder := builder.Where("status = ? AND create_time >= ? AND create_time < ?", 2, startOfDay, endOfDay)
|
||||
todayWithdrawalAmount, err := l.svcCtx.AgentWithdrawalModel.FindSum(l.ctx, todayBuilder, "amount")
|
||||
if err != nil {
|
||||
logx.Errorf("查询今日提现金额失败: %v", err)
|
||||
return nil, fmt.Errorf("查询今日提现金额失败: %w", err)
|
||||
}
|
||||
|
||||
// 构建响应
|
||||
resp = &types.AdminGetWithdrawalStatisticsResp{
|
||||
TotalWithdrawalAmount: totalWithdrawalAmount,
|
||||
TodayWithdrawalAmount: todayWithdrawalAmount,
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
@@ -115,6 +115,7 @@ func (l *AdminGetOrderDetailLogic) AdminGetOrderDetail(req *types.AdminGetOrderD
|
||||
PaymentPlatform: order.PaymentPlatform,
|
||||
PaymentScene: order.PaymentScene,
|
||||
Amount: order.Amount,
|
||||
SalesCost: order.SalesCost,
|
||||
Status: order.Status,
|
||||
CreateTime: order.CreateTime.Format("2006-01-02 15:04:05"),
|
||||
UpdateTime: order.UpdateTime.Format("2006-01-02 15:04:05"),
|
||||
|
||||
@@ -264,6 +264,7 @@ func (l *AdminGetOrderListLogic) AdminGetOrderList(req *types.AdminGetOrderListR
|
||||
PaymentPlatform: order.PaymentPlatform,
|
||||
PaymentScene: order.PaymentScene,
|
||||
Amount: order.Amount,
|
||||
SalesCost: order.SalesCost,
|
||||
Status: order.Status,
|
||||
CreateTime: order.CreateTime.Format("2006-01-02 15:04:05"),
|
||||
QueryState: queryStateMap[order.Id],
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
package admin_order
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"tydata-server/app/main/api/internal/svc"
|
||||
"tydata-server/app/main/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type AdminGetRefundStatisticsLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewAdminGetRefundStatisticsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AdminGetRefundStatisticsLogic {
|
||||
return &AdminGetRefundStatisticsLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *AdminGetRefundStatisticsLogic) AdminGetRefundStatistics(req *types.AdminGetRefundStatisticsReq) (resp *types.AdminGetRefundStatisticsResp, err error) {
|
||||
// 获取今日的开始和结束时间
|
||||
today := time.Now()
|
||||
startOfDay := time.Date(today.Year(), today.Month(), today.Day(), 0, 0, 0, 0, today.Location())
|
||||
endOfDay := startOfDay.Add(24 * time.Hour)
|
||||
|
||||
// 构建查询条件
|
||||
builder := l.svcCtx.OrderModel.SelectBuilder()
|
||||
|
||||
// 查询总退款金额(status=refunded表示已退款)
|
||||
totalBuilder := builder.Where("status = ?", "refunded")
|
||||
totalRefundAmount, err := l.svcCtx.OrderModel.FindSum(l.ctx, totalBuilder, "amount")
|
||||
if err != nil {
|
||||
logx.Errorf("查询总退款金额失败: %v", err)
|
||||
return nil, fmt.Errorf("查询总退款金额失败: %w", err)
|
||||
}
|
||||
|
||||
// 查询今日退款金额(status=refunded表示已退款,且退款时间为今日)
|
||||
todayBuilder := builder.Where("status = ? AND refund_time >= ? AND refund_time < ?", "refunded", startOfDay, endOfDay)
|
||||
todayRefundAmount, err := l.svcCtx.OrderModel.FindSum(l.ctx, todayBuilder, "amount")
|
||||
if err != nil {
|
||||
logx.Errorf("查询今日退款金额失败: %v", err)
|
||||
return nil, fmt.Errorf("查询今日退款金额失败: %w", err)
|
||||
}
|
||||
|
||||
// 构建响应
|
||||
resp = &types.AdminGetRefundStatisticsResp{
|
||||
TotalRefundAmount: totalRefundAmount,
|
||||
TodayRefundAmount: todayRefundAmount,
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
package admin_order
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"tydata-server/app/main/api/internal/svc"
|
||||
"tydata-server/app/main/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type AdminGetRevenueStatisticsLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewAdminGetRevenueStatisticsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AdminGetRevenueStatisticsLogic {
|
||||
return &AdminGetRevenueStatisticsLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *AdminGetRevenueStatisticsLogic) AdminGetRevenueStatistics(req *types.AdminGetRevenueStatisticsReq) (resp *types.AdminGetRevenueStatisticsResp, err error) {
|
||||
// 获取今日的开始和结束时间
|
||||
today := time.Now()
|
||||
startOfDay := time.Date(today.Year(), today.Month(), today.Day(), 0, 0, 0, 0, today.Location())
|
||||
endOfDay := startOfDay.Add(24 * time.Hour)
|
||||
|
||||
// 构建查询条件
|
||||
builder := l.svcCtx.OrderModel.SelectBuilder()
|
||||
|
||||
// 查询总收入金额(status=paid表示已支付)
|
||||
totalRevenueBuilder := builder.Where("status = ?", "paid")
|
||||
totalRevenueAmount, err := l.svcCtx.OrderModel.FindSum(l.ctx, totalRevenueBuilder, "amount")
|
||||
if err != nil {
|
||||
logx.Errorf("查询总收入金额失败: %v", err)
|
||||
return nil, fmt.Errorf("查询总收入金额失败: %w", err)
|
||||
}
|
||||
|
||||
// 查询今日收入金额(status=paid表示已支付,且支付时间为今日)
|
||||
todayRevenueBuilder := builder.Where("status = ? AND pay_time >= ? AND pay_time < ?", "paid", startOfDay, endOfDay)
|
||||
todayRevenueAmount, err := l.svcCtx.OrderModel.FindSum(l.ctx, todayRevenueBuilder, "amount")
|
||||
if err != nil {
|
||||
logx.Errorf("查询今日收入金额失败: %v", err)
|
||||
return nil, fmt.Errorf("查询今日收入金额失败: %w", err)
|
||||
}
|
||||
|
||||
// 查询总成本(status=paid表示已支付)
|
||||
totalCostBuilder := builder.Where("status = ?", "paid")
|
||||
totalCostAmount, err := l.svcCtx.OrderModel.FindSum(l.ctx, totalCostBuilder, "sales_cost")
|
||||
if err != nil {
|
||||
logx.Errorf("查询总成本金额失败: %v", err)
|
||||
return nil, fmt.Errorf("查询总成本金额失败: %w", err)
|
||||
}
|
||||
|
||||
// 查询今日成本(status=paid表示已支付,且支付时间为今日)
|
||||
todayCostBuilder := builder.Where("status = ? AND pay_time >= ? AND pay_time < ?", "paid", startOfDay, endOfDay)
|
||||
todayCostAmount, err := l.svcCtx.OrderModel.FindSum(l.ctx, todayCostBuilder, "sales_cost")
|
||||
if err != nil {
|
||||
logx.Errorf("查询今日成本金额失败: %v", err)
|
||||
return nil, fmt.Errorf("查询今日成本金额失败: %w", err)
|
||||
}
|
||||
|
||||
// 计算总利润 = 总收入 - 总成本
|
||||
totalProfitAmount := totalRevenueAmount - totalCostAmount
|
||||
|
||||
// 计算今日利润 = 今日收入 - 今日成本
|
||||
todayProfitAmount := todayRevenueAmount - todayCostAmount
|
||||
|
||||
// 构建响应
|
||||
resp = &types.AdminGetRevenueStatisticsResp{
|
||||
TotalRevenueAmount: totalRevenueAmount,
|
||||
TodayRevenueAmount: todayRevenueAmount,
|
||||
TotalProfitAmount: totalProfitAmount,
|
||||
TodayProfitAmount: todayProfitAmount,
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
Reference in New Issue
Block a user