f
This commit is contained in:
94
app/main/api/desc/admin/dashboard.api
Normal file
94
app/main/api/desc/admin/dashboard.api
Normal file
@@ -0,0 +1,94 @@
|
||||
syntax = "v1"
|
||||
|
||||
info (
|
||||
title: "后台统计面板服务"
|
||||
desc: "后台统计面板相关接口"
|
||||
author: "team"
|
||||
version: "v1"
|
||||
)
|
||||
|
||||
// ============================================
|
||||
// 统计面板接口
|
||||
// ============================================
|
||||
@server (
|
||||
prefix: /api/v1/admin/dashboard
|
||||
group: admin_dashboard
|
||||
middleware: AdminAuthInterceptor
|
||||
)
|
||||
service main {
|
||||
// 获取统计面板数据
|
||||
@handler AdminGetDashboardStatistics
|
||||
get /statistics returns (AdminGetDashboardStatisticsResp)
|
||||
}
|
||||
|
||||
type (
|
||||
// 统计面板响应
|
||||
AdminGetDashboardStatisticsResp {
|
||||
// 订单统计
|
||||
OrderStats AdminOrderStatistics `json:"order_stats"`
|
||||
// 营收统计
|
||||
RevenueStats AdminRevenueStatistics `json:"revenue_stats"`
|
||||
// 代理统计
|
||||
AgentStats AdminAgentStatistics `json:"agent_stats"`
|
||||
// 利润统计
|
||||
ProfitStats AdminProfitStatistics `json:"profit_stats"`
|
||||
// 订单趋势(最近7天)
|
||||
OrderTrend []AdminTrendData `json:"order_trend"`
|
||||
// 营收趋势(最近7天)
|
||||
RevenueTrend []AdminTrendData `json:"revenue_trend"`
|
||||
}
|
||||
// 订单统计
|
||||
AdminOrderStatistics {
|
||||
TodayCount int64 `json:"today_count"` // 今日订单数
|
||||
MonthCount int64 `json:"month_count"` // 当月订单数
|
||||
TotalCount int64 `json:"total_count"` // 总订单数
|
||||
YesterdayCount int64 `json:"yesterday_count"` // 昨日订单数
|
||||
ChangeRate float64 `json:"change_rate"` // 变化率(百分比)
|
||||
}
|
||||
// 营收统计
|
||||
AdminRevenueStatistics {
|
||||
TodayAmount float64 `json:"today_amount"` // 今日营收
|
||||
MonthAmount float64 `json:"month_amount"` // 当月营收
|
||||
TotalAmount float64 `json:"total_amount"` // 总营收
|
||||
YesterdayAmount float64 `json:"yesterday_amount"` // 昨日营收
|
||||
ChangeRate float64 `json:"change_rate"` // 变化率(百分比)
|
||||
}
|
||||
// 代理统计
|
||||
AdminAgentStatistics {
|
||||
TotalCount int64 `json:"total_count"` // 代理总数
|
||||
TodayNew int64 `json:"today_new"` // 今日新增
|
||||
MonthNew int64 `json:"month_new"` // 当月新增
|
||||
}
|
||||
// 利润统计
|
||||
AdminProfitStatistics {
|
||||
TodayProfit float64 `json:"today_profit"` // 今日利润
|
||||
MonthProfit float64 `json:"month_profit"` // 当月利润
|
||||
TotalProfit float64 `json:"total_profit"` // 总利润
|
||||
TodayProfitRate float64 `json:"today_profit_rate"` // 今日利润率
|
||||
MonthProfitRate float64 `json:"month_profit_rate"` // 当月利润率
|
||||
TotalProfitRate float64 `json:"total_profit_rate"` // 总利润率
|
||||
// 今日明细
|
||||
TodayDetail AdminProfitDetail `json:"today_detail"`
|
||||
// 当月明细
|
||||
MonthDetail AdminProfitDetail `json:"month_detail"`
|
||||
// 总计明细
|
||||
TotalDetail AdminProfitDetail `json:"total_detail"`
|
||||
}
|
||||
// 利润明细
|
||||
AdminProfitDetail {
|
||||
Revenue float64 `json:"revenue"` // 营收
|
||||
Commission float64 `json:"commission"` // 佣金
|
||||
Rebate float64 `json:"rebate"` // 返利
|
||||
CompanyTax float64 `json:"company_tax"` // 税务成本
|
||||
ApiCost float64 `json:"api_cost"` // API调用成本
|
||||
TaxIncome float64 `json:"tax_income"` // 提现收税
|
||||
Profit float64 `json:"profit"` // 利润
|
||||
ProfitRate float64 `json:"profit_rate"` // 利润率
|
||||
}
|
||||
// 趋势数据
|
||||
AdminTrendData {
|
||||
Date string `json:"date"` // 日期(格式:MM-DD)
|
||||
Value float64 `json:"value"` // 数值
|
||||
}
|
||||
)
|
||||
|
||||
@@ -251,6 +251,32 @@ service main {
|
||||
// 获取推广查询报告列表
|
||||
@handler GetPromotionQueryList
|
||||
get /promotion/query/list (GetPromotionQueryListReq) returns (GetPromotionQueryListResp)
|
||||
|
||||
// ============================================
|
||||
// 用户模块白名单相关接口
|
||||
// ============================================
|
||||
@handler GetWhitelistFeatures
|
||||
get /whitelist/features (GetWhitelistFeaturesReq) returns (GetWhitelistFeaturesResp)
|
||||
|
||||
// 创建白名单订单
|
||||
@handler CreateWhitelistOrder
|
||||
post /whitelist/order/create (CreateWhitelistOrderReq) returns (CreateWhitelistOrderResp)
|
||||
|
||||
// 获取用户白名单列表
|
||||
@handler GetWhitelistList
|
||||
get /whitelist/list (GetWhitelistListReq) returns (GetWhitelistListResp)
|
||||
|
||||
// 检查模块是否已下架(用于显示下架按钮状态)
|
||||
@handler CheckFeatureWhitelistStatus
|
||||
get /whitelist/check (CheckFeatureWhitelistStatusReq) returns (CheckFeatureWhitelistStatusResp)
|
||||
|
||||
// 下架单个模块(创建订单并支付)
|
||||
@handler OfflineFeature
|
||||
post /whitelist/offline (OfflineFeatureReq) returns (OfflineFeatureResp)
|
||||
|
||||
// 检查订单是否属于当前代理推广
|
||||
@handler CheckOrderAgent
|
||||
get /order/agent (CheckOrderAgentReq) returns (CheckOrderAgentResp)
|
||||
}
|
||||
|
||||
type (
|
||||
@@ -587,6 +613,81 @@ type (
|
||||
CreateTime string `json:"create_time"` // 创建时间
|
||||
QueryState string `json:"query_state"` // 查询状态
|
||||
}
|
||||
// ============================================
|
||||
// 用户模块白名单相关类型
|
||||
// ============================================
|
||||
GetWhitelistFeaturesReq {}
|
||||
GetWhitelistFeaturesResp {
|
||||
List []WhitelistFeatureItem `json:"list"` // 可屏蔽的feature列表
|
||||
}
|
||||
WhitelistFeatureItem {
|
||||
FeatureId string `json:"feature_id"` // Feature的UUID
|
||||
FeatureApiId string `json:"feature_api_id"` // Feature的API标识
|
||||
FeatureName string `json:"feature_name"` // Feature的名称
|
||||
WhitelistPrice float64 `json:"whitelist_price"` // 屏蔽价格(单位:元)
|
||||
}
|
||||
CreateWhitelistOrderReq {
|
||||
IdCard string `json:"id_card"` // 身份证号(查询对象标识)
|
||||
FeatureIds []string `json:"feature_ids"` // 要屏蔽的feature ID列表
|
||||
OrderId string `json:"order_id,optional"` // 关联的查询订单ID(可选)
|
||||
}
|
||||
CreateWhitelistOrderResp {
|
||||
OrderId string `json:"order_id"` // 订单ID
|
||||
OrderNo string `json:"order_no"` // 订单号
|
||||
TotalAmount float64 `json:"total_amount"` // 总金额
|
||||
}
|
||||
GetWhitelistListReq {
|
||||
Page int64 `form:"page"` // 页码
|
||||
PageSize int64 `form:"page_size"` // 每页数量
|
||||
IdCard string `form:"id_card,optional"` // 身份证号(可选,用于筛选)
|
||||
}
|
||||
GetWhitelistListResp {
|
||||
Total int64 `json:"total"` // 总数
|
||||
List []WhitelistItem `json:"list"` // 列表
|
||||
}
|
||||
WhitelistItem {
|
||||
Id string `json:"id"` // 白名单记录ID
|
||||
IdCard string `json:"id_card"` // 身份证号
|
||||
FeatureId string `json:"feature_id"` // Feature的UUID
|
||||
FeatureApiId string `json:"feature_api_id"` // Feature的API标识
|
||||
FeatureName string `json:"feature_name"` // Feature的名称
|
||||
Amount float64 `json:"amount"` // 费用
|
||||
Status int64 `json:"status"` // 状态:1=生效,2=已失效
|
||||
StatusText string `json:"status_text"` // 状态文本
|
||||
CreateTime string `json:"create_time"` // 创建时间
|
||||
}
|
||||
// 检查模块白名单状态请求
|
||||
CheckFeatureWhitelistStatusReq {
|
||||
IdCard string `form:"id_card"` // 身份证号
|
||||
FeatureApiId string `form:"feature_api_id"` // Feature的API标识
|
||||
QueryId string `form:"query_id,optional"` // 查询记录ID(可选,用于检查报告数据是否已删除)
|
||||
}
|
||||
// 检查模块白名单状态响应
|
||||
CheckFeatureWhitelistStatusResp {
|
||||
IsWhitelisted bool `json:"is_whitelisted"` // 是否在白名单中
|
||||
WhitelistPrice float64 `json:"whitelist_price"` // 屏蔽价格(单位:元),如果为0表示不支持下架
|
||||
FeatureId string `json:"feature_id"` // Feature的UUID
|
||||
DataDeleted bool `json:"data_deleted"` // 报告数据是否已删除(仅当提供了query_id时有效)
|
||||
}
|
||||
// 下架单个模块请求
|
||||
OfflineFeatureReq {
|
||||
FeatureApiId string `json:"feature_api_id"` // Feature的API标识
|
||||
QueryId string `json:"query_id"` // 查询记录ID(Query表的ID,必选)
|
||||
}
|
||||
// 下架单个模块响应
|
||||
OfflineFeatureResp {
|
||||
Success bool `json:"success"` // 是否已完成下架
|
||||
NeedPay bool `json:"need_pay"` // 是否需要发起支付
|
||||
Amount float64 `json:"amount"` // 需要支付的金额(单位:元),0表示无需支付
|
||||
}
|
||||
// 检查订单是否属于当前代理请求
|
||||
CheckOrderAgentReq {
|
||||
OrderId string `form:"order_id"` // 订单ID
|
||||
}
|
||||
// 检查订单是否属于当前代理响应
|
||||
CheckOrderAgentResp {
|
||||
IsAgentOrder bool `json:"is_agent_order"` // 是否是当前代理推广的订单
|
||||
}
|
||||
)
|
||||
|
||||
// ============================================
|
||||
|
||||
@@ -28,3 +28,4 @@ import "./admin/admin_query.api"
|
||||
import "./admin/admin_agent.api"
|
||||
import "./admin/admin_api.api"
|
||||
import "./admin/admin_role_api.api"
|
||||
import "./admin/dashboard.api"
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package admin_dashboard
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"bdqr-server/app/main/api/internal/logic/admin_dashboard"
|
||||
"bdqr-server/app/main/api/internal/svc"
|
||||
"bdqr-server/common/result"
|
||||
)
|
||||
|
||||
func AdminGetDashboardStatisticsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
l := admin_dashboard.NewAdminGetDashboardStatisticsLogic(r.Context(), svcCtx)
|
||||
resp, err := l.AdminGetDashboardStatistics()
|
||||
result.HttpResult(r, w, resp, err)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package agent
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"bdqr-server/app/main/api/internal/logic/agent"
|
||||
"bdqr-server/app/main/api/internal/svc"
|
||||
"bdqr-server/app/main/api/internal/types"
|
||||
"bdqr-server/common/result"
|
||||
"bdqr-server/pkg/lzkit/validator"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
)
|
||||
|
||||
func CheckFeatureWhitelistStatusHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.CheckFeatureWhitelistStatusReq
|
||||
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 := agent.NewCheckFeatureWhitelistStatusLogic(r.Context(), svcCtx)
|
||||
resp, err := l.CheckFeatureWhitelistStatus(&req)
|
||||
result.HttpResult(r, w, resp, err)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package agent
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"bdqr-server/app/main/api/internal/logic/agent"
|
||||
"bdqr-server/app/main/api/internal/svc"
|
||||
"bdqr-server/app/main/api/internal/types"
|
||||
"bdqr-server/common/result"
|
||||
"bdqr-server/pkg/lzkit/validator"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
)
|
||||
|
||||
func CheckOrderAgentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.CheckOrderAgentReq
|
||||
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 := agent.NewCheckOrderAgentLogic(r.Context(), svcCtx)
|
||||
resp, err := l.CheckOrderAgent(&req)
|
||||
result.HttpResult(r, w, resp, err)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package agent
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"bdqr-server/app/main/api/internal/logic/agent"
|
||||
"bdqr-server/app/main/api/internal/svc"
|
||||
"bdqr-server/app/main/api/internal/types"
|
||||
"bdqr-server/common/result"
|
||||
"bdqr-server/pkg/lzkit/validator"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
)
|
||||
|
||||
func CreateWhitelistOrderHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.CreateWhitelistOrderReq
|
||||
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 := agent.NewCreateWhitelistOrderLogic(r.Context(), svcCtx)
|
||||
resp, err := l.CreateWhitelistOrder(&req)
|
||||
result.HttpResult(r, w, resp, err)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package agent
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"bdqr-server/app/main/api/internal/logic/agent"
|
||||
"bdqr-server/app/main/api/internal/svc"
|
||||
"bdqr-server/app/main/api/internal/types"
|
||||
"bdqr-server/common/result"
|
||||
"bdqr-server/pkg/lzkit/validator"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
)
|
||||
|
||||
func GetWhitelistFeaturesHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.GetWhitelistFeaturesReq
|
||||
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 := agent.NewGetWhitelistFeaturesLogic(r.Context(), svcCtx)
|
||||
resp, err := l.GetWhitelistFeatures(&req)
|
||||
result.HttpResult(r, w, resp, err)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package agent
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"bdqr-server/app/main/api/internal/logic/agent"
|
||||
"bdqr-server/app/main/api/internal/svc"
|
||||
"bdqr-server/app/main/api/internal/types"
|
||||
"bdqr-server/common/result"
|
||||
"bdqr-server/pkg/lzkit/validator"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
)
|
||||
|
||||
func GetWhitelistListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.GetWhitelistListReq
|
||||
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 := agent.NewGetWhitelistListLogic(r.Context(), svcCtx)
|
||||
resp, err := l.GetWhitelistList(&req)
|
||||
result.HttpResult(r, w, resp, err)
|
||||
}
|
||||
}
|
||||
29
app/main/api/internal/handler/agent/offlinefeaturehandler.go
Normal file
29
app/main/api/internal/handler/agent/offlinefeaturehandler.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package agent
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"bdqr-server/app/main/api/internal/logic/agent"
|
||||
"bdqr-server/app/main/api/internal/svc"
|
||||
"bdqr-server/app/main/api/internal/types"
|
||||
"bdqr-server/common/result"
|
||||
"bdqr-server/pkg/lzkit/validator"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
)
|
||||
|
||||
func OfflineFeatureHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.OfflineFeatureReq
|
||||
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 := agent.NewOfflineFeatureLogic(r.Context(), svcCtx)
|
||||
resp, err := l.OfflineFeature(&req)
|
||||
result.HttpResult(r, w, resp, err)
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
admin_agent "bdqr-server/app/main/api/internal/handler/admin_agent"
|
||||
admin_api "bdqr-server/app/main/api/internal/handler/admin_api"
|
||||
admin_auth "bdqr-server/app/main/api/internal/handler/admin_auth"
|
||||
admin_dashboard "bdqr-server/app/main/api/internal/handler/admin_dashboard"
|
||||
admin_feature "bdqr-server/app/main/api/internal/handler/admin_feature"
|
||||
admin_menu "bdqr-server/app/main/api/internal/handler/admin_menu"
|
||||
admin_notification "bdqr-server/app/main/api/internal/handler/admin_notification"
|
||||
@@ -172,6 +173,20 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||
rest.WithPrefix("/api/v1/admin/auth"),
|
||||
)
|
||||
|
||||
server.AddRoutes(
|
||||
rest.WithMiddlewares(
|
||||
[]rest.Middleware{serverCtx.AdminAuthInterceptor},
|
||||
[]rest.Route{
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/statistics",
|
||||
Handler: admin_dashboard.AdminGetDashboardStatisticsHandler(serverCtx),
|
||||
},
|
||||
}...,
|
||||
),
|
||||
rest.WithPrefix("/api/v1/admin/dashboard"),
|
||||
)
|
||||
|
||||
server.AddRoutes(
|
||||
rest.WithMiddlewares(
|
||||
[]rest.Middleware{serverCtx.AdminAuthInterceptor},
|
||||
@@ -666,6 +681,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||
Path: "/level/privilege",
|
||||
Handler: agent.GetLevelPrivilegeHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/order/agent",
|
||||
Handler: agent.CheckOrderAgentHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/product_config",
|
||||
@@ -731,6 +751,31 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||
Path: "/upgrade/subordinate",
|
||||
Handler: agent.UpgradeSubordinateHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/whitelist/check",
|
||||
Handler: agent.CheckFeatureWhitelistStatusHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/whitelist/features",
|
||||
Handler: agent.GetWhitelistFeaturesHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/whitelist/list",
|
||||
Handler: agent.GetWhitelistListHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Path: "/whitelist/offline",
|
||||
Handler: agent.OfflineFeatureHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Path: "/whitelist/order/create",
|
||||
Handler: agent.CreateWhitelistOrderHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Path: "/withdrawal/apply",
|
||||
|
||||
@@ -0,0 +1,462 @@
|
||||
package admin_dashboard
|
||||
|
||||
import (
|
||||
"bdqr-server/app/main/api/internal/service"
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"bdqr-server/app/main/api/internal/svc"
|
||||
"bdqr-server/app/main/api/internal/types"
|
||||
"bdqr-server/common/globalkey"
|
||||
"bdqr-server/common/xerr"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type AdminGetDashboardStatisticsLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewAdminGetDashboardStatisticsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AdminGetDashboardStatisticsLogic {
|
||||
return &AdminGetDashboardStatisticsLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *AdminGetDashboardStatisticsLogic) AdminGetDashboardStatistics() (resp *types.AdminGetDashboardStatisticsResp, err error) {
|
||||
// 使用Asia/Shanghai时区
|
||||
loc, _ := time.LoadLocation("Asia/Shanghai")
|
||||
now := time.Now().In(loc)
|
||||
|
||||
// 计算时间范围
|
||||
todayStart := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, loc)
|
||||
todayEnd := todayStart.AddDate(0, 0, 1)
|
||||
yesterdayStart := todayStart.AddDate(0, 0, -1)
|
||||
yesterdayEnd := todayStart
|
||||
monthStart := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, loc)
|
||||
monthEnd := monthStart.AddDate(0, 1, 0)
|
||||
|
||||
// 1. 订单统计
|
||||
orderStats, err := l.calculateOrderStatistics(todayStart, todayEnd, yesterdayStart, yesterdayEnd, monthStart, monthEnd)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "计算订单统计失败, %v", err)
|
||||
}
|
||||
|
||||
// 2. 营收统计
|
||||
revenueStats, err := l.calculateRevenueStatistics(todayStart, todayEnd, yesterdayStart, yesterdayEnd, monthStart, monthEnd)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "计算营收统计失败, %v", err)
|
||||
}
|
||||
|
||||
// 3. 代理统计
|
||||
agentStats, err := l.calculateAgentStatistics(todayStart, monthStart)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "计算代理统计失败, %v", err)
|
||||
}
|
||||
|
||||
// 4. 利润统计
|
||||
profitStats, err := l.calculateProfitStatistics(todayStart, todayEnd, monthStart, monthEnd, revenueStats)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "计算利润统计失败, %v", err)
|
||||
}
|
||||
|
||||
// 5. 订单趋势(最近7天)
|
||||
orderTrend, err := l.calculateOrderTrend(now, loc)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "计算订单趋势失败, %v", err)
|
||||
}
|
||||
|
||||
// 6. 营收趋势(最近7天)
|
||||
revenueTrend, err := l.calculateRevenueTrend(now, loc)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "计算营收趋势失败, %v", err)
|
||||
}
|
||||
|
||||
return &types.AdminGetDashboardStatisticsResp{
|
||||
OrderStats: orderStats,
|
||||
RevenueStats: revenueStats,
|
||||
AgentStats: agentStats,
|
||||
ProfitStats: profitStats,
|
||||
OrderTrend: orderTrend,
|
||||
RevenueTrend: revenueTrend,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// calculateOrderStatistics 计算订单统计
|
||||
func (l *AdminGetDashboardStatisticsLogic) calculateOrderStatistics(todayStart, todayEnd, yesterdayStart, yesterdayEnd, monthStart, monthEnd time.Time) (types.AdminOrderStatistics, error) {
|
||||
var stats types.AdminOrderStatistics
|
||||
|
||||
// 今日订单数
|
||||
todayBuilder := l.svcCtx.OrderModel.SelectBuilder().
|
||||
Where("status = ? AND create_time >= ? AND create_time < ?", "paid", todayStart, todayEnd)
|
||||
todayCount, err := l.svcCtx.OrderModel.FindCount(l.ctx, todayBuilder, "id")
|
||||
if err != nil {
|
||||
return stats, err
|
||||
}
|
||||
stats.TodayCount = todayCount
|
||||
|
||||
// 昨日订单数
|
||||
yesterdayBuilder := l.svcCtx.OrderModel.SelectBuilder().
|
||||
Where("status = ? AND create_time >= ? AND create_time < ?", "paid", yesterdayStart, yesterdayEnd)
|
||||
yesterdayCount, err := l.svcCtx.OrderModel.FindCount(l.ctx, yesterdayBuilder, "id")
|
||||
if err != nil {
|
||||
return stats, err
|
||||
}
|
||||
stats.YesterdayCount = yesterdayCount
|
||||
|
||||
// 当月订单数
|
||||
monthBuilder := l.svcCtx.OrderModel.SelectBuilder().
|
||||
Where("status = ? AND create_time >= ? AND create_time < ?", "paid", monthStart, monthEnd)
|
||||
monthCount, err := l.svcCtx.OrderModel.FindCount(l.ctx, monthBuilder, "id")
|
||||
if err != nil {
|
||||
return stats, err
|
||||
}
|
||||
stats.MonthCount = monthCount
|
||||
|
||||
// 总订单数
|
||||
totalBuilder := l.svcCtx.OrderModel.SelectBuilder().
|
||||
Where("status = ?", "paid")
|
||||
totalCount, err := l.svcCtx.OrderModel.FindCount(l.ctx, totalBuilder, "id")
|
||||
if err != nil {
|
||||
return stats, err
|
||||
}
|
||||
stats.TotalCount = totalCount
|
||||
|
||||
// 计算变化率
|
||||
if stats.YesterdayCount > 0 {
|
||||
stats.ChangeRate = float64(stats.TodayCount-stats.YesterdayCount) / float64(stats.YesterdayCount) * 100
|
||||
} else if stats.TodayCount > 0 {
|
||||
stats.ChangeRate = 100 // 从0增长到有值,算100%增长
|
||||
}
|
||||
|
||||
return stats, nil
|
||||
}
|
||||
|
||||
// calculateRevenueStatistics 计算营收统计
|
||||
func (l *AdminGetDashboardStatisticsLogic) calculateRevenueStatistics(todayStart, todayEnd, yesterdayStart, yesterdayEnd, monthStart, monthEnd time.Time) (types.AdminRevenueStatistics, error) {
|
||||
var stats types.AdminRevenueStatistics
|
||||
|
||||
// 今日营收
|
||||
todayBuilder := l.svcCtx.OrderModel.SelectBuilder().
|
||||
Where("status = ? AND create_time >= ? AND create_time < ?", "paid", todayStart, todayEnd)
|
||||
todayAmount, err := l.svcCtx.OrderModel.FindSum(l.ctx, todayBuilder, "amount")
|
||||
if err != nil {
|
||||
return stats, err
|
||||
}
|
||||
stats.TodayAmount = todayAmount
|
||||
|
||||
// 昨日营收
|
||||
yesterdayBuilder := l.svcCtx.OrderModel.SelectBuilder().
|
||||
Where("status = ? AND create_time >= ? AND create_time < ?", "paid", yesterdayStart, yesterdayEnd)
|
||||
yesterdayAmount, err := l.svcCtx.OrderModel.FindSum(l.ctx, yesterdayBuilder, "amount")
|
||||
if err != nil {
|
||||
return stats, err
|
||||
}
|
||||
stats.YesterdayAmount = yesterdayAmount
|
||||
|
||||
// 当月营收
|
||||
monthBuilder := l.svcCtx.OrderModel.SelectBuilder().
|
||||
Where("status = ? AND create_time >= ? AND create_time < ?", "paid", monthStart, monthEnd)
|
||||
monthAmount, err := l.svcCtx.OrderModel.FindSum(l.ctx, monthBuilder, "amount")
|
||||
if err != nil {
|
||||
return stats, err
|
||||
}
|
||||
stats.MonthAmount = monthAmount
|
||||
|
||||
// 总营收
|
||||
totalBuilder := l.svcCtx.OrderModel.SelectBuilder().
|
||||
Where("status = ?", "paid")
|
||||
totalAmount, err := l.svcCtx.OrderModel.FindSum(l.ctx, totalBuilder, "amount")
|
||||
if err != nil {
|
||||
return stats, err
|
||||
}
|
||||
stats.TotalAmount = totalAmount
|
||||
|
||||
// 计算变化率
|
||||
if stats.YesterdayAmount > 0 {
|
||||
stats.ChangeRate = (stats.TodayAmount - stats.YesterdayAmount) / stats.YesterdayAmount * 100
|
||||
} else if stats.TodayAmount > 0 {
|
||||
stats.ChangeRate = 100 // 从0增长到有值,算100%增长
|
||||
}
|
||||
|
||||
return stats, nil
|
||||
}
|
||||
|
||||
// calculateAgentStatistics 计算代理统计
|
||||
func (l *AdminGetDashboardStatisticsLogic) calculateAgentStatistics(todayStart, monthStart time.Time) (types.AdminAgentStatistics, error) {
|
||||
var stats types.AdminAgentStatistics
|
||||
|
||||
// 代理总数
|
||||
totalBuilder := l.svcCtx.AgentModel.SelectBuilder()
|
||||
totalCount, err := l.svcCtx.AgentModel.FindCount(l.ctx, totalBuilder, "id")
|
||||
if err != nil {
|
||||
return stats, err
|
||||
}
|
||||
stats.TotalCount = totalCount
|
||||
|
||||
// 今日新增
|
||||
todayBuilder := l.svcCtx.AgentModel.SelectBuilder().
|
||||
Where("create_time >= ?", todayStart)
|
||||
todayNew, err := l.svcCtx.AgentModel.FindCount(l.ctx, todayBuilder, "id")
|
||||
if err != nil {
|
||||
return stats, err
|
||||
}
|
||||
stats.TodayNew = todayNew
|
||||
|
||||
// 当月新增
|
||||
monthBuilder := l.svcCtx.AgentModel.SelectBuilder().
|
||||
Where("create_time >= ?", monthStart)
|
||||
monthNew, err := l.svcCtx.AgentModel.FindCount(l.ctx, monthBuilder, "id")
|
||||
if err != nil {
|
||||
return stats, err
|
||||
}
|
||||
stats.MonthNew = monthNew
|
||||
|
||||
return stats, nil
|
||||
}
|
||||
|
||||
// calculateProfitStatistics 计算利润统计
|
||||
func (l *AdminGetDashboardStatisticsLogic) calculateProfitStatistics(todayStart, todayEnd, monthStart, monthEnd time.Time, revenueStats types.AdminRevenueStatistics) (types.AdminProfitStatistics, error) {
|
||||
var stats types.AdminProfitStatistics
|
||||
|
||||
// 税务成本比例(6%)
|
||||
const companyTaxRate = 0.06
|
||||
|
||||
// 今日利润计算
|
||||
// 今日营收
|
||||
todayRevenue := revenueStats.TodayAmount
|
||||
// 今日佣金
|
||||
todayCommissionBuilder := l.svcCtx.AgentCommissionModel.SelectBuilder().
|
||||
Where("del_state = ? AND status != ? AND create_time >= ? AND create_time < ?", globalkey.DelStateNo, 3, todayStart, todayEnd)
|
||||
todayCommission, err := l.svcCtx.AgentCommissionModel.FindSum(l.ctx, todayCommissionBuilder, "amount")
|
||||
if err != nil {
|
||||
return stats, err
|
||||
}
|
||||
// 今日返利
|
||||
todayRebateBuilder := l.svcCtx.AgentRebateModel.SelectBuilder().
|
||||
Where("del_state = ? AND status != ? AND create_time >= ? AND create_time < ?", globalkey.DelStateNo, 3, todayStart, todayEnd)
|
||||
todayRebate, err := l.svcCtx.AgentRebateModel.FindSum(l.ctx, todayRebateBuilder, "rebate_amount")
|
||||
if err != nil {
|
||||
return stats, err
|
||||
}
|
||||
// 今日税务成本(订单金额的6%)
|
||||
todayCompanyTax := todayRevenue * companyTaxRate
|
||||
// 今日提现收税(agent_withdrawal_tax表中tax_status=2的tax_amount总和)
|
||||
todayTaxIncomeBuilder := l.svcCtx.AgentWithdrawalTaxModel.SelectBuilder().
|
||||
Where("del_state = ? AND tax_status = ? AND create_time >= ? AND create_time < ?", globalkey.DelStateNo, 2, todayStart, todayEnd)
|
||||
todayTaxIncome, err := l.svcCtx.AgentWithdrawalTaxModel.FindSum(l.ctx, todayTaxIncomeBuilder, "tax_amount")
|
||||
if err != nil {
|
||||
return stats, err
|
||||
}
|
||||
// 今日API调用成本
|
||||
todayApiCost := 0.0
|
||||
if l.svcCtx.TianyuanapiCallLogService != nil {
|
||||
logx.Infof("开始获取今日API调用成本,时间范围: %v 到 %v", todayStart, todayEnd)
|
||||
todayApiStats, err := l.svcCtx.TianyuanapiCallLogService.GetStatistics(l.ctx, service.StatisticsFilter{
|
||||
StartDate: todayStart,
|
||||
EndDate: todayEnd,
|
||||
})
|
||||
if err != nil {
|
||||
logx.Errorf("获取今日API调用成本失败: %v", err)
|
||||
} else {
|
||||
todayApiCost = todayApiStats.TotalCost
|
||||
logx.Infof("今日API调用成本统计完成,总成本: %f", todayApiCost)
|
||||
}
|
||||
} else {
|
||||
logx.Errorf("TianyuanapiCallLogService 未初始化,无法获取API调用成本")
|
||||
}
|
||||
// 今日利润 = 营收 - 佣金 - 返利 - 税务成本 - API调用成本 + 提现收税
|
||||
stats.TodayProfit = todayRevenue - todayCommission - todayRebate - todayCompanyTax - todayApiCost + todayTaxIncome
|
||||
if todayRevenue > 0 {
|
||||
stats.TodayProfitRate = stats.TodayProfit / todayRevenue * 100
|
||||
}
|
||||
// 今日明细
|
||||
stats.TodayDetail = types.AdminProfitDetail{
|
||||
Revenue: todayRevenue,
|
||||
Commission: todayCommission,
|
||||
Rebate: todayRebate,
|
||||
CompanyTax: todayCompanyTax,
|
||||
ApiCost: todayApiCost,
|
||||
TaxIncome: todayTaxIncome,
|
||||
Profit: stats.TodayProfit,
|
||||
ProfitRate: stats.TodayProfitRate,
|
||||
}
|
||||
|
||||
// 当月利润计算
|
||||
// 当月营收
|
||||
monthRevenue := revenueStats.MonthAmount
|
||||
// 当月佣金
|
||||
monthCommissionBuilder := l.svcCtx.AgentCommissionModel.SelectBuilder().
|
||||
Where("del_state = ? AND status != ? AND create_time >= ? AND create_time < ?", globalkey.DelStateNo, 3, monthStart, monthEnd)
|
||||
monthCommission, err := l.svcCtx.AgentCommissionModel.FindSum(l.ctx, monthCommissionBuilder, "amount")
|
||||
if err != nil {
|
||||
return stats, err
|
||||
}
|
||||
// 当月返利
|
||||
monthRebateBuilder := l.svcCtx.AgentRebateModel.SelectBuilder().
|
||||
Where("del_state = ? AND status != ? AND create_time >= ? AND create_time < ?", globalkey.DelStateNo, 3, monthStart, monthEnd)
|
||||
monthRebate, err := l.svcCtx.AgentRebateModel.FindSum(l.ctx, monthRebateBuilder, "rebate_amount")
|
||||
if err != nil {
|
||||
return stats, err
|
||||
}
|
||||
// 当月税务成本
|
||||
monthCompanyTax := monthRevenue * companyTaxRate
|
||||
// 当月提现收税
|
||||
monthTaxIncomeBuilder := l.svcCtx.AgentWithdrawalTaxModel.SelectBuilder().
|
||||
Where("del_state = ? AND tax_status = ? AND create_time >= ? AND create_time < ?", globalkey.DelStateNo, 2, monthStart, monthEnd)
|
||||
monthTaxIncome, err := l.svcCtx.AgentWithdrawalTaxModel.FindSum(l.ctx, monthTaxIncomeBuilder, "tax_amount")
|
||||
if err != nil {
|
||||
return stats, err
|
||||
}
|
||||
// 当月API调用成本
|
||||
monthApiCost := 0.0
|
||||
if l.svcCtx.TianyuanapiCallLogService != nil {
|
||||
logx.Infof("开始获取当月API调用成本,时间范围: %v 到 %v", monthStart, monthEnd)
|
||||
monthApiStats, err := l.svcCtx.TianyuanapiCallLogService.GetStatistics(l.ctx, service.StatisticsFilter{
|
||||
StartDate: monthStart,
|
||||
EndDate: monthEnd,
|
||||
})
|
||||
if err != nil {
|
||||
logx.Errorf("获取当月API调用成本失败: %v", err)
|
||||
} else {
|
||||
monthApiCost = monthApiStats.TotalCost
|
||||
logx.Infof("当月API调用成本统计完成,总成本: %f", monthApiCost)
|
||||
}
|
||||
} else {
|
||||
logx.Errorf("TianyuanapiCallLogService 未初始化,无法获取API调用成本")
|
||||
}
|
||||
// 当月利润
|
||||
stats.MonthProfit = monthRevenue - monthCommission - monthRebate - monthCompanyTax - monthApiCost + monthTaxIncome
|
||||
if monthRevenue > 0 {
|
||||
stats.MonthProfitRate = stats.MonthProfit / monthRevenue * 100
|
||||
}
|
||||
// 当月明细
|
||||
stats.MonthDetail = types.AdminProfitDetail{
|
||||
Revenue: monthRevenue,
|
||||
Commission: monthCommission,
|
||||
Rebate: monthRebate,
|
||||
CompanyTax: monthCompanyTax,
|
||||
ApiCost: monthApiCost,
|
||||
TaxIncome: monthTaxIncome,
|
||||
Profit: stats.MonthProfit,
|
||||
ProfitRate: stats.MonthProfitRate,
|
||||
}
|
||||
|
||||
// 总利润计算
|
||||
// 总营收
|
||||
totalRevenue := revenueStats.TotalAmount
|
||||
// 总佣金
|
||||
totalCommissionBuilder := l.svcCtx.AgentCommissionModel.SelectBuilder().
|
||||
Where("del_state = ? AND status != ?", globalkey.DelStateNo, 3)
|
||||
totalCommission, err := l.svcCtx.AgentCommissionModel.FindSum(l.ctx, totalCommissionBuilder, "amount")
|
||||
if err != nil {
|
||||
return stats, err
|
||||
}
|
||||
// 总返利
|
||||
totalRebateBuilder := l.svcCtx.AgentRebateModel.SelectBuilder().
|
||||
Where("status != ?", 3)
|
||||
totalRebate, err := l.svcCtx.AgentRebateModel.FindSum(l.ctx, totalRebateBuilder, "rebate_amount")
|
||||
if err != nil {
|
||||
return stats, err
|
||||
}
|
||||
// 总税务成本
|
||||
totalCompanyTax := totalRevenue * companyTaxRate
|
||||
// 总提现收税
|
||||
totalTaxIncomeBuilder := l.svcCtx.AgentWithdrawalTaxModel.SelectBuilder().
|
||||
Where("tax_status = ?", 2)
|
||||
totalTaxIncome, err := l.svcCtx.AgentWithdrawalTaxModel.FindSum(l.ctx, totalTaxIncomeBuilder, "tax_amount")
|
||||
if err != nil {
|
||||
return stats, err
|
||||
}
|
||||
// 总API调用成本
|
||||
totalApiCost := 0.0
|
||||
if l.svcCtx.TianyuanapiCallLogService != nil {
|
||||
logx.Infof("开始获取总API调用成本(无时间限制)")
|
||||
totalApiStats, err := l.svcCtx.TianyuanapiCallLogService.GetStatistics(l.ctx, service.StatisticsFilter{})
|
||||
if err != nil {
|
||||
logx.Errorf("获取总API调用成本失败: %v", err)
|
||||
} else {
|
||||
totalApiCost = totalApiStats.TotalCost
|
||||
logx.Infof("总API调用成本统计完成,总成本: %f", totalApiCost)
|
||||
}
|
||||
} else {
|
||||
logx.Errorf("TianyuanapiCallLogService 未初始化,无法获取API调用成本")
|
||||
}
|
||||
// 总利润
|
||||
stats.TotalProfit = totalRevenue - totalCommission - totalRebate - totalCompanyTax - totalApiCost + totalTaxIncome
|
||||
if totalRevenue > 0 {
|
||||
stats.TotalProfitRate = stats.TotalProfit / totalRevenue * 100
|
||||
}
|
||||
// 总计明细
|
||||
stats.TotalDetail = types.AdminProfitDetail{
|
||||
Revenue: totalRevenue,
|
||||
Commission: totalCommission,
|
||||
Rebate: totalRebate,
|
||||
CompanyTax: totalCompanyTax,
|
||||
ApiCost: totalApiCost,
|
||||
TaxIncome: totalTaxIncome,
|
||||
Profit: stats.TotalProfit,
|
||||
ProfitRate: stats.TotalProfitRate,
|
||||
}
|
||||
|
||||
return stats, nil
|
||||
}
|
||||
|
||||
// calculateOrderTrend 计算订单趋势(最近7天)
|
||||
func (l *AdminGetDashboardStatisticsLogic) calculateOrderTrend(now time.Time, loc *time.Location) ([]types.AdminTrendData, error) {
|
||||
var trend []types.AdminTrendData
|
||||
|
||||
// 计算最近7天的日期
|
||||
for i := 6; i >= 0; i-- {
|
||||
date := now.AddDate(0, 0, -i)
|
||||
dateStart := time.Date(date.Year(), date.Month(), date.Day(), 0, 0, 0, 0, loc)
|
||||
dateEnd := dateStart.AddDate(0, 0, 1)
|
||||
|
||||
// 查询当天的订单数
|
||||
builder := l.svcCtx.OrderModel.SelectBuilder().
|
||||
Where("status = ? AND create_time >= ? AND create_time < ?", "paid", dateStart, dateEnd)
|
||||
count, err := l.svcCtx.OrderModel.FindCount(l.ctx, builder, "id")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
trend = append(trend, types.AdminTrendData{
|
||||
Date: date.Format("01-02"),
|
||||
Value: float64(count),
|
||||
})
|
||||
}
|
||||
|
||||
return trend, nil
|
||||
}
|
||||
|
||||
// calculateRevenueTrend 计算营收趋势(最近7天)
|
||||
func (l *AdminGetDashboardStatisticsLogic) calculateRevenueTrend(now time.Time, loc *time.Location) ([]types.AdminTrendData, error) {
|
||||
var trend []types.AdminTrendData
|
||||
|
||||
// 计算最近7天的日期
|
||||
for i := 6; i >= 0; i-- {
|
||||
date := now.AddDate(0, 0, -i)
|
||||
dateStart := time.Date(date.Year(), date.Month(), date.Day(), 0, 0, 0, 0, loc)
|
||||
dateEnd := dateStart.AddDate(0, 0, 1)
|
||||
|
||||
// 查询当天的营收
|
||||
builder := l.svcCtx.OrderModel.SelectBuilder().
|
||||
Where("status = ? AND create_time >= ? AND create_time < ?", "paid", dateStart, dateEnd)
|
||||
amount, err := l.svcCtx.OrderModel.FindSum(l.ctx, builder, "amount")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
trend = append(trend, types.AdminTrendData{
|
||||
Date: date.Format("01-02"),
|
||||
Value: amount,
|
||||
})
|
||||
}
|
||||
|
||||
return trend, nil
|
||||
}
|
||||
@@ -1,20 +1,20 @@
|
||||
package admin_order
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"time"
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"bdqr-server/app/main/api/internal/svc"
|
||||
"bdqr-server/app/main/api/internal/types"
|
||||
"bdqr-server/app/main/model"
|
||||
"bdqr-server/common/xerr"
|
||||
"bdqr-server/app/main/api/internal/svc"
|
||||
"bdqr-server/app/main/api/internal/types"
|
||||
"bdqr-server/app/main/model"
|
||||
"bdqr-server/common/xerr"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
"github.com/google/uuid"
|
||||
"github.com/google/uuid"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -133,18 +133,18 @@ func (l *AdminRefundOrderLogic) handleWechatRefund(order *model.Order, req *type
|
||||
func (l *AdminRefundOrderLogic) createRefundRecordAndUpdateOrder(order *model.Order, req *types.AdminRefundOrderReq, refundNo, platformRefundId, orderStatus, refundStatus string) error {
|
||||
return l.svcCtx.OrderModel.Trans(l.ctx, func(ctx context.Context, session sqlx.Session) error {
|
||||
// 创建退款记录
|
||||
refund := &model.OrderRefund{
|
||||
Id: uuid.NewString(),
|
||||
RefundNo: refundNo,
|
||||
PlatformRefundId: l.createNullString(platformRefundId),
|
||||
OrderId: order.Id,
|
||||
UserId: order.UserId,
|
||||
ProductId: order.ProductId,
|
||||
RefundAmount: req.RefundAmount,
|
||||
RefundReason: l.createNullString(req.RefundReason),
|
||||
Status: refundStatus, // 使用传入的状态,不再硬编码
|
||||
RefundTime: sql.NullTime{Time: time.Now(), Valid: true},
|
||||
}
|
||||
refund := &model.OrderRefund{
|
||||
Id: uuid.NewString(),
|
||||
RefundNo: refundNo,
|
||||
PlatformRefundId: l.createNullString(platformRefundId),
|
||||
OrderId: order.Id,
|
||||
UserId: order.UserId,
|
||||
ProductId: order.ProductId,
|
||||
RefundAmount: req.RefundAmount,
|
||||
RefundReason: l.createNullString(req.RefundReason),
|
||||
Status: refundStatus, // 使用传入的状态,不再硬编码
|
||||
RefundTime: sql.NullTime{Time: time.Now(), Valid: true},
|
||||
}
|
||||
|
||||
if _, err := l.svcCtx.OrderRefundModel.Insert(ctx, session, refund); err != nil {
|
||||
return fmt.Errorf("创建退款记录失败: %v", err)
|
||||
@@ -162,18 +162,18 @@ func (l *AdminRefundOrderLogic) createRefundRecordAndUpdateOrder(order *model.Or
|
||||
|
||||
// createRefundRecordOnly 仅创建退款记录,不更新订单状态(用于退款失败的情况)
|
||||
func (l *AdminRefundOrderLogic) createRefundRecordOnly(order *model.Order, req *types.AdminRefundOrderReq, refundNo, platformRefundId, refundStatus string) error {
|
||||
refund := &model.OrderRefund{
|
||||
Id: uuid.NewString(),
|
||||
RefundNo: refundNo,
|
||||
PlatformRefundId: l.createNullString(platformRefundId),
|
||||
OrderId: order.Id,
|
||||
UserId: order.UserId,
|
||||
ProductId: order.ProductId,
|
||||
RefundAmount: req.RefundAmount,
|
||||
RefundReason: l.createNullString(req.RefundReason),
|
||||
Status: refundStatus,
|
||||
RefundTime: sql.NullTime{Time: time.Now(), Valid: true},
|
||||
}
|
||||
refund := &model.OrderRefund{
|
||||
Id: uuid.NewString(),
|
||||
RefundNo: refundNo,
|
||||
PlatformRefundId: l.createNullString(platformRefundId),
|
||||
OrderId: order.Id,
|
||||
UserId: order.UserId,
|
||||
ProductId: order.ProductId,
|
||||
RefundAmount: req.RefundAmount,
|
||||
RefundReason: l.createNullString(req.RefundReason),
|
||||
Status: refundStatus,
|
||||
RefundTime: sql.NullTime{Time: time.Now(), Valid: true},
|
||||
}
|
||||
|
||||
_, err := l.svcCtx.OrderRefundModel.Insert(l.ctx, nil, refund)
|
||||
if err != nil {
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package agent
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"bdqr-server/app/main/api/internal/svc"
|
||||
"bdqr-server/app/main/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type CheckFeatureWhitelistStatusLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewCheckFeatureWhitelistStatusLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CheckFeatureWhitelistStatusLogic {
|
||||
return &CheckFeatureWhitelistStatusLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *CheckFeatureWhitelistStatusLogic) CheckFeatureWhitelistStatus(req *types.CheckFeatureWhitelistStatusReq) (resp *types.CheckFeatureWhitelistStatusResp, err error) {
|
||||
// todo: add your logic here and delete this line
|
||||
|
||||
return
|
||||
}
|
||||
30
app/main/api/internal/logic/agent/checkorderagentlogic.go
Normal file
30
app/main/api/internal/logic/agent/checkorderagentlogic.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package agent
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"bdqr-server/app/main/api/internal/svc"
|
||||
"bdqr-server/app/main/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type CheckOrderAgentLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewCheckOrderAgentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CheckOrderAgentLogic {
|
||||
return &CheckOrderAgentLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *CheckOrderAgentLogic) CheckOrderAgent(req *types.CheckOrderAgentReq) (resp *types.CheckOrderAgentResp, err error) {
|
||||
// todo: add your logic here and delete this line
|
||||
|
||||
return
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package agent
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"bdqr-server/app/main/api/internal/svc"
|
||||
"bdqr-server/app/main/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type CreateWhitelistOrderLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewCreateWhitelistOrderLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateWhitelistOrderLogic {
|
||||
return &CreateWhitelistOrderLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *CreateWhitelistOrderLogic) CreateWhitelistOrder(req *types.CreateWhitelistOrderReq) (resp *types.CreateWhitelistOrderResp, err error) {
|
||||
// todo: add your logic here and delete this line
|
||||
|
||||
return
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package agent
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"bdqr-server/app/main/api/internal/svc"
|
||||
"bdqr-server/app/main/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GetWhitelistFeaturesLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewGetWhitelistFeaturesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetWhitelistFeaturesLogic {
|
||||
return &GetWhitelistFeaturesLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetWhitelistFeaturesLogic) GetWhitelistFeatures(req *types.GetWhitelistFeaturesReq) (resp *types.GetWhitelistFeaturesResp, err error) {
|
||||
// todo: add your logic here and delete this line
|
||||
|
||||
return
|
||||
}
|
||||
30
app/main/api/internal/logic/agent/getwhitelistlistlogic.go
Normal file
30
app/main/api/internal/logic/agent/getwhitelistlistlogic.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package agent
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"bdqr-server/app/main/api/internal/svc"
|
||||
"bdqr-server/app/main/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GetWhitelistListLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewGetWhitelistListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetWhitelistListLogic {
|
||||
return &GetWhitelistListLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetWhitelistListLogic) GetWhitelistList(req *types.GetWhitelistListReq) (resp *types.GetWhitelistListResp, err error) {
|
||||
// todo: add your logic here and delete this line
|
||||
|
||||
return
|
||||
}
|
||||
30
app/main/api/internal/logic/agent/offlinefeaturelogic.go
Normal file
30
app/main/api/internal/logic/agent/offlinefeaturelogic.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package agent
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"bdqr-server/app/main/api/internal/svc"
|
||||
"bdqr-server/app/main/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type OfflineFeatureLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewOfflineFeatureLogic(ctx context.Context, svcCtx *svc.ServiceContext) *OfflineFeatureLogic {
|
||||
return &OfflineFeatureLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *OfflineFeatureLogic) OfflineFeature(req *types.OfflineFeatureReq) (resp *types.OfflineFeatureResp, err error) {
|
||||
// todo: add your logic here and delete this line
|
||||
|
||||
return
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
package query
|
||||
|
||||
import (
|
||||
"bdqr-server/common/xerr"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"bdqr-server/common/xerr"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
@@ -36,7 +36,7 @@ func (l *QuerySingleTestLogic) QuerySingleTest(req *types.QuerySingleTestReq) (r
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "单查测试, 序列化参数失败 : %d", err)
|
||||
}
|
||||
apiResp, err := l.svcCtx.ApiRequestService.PreprocessRequestApi(marshalParams, req.Api)
|
||||
apiResp, err := l.svcCtx.ApiRequestService.PreprocessRequestApi(l.ctx, marshalParams, req.Api)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "单查测试, 获取接口失败 : %d", err)
|
||||
}
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
package queue
|
||||
|
||||
import (
|
||||
"bdqr-server/app/main/api/internal/svc"
|
||||
"bdqr-server/app/main/api/internal/types"
|
||||
"bdqr-server/app/main/model"
|
||||
"bdqr-server/pkg/lzkit/crypto"
|
||||
"bdqr-server/pkg/lzkit/lzUtils"
|
||||
"context"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
@@ -8,11 +13,6 @@ import (
|
||||
"os"
|
||||
"regexp"
|
||||
"strings"
|
||||
"bdqr-server/app/main/api/internal/svc"
|
||||
"bdqr-server/app/main/api/internal/types"
|
||||
"bdqr-server/app/main/model"
|
||||
"bdqr-server/pkg/lzkit/crypto"
|
||||
"bdqr-server/pkg/lzkit/lzUtils"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/hibiken/asynq"
|
||||
@@ -158,7 +158,7 @@ func (l *PaySuccessNotifyUserHandler) ProcessTask(ctx context.Context, t *asynq.
|
||||
encryptData = encryptedEmptyData
|
||||
} else {
|
||||
// 正常模式:调用API请求服务
|
||||
combinedResponse, err := l.svcCtx.ApiRequestService.ProcessRequests(decryptData, product.Id)
|
||||
combinedResponse, err := l.svcCtx.ApiRequestService.ProcessRequests(ctx, decryptData, product.Id)
|
||||
if err != nil {
|
||||
return l.handleError(ctx, err, order, query)
|
||||
}
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"bdqr-server/app/main/api/internal/config"
|
||||
tianyuanapi "bdqr-server/app/main/api/internal/service/tianyuanapi_sdk"
|
||||
"bdqr-server/app/main/model"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
@@ -14,6 +11,10 @@ import (
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"bdqr-server/app/main/api/internal/config"
|
||||
tianyuanapi "bdqr-server/app/main/api/internal/service/tianyuanapi_sdk"
|
||||
"bdqr-server/app/main/model"
|
||||
|
||||
"github.com/Masterminds/squirrel"
|
||||
"github.com/tidwall/gjson"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
@@ -24,6 +25,33 @@ func convertTianyuanResponse(resp *tianyuanapi.Response) ([]byte, error) {
|
||||
return json.Marshal(resp.Data)
|
||||
}
|
||||
|
||||
// convertTianyuanBundleResponse 检测并转换组合包响应
|
||||
// 如果响应是组合包格式(包含 "responses" 字段),则转换为统一格式
|
||||
// 否则直接返回原始响应数据
|
||||
func convertTianyuanBundleResponse(resp *tianyuanapi.Response) ([]byte, error) {
|
||||
// 先将响应数据转换为 JSON 字节
|
||||
respData, err := json.Marshal(resp.Data)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("序列化响应数据失败: %v", err)
|
||||
}
|
||||
|
||||
// 检测是否是组合包响应格式(包含 "responses" 字段)
|
||||
if gjson.GetBytes(respData, "responses").Exists() {
|
||||
// 这是组合包响应,转换为统一格式
|
||||
bundleResults, convertErr := convertBundleResponseToStandard(respData)
|
||||
if convertErr != nil {
|
||||
// 转换失败,返回原始数据并记录错误
|
||||
logx.Errorf("转换组合包响应失败: %v", convertErr)
|
||||
return respData, nil
|
||||
}
|
||||
// 转换成功,返回转换后的 JSON
|
||||
return json.Marshal(bundleResults)
|
||||
}
|
||||
|
||||
// 不是组合包响应,直接返回原始数据
|
||||
return respData, nil
|
||||
}
|
||||
|
||||
// 生成认证时间范围:当前时间前后两天的YYYYMMDD-YYMMDD格式
|
||||
func generateAuthDateRange() string {
|
||||
now := time.Now()
|
||||
@@ -32,20 +60,84 @@ func generateAuthDateRange() string {
|
||||
return fmt.Sprintf("%s-%s", start, end)
|
||||
}
|
||||
|
||||
// callTianyuanApiWithLog 调用天元API并记录日志
|
||||
func (a *ApiRequestService) callTianyuanApiWithLog(ctx context.Context, featureID, apiID string, params map[string]interface{}) (*tianyuanapi.Response, error) {
|
||||
startTime := time.Now()
|
||||
resp, err := a.tianyuanapi.CallInterface(apiID, params)
|
||||
responseTime := time.Since(startTime).Milliseconds()
|
||||
|
||||
// 如果没有提供featureID,尝试从缓存中获取
|
||||
if featureID == "" {
|
||||
a.apiFeatureMapMutex.RLock()
|
||||
featureID = a.apiFeatureMapCache[apiID]
|
||||
a.apiFeatureMapMutex.RUnlock()
|
||||
}
|
||||
|
||||
// 构建调用记录选项
|
||||
callStatus := int64(0) // 默认失败
|
||||
errorCode := ""
|
||||
errorMessage := ""
|
||||
responseData := interface{}(nil)
|
||||
transactionID := ""
|
||||
|
||||
if err != nil {
|
||||
// 调用失败
|
||||
errorMessage = err.Error()
|
||||
// 尝试从错误信息中提取错误码
|
||||
if code := tianyuanapi.GetCodeByError(err); code != -1 {
|
||||
errorCode = fmt.Sprintf("%d", code)
|
||||
}
|
||||
} else {
|
||||
// 调用成功
|
||||
callStatus = 1
|
||||
responseData = resp.Data
|
||||
transactionID = resp.TransactionID
|
||||
}
|
||||
|
||||
// 异步记录调用日志(避免影响主流程)
|
||||
go func() {
|
||||
logOpts := CallLogOptions{
|
||||
FeatureID: featureID,
|
||||
ApiID: apiID,
|
||||
CallStatus: callStatus,
|
||||
ResponseTime: responseTime,
|
||||
ErrorCode: errorCode,
|
||||
ErrorMessage: errorMessage,
|
||||
RequestParams: params,
|
||||
ResponseData: responseData,
|
||||
TransactionID: transactionID,
|
||||
}
|
||||
if recordErr := a.tianyuanapiCallLogService.RecordCall(context.Background(), logOpts); recordErr != nil {
|
||||
logx.Errorf("记录天元API调用日志失败,api_id=%s, err=%v", apiID, recordErr)
|
||||
}
|
||||
}()
|
||||
|
||||
return resp, err
|
||||
}
|
||||
|
||||
type ApiRequestService struct {
|
||||
config config.Config
|
||||
featureModel model.FeatureModel
|
||||
productFeatureModel model.ProductFeatureModel
|
||||
tianyuanapi *tianyuanapi.Client
|
||||
config config.Config
|
||||
featureModel model.FeatureModel
|
||||
productFeatureModel model.ProductFeatureModel
|
||||
userFeatureWhitelistModel model.UserFeatureWhitelistModel
|
||||
whitelistService *WhitelistService
|
||||
tianyuanapi *tianyuanapi.Client
|
||||
tianyuanapiCallLogService *TianyuanapiCallLogService
|
||||
apiFeatureMapCache map[string]string // apiID -> featureID 缓存
|
||||
apiFeatureMapMutex sync.RWMutex
|
||||
}
|
||||
|
||||
// NewApiRequestService 是一个构造函数,用于初始化 ApiRequestService
|
||||
func NewApiRequestService(c config.Config, featureModel model.FeatureModel, productFeatureModel model.ProductFeatureModel, tianyuanapi *tianyuanapi.Client) *ApiRequestService {
|
||||
func NewApiRequestService(c config.Config, featureModel model.FeatureModel, productFeatureModel model.ProductFeatureModel, userFeatureWhitelistModel model.UserFeatureWhitelistModel, tianyuanapi *tianyuanapi.Client, tianyuanapiCallLogService *TianyuanapiCallLogService, whitelistService *WhitelistService) *ApiRequestService {
|
||||
return &ApiRequestService{
|
||||
config: c,
|
||||
featureModel: featureModel,
|
||||
productFeatureModel: productFeatureModel,
|
||||
tianyuanapi: tianyuanapi,
|
||||
config: c,
|
||||
featureModel: featureModel,
|
||||
productFeatureModel: productFeatureModel,
|
||||
userFeatureWhitelistModel: userFeatureWhitelistModel,
|
||||
tianyuanapi: tianyuanapi,
|
||||
tianyuanapiCallLogService: tianyuanapiCallLogService,
|
||||
whitelistService: whitelistService,
|
||||
apiFeatureMapCache: make(map[string]string),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,10 +149,76 @@ type APIResponseData struct {
|
||||
Error string `json:"error,omitempty"`
|
||||
}
|
||||
|
||||
// BundleResponseItem 组合包响应中的单个项
|
||||
type BundleResponseItem struct {
|
||||
ApiCode string `json:"api_code"`
|
||||
Success bool `json:"success"`
|
||||
Data json.RawMessage `json:"data"`
|
||||
Error string `json:"error,omitempty"`
|
||||
}
|
||||
|
||||
// BundleResponse 组合包响应结构
|
||||
type BundleResponse struct {
|
||||
Responses []BundleResponseItem `json:"responses"`
|
||||
}
|
||||
|
||||
// convertBundleResponseToStandard 将组合包响应格式转换为统一格式
|
||||
func convertBundleResponseToStandard(bundleResp []byte) ([]APIResponseData, error) {
|
||||
var bundle BundleResponse
|
||||
if err := json.Unmarshal(bundleResp, &bundle); err != nil {
|
||||
return nil, fmt.Errorf("解析组合包响应失败: %v", err)
|
||||
}
|
||||
|
||||
timestamp := time.Now().Format("2006-01-02 15:04:05")
|
||||
var result []APIResponseData
|
||||
|
||||
for _, item := range bundle.Responses {
|
||||
apiResp := APIResponseData{
|
||||
ApiID: item.ApiCode,
|
||||
Success: item.Success,
|
||||
Timestamp: timestamp,
|
||||
}
|
||||
|
||||
// 处理 data 字段
|
||||
if len(item.Data) > 0 {
|
||||
// 如果 data 是 null 的 JSON 字符串,转换为 null
|
||||
if string(item.Data) == "null" {
|
||||
apiResp.Data = []byte("null")
|
||||
} else {
|
||||
apiResp.Data = item.Data
|
||||
}
|
||||
} else {
|
||||
apiResp.Data = []byte("null")
|
||||
}
|
||||
|
||||
// 处理 error 字段
|
||||
if !item.Success && item.Error != "" {
|
||||
apiResp.Error = item.Error
|
||||
}
|
||||
|
||||
result = append(result, apiResp)
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// ProcessRequests 处理请求
|
||||
func (a *ApiRequestService) ProcessRequests(params []byte, productID string) ([]byte, error) {
|
||||
var ctx, cancel = context.WithCancel(context.Background())
|
||||
func (a *ApiRequestService) ProcessRequests(ctx context.Context, params []byte, productID string) ([]byte, error) {
|
||||
var cancel context.CancelFunc
|
||||
ctx, cancel = context.WithCancel(ctx)
|
||||
defer cancel()
|
||||
|
||||
// 从params中提取id_card,用于白名单检查
|
||||
idCard := gjson.GetBytes(params, "id_card").String()
|
||||
|
||||
// 查询白名单(如果提供了id_card),集中由 WhitelistService 处理
|
||||
var whitelistedFeatureApiIds map[string]bool
|
||||
if a.whitelistService != nil {
|
||||
whitelistedFeatureApiIds, _ = a.whitelistService.GetWhitelistedFeatureApisByIdCard(ctx, idCard)
|
||||
} else {
|
||||
whitelistedFeatureApiIds = make(map[string]bool)
|
||||
}
|
||||
|
||||
build := a.productFeatureModel.SelectBuilder().Where(squirrel.Eq{
|
||||
"product_id": productID,
|
||||
})
|
||||
@@ -85,6 +243,13 @@ func (a *ApiRequestService) ProcessRequests(params []byte, productID string) ([]
|
||||
if len(featureList) == 0 {
|
||||
return nil, errors.New("处理请求错误,产品无对应接口功能")
|
||||
}
|
||||
|
||||
// 缓存apiID到featureID的映射关系,供后续调用记录使用
|
||||
a.apiFeatureMapMutex.Lock()
|
||||
for _, feature := range featureList {
|
||||
a.apiFeatureMapCache[feature.ApiId] = feature.Id
|
||||
}
|
||||
a.apiFeatureMapMutex.Unlock()
|
||||
var (
|
||||
wg sync.WaitGroup
|
||||
resultsCh = make(chan APIResponseData, len(featureList))
|
||||
@@ -109,6 +274,18 @@ func (a *ApiRequestService) ProcessRequests(params []byte, productID string) ([]
|
||||
Success: false,
|
||||
}
|
||||
timestamp := time.Now().Format("2006-01-02 15:04:05")
|
||||
|
||||
// 检查是否在白名单中
|
||||
if whitelistedFeatureApiIds[feature.ApiId] {
|
||||
// 在白名单中,返回空结构(data 为 null),保持与正常返回结构一致
|
||||
// 直接设置 data 为 null 的 JSON 字节
|
||||
result.Data = []byte("null")
|
||||
result.Success = true
|
||||
result.Timestamp = timestamp
|
||||
resultsCh <- result
|
||||
return
|
||||
}
|
||||
|
||||
var (
|
||||
resp json.RawMessage
|
||||
preprocessErr error
|
||||
@@ -118,7 +295,7 @@ func (a *ApiRequestService) ProcessRequests(params []byte, productID string) ([]
|
||||
tryCount := 0
|
||||
for {
|
||||
tryCount++
|
||||
resp, preprocessErr = a.PreprocessRequestApi(params, feature.ApiId)
|
||||
resp, preprocessErr = a.PreprocessRequestApi(ctx, params, feature.ApiId)
|
||||
if preprocessErr == nil {
|
||||
break
|
||||
}
|
||||
@@ -153,10 +330,49 @@ func (a *ApiRequestService) ProcessRequests(params []byte, productID string) ([]
|
||||
close(resultsCh)
|
||||
close(errorsCh)
|
||||
}()
|
||||
// 收集所有结果并合并z
|
||||
// 收集所有结果并合并
|
||||
var responseData []APIResponseData
|
||||
for result := range resultsCh {
|
||||
responseData = append(responseData, result)
|
||||
if result.Success && len(result.Data) > 0 {
|
||||
// 先检查是否是已拆开的组合包(统一格式数组)
|
||||
// 特征:是数组格式,且第一个元素包含 "apiID"、"success"、"timestamp" 字段
|
||||
firstItem := gjson.GetBytes(result.Data, "0")
|
||||
if firstItem.Exists() {
|
||||
firstApiID := firstItem.Get("apiID")
|
||||
firstSuccess := firstItem.Get("success")
|
||||
firstTimestamp := firstItem.Get("timestamp")
|
||||
// 如果第一个元素有 apiID、success、timestamp 字段,说明是已拆开的组合包
|
||||
if firstApiID.Exists() && firstSuccess.Exists() && firstTimestamp.Exists() {
|
||||
// 这是已拆开的组合包(统一格式数组),直接展开添加到结果中
|
||||
var bundleResults []APIResponseData
|
||||
if err := json.Unmarshal(result.Data, &bundleResults); err == nil {
|
||||
responseData = append(responseData, bundleResults...)
|
||||
continue
|
||||
}
|
||||
// 解析失败,作为普通响应处理
|
||||
}
|
||||
}
|
||||
|
||||
// 检查是否包含 "responses" 字段(未拆开的组合包)
|
||||
if gjson.GetBytes(result.Data, "responses").Exists() {
|
||||
// 这是未拆开的组合包响应,需要转换
|
||||
bundleResults, convertErr := convertBundleResponseToStandard(result.Data)
|
||||
if convertErr != nil {
|
||||
// 转换失败,记录错误但保留原始结果
|
||||
logx.Errorf("转换组合包响应失败: %v", convertErr)
|
||||
responseData = append(responseData, result)
|
||||
} else {
|
||||
// 转换成功,用转换后的结果替换原始结果
|
||||
responseData = append(responseData, bundleResults...)
|
||||
}
|
||||
} else {
|
||||
// 普通响应,直接添加
|
||||
responseData = append(responseData, result)
|
||||
}
|
||||
} else {
|
||||
// 失败或空响应,直接添加
|
||||
responseData = append(responseData, result)
|
||||
}
|
||||
}
|
||||
if atomic.LoadInt32(&errorCount) >= int32(errorLimit) {
|
||||
var allErrors []error
|
||||
@@ -175,7 +391,7 @@ func (a *ApiRequestService) ProcessRequests(params []byte, productID string) ([]
|
||||
}
|
||||
|
||||
// ------------------------------------请求处理器--------------------------
|
||||
var requestProcessors = map[string]func(*ApiRequestService, []byte) ([]byte, error){
|
||||
var requestProcessors = map[string]func(*ApiRequestService, context.Context, []byte) ([]byte, error){
|
||||
"PersonEnterprisePro": (*ApiRequestService).ProcessPersonEnterpriseProRequest,
|
||||
"BehaviorRiskScan": (*ApiRequestService).ProcessBehaviorRiskScanRequest,
|
||||
"YYSYBE08": (*ApiRequestService).ProcessYYSYBE08Request,
|
||||
@@ -208,19 +424,20 @@ var requestProcessors = map[string]func(*ApiRequestService, []byte) ([]byte, err
|
||||
"JRZQ7F1A": (*ApiRequestService).ProcessJRZQ7F1ARequest,
|
||||
"IVYZ3P9M": (*ApiRequestService).ProcessIVYZ3P9MRequest,
|
||||
"JRZQ6F2A": (*ApiRequestService).ProcessJRZQ6F2ARequest,
|
||||
"COMBQN12": (*ApiRequestService).ProcessCOMBQN12Request,
|
||||
}
|
||||
|
||||
// PreprocessRequestApi 调用指定的请求处理函数
|
||||
func (a *ApiRequestService) PreprocessRequestApi(params []byte, apiID string) ([]byte, error) {
|
||||
func (a *ApiRequestService) PreprocessRequestApi(ctx context.Context, params []byte, apiID string) ([]byte, error) {
|
||||
if processor, exists := requestProcessors[apiID]; exists {
|
||||
return processor(a, params) // 调用 ApiRequestService 方法
|
||||
return processor(a, ctx, params) // 调用 ApiRequestService 方法
|
||||
}
|
||||
|
||||
return nil, errors.New("api请求, 未找到相应的处理程序")
|
||||
}
|
||||
|
||||
// PersonEnterprisePro 人企业关系加强版
|
||||
func (a *ApiRequestService) ProcessPersonEnterpriseProRequest(params []byte) ([]byte, error) {
|
||||
func (a *ApiRequestService) ProcessPersonEnterpriseProRequest(ctx context.Context, params []byte) ([]byte, error) {
|
||||
idCard := gjson.GetBytes(params, "id_card")
|
||||
// 设置最大调用次数上限
|
||||
maxApiCalls := 20 // 允许最多查询20个企业
|
||||
@@ -229,7 +446,7 @@ func (a *ApiRequestService) ProcessPersonEnterpriseProRequest(params []byte) ([]
|
||||
return nil, errors.New("api请求, PersonEnterprisePro, 获取相关参数失败")
|
||||
}
|
||||
|
||||
resp, err := a.tianyuanapi.CallInterface("QYGLB4C0", map[string]interface{}{
|
||||
resp, err := a.callTianyuanApiWithLog(ctx, "", "QYGLB4C0", map[string]interface{}{
|
||||
"id_card": idCard.String(),
|
||||
})
|
||||
if err != nil {
|
||||
@@ -431,7 +648,7 @@ func (a *ApiRequestService) ProcessPersonEnterpriseProRequest(params []byte) ([]
|
||||
}
|
||||
|
||||
// 调用QYGL8271接口获取企业涉诉信息
|
||||
lawsuitResp, err := a.tianyuanapi.CallInterface("QYGL8271", map[string]interface{}{
|
||||
lawsuitResp, err := a.callTianyuanApiWithLog(ctx, "", "QYGL8271", map[string]interface{}{
|
||||
"ent_name": orgName.String(),
|
||||
"ent_code": creditCode.String(),
|
||||
"auth_date": generateAuthDateRange(),
|
||||
@@ -555,14 +772,14 @@ func (a *ApiRequestService) ProcessPersonEnterpriseProRequest(params []byte) ([]
|
||||
}
|
||||
|
||||
// ProcesFLXG0V4BRequest 个人司法涉诉(详版)
|
||||
func (a *ApiRequestService) ProcessFLXG0V4BRequest(params []byte) ([]byte, error) {
|
||||
func (a *ApiRequestService) ProcessFLXG0V4BRequest(ctx context.Context, params []byte) ([]byte, error) {
|
||||
name := gjson.GetBytes(params, "name")
|
||||
idCard := gjson.GetBytes(params, "id_card")
|
||||
if !name.Exists() || !idCard.Exists() {
|
||||
return nil, errors.New("api请求, FLXG0V4B, 获取相关参数失败")
|
||||
}
|
||||
|
||||
resp, err := a.tianyuanapi.CallInterface("FLXG0V4B", map[string]interface{}{
|
||||
resp, err := a.callTianyuanApiWithLog(ctx, "", "FLXG0V4B", map[string]interface{}{
|
||||
"name": name.String(),
|
||||
"id_card": idCard.String(),
|
||||
"auth_date": generateAuthDateRange(),
|
||||
@@ -578,13 +795,13 @@ func (a *ApiRequestService) ProcessFLXG0V4BRequest(params []byte) ([]byte, error
|
||||
}
|
||||
|
||||
// ProcessFLXG0687Request 反诈反赌核验
|
||||
func (a *ApiRequestService) ProcessFLXG0687Request(params []byte) ([]byte, error) {
|
||||
func (a *ApiRequestService) ProcessFLXG0687Request(ctx context.Context, params []byte) ([]byte, error) {
|
||||
idCard := gjson.GetBytes(params, "id_card")
|
||||
if !idCard.Exists() {
|
||||
return nil, errors.New("api请求, FLXG0687, 获取相关参数失败")
|
||||
}
|
||||
|
||||
resp, err := a.tianyuanapi.CallInterface("FLXG0687", map[string]interface{}{
|
||||
resp, err := a.callTianyuanApiWithLog(ctx, "", "FLXG0687", map[string]interface{}{
|
||||
"id_card": idCard.String(),
|
||||
})
|
||||
|
||||
@@ -606,7 +823,7 @@ func (a *ApiRequestService) ProcessFLXG0687Request(params []byte) ([]byte, error
|
||||
}
|
||||
|
||||
// ProcessFLXG3D56Request 违约失信
|
||||
func (a *ApiRequestService) ProcessFLXG3D56Request(params []byte) ([]byte, error) {
|
||||
func (a *ApiRequestService) ProcessFLXG3D56Request(ctx context.Context, params []byte) ([]byte, error) {
|
||||
name := gjson.GetBytes(params, "name")
|
||||
idCard := gjson.GetBytes(params, "id_card")
|
||||
mobile := gjson.GetBytes(params, "mobile")
|
||||
@@ -614,7 +831,7 @@ func (a *ApiRequestService) ProcessFLXG3D56Request(params []byte) ([]byte, error
|
||||
return nil, errors.New("api请求, FLXG3D56, 获取相关参数失败")
|
||||
}
|
||||
|
||||
resp, err := a.tianyuanapi.CallInterface("FLXG3D56", map[string]interface{}{
|
||||
resp, err := a.callTianyuanApiWithLog(ctx, "", "FLXG3D56", map[string]interface{}{
|
||||
"name": name.String(),
|
||||
"id_card": idCard.String(),
|
||||
"mobile_no": mobile.String(),
|
||||
@@ -661,14 +878,14 @@ func (a *ApiRequestService) ProcessFLXG3D56Request(params []byte) ([]byte, error
|
||||
}
|
||||
|
||||
// ProcessIVYZ5733Request 婚姻状况
|
||||
func (a *ApiRequestService) ProcessIVYZ5733Request(params []byte) ([]byte, error) {
|
||||
func (a *ApiRequestService) ProcessIVYZ5733Request(ctx context.Context, params []byte) ([]byte, error) {
|
||||
idCard := gjson.GetBytes(params, "id_card")
|
||||
name := gjson.GetBytes(params, "name")
|
||||
if !idCard.Exists() || !name.Exists() {
|
||||
return nil, errors.New("api请求, IVYZ5733, 获取相关参数失败")
|
||||
}
|
||||
|
||||
resp, err := a.tianyuanapi.CallInterface("IVYZ5733", map[string]interface{}{
|
||||
resp, err := a.callTianyuanApiWithLog(ctx, "", "IVYZ5733", map[string]interface{}{
|
||||
"id_card": idCard.String(),
|
||||
"name": name.String(),
|
||||
})
|
||||
@@ -717,14 +934,14 @@ func (a *ApiRequestService) ProcessIVYZ5733Request(params []byte) ([]byte, error
|
||||
}
|
||||
|
||||
// ProcessIVYZ9A2BRequest 学历查询
|
||||
func (a *ApiRequestService) ProcessIVYZ9A2BRequest(params []byte) ([]byte, error) {
|
||||
func (a *ApiRequestService) ProcessIVYZ9A2BRequest(ctx context.Context, params []byte) ([]byte, error) {
|
||||
idCard := gjson.GetBytes(params, "id_card")
|
||||
name := gjson.GetBytes(params, "name")
|
||||
if !idCard.Exists() || !name.Exists() {
|
||||
return nil, errors.New("api请求, IVYZ9A2B, 获取相关参数失败")
|
||||
}
|
||||
|
||||
resp, err := a.tianyuanapi.CallInterface("IVYZ9A2B", map[string]interface{}{
|
||||
resp, err := a.callTianyuanApiWithLog(ctx, "", "IVYZ9A2B", map[string]interface{}{
|
||||
"id_card": idCard.String(),
|
||||
"name": name.String(),
|
||||
})
|
||||
@@ -788,14 +1005,14 @@ func (a *ApiRequestService) ProcessIVYZ9A2BRequest(params []byte) ([]byte, error
|
||||
}
|
||||
|
||||
// ProcessYYSYBE08Request 二要素
|
||||
func (a *ApiRequestService) ProcessYYSYBE08Request(params []byte) ([]byte, error) {
|
||||
func (a *ApiRequestService) ProcessYYSYBE08Request(ctx context.Context, params []byte) ([]byte, error) {
|
||||
name := gjson.GetBytes(params, "name")
|
||||
idCard := gjson.GetBytes(params, "id_card")
|
||||
if !name.Exists() || !idCard.Exists() {
|
||||
return nil, errors.New("api请求, YYSYBE08, 获取相关参数失败")
|
||||
}
|
||||
|
||||
resp, err := a.tianyuanapi.CallInterface("YYSYBE08", map[string]interface{}{
|
||||
resp, err := a.callTianyuanApiWithLog(ctx, "", "YYSYBE08", map[string]interface{}{
|
||||
"name": name.String(),
|
||||
"id_card": idCard.String(),
|
||||
})
|
||||
@@ -829,7 +1046,7 @@ func (a *ApiRequestService) ProcessYYSYBE08Request(params []byte) ([]byte, error
|
||||
}
|
||||
|
||||
// ProcessJRZQ0A03Request 借贷申请
|
||||
func (a *ApiRequestService) ProcessJRZQ0A03Request(params []byte) ([]byte, error) {
|
||||
func (a *ApiRequestService) ProcessJRZQ0A03Request(ctx context.Context, params []byte) ([]byte, error) {
|
||||
name := gjson.GetBytes(params, "name")
|
||||
idCard := gjson.GetBytes(params, "id_card")
|
||||
mobile := gjson.GetBytes(params, "mobile")
|
||||
@@ -837,7 +1054,7 @@ func (a *ApiRequestService) ProcessJRZQ0A03Request(params []byte) ([]byte, error
|
||||
return nil, errors.New("api请求, JRZQ0A03, 获取相关参数失败")
|
||||
}
|
||||
|
||||
resp, err := a.tianyuanapi.CallInterface("JRZQ0A03", map[string]interface{}{
|
||||
resp, err := a.callTianyuanApiWithLog(ctx, "", "JRZQ0A03", map[string]interface{}{
|
||||
"name": name.String(),
|
||||
"id_card": idCard.String(),
|
||||
"mobile_no": mobile.String(),
|
||||
@@ -886,7 +1103,7 @@ func (a *ApiRequestService) ProcessJRZQ0A03Request(params []byte) ([]byte, error
|
||||
}
|
||||
|
||||
// ProcessJRZQ8203Request 借贷行为
|
||||
func (a *ApiRequestService) ProcessJRZQ8203Request(params []byte) ([]byte, error) {
|
||||
func (a *ApiRequestService) ProcessJRZQ8203Request(ctx context.Context, params []byte) ([]byte, error) {
|
||||
name := gjson.GetBytes(params, "name")
|
||||
idCard := gjson.GetBytes(params, "id_card")
|
||||
mobile := gjson.GetBytes(params, "mobile")
|
||||
@@ -894,7 +1111,7 @@ func (a *ApiRequestService) ProcessJRZQ8203Request(params []byte) ([]byte, error
|
||||
return nil, errors.New("api请求, JRZQ8203, 获取相关参数失败")
|
||||
}
|
||||
|
||||
resp, err := a.tianyuanapi.CallInterface("JRZQ8203", map[string]interface{}{
|
||||
resp, err := a.callTianyuanApiWithLog(ctx, "", "JRZQ8203", map[string]interface{}{
|
||||
"name": name.String(),
|
||||
"id_card": idCard.String(),
|
||||
"mobile_no": mobile.String(),
|
||||
@@ -943,7 +1160,7 @@ func (a *ApiRequestService) ProcessJRZQ8203Request(params []byte) ([]byte, error
|
||||
}
|
||||
|
||||
// ProcessJRZQ4AA8Request 还款压力
|
||||
func (a *ApiRequestService) ProcessJRZQ4AA8Request(params []byte) ([]byte, error) {
|
||||
func (a *ApiRequestService) ProcessJRZQ4AA8Request(ctx context.Context, params []byte) ([]byte, error) {
|
||||
idCard := gjson.GetBytes(params, "id_card")
|
||||
name := gjson.GetBytes(params, "name")
|
||||
mobile := gjson.GetBytes(params, "mobile")
|
||||
@@ -951,7 +1168,7 @@ func (a *ApiRequestService) ProcessJRZQ4AA8Request(params []byte) ([]byte, error
|
||||
return nil, errors.New("api请求, JRZQ4AA8, 获取相关参数失败")
|
||||
}
|
||||
|
||||
resp, err := a.tianyuanapi.CallInterface("JRZQ4AA8", map[string]interface{}{
|
||||
resp, err := a.callTianyuanApiWithLog(ctx, "", "JRZQ4AA8", map[string]interface{}{
|
||||
"id_card": idCard.String(),
|
||||
"name": name.String(),
|
||||
"mobile_no": mobile.String(),
|
||||
@@ -992,7 +1209,7 @@ func (a *ApiRequestService) ProcessJRZQ4AA8Request(params []byte) ([]byte, error
|
||||
}
|
||||
|
||||
// ProcessQYGL8271Request 企业涉诉
|
||||
func (a *ApiRequestService) ProcessQYGL8271Request(params []byte) ([]byte, error) {
|
||||
func (a *ApiRequestService) ProcessQYGL8271Request(ctx context.Context, params []byte) ([]byte, error) {
|
||||
entName := gjson.GetBytes(params, "ent_name")
|
||||
entCode := gjson.GetBytes(params, "ent_code")
|
||||
|
||||
@@ -1000,7 +1217,7 @@ func (a *ApiRequestService) ProcessQYGL8271Request(params []byte) ([]byte, error
|
||||
return nil, errors.New("api请求, QYGL8271, 获取相关参数失败")
|
||||
}
|
||||
|
||||
resp, err := a.tianyuanapi.CallInterface("QYGL8271", map[string]interface{}{
|
||||
resp, err := a.callTianyuanApiWithLog(ctx, "", "QYGL8271", map[string]interface{}{
|
||||
"ent_name": entName.String(),
|
||||
"ent_code": entCode.String(),
|
||||
})
|
||||
@@ -1052,13 +1269,13 @@ func (a *ApiRequestService) ProcessQYGL8271Request(params []byte) ([]byte, error
|
||||
}
|
||||
|
||||
// ProcessQYGL6F2DRequest 人企关联
|
||||
func (a *ApiRequestService) ProcessQYGL6F2DRequest(params []byte) ([]byte, error) {
|
||||
func (a *ApiRequestService) ProcessQYGL6F2DRequest(ctx context.Context, params []byte) ([]byte, error) {
|
||||
idCard := gjson.GetBytes(params, "id_card")
|
||||
if !idCard.Exists() {
|
||||
return nil, errors.New("api请求, QYGL6F2D, 获取相关参数失败")
|
||||
}
|
||||
|
||||
resp, err := a.tianyuanapi.CallInterface("QYGL6F2D", map[string]interface{}{
|
||||
resp, err := a.callTianyuanApiWithLog(ctx, "", "QYGL6F2D", map[string]interface{}{
|
||||
"id_card": idCard.String(),
|
||||
})
|
||||
|
||||
@@ -1093,13 +1310,13 @@ func (a *ApiRequestService) ProcessQYGL6F2DRequest(params []byte) ([]byte, error
|
||||
}
|
||||
|
||||
// ProcessQCXG7A2BRequest 名下车辆
|
||||
func (a *ApiRequestService) ProcessQCXG7A2BRequest(params []byte) ([]byte, error) {
|
||||
func (a *ApiRequestService) ProcessQCXG7A2BRequest(ctx context.Context, params []byte) ([]byte, error) {
|
||||
idCard := gjson.GetBytes(params, "id_card")
|
||||
if !idCard.Exists() {
|
||||
return nil, errors.New("api请求, QCXG7A2B, 获取相关参数失败")
|
||||
}
|
||||
|
||||
resp, err := a.tianyuanapi.CallInterface("QCXG7A2B", map[string]interface{}{
|
||||
resp, err := a.callTianyuanApiWithLog(ctx, "", "QCXG7A2B", map[string]interface{}{
|
||||
"id_card": idCard.String(),
|
||||
})
|
||||
|
||||
@@ -1111,7 +1328,7 @@ func (a *ApiRequestService) ProcessQCXG7A2BRequest(params []byte) ([]byte, error
|
||||
}
|
||||
|
||||
// ProcessYYSY09CDRequest 三要素
|
||||
func (a *ApiRequestService) ProcessYYSY09CDRequest(params []byte) ([]byte, error) {
|
||||
func (a *ApiRequestService) ProcessYYSY09CDRequest(ctx context.Context, params []byte) ([]byte, error) {
|
||||
name := gjson.GetBytes(params, "name")
|
||||
idCard := gjson.GetBytes(params, "id_card")
|
||||
mobile := gjson.GetBytes(params, "mobile")
|
||||
@@ -1119,7 +1336,7 @@ func (a *ApiRequestService) ProcessYYSY09CDRequest(params []byte) ([]byte, error
|
||||
return nil, errors.New("api请求, YYSY09CD, 获取相关参数失败")
|
||||
}
|
||||
|
||||
resp, err := a.tianyuanapi.CallInterface("YYSY09CD", map[string]interface{}{
|
||||
resp, err := a.callTianyuanApiWithLog(ctx, "", "YYSY09CD", map[string]interface{}{
|
||||
"name": name.String(),
|
||||
"id_card": idCard.String(),
|
||||
"mobile_no": mobile.String(),
|
||||
@@ -1154,7 +1371,7 @@ func (a *ApiRequestService) ProcessYYSY09CDRequest(params []byte) ([]byte, error
|
||||
}
|
||||
|
||||
// ProcessBehaviorRiskScanRequest 行为风险扫描
|
||||
func (a *ApiRequestService) ProcessBehaviorRiskScanRequest(params []byte) ([]byte, error) {
|
||||
func (a *ApiRequestService) ProcessBehaviorRiskScanRequest(ctx context.Context, params []byte) ([]byte, error) {
|
||||
name := gjson.GetBytes(params, "name")
|
||||
idCard := gjson.GetBytes(params, "id_card")
|
||||
|
||||
@@ -1176,7 +1393,7 @@ func (a *ApiRequestService) ProcessBehaviorRiskScanRequest(params []byte) ([]byt
|
||||
// 反赌反诈
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
respBytes, err := a.ProcessFLXG0687Request(params)
|
||||
respBytes, err := a.ProcessFLXG0687Request(ctx, params)
|
||||
results <- apiResult{name: "anti_fraud_gaming", data: respBytes, err: err}
|
||||
}()
|
||||
|
||||
@@ -1221,7 +1438,7 @@ func (a *ApiRequestService) ProcessBehaviorRiskScanRequest(params []byte) ([]byt
|
||||
}
|
||||
|
||||
// ProcessDWBG8B4DRequest 谛听多维报告
|
||||
func (a *ApiRequestService) ProcessDWBG8B4DRequest(params []byte) ([]byte, error) {
|
||||
func (a *ApiRequestService) ProcessDWBG8B4DRequest(ctx context.Context, params []byte) ([]byte, error) {
|
||||
name := gjson.GetBytes(params, "name")
|
||||
idCard := gjson.GetBytes(params, "id_card")
|
||||
mobile := gjson.GetBytes(params, "mobile")
|
||||
@@ -1230,7 +1447,7 @@ func (a *ApiRequestService) ProcessDWBG8B4DRequest(params []byte) ([]byte, error
|
||||
return nil, errors.New("api请求, DWBG8B4D, 获取相关参数失败")
|
||||
}
|
||||
|
||||
resp, err := a.tianyuanapi.CallInterface("DWBG8B4D", map[string]interface{}{
|
||||
resp, err := a.callTianyuanApiWithLog(ctx, "", "DWBG8B4D", map[string]interface{}{
|
||||
"name": name.String(),
|
||||
"id_card": idCard.String(),
|
||||
"mobile_no": mobile.String(),
|
||||
@@ -1246,7 +1463,7 @@ func (a *ApiRequestService) ProcessDWBG8B4DRequest(params []byte) ([]byte, error
|
||||
}
|
||||
|
||||
// ProcessDWBG6A2CRequest 司南报告服务
|
||||
func (a *ApiRequestService) ProcessDWBG6A2CRequest(params []byte) ([]byte, error) {
|
||||
func (a *ApiRequestService) ProcessDWBG6A2CRequest(ctx context.Context, params []byte) ([]byte, error) {
|
||||
name := gjson.GetBytes(params, "name")
|
||||
idCard := gjson.GetBytes(params, "id_card")
|
||||
mobile := gjson.GetBytes(params, "mobile")
|
||||
@@ -1255,7 +1472,7 @@ func (a *ApiRequestService) ProcessDWBG6A2CRequest(params []byte) ([]byte, error
|
||||
return nil, errors.New("api请求, DWBG6A2C, 获取相关参数失败")
|
||||
}
|
||||
|
||||
resp, err := a.tianyuanapi.CallInterface("DWBG6A2C", map[string]interface{}{
|
||||
resp, err := a.callTianyuanApiWithLog(ctx, "", "DWBG6A2C", map[string]interface{}{
|
||||
"name": name.String(),
|
||||
"id_card": idCard.String(),
|
||||
"mobile_no": mobile.String(),
|
||||
@@ -1271,7 +1488,7 @@ func (a *ApiRequestService) ProcessDWBG6A2CRequest(params []byte) ([]byte, error
|
||||
}
|
||||
|
||||
// ProcessJRZQ4B6CRequest 探针C风险评估
|
||||
func (a *ApiRequestService) ProcessJRZQ4B6CRequest(params []byte) ([]byte, error) {
|
||||
func (a *ApiRequestService) ProcessJRZQ4B6CRequest(ctx context.Context, params []byte) ([]byte, error) {
|
||||
name := gjson.GetBytes(params, "name")
|
||||
idCard := gjson.GetBytes(params, "id_card")
|
||||
mobile := gjson.GetBytes(params, "mobile")
|
||||
@@ -1279,7 +1496,7 @@ func (a *ApiRequestService) ProcessJRZQ4B6CRequest(params []byte) ([]byte, error
|
||||
return nil, errors.New("api请求, JRZQ4B6C, 获取相关参数失败")
|
||||
}
|
||||
|
||||
resp, err := a.tianyuanapi.CallInterface("JRZQ4B6C", map[string]interface{}{
|
||||
resp, err := a.callTianyuanApiWithLog(ctx, "", "JRZQ4B6C", map[string]interface{}{
|
||||
"name": name.String(),
|
||||
"id_card": idCard.String(),
|
||||
"mobile_no": mobile.String(),
|
||||
@@ -1295,7 +1512,7 @@ func (a *ApiRequestService) ProcessJRZQ4B6CRequest(params []byte) ([]byte, error
|
||||
}
|
||||
|
||||
// ProcessJRZQ09J8Request 收入评估
|
||||
func (a *ApiRequestService) ProcessJRZQ09J8Request(params []byte) ([]byte, error) {
|
||||
func (a *ApiRequestService) ProcessJRZQ09J8Request(ctx context.Context, params []byte) ([]byte, error) {
|
||||
name := gjson.GetBytes(params, "name")
|
||||
idCard := gjson.GetBytes(params, "id_card")
|
||||
mobile := gjson.GetBytes(params, "mobile")
|
||||
@@ -1303,7 +1520,7 @@ func (a *ApiRequestService) ProcessJRZQ09J8Request(params []byte) ([]byte, error
|
||||
return nil, errors.New("api请求, JRZQ09J8, 获取相关参数失败")
|
||||
}
|
||||
|
||||
resp, err := a.tianyuanapi.CallInterface("JRZQ09J8", map[string]interface{}{
|
||||
resp, err := a.callTianyuanApiWithLog(ctx, "", "JRZQ09J8", map[string]interface{}{
|
||||
"name": name.String(),
|
||||
"id_card": idCard.String(),
|
||||
"mobile_no": mobile.String(),
|
||||
@@ -1319,7 +1536,7 @@ func (a *ApiRequestService) ProcessJRZQ09J8Request(params []byte) ([]byte, error
|
||||
}
|
||||
|
||||
// ProcessJRZQ5E9FRequest 借选指数
|
||||
func (a *ApiRequestService) ProcessJRZQ5E9FRequest(params []byte) ([]byte, error) {
|
||||
func (a *ApiRequestService) ProcessJRZQ5E9FRequest(ctx context.Context, params []byte) ([]byte, error) {
|
||||
name := gjson.GetBytes(params, "name")
|
||||
idCard := gjson.GetBytes(params, "id_card")
|
||||
mobile := gjson.GetBytes(params, "mobile")
|
||||
@@ -1327,7 +1544,7 @@ func (a *ApiRequestService) ProcessJRZQ5E9FRequest(params []byte) ([]byte, error
|
||||
return nil, errors.New("api请求, JRZQ5E9F, 获取相关参数失败")
|
||||
}
|
||||
|
||||
resp, err := a.tianyuanapi.CallInterface("JRZQ5E9F", map[string]interface{}{
|
||||
resp, err := a.callTianyuanApiWithLog(ctx, "", "JRZQ5E9F", map[string]interface{}{
|
||||
"name": name.String(),
|
||||
"id_card": idCard.String(),
|
||||
"mobile_no": mobile.String(),
|
||||
@@ -1343,13 +1560,13 @@ func (a *ApiRequestService) ProcessJRZQ5E9FRequest(params []byte) ([]byte, error
|
||||
}
|
||||
|
||||
// ProcessQYGL3F8ERequest 人企关系加强版2
|
||||
func (a *ApiRequestService) ProcessQYGL3F8ERequest(params []byte) ([]byte, error) {
|
||||
func (a *ApiRequestService) ProcessQYGL3F8ERequest(ctx context.Context, params []byte) ([]byte, error) {
|
||||
idCard := gjson.GetBytes(params, "id_card")
|
||||
if !idCard.Exists() {
|
||||
return nil, errors.New("api请求, QYGL3F8E, 获取相关参数失败")
|
||||
}
|
||||
|
||||
resp, err := a.tianyuanapi.CallInterface("QYGL3F8E", map[string]interface{}{
|
||||
resp, err := a.callTianyuanApiWithLog(ctx, "", "QYGL3F8E", map[string]interface{}{
|
||||
"id_card": idCard.String(),
|
||||
})
|
||||
|
||||
@@ -1362,14 +1579,14 @@ func (a *ApiRequestService) ProcessQYGL3F8ERequest(params []byte) ([]byte, error
|
||||
}
|
||||
|
||||
// ProcessIVYZ81NCRequest 婚姻,登记时间版
|
||||
func (a *ApiRequestService) ProcessIVYZ81NCRequest(params []byte) ([]byte, error) {
|
||||
func (a *ApiRequestService) ProcessIVYZ81NCRequest(ctx context.Context, params []byte) ([]byte, error) {
|
||||
name := gjson.GetBytes(params, "name")
|
||||
idCard := gjson.GetBytes(params, "id_card")
|
||||
if !name.Exists() || !idCard.Exists() {
|
||||
return nil, errors.New("api请求, IVYZ81NC, 获取相关参数失败")
|
||||
}
|
||||
|
||||
resp, err := a.tianyuanapi.CallInterface("IVYZ81NC", map[string]interface{}{
|
||||
resp, err := a.callTianyuanApiWithLog(ctx, "", "IVYZ81NC", map[string]interface{}{
|
||||
"name": name.String(),
|
||||
"id_card": idCard.String(),
|
||||
})
|
||||
@@ -1383,14 +1600,14 @@ func (a *ApiRequestService) ProcessIVYZ81NCRequest(params []byte) ([]byte, error
|
||||
}
|
||||
|
||||
// ProcessIVYZ7F3ARequest 学历查询版B
|
||||
func (a *ApiRequestService) ProcessIVYZ7F3ARequest(params []byte) ([]byte, error) {
|
||||
func (a *ApiRequestService) ProcessIVYZ7F3ARequest(ctx context.Context, params []byte) ([]byte, error) {
|
||||
idCard := gjson.GetBytes(params, "id_card")
|
||||
name := gjson.GetBytes(params, "name")
|
||||
if !idCard.Exists() || !name.Exists() {
|
||||
return nil, errors.New("api请求, IVYZ7F3A, 获取相关参数失败")
|
||||
}
|
||||
|
||||
resp, err := a.tianyuanapi.CallInterface("IVYZ7F3A", map[string]interface{}{
|
||||
resp, err := a.callTianyuanApiWithLog(ctx, "", "IVYZ7F3A", map[string]interface{}{
|
||||
"id_card": idCard.String(),
|
||||
"name": name.String(),
|
||||
"authorized": "1",
|
||||
@@ -1405,7 +1622,7 @@ func (a *ApiRequestService) ProcessIVYZ7F3ARequest(params []byte) ([]byte, error
|
||||
}
|
||||
|
||||
// ProcessDWBG7F3ARequest 多头借贷行业风险版
|
||||
func (a *ApiRequestService) ProcessDWBG7F3ARequest(params []byte) ([]byte, error) {
|
||||
func (a *ApiRequestService) ProcessDWBG7F3ARequest(ctx context.Context, params []byte) ([]byte, error) {
|
||||
name := gjson.GetBytes(params, "name")
|
||||
idCard := gjson.GetBytes(params, "id_card")
|
||||
mobile := gjson.GetBytes(params, "mobile")
|
||||
@@ -1413,7 +1630,7 @@ func (a *ApiRequestService) ProcessDWBG7F3ARequest(params []byte) ([]byte, error
|
||||
return nil, errors.New("api请求, DWBG7F3A, 获取相关参数失败")
|
||||
}
|
||||
|
||||
resp, err := a.tianyuanapi.CallInterface("DWBG7F3A", map[string]interface{}{
|
||||
resp, err := a.callTianyuanApiWithLog(ctx, "", "DWBG7F3A", map[string]interface{}{
|
||||
"name": name.String(),
|
||||
"id_card": idCard.String(),
|
||||
"mobile_no": mobile.String(),
|
||||
@@ -1428,7 +1645,7 @@ func (a *ApiRequestService) ProcessDWBG7F3ARequest(params []byte) ([]byte, error
|
||||
}
|
||||
|
||||
// ProcessJRZQ8A2DRequest 特殊名单验证B
|
||||
func (a *ApiRequestService) ProcessJRZQ8A2DRequest(params []byte) ([]byte, error) {
|
||||
func (a *ApiRequestService) ProcessJRZQ8A2DRequest(ctx context.Context, params []byte) ([]byte, error) {
|
||||
name := gjson.GetBytes(params, "name")
|
||||
idCard := gjson.GetBytes(params, "id_card")
|
||||
mobile := gjson.GetBytes(params, "mobile")
|
||||
@@ -1436,7 +1653,7 @@ func (a *ApiRequestService) ProcessJRZQ8A2DRequest(params []byte) ([]byte, error
|
||||
return nil, errors.New("api请求, JRZQ8A2D, 获取相关参数失败")
|
||||
}
|
||||
|
||||
resp, err := a.tianyuanapi.CallInterface("JRZQ8A2D", map[string]interface{}{
|
||||
resp, err := a.callTianyuanApiWithLog(ctx, "", "JRZQ8A2D", map[string]interface{}{
|
||||
"name": name.String(),
|
||||
"id_card": idCard.String(),
|
||||
"mobile_no": mobile.String(),
|
||||
@@ -1452,13 +1669,13 @@ func (a *ApiRequestService) ProcessJRZQ8A2DRequest(params []byte) ([]byte, error
|
||||
}
|
||||
|
||||
// ProcessYYSY8B1CRequest 手机在网时长B
|
||||
func (a *ApiRequestService) ProcessYYSY8B1CRequest(params []byte) ([]byte, error) {
|
||||
func (a *ApiRequestService) ProcessYYSY8B1CRequest(ctx context.Context, params []byte) ([]byte, error) {
|
||||
mobile := gjson.GetBytes(params, "mobile")
|
||||
if !mobile.Exists() {
|
||||
return nil, errors.New("api请求, YYSY8B1C, 获取相关参数失败")
|
||||
}
|
||||
|
||||
resp, err := a.tianyuanapi.CallInterface("YYSY8B1C", map[string]interface{}{
|
||||
resp, err := a.callTianyuanApiWithLog(ctx, "", "YYSY8B1C", map[string]interface{}{
|
||||
"mobile_no": mobile.String(),
|
||||
})
|
||||
|
||||
@@ -1471,13 +1688,13 @@ func (a *ApiRequestService) ProcessYYSY8B1CRequest(params []byte) ([]byte, error
|
||||
}
|
||||
|
||||
// ProcessYYSY7D3ERequest 携号转网查询
|
||||
func (a *ApiRequestService) ProcessYYSY7D3ERequest(params []byte) ([]byte, error) {
|
||||
func (a *ApiRequestService) ProcessYYSY7D3ERequest(ctx context.Context, params []byte) ([]byte, error) {
|
||||
mobile := gjson.GetBytes(params, "mobile")
|
||||
if !mobile.Exists() {
|
||||
return nil, errors.New("api请求, YYSY7D3E, 获取相关参数失败")
|
||||
}
|
||||
|
||||
resp, err := a.tianyuanapi.CallInterface("YYSY7D3E", map[string]interface{}{
|
||||
resp, err := a.callTianyuanApiWithLog(ctx, "", "YYSY7D3E", map[string]interface{}{
|
||||
"mobile_no": mobile.String(),
|
||||
})
|
||||
|
||||
@@ -1490,7 +1707,7 @@ func (a *ApiRequestService) ProcessYYSY7D3ERequest(params []byte) ([]byte, error
|
||||
}
|
||||
|
||||
// ProcessFLXG7E8FRequest 个人司法涉诉查询
|
||||
func (a *ApiRequestService) ProcessFLXG7E8FRequest(params []byte) ([]byte, error) {
|
||||
func (a *ApiRequestService) ProcessFLXG7E8FRequest(ctx context.Context, params []byte) ([]byte, error) {
|
||||
idCard := gjson.GetBytes(params, "id_card")
|
||||
name := gjson.GetBytes(params, "name")
|
||||
mobile := gjson.GetBytes(params, "mobile")
|
||||
@@ -1498,7 +1715,7 @@ func (a *ApiRequestService) ProcessFLXG7E8FRequest(params []byte) ([]byte, error
|
||||
return nil, errors.New("api请求, FLXG7E8F, 获取相关参数失败")
|
||||
}
|
||||
|
||||
resp, err := a.tianyuanapi.CallInterface("FLXG7E8F", map[string]interface{}{
|
||||
resp, err := a.callTianyuanApiWithLog(ctx, "", "FLXG7E8F", map[string]interface{}{
|
||||
"id_card": idCard.String(),
|
||||
"name": name.String(),
|
||||
"mobile_no": mobile.String(),
|
||||
@@ -1513,7 +1730,7 @@ func (a *ApiRequestService) ProcessFLXG7E8FRequest(params []byte) ([]byte, error
|
||||
}
|
||||
|
||||
// ProcessIVYZ8I9JRequest 互联网行为推测
|
||||
func (a *ApiRequestService) ProcessIVYZ8I9JRequest(params []byte) ([]byte, error) {
|
||||
func (a *ApiRequestService) ProcessIVYZ8I9JRequest(ctx context.Context, params []byte) ([]byte, error) {
|
||||
idCard := gjson.GetBytes(params, "id_card")
|
||||
name := gjson.GetBytes(params, "name")
|
||||
mobile := gjson.GetBytes(params, "mobile")
|
||||
@@ -1521,7 +1738,7 @@ func (a *ApiRequestService) ProcessIVYZ8I9JRequest(params []byte) ([]byte, error
|
||||
return nil, errors.New("api请求, IVYZ8I9J, 获取相关参数失败")
|
||||
}
|
||||
|
||||
resp, err := a.tianyuanapi.CallInterface("IVYZ8I9J", map[string]interface{}{
|
||||
resp, err := a.callTianyuanApiWithLog(ctx, "", "IVYZ8I9J", map[string]interface{}{
|
||||
"id_card": idCard.String(),
|
||||
"name": name.String(),
|
||||
"mobile_no": mobile.String(),
|
||||
@@ -1536,7 +1753,7 @@ func (a *ApiRequestService) ProcessIVYZ8I9JRequest(params []byte) ([]byte, error
|
||||
}
|
||||
|
||||
// ProcessJRZQ7F1ARequest 全景雷达
|
||||
func (a *ApiRequestService) ProcessJRZQ7F1ARequest(params []byte) ([]byte, error) {
|
||||
func (a *ApiRequestService) ProcessJRZQ7F1ARequest(ctx context.Context, params []byte) ([]byte, error) {
|
||||
name := gjson.GetBytes(params, "name")
|
||||
idCard := gjson.GetBytes(params, "id_card")
|
||||
mobile := gjson.GetBytes(params, "mobile")
|
||||
@@ -1544,7 +1761,7 @@ func (a *ApiRequestService) ProcessJRZQ7F1ARequest(params []byte) ([]byte, error
|
||||
return nil, errors.New("api请求, JRZQ7F1A, 获取相关参数失败")
|
||||
}
|
||||
|
||||
resp, err := a.tianyuanapi.CallInterface("JRZQ7F1A", map[string]interface{}{
|
||||
resp, err := a.callTianyuanApiWithLog(ctx, "", "JRZQ7F1A", map[string]interface{}{
|
||||
"name": name.String(),
|
||||
"id_card": idCard.String(),
|
||||
"mobile_no": mobile.String(),
|
||||
@@ -1560,14 +1777,14 @@ func (a *ApiRequestService) ProcessJRZQ7F1ARequest(params []byte) ([]byte, error
|
||||
}
|
||||
|
||||
// ProcessIVYZ3P9MRequest 学历实时查询
|
||||
func (a *ApiRequestService) ProcessIVYZ3P9MRequest(params []byte) ([]byte, error) {
|
||||
func (a *ApiRequestService) ProcessIVYZ3P9MRequest(ctx context.Context, params []byte) ([]byte, error) {
|
||||
idCard := gjson.GetBytes(params, "id_card")
|
||||
name := gjson.GetBytes(params, "name")
|
||||
if !idCard.Exists() || !name.Exists() {
|
||||
return nil, errors.New("api请求, IVYZ3P9M, 获取相关参数失败")
|
||||
}
|
||||
|
||||
resp, err := a.tianyuanapi.CallInterface("IVYZ3P9M", map[string]interface{}{
|
||||
resp, err := a.callTianyuanApiWithLog(ctx, "", "IVYZ3P9M", map[string]interface{}{
|
||||
"id_card": idCard.String(),
|
||||
"name": name.String(),
|
||||
})
|
||||
@@ -1580,7 +1797,7 @@ func (a *ApiRequestService) ProcessIVYZ3P9MRequest(params []byte) ([]byte, error
|
||||
}
|
||||
|
||||
// ProcessJRZQ6F2ARequest 借贷申请
|
||||
func (a *ApiRequestService) ProcessJRZQ6F2ARequest(params []byte) ([]byte, error) {
|
||||
func (a *ApiRequestService) ProcessJRZQ6F2ARequest(ctx context.Context, params []byte) ([]byte, error) {
|
||||
name := gjson.GetBytes(params, "name")
|
||||
idCard := gjson.GetBytes(params, "id_card")
|
||||
mobile := gjson.GetBytes(params, "mobile")
|
||||
@@ -1588,7 +1805,7 @@ func (a *ApiRequestService) ProcessJRZQ6F2ARequest(params []byte) ([]byte, error
|
||||
return nil, errors.New("api请求, JRZQ6F2A, 获取相关参数失败")
|
||||
}
|
||||
|
||||
resp, err := a.tianyuanapi.CallInterface("JRZQ6F2A", map[string]interface{}{
|
||||
resp, err := a.callTianyuanApiWithLog(ctx, "", "JRZQ6F2A", map[string]interface{}{
|
||||
"name": name.String(),
|
||||
"id_card": idCard.String(),
|
||||
"mobile_no": mobile.String(),
|
||||
@@ -1600,3 +1817,27 @@ func (a *ApiRequestService) ProcessJRZQ6F2ARequest(params []byte) ([]byte, error
|
||||
|
||||
return convertTianyuanResponse(resp)
|
||||
}
|
||||
|
||||
// ProcessCOMBQN12Request 全能入职背调报告(标准版) - 组合包
|
||||
func (a *ApiRequestService) ProcessCOMBQN12Request(ctx context.Context, params []byte) ([]byte, error) {
|
||||
name := gjson.GetBytes(params, "name")
|
||||
idCard := gjson.GetBytes(params, "id_card")
|
||||
mobile := gjson.GetBytes(params, "mobile")
|
||||
if !name.Exists() || !idCard.Exists() || !mobile.Exists() {
|
||||
return nil, errors.New("api请求, COMBQN12, 获取相关参数失败")
|
||||
}
|
||||
|
||||
resp, err := a.callTianyuanApiWithLog(ctx, "", "COMBQN12", map[string]interface{}{
|
||||
"name": name.String(),
|
||||
"id_card": idCard.String(),
|
||||
"mobile_no": mobile.String(),
|
||||
"authorized": "1",
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 使用组合包响应转换函数,自动检测并转换
|
||||
return convertTianyuanBundleResponse(resp)
|
||||
}
|
||||
|
||||
216
app/main/api/internal/service/tianyuanapiCallLogService.go
Normal file
216
app/main/api/internal/service/tianyuanapiCallLogService.go
Normal file
@@ -0,0 +1,216 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"bdqr-server/app/main/model"
|
||||
"context"
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/Masterminds/squirrel"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
// TianyuanapiCallLogService 天元API调用记录服务
|
||||
type TianyuanapiCallLogService struct {
|
||||
tianyuanapiCallLogModel model.TianyuanapiCallLogModel
|
||||
featureModel model.FeatureModel
|
||||
}
|
||||
|
||||
// NewTianyuanapiCallLogService 创建天元API调用记录服务
|
||||
func NewTianyuanapiCallLogService(
|
||||
tianyuanapiCallLogModel model.TianyuanapiCallLogModel,
|
||||
featureModel model.FeatureModel,
|
||||
) *TianyuanapiCallLogService {
|
||||
return &TianyuanapiCallLogService{
|
||||
tianyuanapiCallLogModel: tianyuanapiCallLogModel,
|
||||
featureModel: featureModel,
|
||||
}
|
||||
}
|
||||
|
||||
// CallLogOptions 调用记录选项
|
||||
type CallLogOptions struct {
|
||||
FeatureID string // 功能ID
|
||||
ApiID string // API标识(如:YYSYBE08)
|
||||
OrderID string // 订单ID(可选)
|
||||
QueryID string // 查询ID(可选)
|
||||
CallStatus int64 // 调用状态:0=失败,1=成功
|
||||
ResponseTime int64 // 响应耗时(毫秒)
|
||||
ErrorCode string // 错误码(失败时)
|
||||
ErrorMessage string // 错误信息(失败时)
|
||||
RequestParams interface{} // 请求参数(可选)
|
||||
ResponseData interface{} // 响应数据(可选)
|
||||
TransactionID string // 天元API流水号
|
||||
}
|
||||
|
||||
// RecordCall 记录天元API调用
|
||||
func (s *TianyuanapiCallLogService) RecordCall(ctx context.Context, opts CallLogOptions) error {
|
||||
// 1. 获取feature的成本价
|
||||
costPrice := 0.00
|
||||
if opts.CallStatus == 1 { // 只有成功才计算成本
|
||||
if opts.FeatureID == "" {
|
||||
logx.Infof("记录API调用时feature_id为空,api_id=%s,无法获取成本价", opts.ApiID)
|
||||
} else {
|
||||
feature, err := s.featureModel.FindOne(ctx, opts.FeatureID)
|
||||
if err == nil {
|
||||
costPrice = feature.CostPrice
|
||||
logx.Infof("记录API调用 - feature_id=%s, api_id=%s, cost_price=%f", opts.FeatureID, opts.ApiID, costPrice)
|
||||
} else {
|
||||
logx.Errorf("查询feature成本价失败,feature_id=%s, api_id=%s, err=%v", opts.FeatureID, opts.ApiID, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 2. 转换参数和响应为JSON字符串
|
||||
var requestParamsStr, responseDataStr *string
|
||||
if opts.RequestParams != nil {
|
||||
if bytes, err := json.Marshal(opts.RequestParams); err == nil {
|
||||
jsonStr := string(bytes)
|
||||
requestParamsStr = &jsonStr
|
||||
}
|
||||
}
|
||||
if opts.ResponseData != nil {
|
||||
// 只记录响应数据的前1000个字符,避免存储过大
|
||||
if bytes, err := json.Marshal(opts.ResponseData); err == nil {
|
||||
jsonStr := string(bytes)
|
||||
if len(jsonStr) > 1000 {
|
||||
jsonStr = jsonStr[:1000] + "...[truncated]"
|
||||
}
|
||||
responseDataStr = &jsonStr
|
||||
}
|
||||
}
|
||||
|
||||
// 3. 构建调用记录
|
||||
callTime := time.Now()
|
||||
deleteTime := sql.NullTime{}
|
||||
callLog := &model.TianyuanapiCallLog{
|
||||
FeatureId: opts.FeatureID,
|
||||
ApiId: opts.ApiID,
|
||||
OrderId: sql.NullString{},
|
||||
QueryId: sql.NullString{},
|
||||
CallStatus: opts.CallStatus,
|
||||
CallTime: callTime,
|
||||
ResponseTime: sql.NullInt64{},
|
||||
CostPrice: costPrice,
|
||||
ErrorCode: sql.NullString{},
|
||||
ErrorMessage: sql.NullString{},
|
||||
RequestParams: sql.NullString{},
|
||||
ResponseData: sql.NullString{},
|
||||
TransactionId: sql.NullString{},
|
||||
CreateTime: callTime,
|
||||
UpdateTime: callTime,
|
||||
DeleteTime: deleteTime,
|
||||
DelState: 0,
|
||||
Version: 0,
|
||||
}
|
||||
|
||||
// 4. 填充可选字段
|
||||
if opts.OrderID != "" {
|
||||
callLog.OrderId = sql.NullString{String: opts.OrderID, Valid: true}
|
||||
}
|
||||
if opts.QueryID != "" {
|
||||
callLog.QueryId = sql.NullString{String: opts.QueryID, Valid: true}
|
||||
}
|
||||
if opts.ResponseTime > 0 {
|
||||
callLog.ResponseTime = sql.NullInt64{Int64: opts.ResponseTime, Valid: true}
|
||||
}
|
||||
if opts.ErrorCode != "" {
|
||||
callLog.ErrorCode = sql.NullString{String: opts.ErrorCode, Valid: true}
|
||||
}
|
||||
if opts.ErrorMessage != "" {
|
||||
callLog.ErrorMessage = sql.NullString{String: opts.ErrorMessage, Valid: true}
|
||||
}
|
||||
if requestParamsStr != nil {
|
||||
callLog.RequestParams = sql.NullString{String: *requestParamsStr, Valid: true}
|
||||
}
|
||||
if responseDataStr != nil {
|
||||
callLog.ResponseData = sql.NullString{String: *responseDataStr, Valid: true}
|
||||
}
|
||||
if opts.TransactionID != "" {
|
||||
callLog.TransactionId = sql.NullString{String: opts.TransactionID, Valid: true}
|
||||
}
|
||||
|
||||
// 5. 插入记录
|
||||
_, err := s.tianyuanapiCallLogModel.Insert(ctx, nil, callLog)
|
||||
if err != nil {
|
||||
logx.Errorf("插入天元API调用记录失败,feature_id=%s, api_id=%s, err=%v", opts.FeatureID, opts.ApiID, err)
|
||||
return fmt.Errorf("插入调用记录失败: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetStatistics 获取统计信息
|
||||
type StatisticsFilter struct {
|
||||
FeatureID string // 功能ID
|
||||
ApiID string // API标识
|
||||
StartDate time.Time // 开始日期
|
||||
EndDate time.Time // 结束日期
|
||||
}
|
||||
|
||||
// Statistics 统计信息
|
||||
type Statistics struct {
|
||||
TotalCalls int64 // 总调用次数
|
||||
SuccessCalls int64 // 成功次数
|
||||
FailedCalls int64 // 失败次数
|
||||
TotalCost float64 // 总成本(成功调用的成本之和)
|
||||
}
|
||||
|
||||
// GetStatistics 获取统计信息
|
||||
func (s *TianyuanapiCallLogService) GetStatistics(ctx context.Context, filter StatisticsFilter) (*Statistics, error) {
|
||||
builder := s.tianyuanapiCallLogModel.SelectBuilder()
|
||||
|
||||
// 添加过滤条件
|
||||
if filter.FeatureID != "" {
|
||||
builder = builder.Where(squirrel.Eq{"feature_id": filter.FeatureID})
|
||||
}
|
||||
if filter.ApiID != "" {
|
||||
builder = builder.Where(squirrel.Eq{"api_id": filter.ApiID})
|
||||
}
|
||||
if !filter.StartDate.IsZero() {
|
||||
builder = builder.Where(squirrel.GtOrEq{"call_time": filter.StartDate})
|
||||
logx.Infof("API成本统计 - 开始时间: %v", filter.StartDate)
|
||||
}
|
||||
if !filter.EndDate.IsZero() {
|
||||
builder = builder.Where(squirrel.Lt{"call_time": filter.EndDate})
|
||||
logx.Infof("API成本统计 - 结束时间: %v", filter.EndDate)
|
||||
}
|
||||
|
||||
// 统计总调用次数
|
||||
totalCalls, err := s.tianyuanapiCallLogModel.FindCount(ctx, builder, "id")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("统计总调用次数失败: %w", err)
|
||||
}
|
||||
logx.Infof("API成本统计 - 总调用次数: %d", totalCalls)
|
||||
|
||||
// 统计成功次数
|
||||
successBuilder := builder.Where(squirrel.Eq{"call_status": 1})
|
||||
successCalls, err := s.tianyuanapiCallLogModel.FindCount(ctx, successBuilder, "id")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("统计成功次数失败: %w", err)
|
||||
}
|
||||
logx.Infof("API成本统计 - 成功调用次数: %d", successCalls)
|
||||
|
||||
// 统计失败次数
|
||||
failedCalls := totalCalls - successCalls
|
||||
|
||||
// 统计总成本(仅成功调用)
|
||||
// 先打印SQL以便调试(复制builder避免影响后续查询)
|
||||
debugBuilder := successBuilder
|
||||
query, values, _ := debugBuilder.Columns("IFNULL(SUM(cost_price),0)").Where("del_state = ?", 0).ToSql()
|
||||
logx.Infof("API成本统计 - SQL: %s, 参数: %v", query, values)
|
||||
|
||||
totalCost, err := s.tianyuanapiCallLogModel.FindSum(ctx, successBuilder, "cost_price")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("统计总成本失败: %w", err)
|
||||
}
|
||||
logx.Infof("API成本统计 - 总成本: %f", totalCost)
|
||||
|
||||
return &Statistics{
|
||||
TotalCalls: totalCalls,
|
||||
SuccessCalls: successCalls,
|
||||
FailedCalls: failedCalls,
|
||||
TotalCost: totalCost,
|
||||
}, nil
|
||||
}
|
||||
570
app/main/api/internal/service/whitelistService.go
Normal file
570
app/main/api/internal/service/whitelistService.go
Normal file
@@ -0,0 +1,570 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"strings"
|
||||
|
||||
"bdqr-server/app/main/api/internal/config"
|
||||
"bdqr-server/app/main/model"
|
||||
"bdqr-server/common/xerr"
|
||||
"bdqr-server/pkg/lzkit/crypto"
|
||||
"bdqr-server/pkg/lzkit/lzUtils"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
)
|
||||
|
||||
// WhitelistService 白名单领域服务,集中处理白名单相关的业务逻辑
|
||||
type WhitelistService struct {
|
||||
config config.Config
|
||||
UserFeatureWhitelistModel model.UserFeatureWhitelistModel
|
||||
WhitelistOrderModel model.WhitelistOrderModel
|
||||
WhitelistOrderItemModel model.WhitelistOrderItemModel
|
||||
QueryModel model.QueryModel
|
||||
FeatureModel model.FeatureModel
|
||||
}
|
||||
|
||||
// NewWhitelistService 创建白名单服务
|
||||
func NewWhitelistService(
|
||||
c config.Config,
|
||||
userFeatureWhitelistModel model.UserFeatureWhitelistModel,
|
||||
whitelistOrderModel model.WhitelistOrderModel,
|
||||
whitelistOrderItemModel model.WhitelistOrderItemModel,
|
||||
queryModel model.QueryModel,
|
||||
featureModel model.FeatureModel,
|
||||
) *WhitelistService {
|
||||
return &WhitelistService{
|
||||
config: c,
|
||||
UserFeatureWhitelistModel: userFeatureWhitelistModel,
|
||||
WhitelistOrderModel: whitelistOrderModel,
|
||||
WhitelistOrderItemModel: whitelistOrderItemModel,
|
||||
QueryModel: queryModel,
|
||||
FeatureModel: featureModel,
|
||||
}
|
||||
}
|
||||
|
||||
// EnsureFreeWhitelist 免费下架:如果还没有生效白名单,则创建一条免费白名单记录
|
||||
func (s *WhitelistService) EnsureFreeWhitelist(
|
||||
ctx context.Context,
|
||||
session sqlx.Session,
|
||||
idCard string,
|
||||
feature *model.Feature,
|
||||
userId string,
|
||||
orderId string,
|
||||
) error {
|
||||
// 检查是否已存在生效白名单
|
||||
builder := s.UserFeatureWhitelistModel.SelectBuilder().
|
||||
Where("id_card = ? AND feature_id = ?", idCard, feature.Id)
|
||||
records, err := s.UserFeatureWhitelistModel.FindAll(ctx, builder, "")
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "查询白名单记录失败")
|
||||
}
|
||||
for _, r := range records {
|
||||
if r.Status == 1 {
|
||||
// 已经下架,直接返回
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
wl := &model.UserFeatureWhitelist{
|
||||
Id: uuid.NewString(),
|
||||
IdCard: idCard,
|
||||
FeatureId: feature.Id,
|
||||
FeatureApiId: feature.ApiId,
|
||||
UserId: userId,
|
||||
OrderId: lzUtils.StringToNullString(orderId),
|
||||
WhitelistOrderId: lzUtils.StringToNullString(""),
|
||||
Amount: 0,
|
||||
Status: 1,
|
||||
}
|
||||
|
||||
_, err = s.UserFeatureWhitelistModel.Insert(ctx, session, wl)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "创建免费白名单记录失败")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// CreateWhitelistByPaidOrder 根据已支付的白名单订单,创建对应的白名单记录
|
||||
func (s *WhitelistService) CreateWhitelistByPaidOrder(
|
||||
ctx context.Context,
|
||||
session sqlx.Session,
|
||||
order *model.Order,
|
||||
whitelistOrder *model.WhitelistOrder,
|
||||
) error {
|
||||
if whitelistOrder.Status != 2 {
|
||||
// 只处理已支付状态
|
||||
return nil
|
||||
}
|
||||
|
||||
itemBuilder := s.WhitelistOrderItemModel.SelectBuilder().
|
||||
Where("order_id = ?", whitelistOrder.Id)
|
||||
items, err := s.WhitelistOrderItemModel.FindAll(ctx, itemBuilder, "")
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "查询白名单订单明细失败")
|
||||
}
|
||||
|
||||
for _, item := range items {
|
||||
wl := &model.UserFeatureWhitelist{
|
||||
Id: uuid.NewString(),
|
||||
IdCard: whitelistOrder.IdCard,
|
||||
FeatureId: item.FeatureId,
|
||||
FeatureApiId: item.FeatureApiId,
|
||||
UserId: whitelistOrder.UserId,
|
||||
OrderId: lzUtils.StringToNullString(order.Id),
|
||||
WhitelistOrderId: lzUtils.StringToNullString(whitelistOrder.Id),
|
||||
Amount: item.Price,
|
||||
Status: 1,
|
||||
}
|
||||
if _, err := s.UserFeatureWhitelistModel.Insert(ctx, session, wl); err != nil {
|
||||
return errors.Wrap(err, "创建白名单记录失败")
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetWhitelistedFeatureApisByIdCard 获取某个身份证号已下架的 feature_api_id 集合
|
||||
func (s *WhitelistService) GetWhitelistedFeatureApisByIdCard(
|
||||
ctx context.Context,
|
||||
idCard string,
|
||||
) (map[string]bool, error) {
|
||||
result := make(map[string]bool)
|
||||
if s == nil {
|
||||
return result, nil
|
||||
}
|
||||
if idCard == "" {
|
||||
return result, nil
|
||||
}
|
||||
|
||||
builder := s.UserFeatureWhitelistModel.SelectBuilder().
|
||||
Where("id_card = ? AND status = ?", idCard, 1)
|
||||
list, err := s.UserFeatureWhitelistModel.FindAll(ctx, builder, "")
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "查询白名单失败")
|
||||
}
|
||||
|
||||
for _, wl := range list {
|
||||
result[wl.FeatureApiId] = true
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// CheckWhitelistExists 检查指定身份证号和模块是否已有生效的白名单记录
|
||||
func (s *WhitelistService) CheckWhitelistExists(
|
||||
ctx context.Context,
|
||||
idCard string,
|
||||
featureId string,
|
||||
) (bool, error) {
|
||||
if idCard == "" || featureId == "" {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
builder := s.UserFeatureWhitelistModel.SelectBuilder().
|
||||
Where("id_card = ? AND feature_id = ? AND status = ?", idCard, featureId, 1)
|
||||
list, err := s.UserFeatureWhitelistModel.FindAll(ctx, builder, "")
|
||||
if err != nil {
|
||||
return false, errors.Wrap(err, "查询白名单记录失败")
|
||||
}
|
||||
|
||||
return len(list) > 0, nil
|
||||
}
|
||||
|
||||
// ProcessOfflineFeature 统一下架处理:处理免费下架或检查付费下架
|
||||
// 返回:needPay(是否需要支付), amount(金额), whitelistCreated(是否已创建白名单)
|
||||
func (s *WhitelistService) ProcessOfflineFeature(
|
||||
ctx context.Context,
|
||||
session sqlx.Session,
|
||||
idCard string,
|
||||
featureApiId string,
|
||||
userId string,
|
||||
orderId string,
|
||||
) (needPay bool, amount float64, whitelistCreated bool, err error) {
|
||||
// 1. 提取主模块ID并查询feature信息
|
||||
mainApiId := s.extractMainApiId(featureApiId)
|
||||
feature, err := s.getFeatureByApiId(ctx, mainApiId)
|
||||
if err != nil {
|
||||
return false, 0, false, err
|
||||
}
|
||||
|
||||
// 2. 不支持下架的模块:whitelist_price < 0 表示该模块不开放下架功能
|
||||
if feature.WhitelistPrice < 0 {
|
||||
return false, 0, false, errors.Wrapf(xerr.NewErrMsg("该模块不支持下架"), "")
|
||||
}
|
||||
|
||||
// 3. 检查是否已有白名单
|
||||
exists, err := s.CheckWhitelistExists(ctx, idCard, feature.Id)
|
||||
if err != nil {
|
||||
return false, 0, false, err
|
||||
}
|
||||
if exists {
|
||||
// 已有白名单,直接返回成功
|
||||
return false, 0, true, nil
|
||||
}
|
||||
|
||||
price := feature.WhitelistPrice
|
||||
|
||||
// 4. 免费下架:直接创建白名单记录(whitelist_price = 0)
|
||||
if price <= 0 {
|
||||
if err := s.EnsureFreeWhitelist(ctx, session, idCard, feature, userId, orderId); err != nil {
|
||||
return false, 0, false, err
|
||||
}
|
||||
return false, 0, true, nil
|
||||
}
|
||||
|
||||
// 5. 付费下架:检查是否已有支付成功的订单
|
||||
paidOrderId, err := s.findPaidWhitelistOrder(ctx, userId, idCard, feature.Id)
|
||||
if err != nil {
|
||||
return false, 0, false, err
|
||||
}
|
||||
|
||||
// 6. 如果已有支付成功订单,补创建白名单记录
|
||||
if paidOrderId != "" {
|
||||
if err := s.createWhitelistFromPaidOrder(ctx, session, idCard, feature, userId, orderId, paidOrderId, price); err != nil {
|
||||
return false, 0, false, err
|
||||
}
|
||||
return false, price, true, nil
|
||||
}
|
||||
|
||||
// 7. 需要支付
|
||||
return true, price, false, nil
|
||||
}
|
||||
|
||||
// extractMainApiId 提取主模块ID(去掉下划线后的部分)
|
||||
func (s *WhitelistService) extractMainApiId(featureApiId string) string {
|
||||
if idx := strings.Index(featureApiId, "_"); idx > 0 {
|
||||
return featureApiId[:idx]
|
||||
}
|
||||
return featureApiId
|
||||
}
|
||||
|
||||
// getFeatureByApiId 根据API ID查询feature信息
|
||||
func (s *WhitelistService) getFeatureByApiId(ctx context.Context, apiId string) (*model.Feature, error) {
|
||||
feature, err := s.FeatureModel.FindOneByApiId(ctx, apiId)
|
||||
if err != nil {
|
||||
if errors.Is(err, model.ErrNotFound) {
|
||||
return nil, errors.Wrap(err, "模块不存在")
|
||||
}
|
||||
return nil, errors.Wrap(err, "查询模块信息失败")
|
||||
}
|
||||
return feature, nil
|
||||
}
|
||||
|
||||
// findPaidWhitelistOrder 查找已支付的白名单订单中是否包含指定feature
|
||||
// 返回:paidOrderId(如果找到已支付订单),error
|
||||
func (s *WhitelistService) findPaidWhitelistOrder(
|
||||
ctx context.Context,
|
||||
userId string,
|
||||
idCard string,
|
||||
featureId string,
|
||||
) (string, error) {
|
||||
orderBuilder := s.WhitelistOrderModel.SelectBuilder().
|
||||
Where("user_id = ? AND id_card = ? AND status = ?", userId, idCard, 2) // 2表示已支付
|
||||
orders, err := s.WhitelistOrderModel.FindAll(ctx, orderBuilder, "")
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "查询白名单订单失败")
|
||||
}
|
||||
|
||||
// 查找已支付订单中是否包含该feature
|
||||
for _, order := range orders {
|
||||
itemBuilder := s.WhitelistOrderItemModel.SelectBuilder().
|
||||
Where("order_id = ? AND feature_id = ?", order.Id, featureId)
|
||||
items, itemErr := s.WhitelistOrderItemModel.FindAll(ctx, itemBuilder, "")
|
||||
if itemErr != nil {
|
||||
return "", errors.Wrap(itemErr, "查询白名单订单明细失败")
|
||||
}
|
||||
if len(items) > 0 {
|
||||
return order.Id, nil
|
||||
}
|
||||
}
|
||||
|
||||
return "", nil
|
||||
}
|
||||
|
||||
// createWhitelistFromPaidOrder 根据已支付订单创建白名单记录
|
||||
func (s *WhitelistService) createWhitelistFromPaidOrder(
|
||||
ctx context.Context,
|
||||
session sqlx.Session,
|
||||
idCard string,
|
||||
feature *model.Feature,
|
||||
userId string,
|
||||
orderId string,
|
||||
paidOrderId string,
|
||||
price float64,
|
||||
) error {
|
||||
wl := &model.UserFeatureWhitelist{
|
||||
Id: uuid.NewString(),
|
||||
IdCard: idCard,
|
||||
FeatureId: feature.Id,
|
||||
FeatureApiId: feature.ApiId,
|
||||
UserId: userId,
|
||||
OrderId: lzUtils.StringToNullString(orderId),
|
||||
WhitelistOrderId: lzUtils.StringToNullString(paidOrderId),
|
||||
Amount: price,
|
||||
Status: 1, // 生效
|
||||
}
|
||||
if _, err := s.UserFeatureWhitelistModel.Insert(ctx, session, wl); err != nil {
|
||||
return errors.Wrap(err, "根据已支付订单创建白名单记录失败")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeleteFeatureFromQueryData 从报告数据中删除指定模块的数据
|
||||
// queryId: 查询记录ID(Query表的ID)
|
||||
// featureApiId: 要删除的模块API标识
|
||||
func (s *WhitelistService) DeleteFeatureFromQueryData(
|
||||
ctx context.Context,
|
||||
session sqlx.Session,
|
||||
queryId string,
|
||||
featureApiId string,
|
||||
) error {
|
||||
// 1. 获取查询记录
|
||||
queryModel, err := s.getQueryModel(ctx, queryId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if queryModel == nil {
|
||||
// 报告不存在或数据为空,直接返回成功
|
||||
return nil
|
||||
}
|
||||
|
||||
// 2. 解密并解析报告数据
|
||||
mainApiId := s.extractMainApiId(featureApiId)
|
||||
dataArray, key, err := s.decryptQueryData(queryModel)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// 3. 清空对应模块的数据(将 data 字段设置为 null)
|
||||
modifiedArray, hasModified := s.clearFeatureData(dataArray, mainApiId)
|
||||
if !hasModified {
|
||||
logx.Infof("删除报告数据:查询记录 %s 中未找到模块 %s 的数据,跳过删除", queryId, featureApiId)
|
||||
return nil
|
||||
}
|
||||
|
||||
// 4. 重新加密并更新数据库
|
||||
if err := s.updateQueryData(ctx, session, queryModel, modifiedArray, key); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
logx.Infof("删除报告数据成功:查询记录 %s,模块 %s,已将对应模块的 data 字段设置为 null", queryId, featureApiId)
|
||||
return nil
|
||||
}
|
||||
|
||||
// getQueryModel 获取查询记录,如果不存在或数据为空则返回nil
|
||||
func (s *WhitelistService) getQueryModel(ctx context.Context, queryId string) (*model.Query, error) {
|
||||
queryModel, err := s.QueryModel.FindOne(ctx, queryId)
|
||||
if err != nil {
|
||||
if errors.Is(err, model.ErrNotFound) {
|
||||
logx.Infof("删除报告数据:查询记录 %s 不存在,跳过删除", queryId)
|
||||
return nil, nil
|
||||
}
|
||||
return nil, errors.Wrap(err, "查询报告记录失败")
|
||||
}
|
||||
|
||||
// 如果报告数据为空,直接返回
|
||||
if !queryModel.QueryData.Valid || queryModel.QueryData.String == "" {
|
||||
logx.Infof("删除报告数据:查询记录 %s 对应的报告数据为空,跳过删除", queryId)
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
return queryModel, nil
|
||||
}
|
||||
|
||||
// decryptQueryData 解密并解析报告数据
|
||||
func (s *WhitelistService) decryptQueryData(queryModel *model.Query) ([]map[string]interface{}, []byte, error) {
|
||||
// 获取加密密钥
|
||||
secretKey := s.config.Encrypt.SecretKey
|
||||
key, decodeErr := hex.DecodeString(secretKey)
|
||||
if decodeErr != nil {
|
||||
return nil, nil, errors.Wrap(decodeErr, "获取AES密钥失败")
|
||||
}
|
||||
|
||||
// 解密报告数据
|
||||
decryptedData, decryptErr := crypto.AesDecrypt(queryModel.QueryData.String, key)
|
||||
if decryptErr != nil {
|
||||
return nil, nil, errors.Wrap(decryptErr, "解密报告数据失败")
|
||||
}
|
||||
|
||||
// 解析JSON数组
|
||||
var dataArray []map[string]interface{}
|
||||
unmarshalErr := json.Unmarshal(decryptedData, &dataArray)
|
||||
if unmarshalErr != nil {
|
||||
return nil, nil, errors.Wrap(unmarshalErr, "解析报告数据失败")
|
||||
}
|
||||
|
||||
return dataArray, key, nil
|
||||
}
|
||||
|
||||
// clearFeatureData 清空指定模块的数据(将 data 字段设置为 null)
|
||||
// 返回修改后的数组和是否进行了修改
|
||||
func (s *WhitelistService) clearFeatureData(dataArray []map[string]interface{}, mainApiId string) ([]map[string]interface{}, bool) {
|
||||
modifiedArray := make([]map[string]interface{}, 0, len(dataArray))
|
||||
hasModified := false
|
||||
|
||||
for _, item := range dataArray {
|
||||
// 深拷贝 item,避免修改原数据
|
||||
newItem := make(map[string]interface{})
|
||||
for k, v := range item {
|
||||
newItem[k] = v
|
||||
}
|
||||
|
||||
apiID, ok := item["apiID"].(string)
|
||||
if !ok {
|
||||
// 如果apiID不存在或类型不对,保留原样
|
||||
modifiedArray = append(modifiedArray, newItem)
|
||||
continue
|
||||
}
|
||||
|
||||
// 提取主模块ID进行比较
|
||||
itemMainApiId := s.extractMainApiId(apiID)
|
||||
|
||||
// 如果主模块ID匹配,将 data 字段设置为 null
|
||||
if itemMainApiId == mainApiId {
|
||||
newItem["data"] = nil
|
||||
hasModified = true
|
||||
}
|
||||
|
||||
modifiedArray = append(modifiedArray, newItem)
|
||||
}
|
||||
|
||||
return modifiedArray, hasModified
|
||||
}
|
||||
|
||||
// updateQueryData 重新加密并更新数据库
|
||||
func (s *WhitelistService) updateQueryData(
|
||||
ctx context.Context,
|
||||
session sqlx.Session,
|
||||
queryModel *model.Query,
|
||||
filteredArray []map[string]interface{},
|
||||
key []byte,
|
||||
) error {
|
||||
// 重新序列化
|
||||
filteredBytes, marshalErr := json.Marshal(filteredArray)
|
||||
if marshalErr != nil {
|
||||
return errors.Wrap(marshalErr, "序列化过滤后的报告数据失败")
|
||||
}
|
||||
|
||||
// 重新加密
|
||||
encryptedData, encryptErr := crypto.AesEncrypt(filteredBytes, key)
|
||||
if encryptErr != nil {
|
||||
return errors.Wrap(encryptErr, "加密过滤后的报告数据失败")
|
||||
}
|
||||
|
||||
// 更新数据库
|
||||
queryModel.QueryData = sql.NullString{
|
||||
String: encryptedData,
|
||||
Valid: true,
|
||||
}
|
||||
updateErr := s.QueryModel.UpdateWithVersion(ctx, session, queryModel)
|
||||
if updateErr != nil {
|
||||
return errors.Wrap(updateErr, "更新报告数据失败")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// CheckQueryDataContainsFeature 检查报告数据中是否包含指定的模块
|
||||
// 返回 true 表示包含该模块,false 表示不包含(已删除)
|
||||
func (s *WhitelistService) CheckQueryDataContainsFeature(
|
||||
ctx context.Context,
|
||||
queryId string,
|
||||
featureApiId string,
|
||||
) (bool, error) {
|
||||
// 1. 获取查询记录
|
||||
queryModel, err := s.getQueryModel(ctx, queryId)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
if queryModel == nil {
|
||||
// 报告不存在,认为数据已删除
|
||||
return false, nil
|
||||
}
|
||||
|
||||
// 2. 解密并解析报告数据
|
||||
mainApiId := s.extractMainApiId(featureApiId)
|
||||
dataArray, _, err := s.decryptQueryData(queryModel)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
// 3. 检查数据中是否包含该模块(且 data 不为 null)
|
||||
for _, item := range dataArray {
|
||||
apiID, ok := item["apiID"].(string)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
// 提取主模块ID进行比较
|
||||
itemMainApiId := s.extractMainApiId(apiID)
|
||||
if itemMainApiId == mainApiId {
|
||||
// 找到了该模块,检查 data 字段
|
||||
dataValue, exists := item["data"]
|
||||
if !exists || dataValue == nil {
|
||||
// data 字段不存在或为 null,认为数据已删除
|
||||
return false, nil
|
||||
}
|
||||
// data 字段存在且不为 null,认为数据存在
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
|
||||
// 未找到该模块的数据,说明已删除
|
||||
return false, nil
|
||||
}
|
||||
|
||||
// ProcessPaidWhitelistOrder 处理已支付的白名单订单:创建白名单记录并删除报告数据
|
||||
// order: 支付订单(Order表)
|
||||
// whitelistOrder: 白名单订单(WhitelistOrder表)
|
||||
func (s *WhitelistService) ProcessPaidWhitelistOrder(
|
||||
ctx context.Context,
|
||||
session sqlx.Session,
|
||||
order *model.Order,
|
||||
whitelistOrder *model.WhitelistOrder,
|
||||
) error {
|
||||
if whitelistOrder.Status != 2 {
|
||||
// 只处理已支付状态
|
||||
return nil
|
||||
}
|
||||
|
||||
// 查询订单明细
|
||||
itemBuilder := s.WhitelistOrderItemModel.SelectBuilder().
|
||||
Where("order_id = ?", whitelistOrder.Id)
|
||||
items, err := s.WhitelistOrderItemModel.FindAll(ctx, itemBuilder, "")
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "查询白名单订单明细失败")
|
||||
}
|
||||
|
||||
// 为每个明细创建白名单记录并删除报告数据
|
||||
for _, item := range items {
|
||||
// 创建白名单记录
|
||||
wl := &model.UserFeatureWhitelist{
|
||||
Id: uuid.NewString(),
|
||||
IdCard: whitelistOrder.IdCard,
|
||||
FeatureId: item.FeatureId,
|
||||
FeatureApiId: item.FeatureApiId,
|
||||
UserId: whitelistOrder.UserId,
|
||||
OrderId: lzUtils.StringToNullString(""), // 查询订单ID,如果有的话会在后续步骤中设置
|
||||
WhitelistOrderId: lzUtils.StringToNullString(whitelistOrder.Id),
|
||||
Amount: item.Price,
|
||||
Status: 1, // 生效
|
||||
}
|
||||
if _, err := s.UserFeatureWhitelistModel.Insert(ctx, session, wl); err != nil {
|
||||
return errors.Wrap(err, "创建白名单记录失败")
|
||||
}
|
||||
|
||||
// 尝试删除报告数据
|
||||
// 注意:由于支付回调时可能不知道具体的查询订单ID,这里先尝试根据 id_card 查找
|
||||
// 如果找不到对应的报告,就跳过删除步骤(不影响主流程)
|
||||
// 实际的报告数据删除应该在 OfflineFeature 接口中完成(如果提供了 orderId)
|
||||
// 这里暂时不删除,因为无法确定是哪个具体的查询订单
|
||||
logx.Infof("白名单订单支付成功:订单 %s,模块 %s,已创建白名单记录。如需删除报告数据,请在 OfflineFeature 接口中提供查询订单ID", whitelistOrder.OrderNo, item.FeatureApiId)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -34,6 +34,11 @@ type ServiceContext struct {
|
||||
FeatureModel model.FeatureModel
|
||||
ProductFeatureModel model.ProductFeatureModel
|
||||
|
||||
// 白名单相关模型
|
||||
UserFeatureWhitelistModel model.UserFeatureWhitelistModel
|
||||
WhitelistOrderModel model.WhitelistOrderModel
|
||||
WhitelistOrderItemModel model.WhitelistOrderItemModel
|
||||
|
||||
// 订单相关模型
|
||||
OrderModel model.OrderModel
|
||||
OrderRefundModel model.OrderRefundModel
|
||||
@@ -77,11 +82,14 @@ type ServiceContext struct {
|
||||
GlobalNotificationsModel model.GlobalNotificationsModel
|
||||
AuthorizationDocumentModel model.AuthorizationDocumentModel
|
||||
|
||||
// 第三方服务
|
||||
TianyuanapiCallLogService *service.TianyuanapiCallLogService
|
||||
// 服务
|
||||
AlipayService *service.AliPayService
|
||||
WechatPayService *service.WechatPayService
|
||||
ApplePayService *service.ApplePayService
|
||||
ApiRequestService *service.ApiRequestService
|
||||
WhitelistService *service.WhitelistService
|
||||
AsynqServer *asynq.Server
|
||||
AsynqService *service.AsynqService
|
||||
VerificationService *service.VerificationService
|
||||
@@ -116,6 +124,11 @@ func NewServiceContext(c config.Config) *ServiceContext {
|
||||
featureModel := model.NewFeatureModel(db, cacheConf)
|
||||
productFeatureModel := model.NewProductFeatureModel(db, cacheConf)
|
||||
|
||||
// ============================== 白名单相关模型 ==============================
|
||||
userFeatureWhitelistModel := model.NewUserFeatureWhitelistModel(db, cacheConf)
|
||||
whitelistOrderModel := model.NewWhitelistOrderModel(db, cacheConf)
|
||||
whitelistOrderItemModel := model.NewWhitelistOrderItemModel(db, cacheConf)
|
||||
|
||||
// ============================== 订单相关模型 ==============================
|
||||
orderModel := model.NewOrderModel(db, cacheConf)
|
||||
queryModel := model.NewQueryModel(db, cacheConf)
|
||||
@@ -158,6 +171,7 @@ func NewServiceContext(c config.Config) *ServiceContext {
|
||||
globalNotificationsModel := model.NewGlobalNotificationsModel(db, cacheConf)
|
||||
authorizationDocumentModel := model.NewAuthorizationDocumentModel(db, cacheConf)
|
||||
|
||||
tianyuanapiCallLogModel := model.NewTianyuanapiCallLogModel(db, cacheConf)
|
||||
// ============================== 第三方服务初始化 ==============================
|
||||
tianyuanapi, err := tianyuanapi.NewClient(tianyuanapi.Config{
|
||||
AccessID: c.Tianyuanapi.AccessID,
|
||||
@@ -173,7 +187,9 @@ func NewServiceContext(c config.Config) *ServiceContext {
|
||||
alipayService := service.NewAliPayService(c)
|
||||
wechatPayService := service.NewWechatPayService(c, userAuthModel, service.InitTypeWxPayPubKeyPure)
|
||||
applePayService := service.NewApplePayService(c)
|
||||
apiRequestService := service.NewApiRequestService(c, featureModel, productFeatureModel, tianyuanapi)
|
||||
tianyuanapiCallLogService := service.NewTianyuanapiCallLogService(tianyuanapiCallLogModel, featureModel)
|
||||
whitelistService := service.NewWhitelistService(c, userFeatureWhitelistModel, whitelistOrderModel, whitelistOrderItemModel, queryModel, featureModel)
|
||||
apiRequestService := service.NewApiRequestService(c, featureModel, productFeatureModel, userFeatureWhitelistModel, tianyuanapi, tianyuanapiCallLogService, whitelistService)
|
||||
verificationService := service.NewVerificationService(c, tianyuanapi, apiRequestService)
|
||||
asynqService := service.NewAsynqService(c)
|
||||
agentService := service.NewAgentService(c, orderModel, agentModel, agentWalletModel,
|
||||
@@ -215,6 +231,11 @@ func NewServiceContext(c config.Config) *ServiceContext {
|
||||
FeatureModel: featureModel,
|
||||
ProductFeatureModel: productFeatureModel,
|
||||
|
||||
// 白名单相关模型
|
||||
UserFeatureWhitelistModel: userFeatureWhitelistModel,
|
||||
WhitelistOrderModel: whitelistOrderModel,
|
||||
WhitelistOrderItemModel: whitelistOrderItemModel,
|
||||
|
||||
// 订单相关模型
|
||||
OrderModel: orderModel,
|
||||
QueryModel: queryModel,
|
||||
@@ -258,11 +279,15 @@ func NewServiceContext(c config.Config) *ServiceContext {
|
||||
GlobalNotificationsModel: globalNotificationsModel,
|
||||
AuthorizationDocumentModel: authorizationDocumentModel,
|
||||
|
||||
// 第三方服务
|
||||
TianyuanapiCallLogService: tianyuanapiCallLogService,
|
||||
|
||||
// 服务
|
||||
AlipayService: alipayService,
|
||||
WechatPayService: wechatPayService,
|
||||
ApplePayService: applePayService,
|
||||
ApiRequestService: apiRequestService,
|
||||
WhitelistService: whitelistService,
|
||||
AsynqServer: asynqServer,
|
||||
AsynqService: asynqService,
|
||||
VerificationService: verificationService,
|
||||
|
||||
@@ -1,204 +0,0 @@
|
||||
// Code generated by goctl. DO NOT EDIT.
|
||||
package types
|
||||
|
||||
type AdminAuditAgentReq struct {
|
||||
AuditId int64 `json:"audit_id"` // 审核记录ID
|
||||
Status int64 `json:"status"` // 审核状态:1=通过,2=拒绝
|
||||
AuditReason string `json:"audit_reason"` // 审核原因(拒绝时必填)
|
||||
}
|
||||
|
||||
type AdminAuditAgentResp struct {
|
||||
Success bool `json:"success"`
|
||||
}
|
||||
|
||||
type AdminAuditWithdrawalReq struct {
|
||||
WithdrawalId string `json:"withdrawal_id"` // 提现记录ID
|
||||
Status int64 `json:"status"` // 审核状态:2=通过,3=拒绝
|
||||
Remark string `json:"remark"` // 备注
|
||||
}
|
||||
|
||||
type AdminAuditWithdrawalResp struct {
|
||||
Success bool `json:"success"`
|
||||
}
|
||||
|
||||
type AdminGenerateDiamondInviteCodeReq struct {
|
||||
Count int64 `json:"count"` // 生成数量
|
||||
ExpireDays int64 `json:"expire_days,optional"` // 过期天数(可选,0表示不过期)
|
||||
Remark string `json:"remark,optional"` // 备注(可选)
|
||||
}
|
||||
|
||||
type AdminGenerateDiamondInviteCodeResp struct {
|
||||
Codes []string `json:"codes"` // 生成的邀请码列表
|
||||
}
|
||||
|
||||
type AdminGetAgentCommissionListReq struct {
|
||||
Page int64 `form:"page"` // 页码
|
||||
PageSize int64 `form:"pageSize"` // 每页数量
|
||||
AgentId *string `form:"agent_id,optional"` // 代理ID(可选)
|
||||
OrderId *string `form:"order_id,optional"` // 订单ID(可选)
|
||||
Status *int64 `form:"status,optional"` // 状态(可选)
|
||||
}
|
||||
|
||||
type AdminGetAgentCommissionListResp struct {
|
||||
Total int64 `json:"total"` // 总数
|
||||
Items []AgentCommissionListItem `json:"items"` // 列表数据
|
||||
}
|
||||
|
||||
type AdminGetAgentConfigResp struct {
|
||||
LevelBonus LevelBonusConfig `json:"level_bonus"` // 等级加成配置
|
||||
UpgradeFee UpgradeFeeConfig `json:"upgrade_fee"` // 升级费用配置
|
||||
UpgradeRebate UpgradeRebateConfig `json:"upgrade_rebate"` // 升级返佣配置
|
||||
DirectParentRebate DirectParentRebateConfig `json:"direct_parent_rebate"` // 直接上级返佣配置
|
||||
MaxGoldRebateAmount float64 `json:"max_gold_rebate_amount"` // 黄金代理最大返佣金额
|
||||
CommissionFreeze CommissionFreezeConfig `json:"commission_freeze"` // 佣金冻结配置
|
||||
TaxRate float64 `json:"tax_rate"` // 税率
|
||||
TaxExemptionAmount float64 `json:"tax_exemption_amount"` // 免税额度
|
||||
GoldMaxUpliftAmount float64 `json:"gold_max_uplift_amount"`
|
||||
DiamondMaxUpliftAmount float64 `json:"diamond_max_uplift_amount"`
|
||||
}
|
||||
|
||||
type AdminGetAgentLinkListReq struct {
|
||||
Page int64 `form:"page"` // 页码
|
||||
PageSize int64 `form:"pageSize"` // 每页数量
|
||||
AgentId *string `form:"agent_id,optional"` // 代理ID(可选)
|
||||
ProductId *string `form:"product_id,optional"` // 产品ID(可选)
|
||||
LinkIdentifier *string `form:"link_identifier,optional"` // 推广码(可选)
|
||||
}
|
||||
|
||||
type AdminGetAgentLinkListResp struct {
|
||||
Total int64 `json:"total"` // 总数
|
||||
Items []AgentLinkListItem `json:"items"` // 列表数据
|
||||
}
|
||||
|
||||
type AdminGetAgentListReq struct {
|
||||
Page int64 `form:"page"` // 页码
|
||||
PageSize int64 `form:"pageSize"` // 每页数量
|
||||
Mobile *string `form:"mobile,optional"` // 手机号(可选)
|
||||
Region *string `form:"region,optional"` // 区域(可选)
|
||||
Level *int64 `form:"level,optional"` // 等级(可选)
|
||||
TeamLeaderId *string `form:"team_leader_id,optional"` // 团队首领ID(可选)
|
||||
}
|
||||
|
||||
type AdminGetAgentListResp struct {
|
||||
Total int64 `json:"total"` // 总数
|
||||
Items []AgentListItem `json:"items"` // 列表数据
|
||||
}
|
||||
|
||||
type AdminGetAgentOrderListReq struct {
|
||||
Page int64 `form:"page"` // 页码
|
||||
PageSize int64 `form:"pageSize"` // 每页数量
|
||||
AgentId *string `form:"agent_id,optional"` // 代理ID(可选)
|
||||
OrderId *string `form:"order_id,optional"` // 订单ID(可选)
|
||||
ProcessStatus *int64 `form:"process_status,optional"` // 处理状态(可选)
|
||||
}
|
||||
|
||||
type AdminGetAgentOrderListResp struct {
|
||||
Total int64 `json:"total"` // 总数
|
||||
Items []AgentOrderListItem `json:"items"` // 列表数据
|
||||
}
|
||||
|
||||
type AdminGetAgentProductConfigListReq struct {
|
||||
Page int64 `form:"page"` // 页码
|
||||
PageSize int64 `form:"pageSize"` // 每页数量
|
||||
ProductId *string `form:"product_id,optional"` // 产品ID(可选)
|
||||
ProductName *string `form:"product_name,optional"` // 产品名称(可选,用于搜索)
|
||||
}
|
||||
|
||||
type AdminGetAgentProductConfigListResp struct {
|
||||
Total int64 `json:"total"` // 总数
|
||||
Items []AgentProductConfigItem `json:"items"` // 列表数据
|
||||
}
|
||||
|
||||
type AdminGetAgentRealNameListReq struct {
|
||||
Page int64 `form:"page"` // 页码
|
||||
PageSize int64 `form:"pageSize"` // 每页数量
|
||||
AgentId *string `form:"agent_id,optional"` // 代理ID(可选)
|
||||
Status *int64 `form:"status,optional"` // 状态(可选):1=未验证,2=已通过
|
||||
}
|
||||
|
||||
type AdminGetAgentRealNameListResp struct {
|
||||
Total int64 `json:"total"` // 总数
|
||||
Items []AgentRealNameListItem `json:"items"` // 列表数据
|
||||
}
|
||||
|
||||
type AdminGetAgentRebateListReq struct {
|
||||
Page int64 `form:"page"` // 页码
|
||||
PageSize int64 `form:"pageSize"` // 每页数量
|
||||
AgentId *string `form:"agent_id,optional"` // 代理ID(可选)
|
||||
SourceAgentId *string `form:"source_agent_id,optional"` // 来源代理ID(可选)
|
||||
RebateType *int64 `form:"rebate_type,optional"` // 返佣类型(可选)
|
||||
}
|
||||
|
||||
type AdminGetAgentRebateListResp struct {
|
||||
Total int64 `json:"total"` // 总数
|
||||
Items []AgentRebateListItem `json:"items"` // 列表数据
|
||||
}
|
||||
|
||||
type AdminGetAgentUpgradeListReq struct {
|
||||
Page int64 `form:"page"` // 页码
|
||||
PageSize int64 `form:"pageSize"` // 每页数量
|
||||
AgentId *string `form:"agent_id,optional"` // 代理ID(可选)
|
||||
UpgradeType *int64 `form:"upgrade_type,optional"` // 升级类型(可选)
|
||||
Status *int64 `form:"status,optional"` // 状态(可选)
|
||||
}
|
||||
|
||||
type AdminGetAgentUpgradeListResp struct {
|
||||
Total int64 `json:"total"` // 总数
|
||||
Items []AgentUpgradeListItem `json:"items"` // 列表数据
|
||||
}
|
||||
|
||||
type AdminGetAgentWithdrawalListReq struct {
|
||||
Page int64 `form:"page"` // 页码
|
||||
PageSize int64 `form:"pageSize"` // 每页数量
|
||||
AgentId *string `form:"agent_id,optional"` // 代理ID(可选)
|
||||
Status *int64 `form:"status,optional"` // 状态(可选)
|
||||
WithdrawNo *string `form:"withdraw_no,optional"` // 提现单号(可选)
|
||||
}
|
||||
|
||||
type AdminGetAgentWithdrawalListResp struct {
|
||||
Total int64 `json:"total"` // 总数
|
||||
Items []AgentWithdrawalListItem `json:"items"` // 列表数据
|
||||
}
|
||||
|
||||
type AdminGetInviteCodeListReq struct {
|
||||
Page int64 `form:"page"` // 页码
|
||||
PageSize int64 `form:"pageSize"` // 每页数量
|
||||
Code *string `form:"code,optional"` // 邀请码(可选)
|
||||
AgentId *string `form:"agent_id,optional"` // 发放代理ID(可选,NULL表示平台发放)
|
||||
TargetLevel *int64 `form:"target_level,optional"` // 目标等级(可选)
|
||||
Status *int64 `form:"status,optional"` // 状态(可选)
|
||||
}
|
||||
|
||||
type AdminGetInviteCodeListResp struct {
|
||||
Total int64 `json:"total"` // 总数
|
||||
Items []InviteCodeListItem `json:"items"` // 列表数据
|
||||
}
|
||||
|
||||
type AdminUpdateAgentConfigReq struct {
|
||||
LevelBonus *LevelBonusConfig `json:"level_bonus,optional"` // 等级加成配置
|
||||
UpgradeFee *UpgradeFeeConfig `json:"upgrade_fee,optional"` // 升级费用配置
|
||||
UpgradeRebate *UpgradeRebateConfig `json:"upgrade_rebate,optional"` // 升级返佣配置
|
||||
DirectParentRebate *DirectParentRebateConfig `json:"direct_parent_rebate,optional"` // 直接上级返佣配置
|
||||
MaxGoldRebateAmount *float64 `json:"max_gold_rebate_amount,optional"` // 黄金代理最大返佣金额
|
||||
CommissionFreeze *CommissionFreezeConfig `json:"commission_freeze,optional"` // 佣金冻结配置
|
||||
TaxRate *float64 `json:"tax_rate,optional"` // 税率
|
||||
TaxExemptionAmount *float64 `json:"tax_exemption_amount,optional"` // 免税额度
|
||||
GoldMaxUpliftAmount *float64 `json:"gold_max_uplift_amount,optional"`
|
||||
DiamondMaxUpliftAmount *float64 `json:"diamond_max_uplift_amount,optional"`
|
||||
}
|
||||
|
||||
type AdminUpdateAgentConfigResp struct {
|
||||
Success bool `json:"success"`
|
||||
}
|
||||
|
||||
type AdminUpdateAgentProductConfigReq struct {
|
||||
Id string `json:"id"` // 主键
|
||||
BasePrice float64 `json:"base_price"` // 基础底价
|
||||
PriceRangeMax float64 `json:"price_range_max"` // 最高定价(对应数据库 system_max_price)
|
||||
PriceThreshold *float64 `json:"price_threshold,optional"` // 提价标准阈值(可选)
|
||||
PriceFeeRate *float64 `json:"price_fee_rate,optional"` // 提价手续费比例(可选)
|
||||
}
|
||||
|
||||
type AdminUpdateAgentProductConfigResp struct {
|
||||
Success bool `json:"success"`
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
// Code generated by goctl. DO NOT EDIT.
|
||||
package types
|
||||
|
||||
type AdminBatchUpdateApiStatusReq struct {
|
||||
Ids []string `json:"ids"`
|
||||
Status int64 `json:"status"`
|
||||
}
|
||||
|
||||
type AdminBatchUpdateApiStatusResp struct {
|
||||
Success bool `json:"success"`
|
||||
}
|
||||
|
||||
type AdminCreateApiReq struct {
|
||||
ApiName string `json:"api_name"`
|
||||
ApiCode string `json:"api_code"`
|
||||
Method string `json:"method"`
|
||||
Url string `json:"url"`
|
||||
Status int64 `json:"status,default=1"`
|
||||
Description string `json:"description,optional"`
|
||||
}
|
||||
|
||||
type AdminCreateApiResp struct {
|
||||
Id string `json:"id"`
|
||||
}
|
||||
|
||||
type AdminDeleteApiReq struct {
|
||||
Id string `path:"id"`
|
||||
}
|
||||
|
||||
type AdminDeleteApiResp struct {
|
||||
Success bool `json:"success"`
|
||||
}
|
||||
|
||||
type AdminGetApiDetailReq struct {
|
||||
Id string `path:"id"`
|
||||
}
|
||||
|
||||
type AdminGetApiDetailResp struct {
|
||||
AdminApiInfo
|
||||
}
|
||||
|
||||
type AdminGetApiListReq struct {
|
||||
Page int64 `form:"page,default=1"`
|
||||
PageSize int64 `form:"page_size,default=20"`
|
||||
ApiName string `form:"api_name,optional"`
|
||||
Method string `form:"method,optional"`
|
||||
Status int64 `form:"status,optional"`
|
||||
}
|
||||
|
||||
type AdminGetApiListResp struct {
|
||||
Items []AdminApiInfo `json:"items"`
|
||||
Total int64 `json:"total"`
|
||||
}
|
||||
|
||||
type AdminUpdateApiReq struct {
|
||||
Id string `path:"id"`
|
||||
ApiName string `json:"api_name"`
|
||||
ApiCode string `json:"api_code"`
|
||||
Method string `json:"method"`
|
||||
Url string `json:"url"`
|
||||
Status int64 `json:"status"`
|
||||
Description string `json:"description,optional"`
|
||||
}
|
||||
|
||||
type AdminUpdateApiResp struct {
|
||||
Success bool `json:"success"`
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
// Code generated by goctl. DO NOT EDIT.
|
||||
package types
|
||||
|
||||
type AdminLoginReq struct {
|
||||
Username string `json:"username" validate:"required"`
|
||||
Password string `json:"password" validate:"required"`
|
||||
Captcha bool `json:"captcha" validate:"required"`
|
||||
}
|
||||
|
||||
type AdminLoginResp struct {
|
||||
AccessToken string `json:"access_token"`
|
||||
AccessExpire int64 `json:"access_expire"`
|
||||
RefreshAfter int64 `json:"refresh_after"`
|
||||
Roles []string `json:"roles"`
|
||||
}
|
||||
@@ -1,75 +0,0 @@
|
||||
// Code generated by goctl. DO NOT EDIT.
|
||||
package types
|
||||
|
||||
type AdminConfigFeatureExampleReq struct {
|
||||
FeatureId string `json:"feature_id"` // 功能ID
|
||||
Data string `json:"data"` // 示例数据JSON
|
||||
}
|
||||
|
||||
type AdminConfigFeatureExampleResp struct {
|
||||
Success bool `json:"success"` // 是否成功
|
||||
}
|
||||
|
||||
type AdminCreateFeatureReq struct {
|
||||
ApiId string `json:"api_id"` // API标识
|
||||
Name string `json:"name"` // 描述
|
||||
}
|
||||
|
||||
type AdminCreateFeatureResp struct {
|
||||
Id string `json:"id"` // 功能ID
|
||||
}
|
||||
|
||||
type AdminDeleteFeatureReq struct {
|
||||
Id string `path:"id"` // 功能ID
|
||||
}
|
||||
|
||||
type AdminDeleteFeatureResp struct {
|
||||
Success bool `json:"success"` // 是否成功
|
||||
}
|
||||
|
||||
type AdminGetFeatureDetailReq struct {
|
||||
Id string `path:"id"` // 功能ID
|
||||
}
|
||||
|
||||
type AdminGetFeatureDetailResp struct {
|
||||
Id string `json:"id"` // 功能ID
|
||||
ApiId string `json:"api_id"` // API标识
|
||||
Name string `json:"name"` // 描述
|
||||
CreateTime string `json:"create_time"` // 创建时间
|
||||
UpdateTime string `json:"update_time"` // 更新时间
|
||||
}
|
||||
|
||||
type AdminGetFeatureExampleReq struct {
|
||||
FeatureId string `path:"feature_id"` // 功能ID
|
||||
}
|
||||
|
||||
type AdminGetFeatureExampleResp struct {
|
||||
Id string `json:"id"` // 示例数据ID
|
||||
FeatureId string `json:"feature_id"` // 功能ID
|
||||
ApiId string `json:"api_id"` // API标识
|
||||
Data string `json:"data"` // 示例数据JSON
|
||||
CreateTime string `json:"create_time"` // 创建时间
|
||||
UpdateTime string `json:"update_time"` // 更新时间
|
||||
}
|
||||
|
||||
type AdminGetFeatureListReq struct {
|
||||
Page int64 `form:"page"` // 页码
|
||||
PageSize int64 `form:"pageSize"` // 每页数量
|
||||
ApiId *string `form:"api_id,optional"` // API标识
|
||||
Name *string `form:"name,optional"` // 描述
|
||||
}
|
||||
|
||||
type AdminGetFeatureListResp struct {
|
||||
Total int64 `json:"total"` // 总数
|
||||
Items []FeatureListItem `json:"items"` // 列表数据
|
||||
}
|
||||
|
||||
type AdminUpdateFeatureReq struct {
|
||||
Id string `path:"id"` // 功能ID
|
||||
ApiId *string `json:"api_id,optional"` // API标识
|
||||
Name *string `json:"name,optional"` // 描述
|
||||
}
|
||||
|
||||
type AdminUpdateFeatureResp struct {
|
||||
Success bool `json:"success"` // 是否成功
|
||||
}
|
||||
@@ -1,97 +0,0 @@
|
||||
// Code generated by goctl. DO NOT EDIT.
|
||||
package types
|
||||
|
||||
type CreateMenuReq struct {
|
||||
Pid string `json:"pid,optional"` // 父菜单ID
|
||||
Name string `json:"name"` // 路由名称
|
||||
Path string `json:"path,optional"` // 路由路径
|
||||
Component string `json:"component,optional"` // 组件路径
|
||||
Redirect string `json:"redirect,optional"` // 重定向路径
|
||||
Meta map[string]interface{} `json:"meta"` // 路由元数据
|
||||
Status int64 `json:"status,optional,default=1"` // 状态:0-禁用,1-启用
|
||||
Type string `json:"type"` // 类型
|
||||
Sort int64 `json:"sort,optional"` // 排序
|
||||
}
|
||||
|
||||
type CreateMenuResp struct {
|
||||
Id string `json:"id"` // 菜单ID
|
||||
}
|
||||
|
||||
type DeleteMenuReq struct {
|
||||
Id string `path:"id"` // 菜单ID
|
||||
}
|
||||
|
||||
type DeleteMenuResp struct {
|
||||
Success bool `json:"success"` // 是否成功
|
||||
}
|
||||
|
||||
type GetMenuAllReq struct {
|
||||
}
|
||||
|
||||
type GetMenuAllResp struct {
|
||||
Name string `json:"name"`
|
||||
Path string `json:"path"`
|
||||
Redirect string `json:"redirect,omitempty"`
|
||||
Component string `json:"component,omitempty"`
|
||||
Sort int64 `json:"sort"`
|
||||
Meta map[string]interface{} `json:"meta"`
|
||||
Children []GetMenuAllResp `json:"children"`
|
||||
}
|
||||
|
||||
type GetMenuDetailReq struct {
|
||||
Id string `path:"id"` // 菜单ID
|
||||
}
|
||||
|
||||
type GetMenuDetailResp struct {
|
||||
Id string `json:"id"` // 菜单ID
|
||||
Pid string `json:"pid"` // 父菜单ID
|
||||
Name string `json:"name"` // 路由名称
|
||||
Path string `json:"path"` // 路由路径
|
||||
Component string `json:"component"` // 组件路径
|
||||
Redirect string `json:"redirect"` // 重定向路径
|
||||
Meta map[string]interface{} `json:"meta"` // 路由元数据
|
||||
Status int64 `json:"status"` // 状态:0-禁用,1-启用
|
||||
Type string `json:"type"` // 类型
|
||||
Sort int64 `json:"sort"` // 排序
|
||||
CreateTime string `json:"createTime"` // 创建时间
|
||||
UpdateTime string `json:"updateTime"` // 更新时间
|
||||
}
|
||||
|
||||
type GetMenuListReq struct {
|
||||
Name string `form:"name,optional"` // 菜单名称
|
||||
Path string `form:"path,optional"` // 路由路径
|
||||
Status int64 `form:"status,optional,default=-1"` // 状态:0-禁用,1-启用
|
||||
Type string `form:"type,optional"` // 类型
|
||||
}
|
||||
|
||||
type MenuListItem struct {
|
||||
Id string `json:"id"` // 菜单ID
|
||||
Pid string `json:"pid"` // 父菜单ID
|
||||
Name string `json:"name"` // 路由名称
|
||||
Path string `json:"path"` // 路由路径
|
||||
Component string `json:"component"` // 组件路径
|
||||
Redirect string `json:"redirect"` // 重定向路径
|
||||
Meta map[string]interface{} `json:"meta"` // 路由元数据
|
||||
Status int64 `json:"status"` // 状态:0-禁用,1-启用
|
||||
Type string `json:"type"` // 类型
|
||||
Sort int64 `json:"sort"` // 排序
|
||||
CreateTime string `json:"createTime"` // 创建时间
|
||||
Children []MenuListItem `json:"children"` // 子菜单
|
||||
}
|
||||
|
||||
type UpdateMenuReq struct {
|
||||
Id string `path:"id"` // 菜单ID
|
||||
Pid *string `json:"pid,optional"` // 父菜单ID
|
||||
Name string `json:"name"` // 路由名称
|
||||
Path string `json:"path,optional"` // 路由路径
|
||||
Component string `json:"component,optional"` // 组件路径
|
||||
Redirect string `json:"redirect,optional"` // 重定向路径
|
||||
Meta map[string]interface{} `json:"meta"` // 路由元数据
|
||||
Status int64 `json:"status,optional"` // 状态:0-禁用,1-启用
|
||||
Type string `json:"type"` // 类型
|
||||
Sort int64 `json:"sort,optional"` // 排序
|
||||
}
|
||||
|
||||
type UpdateMenuResp struct {
|
||||
Success bool `json:"success"` // 是否成功
|
||||
}
|
||||
@@ -1,74 +0,0 @@
|
||||
// Code generated by goctl. DO NOT EDIT.
|
||||
package types
|
||||
|
||||
type AdminCreateNotificationReq struct {
|
||||
Title string `json:"title"` // 通知标题
|
||||
NotificationPage string `json:"notification_page"` // 通知页面
|
||||
Content string `json:"content"` // 通知内容
|
||||
StartDate string `json:"start_date"` // 生效开始日期(yyyy-MM-dd)
|
||||
StartTime string `json:"start_time"` // 生效开始时间(HH:mm:ss)
|
||||
EndDate string `json:"end_date"` // 生效结束日期(yyyy-MM-dd)
|
||||
EndTime string `json:"end_time"` // 生效结束时间(HH:mm:ss)
|
||||
Status int64 `json:"status"` // 状态:1-启用,0-禁用
|
||||
}
|
||||
|
||||
type AdminCreateNotificationResp struct {
|
||||
Id string `json:"id"` // 通知ID
|
||||
}
|
||||
|
||||
type AdminDeleteNotificationReq struct {
|
||||
Id string `path:"id"` // 通知ID
|
||||
}
|
||||
|
||||
type AdminDeleteNotificationResp struct {
|
||||
Success bool `json:"success"` // 是否成功
|
||||
}
|
||||
|
||||
type AdminGetNotificationDetailReq struct {
|
||||
Id string `path:"id"` // 通知ID
|
||||
}
|
||||
|
||||
type AdminGetNotificationDetailResp struct {
|
||||
Id string `json:"id"` // 通知ID
|
||||
Title string `json:"title"` // 通知标题
|
||||
Content string `json:"content"` // 通知内容
|
||||
NotificationPage string `json:"notification_page"` // 通知页面
|
||||
StartDate string `json:"start_date"` // 生效开始日期
|
||||
StartTime string `json:"start_time"` // 生效开始时间
|
||||
EndDate string `json:"end_date"` // 生效结束日期
|
||||
EndTime string `json:"end_time"` // 生效结束时间
|
||||
Status int64 `json:"status"` // 状态
|
||||
CreateTime string `json:"create_time"` // 创建时间
|
||||
UpdateTime string `json:"update_time"` // 更新时间
|
||||
}
|
||||
|
||||
type AdminGetNotificationListReq struct {
|
||||
Page int64 `form:"page"` // 页码
|
||||
PageSize int64 `form:"pageSize"` // 每页数量
|
||||
Title *string `form:"title,optional"` // 通知标题(可选)
|
||||
NotificationPage *string `form:"notification_page,optional"` // 通知页面(可选)
|
||||
Status *int64 `form:"status,optional"` // 状态(可选)
|
||||
StartDate *string `form:"start_date,optional"` // 开始日期范围(可选)
|
||||
EndDate *string `form:"end_date,optional"` // 结束日期范围(可选)
|
||||
}
|
||||
|
||||
type AdminGetNotificationListResp struct {
|
||||
Total int64 `json:"total"` // 总数
|
||||
Items []NotificationListItem `json:"items"` // 列表数据
|
||||
}
|
||||
|
||||
type AdminUpdateNotificationReq struct {
|
||||
Id string `path:"id"` // 通知ID
|
||||
Title *string `json:"title,optional"` // 通知标题
|
||||
Content *string `json:"content,optional"` // 通知内容
|
||||
NotificationPage *string `json:"notification_page,optional"` // 通知页面
|
||||
StartDate *string `json:"start_date,optional"` // 生效开始日期
|
||||
StartTime *string `json:"start_time,optional"` // 生效开始时间
|
||||
EndDate *string `json:"end_date,optional"` // 生效结束日期
|
||||
EndTime *string `json:"end_time,optional"` // 生效结束时间
|
||||
Status *int64 `json:"status,optional"` // 状态
|
||||
}
|
||||
|
||||
type AdminUpdateNotificationResp struct {
|
||||
Success bool `json:"success"` // 是否成功
|
||||
}
|
||||
@@ -1,108 +0,0 @@
|
||||
// Code generated by goctl. DO NOT EDIT.
|
||||
package types
|
||||
|
||||
type AdminCreateOrderReq struct {
|
||||
OrderNo string `json:"order_no"` // 商户订单号
|
||||
PlatformOrderId string `json:"platform_order_id"` // 支付订单号
|
||||
ProductName string `json:"product_name"` // 产品名称
|
||||
PaymentPlatform string `json:"payment_platform"` // 支付方式
|
||||
PaymentScene string `json:"payment_scene"` // 支付平台
|
||||
Amount float64 `json:"amount"` // 金额
|
||||
Status string `json:"status,default=pending"` // 支付状态:pending-待支付,paid-已支付,refunded-已退款,closed-已关闭,failed-支付失败
|
||||
}
|
||||
|
||||
type AdminCreateOrderResp struct {
|
||||
Id string `json:"id"` // 订单ID
|
||||
}
|
||||
|
||||
type AdminDeleteOrderReq struct {
|
||||
Id string `path:"id"` // 订单ID
|
||||
}
|
||||
|
||||
type AdminDeleteOrderResp struct {
|
||||
Success bool `json:"success"` // 是否成功
|
||||
}
|
||||
|
||||
type AdminGetOrderDetailReq struct {
|
||||
Id string `path:"id"` // 订单ID
|
||||
}
|
||||
|
||||
type AdminGetOrderDetailResp struct {
|
||||
Id string `json:"id"` // 订单ID
|
||||
OrderNo string `json:"order_no"` // 商户订单号
|
||||
PlatformOrderId string `json:"platform_order_id"` // 支付订单号
|
||||
ProductName string `json:"product_name"` // 产品名称
|
||||
PaymentPlatform string `json:"payment_platform"` // 支付方式
|
||||
PaymentScene string `json:"payment_scene"` // 支付平台
|
||||
Amount float64 `json:"amount"` // 金额
|
||||
Status string `json:"status"` // 支付状态:pending-待支付,paid-已支付,refunded-已退款,closed-已关闭,failed-支付失败
|
||||
QueryState string `json:"query_state"` // 查询状态:pending-待查询,success-查询成功,failed-查询失败 processing-查询中
|
||||
CreateTime string `json:"create_time"` // 创建时间
|
||||
PayTime string `json:"pay_time"` // 支付时间
|
||||
RefundTime string `json:"refund_time"` // 退款时间
|
||||
UpdateTime string `json:"update_time"` // 更新时间
|
||||
IsAgentOrder bool `json:"is_agent_order"` // 是否是代理订单
|
||||
AgentProcessStatus string `json:"agent_process_status"` // 代理事务处理状态:not_agent-非代理订单,success-处理成功,failed-处理失败,pending-待处理
|
||||
}
|
||||
|
||||
type AdminGetOrderListReq struct {
|
||||
Page int64 `form:"page,default=1"` // 页码
|
||||
PageSize int64 `form:"pageSize,default=20"` // 每页数量
|
||||
OrderNo string `form:"order_no,optional"` // 商户订单号
|
||||
PlatformOrderId string `form:"platform_order_id,optional"` // 支付订单号
|
||||
ProductName string `form:"product_name,optional"` // 产品名称
|
||||
PaymentPlatform string `form:"payment_platform,optional"` // 支付方式
|
||||
PaymentScene string `form:"payment_scene,optional"` // 支付平台
|
||||
Amount float64 `form:"amount,optional"` // 金额
|
||||
Status string `form:"status,optional"` // 支付状态:pending-待支付,paid-已支付,refunded-已退款,closed-已关闭,failed-支付失败
|
||||
CreateTimeStart string `form:"create_time_start,optional"` // 创建时间开始
|
||||
CreateTimeEnd string `form:"create_time_end,optional"` // 创建时间结束
|
||||
PayTimeStart string `form:"pay_time_start,optional"` // 支付时间开始
|
||||
PayTimeEnd string `form:"pay_time_end,optional"` // 支付时间结束
|
||||
RefundTimeStart string `form:"refund_time_start,optional"` // 退款时间开始
|
||||
RefundTimeEnd string `form:"refund_time_end,optional"` // 退款时间结束
|
||||
}
|
||||
|
||||
type AdminGetOrderListResp struct {
|
||||
Total int64 `json:"total"` // 总数
|
||||
Items []OrderListItem `json:"items"` // 列表
|
||||
}
|
||||
|
||||
type AdminRefundOrderReq struct {
|
||||
Id string `path:"id"` // 订单ID
|
||||
RefundAmount float64 `json:"refund_amount"` // 退款金额
|
||||
RefundReason string `json:"refund_reason"` // 退款原因
|
||||
}
|
||||
|
||||
type AdminRefundOrderResp struct {
|
||||
Status string `json:"status"` // 退款状态
|
||||
RefundNo string `json:"refund_no"` // 退款单号
|
||||
Amount float64 `json:"amount"` // 退款金额
|
||||
}
|
||||
|
||||
type AdminRetryAgentProcessReq struct {
|
||||
Id string `path:"id"` // 订单ID
|
||||
}
|
||||
|
||||
type AdminRetryAgentProcessResp struct {
|
||||
Status string `json:"status"` // 执行状态:success-成功,already_processed-已处理,failed-失败
|
||||
Message string `json:"message"` // 执行结果消息
|
||||
ProcessedAt string `json:"processed_at"` // 处理时间
|
||||
}
|
||||
|
||||
type AdminUpdateOrderReq struct {
|
||||
Id string `path:"id"` // 订单ID
|
||||
OrderNo *string `json:"order_no,optional"` // 商户订单号
|
||||
PlatformOrderId *string `json:"platform_order_id,optional"` // 支付订单号
|
||||
ProductName *string `json:"product_name,optional"` // 产品名称
|
||||
PaymentPlatform *string `json:"payment_platform,optional"` // 支付方式
|
||||
PaymentScene *string `json:"payment_scene,optional"` // 支付平台
|
||||
Amount *float64 `json:"amount,optional"` // 金额
|
||||
Status *string `json:"status,optional"` // 支付状态:pending-待支付,paid-已支付,refunded-已退款,closed-已关闭,failed-支付失败
|
||||
PayTime *string `json:"pay_time,optional"` // 支付时间
|
||||
RefundTime *string `json:"refund_time,optional"` // 退款时间
|
||||
}
|
||||
|
||||
type AdminUpdateOrderResp struct {
|
||||
Success bool `json:"success"` // 是否成功
|
||||
}
|
||||
@@ -1,66 +0,0 @@
|
||||
// Code generated by goctl. DO NOT EDIT.
|
||||
package types
|
||||
|
||||
type AdminCreatePlatformUserReq struct {
|
||||
Mobile string `json:"mobile"` // 手机号
|
||||
Password string `json:"password"` // 密码
|
||||
Nickname string `json:"nickname"` // 昵称
|
||||
Info string `json:"info"` // 备注信息
|
||||
Inside int64 `json:"inside"` // 是否内部用户 1-是 0-否
|
||||
}
|
||||
|
||||
type AdminCreatePlatformUserResp struct {
|
||||
Id string `json:"id"` // 用户ID
|
||||
}
|
||||
|
||||
type AdminDeletePlatformUserReq struct {
|
||||
Id string `path:"id"` // 用户ID
|
||||
}
|
||||
|
||||
type AdminDeletePlatformUserResp struct {
|
||||
Success bool `json:"success"` // 是否成功
|
||||
}
|
||||
|
||||
type AdminGetPlatformUserDetailReq struct {
|
||||
Id string `path:"id"` // 用户ID
|
||||
}
|
||||
|
||||
type AdminGetPlatformUserDetailResp struct {
|
||||
Id string `json:"id"` // 用户ID
|
||||
Mobile string `json:"mobile"` // 手机号
|
||||
Nickname string `json:"nickname"` // 昵称
|
||||
Info string `json:"info"` // 备注信息
|
||||
Inside int64 `json:"inside"` // 是否内部用户 1-是 0-否
|
||||
CreateTime string `json:"create_time"` // 创建时间
|
||||
UpdateTime string `json:"update_time"` // 更新时间
|
||||
}
|
||||
|
||||
type AdminGetPlatformUserListReq struct {
|
||||
Page int64 `form:"page,default=1"` // 页码
|
||||
PageSize int64 `form:"pageSize,default=20"` // 每页数量
|
||||
Mobile string `form:"mobile,optional"` // 手机号
|
||||
Nickname string `form:"nickname,optional"` // 昵称
|
||||
Inside int64 `form:"inside,optional"` // 是否内部用户 1-是 0-否
|
||||
CreateTimeStart string `form:"create_time_start,optional"` // 创建时间开始
|
||||
CreateTimeEnd string `form:"create_time_end,optional"` // 创建时间结束
|
||||
OrderBy string `form:"order_by,optional"` // 排序字段
|
||||
OrderType string `form:"order_type,optional"` // 排序类型
|
||||
}
|
||||
|
||||
type AdminGetPlatformUserListResp struct {
|
||||
Total int64 `json:"total"` // 总数
|
||||
Items []PlatformUserListItem `json:"items"` // 列表
|
||||
}
|
||||
|
||||
type AdminUpdatePlatformUserReq struct {
|
||||
Id string `path:"id"` // 用户ID
|
||||
Mobile *string `json:"mobile,optional"` // 手机号
|
||||
Password *string `json:"password,optional"` // 密码
|
||||
Nickname *string `json:"nickname,optional"` // 昵称
|
||||
Info *string `json:"info,optional"` // 备注信息
|
||||
Inside *int64 `json:"inside,optional"` // 是否内部用户 1-是 0-否
|
||||
}
|
||||
|
||||
type AdminUpdatePlatformUserResp struct {
|
||||
Success bool `json:"success"` // 是否成功
|
||||
}
|
||||
@@ -1,91 +0,0 @@
|
||||
// Code generated by goctl. DO NOT EDIT.
|
||||
package types
|
||||
|
||||
type AdminCreateProductReq struct {
|
||||
ProductName string `json:"product_name"` // 服务名
|
||||
ProductEn string `json:"product_en"` // 英文名
|
||||
Description string `json:"description"` // 描述
|
||||
Notes string `json:"notes,optional"` // 备注
|
||||
CostPrice float64 `json:"cost_price"` // 成本
|
||||
SellPrice float64 `json:"sell_price"` // 售价
|
||||
}
|
||||
|
||||
type AdminCreateProductResp struct {
|
||||
Id string `json:"id"` // 产品ID
|
||||
}
|
||||
|
||||
type AdminDeleteProductReq struct {
|
||||
Id string `path:"id"` // 产品ID
|
||||
}
|
||||
|
||||
type AdminDeleteProductResp struct {
|
||||
Success bool `json:"success"` // 是否成功
|
||||
}
|
||||
|
||||
type AdminGetProductDetailReq struct {
|
||||
Id string `path:"id"` // 产品ID
|
||||
}
|
||||
|
||||
type AdminGetProductDetailResp struct {
|
||||
Id string `json:"id"` // 产品ID
|
||||
ProductName string `json:"product_name"` // 服务名
|
||||
ProductEn string `json:"product_en"` // 英文名
|
||||
Description string `json:"description"` // 描述
|
||||
Notes string `json:"notes"` // 备注
|
||||
CostPrice float64 `json:"cost_price"` // 成本
|
||||
SellPrice float64 `json:"sell_price"` // 售价
|
||||
CreateTime string `json:"create_time"` // 创建时间
|
||||
UpdateTime string `json:"update_time"` // 更新时间
|
||||
}
|
||||
|
||||
type AdminGetProductFeatureListReq struct {
|
||||
ProductId string `path:"product_id"` // 产品ID
|
||||
}
|
||||
|
||||
type AdminGetProductFeatureListResp struct {
|
||||
Id string `json:"id"` // 关联ID
|
||||
ProductId string `json:"product_id"` // 产品ID
|
||||
FeatureId string `json:"feature_id"` // 功能ID
|
||||
ApiId string `json:"api_id"` // API标识
|
||||
Name string `json:"name"` // 功能描述
|
||||
Sort int64 `json:"sort"` // 排序
|
||||
Enable int64 `json:"enable"` // 是否启用
|
||||
IsImportant int64 `json:"is_important"` // 是否重要
|
||||
CreateTime string `json:"create_time"` // 创建时间
|
||||
UpdateTime string `json:"update_time"` // 更新时间
|
||||
}
|
||||
|
||||
type AdminGetProductListReq struct {
|
||||
Page int64 `form:"page"` // 页码
|
||||
PageSize int64 `form:"pageSize"` // 每页数量
|
||||
ProductName *string `form:"product_name,optional"` // 服务名
|
||||
ProductEn *string `form:"product_en,optional"` // 英文名
|
||||
}
|
||||
|
||||
type AdminGetProductListResp struct {
|
||||
Total int64 `json:"total"` // 总数
|
||||
Items []ProductListItem `json:"items"` // 列表数据
|
||||
}
|
||||
|
||||
type AdminUpdateProductFeaturesReq struct {
|
||||
ProductId string `path:"product_id"` // 产品ID
|
||||
Features []ProductFeatureItem `json:"features"` // 功能列表
|
||||
}
|
||||
|
||||
type AdminUpdateProductFeaturesResp struct {
|
||||
Success bool `json:"success"` // 是否成功
|
||||
}
|
||||
|
||||
type AdminUpdateProductReq struct {
|
||||
Id string `path:"id"` // 产品ID
|
||||
ProductName *string `json:"product_name,optional"` // 服务名
|
||||
ProductEn *string `json:"product_en,optional"` // 英文名
|
||||
Description *string `json:"description,optional"` // 描述
|
||||
Notes *string `json:"notes,optional"` // 备注
|
||||
CostPrice *float64 `json:"cost_price,optional"` // 成本
|
||||
SellPrice *float64 `json:"sell_price,optional"` // 售价
|
||||
}
|
||||
|
||||
type AdminUpdateProductResp struct {
|
||||
Success bool `json:"success"` // 是否成功
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
// Code generated by goctl. DO NOT EDIT.
|
||||
package types
|
||||
|
||||
type AdminGetQueryCleanupConfigListReq struct {
|
||||
Status int64 `form:"status,optional"` // 状态:1-启用,0-禁用
|
||||
}
|
||||
|
||||
type AdminGetQueryCleanupConfigListResp struct {
|
||||
Items []QueryCleanupConfigItem `json:"items"` // 配置列表
|
||||
}
|
||||
|
||||
type AdminGetQueryCleanupDetailListReq struct {
|
||||
LogId string `path:"log_id"` // 清理日志ID
|
||||
Page int64 `form:"page,default=1"` // 页码
|
||||
PageSize int64 `form:"page_size,default=20"` // 每页数量
|
||||
}
|
||||
|
||||
type AdminGetQueryCleanupDetailListResp struct {
|
||||
Total int64 `json:"total"` // 总数
|
||||
Items []QueryCleanupDetailItem `json:"items"` // 列表
|
||||
}
|
||||
|
||||
type AdminGetQueryCleanupLogListReq struct {
|
||||
Page int64 `form:"page,default=1"` // 页码
|
||||
PageSize int64 `form:"page_size,default=20"` // 每页数量
|
||||
Status int64 `form:"status,optional"` // 状态:1-成功,2-失败
|
||||
StartTime string `form:"start_time,optional"` // 开始时间
|
||||
EndTime string `form:"end_time,optional"` // 结束时间
|
||||
}
|
||||
|
||||
type AdminGetQueryCleanupLogListResp struct {
|
||||
Total int64 `json:"total"` // 总数
|
||||
Items []QueryCleanupLogItem `json:"items"` // 列表
|
||||
}
|
||||
|
||||
type AdminGetQueryDetailByOrderIdReq struct {
|
||||
OrderId string `path:"order_id"`
|
||||
}
|
||||
|
||||
type AdminGetQueryDetailByOrderIdResp struct {
|
||||
Id string `json:"id"` // 主键ID
|
||||
OrderId string `json:"order_id"` // 订单ID
|
||||
UserId string `json:"user_id"` // 用户ID
|
||||
ProductName string `json:"product_name"` // 产品ID
|
||||
QueryParams map[string]interface{} `json:"query_params"`
|
||||
QueryData []AdminQueryItem `json:"query_data"`
|
||||
CreateTime string `json:"create_time"` // 创建时间
|
||||
UpdateTime string `json:"update_time"` // 更新时间
|
||||
QueryState string `json:"query_state"` // 查询状态
|
||||
}
|
||||
|
||||
type AdminUpdateQueryCleanupConfigReq struct {
|
||||
Id string `json:"id"` // 主键ID
|
||||
ConfigValue string `json:"config_value"` // 配置值
|
||||
Status int64 `json:"status"` // 状态:1-启用,0-禁用
|
||||
}
|
||||
|
||||
type AdminUpdateQueryCleanupConfigResp struct {
|
||||
Success bool `json:"success"` // 是否成功
|
||||
}
|
||||
@@ -1,66 +0,0 @@
|
||||
// Code generated by goctl. DO NOT EDIT.
|
||||
package types
|
||||
|
||||
type CreateRoleReq struct {
|
||||
RoleName string `json:"role_name"` // 角色名称
|
||||
RoleCode string `json:"role_code"` // 角色编码
|
||||
Description string `json:"description"` // 角色描述
|
||||
Status int64 `json:"status,default=1"` // 状态:0-禁用,1-启用
|
||||
Sort int64 `json:"sort,default=0"` // 排序
|
||||
MenuIds []string `json:"menu_ids"` // 关联的菜单ID列表
|
||||
}
|
||||
|
||||
type CreateRoleResp struct {
|
||||
Id string `json:"id"` // 角色ID
|
||||
}
|
||||
|
||||
type DeleteRoleReq struct {
|
||||
Id string `path:"id"` // 角色ID
|
||||
}
|
||||
|
||||
type DeleteRoleResp struct {
|
||||
Success bool `json:"success"` // 是否成功
|
||||
}
|
||||
|
||||
type GetRoleDetailReq struct {
|
||||
Id string `path:"id"` // 角色ID
|
||||
}
|
||||
|
||||
type GetRoleDetailResp struct {
|
||||
Id string `json:"id"` // 角色ID
|
||||
RoleName string `json:"role_name"` // 角色名称
|
||||
RoleCode string `json:"role_code"` // 角色编码
|
||||
Description string `json:"description"` // 角色描述
|
||||
Status int64 `json:"status"` // 状态:0-禁用,1-启用
|
||||
Sort int64 `json:"sort"` // 排序
|
||||
CreateTime string `json:"create_time"` // 创建时间
|
||||
UpdateTime string `json:"update_time"` // 更新时间
|
||||
MenuIds []string `json:"menu_ids"` // 关联的菜单ID列表
|
||||
}
|
||||
|
||||
type GetRoleListReq struct {
|
||||
Page int64 `form:"page,default=1"` // 页码
|
||||
PageSize int64 `form:"pageSize,default=20"` // 每页数量
|
||||
Name string `form:"name,optional"` // 角色名称
|
||||
Code string `form:"code,optional"` // 角色编码
|
||||
Status int64 `form:"status,optional,default=-1"` // 状态:0-禁用,1-启用
|
||||
}
|
||||
|
||||
type GetRoleListResp struct {
|
||||
Total int64 `json:"total"` // 总数
|
||||
Items []RoleListItem `json:"items"` // 列表
|
||||
}
|
||||
|
||||
type UpdateRoleReq struct {
|
||||
Id string `path:"id"` // 角色ID
|
||||
RoleName *string `json:"role_name,optional"` // 角色名称
|
||||
RoleCode *string `json:"role_code,optional"` // 角色编码
|
||||
Description *string `json:"description,optional"` // 角色描述
|
||||
Status *int64 `json:"status,optional"` // 状态:0-禁用,1-启用
|
||||
Sort *int64 `json:"sort,optional"` // 排序
|
||||
MenuIds []string `json:"menu_ids,optional"` // 关联的菜单ID列表
|
||||
}
|
||||
|
||||
type UpdateRoleResp struct {
|
||||
Success bool `json:"success"` // 是否成功
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
// Code generated by goctl. DO NOT EDIT.
|
||||
package types
|
||||
|
||||
type AdminAssignRoleApiReq struct {
|
||||
RoleId string `json:"role_id"`
|
||||
ApiIds []string `json:"api_ids"`
|
||||
}
|
||||
|
||||
type AdminAssignRoleApiResp struct {
|
||||
Success bool `json:"success"`
|
||||
}
|
||||
|
||||
type AdminGetAllApiListReq struct {
|
||||
Status int64 `form:"status,optional,default=1"`
|
||||
}
|
||||
|
||||
type AdminGetAllApiListResp struct {
|
||||
Items []AdminRoleApiInfo `json:"items"`
|
||||
}
|
||||
|
||||
type AdminGetRoleApiListReq struct {
|
||||
RoleId string `path:"role_id"`
|
||||
}
|
||||
|
||||
type AdminGetRoleApiListResp struct {
|
||||
Items []AdminRoleApiInfo `json:"items"`
|
||||
}
|
||||
|
||||
type AdminRemoveRoleApiReq struct {
|
||||
RoleId string `json:"role_id"`
|
||||
ApiIds []string `json:"api_ids"`
|
||||
}
|
||||
|
||||
type AdminRemoveRoleApiResp struct {
|
||||
Success bool `json:"success"`
|
||||
}
|
||||
|
||||
type AdminUpdateRoleApiReq struct {
|
||||
RoleId string `json:"role_id"`
|
||||
ApiIds []string `json:"api_ids"`
|
||||
}
|
||||
|
||||
type AdminUpdateRoleApiResp struct {
|
||||
Success bool `json:"success"`
|
||||
}
|
||||
@@ -1,78 +0,0 @@
|
||||
// Code generated by goctl. DO NOT EDIT.
|
||||
package types
|
||||
|
||||
type AdminCreateUserReq struct {
|
||||
Username string `json:"username"` // 用户名
|
||||
RealName string `json:"real_name"` // 真实姓名
|
||||
Status int64 `json:"status,default=1"` // 状态:0-禁用,1-启用
|
||||
RoleIds []string `json:"role_ids"` // 关联的角色ID列表
|
||||
}
|
||||
|
||||
type AdminCreateUserResp struct {
|
||||
Id string `json:"id"` // 用户ID
|
||||
}
|
||||
|
||||
type AdminDeleteUserReq struct {
|
||||
Id string `path:"id"` // 用户ID
|
||||
}
|
||||
|
||||
type AdminDeleteUserResp struct {
|
||||
Success bool `json:"success"` // 是否成功
|
||||
}
|
||||
|
||||
type AdminGetUserDetailReq struct {
|
||||
Id string `path:"id"` // 用户ID
|
||||
}
|
||||
|
||||
type AdminGetUserDetailResp struct {
|
||||
Id string `json:"id"` // 用户ID
|
||||
Username string `json:"username"` // 用户名
|
||||
RealName string `json:"real_name"` // 真实姓名
|
||||
Status int64 `json:"status"` // 状态:0-禁用,1-启用
|
||||
CreateTime string `json:"create_time"` // 创建时间
|
||||
UpdateTime string `json:"update_time"` // 更新时间
|
||||
RoleIds []string `json:"role_ids"` // 关联的角色ID列表
|
||||
}
|
||||
|
||||
type AdminGetUserListReq struct {
|
||||
Page int64 `form:"page,default=1"` // 页码
|
||||
PageSize int64 `form:"pageSize,default=20"` // 每页数量
|
||||
Username string `form:"username,optional"` // 用户名
|
||||
RealName string `form:"real_name,optional"` // 真实姓名
|
||||
Status int64 `form:"status,optional,default=-1"` // 状态:0-禁用,1-启用
|
||||
}
|
||||
|
||||
type AdminGetUserListResp struct {
|
||||
Total int64 `json:"total"` // 总数
|
||||
Items []AdminUserListItem `json:"items"` // 列表
|
||||
}
|
||||
|
||||
type AdminResetPasswordReq struct {
|
||||
Id string `path:"id"` // 用户ID
|
||||
Password string `json:"password"` // 新密码
|
||||
}
|
||||
|
||||
type AdminResetPasswordResp struct {
|
||||
Success bool `json:"success"` // 是否成功
|
||||
}
|
||||
|
||||
type AdminUpdateUserReq struct {
|
||||
Id string `path:"id"` // 用户ID
|
||||
Username *string `json:"username,optional"` // 用户名
|
||||
RealName *string `json:"real_name,optional"` // 真实姓名
|
||||
Status *int64 `json:"status,optional"` // 状态:0-禁用,1-启用
|
||||
RoleIds []string `json:"role_ids,optional"` // 关联的角色ID列表
|
||||
}
|
||||
|
||||
type AdminUpdateUserResp struct {
|
||||
Success bool `json:"success"` // 是否成功
|
||||
}
|
||||
|
||||
type AdminUserInfoReq struct {
|
||||
}
|
||||
|
||||
type AdminUserInfoResp struct {
|
||||
Username string `json:"username"` // 用户名
|
||||
RealName string `json:"real_name"` // 真实姓名
|
||||
Roles []string `json:"roles"` // 角色编码列表
|
||||
}
|
||||
@@ -1,300 +0,0 @@
|
||||
// Code generated by goctl. DO NOT EDIT.
|
||||
package types
|
||||
|
||||
type AgentApplyReq struct {
|
||||
Region string `json:"region,optional"`
|
||||
Mobile string `json:"mobile"`
|
||||
Code string `json:"code"`
|
||||
Referrer string `json:"referrer"`
|
||||
InviteCode string `json:"invite_code,optional"`
|
||||
AgentCode int64 `json:"agent_code,optional"`
|
||||
}
|
||||
|
||||
type AgentApplyResp struct {
|
||||
AccessToken string `json:"accessToken"`
|
||||
AccessExpire int64 `json:"accessExpire"`
|
||||
RefreshAfter int64 `json:"refreshAfter"`
|
||||
AgentCode int64 `json:"agent_code"`
|
||||
}
|
||||
|
||||
type AgentGeneratingLinkReq struct {
|
||||
ProductId string `json:"product_id"` // 产品ID
|
||||
SetPrice float64 `json:"set_price"` // 设定价格
|
||||
TargetPath string `json:"target_path,optional"` // 目标地址(可选,默认为推广报告页面)
|
||||
}
|
||||
|
||||
type AgentGeneratingLinkResp struct {
|
||||
LinkIdentifier string `json:"link_identifier"` // 推广链接标识
|
||||
FullLink string `json:"full_link"` // 完整短链URL
|
||||
}
|
||||
|
||||
type AgentInfoResp struct {
|
||||
AgentId string `json:"agent_id"`
|
||||
Level int64 `json:"level"`
|
||||
LevelName string `json:"level_name"`
|
||||
Region string `json:"region"`
|
||||
Mobile string `json:"mobile"`
|
||||
WechatId string `json:"wechat_id"`
|
||||
TeamLeaderId string `json:"team_leader_id"`
|
||||
IsRealName bool `json:"is_real_name"`
|
||||
AgentCode int64 `json:"agent_code"`
|
||||
}
|
||||
|
||||
type AgentProductConfigResp struct {
|
||||
List []ProductConfigItem `json:"list"`
|
||||
}
|
||||
|
||||
type ApplyUpgradeReq struct {
|
||||
ToLevel int64 `json:"to_level"` // 目标等级:2=黄金,3=钻石
|
||||
}
|
||||
|
||||
type ApplyUpgradeResp struct {
|
||||
UpgradeId string `json:"upgrade_id"` // 升级记录ID
|
||||
OrderNo string `json:"order_no"` // 支付订单号
|
||||
}
|
||||
|
||||
type ApplyWithdrawalReq struct {
|
||||
Amount float64 `json:"amount"` // 提现金额
|
||||
PayeeAccount string `json:"payee_account"` // 收款账户
|
||||
PayeeName string `json:"payee_name"` // 收款人姓名
|
||||
}
|
||||
|
||||
type ApplyWithdrawalResp struct {
|
||||
WithdrawalId string `json:"withdrawal_id"` // 提现记录ID
|
||||
WithdrawalNo string `json:"withdrawal_no"` // 提现单号
|
||||
}
|
||||
|
||||
type ConversionRateResp struct {
|
||||
MyConversionRate ConversionRateData `json:"my_conversion_rate"` // 我的转化率
|
||||
SubordinateConversionRate ConversionRateData `json:"subordinate_conversion_rate"` // 我的下级转化率
|
||||
}
|
||||
|
||||
type DeleteInviteCodeReq struct {
|
||||
Id string `json:"id"` // 邀请码ID
|
||||
}
|
||||
|
||||
type DeleteInviteCodeResp struct {
|
||||
}
|
||||
|
||||
type GenerateInviteCodeReq struct {
|
||||
Count int64 `json:"count"` // 生成数量
|
||||
ExpireDays int64 `json:"expire_days,optional"` // 过期天数(可选,0表示不过期)
|
||||
Remark string `json:"remark,optional"` // 备注(可选)
|
||||
}
|
||||
|
||||
type GenerateInviteCodeResp struct {
|
||||
Codes []string `json:"codes"` // 生成的邀请码列表
|
||||
}
|
||||
|
||||
type GetCommissionListReq struct {
|
||||
Page int64 `form:"page"` // 页码
|
||||
PageSize int64 `form:"page_size"` // 每页数量
|
||||
}
|
||||
|
||||
type GetCommissionListResp struct {
|
||||
Total int64 `json:"total"` // 总数
|
||||
List []CommissionItem `json:"list"` // 列表
|
||||
}
|
||||
|
||||
type GetInviteCodeListReq struct {
|
||||
Page int64 `form:"page"` // 页码
|
||||
PageSize int64 `form:"page_size"` // 每页数量
|
||||
Status int64 `form:"status,optional"` // 状态(可选)
|
||||
}
|
||||
|
||||
type GetInviteCodeListResp struct {
|
||||
Total int64 `json:"total"` // 总数
|
||||
List []InviteCodeItem `json:"list"` // 列表
|
||||
}
|
||||
|
||||
type GetInviteLinkReq struct {
|
||||
InviteCode string `form:"invite_code"` // 邀请码
|
||||
TargetPath string `form:"target_path,optional"` // 目标地址(可选,默认为注册页面)
|
||||
}
|
||||
|
||||
type GetInviteLinkResp struct {
|
||||
InviteLink string `json:"invite_link"` // 邀请链接
|
||||
}
|
||||
|
||||
type GetLevelPrivilegeResp struct {
|
||||
Levels []LevelPrivilegeItem `json:"levels"`
|
||||
UpgradeToGoldFee float64 `json:"upgrade_to_gold_fee"`
|
||||
UpgradeToDiamondFee float64 `json:"upgrade_to_diamond_fee"`
|
||||
UpgradeToGoldRebate float64 `json:"upgrade_to_gold_rebate"`
|
||||
UpgradeToDiamondRebate float64 `json:"upgrade_to_diamond_rebate"`
|
||||
}
|
||||
|
||||
type GetLinkDataReq struct {
|
||||
LinkIdentifier string `form:"link_identifier"` // 推广链接标识
|
||||
}
|
||||
|
||||
type GetLinkDataResp struct {
|
||||
AgentId string `json:"agent_id"` // 代理ID
|
||||
ProductId string `json:"product_id"` // 产品ID
|
||||
SetPrice float64 `json:"set_price"` // 代理设定价格
|
||||
ActualBasePrice float64 `json:"actual_base_price"` // 实际底价
|
||||
ProductName string `json:"product_name"` // 产品名称
|
||||
ProductEn string `json:"product_en"` // 产品英文标识
|
||||
SellPrice float64 `json:"sell_price"` // 销售价格(使用代理设定价格)
|
||||
Description string `json:"description"` // 产品描述
|
||||
Features []Feature `json:"features"` // 产品功能列表
|
||||
}
|
||||
|
||||
type GetPromotionQueryListReq struct {
|
||||
Page int64 `form:"page"` // 页码
|
||||
PageSize int64 `form:"page_size"` // 每页数量
|
||||
}
|
||||
|
||||
type GetPromotionQueryListResp struct {
|
||||
Total int64 `json:"total"` // 总数
|
||||
List []PromotionQueryItem `json:"list"` // 列表
|
||||
}
|
||||
|
||||
type GetRebateListReq struct {
|
||||
Page int64 `form:"page"` // 页码
|
||||
PageSize int64 `form:"page_size"` // 每页数量
|
||||
RebateType *int64 `form:"rebate_type,optional"` // 返佣类型(可选):1=直接上级返佣,2=钻石上级返佣,3=黄金上级返佣
|
||||
}
|
||||
|
||||
type GetRebateListResp struct {
|
||||
Total int64 `json:"total"` // 总数
|
||||
List []RebateItem `json:"list"` // 列表
|
||||
}
|
||||
|
||||
type GetRevenueInfoResp struct {
|
||||
Balance float64 `json:"balance"` // 可用余额
|
||||
FrozenBalance float64 `json:"frozen_balance"` // 冻结余额
|
||||
TotalEarnings float64 `json:"total_earnings"` // 累计收益(钱包总收益)
|
||||
WithdrawnAmount float64 `json:"withdrawn_amount"` // 累计提现
|
||||
CommissionTotal float64 `json:"commission_total"` // 佣金累计总收益(推广订单获得的佣金)
|
||||
CommissionToday float64 `json:"commission_today"` // 佣金今日收益
|
||||
CommissionMonth float64 `json:"commission_month"` // 佣金本月收益
|
||||
RebateTotal float64 `json:"rebate_total"` // 返佣累计总收益(包括推广返佣和升级返佣)
|
||||
RebateToday float64 `json:"rebate_today"` // 返佣今日收益
|
||||
RebateMonth float64 `json:"rebate_month"` // 返佣本月收益
|
||||
}
|
||||
|
||||
type GetSubordinateContributionDetailReq struct {
|
||||
SubordinateId string `form:"subordinate_id"` // 下级代理ID
|
||||
Page int64 `form:"page"` // 页码
|
||||
PageSize int64 `form:"page_size"` // 每页数量
|
||||
TabType string `form:"tab_type,optional"` // 标签页类型:order=订单列表,invite=邀请列表
|
||||
}
|
||||
|
||||
type GetSubordinateContributionDetailResp struct {
|
||||
Mobile string `json:"mobile"` // 手机号
|
||||
LevelName string `json:"level_name"` // 等级名称
|
||||
CreateTime string `json:"create_time"` // 创建时间
|
||||
OrderStats OrderStatistics `json:"order_stats"` // 订单统计(仅统计有返佣的订单)
|
||||
RebateStats RebateStatistics `json:"rebate_stats"` // 返佣统计
|
||||
InviteStats InviteStatistics `json:"invite_stats"` // 邀请统计
|
||||
OrderList []OrderItem `json:"order_list"` // 订单列表(仅有贡献的订单)
|
||||
InviteList []InviteItem `json:"invite_list"` // 邀请列表
|
||||
OrderListTotal int64 `json:"order_list_total"` // 订单列表总数
|
||||
InviteListTotal int64 `json:"invite_list_total"` // 邀请列表总数
|
||||
}
|
||||
|
||||
type GetSubordinateListReq struct {
|
||||
Page int64 `form:"page"` // 页码
|
||||
PageSize int64 `form:"page_size"` // 每页数量
|
||||
}
|
||||
|
||||
type GetSubordinateListResp struct {
|
||||
Total int64 `json:"total"` // 总数
|
||||
List []SubordinateItem `json:"list"` // 列表
|
||||
}
|
||||
|
||||
type GetTeamListReq struct {
|
||||
Page int64 `form:"page"` // 页码
|
||||
PageSize int64 `form:"page_size"` // 每页数量
|
||||
Mobile string `form:"mobile,optional"` // 手机号(可选,用于搜索)
|
||||
}
|
||||
|
||||
type GetTeamListResp struct {
|
||||
Statistics TeamStatistics `json:"statistics"` // 统计数据
|
||||
Total int64 `json:"total"` // 总数
|
||||
List []TeamMemberItem `json:"list"` // 列表
|
||||
}
|
||||
|
||||
type GetUpgradeListReq struct {
|
||||
Page int64 `form:"page"` // 页码
|
||||
PageSize int64 `form:"page_size"` // 每页数量
|
||||
}
|
||||
|
||||
type GetUpgradeListResp struct {
|
||||
Total int64 `json:"total"` // 总数
|
||||
List []UpgradeItem `json:"list"` // 列表
|
||||
}
|
||||
|
||||
type GetUpgradeRebateListReq struct {
|
||||
Page int64 `form:"page"` // 页码
|
||||
PageSize int64 `form:"page_size"` // 每页数量
|
||||
}
|
||||
|
||||
type GetUpgradeRebateListResp struct {
|
||||
Total int64 `json:"total"` // 总数
|
||||
List []UpgradeRebateItem `json:"list"` // 列表
|
||||
}
|
||||
|
||||
type GetWithdrawalListReq struct {
|
||||
Page int64 `form:"page"` // 页码
|
||||
PageSize int64 `form:"page_size"` // 每页数量
|
||||
}
|
||||
|
||||
type GetWithdrawalListResp struct {
|
||||
Total int64 `json:"total"` // 总数
|
||||
List []WithdrawalItem `json:"list"` // 列表
|
||||
}
|
||||
|
||||
type RealNameAuthReq struct {
|
||||
Name string `json:"name"` // 姓名
|
||||
IdCard string `json:"id_card"` // 身份证号
|
||||
Mobile string `json:"mobile"` // 手机号
|
||||
Code string `json:"code"` // 验证码
|
||||
}
|
||||
|
||||
type RealNameAuthResp struct {
|
||||
Status string `json:"status"` // 状态:pending=待审核,approved=已通过,rejected=已拒绝
|
||||
}
|
||||
|
||||
type RegisterByInviteCodeReq struct {
|
||||
Referrer string `json:"referrer"`
|
||||
InviteCode string `json:"invite_code,optional"`
|
||||
AgentCode int64 `json:"agent_code,optional"`
|
||||
Mobile string `json:"mobile"`
|
||||
Code string `json:"code"`
|
||||
Region string `json:"region,optional"`
|
||||
WechatId string `json:"wechat_id,optional"`
|
||||
}
|
||||
|
||||
type RegisterByInviteCodeResp struct {
|
||||
AccessToken string `json:"accessToken"`
|
||||
AccessExpire int64 `json:"accessExpire"`
|
||||
RefreshAfter int64 `json:"refreshAfter"`
|
||||
AgentId string `json:"agent_id"` // 代理ID
|
||||
Level int64 `json:"level"` // 代理等级
|
||||
LevelName string `json:"level_name"` // 等级名称
|
||||
AgentCode int64 `json:"agent_code"`
|
||||
}
|
||||
|
||||
type ShortLinkRedirectResp struct {
|
||||
}
|
||||
|
||||
type TeamStatisticsResp struct {
|
||||
TotalCount int64 `json:"total_count"` // 团队总人数(不包括自己)
|
||||
DirectCount int64 `json:"direct_count"` // 直接下级数量
|
||||
IndirectCount int64 `json:"indirect_count"` // 间接下级数量
|
||||
GoldCount int64 `json:"gold_count"` // 黄金代理数量
|
||||
NormalCount int64 `json:"normal_count"` // 白银代理数量
|
||||
TodayNewMembers int64 `json:"today_new_members"` // 今日新增成员
|
||||
MonthNewMembers int64 `json:"month_new_members"` // 本月新增成员
|
||||
}
|
||||
|
||||
type UpgradeSubordinateReq struct {
|
||||
SubordinateId string `json:"subordinate_id"` // 下级代理ID
|
||||
ToLevel int64 `json:"to_level"` // 目标等级(只能是2=黄金)
|
||||
}
|
||||
|
||||
type UpgradeSubordinateResp struct {
|
||||
Success bool `json:"success"`
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
// Code generated by goctl. DO NOT EDIT.
|
||||
package types
|
||||
|
||||
type HealthCheckResp struct {
|
||||
Status string `json:"status"` // 服务状态
|
||||
Message string `json:"message"` // 状态信息
|
||||
}
|
||||
|
||||
type GetAppConfigResp struct {
|
||||
QueryRetentionDays int64 `json:"query_retention_days"`
|
||||
}
|
||||
|
||||
type GetAppVersionResp struct {
|
||||
Version string `json:"version"`
|
||||
WgtUrl string `json:"wgtUrl"`
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
// Code generated by goctl. DO NOT EDIT.
|
||||
package types
|
||||
|
||||
type SendSmsReq struct {
|
||||
Mobile string `json:"mobile" validate:"required,mobile"`
|
||||
ActionType string `json:"actionType" validate:"required,oneof=login register query agentApply realName bindMobile"`
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
// Code generated by goctl. DO NOT EDIT.
|
||||
package types
|
||||
|
||||
type DownloadAuthorizationDocumentReq struct {
|
||||
DocumentId string `json:"documentId" validate:"required"` // 授权书ID
|
||||
}
|
||||
|
||||
type DownloadAuthorizationDocumentResp struct {
|
||||
FileName string `json:"fileName"` // 文件名
|
||||
FileUrl string `json:"fileUrl"` // 文件访问URL
|
||||
}
|
||||
|
||||
type GetAuthorizationDocumentByOrderReq struct {
|
||||
OrderId string `json:"orderId" validate:"required"` // 订单ID
|
||||
}
|
||||
|
||||
type GetAuthorizationDocumentByOrderResp struct {
|
||||
Documents []AuthorizationDocumentInfo `json:"documents"` // 授权书列表
|
||||
}
|
||||
|
||||
type GetAuthorizationDocumentReq struct {
|
||||
DocumentId string `json:"documentId" validate:"required"` // 授权书ID
|
||||
}
|
||||
|
||||
type GetAuthorizationDocumentResp struct {
|
||||
DocumentId string `json:"documentId"` // 授权书ID
|
||||
UserId string `json:"userId"` // 用户ID
|
||||
OrderId string `json:"orderId"` // 订单ID
|
||||
QueryId string `json:"queryId"` // 查询ID
|
||||
FileName string `json:"fileName"` // 文件名
|
||||
FileUrl string `json:"fileUrl"` // 文件访问URL
|
||||
FileSize int64 `json:"fileSize"` // 文件大小
|
||||
FileType string `json:"fileType"` // 文件类型
|
||||
Status string `json:"status"` // 状态
|
||||
CreateTime string `json:"createTime"` // 创建时间
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
// Code generated by goctl. DO NOT EDIT.
|
||||
package types
|
||||
|
||||
type GetNotificationsResp struct {
|
||||
Notifications []Notification `json:"notifications"` // 通知列表
|
||||
Total int64 `json:"total"` // 总记录数
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
// Code generated by goctl. DO NOT EDIT.
|
||||
package types
|
||||
|
||||
type IapCallbackReq struct {
|
||||
OrderID string `json:"order_id" validate:"required"`
|
||||
TransactionReceipt string `json:"transaction_receipt" validate:"required"`
|
||||
}
|
||||
|
||||
type PaymentCheckReq struct {
|
||||
OrderNo string `json:"order_no" validate:"required"`
|
||||
}
|
||||
|
||||
type PaymentCheckResp struct {
|
||||
Type string `json:"type"`
|
||||
Status string `json:"status"`
|
||||
}
|
||||
|
||||
type PaymentReq struct {
|
||||
Id string `json:"id"`
|
||||
PayMethod string `json:"pay_method"` // 支付方式: wechat, alipay, appleiap, test(仅开发环境), test_empty(仅开发环境-空报告模式)
|
||||
PayType string `json:"pay_type" validate:"required,oneof=query agent_vip agent_upgrade"`
|
||||
}
|
||||
|
||||
type PaymentResp struct {
|
||||
PrepayData interface{} `json:"prepay_data"`
|
||||
PrepayId string `json:"prepay_id"`
|
||||
OrderNo string `json:"order_no"`
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
// Code generated by goctl. DO NOT EDIT.
|
||||
package types
|
||||
|
||||
type GetProductByEnRequest struct {
|
||||
ProductEn string `path:"product_en"`
|
||||
}
|
||||
|
||||
type GetProductByIDRequest struct {
|
||||
Id string `path:"id"`
|
||||
}
|
||||
|
||||
type ProductResponse struct {
|
||||
Product
|
||||
}
|
||||
@@ -1,90 +0,0 @@
|
||||
// Code generated by goctl. DO NOT EDIT.
|
||||
package types
|
||||
|
||||
type QueryDetailByOrderIdReq struct {
|
||||
OrderId string `path:"order_id"`
|
||||
}
|
||||
|
||||
type QueryDetailByOrderNoReq struct {
|
||||
OrderNo string `path:"order_no"`
|
||||
}
|
||||
|
||||
type QueryExampleReq struct {
|
||||
Feature string `form:"feature"`
|
||||
}
|
||||
|
||||
type QueryGenerateShareLinkReq struct {
|
||||
OrderId *string `json:"order_id,optional"`
|
||||
OrderNo *string `json:"order_no,optional"`
|
||||
}
|
||||
|
||||
type QueryGenerateShareLinkResp struct {
|
||||
ShareLink string `json:"share_link"`
|
||||
}
|
||||
|
||||
type QueryListReq struct {
|
||||
Page int64 `form:"page"` // 页码
|
||||
PageSize int64 `form:"page_size"` // 每页数据量
|
||||
}
|
||||
|
||||
type QueryListResp struct {
|
||||
Total int64 `json:"total"` // 总记录数
|
||||
List []Query `json:"list"` // 查询列表
|
||||
}
|
||||
|
||||
type QueryProvisionalOrderReq struct {
|
||||
Id string `path:"id"`
|
||||
}
|
||||
|
||||
type QueryProvisionalOrderResp struct {
|
||||
Name string `json:"name"`
|
||||
IdCard string `json:"id_card"`
|
||||
Mobile string `json:"mobile"`
|
||||
Product Product `json:"product"`
|
||||
}
|
||||
|
||||
type QueryRetryReq struct {
|
||||
Id string `path:"id"`
|
||||
}
|
||||
|
||||
type QueryRetryResp struct {
|
||||
Query
|
||||
}
|
||||
|
||||
type QueryServiceReq struct {
|
||||
Product string `path:"product"`
|
||||
Data string `json:"data" validate:"required"`
|
||||
AgentIdentifier string `json:"agent_identifier,optional"`
|
||||
App bool `json:"app,optional"`
|
||||
}
|
||||
|
||||
type QueryServiceResp struct {
|
||||
Id string `json:"id"`
|
||||
AccessToken string `json:"accessToken"`
|
||||
AccessExpire int64 `json:"accessExpire"`
|
||||
RefreshAfter int64 `json:"refreshAfter"`
|
||||
}
|
||||
|
||||
type QueryShareDetailReq struct {
|
||||
Id string `path:"id"`
|
||||
}
|
||||
|
||||
type QuerySingleTestReq struct {
|
||||
Params map[string]interface{} `json:"params"`
|
||||
Api string `json:"api"`
|
||||
}
|
||||
|
||||
type QuerySingleTestResp struct {
|
||||
Data interface{} `json:"data"`
|
||||
Api string `json:"api"`
|
||||
}
|
||||
|
||||
type UpdateQueryDataReq struct {
|
||||
Id string `json:"id"` // 查询ID
|
||||
QueryData string `json:"query_data"` // 查询数据(未加密的JSON)
|
||||
}
|
||||
|
||||
type UpdateQueryDataResp struct {
|
||||
Id string `json:"id"`
|
||||
UpdatedAt string `json:"updated_at"` // 更新时间
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,73 +0,0 @@
|
||||
// Code generated by goctl. DO NOT EDIT.
|
||||
package types
|
||||
|
||||
type AuthReq struct {
|
||||
Platform string `json:"platform"` // browser|wxh5|wxmini
|
||||
Code string `json:"code,optional"`
|
||||
}
|
||||
|
||||
type AuthResp struct {
|
||||
AccessToken string `json:"accessToken"`
|
||||
AccessExpire int64 `json:"accessExpire"`
|
||||
RefreshAfter int64 `json:"refreshAfter"`
|
||||
UserType int64 `json:"userType"`
|
||||
HasMobile bool `json:"hasMobile"`
|
||||
IsAgent bool `json:"isAgent"`
|
||||
}
|
||||
|
||||
type BindMobileReq struct {
|
||||
Mobile string `json:"mobile" validate:"required,mobile"`
|
||||
Code string `json:"code" validate:"required"`
|
||||
}
|
||||
|
||||
type BindMobileResp struct {
|
||||
AccessToken string `json:"accessToken"`
|
||||
AccessExpire int64 `json:"accessExpire"`
|
||||
RefreshAfter int64 `json:"refreshAfter"`
|
||||
}
|
||||
|
||||
type GetSignatureReq struct {
|
||||
Url string `json:"url"`
|
||||
}
|
||||
|
||||
type GetSignatureResp struct {
|
||||
AppId string `json:"appId"`
|
||||
Timestamp int64 `json:"timestamp"`
|
||||
NonceStr string `json:"nonceStr"`
|
||||
Signature string `json:"signature"`
|
||||
}
|
||||
|
||||
type MobileCodeLoginReq struct {
|
||||
Mobile string `json:"mobile"`
|
||||
Code string `json:"code" validate:"required"`
|
||||
}
|
||||
|
||||
type MobileCodeLoginResp struct {
|
||||
AccessToken string `json:"accessToken"`
|
||||
AccessExpire int64 `json:"accessExpire"`
|
||||
RefreshAfter int64 `json:"refreshAfter"`
|
||||
}
|
||||
|
||||
type UserInfoResp struct {
|
||||
UserInfo User `json:"userInfo"`
|
||||
}
|
||||
|
||||
type WXH5AuthReq struct {
|
||||
Code string `json:"code"`
|
||||
}
|
||||
|
||||
type WXH5AuthResp struct {
|
||||
AccessToken string `json:"accessToken"`
|
||||
AccessExpire int64 `json:"accessExpire"`
|
||||
RefreshAfter int64 `json:"refreshAfter"`
|
||||
}
|
||||
|
||||
type WXMiniAuthReq struct {
|
||||
Code string `json:"code"`
|
||||
}
|
||||
|
||||
type WXMiniAuthResp struct {
|
||||
AccessToken string `json:"accessToken"`
|
||||
AccessExpire int64 `json:"accessExpire"`
|
||||
RefreshAfter int64 `json:"refreshAfter"`
|
||||
}
|
||||
@@ -12,7 +12,6 @@ import (
|
||||
"time"
|
||||
|
||||
"bdqr-server/common/globalkey"
|
||||
|
||||
"github.com/Masterminds/squirrel"
|
||||
"github.com/google/uuid"
|
||||
"github.com/pkg/errors"
|
||||
@@ -59,14 +58,16 @@ type (
|
||||
}
|
||||
|
||||
Feature struct {
|
||||
Id string `db:"id"`
|
||||
CreateTime time.Time `db:"create_time"` // 创建时间
|
||||
UpdateTime time.Time `db:"update_time"` // 更新时间
|
||||
DeleteTime sql.NullTime `db:"delete_time"` // 删除时间
|
||||
DelState int64 `db:"del_state"` // 删除状态
|
||||
Version int64 `db:"version"` // 版本号
|
||||
ApiId string `db:"api_id"` // API标识
|
||||
Name string `db:"name"` // 描述
|
||||
Id string `db:"id"`
|
||||
CreateTime time.Time `db:"create_time"` // 创建时间
|
||||
UpdateTime time.Time `db:"update_time"` // 更新时间
|
||||
DeleteTime sql.NullTime `db:"delete_time"` // 删除时间
|
||||
DelState int64 `db:"del_state"` // 删除状态
|
||||
Version int64 `db:"version"` // 版本号
|
||||
ApiId string `db:"api_id"` // API标识
|
||||
Name string `db:"name"` // 描述
|
||||
WhitelistPrice float64 `db:"whitelist_price"` // 白名单屏蔽价格(单位:元)
|
||||
CostPrice float64 `db:"cost_price"` // 天远API调用成本价(单位:元)
|
||||
}
|
||||
)
|
||||
|
||||
@@ -83,11 +84,11 @@ func (m *defaultFeatureModel) Insert(ctx context.Context, session sqlx.Session,
|
||||
bdqrFeatureApiIdKey := fmt.Sprintf("%s%v", cacheBdqrFeatureApiIdPrefix, data.ApiId)
|
||||
bdqrFeatureIdKey := fmt.Sprintf("%s%v", cacheBdqrFeatureIdPrefix, data.Id)
|
||||
return m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
||||
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?)", m.table, featureRowsExpectAutoSet)
|
||||
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?)", m.table, featureRowsExpectAutoSet)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, data.Id, data.DeleteTime, data.DelState, data.Version, data.ApiId, data.Name)
|
||||
return session.ExecCtx(ctx, query, data.Id, data.DeleteTime, data.DelState, data.Version, data.ApiId, data.Name, data.WhitelistPrice, data.CostPrice)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, data.Id, data.DeleteTime, data.DelState, data.Version, data.ApiId, data.Name)
|
||||
return conn.ExecCtx(ctx, query, data.Id, data.DeleteTime, data.DelState, data.Version, data.ApiId, data.Name, data.WhitelistPrice, data.CostPrice)
|
||||
}, bdqrFeatureApiIdKey, bdqrFeatureIdKey)
|
||||
}
|
||||
func (m *defaultFeatureModel) insertUUID(data *Feature) {
|
||||
@@ -154,9 +155,9 @@ func (m *defaultFeatureModel) Update(ctx context.Context, session sqlx.Session,
|
||||
return m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
||||
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, featureRowsWithPlaceHolder)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.ApiId, newData.Name, newData.Id)
|
||||
return session.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.ApiId, newData.Name, newData.WhitelistPrice, newData.CostPrice, newData.Id)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.ApiId, newData.Name, newData.Id)
|
||||
return conn.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.ApiId, newData.Name, newData.WhitelistPrice, newData.CostPrice, newData.Id)
|
||||
}, bdqrFeatureApiIdKey, bdqrFeatureIdKey)
|
||||
}
|
||||
|
||||
@@ -177,9 +178,9 @@ func (m *defaultFeatureModel) UpdateWithVersion(ctx context.Context, session sql
|
||||
sqlResult, err = m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
||||
query := fmt.Sprintf("update %s set %s where `id` = ? and version = ? ", m.table, featureRowsWithPlaceHolder)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.ApiId, newData.Name, newData.Id, oldVersion)
|
||||
return session.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.ApiId, newData.Name, newData.WhitelistPrice, newData.CostPrice, newData.Id, oldVersion)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.ApiId, newData.Name, newData.Id, oldVersion)
|
||||
return conn.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.ApiId, newData.Name, newData.WhitelistPrice, newData.CostPrice, newData.Id, oldVersion)
|
||||
}, bdqrFeatureApiIdKey, bdqrFeatureIdKey)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
27
app/main/model/tianyuanapiCallLogModel.go
Normal file
27
app/main/model/tianyuanapiCallLogModel.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"github.com/zeromicro/go-zero/core/stores/cache"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
)
|
||||
|
||||
var _ TianyuanapiCallLogModel = (*customTianyuanapiCallLogModel)(nil)
|
||||
|
||||
type (
|
||||
// TianyuanapiCallLogModel is an interface to be customized, add more methods here,
|
||||
// and implement the added methods in customTianyuanapiCallLogModel.
|
||||
TianyuanapiCallLogModel interface {
|
||||
tianyuanapiCallLogModel
|
||||
}
|
||||
|
||||
customTianyuanapiCallLogModel struct {
|
||||
*defaultTianyuanapiCallLogModel
|
||||
}
|
||||
)
|
||||
|
||||
// NewTianyuanapiCallLogModel returns a model for the database table.
|
||||
func NewTianyuanapiCallLogModel(conn sqlx.SqlConn, c cache.CacheConf) TianyuanapiCallLogModel {
|
||||
return &customTianyuanapiCallLogModel{
|
||||
defaultTianyuanapiCallLogModel: newTianyuanapiCallLogModel(conn, c),
|
||||
}
|
||||
}
|
||||
399
app/main/model/tianyuanapiCallLogModel_gen.go
Normal file
399
app/main/model/tianyuanapiCallLogModel_gen.go
Normal file
@@ -0,0 +1,399 @@
|
||||
// Code generated by goctl. DO NOT EDIT!
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"reflect"
|
||||
"time"
|
||||
|
||||
"bdqr-server/common/globalkey"
|
||||
|
||||
"github.com/Masterminds/squirrel"
|
||||
"github.com/google/uuid"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/zeromicro/go-zero/core/stores/builder"
|
||||
"github.com/zeromicro/go-zero/core/stores/cache"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlc"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
"github.com/zeromicro/go-zero/core/stringx"
|
||||
)
|
||||
|
||||
var (
|
||||
tianyuanapiCallLogFieldNames = builder.RawFieldNames(&TianyuanapiCallLog{})
|
||||
tianyuanapiCallLogRows = strings.Join(tianyuanapiCallLogFieldNames, ",")
|
||||
tianyuanapiCallLogRowsExpectAutoSet = strings.Join(stringx.Remove(tianyuanapiCallLogFieldNames, "`id`", "`create_time`", "`update_time`"), ",")
|
||||
tianyuanapiCallLogRowsWithPlaceHolder = strings.Join(stringx.Remove(tianyuanapiCallLogFieldNames, "`id`", "`create_time`", "`update_time`"), "=?,") + "=?"
|
||||
|
||||
cacheBdqrTianyuanapiCallLogIdPrefix = "cache:bdqr:tianyuanapiCallLog:id:"
|
||||
)
|
||||
|
||||
type (
|
||||
tianyuanapiCallLogModel interface {
|
||||
Insert(ctx context.Context, session sqlx.Session, data *TianyuanapiCallLog) (sql.Result, error)
|
||||
FindOne(ctx context.Context, id int64) (*TianyuanapiCallLog, error)
|
||||
Update(ctx context.Context, session sqlx.Session, data *TianyuanapiCallLog) (sql.Result, error)
|
||||
UpdateWithVersion(ctx context.Context, session sqlx.Session, data *TianyuanapiCallLog) error
|
||||
Trans(ctx context.Context, fn func(context context.Context, session sqlx.Session) error) error
|
||||
SelectBuilder() squirrel.SelectBuilder
|
||||
DeleteSoft(ctx context.Context, session sqlx.Session, data *TianyuanapiCallLog) error
|
||||
FindSum(ctx context.Context, sumBuilder squirrel.SelectBuilder, field string) (float64, error)
|
||||
FindCount(ctx context.Context, countBuilder squirrel.SelectBuilder, field string) (int64, error)
|
||||
FindAll(ctx context.Context, rowBuilder squirrel.SelectBuilder, orderBy string) ([]*TianyuanapiCallLog, error)
|
||||
FindPageListByPage(ctx context.Context, rowBuilder squirrel.SelectBuilder, page, pageSize int64, orderBy string) ([]*TianyuanapiCallLog, error)
|
||||
FindPageListByPageWithTotal(ctx context.Context, rowBuilder squirrel.SelectBuilder, page, pageSize int64, orderBy string) ([]*TianyuanapiCallLog, int64, error)
|
||||
FindPageListByIdDESC(ctx context.Context, rowBuilder squirrel.SelectBuilder, preMinId, pageSize int64) ([]*TianyuanapiCallLog, error)
|
||||
FindPageListByIdASC(ctx context.Context, rowBuilder squirrel.SelectBuilder, preMaxId, pageSize int64) ([]*TianyuanapiCallLog, error)
|
||||
Delete(ctx context.Context, session sqlx.Session, id int64) error
|
||||
}
|
||||
|
||||
defaultTianyuanapiCallLogModel struct {
|
||||
sqlc.CachedConn
|
||||
table string
|
||||
}
|
||||
|
||||
TianyuanapiCallLog struct {
|
||||
Id int64 `db:"id"` // 主键ID
|
||||
FeatureId string `db:"feature_id"` // 功能ID(关联feature表)
|
||||
ApiId string `db:"api_id"` // API标识(如:YYSYBE08)
|
||||
OrderId sql.NullString `db:"order_id"` // 订单ID(关联order表)
|
||||
QueryId sql.NullString `db:"query_id"` // 查询ID(关联query表)
|
||||
CallStatus int64 `db:"call_status"` // 调用状态:0=失败,1=成功
|
||||
CallTime time.Time `db:"call_time"` // 调用时间
|
||||
ResponseTime sql.NullInt64 `db:"response_time"` // 响应耗时(毫秒)
|
||||
CostPrice float64 `db:"cost_price"` // 本次调用成本(成功时从feature.cost_price获取,失败时为0)
|
||||
ErrorCode sql.NullString `db:"error_code"` // 错误码(失败时记录)
|
||||
ErrorMessage sql.NullString `db:"error_message"` // 错误信息(失败时记录)
|
||||
RequestParams sql.NullString `db:"request_params"` // 请求参数(JSON格式)
|
||||
ResponseData sql.NullString `db:"response_data"` // 响应数据(JSON格式,仅记录关键信息)
|
||||
TransactionId sql.NullString `db:"transaction_id"` // 天远API流水号
|
||||
CreateTime time.Time `db:"create_time"` // 创建时间
|
||||
UpdateTime time.Time `db:"update_time"` // 更新时间
|
||||
DeleteTime sql.NullTime `db:"delete_time"` // 删除时间
|
||||
DelState int64 `db:"del_state"` // 删除状态:0=未删除,1=已删除
|
||||
Version int64 `db:"version"` // 版本号(乐观锁)
|
||||
}
|
||||
)
|
||||
|
||||
func newTianyuanapiCallLogModel(conn sqlx.SqlConn, c cache.CacheConf) *defaultTianyuanapiCallLogModel {
|
||||
return &defaultTianyuanapiCallLogModel{
|
||||
CachedConn: sqlc.NewConn(conn, c),
|
||||
table: "`tianyuanapi_call_log`",
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultTianyuanapiCallLogModel) Insert(ctx context.Context, session sqlx.Session, data *TianyuanapiCallLog) (sql.Result, error) {
|
||||
data.DelState = globalkey.DelStateNo
|
||||
m.insertUUID(data)
|
||||
bdqrTianyuanapiCallLogIdKey := fmt.Sprintf("%s%v", cacheBdqrTianyuanapiCallLogIdPrefix, data.Id)
|
||||
return m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
||||
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, tianyuanapiCallLogRowsExpectAutoSet)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, data.FeatureId, data.ApiId, data.OrderId, data.QueryId, data.CallStatus, data.CallTime, data.ResponseTime, data.CostPrice, data.ErrorCode, data.ErrorMessage, data.RequestParams, data.ResponseData, data.TransactionId, data.DeleteTime, data.DelState, data.Version)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, data.FeatureId, data.ApiId, data.OrderId, data.QueryId, data.CallStatus, data.CallTime, data.ResponseTime, data.CostPrice, data.ErrorCode, data.ErrorMessage, data.RequestParams, data.ResponseData, data.TransactionId, data.DeleteTime, data.DelState, data.Version)
|
||||
}, bdqrTianyuanapiCallLogIdKey)
|
||||
}
|
||||
func (m *defaultTianyuanapiCallLogModel) insertUUID(data *TianyuanapiCallLog) {
|
||||
t := reflect.TypeOf(data).Elem()
|
||||
v := reflect.ValueOf(data).Elem()
|
||||
for i := 0; i < t.NumField(); i++ {
|
||||
sf := t.Field(i)
|
||||
if sf.Tag.Get("db") == "id" {
|
||||
f := v.Field(i)
|
||||
if f.IsValid() && f.CanSet() && f.Kind() == reflect.String {
|
||||
if f.String() == "" {
|
||||
f.SetString(uuid.NewString())
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultTianyuanapiCallLogModel) FindOne(ctx context.Context, id int64) (*TianyuanapiCallLog, error) {
|
||||
bdqrTianyuanapiCallLogIdKey := fmt.Sprintf("%s%v", cacheBdqrTianyuanapiCallLogIdPrefix, id)
|
||||
var resp TianyuanapiCallLog
|
||||
err := m.QueryRowCtx(ctx, &resp, bdqrTianyuanapiCallLogIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
|
||||
query := fmt.Sprintf("select %s from %s where `id` = ? and del_state = ? limit 1", tianyuanapiCallLogRows, m.table)
|
||||
return conn.QueryRowCtx(ctx, v, query, id, globalkey.DelStateNo)
|
||||
})
|
||||
switch err {
|
||||
case nil:
|
||||
return &resp, nil
|
||||
case sqlc.ErrNotFound:
|
||||
return nil, ErrNotFound
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultTianyuanapiCallLogModel) Update(ctx context.Context, session sqlx.Session, data *TianyuanapiCallLog) (sql.Result, error) {
|
||||
bdqrTianyuanapiCallLogIdKey := fmt.Sprintf("%s%v", cacheBdqrTianyuanapiCallLogIdPrefix, data.Id)
|
||||
return m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
||||
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, tianyuanapiCallLogRowsWithPlaceHolder)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, data.FeatureId, data.ApiId, data.OrderId, data.QueryId, data.CallStatus, data.CallTime, data.ResponseTime, data.CostPrice, data.ErrorCode, data.ErrorMessage, data.RequestParams, data.ResponseData, data.TransactionId, data.DeleteTime, data.DelState, data.Version, data.Id)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, data.FeatureId, data.ApiId, data.OrderId, data.QueryId, data.CallStatus, data.CallTime, data.ResponseTime, data.CostPrice, data.ErrorCode, data.ErrorMessage, data.RequestParams, data.ResponseData, data.TransactionId, data.DeleteTime, data.DelState, data.Version, data.Id)
|
||||
}, bdqrTianyuanapiCallLogIdKey)
|
||||
}
|
||||
|
||||
func (m *defaultTianyuanapiCallLogModel) UpdateWithVersion(ctx context.Context, session sqlx.Session, data *TianyuanapiCallLog) error {
|
||||
|
||||
oldVersion := data.Version
|
||||
data.Version += 1
|
||||
|
||||
var sqlResult sql.Result
|
||||
var err error
|
||||
|
||||
bdqrTianyuanapiCallLogIdKey := fmt.Sprintf("%s%v", cacheBdqrTianyuanapiCallLogIdPrefix, data.Id)
|
||||
sqlResult, err = m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
||||
query := fmt.Sprintf("update %s set %s where `id` = ? and version = ? ", m.table, tianyuanapiCallLogRowsWithPlaceHolder)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, data.FeatureId, data.ApiId, data.OrderId, data.QueryId, data.CallStatus, data.CallTime, data.ResponseTime, data.CostPrice, data.ErrorCode, data.ErrorMessage, data.RequestParams, data.ResponseData, data.TransactionId, data.DeleteTime, data.DelState, data.Version, data.Id, oldVersion)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, data.FeatureId, data.ApiId, data.OrderId, data.QueryId, data.CallStatus, data.CallTime, data.ResponseTime, data.CostPrice, data.ErrorCode, data.ErrorMessage, data.RequestParams, data.ResponseData, data.TransactionId, data.DeleteTime, data.DelState, data.Version, data.Id, oldVersion)
|
||||
}, bdqrTianyuanapiCallLogIdKey)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
updateCount, err := sqlResult.RowsAffected()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if updateCount == 0 {
|
||||
return ErrNoRowsUpdate
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *defaultTianyuanapiCallLogModel) DeleteSoft(ctx context.Context, session sqlx.Session, data *TianyuanapiCallLog) error {
|
||||
data.DelState = globalkey.DelStateYes
|
||||
data.DeleteTime = sql.NullTime{Time: time.Now(), Valid: true}
|
||||
if err := m.UpdateWithVersion(ctx, session, data); err != nil {
|
||||
return errors.Wrapf(errors.New("delete soft failed "), "TianyuanapiCallLogModel delete err : %+v", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *defaultTianyuanapiCallLogModel) FindSum(ctx context.Context, builder squirrel.SelectBuilder, field string) (float64, error) {
|
||||
|
||||
if len(field) == 0 {
|
||||
return 0, errors.Wrapf(errors.New("FindSum Least One Field"), "FindSum Least One Field")
|
||||
}
|
||||
|
||||
builder = builder.Columns("IFNULL(SUM(" + field + "),0)")
|
||||
|
||||
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).ToSql()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
var resp float64
|
||||
err = m.QueryRowNoCacheCtx(ctx, &resp, query, values...)
|
||||
switch err {
|
||||
case nil:
|
||||
return resp, nil
|
||||
default:
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultTianyuanapiCallLogModel) FindCount(ctx context.Context, builder squirrel.SelectBuilder, field string) (int64, error) {
|
||||
|
||||
if len(field) == 0 {
|
||||
return 0, errors.Wrapf(errors.New("FindCount Least One Field"), "FindCount Least One Field")
|
||||
}
|
||||
|
||||
builder = builder.Columns("COUNT(" + field + ")")
|
||||
|
||||
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).ToSql()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
var resp int64
|
||||
err = m.QueryRowNoCacheCtx(ctx, &resp, query, values...)
|
||||
switch err {
|
||||
case nil:
|
||||
return resp, nil
|
||||
default:
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultTianyuanapiCallLogModel) FindAll(ctx context.Context, builder squirrel.SelectBuilder, orderBy string) ([]*TianyuanapiCallLog, error) {
|
||||
|
||||
builder = builder.Columns(tianyuanapiCallLogRows)
|
||||
|
||||
if orderBy == "" {
|
||||
builder = builder.OrderBy("id DESC")
|
||||
} else {
|
||||
builder = builder.OrderBy(orderBy)
|
||||
}
|
||||
|
||||
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).ToSql()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var resp []*TianyuanapiCallLog
|
||||
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
||||
switch err {
|
||||
case nil:
|
||||
return resp, nil
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultTianyuanapiCallLogModel) FindPageListByPage(ctx context.Context, builder squirrel.SelectBuilder, page, pageSize int64, orderBy string) ([]*TianyuanapiCallLog, error) {
|
||||
|
||||
builder = builder.Columns(tianyuanapiCallLogRows)
|
||||
|
||||
if orderBy == "" {
|
||||
builder = builder.OrderBy("id DESC")
|
||||
} else {
|
||||
builder = builder.OrderBy(orderBy)
|
||||
}
|
||||
|
||||
if page < 1 {
|
||||
page = 1
|
||||
}
|
||||
offset := (page - 1) * pageSize
|
||||
|
||||
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).Offset(uint64(offset)).Limit(uint64(pageSize)).ToSql()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var resp []*TianyuanapiCallLog
|
||||
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
||||
switch err {
|
||||
case nil:
|
||||
return resp, nil
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultTianyuanapiCallLogModel) FindPageListByPageWithTotal(ctx context.Context, builder squirrel.SelectBuilder, page, pageSize int64, orderBy string) ([]*TianyuanapiCallLog, int64, error) {
|
||||
|
||||
total, err := m.FindCount(ctx, builder, "id")
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
builder = builder.Columns(tianyuanapiCallLogRows)
|
||||
|
||||
if orderBy == "" {
|
||||
builder = builder.OrderBy("id DESC")
|
||||
} else {
|
||||
builder = builder.OrderBy(orderBy)
|
||||
}
|
||||
|
||||
if page < 1 {
|
||||
page = 1
|
||||
}
|
||||
offset := (page - 1) * pageSize
|
||||
|
||||
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).Offset(uint64(offset)).Limit(uint64(pageSize)).ToSql()
|
||||
if err != nil {
|
||||
return nil, total, err
|
||||
}
|
||||
|
||||
var resp []*TianyuanapiCallLog
|
||||
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
||||
switch err {
|
||||
case nil:
|
||||
return resp, total, nil
|
||||
default:
|
||||
return nil, total, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultTianyuanapiCallLogModel) FindPageListByIdDESC(ctx context.Context, builder squirrel.SelectBuilder, preMinId, pageSize int64) ([]*TianyuanapiCallLog, error) {
|
||||
|
||||
builder = builder.Columns(tianyuanapiCallLogRows)
|
||||
|
||||
if preMinId > 0 {
|
||||
builder = builder.Where(" id < ? ", preMinId)
|
||||
}
|
||||
|
||||
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).OrderBy("id DESC").Limit(uint64(pageSize)).ToSql()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var resp []*TianyuanapiCallLog
|
||||
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
||||
switch err {
|
||||
case nil:
|
||||
return resp, nil
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultTianyuanapiCallLogModel) FindPageListByIdASC(ctx context.Context, builder squirrel.SelectBuilder, preMaxId, pageSize int64) ([]*TianyuanapiCallLog, error) {
|
||||
|
||||
builder = builder.Columns(tianyuanapiCallLogRows)
|
||||
|
||||
if preMaxId > 0 {
|
||||
builder = builder.Where(" id > ? ", preMaxId)
|
||||
}
|
||||
|
||||
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).OrderBy("id ASC").Limit(uint64(pageSize)).ToSql()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var resp []*TianyuanapiCallLog
|
||||
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
||||
switch err {
|
||||
case nil:
|
||||
return resp, nil
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultTianyuanapiCallLogModel) Trans(ctx context.Context, fn func(ctx context.Context, session sqlx.Session) error) error {
|
||||
|
||||
return m.TransactCtx(ctx, func(ctx context.Context, session sqlx.Session) error {
|
||||
return fn(ctx, session)
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
func (m *defaultTianyuanapiCallLogModel) SelectBuilder() squirrel.SelectBuilder {
|
||||
return squirrel.Select().From(m.table)
|
||||
}
|
||||
func (m *defaultTianyuanapiCallLogModel) Delete(ctx context.Context, session sqlx.Session, id int64) error {
|
||||
bdqrTianyuanapiCallLogIdKey := fmt.Sprintf("%s%v", cacheBdqrTianyuanapiCallLogIdPrefix, id)
|
||||
_, err := m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
||||
query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, id)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, id)
|
||||
}, bdqrTianyuanapiCallLogIdKey)
|
||||
return err
|
||||
}
|
||||
func (m *defaultTianyuanapiCallLogModel) formatPrimary(primary interface{}) string {
|
||||
return fmt.Sprintf("%s%v", cacheBdqrTianyuanapiCallLogIdPrefix, primary)
|
||||
}
|
||||
func (m *defaultTianyuanapiCallLogModel) queryPrimary(ctx context.Context, conn sqlx.SqlConn, v, primary interface{}) error {
|
||||
query := fmt.Sprintf("select %s from %s where `id` = ? and del_state = ? limit 1", tianyuanapiCallLogRows, m.table)
|
||||
return conn.QueryRowCtx(ctx, v, query, primary, globalkey.DelStateNo)
|
||||
}
|
||||
|
||||
func (m *defaultTianyuanapiCallLogModel) tableName() string {
|
||||
return m.table
|
||||
}
|
||||
27
app/main/model/userFeatureWhitelistModel.go
Normal file
27
app/main/model/userFeatureWhitelistModel.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"github.com/zeromicro/go-zero/core/stores/cache"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
)
|
||||
|
||||
var _ UserFeatureWhitelistModel = (*customUserFeatureWhitelistModel)(nil)
|
||||
|
||||
type (
|
||||
// UserFeatureWhitelistModel is an interface to be customized, add more methods here,
|
||||
// and implement the added methods in customUserFeatureWhitelistModel.
|
||||
UserFeatureWhitelistModel interface {
|
||||
userFeatureWhitelistModel
|
||||
}
|
||||
|
||||
customUserFeatureWhitelistModel struct {
|
||||
*defaultUserFeatureWhitelistModel
|
||||
}
|
||||
)
|
||||
|
||||
// NewUserFeatureWhitelistModel returns a model for the database table.
|
||||
func NewUserFeatureWhitelistModel(conn sqlx.SqlConn, c cache.CacheConf) UserFeatureWhitelistModel {
|
||||
return &customUserFeatureWhitelistModel{
|
||||
defaultUserFeatureWhitelistModel: newUserFeatureWhitelistModel(conn, c),
|
||||
}
|
||||
}
|
||||
484
app/main/model/userFeatureWhitelistModel_gen.go
Normal file
484
app/main/model/userFeatureWhitelistModel_gen.go
Normal file
@@ -0,0 +1,484 @@
|
||||
// Code generated by goctl. DO NOT EDIT!
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"reflect"
|
||||
"time"
|
||||
|
||||
"bdqr-server/common/globalkey"
|
||||
"github.com/Masterminds/squirrel"
|
||||
"github.com/google/uuid"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/zeromicro/go-zero/core/stores/builder"
|
||||
"github.com/zeromicro/go-zero/core/stores/cache"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlc"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
"github.com/zeromicro/go-zero/core/stringx"
|
||||
)
|
||||
|
||||
var (
|
||||
userFeatureWhitelistFieldNames = builder.RawFieldNames(&UserFeatureWhitelist{})
|
||||
userFeatureWhitelistRows = strings.Join(userFeatureWhitelistFieldNames, ",")
|
||||
userFeatureWhitelistRowsExpectAutoSet = strings.Join(stringx.Remove(userFeatureWhitelistFieldNames, "`create_time`", "`update_time`"), ",")
|
||||
userFeatureWhitelistRowsWithPlaceHolder = strings.Join(stringx.Remove(userFeatureWhitelistFieldNames, "`id`", "`create_time`", "`update_time`"), "=?,") + "=?"
|
||||
|
||||
cacheBdqrUserFeatureWhitelistIdPrefix = "cache:bdqr:userFeatureWhitelist:id:"
|
||||
cacheBdqrUserFeatureWhitelistIdCardFeatureApiIdDelStatePrefix = "cache:bdqr:userFeatureWhitelist:idCard:featureApiId:delState:"
|
||||
cacheBdqrUserFeatureWhitelistIdCardFeatureIdDelStatePrefix = "cache:bdqr:userFeatureWhitelist:idCard:featureId:delState:"
|
||||
cacheBdqrUserFeatureWhitelistWhitelistOrderIdPrefix = "cache:bdqr:userFeatureWhitelist:whitelistOrderId:"
|
||||
)
|
||||
|
||||
type (
|
||||
userFeatureWhitelistModel interface {
|
||||
Insert(ctx context.Context, session sqlx.Session, data *UserFeatureWhitelist) (sql.Result, error)
|
||||
FindOne(ctx context.Context, id string) (*UserFeatureWhitelist, error)
|
||||
FindOneByIdCardFeatureApiIdDelState(ctx context.Context, idCard string, featureApiId string, delState int64) (*UserFeatureWhitelist, error)
|
||||
FindOneByIdCardFeatureIdDelState(ctx context.Context, idCard string, featureId string, delState int64) (*UserFeatureWhitelist, error)
|
||||
FindOneByWhitelistOrderId(ctx context.Context, whitelistOrderId sql.NullString) (*UserFeatureWhitelist, error)
|
||||
Update(ctx context.Context, session sqlx.Session, data *UserFeatureWhitelist) (sql.Result, error)
|
||||
UpdateWithVersion(ctx context.Context, session sqlx.Session, data *UserFeatureWhitelist) error
|
||||
Trans(ctx context.Context, fn func(context context.Context, session sqlx.Session) error) error
|
||||
SelectBuilder() squirrel.SelectBuilder
|
||||
DeleteSoft(ctx context.Context, session sqlx.Session, data *UserFeatureWhitelist) error
|
||||
FindSum(ctx context.Context, sumBuilder squirrel.SelectBuilder, field string) (float64, error)
|
||||
FindCount(ctx context.Context, countBuilder squirrel.SelectBuilder, field string) (int64, error)
|
||||
FindAll(ctx context.Context, rowBuilder squirrel.SelectBuilder, orderBy string) ([]*UserFeatureWhitelist, error)
|
||||
FindPageListByPage(ctx context.Context, rowBuilder squirrel.SelectBuilder, page, pageSize int64, orderBy string) ([]*UserFeatureWhitelist, error)
|
||||
FindPageListByPageWithTotal(ctx context.Context, rowBuilder squirrel.SelectBuilder, page, pageSize int64, orderBy string) ([]*UserFeatureWhitelist, int64, error)
|
||||
FindPageListByIdDESC(ctx context.Context, rowBuilder squirrel.SelectBuilder, preMinId, pageSize int64) ([]*UserFeatureWhitelist, error)
|
||||
FindPageListByIdASC(ctx context.Context, rowBuilder squirrel.SelectBuilder, preMaxId, pageSize int64) ([]*UserFeatureWhitelist, error)
|
||||
Delete(ctx context.Context, session sqlx.Session, id string) error
|
||||
}
|
||||
|
||||
defaultUserFeatureWhitelistModel struct {
|
||||
sqlc.CachedConn
|
||||
table string
|
||||
}
|
||||
|
||||
UserFeatureWhitelist struct {
|
||||
Id string `db:"id"` // UUID主键
|
||||
CreateTime time.Time `db:"create_time"` // 创建时间
|
||||
UpdateTime time.Time `db:"update_time"` // 更新时间
|
||||
DeleteTime sql.NullTime `db:"delete_time"` // 删除时间
|
||||
DelState int64 `db:"del_state"` // 删除状态:0=未删除,1=已删除
|
||||
Version int64 `db:"version"` // 版本号(乐观锁)
|
||||
IdCard string `db:"id_card"` // 身份证号(查询对象标识)
|
||||
FeatureId string `db:"feature_id"` // Feature的UUID
|
||||
FeatureApiId string `db:"feature_api_id"` // Feature的API标识(冗余字段,方便查询)
|
||||
UserId string `db:"user_id"` // 操作用户ID(代理的user_id,以后可扩展为普通用户)
|
||||
OrderId sql.NullString `db:"order_id"` // 关联的查询订单ID(可选,记录来源)
|
||||
WhitelistOrderId sql.NullString `db:"whitelist_order_id"` // 关联的白名单订单ID(用于付费)
|
||||
Amount float64 `db:"amount"` // 费用(单位:元)
|
||||
Status int64 `db:"status"` // 状态:1=生效,2=已失效
|
||||
}
|
||||
)
|
||||
|
||||
func newUserFeatureWhitelistModel(conn sqlx.SqlConn, c cache.CacheConf) *defaultUserFeatureWhitelistModel {
|
||||
return &defaultUserFeatureWhitelistModel{
|
||||
CachedConn: sqlc.NewConn(conn, c),
|
||||
table: "`user_feature_whitelist`",
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultUserFeatureWhitelistModel) Insert(ctx context.Context, session sqlx.Session, data *UserFeatureWhitelist) (sql.Result, error) {
|
||||
data.DelState = globalkey.DelStateNo
|
||||
m.insertUUID(data)
|
||||
bdqrUserFeatureWhitelistIdCardFeatureApiIdDelStateKey := fmt.Sprintf("%s%v:%v:%v", cacheBdqrUserFeatureWhitelistIdCardFeatureApiIdDelStatePrefix, data.IdCard, data.FeatureApiId, data.DelState)
|
||||
bdqrUserFeatureWhitelistIdCardFeatureIdDelStateKey := fmt.Sprintf("%s%v:%v:%v", cacheBdqrUserFeatureWhitelistIdCardFeatureIdDelStatePrefix, data.IdCard, data.FeatureId, data.DelState)
|
||||
bdqrUserFeatureWhitelistIdKey := fmt.Sprintf("%s%v", cacheBdqrUserFeatureWhitelistIdPrefix, data.Id)
|
||||
bdqrUserFeatureWhitelistWhitelistOrderIdKey := fmt.Sprintf("%s%v", cacheBdqrUserFeatureWhitelistWhitelistOrderIdPrefix, data.WhitelistOrderId)
|
||||
return m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
||||
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, userFeatureWhitelistRowsExpectAutoSet)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, data.Id, data.DeleteTime, data.DelState, data.Version, data.IdCard, data.FeatureId, data.FeatureApiId, data.UserId, data.OrderId, data.WhitelistOrderId, data.Amount, data.Status)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, data.Id, data.DeleteTime, data.DelState, data.Version, data.IdCard, data.FeatureId, data.FeatureApiId, data.UserId, data.OrderId, data.WhitelistOrderId, data.Amount, data.Status)
|
||||
}, bdqrUserFeatureWhitelistIdCardFeatureApiIdDelStateKey, bdqrUserFeatureWhitelistIdCardFeatureIdDelStateKey, bdqrUserFeatureWhitelistIdKey, bdqrUserFeatureWhitelistWhitelistOrderIdKey)
|
||||
}
|
||||
func (m *defaultUserFeatureWhitelistModel) insertUUID(data *UserFeatureWhitelist) {
|
||||
t := reflect.TypeOf(data).Elem()
|
||||
v := reflect.ValueOf(data).Elem()
|
||||
for i := 0; i < t.NumField(); i++ {
|
||||
sf := t.Field(i)
|
||||
if sf.Tag.Get("db") == "id" {
|
||||
f := v.Field(i)
|
||||
if f.IsValid() && f.CanSet() && f.Kind() == reflect.String {
|
||||
if f.String() == "" {
|
||||
f.SetString(uuid.NewString())
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultUserFeatureWhitelistModel) FindOne(ctx context.Context, id string) (*UserFeatureWhitelist, error) {
|
||||
bdqrUserFeatureWhitelistIdKey := fmt.Sprintf("%s%v", cacheBdqrUserFeatureWhitelistIdPrefix, id)
|
||||
var resp UserFeatureWhitelist
|
||||
err := m.QueryRowCtx(ctx, &resp, bdqrUserFeatureWhitelistIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
|
||||
query := fmt.Sprintf("select %s from %s where `id` = ? and del_state = ? limit 1", userFeatureWhitelistRows, m.table)
|
||||
return conn.QueryRowCtx(ctx, v, query, id, globalkey.DelStateNo)
|
||||
})
|
||||
switch err {
|
||||
case nil:
|
||||
return &resp, nil
|
||||
case sqlc.ErrNotFound:
|
||||
return nil, ErrNotFound
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultUserFeatureWhitelistModel) FindOneByIdCardFeatureApiIdDelState(ctx context.Context, idCard string, featureApiId string, delState int64) (*UserFeatureWhitelist, error) {
|
||||
bdqrUserFeatureWhitelistIdCardFeatureApiIdDelStateKey := fmt.Sprintf("%s%v:%v:%v", cacheBdqrUserFeatureWhitelistIdCardFeatureApiIdDelStatePrefix, idCard, featureApiId, delState)
|
||||
var resp UserFeatureWhitelist
|
||||
err := m.QueryRowIndexCtx(ctx, &resp, bdqrUserFeatureWhitelistIdCardFeatureApiIdDelStateKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) (i interface{}, e error) {
|
||||
query := fmt.Sprintf("select %s from %s where `id_card` = ? and `feature_api_id` = ? and `del_state` = ? and del_state = ? limit 1", userFeatureWhitelistRows, m.table)
|
||||
if err := conn.QueryRowCtx(ctx, &resp, query, idCard, featureApiId, delState, globalkey.DelStateNo); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return resp.Id, nil
|
||||
}, m.queryPrimary)
|
||||
switch err {
|
||||
case nil:
|
||||
return &resp, nil
|
||||
case sqlc.ErrNotFound:
|
||||
return nil, ErrNotFound
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultUserFeatureWhitelistModel) FindOneByIdCardFeatureIdDelState(ctx context.Context, idCard string, featureId string, delState int64) (*UserFeatureWhitelist, error) {
|
||||
bdqrUserFeatureWhitelistIdCardFeatureIdDelStateKey := fmt.Sprintf("%s%v:%v:%v", cacheBdqrUserFeatureWhitelistIdCardFeatureIdDelStatePrefix, idCard, featureId, delState)
|
||||
var resp UserFeatureWhitelist
|
||||
err := m.QueryRowIndexCtx(ctx, &resp, bdqrUserFeatureWhitelistIdCardFeatureIdDelStateKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) (i interface{}, e error) {
|
||||
query := fmt.Sprintf("select %s from %s where `id_card` = ? and `feature_id` = ? and `del_state` = ? and del_state = ? limit 1", userFeatureWhitelistRows, m.table)
|
||||
if err := conn.QueryRowCtx(ctx, &resp, query, idCard, featureId, delState, globalkey.DelStateNo); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return resp.Id, nil
|
||||
}, m.queryPrimary)
|
||||
switch err {
|
||||
case nil:
|
||||
return &resp, nil
|
||||
case sqlc.ErrNotFound:
|
||||
return nil, ErrNotFound
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultUserFeatureWhitelistModel) FindOneByWhitelistOrderId(ctx context.Context, whitelistOrderId sql.NullString) (*UserFeatureWhitelist, error) {
|
||||
bdqrUserFeatureWhitelistWhitelistOrderIdKey := fmt.Sprintf("%s%v", cacheBdqrUserFeatureWhitelistWhitelistOrderIdPrefix, whitelistOrderId)
|
||||
var resp UserFeatureWhitelist
|
||||
err := m.QueryRowIndexCtx(ctx, &resp, bdqrUserFeatureWhitelistWhitelistOrderIdKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) (i interface{}, e error) {
|
||||
query := fmt.Sprintf("select %s from %s where `whitelist_order_id` = ? and del_state = ? limit 1", userFeatureWhitelistRows, m.table)
|
||||
if err := conn.QueryRowCtx(ctx, &resp, query, whitelistOrderId, globalkey.DelStateNo); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return resp.Id, nil
|
||||
}, m.queryPrimary)
|
||||
switch err {
|
||||
case nil:
|
||||
return &resp, nil
|
||||
case sqlc.ErrNotFound:
|
||||
return nil, ErrNotFound
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultUserFeatureWhitelistModel) Update(ctx context.Context, session sqlx.Session, newData *UserFeatureWhitelist) (sql.Result, error) {
|
||||
data, err := m.FindOne(ctx, newData.Id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
bdqrUserFeatureWhitelistIdCardFeatureApiIdDelStateKey := fmt.Sprintf("%s%v:%v:%v", cacheBdqrUserFeatureWhitelistIdCardFeatureApiIdDelStatePrefix, data.IdCard, data.FeatureApiId, data.DelState)
|
||||
bdqrUserFeatureWhitelistIdCardFeatureIdDelStateKey := fmt.Sprintf("%s%v:%v:%v", cacheBdqrUserFeatureWhitelistIdCardFeatureIdDelStatePrefix, data.IdCard, data.FeatureId, data.DelState)
|
||||
bdqrUserFeatureWhitelistIdKey := fmt.Sprintf("%s%v", cacheBdqrUserFeatureWhitelistIdPrefix, data.Id)
|
||||
bdqrUserFeatureWhitelistWhitelistOrderIdKey := fmt.Sprintf("%s%v", cacheBdqrUserFeatureWhitelistWhitelistOrderIdPrefix, data.WhitelistOrderId)
|
||||
return m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
||||
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, userFeatureWhitelistRowsWithPlaceHolder)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.IdCard, newData.FeatureId, newData.FeatureApiId, newData.UserId, newData.OrderId, newData.WhitelistOrderId, newData.Amount, newData.Status, newData.Id)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.IdCard, newData.FeatureId, newData.FeatureApiId, newData.UserId, newData.OrderId, newData.WhitelistOrderId, newData.Amount, newData.Status, newData.Id)
|
||||
}, bdqrUserFeatureWhitelistIdCardFeatureApiIdDelStateKey, bdqrUserFeatureWhitelistIdCardFeatureIdDelStateKey, bdqrUserFeatureWhitelistIdKey, bdqrUserFeatureWhitelistWhitelistOrderIdKey)
|
||||
}
|
||||
|
||||
func (m *defaultUserFeatureWhitelistModel) UpdateWithVersion(ctx context.Context, session sqlx.Session, newData *UserFeatureWhitelist) error {
|
||||
|
||||
oldVersion := newData.Version
|
||||
newData.Version += 1
|
||||
|
||||
var sqlResult sql.Result
|
||||
var err error
|
||||
|
||||
data, err := m.FindOne(ctx, newData.Id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
bdqrUserFeatureWhitelistIdCardFeatureApiIdDelStateKey := fmt.Sprintf("%s%v:%v:%v", cacheBdqrUserFeatureWhitelistIdCardFeatureApiIdDelStatePrefix, data.IdCard, data.FeatureApiId, data.DelState)
|
||||
bdqrUserFeatureWhitelistIdCardFeatureIdDelStateKey := fmt.Sprintf("%s%v:%v:%v", cacheBdqrUserFeatureWhitelistIdCardFeatureIdDelStatePrefix, data.IdCard, data.FeatureId, data.DelState)
|
||||
bdqrUserFeatureWhitelistIdKey := fmt.Sprintf("%s%v", cacheBdqrUserFeatureWhitelistIdPrefix, data.Id)
|
||||
bdqrUserFeatureWhitelistWhitelistOrderIdKey := fmt.Sprintf("%s%v", cacheBdqrUserFeatureWhitelistWhitelistOrderIdPrefix, data.WhitelistOrderId)
|
||||
sqlResult, err = m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
||||
query := fmt.Sprintf("update %s set %s where `id` = ? and version = ? ", m.table, userFeatureWhitelistRowsWithPlaceHolder)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.IdCard, newData.FeatureId, newData.FeatureApiId, newData.UserId, newData.OrderId, newData.WhitelistOrderId, newData.Amount, newData.Status, newData.Id, oldVersion)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.IdCard, newData.FeatureId, newData.FeatureApiId, newData.UserId, newData.OrderId, newData.WhitelistOrderId, newData.Amount, newData.Status, newData.Id, oldVersion)
|
||||
}, bdqrUserFeatureWhitelistIdCardFeatureApiIdDelStateKey, bdqrUserFeatureWhitelistIdCardFeatureIdDelStateKey, bdqrUserFeatureWhitelistIdKey, bdqrUserFeatureWhitelistWhitelistOrderIdKey)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
updateCount, err := sqlResult.RowsAffected()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if updateCount == 0 {
|
||||
return ErrNoRowsUpdate
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *defaultUserFeatureWhitelistModel) DeleteSoft(ctx context.Context, session sqlx.Session, data *UserFeatureWhitelist) error {
|
||||
data.DelState = globalkey.DelStateYes
|
||||
data.DeleteTime = sql.NullTime{Time: time.Now(), Valid: true}
|
||||
if err := m.UpdateWithVersion(ctx, session, data); err != nil {
|
||||
return errors.Wrapf(errors.New("delete soft failed "), "UserFeatureWhitelistModel delete err : %+v", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *defaultUserFeatureWhitelistModel) FindSum(ctx context.Context, builder squirrel.SelectBuilder, field string) (float64, error) {
|
||||
|
||||
if len(field) == 0 {
|
||||
return 0, errors.Wrapf(errors.New("FindSum Least One Field"), "FindSum Least One Field")
|
||||
}
|
||||
|
||||
builder = builder.Columns("IFNULL(SUM(" + field + "),0)")
|
||||
|
||||
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).ToSql()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
var resp float64
|
||||
err = m.QueryRowNoCacheCtx(ctx, &resp, query, values...)
|
||||
switch err {
|
||||
case nil:
|
||||
return resp, nil
|
||||
default:
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultUserFeatureWhitelistModel) FindCount(ctx context.Context, builder squirrel.SelectBuilder, field string) (int64, error) {
|
||||
|
||||
if len(field) == 0 {
|
||||
return 0, errors.Wrapf(errors.New("FindCount Least One Field"), "FindCount Least One Field")
|
||||
}
|
||||
|
||||
builder = builder.Columns("COUNT(" + field + ")")
|
||||
|
||||
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).ToSql()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
var resp int64
|
||||
err = m.QueryRowNoCacheCtx(ctx, &resp, query, values...)
|
||||
switch err {
|
||||
case nil:
|
||||
return resp, nil
|
||||
default:
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultUserFeatureWhitelistModel) FindAll(ctx context.Context, builder squirrel.SelectBuilder, orderBy string) ([]*UserFeatureWhitelist, error) {
|
||||
|
||||
builder = builder.Columns(userFeatureWhitelistRows)
|
||||
|
||||
if orderBy == "" {
|
||||
builder = builder.OrderBy("id DESC")
|
||||
} else {
|
||||
builder = builder.OrderBy(orderBy)
|
||||
}
|
||||
|
||||
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).ToSql()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var resp []*UserFeatureWhitelist
|
||||
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
||||
switch err {
|
||||
case nil:
|
||||
return resp, nil
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultUserFeatureWhitelistModel) FindPageListByPage(ctx context.Context, builder squirrel.SelectBuilder, page, pageSize int64, orderBy string) ([]*UserFeatureWhitelist, error) {
|
||||
|
||||
builder = builder.Columns(userFeatureWhitelistRows)
|
||||
|
||||
if orderBy == "" {
|
||||
builder = builder.OrderBy("id DESC")
|
||||
} else {
|
||||
builder = builder.OrderBy(orderBy)
|
||||
}
|
||||
|
||||
if page < 1 {
|
||||
page = 1
|
||||
}
|
||||
offset := (page - 1) * pageSize
|
||||
|
||||
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).Offset(uint64(offset)).Limit(uint64(pageSize)).ToSql()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var resp []*UserFeatureWhitelist
|
||||
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
||||
switch err {
|
||||
case nil:
|
||||
return resp, nil
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultUserFeatureWhitelistModel) FindPageListByPageWithTotal(ctx context.Context, builder squirrel.SelectBuilder, page, pageSize int64, orderBy string) ([]*UserFeatureWhitelist, int64, error) {
|
||||
|
||||
total, err := m.FindCount(ctx, builder, "id")
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
builder = builder.Columns(userFeatureWhitelistRows)
|
||||
|
||||
if orderBy == "" {
|
||||
builder = builder.OrderBy("id DESC")
|
||||
} else {
|
||||
builder = builder.OrderBy(orderBy)
|
||||
}
|
||||
|
||||
if page < 1 {
|
||||
page = 1
|
||||
}
|
||||
offset := (page - 1) * pageSize
|
||||
|
||||
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).Offset(uint64(offset)).Limit(uint64(pageSize)).ToSql()
|
||||
if err != nil {
|
||||
return nil, total, err
|
||||
}
|
||||
|
||||
var resp []*UserFeatureWhitelist
|
||||
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
||||
switch err {
|
||||
case nil:
|
||||
return resp, total, nil
|
||||
default:
|
||||
return nil, total, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultUserFeatureWhitelistModel) FindPageListByIdDESC(ctx context.Context, builder squirrel.SelectBuilder, preMinId, pageSize int64) ([]*UserFeatureWhitelist, error) {
|
||||
|
||||
builder = builder.Columns(userFeatureWhitelistRows)
|
||||
|
||||
if preMinId > 0 {
|
||||
builder = builder.Where(" id < ? ", preMinId)
|
||||
}
|
||||
|
||||
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).OrderBy("id DESC").Limit(uint64(pageSize)).ToSql()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var resp []*UserFeatureWhitelist
|
||||
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
||||
switch err {
|
||||
case nil:
|
||||
return resp, nil
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultUserFeatureWhitelistModel) FindPageListByIdASC(ctx context.Context, builder squirrel.SelectBuilder, preMaxId, pageSize int64) ([]*UserFeatureWhitelist, error) {
|
||||
|
||||
builder = builder.Columns(userFeatureWhitelistRows)
|
||||
|
||||
if preMaxId > 0 {
|
||||
builder = builder.Where(" id > ? ", preMaxId)
|
||||
}
|
||||
|
||||
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).OrderBy("id ASC").Limit(uint64(pageSize)).ToSql()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var resp []*UserFeatureWhitelist
|
||||
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
||||
switch err {
|
||||
case nil:
|
||||
return resp, nil
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultUserFeatureWhitelistModel) Trans(ctx context.Context, fn func(ctx context.Context, session sqlx.Session) error) error {
|
||||
|
||||
return m.TransactCtx(ctx, func(ctx context.Context, session sqlx.Session) error {
|
||||
return fn(ctx, session)
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
func (m *defaultUserFeatureWhitelistModel) SelectBuilder() squirrel.SelectBuilder {
|
||||
return squirrel.Select().From(m.table)
|
||||
}
|
||||
func (m *defaultUserFeatureWhitelistModel) Delete(ctx context.Context, session sqlx.Session, id string) error {
|
||||
data, err := m.FindOne(ctx, id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
bdqrUserFeatureWhitelistIdCardFeatureApiIdDelStateKey := fmt.Sprintf("%s%v:%v:%v", cacheBdqrUserFeatureWhitelistIdCardFeatureApiIdDelStatePrefix, data.IdCard, data.FeatureApiId, data.DelState)
|
||||
bdqrUserFeatureWhitelistIdCardFeatureIdDelStateKey := fmt.Sprintf("%s%v:%v:%v", cacheBdqrUserFeatureWhitelistIdCardFeatureIdDelStatePrefix, data.IdCard, data.FeatureId, data.DelState)
|
||||
bdqrUserFeatureWhitelistIdKey := fmt.Sprintf("%s%v", cacheBdqrUserFeatureWhitelistIdPrefix, id)
|
||||
bdqrUserFeatureWhitelistWhitelistOrderIdKey := fmt.Sprintf("%s%v", cacheBdqrUserFeatureWhitelistWhitelistOrderIdPrefix, data.WhitelistOrderId)
|
||||
_, err = m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
||||
query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, id)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, id)
|
||||
}, bdqrUserFeatureWhitelistIdCardFeatureApiIdDelStateKey, bdqrUserFeatureWhitelistIdCardFeatureIdDelStateKey, bdqrUserFeatureWhitelistIdKey, bdqrUserFeatureWhitelistWhitelistOrderIdKey)
|
||||
return err
|
||||
}
|
||||
func (m *defaultUserFeatureWhitelistModel) formatPrimary(primary interface{}) string {
|
||||
return fmt.Sprintf("%s%v", cacheBdqrUserFeatureWhitelistIdPrefix, primary)
|
||||
}
|
||||
func (m *defaultUserFeatureWhitelistModel) queryPrimary(ctx context.Context, conn sqlx.SqlConn, v, primary interface{}) error {
|
||||
query := fmt.Sprintf("select %s from %s where `id` = ? and del_state = ? limit 1", userFeatureWhitelistRows, m.table)
|
||||
return conn.QueryRowCtx(ctx, v, query, primary, globalkey.DelStateNo)
|
||||
}
|
||||
|
||||
func (m *defaultUserFeatureWhitelistModel) tableName() string {
|
||||
return m.table
|
||||
}
|
||||
27
app/main/model/whitelistOrderItemModel.go
Normal file
27
app/main/model/whitelistOrderItemModel.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"github.com/zeromicro/go-zero/core/stores/cache"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
)
|
||||
|
||||
var _ WhitelistOrderItemModel = (*customWhitelistOrderItemModel)(nil)
|
||||
|
||||
type (
|
||||
// WhitelistOrderItemModel is an interface to be customized, add more methods here,
|
||||
// and implement the added methods in customWhitelistOrderItemModel.
|
||||
WhitelistOrderItemModel interface {
|
||||
whitelistOrderItemModel
|
||||
}
|
||||
|
||||
customWhitelistOrderItemModel struct {
|
||||
*defaultWhitelistOrderItemModel
|
||||
}
|
||||
)
|
||||
|
||||
// NewWhitelistOrderItemModel returns a model for the database table.
|
||||
func NewWhitelistOrderItemModel(conn sqlx.SqlConn, c cache.CacheConf) WhitelistOrderItemModel {
|
||||
return &customWhitelistOrderItemModel{
|
||||
defaultWhitelistOrderItemModel: newWhitelistOrderItemModel(conn, c),
|
||||
}
|
||||
}
|
||||
390
app/main/model/whitelistOrderItemModel_gen.go
Normal file
390
app/main/model/whitelistOrderItemModel_gen.go
Normal file
@@ -0,0 +1,390 @@
|
||||
// Code generated by goctl. DO NOT EDIT!
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"reflect"
|
||||
"time"
|
||||
|
||||
"bdqr-server/common/globalkey"
|
||||
"github.com/Masterminds/squirrel"
|
||||
"github.com/google/uuid"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/zeromicro/go-zero/core/stores/builder"
|
||||
"github.com/zeromicro/go-zero/core/stores/cache"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlc"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
"github.com/zeromicro/go-zero/core/stringx"
|
||||
)
|
||||
|
||||
var (
|
||||
whitelistOrderItemFieldNames = builder.RawFieldNames(&WhitelistOrderItem{})
|
||||
whitelistOrderItemRows = strings.Join(whitelistOrderItemFieldNames, ",")
|
||||
whitelistOrderItemRowsExpectAutoSet = strings.Join(stringx.Remove(whitelistOrderItemFieldNames, "`create_time`", "`update_time`"), ",")
|
||||
whitelistOrderItemRowsWithPlaceHolder = strings.Join(stringx.Remove(whitelistOrderItemFieldNames, "`id`", "`create_time`", "`update_time`"), "=?,") + "=?"
|
||||
|
||||
cacheBdqrWhitelistOrderItemIdPrefix = "cache:bdqr:whitelistOrderItem:id:"
|
||||
)
|
||||
|
||||
type (
|
||||
whitelistOrderItemModel interface {
|
||||
Insert(ctx context.Context, session sqlx.Session, data *WhitelistOrderItem) (sql.Result, error)
|
||||
FindOne(ctx context.Context, id string) (*WhitelistOrderItem, error)
|
||||
Update(ctx context.Context, session sqlx.Session, data *WhitelistOrderItem) (sql.Result, error)
|
||||
UpdateWithVersion(ctx context.Context, session sqlx.Session, data *WhitelistOrderItem) error
|
||||
Trans(ctx context.Context, fn func(context context.Context, session sqlx.Session) error) error
|
||||
SelectBuilder() squirrel.SelectBuilder
|
||||
DeleteSoft(ctx context.Context, session sqlx.Session, data *WhitelistOrderItem) error
|
||||
FindSum(ctx context.Context, sumBuilder squirrel.SelectBuilder, field string) (float64, error)
|
||||
FindCount(ctx context.Context, countBuilder squirrel.SelectBuilder, field string) (int64, error)
|
||||
FindAll(ctx context.Context, rowBuilder squirrel.SelectBuilder, orderBy string) ([]*WhitelistOrderItem, error)
|
||||
FindPageListByPage(ctx context.Context, rowBuilder squirrel.SelectBuilder, page, pageSize int64, orderBy string) ([]*WhitelistOrderItem, error)
|
||||
FindPageListByPageWithTotal(ctx context.Context, rowBuilder squirrel.SelectBuilder, page, pageSize int64, orderBy string) ([]*WhitelistOrderItem, int64, error)
|
||||
FindPageListByIdDESC(ctx context.Context, rowBuilder squirrel.SelectBuilder, preMinId, pageSize int64) ([]*WhitelistOrderItem, error)
|
||||
FindPageListByIdASC(ctx context.Context, rowBuilder squirrel.SelectBuilder, preMaxId, pageSize int64) ([]*WhitelistOrderItem, error)
|
||||
Delete(ctx context.Context, session sqlx.Session, id string) error
|
||||
}
|
||||
|
||||
defaultWhitelistOrderItemModel struct {
|
||||
sqlc.CachedConn
|
||||
table string
|
||||
}
|
||||
|
||||
WhitelistOrderItem struct {
|
||||
Id string `db:"id"` // UUID主键
|
||||
CreateTime time.Time `db:"create_time"` // 创建时间
|
||||
UpdateTime time.Time `db:"update_time"` // 更新时间
|
||||
DeleteTime sql.NullTime `db:"delete_time"` // 删除时间
|
||||
DelState int64 `db:"del_state"` // 删除状态:0=未删除,1=已删除
|
||||
Version int64 `db:"version"` // 版本号(乐观锁)
|
||||
OrderId string `db:"order_id"` // 订单ID(关联whitelist_order.id)
|
||||
FeatureId string `db:"feature_id"` // Feature的UUID
|
||||
FeatureApiId string `db:"feature_api_id"` // Feature的API标识(冗余)
|
||||
FeatureName string `db:"feature_name"` // Feature的名称(冗余)
|
||||
Price float64 `db:"price"` // 单价(单位:元)
|
||||
}
|
||||
)
|
||||
|
||||
func newWhitelistOrderItemModel(conn sqlx.SqlConn, c cache.CacheConf) *defaultWhitelistOrderItemModel {
|
||||
return &defaultWhitelistOrderItemModel{
|
||||
CachedConn: sqlc.NewConn(conn, c),
|
||||
table: "`whitelist_order_item`",
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultWhitelistOrderItemModel) Insert(ctx context.Context, session sqlx.Session, data *WhitelistOrderItem) (sql.Result, error) {
|
||||
data.DelState = globalkey.DelStateNo
|
||||
m.insertUUID(data)
|
||||
bdqrWhitelistOrderItemIdKey := fmt.Sprintf("%s%v", cacheBdqrWhitelistOrderItemIdPrefix, data.Id)
|
||||
return m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
||||
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, whitelistOrderItemRowsExpectAutoSet)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, data.Id, data.DeleteTime, data.DelState, data.Version, data.OrderId, data.FeatureId, data.FeatureApiId, data.FeatureName, data.Price)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, data.Id, data.DeleteTime, data.DelState, data.Version, data.OrderId, data.FeatureId, data.FeatureApiId, data.FeatureName, data.Price)
|
||||
}, bdqrWhitelistOrderItemIdKey)
|
||||
}
|
||||
func (m *defaultWhitelistOrderItemModel) insertUUID(data *WhitelistOrderItem) {
|
||||
t := reflect.TypeOf(data).Elem()
|
||||
v := reflect.ValueOf(data).Elem()
|
||||
for i := 0; i < t.NumField(); i++ {
|
||||
sf := t.Field(i)
|
||||
if sf.Tag.Get("db") == "id" {
|
||||
f := v.Field(i)
|
||||
if f.IsValid() && f.CanSet() && f.Kind() == reflect.String {
|
||||
if f.String() == "" {
|
||||
f.SetString(uuid.NewString())
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultWhitelistOrderItemModel) FindOne(ctx context.Context, id string) (*WhitelistOrderItem, error) {
|
||||
bdqrWhitelistOrderItemIdKey := fmt.Sprintf("%s%v", cacheBdqrWhitelistOrderItemIdPrefix, id)
|
||||
var resp WhitelistOrderItem
|
||||
err := m.QueryRowCtx(ctx, &resp, bdqrWhitelistOrderItemIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
|
||||
query := fmt.Sprintf("select %s from %s where `id` = ? and del_state = ? limit 1", whitelistOrderItemRows, m.table)
|
||||
return conn.QueryRowCtx(ctx, v, query, id, globalkey.DelStateNo)
|
||||
})
|
||||
switch err {
|
||||
case nil:
|
||||
return &resp, nil
|
||||
case sqlc.ErrNotFound:
|
||||
return nil, ErrNotFound
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultWhitelistOrderItemModel) Update(ctx context.Context, session sqlx.Session, data *WhitelistOrderItem) (sql.Result, error) {
|
||||
bdqrWhitelistOrderItemIdKey := fmt.Sprintf("%s%v", cacheBdqrWhitelistOrderItemIdPrefix, data.Id)
|
||||
return m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
||||
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, whitelistOrderItemRowsWithPlaceHolder)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, data.DeleteTime, data.DelState, data.Version, data.OrderId, data.FeatureId, data.FeatureApiId, data.FeatureName, data.Price, data.Id)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, data.DeleteTime, data.DelState, data.Version, data.OrderId, data.FeatureId, data.FeatureApiId, data.FeatureName, data.Price, data.Id)
|
||||
}, bdqrWhitelistOrderItemIdKey)
|
||||
}
|
||||
|
||||
func (m *defaultWhitelistOrderItemModel) UpdateWithVersion(ctx context.Context, session sqlx.Session, data *WhitelistOrderItem) error {
|
||||
|
||||
oldVersion := data.Version
|
||||
data.Version += 1
|
||||
|
||||
var sqlResult sql.Result
|
||||
var err error
|
||||
|
||||
bdqrWhitelistOrderItemIdKey := fmt.Sprintf("%s%v", cacheBdqrWhitelistOrderItemIdPrefix, data.Id)
|
||||
sqlResult, err = m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
||||
query := fmt.Sprintf("update %s set %s where `id` = ? and version = ? ", m.table, whitelistOrderItemRowsWithPlaceHolder)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, data.DeleteTime, data.DelState, data.Version, data.OrderId, data.FeatureId, data.FeatureApiId, data.FeatureName, data.Price, data.Id, oldVersion)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, data.DeleteTime, data.DelState, data.Version, data.OrderId, data.FeatureId, data.FeatureApiId, data.FeatureName, data.Price, data.Id, oldVersion)
|
||||
}, bdqrWhitelistOrderItemIdKey)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
updateCount, err := sqlResult.RowsAffected()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if updateCount == 0 {
|
||||
return ErrNoRowsUpdate
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *defaultWhitelistOrderItemModel) DeleteSoft(ctx context.Context, session sqlx.Session, data *WhitelistOrderItem) error {
|
||||
data.DelState = globalkey.DelStateYes
|
||||
data.DeleteTime = sql.NullTime{Time: time.Now(), Valid: true}
|
||||
if err := m.UpdateWithVersion(ctx, session, data); err != nil {
|
||||
return errors.Wrapf(errors.New("delete soft failed "), "WhitelistOrderItemModel delete err : %+v", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *defaultWhitelistOrderItemModel) FindSum(ctx context.Context, builder squirrel.SelectBuilder, field string) (float64, error) {
|
||||
|
||||
if len(field) == 0 {
|
||||
return 0, errors.Wrapf(errors.New("FindSum Least One Field"), "FindSum Least One Field")
|
||||
}
|
||||
|
||||
builder = builder.Columns("IFNULL(SUM(" + field + "),0)")
|
||||
|
||||
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).ToSql()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
var resp float64
|
||||
err = m.QueryRowNoCacheCtx(ctx, &resp, query, values...)
|
||||
switch err {
|
||||
case nil:
|
||||
return resp, nil
|
||||
default:
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultWhitelistOrderItemModel) FindCount(ctx context.Context, builder squirrel.SelectBuilder, field string) (int64, error) {
|
||||
|
||||
if len(field) == 0 {
|
||||
return 0, errors.Wrapf(errors.New("FindCount Least One Field"), "FindCount Least One Field")
|
||||
}
|
||||
|
||||
builder = builder.Columns("COUNT(" + field + ")")
|
||||
|
||||
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).ToSql()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
var resp int64
|
||||
err = m.QueryRowNoCacheCtx(ctx, &resp, query, values...)
|
||||
switch err {
|
||||
case nil:
|
||||
return resp, nil
|
||||
default:
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultWhitelistOrderItemModel) FindAll(ctx context.Context, builder squirrel.SelectBuilder, orderBy string) ([]*WhitelistOrderItem, error) {
|
||||
|
||||
builder = builder.Columns(whitelistOrderItemRows)
|
||||
|
||||
if orderBy == "" {
|
||||
builder = builder.OrderBy("id DESC")
|
||||
} else {
|
||||
builder = builder.OrderBy(orderBy)
|
||||
}
|
||||
|
||||
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).ToSql()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var resp []*WhitelistOrderItem
|
||||
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
||||
switch err {
|
||||
case nil:
|
||||
return resp, nil
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultWhitelistOrderItemModel) FindPageListByPage(ctx context.Context, builder squirrel.SelectBuilder, page, pageSize int64, orderBy string) ([]*WhitelistOrderItem, error) {
|
||||
|
||||
builder = builder.Columns(whitelistOrderItemRows)
|
||||
|
||||
if orderBy == "" {
|
||||
builder = builder.OrderBy("id DESC")
|
||||
} else {
|
||||
builder = builder.OrderBy(orderBy)
|
||||
}
|
||||
|
||||
if page < 1 {
|
||||
page = 1
|
||||
}
|
||||
offset := (page - 1) * pageSize
|
||||
|
||||
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).Offset(uint64(offset)).Limit(uint64(pageSize)).ToSql()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var resp []*WhitelistOrderItem
|
||||
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
||||
switch err {
|
||||
case nil:
|
||||
return resp, nil
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultWhitelistOrderItemModel) FindPageListByPageWithTotal(ctx context.Context, builder squirrel.SelectBuilder, page, pageSize int64, orderBy string) ([]*WhitelistOrderItem, int64, error) {
|
||||
|
||||
total, err := m.FindCount(ctx, builder, "id")
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
builder = builder.Columns(whitelistOrderItemRows)
|
||||
|
||||
if orderBy == "" {
|
||||
builder = builder.OrderBy("id DESC")
|
||||
} else {
|
||||
builder = builder.OrderBy(orderBy)
|
||||
}
|
||||
|
||||
if page < 1 {
|
||||
page = 1
|
||||
}
|
||||
offset := (page - 1) * pageSize
|
||||
|
||||
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).Offset(uint64(offset)).Limit(uint64(pageSize)).ToSql()
|
||||
if err != nil {
|
||||
return nil, total, err
|
||||
}
|
||||
|
||||
var resp []*WhitelistOrderItem
|
||||
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
||||
switch err {
|
||||
case nil:
|
||||
return resp, total, nil
|
||||
default:
|
||||
return nil, total, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultWhitelistOrderItemModel) FindPageListByIdDESC(ctx context.Context, builder squirrel.SelectBuilder, preMinId, pageSize int64) ([]*WhitelistOrderItem, error) {
|
||||
|
||||
builder = builder.Columns(whitelistOrderItemRows)
|
||||
|
||||
if preMinId > 0 {
|
||||
builder = builder.Where(" id < ? ", preMinId)
|
||||
}
|
||||
|
||||
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).OrderBy("id DESC").Limit(uint64(pageSize)).ToSql()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var resp []*WhitelistOrderItem
|
||||
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
||||
switch err {
|
||||
case nil:
|
||||
return resp, nil
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultWhitelistOrderItemModel) FindPageListByIdASC(ctx context.Context, builder squirrel.SelectBuilder, preMaxId, pageSize int64) ([]*WhitelistOrderItem, error) {
|
||||
|
||||
builder = builder.Columns(whitelistOrderItemRows)
|
||||
|
||||
if preMaxId > 0 {
|
||||
builder = builder.Where(" id > ? ", preMaxId)
|
||||
}
|
||||
|
||||
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).OrderBy("id ASC").Limit(uint64(pageSize)).ToSql()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var resp []*WhitelistOrderItem
|
||||
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
||||
switch err {
|
||||
case nil:
|
||||
return resp, nil
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultWhitelistOrderItemModel) Trans(ctx context.Context, fn func(ctx context.Context, session sqlx.Session) error) error {
|
||||
|
||||
return m.TransactCtx(ctx, func(ctx context.Context, session sqlx.Session) error {
|
||||
return fn(ctx, session)
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
func (m *defaultWhitelistOrderItemModel) SelectBuilder() squirrel.SelectBuilder {
|
||||
return squirrel.Select().From(m.table)
|
||||
}
|
||||
func (m *defaultWhitelistOrderItemModel) Delete(ctx context.Context, session sqlx.Session, id string) error {
|
||||
bdqrWhitelistOrderItemIdKey := fmt.Sprintf("%s%v", cacheBdqrWhitelistOrderItemIdPrefix, id)
|
||||
_, err := m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
||||
query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, id)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, id)
|
||||
}, bdqrWhitelistOrderItemIdKey)
|
||||
return err
|
||||
}
|
||||
func (m *defaultWhitelistOrderItemModel) formatPrimary(primary interface{}) string {
|
||||
return fmt.Sprintf("%s%v", cacheBdqrWhitelistOrderItemIdPrefix, primary)
|
||||
}
|
||||
func (m *defaultWhitelistOrderItemModel) queryPrimary(ctx context.Context, conn sqlx.SqlConn, v, primary interface{}) error {
|
||||
query := fmt.Sprintf("select %s from %s where `id` = ? and del_state = ? limit 1", whitelistOrderItemRows, m.table)
|
||||
return conn.QueryRowCtx(ctx, v, query, primary, globalkey.DelStateNo)
|
||||
}
|
||||
|
||||
func (m *defaultWhitelistOrderItemModel) tableName() string {
|
||||
return m.table
|
||||
}
|
||||
27
app/main/model/whitelistOrderModel.go
Normal file
27
app/main/model/whitelistOrderModel.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"github.com/zeromicro/go-zero/core/stores/cache"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
)
|
||||
|
||||
var _ WhitelistOrderModel = (*customWhitelistOrderModel)(nil)
|
||||
|
||||
type (
|
||||
// WhitelistOrderModel is an interface to be customized, add more methods here,
|
||||
// and implement the added methods in customWhitelistOrderModel.
|
||||
WhitelistOrderModel interface {
|
||||
whitelistOrderModel
|
||||
}
|
||||
|
||||
customWhitelistOrderModel struct {
|
||||
*defaultWhitelistOrderModel
|
||||
}
|
||||
)
|
||||
|
||||
// NewWhitelistOrderModel returns a model for the database table.
|
||||
func NewWhitelistOrderModel(conn sqlx.SqlConn, c cache.CacheConf) WhitelistOrderModel {
|
||||
return &customWhitelistOrderModel{
|
||||
defaultWhitelistOrderModel: newWhitelistOrderModel(conn, c),
|
||||
}
|
||||
}
|
||||
433
app/main/model/whitelistOrderModel_gen.go
Normal file
433
app/main/model/whitelistOrderModel_gen.go
Normal file
@@ -0,0 +1,433 @@
|
||||
// Code generated by goctl. DO NOT EDIT!
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"reflect"
|
||||
"time"
|
||||
|
||||
"bdqr-server/common/globalkey"
|
||||
"github.com/Masterminds/squirrel"
|
||||
"github.com/google/uuid"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/zeromicro/go-zero/core/stores/builder"
|
||||
"github.com/zeromicro/go-zero/core/stores/cache"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlc"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
"github.com/zeromicro/go-zero/core/stringx"
|
||||
)
|
||||
|
||||
var (
|
||||
whitelistOrderFieldNames = builder.RawFieldNames(&WhitelistOrder{})
|
||||
whitelistOrderRows = strings.Join(whitelistOrderFieldNames, ",")
|
||||
whitelistOrderRowsExpectAutoSet = strings.Join(stringx.Remove(whitelistOrderFieldNames, "`create_time`", "`update_time`"), ",")
|
||||
whitelistOrderRowsWithPlaceHolder = strings.Join(stringx.Remove(whitelistOrderFieldNames, "`id`", "`create_time`", "`update_time`"), "=?,") + "=?"
|
||||
|
||||
cacheBdqrWhitelistOrderIdPrefix = "cache:bdqr:whitelistOrder:id:"
|
||||
cacheBdqrWhitelistOrderOrderNoPrefix = "cache:bdqr:whitelistOrder:orderNo:"
|
||||
)
|
||||
|
||||
type (
|
||||
whitelistOrderModel interface {
|
||||
Insert(ctx context.Context, session sqlx.Session, data *WhitelistOrder) (sql.Result, error)
|
||||
FindOne(ctx context.Context, id string) (*WhitelistOrder, error)
|
||||
FindOneByOrderNo(ctx context.Context, orderNo string) (*WhitelistOrder, error)
|
||||
Update(ctx context.Context, session sqlx.Session, data *WhitelistOrder) (sql.Result, error)
|
||||
UpdateWithVersion(ctx context.Context, session sqlx.Session, data *WhitelistOrder) error
|
||||
Trans(ctx context.Context, fn func(context context.Context, session sqlx.Session) error) error
|
||||
SelectBuilder() squirrel.SelectBuilder
|
||||
DeleteSoft(ctx context.Context, session sqlx.Session, data *WhitelistOrder) error
|
||||
FindSum(ctx context.Context, sumBuilder squirrel.SelectBuilder, field string) (float64, error)
|
||||
FindCount(ctx context.Context, countBuilder squirrel.SelectBuilder, field string) (int64, error)
|
||||
FindAll(ctx context.Context, rowBuilder squirrel.SelectBuilder, orderBy string) ([]*WhitelistOrder, error)
|
||||
FindPageListByPage(ctx context.Context, rowBuilder squirrel.SelectBuilder, page, pageSize int64, orderBy string) ([]*WhitelistOrder, error)
|
||||
FindPageListByPageWithTotal(ctx context.Context, rowBuilder squirrel.SelectBuilder, page, pageSize int64, orderBy string) ([]*WhitelistOrder, int64, error)
|
||||
FindPageListByIdDESC(ctx context.Context, rowBuilder squirrel.SelectBuilder, preMinId, pageSize int64) ([]*WhitelistOrder, error)
|
||||
FindPageListByIdASC(ctx context.Context, rowBuilder squirrel.SelectBuilder, preMaxId, pageSize int64) ([]*WhitelistOrder, error)
|
||||
Delete(ctx context.Context, session sqlx.Session, id string) error
|
||||
}
|
||||
|
||||
defaultWhitelistOrderModel struct {
|
||||
sqlc.CachedConn
|
||||
table string
|
||||
}
|
||||
|
||||
WhitelistOrder struct {
|
||||
Id string `db:"id"` // UUID主键
|
||||
CreateTime time.Time `db:"create_time"` // 创建时间
|
||||
UpdateTime time.Time `db:"update_time"` // 更新时间
|
||||
DeleteTime sql.NullTime `db:"delete_time"` // 删除时间
|
||||
DelState int64 `db:"del_state"` // 删除状态:0=未删除,1=已删除
|
||||
Version int64 `db:"version"` // 版本号(乐观锁)
|
||||
OrderNo string `db:"order_no"` // 订单号(唯一)
|
||||
UserId string `db:"user_id"` // 用户ID(代理的user_id)
|
||||
IdCard string `db:"id_card"` // 身份证号(查询对象标识)
|
||||
TotalAmount float64 `db:"total_amount"` // 总金额(单位:元)
|
||||
Status int64 `db:"status"` // 订单状态:1=待支付,2=已支付,3=已取消
|
||||
PaymentMethod sql.NullString `db:"payment_method"` // 支付方式:wechat, alipay, appleiap等
|
||||
PaymentPlatform sql.NullString `db:"payment_platform"` // 支付平台:alipay, wechat, appleiap等
|
||||
PlatformOrderId sql.NullString `db:"platform_order_id"` // 支付平台订单号(第三方平台的订单号)
|
||||
PayTime sql.NullTime `db:"pay_time"` // 支付时间
|
||||
}
|
||||
)
|
||||
|
||||
func newWhitelistOrderModel(conn sqlx.SqlConn, c cache.CacheConf) *defaultWhitelistOrderModel {
|
||||
return &defaultWhitelistOrderModel{
|
||||
CachedConn: sqlc.NewConn(conn, c),
|
||||
table: "`whitelist_order`",
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultWhitelistOrderModel) Insert(ctx context.Context, session sqlx.Session, data *WhitelistOrder) (sql.Result, error) {
|
||||
data.DelState = globalkey.DelStateNo
|
||||
m.insertUUID(data)
|
||||
bdqrWhitelistOrderIdKey := fmt.Sprintf("%s%v", cacheBdqrWhitelistOrderIdPrefix, data.Id)
|
||||
bdqrWhitelistOrderOrderNoKey := fmt.Sprintf("%s%v", cacheBdqrWhitelistOrderOrderNoPrefix, data.OrderNo)
|
||||
return m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
||||
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, whitelistOrderRowsExpectAutoSet)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, data.Id, data.DeleteTime, data.DelState, data.Version, data.OrderNo, data.UserId, data.IdCard, data.TotalAmount, data.Status, data.PaymentMethod, data.PaymentPlatform, data.PlatformOrderId, data.PayTime)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, data.Id, data.DeleteTime, data.DelState, data.Version, data.OrderNo, data.UserId, data.IdCard, data.TotalAmount, data.Status, data.PaymentMethod, data.PaymentPlatform, data.PlatformOrderId, data.PayTime)
|
||||
}, bdqrWhitelistOrderIdKey, bdqrWhitelistOrderOrderNoKey)
|
||||
}
|
||||
func (m *defaultWhitelistOrderModel) insertUUID(data *WhitelistOrder) {
|
||||
t := reflect.TypeOf(data).Elem()
|
||||
v := reflect.ValueOf(data).Elem()
|
||||
for i := 0; i < t.NumField(); i++ {
|
||||
sf := t.Field(i)
|
||||
if sf.Tag.Get("db") == "id" {
|
||||
f := v.Field(i)
|
||||
if f.IsValid() && f.CanSet() && f.Kind() == reflect.String {
|
||||
if f.String() == "" {
|
||||
f.SetString(uuid.NewString())
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultWhitelistOrderModel) FindOne(ctx context.Context, id string) (*WhitelistOrder, error) {
|
||||
bdqrWhitelistOrderIdKey := fmt.Sprintf("%s%v", cacheBdqrWhitelistOrderIdPrefix, id)
|
||||
var resp WhitelistOrder
|
||||
err := m.QueryRowCtx(ctx, &resp, bdqrWhitelistOrderIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
|
||||
query := fmt.Sprintf("select %s from %s where `id` = ? and del_state = ? limit 1", whitelistOrderRows, m.table)
|
||||
return conn.QueryRowCtx(ctx, v, query, id, globalkey.DelStateNo)
|
||||
})
|
||||
switch err {
|
||||
case nil:
|
||||
return &resp, nil
|
||||
case sqlc.ErrNotFound:
|
||||
return nil, ErrNotFound
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultWhitelistOrderModel) FindOneByOrderNo(ctx context.Context, orderNo string) (*WhitelistOrder, error) {
|
||||
bdqrWhitelistOrderOrderNoKey := fmt.Sprintf("%s%v", cacheBdqrWhitelistOrderOrderNoPrefix, orderNo)
|
||||
var resp WhitelistOrder
|
||||
err := m.QueryRowIndexCtx(ctx, &resp, bdqrWhitelistOrderOrderNoKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) (i interface{}, e error) {
|
||||
query := fmt.Sprintf("select %s from %s where `order_no` = ? and del_state = ? limit 1", whitelistOrderRows, m.table)
|
||||
if err := conn.QueryRowCtx(ctx, &resp, query, orderNo, globalkey.DelStateNo); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return resp.Id, nil
|
||||
}, m.queryPrimary)
|
||||
switch err {
|
||||
case nil:
|
||||
return &resp, nil
|
||||
case sqlc.ErrNotFound:
|
||||
return nil, ErrNotFound
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultWhitelistOrderModel) Update(ctx context.Context, session sqlx.Session, newData *WhitelistOrder) (sql.Result, error) {
|
||||
data, err := m.FindOne(ctx, newData.Id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
bdqrWhitelistOrderIdKey := fmt.Sprintf("%s%v", cacheBdqrWhitelistOrderIdPrefix, data.Id)
|
||||
bdqrWhitelistOrderOrderNoKey := fmt.Sprintf("%s%v", cacheBdqrWhitelistOrderOrderNoPrefix, data.OrderNo)
|
||||
return m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
||||
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, whitelistOrderRowsWithPlaceHolder)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.OrderNo, newData.UserId, newData.IdCard, newData.TotalAmount, newData.Status, newData.PaymentMethod, newData.PaymentPlatform, newData.PlatformOrderId, newData.PayTime, newData.Id)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.OrderNo, newData.UserId, newData.IdCard, newData.TotalAmount, newData.Status, newData.PaymentMethod, newData.PaymentPlatform, newData.PlatformOrderId, newData.PayTime, newData.Id)
|
||||
}, bdqrWhitelistOrderIdKey, bdqrWhitelistOrderOrderNoKey)
|
||||
}
|
||||
|
||||
func (m *defaultWhitelistOrderModel) UpdateWithVersion(ctx context.Context, session sqlx.Session, newData *WhitelistOrder) error {
|
||||
|
||||
oldVersion := newData.Version
|
||||
newData.Version += 1
|
||||
|
||||
var sqlResult sql.Result
|
||||
var err error
|
||||
|
||||
data, err := m.FindOne(ctx, newData.Id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
bdqrWhitelistOrderIdKey := fmt.Sprintf("%s%v", cacheBdqrWhitelistOrderIdPrefix, data.Id)
|
||||
bdqrWhitelistOrderOrderNoKey := fmt.Sprintf("%s%v", cacheBdqrWhitelistOrderOrderNoPrefix, data.OrderNo)
|
||||
sqlResult, err = m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
||||
query := fmt.Sprintf("update %s set %s where `id` = ? and version = ? ", m.table, whitelistOrderRowsWithPlaceHolder)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.OrderNo, newData.UserId, newData.IdCard, newData.TotalAmount, newData.Status, newData.PaymentMethod, newData.PaymentPlatform, newData.PlatformOrderId, newData.PayTime, newData.Id, oldVersion)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.OrderNo, newData.UserId, newData.IdCard, newData.TotalAmount, newData.Status, newData.PaymentMethod, newData.PaymentPlatform, newData.PlatformOrderId, newData.PayTime, newData.Id, oldVersion)
|
||||
}, bdqrWhitelistOrderIdKey, bdqrWhitelistOrderOrderNoKey)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
updateCount, err := sqlResult.RowsAffected()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if updateCount == 0 {
|
||||
return ErrNoRowsUpdate
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *defaultWhitelistOrderModel) DeleteSoft(ctx context.Context, session sqlx.Session, data *WhitelistOrder) error {
|
||||
data.DelState = globalkey.DelStateYes
|
||||
data.DeleteTime = sql.NullTime{Time: time.Now(), Valid: true}
|
||||
if err := m.UpdateWithVersion(ctx, session, data); err != nil {
|
||||
return errors.Wrapf(errors.New("delete soft failed "), "WhitelistOrderModel delete err : %+v", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *defaultWhitelistOrderModel) FindSum(ctx context.Context, builder squirrel.SelectBuilder, field string) (float64, error) {
|
||||
|
||||
if len(field) == 0 {
|
||||
return 0, errors.Wrapf(errors.New("FindSum Least One Field"), "FindSum Least One Field")
|
||||
}
|
||||
|
||||
builder = builder.Columns("IFNULL(SUM(" + field + "),0)")
|
||||
|
||||
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).ToSql()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
var resp float64
|
||||
err = m.QueryRowNoCacheCtx(ctx, &resp, query, values...)
|
||||
switch err {
|
||||
case nil:
|
||||
return resp, nil
|
||||
default:
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultWhitelistOrderModel) FindCount(ctx context.Context, builder squirrel.SelectBuilder, field string) (int64, error) {
|
||||
|
||||
if len(field) == 0 {
|
||||
return 0, errors.Wrapf(errors.New("FindCount Least One Field"), "FindCount Least One Field")
|
||||
}
|
||||
|
||||
builder = builder.Columns("COUNT(" + field + ")")
|
||||
|
||||
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).ToSql()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
var resp int64
|
||||
err = m.QueryRowNoCacheCtx(ctx, &resp, query, values...)
|
||||
switch err {
|
||||
case nil:
|
||||
return resp, nil
|
||||
default:
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultWhitelistOrderModel) FindAll(ctx context.Context, builder squirrel.SelectBuilder, orderBy string) ([]*WhitelistOrder, error) {
|
||||
|
||||
builder = builder.Columns(whitelistOrderRows)
|
||||
|
||||
if orderBy == "" {
|
||||
builder = builder.OrderBy("id DESC")
|
||||
} else {
|
||||
builder = builder.OrderBy(orderBy)
|
||||
}
|
||||
|
||||
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).ToSql()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var resp []*WhitelistOrder
|
||||
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
||||
switch err {
|
||||
case nil:
|
||||
return resp, nil
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultWhitelistOrderModel) FindPageListByPage(ctx context.Context, builder squirrel.SelectBuilder, page, pageSize int64, orderBy string) ([]*WhitelistOrder, error) {
|
||||
|
||||
builder = builder.Columns(whitelistOrderRows)
|
||||
|
||||
if orderBy == "" {
|
||||
builder = builder.OrderBy("id DESC")
|
||||
} else {
|
||||
builder = builder.OrderBy(orderBy)
|
||||
}
|
||||
|
||||
if page < 1 {
|
||||
page = 1
|
||||
}
|
||||
offset := (page - 1) * pageSize
|
||||
|
||||
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).Offset(uint64(offset)).Limit(uint64(pageSize)).ToSql()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var resp []*WhitelistOrder
|
||||
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
||||
switch err {
|
||||
case nil:
|
||||
return resp, nil
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultWhitelistOrderModel) FindPageListByPageWithTotal(ctx context.Context, builder squirrel.SelectBuilder, page, pageSize int64, orderBy string) ([]*WhitelistOrder, int64, error) {
|
||||
|
||||
total, err := m.FindCount(ctx, builder, "id")
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
builder = builder.Columns(whitelistOrderRows)
|
||||
|
||||
if orderBy == "" {
|
||||
builder = builder.OrderBy("id DESC")
|
||||
} else {
|
||||
builder = builder.OrderBy(orderBy)
|
||||
}
|
||||
|
||||
if page < 1 {
|
||||
page = 1
|
||||
}
|
||||
offset := (page - 1) * pageSize
|
||||
|
||||
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).Offset(uint64(offset)).Limit(uint64(pageSize)).ToSql()
|
||||
if err != nil {
|
||||
return nil, total, err
|
||||
}
|
||||
|
||||
var resp []*WhitelistOrder
|
||||
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
||||
switch err {
|
||||
case nil:
|
||||
return resp, total, nil
|
||||
default:
|
||||
return nil, total, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultWhitelistOrderModel) FindPageListByIdDESC(ctx context.Context, builder squirrel.SelectBuilder, preMinId, pageSize int64) ([]*WhitelistOrder, error) {
|
||||
|
||||
builder = builder.Columns(whitelistOrderRows)
|
||||
|
||||
if preMinId > 0 {
|
||||
builder = builder.Where(" id < ? ", preMinId)
|
||||
}
|
||||
|
||||
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).OrderBy("id DESC").Limit(uint64(pageSize)).ToSql()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var resp []*WhitelistOrder
|
||||
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
||||
switch err {
|
||||
case nil:
|
||||
return resp, nil
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultWhitelistOrderModel) FindPageListByIdASC(ctx context.Context, builder squirrel.SelectBuilder, preMaxId, pageSize int64) ([]*WhitelistOrder, error) {
|
||||
|
||||
builder = builder.Columns(whitelistOrderRows)
|
||||
|
||||
if preMaxId > 0 {
|
||||
builder = builder.Where(" id > ? ", preMaxId)
|
||||
}
|
||||
|
||||
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).OrderBy("id ASC").Limit(uint64(pageSize)).ToSql()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var resp []*WhitelistOrder
|
||||
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
||||
switch err {
|
||||
case nil:
|
||||
return resp, nil
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultWhitelistOrderModel) Trans(ctx context.Context, fn func(ctx context.Context, session sqlx.Session) error) error {
|
||||
|
||||
return m.TransactCtx(ctx, func(ctx context.Context, session sqlx.Session) error {
|
||||
return fn(ctx, session)
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
func (m *defaultWhitelistOrderModel) SelectBuilder() squirrel.SelectBuilder {
|
||||
return squirrel.Select().From(m.table)
|
||||
}
|
||||
func (m *defaultWhitelistOrderModel) Delete(ctx context.Context, session sqlx.Session, id string) error {
|
||||
data, err := m.FindOne(ctx, id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
bdqrWhitelistOrderIdKey := fmt.Sprintf("%s%v", cacheBdqrWhitelistOrderIdPrefix, id)
|
||||
bdqrWhitelistOrderOrderNoKey := fmt.Sprintf("%s%v", cacheBdqrWhitelistOrderOrderNoPrefix, data.OrderNo)
|
||||
_, err = m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
||||
query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, id)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, id)
|
||||
}, bdqrWhitelistOrderIdKey, bdqrWhitelistOrderOrderNoKey)
|
||||
return err
|
||||
}
|
||||
func (m *defaultWhitelistOrderModel) formatPrimary(primary interface{}) string {
|
||||
return fmt.Sprintf("%s%v", cacheBdqrWhitelistOrderIdPrefix, primary)
|
||||
}
|
||||
func (m *defaultWhitelistOrderModel) queryPrimary(ctx context.Context, conn sqlx.SqlConn, v, primary interface{}) error {
|
||||
query := fmt.Sprintf("select %s from %s where `id` = ? and del_state = ? limit 1", whitelistOrderRows, m.table)
|
||||
return conn.QueryRowCtx(ctx, v, query, primary, globalkey.DelStateNo)
|
||||
}
|
||||
|
||||
func (m *defaultWhitelistOrderModel) tableName() string {
|
||||
return m.table
|
||||
}
|
||||
Reference in New Issue
Block a user