fixadd
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
package admin_agent
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"tydata-server/app/main/api/internal/logic/admin_agent"
|
||||
"tydata-server/app/main/api/internal/svc"
|
||||
"tydata-server/app/main/api/internal/types"
|
||||
"tydata-server/common/result"
|
||||
"tydata-server/pkg/lzkit/validator"
|
||||
)
|
||||
|
||||
func AdminGetAgentOrderStatisticsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.AdminGetAgentOrderStatisticsReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
result.ParamErrorResult(r, w, err)
|
||||
return
|
||||
}
|
||||
if err := validator.Validate(req); err != nil {
|
||||
result.ParamValidateErrorResult(r, w, err)
|
||||
return
|
||||
}
|
||||
l := admin_agent.NewAdminGetAgentOrderStatisticsLogic(r.Context(), svcCtx)
|
||||
resp, err := l.AdminGetAgentOrderStatistics(&req)
|
||||
result.HttpResult(r, w, resp, err)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package admin_agent
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"tydata-server/app/main/api/internal/logic/admin_agent"
|
||||
"tydata-server/app/main/api/internal/svc"
|
||||
"tydata-server/app/main/api/internal/types"
|
||||
"tydata-server/common/result"
|
||||
"tydata-server/pkg/lzkit/validator"
|
||||
)
|
||||
|
||||
func AdminGetAgentStatisticsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.AdminGetAgentStatisticsReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
result.ParamErrorResult(r, w, err)
|
||||
return
|
||||
}
|
||||
if err := validator.Validate(req); err != nil {
|
||||
result.ParamValidateErrorResult(r, w, err)
|
||||
return
|
||||
}
|
||||
l := admin_agent.NewAdminGetAgentStatisticsLogic(r.Context(), svcCtx)
|
||||
resp, err := l.AdminGetAgentStatistics(&req)
|
||||
result.HttpResult(r, w, resp, err)
|
||||
}
|
||||
}
|
||||
@@ -3,12 +3,13 @@ package admin_agent
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"tydata-server/app/main/api/internal/logic/admin_agent"
|
||||
"tydata-server/app/main/api/internal/svc"
|
||||
"tydata-server/app/main/api/internal/types"
|
||||
"tydata-server/common/result"
|
||||
"tydata-server/pkg/lzkit/validator"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
)
|
||||
|
||||
func AdminGetWithdrawalStatisticsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
|
||||
@@ -67,6 +67,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||
Path: "/agent-membership-recharge-order/list",
|
||||
Handler: admin_agent.AdminGetAgentMembershipRechargeOrderListHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/agent-order/statistics",
|
||||
Handler: admin_agent.AdminGetAgentOrderStatisticsHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/agent-platform-deduction/list",
|
||||
@@ -107,6 +112,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||
Path: "/list",
|
||||
Handler: admin_agent.AdminGetAgentListHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/statistics",
|
||||
Handler: admin_agent.AdminGetAgentStatisticsHandler(serverCtx),
|
||||
},
|
||||
}...,
|
||||
),
|
||||
rest.WithPrefix("/api/v1/admin/agent"),
|
||||
|
||||
@@ -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 AdminGetAgentOrderStatisticsLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewAdminGetAgentOrderStatisticsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AdminGetAgentOrderStatisticsLogic {
|
||||
return &AdminGetAgentOrderStatisticsLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *AdminGetAgentOrderStatisticsLogic) AdminGetAgentOrderStatistics(req *types.AdminGetAgentOrderStatisticsReq) (resp *types.AdminGetAgentOrderStatisticsResp, 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.AgentOrderModel.SelectBuilder()
|
||||
|
||||
// 查询总代理订单数
|
||||
totalBuilder := builder
|
||||
totalAgentOrderCount, err := l.svcCtx.AgentOrderModel.FindCount(l.ctx, totalBuilder, "id")
|
||||
if err != nil {
|
||||
logx.Errorf("查询总代理订单数失败: %v", err)
|
||||
return nil, fmt.Errorf("查询总代理订单数失败: %w", err)
|
||||
}
|
||||
|
||||
// 查询今日代理订单数
|
||||
todayBuilder := builder.Where("create_time >= ? AND create_time < ?", startOfDay, endOfDay)
|
||||
todayAgentOrderCount, err := l.svcCtx.AgentOrderModel.FindCount(l.ctx, todayBuilder, "id")
|
||||
if err != nil {
|
||||
logx.Errorf("查询今日代理订单数失败: %v", err)
|
||||
return nil, fmt.Errorf("查询今日代理订单数失败: %w", err)
|
||||
}
|
||||
|
||||
// 构建响应
|
||||
resp = &types.AdminGetAgentOrderStatisticsResp{
|
||||
TotalAgentOrderCount: totalAgentOrderCount,
|
||||
TodayAgentOrderCount: todayAgentOrderCount,
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
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 AdminGetAgentStatisticsLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewAdminGetAgentStatisticsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AdminGetAgentStatisticsLogic {
|
||||
return &AdminGetAgentStatisticsLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *AdminGetAgentStatisticsLogic) AdminGetAgentStatistics(req *types.AdminGetAgentStatisticsReq) (resp *types.AdminGetAgentStatisticsResp, err error) {
|
||||
// 使用AgentModel的SelectBuilder和FindCount方法获取总代理数
|
||||
totalBuilder := l.svcCtx.AgentModel.SelectBuilder()
|
||||
totalAgentCount, err := l.svcCtx.AgentModel.FindCount(l.ctx, totalBuilder, "id")
|
||||
if err != nil {
|
||||
logx.Errorf("获取总代理数失败: %v", err)
|
||||
return nil, fmt.Errorf("获取总代理数失败: %w", err)
|
||||
}
|
||||
|
||||
// 获取今日新增代理数
|
||||
todayBuilder := l.svcCtx.AgentModel.SelectBuilder()
|
||||
today := time.Now()
|
||||
startOfDay := time.Date(today.Year(), today.Month(), today.Day(), 0, 0, 0, 0, today.Location())
|
||||
endOfDay := startOfDay.Add(24 * time.Hour)
|
||||
todayBuilder = todayBuilder.Where("create_time >= ? AND create_time < ?", startOfDay, endOfDay)
|
||||
|
||||
todayAgentCount, err := l.svcCtx.AgentModel.FindCount(l.ctx, todayBuilder, "id")
|
||||
if err != nil {
|
||||
logx.Errorf("获取今日新增代理数失败: %v", err)
|
||||
return nil, fmt.Errorf("获取今日新增代理数失败: %w", err)
|
||||
}
|
||||
|
||||
resp = &types.AdminGetAgentStatisticsResp{
|
||||
TotalAgentCount: totalAgentCount,
|
||||
TodayAgentCount: todayAgentCount,
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
@@ -279,6 +279,14 @@ type AdminGetAgentMembershipRechargeOrderListResp struct {
|
||||
Items []AgentMembershipRechargeOrderListItem `json:"items"` // 列表数据
|
||||
}
|
||||
|
||||
type AdminGetAgentOrderStatisticsReq struct {
|
||||
}
|
||||
|
||||
type AdminGetAgentOrderStatisticsResp struct {
|
||||
TotalAgentOrderCount int64 `json:"total_agent_order_count"` // 总代理订单数
|
||||
TodayAgentOrderCount int64 `json:"today_agent_order_count"` // 今日代理订单数
|
||||
}
|
||||
|
||||
type AdminGetAgentPlatformDeductionListReq struct {
|
||||
Page int64 `form:"page"` // 页码
|
||||
PageSize int64 `form:"pageSize"` // 每页数量
|
||||
@@ -317,6 +325,14 @@ type AdminGetAgentRewardListResp struct {
|
||||
Items []AgentRewardListItem `json:"items"` // 列表数据
|
||||
}
|
||||
|
||||
type AdminGetAgentStatisticsReq struct {
|
||||
}
|
||||
|
||||
type AdminGetAgentStatisticsResp struct {
|
||||
TotalAgentCount int64 `json:"total_agent_count"` // 总代理数
|
||||
TodayAgentCount int64 `json:"today_agent_count"` // 今日新增代理数
|
||||
}
|
||||
|
||||
type AdminGetAgentWithdrawalListReq struct {
|
||||
Page int64 `form:"page"` // 页码
|
||||
PageSize int64 `form:"pageSize"` // 每页数量
|
||||
|
||||
Reference in New Issue
Block a user