f
This commit is contained in:
@@ -45,8 +45,10 @@ service main {
|
|||||||
type (
|
type (
|
||||||
// 创建功能请求
|
// 创建功能请求
|
||||||
AdminCreateFeatureReq {
|
AdminCreateFeatureReq {
|
||||||
ApiId string `json:"api_id"` // API标识
|
ApiId string `json:"api_id"` // API标识
|
||||||
Name string `json:"name"` // 描述
|
Name string `json:"name"` // 描述
|
||||||
|
WhitelistPrice *float64 `json:"whitelist_price,optional"` // 白名单屏蔽价格(单位:元)
|
||||||
|
CostPrice *float64 `json:"cost_price,optional"` // 天远API调用成本价(单位:元)
|
||||||
}
|
}
|
||||||
// 创建功能响应
|
// 创建功能响应
|
||||||
AdminCreateFeatureResp {
|
AdminCreateFeatureResp {
|
||||||
@@ -54,9 +56,11 @@ type (
|
|||||||
}
|
}
|
||||||
// 更新功能请求
|
// 更新功能请求
|
||||||
AdminUpdateFeatureReq {
|
AdminUpdateFeatureReq {
|
||||||
Id string `path:"id"` // 功能ID
|
Id string `path:"id"` // 功能ID
|
||||||
ApiId *string `json:"api_id,optional"` // API标识
|
ApiId *string `json:"api_id,optional"` // API标识
|
||||||
Name *string `json:"name,optional"` // 描述
|
Name *string `json:"name,optional"` // 描述
|
||||||
|
WhitelistPrice *float64 `json:"whitelist_price,optional"` // 白名单屏蔽价格(单位:元)
|
||||||
|
CostPrice *float64 `json:"cost_price,optional"` // 天远API调用成本价(单位:元)
|
||||||
}
|
}
|
||||||
// 更新功能响应
|
// 更新功能响应
|
||||||
AdminUpdateFeatureResp {
|
AdminUpdateFeatureResp {
|
||||||
@@ -79,11 +83,13 @@ type (
|
|||||||
}
|
}
|
||||||
// 功能列表项
|
// 功能列表项
|
||||||
FeatureListItem {
|
FeatureListItem {
|
||||||
Id string `json:"id"` // 功能ID
|
Id string `json:"id"` // 功能ID
|
||||||
ApiId string `json:"api_id"` // API标识
|
ApiId string `json:"api_id"` // API标识
|
||||||
Name string `json:"name"` // 描述
|
Name string `json:"name"` // 描述
|
||||||
CreateTime string `json:"create_time"` // 创建时间
|
WhitelistPrice float64 `json:"whitelist_price"` // 白名单屏蔽价格(单位:元)
|
||||||
UpdateTime string `json:"update_time"` // 更新时间
|
CostPrice float64 `json:"cost_price"` // 天远API调用成本价(单位:元)
|
||||||
|
CreateTime string `json:"create_time"` // 创建时间
|
||||||
|
UpdateTime string `json:"update_time"` // 更新时间
|
||||||
}
|
}
|
||||||
// 获取功能列表响应
|
// 获取功能列表响应
|
||||||
AdminGetFeatureListResp {
|
AdminGetFeatureListResp {
|
||||||
@@ -96,11 +102,13 @@ type (
|
|||||||
}
|
}
|
||||||
// 获取功能详情响应
|
// 获取功能详情响应
|
||||||
AdminGetFeatureDetailResp {
|
AdminGetFeatureDetailResp {
|
||||||
Id string `json:"id"` // 功能ID
|
Id string `json:"id"` // 功能ID
|
||||||
ApiId string `json:"api_id"` // API标识
|
ApiId string `json:"api_id"` // API标识
|
||||||
Name string `json:"name"` // 描述
|
Name string `json:"name"` // 描述
|
||||||
CreateTime string `json:"create_time"` // 创建时间
|
WhitelistPrice float64 `json:"whitelist_price"` // 白名单屏蔽价格(单位:元)
|
||||||
UpdateTime string `json:"update_time"` // 更新时间
|
CostPrice float64 `json:"cost_price"` // 天远API调用成本价(单位:元)
|
||||||
|
CreateTime string `json:"create_time"` // 创建时间
|
||||||
|
UpdateTime string `json:"update_time"` // 更新时间
|
||||||
}
|
}
|
||||||
// 配置功能示例数据请求
|
// 配置功能示例数据请求
|
||||||
AdminConfigFeatureExampleReq {
|
AdminConfigFeatureExampleReq {
|
||||||
|
|||||||
93
app/main/api/desc/admin/dashboard.api
Normal file
93
app/main/api/desc/admin/dashboard.api
Normal file
@@ -0,0 +1,93 @@
|
|||||||
|
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
|
@handler GetPromotionQueryList
|
||||||
get /promotion/query/list (GetPromotionQueryListReq) returns (GetPromotionQueryListResp)
|
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 (
|
type (
|
||||||
@@ -587,6 +613,75 @@ type (
|
|||||||
CreateTime string `json:"create_time"` // 创建时间
|
CreateTime string `json:"create_time"` // 创建时间
|
||||||
QueryState string `json:"query_state"` // 查询状态
|
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"` // 报告数据是否已删除
|
||||||
|
}
|
||||||
|
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"` // 是否是当前代理推广的订单
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
// ============================================
|
// ============================================
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ type (
|
|||||||
PaymentReq {
|
PaymentReq {
|
||||||
Id string `json:"id"`
|
Id string `json:"id"`
|
||||||
PayMethod string `json:"pay_method"` // 支付方式: wechat, alipay, appleiap, test(仅开发环境), test_empty(仅开发环境-空报告模式)
|
PayMethod string `json:"pay_method"` // 支付方式: wechat, alipay, appleiap, test(仅开发环境), test_empty(仅开发环境-空报告模式)
|
||||||
PayType string `json:"pay_type" validate:"required,oneof=query agent_vip agent_upgrade"`
|
PayType string `json:"pay_type" validate:"required,oneof=query agent_vip agent_upgrade whitelist"`
|
||||||
}
|
}
|
||||||
PaymentResp {
|
PaymentResp {
|
||||||
PrepayData interface{} `json:"prepay_data"`
|
PrepayData interface{} `json:"prepay_data"`
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import "./admin/platform_user.api"
|
|||||||
import "./admin/notification.api"
|
import "./admin/notification.api"
|
||||||
import "./admin/admin_product.api"
|
import "./admin/admin_product.api"
|
||||||
import "./admin/admin_feature.api"
|
import "./admin/admin_feature.api"
|
||||||
|
import "./admin/dashboard.api"
|
||||||
import "./admin/admin_query.api"
|
import "./admin/admin_query.api"
|
||||||
import "./admin/admin_agent.api"
|
import "./admin/admin_agent.api"
|
||||||
import "./admin/admin_api.api"
|
import "./admin/admin_api.api"
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package admin_dashboard
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"qnc-server/app/main/api/internal/logic/admin_dashboard"
|
||||||
|
"qnc-server/app/main/api/internal/svc"
|
||||||
|
"qnc-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"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
|
"qnc-server/app/main/api/internal/logic/agent"
|
||||||
|
"qnc-server/app/main/api/internal/svc"
|
||||||
|
"qnc-server/app/main/api/internal/types"
|
||||||
|
"qnc-server/common/result"
|
||||||
|
"qnc-server/pkg/lzkit/validator"
|
||||||
|
)
|
||||||
|
|
||||||
|
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"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
|
"qnc-server/app/main/api/internal/logic/agent"
|
||||||
|
"qnc-server/app/main/api/internal/svc"
|
||||||
|
"qnc-server/app/main/api/internal/types"
|
||||||
|
"qnc-server/common/result"
|
||||||
|
"qnc-server/pkg/lzkit/validator"
|
||||||
|
)
|
||||||
|
|
||||||
|
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"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
|
"qnc-server/app/main/api/internal/logic/agent"
|
||||||
|
"qnc-server/app/main/api/internal/svc"
|
||||||
|
"qnc-server/app/main/api/internal/types"
|
||||||
|
"qnc-server/common/result"
|
||||||
|
"qnc-server/pkg/lzkit/validator"
|
||||||
|
)
|
||||||
|
|
||||||
|
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"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
|
"qnc-server/app/main/api/internal/logic/agent"
|
||||||
|
"qnc-server/app/main/api/internal/svc"
|
||||||
|
"qnc-server/app/main/api/internal/types"
|
||||||
|
"qnc-server/common/result"
|
||||||
|
"qnc-server/pkg/lzkit/validator"
|
||||||
|
)
|
||||||
|
|
||||||
|
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"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
|
"qnc-server/app/main/api/internal/logic/agent"
|
||||||
|
"qnc-server/app/main/api/internal/svc"
|
||||||
|
"qnc-server/app/main/api/internal/types"
|
||||||
|
"qnc-server/common/result"
|
||||||
|
"qnc-server/pkg/lzkit/validator"
|
||||||
|
)
|
||||||
|
|
||||||
|
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"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
|
"qnc-server/app/main/api/internal/logic/agent"
|
||||||
|
"qnc-server/app/main/api/internal/svc"
|
||||||
|
"qnc-server/app/main/api/internal/types"
|
||||||
|
"qnc-server/common/result"
|
||||||
|
"qnc-server/pkg/lzkit/validator"
|
||||||
|
)
|
||||||
|
|
||||||
|
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 "qnc-server/app/main/api/internal/handler/admin_agent"
|
admin_agent "qnc-server/app/main/api/internal/handler/admin_agent"
|
||||||
admin_api "qnc-server/app/main/api/internal/handler/admin_api"
|
admin_api "qnc-server/app/main/api/internal/handler/admin_api"
|
||||||
admin_auth "qnc-server/app/main/api/internal/handler/admin_auth"
|
admin_auth "qnc-server/app/main/api/internal/handler/admin_auth"
|
||||||
|
admin_dashboard "qnc-server/app/main/api/internal/handler/admin_dashboard"
|
||||||
admin_feature "qnc-server/app/main/api/internal/handler/admin_feature"
|
admin_feature "qnc-server/app/main/api/internal/handler/admin_feature"
|
||||||
admin_menu "qnc-server/app/main/api/internal/handler/admin_menu"
|
admin_menu "qnc-server/app/main/api/internal/handler/admin_menu"
|
||||||
admin_notification "qnc-server/app/main/api/internal/handler/admin_notification"
|
admin_notification "qnc-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"),
|
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(
|
server.AddRoutes(
|
||||||
rest.WithMiddlewares(
|
rest.WithMiddlewares(
|
||||||
[]rest.Middleware{serverCtx.AdminAuthInterceptor},
|
[]rest.Middleware{serverCtx.AdminAuthInterceptor},
|
||||||
@@ -666,6 +681,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
|||||||
Path: "/level/privilege",
|
Path: "/level/privilege",
|
||||||
Handler: agent.GetLevelPrivilegeHandler(serverCtx),
|
Handler: agent.GetLevelPrivilegeHandler(serverCtx),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Method: http.MethodGet,
|
||||||
|
Path: "/order/agent",
|
||||||
|
Handler: agent.CheckOrderAgentHandler(serverCtx),
|
||||||
|
},
|
||||||
{
|
{
|
||||||
Method: http.MethodGet,
|
Method: http.MethodGet,
|
||||||
Path: "/product_config",
|
Path: "/product_config",
|
||||||
@@ -731,6 +751,31 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
|||||||
Path: "/upgrade/subordinate",
|
Path: "/upgrade/subordinate",
|
||||||
Handler: agent.UpgradeSubordinateHandler(serverCtx),
|
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,
|
Method: http.MethodPost,
|
||||||
Path: "/withdrawal/apply",
|
Path: "/withdrawal/apply",
|
||||||
|
|||||||
@@ -0,0 +1,213 @@
|
|||||||
|
package admin_dashboard
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
"qnc-server/app/main/api/internal/service"
|
||||||
|
"qnc-server/app/main/api/internal/svc"
|
||||||
|
"qnc-server/app/main/api/internal/types"
|
||||||
|
"qnc-server/common/globalkey"
|
||||||
|
"qnc-server/common/xerr"
|
||||||
|
)
|
||||||
|
|
||||||
|
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) {
|
||||||
|
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)
|
||||||
|
|
||||||
|
orderStats, err := l.calculateOrderStatistics(todayStart, todayEnd, yesterdayStart, yesterdayEnd, monthStart, monthEnd)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "计算订单统计失败, %v", err)
|
||||||
|
}
|
||||||
|
revenueStats, err := l.calculateRevenueStatistics(todayStart, todayEnd, yesterdayStart, yesterdayEnd, monthStart, monthEnd)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "计算营收统计失败, %v", err)
|
||||||
|
}
|
||||||
|
agentStats, err := l.calculateAgentStatistics(todayStart, monthStart)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "计算代理统计失败, %v", err)
|
||||||
|
}
|
||||||
|
profitStats, err := l.calculateProfitStatistics(todayStart, todayEnd, monthStart, monthEnd, revenueStats)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "计算利润统计失败, %v", err)
|
||||||
|
}
|
||||||
|
orderTrend, err := l.calculateOrderTrend(now, loc)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "计算订单趋势失败, %v", err)
|
||||||
|
}
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
stats.YesterdayCount, _ = l.svcCtx.OrderModel.FindCount(l.ctx, yesterdayBuilder, "id")
|
||||||
|
monthBuilder := l.svcCtx.OrderModel.SelectBuilder().Where("status = ? AND create_time >= ? AND create_time < ?", "paid", monthStart, monthEnd)
|
||||||
|
stats.MonthCount, _ = l.svcCtx.OrderModel.FindCount(l.ctx, monthBuilder, "id")
|
||||||
|
totalBuilder := l.svcCtx.OrderModel.SelectBuilder().Where("status = ?", "paid")
|
||||||
|
stats.TotalCount, _ = l.svcCtx.OrderModel.FindCount(l.ctx, totalBuilder, "id")
|
||||||
|
if stats.YesterdayCount > 0 {
|
||||||
|
stats.ChangeRate = float64(stats.TodayCount-stats.YesterdayCount) / float64(stats.YesterdayCount) * 100
|
||||||
|
} else if stats.TodayCount > 0 {
|
||||||
|
stats.ChangeRate = 100
|
||||||
|
}
|
||||||
|
return stats, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
stats.TodayAmount, _ = l.svcCtx.OrderModel.FindSum(l.ctx, todayBuilder, "amount")
|
||||||
|
yesterdayBuilder := l.svcCtx.OrderModel.SelectBuilder().Where("status = ? AND create_time >= ? AND create_time < ?", "paid", yesterdayStart, yesterdayEnd)
|
||||||
|
stats.YesterdayAmount, _ = l.svcCtx.OrderModel.FindSum(l.ctx, yesterdayBuilder, "amount")
|
||||||
|
monthBuilder := l.svcCtx.OrderModel.SelectBuilder().Where("status = ? AND create_time >= ? AND create_time < ?", "paid", monthStart, monthEnd)
|
||||||
|
stats.MonthAmount, _ = l.svcCtx.OrderModel.FindSum(l.ctx, monthBuilder, "amount")
|
||||||
|
totalBuilder := l.svcCtx.OrderModel.SelectBuilder().Where("status = ?", "paid")
|
||||||
|
stats.TotalAmount, _ = l.svcCtx.OrderModel.FindSum(l.ctx, totalBuilder, "amount")
|
||||||
|
if stats.YesterdayAmount > 0 {
|
||||||
|
stats.ChangeRate = (stats.TodayAmount - stats.YesterdayAmount) / stats.YesterdayAmount * 100
|
||||||
|
} else if stats.TodayAmount > 0 {
|
||||||
|
stats.ChangeRate = 100
|
||||||
|
}
|
||||||
|
return stats, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *AdminGetDashboardStatisticsLogic) calculateAgentStatistics(todayStart, monthStart time.Time) (types.AdminAgentStatistics, error) {
|
||||||
|
var stats types.AdminAgentStatistics
|
||||||
|
stats.TotalCount, _ = l.svcCtx.AgentModel.FindCount(l.ctx, l.svcCtx.AgentModel.SelectBuilder(), "id")
|
||||||
|
todayBuilder := l.svcCtx.AgentModel.SelectBuilder().Where("create_time >= ?", todayStart)
|
||||||
|
stats.TodayNew, _ = l.svcCtx.AgentModel.FindCount(l.ctx, todayBuilder, "id")
|
||||||
|
monthBuilder := l.svcCtx.AgentModel.SelectBuilder().Where("create_time >= ?", monthStart)
|
||||||
|
stats.MonthNew, _ = l.svcCtx.AgentModel.FindCount(l.ctx, monthBuilder, "id")
|
||||||
|
return stats, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *AdminGetDashboardStatisticsLogic) calculateProfitStatistics(todayStart, todayEnd, monthStart, monthEnd time.Time, revenueStats types.AdminRevenueStatistics) (types.AdminProfitStatistics, error) {
|
||||||
|
var stats types.AdminProfitStatistics
|
||||||
|
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, _ := l.svcCtx.AgentCommissionModel.FindSum(l.ctx, todayCommissionBuilder, "amount")
|
||||||
|
todayRebateBuilder := l.svcCtx.AgentRebateModel.SelectBuilder().Where("del_state = ? AND status != ? AND create_time >= ? AND create_time < ?", globalkey.DelStateNo, 3, todayStart, todayEnd)
|
||||||
|
todayRebate, _ := l.svcCtx.AgentRebateModel.FindSum(l.ctx, todayRebateBuilder, "rebate_amount")
|
||||||
|
todayCompanyTax := todayRevenue * companyTaxRate
|
||||||
|
todayTaxIncomeBuilder := l.svcCtx.AgentWithdrawalTaxModel.SelectBuilder().Where("del_state = ? AND tax_status = ? AND create_time >= ? AND create_time < ?", globalkey.DelStateNo, 2, todayStart, todayEnd)
|
||||||
|
todayTaxIncome, _ := l.svcCtx.AgentWithdrawalTaxModel.FindSum(l.ctx, todayTaxIncomeBuilder, "tax_amount")
|
||||||
|
todayApiCost := 0.0
|
||||||
|
if l.svcCtx.TianyuanapiCallLogService != nil {
|
||||||
|
if st, e := l.svcCtx.TianyuanapiCallLogService.GetStatistics(l.ctx, service.StatisticsFilter{StartDate: todayStart, EndDate: todayEnd}); e == nil {
|
||||||
|
todayApiCost = st.TotalCost
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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, _ := l.svcCtx.AgentCommissionModel.FindSum(l.ctx, monthCommissionBuilder, "amount")
|
||||||
|
monthRebateBuilder := l.svcCtx.AgentRebateModel.SelectBuilder().Where("del_state = ? AND status != ? AND create_time >= ? AND create_time < ?", globalkey.DelStateNo, 3, monthStart, monthEnd)
|
||||||
|
monthRebate, _ := l.svcCtx.AgentRebateModel.FindSum(l.ctx, monthRebateBuilder, "rebate_amount")
|
||||||
|
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, _ := l.svcCtx.AgentWithdrawalTaxModel.FindSum(l.ctx, monthTaxIncomeBuilder, "tax_amount")
|
||||||
|
monthApiCost := 0.0
|
||||||
|
if l.svcCtx.TianyuanapiCallLogService != nil {
|
||||||
|
if st, e := l.svcCtx.TianyuanapiCallLogService.GetStatistics(l.ctx, service.StatisticsFilter{StartDate: monthStart, EndDate: monthEnd}); e == nil {
|
||||||
|
monthApiCost = st.TotalCost
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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, _ := l.svcCtx.AgentCommissionModel.FindSum(l.ctx, totalCommissionBuilder, "amount")
|
||||||
|
totalRebateBuilder := l.svcCtx.AgentRebateModel.SelectBuilder().Where("status != ?", 3)
|
||||||
|
totalRebate, _ := l.svcCtx.AgentRebateModel.FindSum(l.ctx, totalRebateBuilder, "rebate_amount")
|
||||||
|
totalCompanyTax := totalRevenue * companyTaxRate
|
||||||
|
totalTaxIncomeBuilder := l.svcCtx.AgentWithdrawalTaxModel.SelectBuilder().Where("tax_status = ?", 2)
|
||||||
|
totalTaxIncome, _ := l.svcCtx.AgentWithdrawalTaxModel.FindSum(l.ctx, totalTaxIncomeBuilder, "tax_amount")
|
||||||
|
totalApiCost := 0.0
|
||||||
|
if l.svcCtx.TianyuanapiCallLogService != nil {
|
||||||
|
if st, e := l.svcCtx.TianyuanapiCallLogService.GetStatistics(l.ctx, service.StatisticsFilter{}); e == nil {
|
||||||
|
totalApiCost = st.TotalCost
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *AdminGetDashboardStatisticsLogic) calculateOrderTrend(now time.Time, loc *time.Location) ([]types.AdminTrendData, error) {
|
||||||
|
var trend []types.AdminTrendData
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *AdminGetDashboardStatisticsLogic) calculateRevenueTrend(now time.Time, loc *time.Location) ([]types.AdminTrendData, error) {
|
||||||
|
var trend []types.AdminTrendData
|
||||||
|
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
|
||||||
|
}
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
package agent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
"qnc-server/app/main/api/internal/svc"
|
||||||
|
"qnc-server/app/main/api/internal/types"
|
||||||
|
"qnc-server/app/main/model"
|
||||||
|
"qnc-server/common/xerr"
|
||||||
|
)
|
||||||
|
|
||||||
|
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) {
|
||||||
|
if req.IdCard == "" {
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrMsg("身份证号不能为空"), "")
|
||||||
|
}
|
||||||
|
if req.FeatureApiId == "" {
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrMsg("模块API标识不能为空"), "")
|
||||||
|
}
|
||||||
|
mainApiId := req.FeatureApiId
|
||||||
|
if idx := strings.Index(req.FeatureApiId, "_"); idx > 0 {
|
||||||
|
mainApiId = req.FeatureApiId[:idx]
|
||||||
|
}
|
||||||
|
feature, err := l.svcCtx.FeatureModel.FindOneByApiId(l.ctx, mainApiId)
|
||||||
|
if err != nil {
|
||||||
|
if errors.Is(err, model.ErrNotFound) {
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrMsg("模块不存在"), "")
|
||||||
|
}
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "查询模块信息失败, %v", err)
|
||||||
|
}
|
||||||
|
whitelistBuilder := l.svcCtx.UserFeatureWhitelistModel.SelectBuilder().Where("id_card = ? AND feature_api_id = ? AND status = ?", req.IdCard, mainApiId, 1)
|
||||||
|
whitelists, err := l.svcCtx.UserFeatureWhitelistModel.FindAll(l.ctx, whitelistBuilder, "")
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "查询白名单记录失败, %v", err)
|
||||||
|
}
|
||||||
|
isWhitelisted := len(whitelists) > 0
|
||||||
|
dataDeleted := false
|
||||||
|
if req.QueryId != "" {
|
||||||
|
containsFeature, err := l.svcCtx.WhitelistService.CheckQueryDataContainsFeature(l.ctx, req.QueryId, req.FeatureApiId)
|
||||||
|
if err != nil {
|
||||||
|
logx.Errorf("检查报告数据是否包含模块失败:%v", err)
|
||||||
|
dataDeleted = true
|
||||||
|
} else {
|
||||||
|
dataDeleted = !containsFeature
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
dataDeleted = true
|
||||||
|
}
|
||||||
|
return &types.CheckFeatureWhitelistStatusResp{
|
||||||
|
IsWhitelisted: isWhitelisted, WhitelistPrice: feature.WhitelistPrice, FeatureId: feature.Id, DataDeleted: dataDeleted,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
53
app/main/api/internal/logic/agent/checkorderagentlogic.go
Normal file
53
app/main/api/internal/logic/agent/checkorderagentlogic.go
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
package agent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
"qnc-server/app/main/api/internal/svc"
|
||||||
|
"qnc-server/app/main/api/internal/types"
|
||||||
|
"qnc-server/app/main/model"
|
||||||
|
"qnc-server/common/ctxdata"
|
||||||
|
"qnc-server/common/xerr"
|
||||||
|
)
|
||||||
|
|
||||||
|
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,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// CheckOrderAgent 判断订单是否为当前代理推广的订单(通过 agent_order 关联)
|
||||||
|
func (l *CheckOrderAgentLogic) CheckOrderAgent(req *types.CheckOrderAgentReq) (resp *types.CheckOrderAgentResp, err error) {
|
||||||
|
if req.OrderId == "" {
|
||||||
|
return &types.CheckOrderAgentResp{IsAgentOrder: false}, nil
|
||||||
|
}
|
||||||
|
userID, err := ctxdata.GetUidFromCtx(l.ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "获取用户信息失败, %v", err)
|
||||||
|
}
|
||||||
|
agent, err := l.svcCtx.AgentModel.FindOneByUserId(l.ctx, userID)
|
||||||
|
if err != nil {
|
||||||
|
if errors.Is(err, model.ErrNotFound) {
|
||||||
|
return &types.CheckOrderAgentResp{IsAgentOrder: false}, nil
|
||||||
|
}
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "查询代理信息失败, %v", err)
|
||||||
|
}
|
||||||
|
agentOrder, err := l.svcCtx.AgentOrderModel.FindOneByOrderId(l.ctx, req.OrderId)
|
||||||
|
if err != nil {
|
||||||
|
if errors.Is(err, model.ErrNotFound) {
|
||||||
|
return &types.CheckOrderAgentResp{IsAgentOrder: false}, nil
|
||||||
|
}
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "查询订单关联失败, %v", err)
|
||||||
|
}
|
||||||
|
return &types.CheckOrderAgentResp{IsAgentOrder: agentOrder.AgentId == agent.Id}, nil
|
||||||
|
}
|
||||||
111
app/main/api/internal/logic/agent/createwhitelistorderlogic.go
Normal file
111
app/main/api/internal/logic/agent/createwhitelistorderlogic.go
Normal file
@@ -0,0 +1,111 @@
|
|||||||
|
package agent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/google/uuid"
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||||
|
"qnc-server/app/main/api/internal/svc"
|
||||||
|
"qnc-server/app/main/api/internal/types"
|
||||||
|
"qnc-server/app/main/model"
|
||||||
|
"qnc-server/common/ctxdata"
|
||||||
|
"qnc-server/common/xerr"
|
||||||
|
)
|
||||||
|
|
||||||
|
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) {
|
||||||
|
userID, err := ctxdata.GetUidFromCtx(l.ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "获取用户信息失败, %v", err)
|
||||||
|
}
|
||||||
|
_, err = l.svcCtx.AgentModel.FindOneByUserId(l.ctx, userID)
|
||||||
|
if err != nil {
|
||||||
|
if errors.Is(err, model.ErrNotFound) {
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrMsg("您不是代理"), "")
|
||||||
|
}
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "查询代理信息失败, %v", err)
|
||||||
|
}
|
||||||
|
if req.IdCard == "" {
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrMsg("身份证号不能为空"), "")
|
||||||
|
}
|
||||||
|
if len(req.FeatureIds) == 0 {
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrMsg("请至少选择一个模块"), "")
|
||||||
|
}
|
||||||
|
var totalAmount float64
|
||||||
|
var orderItems []struct {
|
||||||
|
FeatureId string
|
||||||
|
FeatureApiId string
|
||||||
|
FeatureName string
|
||||||
|
Price float64
|
||||||
|
}
|
||||||
|
for _, featureId := range req.FeatureIds {
|
||||||
|
feature, err := l.svcCtx.FeatureModel.FindOne(l.ctx, featureId)
|
||||||
|
if err != nil {
|
||||||
|
if errors.Is(err, model.ErrNotFound) {
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrMsg(fmt.Sprintf("模块不存在: %s", featureId)), "")
|
||||||
|
}
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "查询模块信息失败, %v", err)
|
||||||
|
}
|
||||||
|
if feature.WhitelistPrice <= 0 {
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrMsg(fmt.Sprintf("模块 %s 不支持白名单屏蔽", feature.Name)), "")
|
||||||
|
}
|
||||||
|
whitelistBuilder := l.svcCtx.UserFeatureWhitelistModel.SelectBuilder().Where("id_card = ? AND feature_id = ?", req.IdCard, featureId)
|
||||||
|
existing, err := l.svcCtx.UserFeatureWhitelistModel.FindAll(l.ctx, whitelistBuilder, "")
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "查询白名单记录失败, %v", err)
|
||||||
|
}
|
||||||
|
for _, item := range existing {
|
||||||
|
if item.Status == 1 {
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrMsg(fmt.Sprintf("身份证号 %s 的模块 %s 已经加入白名单", req.IdCard, feature.Name)), "")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
totalAmount += feature.WhitelistPrice
|
||||||
|
orderItems = append(orderItems, struct {
|
||||||
|
FeatureId string
|
||||||
|
FeatureApiId string
|
||||||
|
FeatureName string
|
||||||
|
Price float64
|
||||||
|
}{FeatureId: feature.Id, FeatureApiId: feature.ApiId, FeatureName: feature.Name, Price: feature.WhitelistPrice})
|
||||||
|
}
|
||||||
|
base := l.svcCtx.AlipayService.GenerateOutTradeNo()
|
||||||
|
orderNo := "W_" + base
|
||||||
|
if len(orderNo) > 32 {
|
||||||
|
orderNo = orderNo[:32]
|
||||||
|
}
|
||||||
|
var orderId string
|
||||||
|
err = l.svcCtx.WhitelistOrderModel.Trans(l.ctx, func(ctx context.Context, session sqlx.Session) error {
|
||||||
|
order := &model.WhitelistOrder{Id: uuid.NewString(), OrderNo: orderNo, UserId: userID, IdCard: req.IdCard, TotalAmount: totalAmount, Status: 1}
|
||||||
|
_, err := l.svcCtx.WhitelistOrderModel.Insert(ctx, session, order)
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "创建订单失败, %v", err)
|
||||||
|
}
|
||||||
|
orderId = order.Id
|
||||||
|
for _, item := range orderItems {
|
||||||
|
orderItem := &model.WhitelistOrderItem{Id: uuid.NewString(), OrderId: orderId, FeatureId: item.FeatureId, FeatureApiId: item.FeatureApiId, FeatureName: item.FeatureName, Price: item.Price}
|
||||||
|
if _, err := l.svcCtx.WhitelistOrderItemModel.Insert(ctx, session, orderItem); err != nil {
|
||||||
|
return errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "创建订单明细失败, %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &types.CreateWhitelistOrderResp{OrderId: orderId, OrderNo: orderNo, TotalAmount: totalAmount}, nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
package agent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
"qnc-server/app/main/api/internal/svc"
|
||||||
|
"qnc-server/app/main/api/internal/types"
|
||||||
|
"qnc-server/common/xerr"
|
||||||
|
)
|
||||||
|
|
||||||
|
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,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetWhitelistFeatures 返回支持白名单屏蔽的 feature 列表(whitelist_price > 0)
|
||||||
|
func (l *GetWhitelistFeaturesLogic) GetWhitelistFeatures(req *types.GetWhitelistFeaturesReq) (resp *types.GetWhitelistFeaturesResp, err error) {
|
||||||
|
builder := l.svcCtx.FeatureModel.SelectBuilder().Where("whitelist_price > ?", 0)
|
||||||
|
list, err := l.svcCtx.FeatureModel.FindAll(l.ctx, builder, "id ASC")
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "查询功能列表失败, %v", err)
|
||||||
|
}
|
||||||
|
items := make([]types.WhitelistFeatureItem, 0, len(list))
|
||||||
|
for _, f := range list {
|
||||||
|
items = append(items, types.WhitelistFeatureItem{
|
||||||
|
FeatureId: f.Id, FeatureApiId: f.ApiId, FeatureName: f.Name, WhitelistPrice: f.WhitelistPrice,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return &types.GetWhitelistFeaturesResp{List: items}, nil
|
||||||
|
}
|
||||||
69
app/main/api/internal/logic/agent/getwhitelistlistlogic.go
Normal file
69
app/main/api/internal/logic/agent/getwhitelistlistlogic.go
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
package agent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
"qnc-server/app/main/api/internal/svc"
|
||||||
|
"qnc-server/app/main/api/internal/types"
|
||||||
|
"qnc-server/common/ctxdata"
|
||||||
|
"qnc-server/common/xerr"
|
||||||
|
)
|
||||||
|
|
||||||
|
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 statusToText(status int64) string {
|
||||||
|
if status == 1 {
|
||||||
|
return "生效"
|
||||||
|
}
|
||||||
|
if status == 2 {
|
||||||
|
return "已失效"
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *GetWhitelistListLogic) GetWhitelistList(req *types.GetWhitelistListReq) (resp *types.GetWhitelistListResp, err error) {
|
||||||
|
userID, err := ctxdata.GetUidFromCtx(l.ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "获取用户信息失败, %v", err)
|
||||||
|
}
|
||||||
|
if req.Page <= 0 {
|
||||||
|
req.Page = 1
|
||||||
|
}
|
||||||
|
if req.PageSize <= 0 || req.PageSize > 100 {
|
||||||
|
req.PageSize = 10
|
||||||
|
}
|
||||||
|
builder := l.svcCtx.UserFeatureWhitelistModel.SelectBuilder().Where("user_id = ?", userID)
|
||||||
|
if req.IdCard != "" {
|
||||||
|
builder = builder.Where("id_card = ?", req.IdCard)
|
||||||
|
}
|
||||||
|
list, total, err := l.svcCtx.UserFeatureWhitelistModel.FindPageListByPageWithTotal(l.ctx, builder, req.Page, req.PageSize, "create_time DESC")
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "查询白名单列表失败, %v", err)
|
||||||
|
}
|
||||||
|
items := make([]types.WhitelistItem, 0, len(list))
|
||||||
|
for _, r := range list {
|
||||||
|
featureName := r.FeatureApiId
|
||||||
|
if f, e := l.svcCtx.FeatureModel.FindOne(l.ctx, r.FeatureId); e == nil {
|
||||||
|
featureName = f.Name
|
||||||
|
}
|
||||||
|
items = append(items, types.WhitelistItem{
|
||||||
|
Id: r.Id, IdCard: r.IdCard, FeatureId: r.FeatureId, FeatureApiId: r.FeatureApiId, FeatureName: featureName,
|
||||||
|
Amount: r.Amount, Status: r.Status, StatusText: statusToText(r.Status), CreateTime: r.CreateTime.Format("2006-01-02 15:04:05"),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return &types.GetWhitelistListResp{Total: total, List: items}, nil
|
||||||
|
}
|
||||||
69
app/main/api/internal/logic/agent/offlinefeaturelogic.go
Normal file
69
app/main/api/internal/logic/agent/offlinefeaturelogic.go
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
package agent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
"qnc-server/app/main/api/internal/svc"
|
||||||
|
"qnc-server/app/main/api/internal/types"
|
||||||
|
"qnc-server/common/ctxdata"
|
||||||
|
"qnc-server/common/xerr"
|
||||||
|
)
|
||||||
|
|
||||||
|
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) {
|
||||||
|
userID, err := ctxdata.GetUidFromCtx(l.ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "获取用户信息失败, %v", err)
|
||||||
|
}
|
||||||
|
if req.FeatureApiId == "" || req.QueryId == "" {
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrMsg("模块标识和查询记录ID不能为空"), "")
|
||||||
|
}
|
||||||
|
query, err := l.svcCtx.QueryModel.FindOne(l.ctx, req.QueryId)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "查询记录不存在或查询失败, %v", err)
|
||||||
|
}
|
||||||
|
idCard := ""
|
||||||
|
if query.QueryParams != "" {
|
||||||
|
var params map[string]interface{}
|
||||||
|
if e := json.Unmarshal([]byte(query.QueryParams), ¶ms); e == nil {
|
||||||
|
if v, ok := params["id_card"]; ok {
|
||||||
|
if s, ok := v.(string); ok {
|
||||||
|
idCard = s
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if idCard == "" {
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrMsg("无法从查询记录中获取身份证号"), "")
|
||||||
|
}
|
||||||
|
needPay, amount, whitelistCreated, err := l.svcCtx.WhitelistService.ProcessOfflineFeature(l.ctx, nil, idCard, req.FeatureApiId, userID, req.QueryId)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if whitelistCreated && !needPay {
|
||||||
|
if err := l.svcCtx.WhitelistService.DeleteFeatureFromQueryData(l.ctx, nil, req.QueryId, req.FeatureApiId); err != nil {
|
||||||
|
logx.Errorf("从报告数据中删除模块失败: %v", err)
|
||||||
|
}
|
||||||
|
return &types.OfflineFeatureResp{Success: true, NeedPay: false, Amount: 0}, nil
|
||||||
|
}
|
||||||
|
if needPay {
|
||||||
|
return &types.OfflineFeatureResp{Success: false, NeedPay: true, Amount: amount}, nil
|
||||||
|
}
|
||||||
|
return &types.OfflineFeatureResp{Success: true, NeedPay: false, Amount: 0}, nil
|
||||||
|
}
|
||||||
@@ -5,13 +5,13 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"qnc-server/app/main/api/internal/svc"
|
||||||
|
"qnc-server/app/main/model"
|
||||||
"qnc-server/pkg/lzkit/lzUtils"
|
"qnc-server/pkg/lzkit/lzUtils"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/smartwalle/alipay/v3"
|
"github.com/smartwalle/alipay/v3"
|
||||||
|
|
||||||
"qnc-server/app/main/api/internal/svc"
|
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||||
)
|
)
|
||||||
@@ -45,6 +45,9 @@ func (l *AlipayCallbackLogic) AlipayCallback(w http.ResponseWriter, r *http.Requ
|
|||||||
} else if strings.HasPrefix(orderNo, "U_") {
|
} else if strings.HasPrefix(orderNo, "U_") {
|
||||||
// 代理升级订单处理
|
// 代理升级订单处理
|
||||||
return l.handleAgentUpgradeOrderPayment(w, notification)
|
return l.handleAgentUpgradeOrderPayment(w, notification)
|
||||||
|
} else if strings.HasPrefix(orderNo, "W_") {
|
||||||
|
// 白名单下架订单
|
||||||
|
return l.handleWhitelistOrderPayment(w, notification)
|
||||||
} else if strings.HasPrefix(orderNo, "A_") {
|
} else if strings.HasPrefix(orderNo, "A_") {
|
||||||
// 旧系统会员充值订单(已废弃,新系统使用升级功能)
|
// 旧系统会员充值订单(已废弃,新系统使用升级功能)
|
||||||
// return l.handleAgentVipOrderPayment(w, notification)
|
// return l.handleAgentVipOrderPayment(w, notification)
|
||||||
@@ -226,6 +229,51 @@ func (l *AlipayCallbackLogic) handleAgentUpgradeOrderPayment(w http.ResponseWrit
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// handleWhitelistOrderPayment 处理白名单下架订单支付
|
||||||
|
func (l *AlipayCallbackLogic) handleWhitelistOrderPayment(w http.ResponseWriter, notification *alipay.Notification) error {
|
||||||
|
wo, err := l.svcCtx.WhitelistOrderModel.FindOneByOrderNo(l.ctx, notification.OutTradeNo)
|
||||||
|
if err != nil {
|
||||||
|
if errors.Is(err, model.ErrNotFound) {
|
||||||
|
logx.Errorf("支付宝支付回调,白名单订单不存在: %s", notification.OutTradeNo)
|
||||||
|
} else {
|
||||||
|
logx.Errorf("支付宝支付回调,查找白名单订单失败: %+v", err)
|
||||||
|
}
|
||||||
|
alipay.ACKNotification(w)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if wo.Status != 1 {
|
||||||
|
alipay.ACKNotification(w)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
amount := lzUtils.ToAlipayAmount(wo.TotalAmount)
|
||||||
|
if amount != notification.TotalAmount {
|
||||||
|
logx.Errorf("支付宝支付回调,白名单订单金额不一致")
|
||||||
|
alipay.ACKNotification(w)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if notification.TradeStatus != alipay.TradeStatusSuccess {
|
||||||
|
alipay.ACKNotification(w)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
wo.Status = 2
|
||||||
|
wo.PaymentMethod = lzUtils.StringToNullString("alipay")
|
||||||
|
wo.PayTime = lzUtils.TimeToNullTime(time.Now())
|
||||||
|
wo.PlatformOrderId = lzUtils.StringToNullString(notification.TradeNo)
|
||||||
|
if updateErr := l.svcCtx.WhitelistOrderModel.UpdateWithVersion(l.ctx, nil, wo); updateErr != nil {
|
||||||
|
logx.Errorf("支付宝支付回调,更新白名单订单失败: %+v", updateErr)
|
||||||
|
alipay.ACKNotification(w)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
err = l.svcCtx.WhitelistOrderModel.Trans(l.ctx, func(ctx context.Context, session sqlx.Session) error {
|
||||||
|
return l.svcCtx.WhitelistService.ProcessPaidWhitelistOrder(ctx, session, nil, wo)
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
logx.Errorf("支付宝支付回调,处理白名单订单失败: %+v", err)
|
||||||
|
}
|
||||||
|
alipay.ACKNotification(w)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// 处理代理会员订单支付(已废弃,新系统使用升级功能)
|
// 处理代理会员订单支付(已废弃,新系统使用升级功能)
|
||||||
/*
|
/*
|
||||||
func (l *AlipayCallbackLogic) handleAgentVipOrderPayment(w http.ResponseWriter, notification *alipay.Notification) error {
|
func (l *AlipayCallbackLogic) handleAgentVipOrderPayment(w http.ResponseWriter, notification *alipay.Notification) error {
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package pay
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"qnc-server/app/main/api/internal/svc"
|
"qnc-server/app/main/api/internal/svc"
|
||||||
"qnc-server/app/main/api/internal/types"
|
"qnc-server/app/main/api/internal/types"
|
||||||
"qnc-server/common/xerr"
|
"qnc-server/common/xerr"
|
||||||
@@ -27,8 +28,33 @@ func NewPaymentCheckLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Paym
|
|||||||
|
|
||||||
func (l *PaymentCheckLogic) PaymentCheck(req *types.PaymentCheckReq) (resp *types.PaymentCheckResp, err error) {
|
func (l *PaymentCheckLogic) PaymentCheck(req *types.PaymentCheckReq) (resp *types.PaymentCheckResp, err error) {
|
||||||
// 根据订单号前缀判断订单类型
|
// 根据订单号前缀判断订单类型
|
||||||
|
// 白名单下架订单:前缀 W_
|
||||||
|
if strings.HasPrefix(req.OrderNo, "W_") {
|
||||||
|
whitelistOrder, err := l.svcCtx.WhitelistOrderModel.FindOneByOrderNo(l.ctx, req.OrderNo)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "查询白名单订单失败: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
status := "pending"
|
||||||
|
switch whitelistOrder.Status {
|
||||||
|
case 1:
|
||||||
|
status = "pending"
|
||||||
|
case 2:
|
||||||
|
status = "paid"
|
||||||
|
case 3:
|
||||||
|
status = "closed"
|
||||||
|
default:
|
||||||
|
status = "pending"
|
||||||
|
}
|
||||||
|
|
||||||
|
return &types.PaymentCheckResp{
|
||||||
|
Type: "whitelist",
|
||||||
|
Status: status,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// 升级订单:前缀 U_
|
||||||
if strings.HasPrefix(req.OrderNo, "U_") {
|
if strings.HasPrefix(req.OrderNo, "U_") {
|
||||||
// 升级订单
|
|
||||||
order, err := l.svcCtx.OrderModel.FindOneByOrderNo(l.ctx, req.OrderNo)
|
order, err := l.svcCtx.OrderModel.FindOneByOrderNo(l.ctx, req.OrderNo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "查询升级订单失败: %v", err)
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "查询升级订单失败: %v", err)
|
||||||
@@ -38,8 +64,8 @@ func (l *PaymentCheckLogic) PaymentCheck(req *types.PaymentCheckReq) (resp *type
|
|||||||
Status: order.Status,
|
Status: order.Status,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查询订单(包括代理订单)
|
// 其他视为常规查询订单(包括代理推广查询)
|
||||||
order, err := l.svcCtx.OrderModel.FindOneByOrderNo(l.ctx, req.OrderNo)
|
order, err := l.svcCtx.OrderModel.FindOneByOrderNo(l.ctx, req.OrderNo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "查询订单失败: %v", err)
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "查询订单失败: %v", err)
|
||||||
|
|||||||
@@ -76,6 +76,12 @@ func (l *PaymentLogic) Payment(req *types.PaymentReq) (resp *types.PaymentResp,
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case "whitelist":
|
||||||
|
paymentTypeResp, err = l.WhitelistOrderPayment(req, session)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 开发环境测试支付模式:跳过实际支付流程
|
// 开发环境测试支付模式:跳过实际支付流程
|
||||||
@@ -462,6 +468,67 @@ func (l *PaymentLogic) AgentUpgradeOrderPayment(req *types.PaymentReq, session s
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WhitelistOrderPayment 白名单下架订单支付(id 格式:id_card|feature_api_id)
|
||||||
|
func (l *PaymentLogic) WhitelistOrderPayment(req *types.PaymentReq, session sqlx.Session) (resp *PaymentTypeResp, err error) {
|
||||||
|
userID, err := ctxdata.GetUidFromCtx(l.ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "获取用户信息失败, %v", err)
|
||||||
|
}
|
||||||
|
parts := strings.SplitN(req.Id, "|", 2)
|
||||||
|
if len(parts) != 2 || parts[0] == "" || parts[1] == "" {
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrMsg("白名单支付参数无效,id 格式应为 id_card|feature_api_id"), "")
|
||||||
|
}
|
||||||
|
idCard := parts[0]
|
||||||
|
featureApiId := parts[1]
|
||||||
|
feature, err := l.svcCtx.FeatureModel.FindOneByApiId(l.ctx, featureApiId)
|
||||||
|
if err != nil {
|
||||||
|
if errors.Is(err, model.ErrNotFound) {
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrMsg("模块不存在"), "")
|
||||||
|
}
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "查询模块失败: %v", err)
|
||||||
|
}
|
||||||
|
if feature.WhitelistPrice <= 0 {
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrMsg("该模块不支持付费下架"), "")
|
||||||
|
}
|
||||||
|
base := l.svcCtx.AlipayService.GenerateOutTradeNo()
|
||||||
|
outTradeNo := "W_" + base
|
||||||
|
if len(outTradeNo) > 32 {
|
||||||
|
outTradeNo = outTradeNo[:32]
|
||||||
|
}
|
||||||
|
amount := feature.WhitelistPrice
|
||||||
|
wo := &model.WhitelistOrder{
|
||||||
|
Id: uuid.NewString(),
|
||||||
|
OrderNo: outTradeNo,
|
||||||
|
UserId: userID,
|
||||||
|
IdCard: idCard,
|
||||||
|
TotalAmount: amount,
|
||||||
|
Status: 1,
|
||||||
|
}
|
||||||
|
_, err = l.svcCtx.WhitelistOrderModel.Insert(l.ctx, session, wo)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "创建白名单订单失败: %v", err)
|
||||||
|
}
|
||||||
|
item := &model.WhitelistOrderItem{
|
||||||
|
Id: uuid.NewString(),
|
||||||
|
OrderId: wo.Id,
|
||||||
|
FeatureId: feature.Id,
|
||||||
|
FeatureApiId: feature.ApiId,
|
||||||
|
FeatureName: feature.Name,
|
||||||
|
Price: amount,
|
||||||
|
}
|
||||||
|
_, err = l.svcCtx.WhitelistOrderItemModel.Insert(l.ctx, session, item)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "创建白名单订单明细失败: %v", err)
|
||||||
|
}
|
||||||
|
description := fmt.Sprintf("%s 模块下架", feature.Name)
|
||||||
|
return &PaymentTypeResp{
|
||||||
|
amount: amount,
|
||||||
|
outTradeNo: outTradeNo,
|
||||||
|
description: description,
|
||||||
|
orderID: wo.Id,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
// getLevelBonus 获取等级加成(从配置表读取)
|
// getLevelBonus 获取等级加成(从配置表读取)
|
||||||
func (l *PaymentLogic) getLevelBonus(level int64) (int64, error) {
|
func (l *PaymentLogic) getLevelBonus(level int64) (int64, error) {
|
||||||
var configKey string
|
var configKey string
|
||||||
|
|||||||
@@ -5,10 +5,11 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
"qnc-server/app/main/api/internal/service"
|
|
||||||
"qnc-server/pkg/lzkit/lzUtils"
|
|
||||||
|
|
||||||
|
"qnc-server/app/main/api/internal/service"
|
||||||
"qnc-server/app/main/api/internal/svc"
|
"qnc-server/app/main/api/internal/svc"
|
||||||
|
"qnc-server/app/main/model"
|
||||||
|
"qnc-server/pkg/lzkit/lzUtils"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/wechatpay-apiv3/wechatpay-go/services/payments"
|
"github.com/wechatpay-apiv3/wechatpay-go/services/payments"
|
||||||
@@ -45,6 +46,9 @@ func (l *WechatPayCallbackLogic) WechatPayCallback(w http.ResponseWriter, r *htt
|
|||||||
} else if strings.HasPrefix(orderNo, "U_") {
|
} else if strings.HasPrefix(orderNo, "U_") {
|
||||||
// 代理升级订单处理
|
// 代理升级订单处理
|
||||||
return l.handleAgentUpgradeOrderPayment(w, notification)
|
return l.handleAgentUpgradeOrderPayment(w, notification)
|
||||||
|
} else if strings.HasPrefix(orderNo, "W_") {
|
||||||
|
// 白名单下架订单
|
||||||
|
return l.handleWhitelistOrderPayment(w, notification)
|
||||||
} else if strings.HasPrefix(orderNo, "A_") {
|
} else if strings.HasPrefix(orderNo, "A_") {
|
||||||
// 旧系统会员充值订单(已废弃,新系统使用升级功能)
|
// 旧系统会员充值订单(已废弃,新系统使用升级功能)
|
||||||
// return l.handleAgentVipOrderPayment(w, notification)
|
// return l.handleAgentVipOrderPayment(w, notification)
|
||||||
@@ -222,6 +226,57 @@ func (l *WechatPayCallbackLogic) handleAgentUpgradeOrderPayment(w http.ResponseW
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// handleWhitelistOrderPayment 处理白名单下架订单支付
|
||||||
|
func (l *WechatPayCallbackLogic) handleWhitelistOrderPayment(w http.ResponseWriter, notification *payments.Transaction) error {
|
||||||
|
wo, err := l.svcCtx.WhitelistOrderModel.FindOneByOrderNo(l.ctx, *notification.OutTradeNo)
|
||||||
|
if err != nil {
|
||||||
|
if errors.Is(err, model.ErrNotFound) {
|
||||||
|
logx.Errorf("微信支付回调,白名单订单不存在: %s", *notification.OutTradeNo)
|
||||||
|
} else {
|
||||||
|
logx.Errorf("微信支付回调,查找白名单订单失败: %+v", err)
|
||||||
|
}
|
||||||
|
w.WriteHeader(http.StatusOK)
|
||||||
|
_, _ = w.Write([]byte("success"))
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if wo.Status != 1 {
|
||||||
|
w.WriteHeader(http.StatusOK)
|
||||||
|
_, _ = w.Write([]byte("success"))
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
amount := lzUtils.ToWechatAmount(wo.TotalAmount)
|
||||||
|
if amount != *notification.Amount.Total {
|
||||||
|
logx.Errorf("微信支付回调,白名单订单金额不一致")
|
||||||
|
w.WriteHeader(http.StatusOK)
|
||||||
|
_, _ = w.Write([]byte("success"))
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if *notification.TradeState != service.TradeStateSuccess {
|
||||||
|
w.WriteHeader(http.StatusOK)
|
||||||
|
_, _ = w.Write([]byte("success"))
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
wo.Status = 2
|
||||||
|
wo.PaymentMethod = lzUtils.StringToNullString("wechat")
|
||||||
|
wo.PayTime = lzUtils.TimeToNullTime(time.Now())
|
||||||
|
wo.PlatformOrderId = lzUtils.StringToNullString(*notification.TransactionId)
|
||||||
|
if updateErr := l.svcCtx.WhitelistOrderModel.UpdateWithVersion(l.ctx, nil, wo); updateErr != nil {
|
||||||
|
logx.Errorf("微信支付回调,更新白名单订单失败: %+v", updateErr)
|
||||||
|
w.WriteHeader(http.StatusOK)
|
||||||
|
_, _ = w.Write([]byte("success"))
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
err = l.svcCtx.WhitelistOrderModel.Trans(l.ctx, func(ctx context.Context, session sqlx.Session) error {
|
||||||
|
return l.svcCtx.WhitelistService.ProcessPaidWhitelistOrder(ctx, session, nil, wo)
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
logx.Errorf("微信支付回调,处理白名单订单失败: %+v", err)
|
||||||
|
}
|
||||||
|
w.WriteHeader(http.StatusOK)
|
||||||
|
_, _ = w.Write([]byte("success"))
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// 处理代理会员订单支付(已废弃,新系统使用升级功能)
|
// 处理代理会员订单支付(已废弃,新系统使用升级功能)
|
||||||
/*
|
/*
|
||||||
func (l *WechatPayCallbackLogic) handleAgentVipOrderPayment(w http.ResponseWriter, notification *payments.Transaction) error {
|
func (l *WechatPayCallbackLogic) handleAgentVipOrderPayment(w http.ResponseWriter, notification *payments.Transaction) error {
|
||||||
|
|||||||
@@ -115,6 +115,8 @@ func BuildEncryptedQuery(ctx context.Context, svcCtx *svc.ServiceContext, queryM
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return "", errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "报告查询, 报告结构体复制失败, %v", err)
|
return "", errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "报告查询, 报告结构体复制失败, %v", err)
|
||||||
}
|
}
|
||||||
|
// 供前端报告页模块下架等使用
|
||||||
|
query.Id = queryModel.Id
|
||||||
product, err := svcCtx.ProductModel.FindOne(ctx, queryModel.ProductId)
|
product, err := svcCtx.ProductModel.FindOne(ctx, queryModel.ProductId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "报告查询, 获取商品信息失败, %v", err)
|
return "", errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "报告查询, 获取商品信息失败, %v", err)
|
||||||
|
|||||||
190
app/main/api/internal/service/tianyuanapiCallLogService.go
Normal file
190
app/main/api/internal/service/tianyuanapiCallLogService.go
Normal file
@@ -0,0 +1,190 @@
|
|||||||
|
package service
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"database/sql"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/Masterminds/squirrel"
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
"qnc-server/app/main/model"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 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 {
|
||||||
|
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,
|
||||||
|
}
|
||||||
|
|
||||||
|
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}
|
||||||
|
}
|
||||||
|
|
||||||
|
_, 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
|
||||||
|
}
|
||||||
|
|
||||||
|
// StatisticsFilter 统计过滤条件
|
||||||
|
type StatisticsFilter struct {
|
||||||
|
FeatureID string
|
||||||
|
ApiID string
|
||||||
|
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})
|
||||||
|
}
|
||||||
|
if !filter.EndDate.IsZero() {
|
||||||
|
builder = builder.Where(squirrel.Lt{"call_time": filter.EndDate})
|
||||||
|
}
|
||||||
|
totalCalls, err := s.tianyuanapiCallLogModel.FindCount(ctx, builder, "id")
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("统计总调用次数失败: %w", err)
|
||||||
|
}
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
totalCost, err := s.tianyuanapiCallLogModel.FindSum(ctx, successBuilder, "cost_price")
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("统计总成本失败: %w", err)
|
||||||
|
}
|
||||||
|
return &Statistics{
|
||||||
|
TotalCalls: totalCalls,
|
||||||
|
SuccessCalls: successCalls,
|
||||||
|
FailedCalls: totalCalls - successCalls,
|
||||||
|
TotalCost: totalCost,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
450
app/main/api/internal/service/whitelistService.go
Normal file
450
app/main/api/internal/service/whitelistService.go
Normal file
@@ -0,0 +1,450 @@
|
|||||||
|
package service
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"database/sql"
|
||||||
|
"encoding/hex"
|
||||||
|
"encoding/json"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/google/uuid"
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||||
|
"qnc-server/app/main/api/internal/config"
|
||||||
|
"qnc-server/app/main/model"
|
||||||
|
"qnc-server/common/xerr"
|
||||||
|
"qnc-server/pkg/lzkit/crypto"
|
||||||
|
"qnc-server/pkg/lzkit/lzUtils"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 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 || 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 统一下架处理
|
||||||
|
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) {
|
||||||
|
mainApiId := s.extractMainApiId(featureApiId)
|
||||||
|
feature, err := s.getFeatureByApiId(ctx, mainApiId)
|
||||||
|
if err != nil {
|
||||||
|
return false, 0, false, err
|
||||||
|
}
|
||||||
|
if feature.WhitelistPrice < 0 {
|
||||||
|
return false, 0, false, errors.Wrapf(xerr.NewErrMsg("该模块不支持下架"), "")
|
||||||
|
}
|
||||||
|
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
|
||||||
|
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
|
||||||
|
}
|
||||||
|
paidOrderId, err := s.findPaidWhitelistOrder(ctx, userId, idCard, feature.Id)
|
||||||
|
if err != nil {
|
||||||
|
return false, 0, false, err
|
||||||
|
}
|
||||||
|
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
|
||||||
|
}
|
||||||
|
return true, price, false, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *WhitelistService) extractMainApiId(featureApiId string) string {
|
||||||
|
if idx := strings.Index(featureApiId, "_"); idx > 0 {
|
||||||
|
return featureApiId[:idx]
|
||||||
|
}
|
||||||
|
return featureApiId
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
orders, err := s.WhitelistOrderModel.FindAll(ctx, orderBuilder, "")
|
||||||
|
if err != nil {
|
||||||
|
return "", errors.Wrap(err, "查询白名单订单失败")
|
||||||
|
}
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
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 从报告数据中删除指定模块的数据
|
||||||
|
func (s *WhitelistService) DeleteFeatureFromQueryData(
|
||||||
|
ctx context.Context,
|
||||||
|
session sqlx.Session,
|
||||||
|
queryId string,
|
||||||
|
featureApiId string,
|
||||||
|
) error {
|
||||||
|
queryModel, err := s.getQueryModel(ctx, queryId)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if queryModel == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
mainApiId := s.extractMainApiId(featureApiId)
|
||||||
|
dataArray, key, err := s.decryptQueryData(queryModel)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
modifiedArray, hasModified := s.clearFeatureData(dataArray, mainApiId)
|
||||||
|
if !hasModified {
|
||||||
|
logx.Infof("删除报告数据:查询记录 %s 中未找到模块 %s 的数据,跳过删除", queryId, featureApiId)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if err := s.updateQueryData(ctx, session, queryModel, modifiedArray, key); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return 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) {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
return nil, errors.Wrap(err, "查询报告记录失败")
|
||||||
|
}
|
||||||
|
if !queryModel.QueryData.Valid || queryModel.QueryData.String == "" {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
return queryModel, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
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, "解密报告数据失败")
|
||||||
|
}
|
||||||
|
var dataArray []map[string]interface{}
|
||||||
|
if unmarshalErr := json.Unmarshal(decryptedData, &dataArray); unmarshalErr != nil {
|
||||||
|
return nil, nil, errors.Wrap(unmarshalErr, "解析报告数据失败")
|
||||||
|
}
|
||||||
|
return dataArray, key, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
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 {
|
||||||
|
newItem := make(map[string]interface{})
|
||||||
|
for k, v := range item {
|
||||||
|
newItem[k] = v
|
||||||
|
}
|
||||||
|
apiID, ok := item["apiID"].(string)
|
||||||
|
if !ok {
|
||||||
|
modifiedArray = append(modifiedArray, newItem)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if s.extractMainApiId(apiID) == mainApiId {
|
||||||
|
newItem["data"] = nil
|
||||||
|
hasModified = true
|
||||||
|
}
|
||||||
|
modifiedArray = append(modifiedArray, newItem)
|
||||||
|
}
|
||||||
|
return modifiedArray, hasModified
|
||||||
|
}
|
||||||
|
|
||||||
|
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}
|
||||||
|
if updateErr := s.QueryModel.UpdateWithVersion(ctx, session, queryModel); updateErr != nil {
|
||||||
|
return errors.Wrap(updateErr, "更新报告数据失败")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// CheckQueryDataContainsFeature 检查报告数据中是否包含指定的模块
|
||||||
|
func (s *WhitelistService) CheckQueryDataContainsFeature(
|
||||||
|
ctx context.Context,
|
||||||
|
queryId string,
|
||||||
|
featureApiId string,
|
||||||
|
) (bool, error) {
|
||||||
|
queryModel, err := s.getQueryModel(ctx, queryId)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
if queryModel == nil {
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
mainApiId := s.extractMainApiId(featureApiId)
|
||||||
|
dataArray, _, err := s.decryptQueryData(queryModel)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
for _, item := range dataArray {
|
||||||
|
apiID, ok := item["apiID"].(string)
|
||||||
|
if !ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if s.extractMainApiId(apiID) == mainApiId {
|
||||||
|
dataValue, exists := item["data"]
|
||||||
|
if !exists || dataValue == nil {
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProcessPaidWhitelistOrder 处理已支付的白名单订单
|
||||||
|
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(""),
|
||||||
|
WhitelistOrderId: lzUtils.StringToNullString(whitelistOrder.Id),
|
||||||
|
Amount: item.Price,
|
||||||
|
Status: 1,
|
||||||
|
}
|
||||||
|
if _, err := s.UserFeatureWhitelistModel.Insert(ctx, session, wl); err != nil {
|
||||||
|
return errors.Wrap(err, "创建白名单记录失败")
|
||||||
|
}
|
||||||
|
logx.Infof("白名单订单支付成功:订单 %s,模块 %s,已创建白名单记录", whitelistOrder.OrderNo, item.FeatureApiId)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -78,8 +78,16 @@ type ServiceContext struct {
|
|||||||
GlobalNotificationsModel model.GlobalNotificationsModel
|
GlobalNotificationsModel model.GlobalNotificationsModel
|
||||||
AuthorizationDocumentModel model.AuthorizationDocumentModel
|
AuthorizationDocumentModel model.AuthorizationDocumentModel
|
||||||
|
|
||||||
|
// 白名单与天元API调用记录
|
||||||
|
UserFeatureWhitelistModel model.UserFeatureWhitelistModel
|
||||||
|
WhitelistOrderModel model.WhitelistOrderModel
|
||||||
|
WhitelistOrderItemModel model.WhitelistOrderItemModel
|
||||||
|
TianyuanapiCallLogModel model.TianyuanapiCallLogModel
|
||||||
|
|
||||||
// 服务
|
// 服务
|
||||||
AlipayService *service.AliPayService
|
WhitelistService *service.WhitelistService
|
||||||
|
TianyuanapiCallLogService *service.TianyuanapiCallLogService
|
||||||
|
AlipayService *service.AliPayService
|
||||||
WechatPayService *service.WechatPayService
|
WechatPayService *service.WechatPayService
|
||||||
ApplePayService *service.ApplePayService
|
ApplePayService *service.ApplePayService
|
||||||
ApiRequestService *service.ApiRequestService
|
ApiRequestService *service.ApiRequestService
|
||||||
@@ -159,6 +167,12 @@ func NewServiceContext(c config.Config) *ServiceContext {
|
|||||||
globalNotificationsModel := model.NewGlobalNotificationsModel(db, cacheConf)
|
globalNotificationsModel := model.NewGlobalNotificationsModel(db, cacheConf)
|
||||||
authorizationDocumentModel := model.NewAuthorizationDocumentModel(db, cacheConf)
|
authorizationDocumentModel := model.NewAuthorizationDocumentModel(db, cacheConf)
|
||||||
|
|
||||||
|
// ============================== 白名单与天元API调用记录 ==============================
|
||||||
|
userFeatureWhitelistModel := model.NewUserFeatureWhitelistModel(db, cacheConf)
|
||||||
|
whitelistOrderModel := model.NewWhitelistOrderModel(db, cacheConf)
|
||||||
|
whitelistOrderItemModel := model.NewWhitelistOrderItemModel(db, cacheConf)
|
||||||
|
tianyuanapiCallLogModel := model.NewTianyuanapiCallLogModel(db, cacheConf)
|
||||||
|
|
||||||
// ============================== 第三方服务初始化 ==============================
|
// ============================== 第三方服务初始化 ==============================
|
||||||
tianyuanapi, err := tianyuanapi.NewClient(tianyuanapi.Config{
|
tianyuanapi, err := tianyuanapi.NewClient(tianyuanapi.Config{
|
||||||
AccessID: c.Tianyuanapi.AccessID,
|
AccessID: c.Tianyuanapi.AccessID,
|
||||||
@@ -260,8 +274,16 @@ func NewServiceContext(c config.Config) *ServiceContext {
|
|||||||
GlobalNotificationsModel: globalNotificationsModel,
|
GlobalNotificationsModel: globalNotificationsModel,
|
||||||
AuthorizationDocumentModel: authorizationDocumentModel,
|
AuthorizationDocumentModel: authorizationDocumentModel,
|
||||||
|
|
||||||
|
// 白名单与天元API调用记录
|
||||||
|
UserFeatureWhitelistModel: userFeatureWhitelistModel,
|
||||||
|
WhitelistOrderModel: whitelistOrderModel,
|
||||||
|
WhitelistOrderItemModel: whitelistOrderItemModel,
|
||||||
|
TianyuanapiCallLogModel: tianyuanapiCallLogModel,
|
||||||
|
|
||||||
// 服务
|
// 服务
|
||||||
AlipayService: alipayService,
|
WhitelistService: service.NewWhitelistService(c, userFeatureWhitelistModel, whitelistOrderModel, whitelistOrderItemModel, queryModel, featureModel),
|
||||||
|
TianyuanapiCallLogService: service.NewTianyuanapiCallLogService(tianyuanapiCallLogModel, featureModel),
|
||||||
|
AlipayService: alipayService,
|
||||||
WechatPayService: wechatPayService,
|
WechatPayService: wechatPayService,
|
||||||
ApplePayService: applePayService,
|
ApplePayService: applePayService,
|
||||||
ApiRequestService: apiRequestService,
|
ApiRequestService: apiRequestService,
|
||||||
|
|||||||
@@ -1,6 +1,12 @@
|
|||||||
// Code generated by goctl. DO NOT EDIT.
|
// Code generated by goctl. DO NOT EDIT.
|
||||||
package types
|
package types
|
||||||
|
|
||||||
|
type AdminAgentStatistics struct {
|
||||||
|
TotalCount int64 `json:"total_count"` // 代理总数
|
||||||
|
TodayNew int64 `json:"today_new"` // 今日新增
|
||||||
|
MonthNew int64 `json:"month_new"` // 当月新增
|
||||||
|
}
|
||||||
|
|
||||||
type AdminApiInfo struct {
|
type AdminApiInfo struct {
|
||||||
Id string `json:"id"`
|
Id string `json:"id"`
|
||||||
ApiName string `json:"api_name"`
|
ApiName string `json:"api_name"`
|
||||||
@@ -84,8 +90,10 @@ type AdminCreateApiResp struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type AdminCreateFeatureReq struct {
|
type AdminCreateFeatureReq struct {
|
||||||
ApiId string `json:"api_id"` // API标识
|
ApiId string `json:"api_id"` // API标识
|
||||||
Name string `json:"name"` // 描述
|
Name string `json:"name"` // 描述
|
||||||
|
WhitelistPrice *float64 `json:"whitelist_price,optional"` // 白名单屏蔽价格(单位:元)
|
||||||
|
CostPrice *float64 `json:"cost_price,optional"` // 天远API调用成本价(单位:元)
|
||||||
}
|
}
|
||||||
|
|
||||||
type AdminCreateFeatureResp struct {
|
type AdminCreateFeatureResp struct {
|
||||||
@@ -381,16 +389,27 @@ type AdminGetApiListResp struct {
|
|||||||
Total int64 `json:"total"`
|
Total int64 `json:"total"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type AdminGetDashboardStatisticsResp struct {
|
||||||
|
OrderStats AdminOrderStatistics `json:"order_stats"`
|
||||||
|
RevenueStats AdminRevenueStatistics `json:"revenue_stats"`
|
||||||
|
AgentStats AdminAgentStatistics `json:"agent_stats"`
|
||||||
|
ProfitStats AdminProfitStatistics `json:"profit_stats"`
|
||||||
|
OrderTrend []AdminTrendData `json:"order_trend"`
|
||||||
|
RevenueTrend []AdminTrendData `json:"revenue_trend"`
|
||||||
|
}
|
||||||
|
|
||||||
type AdminGetFeatureDetailReq struct {
|
type AdminGetFeatureDetailReq struct {
|
||||||
Id string `path:"id"` // 功能ID
|
Id string `path:"id"` // 功能ID
|
||||||
}
|
}
|
||||||
|
|
||||||
type AdminGetFeatureDetailResp struct {
|
type AdminGetFeatureDetailResp struct {
|
||||||
Id string `json:"id"` // 功能ID
|
Id string `json:"id"` // 功能ID
|
||||||
ApiId string `json:"api_id"` // API标识
|
ApiId string `json:"api_id"` // API标识
|
||||||
Name string `json:"name"` // 描述
|
Name string `json:"name"` // 描述
|
||||||
CreateTime string `json:"create_time"` // 创建时间
|
WhitelistPrice float64 `json:"whitelist_price"` // 白名单屏蔽价格(单位:元)
|
||||||
UpdateTime string `json:"update_time"` // 更新时间
|
CostPrice float64 `json:"cost_price"` // 天远API调用成本价(单位:元)
|
||||||
|
CreateTime string `json:"create_time"` // 创建时间
|
||||||
|
UpdateTime string `json:"update_time"` // 更新时间
|
||||||
}
|
}
|
||||||
|
|
||||||
type AdminGetFeatureExampleReq struct {
|
type AdminGetFeatureExampleReq struct {
|
||||||
@@ -687,6 +706,37 @@ type AdminLoginResp struct {
|
|||||||
Roles []string `json:"roles"`
|
Roles []string `json:"roles"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type AdminOrderStatistics struct {
|
||||||
|
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"` // 变化率(百分比)
|
||||||
|
}
|
||||||
|
|
||||||
|
type AdminProfitDetail struct {
|
||||||
|
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"` // 利润率
|
||||||
|
}
|
||||||
|
|
||||||
|
type AdminProfitStatistics struct {
|
||||||
|
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"`
|
||||||
|
}
|
||||||
|
|
||||||
type AdminQueryItem struct {
|
type AdminQueryItem struct {
|
||||||
Feature interface{} `json:"feature"`
|
Feature interface{} `json:"feature"`
|
||||||
Data interface{} `json:"data"` // 这里可以是 map 或 具体的 struct
|
Data interface{} `json:"data"` // 这里可以是 map 或 具体的 struct
|
||||||
@@ -732,6 +782,14 @@ type AdminRetryAgentProcessResp struct {
|
|||||||
ProcessedAt string `json:"processed_at"` // 处理时间
|
ProcessedAt string `json:"processed_at"` // 处理时间
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type AdminRevenueStatistics struct {
|
||||||
|
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"` // 变化率(百分比)
|
||||||
|
}
|
||||||
|
|
||||||
type AdminRoleApiInfo struct {
|
type AdminRoleApiInfo struct {
|
||||||
Id string `json:"id"`
|
Id string `json:"id"`
|
||||||
RoleId string `json:"role_id"`
|
RoleId string `json:"role_id"`
|
||||||
@@ -744,6 +802,11 @@ type AdminRoleApiInfo struct {
|
|||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type AdminTrendData struct {
|
||||||
|
Date string `json:"date"` // 日期(格式:MM-DD)
|
||||||
|
Value float64 `json:"value"` // 数值
|
||||||
|
}
|
||||||
|
|
||||||
type AdminUpdateAgentConfigReq struct {
|
type AdminUpdateAgentConfigReq struct {
|
||||||
LevelBonus *LevelBonusConfig `json:"level_bonus,optional"` // 等级加成配置
|
LevelBonus *LevelBonusConfig `json:"level_bonus,optional"` // 等级加成配置
|
||||||
UpgradeFee *UpgradeFeeConfig `json:"upgrade_fee,optional"` // 升级费用配置
|
UpgradeFee *UpgradeFeeConfig `json:"upgrade_fee,optional"` // 升级费用配置
|
||||||
@@ -788,9 +851,11 @@ type AdminUpdateApiResp struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type AdminUpdateFeatureReq struct {
|
type AdminUpdateFeatureReq struct {
|
||||||
Id string `path:"id"` // 功能ID
|
Id string `path:"id"` // 功能ID
|
||||||
ApiId *string `json:"api_id,optional"` // API标识
|
ApiId *string `json:"api_id,optional"` // API标识
|
||||||
Name *string `json:"name,optional"` // 描述
|
Name *string `json:"name,optional"` // 描述
|
||||||
|
WhitelistPrice *float64 `json:"whitelist_price,optional"` // 白名单屏蔽价格(单位:元)
|
||||||
|
CostPrice *float64 `json:"cost_price,optional"` // 天远API调用成本价(单位:元)
|
||||||
}
|
}
|
||||||
|
|
||||||
type AdminUpdateFeatureResp struct {
|
type AdminUpdateFeatureResp struct {
|
||||||
@@ -1130,6 +1195,27 @@ type BindMobileResp struct {
|
|||||||
RefreshAfter int64 `json:"refreshAfter"`
|
RefreshAfter int64 `json:"refreshAfter"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type CheckFeatureWhitelistStatusReq struct {
|
||||||
|
IdCard string `form:"id_card"` // 身份证号
|
||||||
|
FeatureApiId string `form:"feature_api_id"` // Feature的API标识
|
||||||
|
QueryId string `form:"query_id,optional"` // 查询记录ID(可选)
|
||||||
|
}
|
||||||
|
|
||||||
|
type CheckFeatureWhitelistStatusResp struct {
|
||||||
|
IsWhitelisted bool `json:"is_whitelisted"` // 是否在白名单中
|
||||||
|
WhitelistPrice float64 `json:"whitelist_price"` // 屏蔽价格(单位:元),0表示不支持下架
|
||||||
|
FeatureId string `json:"feature_id"` // Feature的UUID
|
||||||
|
DataDeleted bool `json:"data_deleted"` // 报告数据是否已删除
|
||||||
|
}
|
||||||
|
|
||||||
|
type CheckOrderAgentReq struct {
|
||||||
|
OrderId string `form:"order_id"` // 订单ID
|
||||||
|
}
|
||||||
|
|
||||||
|
type CheckOrderAgentResp struct {
|
||||||
|
IsAgentOrder bool `json:"is_agent_order"` // 是否是当前代理推广的订单
|
||||||
|
}
|
||||||
|
|
||||||
type CommissionFreezeConfig struct {
|
type CommissionFreezeConfig struct {
|
||||||
Ratio float64 `json:"ratio"` // 佣金冻结比例(例如:0.1表示10%)
|
Ratio float64 `json:"ratio"` // 佣金冻结比例(例如:0.1表示10%)
|
||||||
Threshold float64 `json:"threshold"` // 佣金冻结阈值(订单单价达到此金额才触发冻结,单位:元)
|
Threshold float64 `json:"threshold"` // 佣金冻结阈值(订单单价达到此金额才触发冻结,单位:元)
|
||||||
@@ -1186,6 +1272,18 @@ type CreateRoleResp struct {
|
|||||||
Id string `json:"id"` // 角色ID
|
Id string `json:"id"` // 角色ID
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type CreateWhitelistOrderReq struct {
|
||||||
|
IdCard string `json:"id_card"` // 身份证号(查询对象标识)
|
||||||
|
FeatureIds []string `json:"feature_ids"` // 要屏蔽的feature ID列表
|
||||||
|
OrderId string `json:"order_id,optional"` // 关联的查询订单ID(可选)
|
||||||
|
}
|
||||||
|
|
||||||
|
type CreateWhitelistOrderResp struct {
|
||||||
|
OrderId string `json:"order_id"` // 订单ID
|
||||||
|
OrderNo string `json:"order_no"` // 订单号
|
||||||
|
TotalAmount float64 `json:"total_amount"` // 总金额
|
||||||
|
}
|
||||||
|
|
||||||
type DeleteInviteCodeReq struct {
|
type DeleteInviteCodeReq struct {
|
||||||
Id string `json:"id"` // 邀请码ID
|
Id string `json:"id"` // 邀请码ID
|
||||||
}
|
}
|
||||||
@@ -1231,11 +1329,13 @@ type Feature struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type FeatureListItem struct {
|
type FeatureListItem struct {
|
||||||
Id string `json:"id"` // 功能ID
|
Id string `json:"id"` // 功能ID
|
||||||
ApiId string `json:"api_id"` // API标识
|
ApiId string `json:"api_id"` // API标识
|
||||||
Name string `json:"name"` // 描述
|
Name string `json:"name"` // 描述
|
||||||
CreateTime string `json:"create_time"` // 创建时间
|
WhitelistPrice float64 `json:"whitelist_price"` // 白名单屏蔽价格(单位:元)
|
||||||
UpdateTime string `json:"update_time"` // 更新时间
|
CostPrice float64 `json:"cost_price"` // 天远API调用成本价(单位:元)
|
||||||
|
CreateTime string `json:"create_time"` // 创建时间
|
||||||
|
UpdateTime string `json:"update_time"` // 更新时间
|
||||||
}
|
}
|
||||||
|
|
||||||
type GenerateInviteCodeReq struct {
|
type GenerateInviteCodeReq struct {
|
||||||
@@ -1515,6 +1615,24 @@ type GetUpgradeRebateListResp struct {
|
|||||||
List []UpgradeRebateItem `json:"list"` // 列表
|
List []UpgradeRebateItem `json:"list"` // 列表
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type GetWhitelistFeaturesReq struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
type GetWhitelistFeaturesResp struct {
|
||||||
|
List []WhitelistFeatureItem `json:"list"` // 可屏蔽的feature列表
|
||||||
|
}
|
||||||
|
|
||||||
|
type GetWhitelistListReq struct {
|
||||||
|
Page int64 `form:"page"` // 页码
|
||||||
|
PageSize int64 `form:"page_size"` // 每页数量
|
||||||
|
IdCard string `form:"id_card,optional"` // 身份证号(可选,用于筛选)
|
||||||
|
}
|
||||||
|
|
||||||
|
type GetWhitelistListResp struct {
|
||||||
|
Total int64 `json:"total"` // 总数
|
||||||
|
List []WhitelistItem `json:"list"` // 列表
|
||||||
|
}
|
||||||
|
|
||||||
type GetWithdrawalListReq struct {
|
type GetWithdrawalListReq struct {
|
||||||
Page int64 `form:"page"` // 页码
|
Page int64 `form:"page"` // 页码
|
||||||
PageSize int64 `form:"page_size"` // 每页数量
|
PageSize int64 `form:"page_size"` // 每页数量
|
||||||
@@ -1647,6 +1765,17 @@ type NotificationListItem struct {
|
|||||||
UpdateTime string `json:"update_time"` // 更新时间
|
UpdateTime string `json:"update_time"` // 更新时间
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type OfflineFeatureReq struct {
|
||||||
|
FeatureApiId string `json:"feature_api_id"` // Feature的API标识
|
||||||
|
QueryId string `json:"query_id"` // 查询记录ID(Query表的ID,必选)
|
||||||
|
}
|
||||||
|
|
||||||
|
type OfflineFeatureResp struct {
|
||||||
|
Success bool `json:"success"` // 是否已完成下架
|
||||||
|
NeedPay bool `json:"need_pay"` // 是否需要发起支付
|
||||||
|
Amount float64 `json:"amount"` // 需要支付的金额(元),0表示无需支付
|
||||||
|
}
|
||||||
|
|
||||||
type OrderItem struct {
|
type OrderItem struct {
|
||||||
OrderNo string `json:"order_no"` // 订单号
|
OrderNo string `json:"order_no"` // 订单号
|
||||||
ProductId string `json:"product_id"` // 产品ID
|
ProductId string `json:"product_id"` // 产品ID
|
||||||
@@ -1691,7 +1820,7 @@ type PaymentCheckResp struct {
|
|||||||
type PaymentReq struct {
|
type PaymentReq struct {
|
||||||
Id string `json:"id"`
|
Id string `json:"id"`
|
||||||
PayMethod string `json:"pay_method"` // 支付方式: wechat, alipay, appleiap, test(仅开发环境), test_empty(仅开发环境-空报告模式)
|
PayMethod string `json:"pay_method"` // 支付方式: wechat, alipay, appleiap, test(仅开发环境), test_empty(仅开发环境-空报告模式)
|
||||||
PayType string `json:"pay_type" validate:"required,oneof=query agent_vip agent_upgrade"`
|
PayType string `json:"pay_type" validate:"required,oneof=query agent_vip agent_upgrade whitelist"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type PaymentResp struct {
|
type PaymentResp struct {
|
||||||
@@ -2134,6 +2263,25 @@ type WXMiniAuthResp struct {
|
|||||||
RefreshAfter int64 `json:"refreshAfter"`
|
RefreshAfter int64 `json:"refreshAfter"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type WhitelistFeatureItem struct {
|
||||||
|
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"` // 屏蔽价格(单位:元)
|
||||||
|
}
|
||||||
|
|
||||||
|
type WhitelistItem struct {
|
||||||
|
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"` // 创建时间
|
||||||
|
}
|
||||||
|
|
||||||
type WithdrawalItem struct {
|
type WithdrawalItem struct {
|
||||||
Id string `json:"id"` // 记录ID
|
Id string `json:"id"` // 记录ID
|
||||||
WithdrawalNo string `json:"withdrawal_no"` // 提现单号
|
WithdrawalNo string `json:"withdrawal_no"` // 提现单号
|
||||||
|
|||||||
@@ -11,8 +11,6 @@ import (
|
|||||||
"reflect"
|
"reflect"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"qnc-server/common/globalkey"
|
|
||||||
|
|
||||||
"github.com/Masterminds/squirrel"
|
"github.com/Masterminds/squirrel"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
@@ -21,6 +19,7 @@ import (
|
|||||||
"github.com/zeromicro/go-zero/core/stores/sqlc"
|
"github.com/zeromicro/go-zero/core/stores/sqlc"
|
||||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||||
"github.com/zeromicro/go-zero/core/stringx"
|
"github.com/zeromicro/go-zero/core/stringx"
|
||||||
|
"qnc-server/common/globalkey"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -59,14 +58,16 @@ type (
|
|||||||
}
|
}
|
||||||
|
|
||||||
Feature struct {
|
Feature struct {
|
||||||
Id string `db:"id"`
|
Id string `db:"id"`
|
||||||
CreateTime time.Time `db:"create_time"` // 创建时间
|
CreateTime time.Time `db:"create_time"` // 创建时间
|
||||||
UpdateTime time.Time `db:"update_time"` // 更新时间
|
UpdateTime time.Time `db:"update_time"` // 更新时间
|
||||||
DeleteTime sql.NullTime `db:"delete_time"` // 删除时间
|
DeleteTime sql.NullTime `db:"delete_time"` // 删除时间
|
||||||
DelState int64 `db:"del_state"` // 删除状态
|
DelState int64 `db:"del_state"` // 删除状态
|
||||||
Version int64 `db:"version"` // 版本号
|
Version int64 `db:"version"` // 版本号
|
||||||
ApiId string `db:"api_id"` // API标识
|
ApiId string `db:"api_id"` // API标识
|
||||||
Name string `db:"name"` // 描述
|
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,
|
|||||||
qncFeatureApiIdKey := fmt.Sprintf("%s%v", cacheQncFeatureApiIdPrefix, data.ApiId)
|
qncFeatureApiIdKey := fmt.Sprintf("%s%v", cacheQncFeatureApiIdPrefix, data.ApiId)
|
||||||
qncFeatureIdKey := fmt.Sprintf("%s%v", cacheQncFeatureIdPrefix, data.Id)
|
qncFeatureIdKey := fmt.Sprintf("%s%v", cacheQncFeatureIdPrefix, data.Id)
|
||||||
return m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
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 {
|
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)
|
||||||
}, qncFeatureApiIdKey, qncFeatureIdKey)
|
}, qncFeatureApiIdKey, qncFeatureIdKey)
|
||||||
}
|
}
|
||||||
func (m *defaultFeatureModel) insertUUID(data *Feature) {
|
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) {
|
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)
|
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, featureRowsWithPlaceHolder)
|
||||||
if session != nil {
|
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)
|
||||||
}, qncFeatureApiIdKey, qncFeatureIdKey)
|
}, qncFeatureApiIdKey, qncFeatureIdKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -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) {
|
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)
|
query := fmt.Sprintf("update %s set %s where `id` = ? and version = ? ", m.table, featureRowsWithPlaceHolder)
|
||||||
if session != nil {
|
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)
|
||||||
}, qncFeatureApiIdKey, qncFeatureIdKey)
|
}, qncFeatureApiIdKey, qncFeatureIdKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
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),
|
||||||
|
}
|
||||||
|
}
|
||||||
398
app/main/model/tianyuanapiCallLogModel_gen.go
Normal file
398
app/main/model/tianyuanapiCallLogModel_gen.go
Normal file
@@ -0,0 +1,398 @@
|
|||||||
|
// Code generated by goctl. DO NOT EDIT!
|
||||||
|
|
||||||
|
package model
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"database/sql"
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"reflect"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"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"
|
||||||
|
"qnc-server/common/globalkey"
|
||||||
|
)
|
||||||
|
|
||||||
|
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`"), "=?,") + "=?"
|
||||||
|
|
||||||
|
cacheQncTianyuanapiCallLogIdPrefix = "cache:qnc: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"`
|
||||||
|
FeatureId string `db:"feature_id"` // 功能ID(关联feature表)
|
||||||
|
ApiId string `db:"api_id"` // API标识
|
||||||
|
OrderId sql.NullString `db:"order_id"` // 订单ID
|
||||||
|
QueryId sql.NullString `db:"query_id"` // 查询ID
|
||||||
|
CallStatus int64 `db:"call_status"` // 调用状态:0=失败,1=成功
|
||||||
|
CallTime time.Time `db:"call_time"` // 调用时间
|
||||||
|
ResponseTime sql.NullInt64 `db:"response_time"` // 响应耗时(毫秒)
|
||||||
|
CostPrice float64 `db:"cost_price"` // 本次调用成本(元)
|
||||||
|
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)
|
||||||
|
qncTianyuanapiCallLogIdKey := fmt.Sprintf("%s%v", cacheQncTianyuanapiCallLogIdPrefix, 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)
|
||||||
|
}, qncTianyuanapiCallLogIdKey)
|
||||||
|
}
|
||||||
|
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) {
|
||||||
|
qncTianyuanapiCallLogIdKey := fmt.Sprintf("%s%v", cacheQncTianyuanapiCallLogIdPrefix, id)
|
||||||
|
var resp TianyuanapiCallLog
|
||||||
|
err := m.QueryRowCtx(ctx, &resp, qncTianyuanapiCallLogIdKey, 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) {
|
||||||
|
qncTianyuanapiCallLogIdKey := fmt.Sprintf("%s%v", cacheQncTianyuanapiCallLogIdPrefix, 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)
|
||||||
|
}, qncTianyuanapiCallLogIdKey)
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
qncTianyuanapiCallLogIdKey := fmt.Sprintf("%s%v", cacheQncTianyuanapiCallLogIdPrefix, 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)
|
||||||
|
}, qncTianyuanapiCallLogIdKey)
|
||||||
|
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 {
|
||||||
|
qncTianyuanapiCallLogIdKey := fmt.Sprintf("%s%v", cacheQncTianyuanapiCallLogIdPrefix, 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)
|
||||||
|
}, qncTianyuanapiCallLogIdKey)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
func (m *defaultTianyuanapiCallLogModel) formatPrimary(primary interface{}) string {
|
||||||
|
return fmt.Sprintf("%s%v", cacheQncTianyuanapiCallLogIdPrefix, 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),
|
||||||
|
}
|
||||||
|
}
|
||||||
432
app/main/model/userFeatureWhitelistModel_gen.go
Normal file
432
app/main/model/userFeatureWhitelistModel_gen.go
Normal file
@@ -0,0 +1,432 @@
|
|||||||
|
// Code generated by goctl. DO NOT EDIT!
|
||||||
|
|
||||||
|
package model
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"database/sql"
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"reflect"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"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"
|
||||||
|
"qnc-server/common/globalkey"
|
||||||
|
)
|
||||||
|
|
||||||
|
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`"), "=?,") + "=?"
|
||||||
|
|
||||||
|
cacheQncUserFeatureWhitelistIdPrefix = "cache:qnc:userFeatureWhitelist:id:"
|
||||||
|
cacheQncUserFeatureWhitelistIdCardFeatureApiIdDelStatePrefix = "cache:qnc:userFeatureWhitelist:idCard:featureApiId:delState:"
|
||||||
|
)
|
||||||
|
|
||||||
|
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)
|
||||||
|
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
|
||||||
|
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)
|
||||||
|
qncUserFeatureWhitelistIdCardFeatureApiIdDelStateKey := fmt.Sprintf("%s%v:%v:%v", cacheQncUserFeatureWhitelistIdCardFeatureApiIdDelStatePrefix, data.IdCard, data.FeatureApiId, data.DelState)
|
||||||
|
qncUserFeatureWhitelistIdKey := fmt.Sprintf("%s%v", cacheQncUserFeatureWhitelistIdPrefix, 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, 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)
|
||||||
|
}, qncUserFeatureWhitelistIdCardFeatureApiIdDelStateKey, qncUserFeatureWhitelistIdKey)
|
||||||
|
}
|
||||||
|
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) {
|
||||||
|
qncUserFeatureWhitelistIdKey := fmt.Sprintf("%s%v", cacheQncUserFeatureWhitelistIdPrefix, id)
|
||||||
|
var resp UserFeatureWhitelist
|
||||||
|
err := m.QueryRowCtx(ctx, &resp, qncUserFeatureWhitelistIdKey, 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) {
|
||||||
|
qncUserFeatureWhitelistIdCardFeatureApiIdDelStateKey := fmt.Sprintf("%s%v:%v:%v", cacheQncUserFeatureWhitelistIdCardFeatureApiIdDelStatePrefix, idCard, featureApiId, delState)
|
||||||
|
var resp UserFeatureWhitelist
|
||||||
|
err := m.QueryRowIndexCtx(ctx, &resp, qncUserFeatureWhitelistIdCardFeatureApiIdDelStateKey, 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) 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
|
||||||
|
}
|
||||||
|
qncUserFeatureWhitelistIdCardFeatureApiIdDelStateKey := fmt.Sprintf("%s%v:%v:%v", cacheQncUserFeatureWhitelistIdCardFeatureApiIdDelStatePrefix, data.IdCard, data.FeatureApiId, data.DelState)
|
||||||
|
qncUserFeatureWhitelistIdKey := fmt.Sprintf("%s%v", cacheQncUserFeatureWhitelistIdPrefix, 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, 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)
|
||||||
|
}, qncUserFeatureWhitelistIdCardFeatureApiIdDelStateKey, qncUserFeatureWhitelistIdKey)
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
qncUserFeatureWhitelistIdCardFeatureApiIdDelStateKey := fmt.Sprintf("%s%v:%v:%v", cacheQncUserFeatureWhitelistIdCardFeatureApiIdDelStatePrefix, data.IdCard, data.FeatureApiId, data.DelState)
|
||||||
|
qncUserFeatureWhitelistIdKey := fmt.Sprintf("%s%v", cacheQncUserFeatureWhitelistIdPrefix, 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, 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)
|
||||||
|
}, qncUserFeatureWhitelistIdCardFeatureApiIdDelStateKey, qncUserFeatureWhitelistIdKey)
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
qncUserFeatureWhitelistIdCardFeatureApiIdDelStateKey := fmt.Sprintf("%s%v:%v:%v", cacheQncUserFeatureWhitelistIdCardFeatureApiIdDelStatePrefix, data.IdCard, data.FeatureApiId, data.DelState)
|
||||||
|
qncUserFeatureWhitelistIdKey := fmt.Sprintf("%s%v", cacheQncUserFeatureWhitelistIdPrefix, 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)
|
||||||
|
}, qncUserFeatureWhitelistIdCardFeatureApiIdDelStateKey, qncUserFeatureWhitelistIdKey)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
func (m *defaultUserFeatureWhitelistModel) formatPrimary(primary interface{}) string {
|
||||||
|
return fmt.Sprintf("%s%v", cacheQncUserFeatureWhitelistIdPrefix, 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"
|
||||||
|
|
||||||
|
"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"
|
||||||
|
"qnc-server/common/globalkey"
|
||||||
|
)
|
||||||
|
|
||||||
|
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`"), "=?,") + "=?"
|
||||||
|
|
||||||
|
cacheQncWhitelistOrderItemIdPrefix = "cache:qnc: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)
|
||||||
|
qncWhitelistOrderItemIdKey := fmt.Sprintf("%s%v", cacheQncWhitelistOrderItemIdPrefix, 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)
|
||||||
|
}, qncWhitelistOrderItemIdKey)
|
||||||
|
}
|
||||||
|
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) {
|
||||||
|
qncWhitelistOrderItemIdKey := fmt.Sprintf("%s%v", cacheQncWhitelistOrderItemIdPrefix, id)
|
||||||
|
var resp WhitelistOrderItem
|
||||||
|
err := m.QueryRowCtx(ctx, &resp, qncWhitelistOrderItemIdKey, 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) {
|
||||||
|
qncWhitelistOrderItemIdKey := fmt.Sprintf("%s%v", cacheQncWhitelistOrderItemIdPrefix, 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)
|
||||||
|
}, qncWhitelistOrderItemIdKey)
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
qncWhitelistOrderItemIdKey := fmt.Sprintf("%s%v", cacheQncWhitelistOrderItemIdPrefix, 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)
|
||||||
|
}, qncWhitelistOrderItemIdKey)
|
||||||
|
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 {
|
||||||
|
qncWhitelistOrderItemIdKey := fmt.Sprintf("%s%v", cacheQncWhitelistOrderItemIdPrefix, 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)
|
||||||
|
}, qncWhitelistOrderItemIdKey)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
func (m *defaultWhitelistOrderItemModel) formatPrimary(primary interface{}) string {
|
||||||
|
return fmt.Sprintf("%s%v", cacheQncWhitelistOrderItemIdPrefix, 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"
|
||||||
|
|
||||||
|
"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"
|
||||||
|
"qnc-server/common/globalkey"
|
||||||
|
)
|
||||||
|
|
||||||
|
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`"), "=?,") + "=?"
|
||||||
|
|
||||||
|
cacheQncWhitelistOrderIdPrefix = "cache:qnc:whitelistOrder:id:"
|
||||||
|
cacheQncWhitelistOrderOrderNoPrefix = "cache:qnc: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"` // 支付平台
|
||||||
|
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)
|
||||||
|
qncWhitelistOrderIdKey := fmt.Sprintf("%s%v", cacheQncWhitelistOrderIdPrefix, data.Id)
|
||||||
|
qncWhitelistOrderOrderNoKey := fmt.Sprintf("%s%v", cacheQncWhitelistOrderOrderNoPrefix, 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)
|
||||||
|
}, qncWhitelistOrderIdKey, qncWhitelistOrderOrderNoKey)
|
||||||
|
}
|
||||||
|
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) {
|
||||||
|
qncWhitelistOrderIdKey := fmt.Sprintf("%s%v", cacheQncWhitelistOrderIdPrefix, id)
|
||||||
|
var resp WhitelistOrder
|
||||||
|
err := m.QueryRowCtx(ctx, &resp, qncWhitelistOrderIdKey, 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) {
|
||||||
|
qncWhitelistOrderOrderNoKey := fmt.Sprintf("%s%v", cacheQncWhitelistOrderOrderNoPrefix, orderNo)
|
||||||
|
var resp WhitelistOrder
|
||||||
|
err := m.QueryRowIndexCtx(ctx, &resp, qncWhitelistOrderOrderNoKey, 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
|
||||||
|
}
|
||||||
|
qncWhitelistOrderIdKey := fmt.Sprintf("%s%v", cacheQncWhitelistOrderIdPrefix, data.Id)
|
||||||
|
qncWhitelistOrderOrderNoKey := fmt.Sprintf("%s%v", cacheQncWhitelistOrderOrderNoPrefix, 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)
|
||||||
|
}, qncWhitelistOrderIdKey, qncWhitelistOrderOrderNoKey)
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
qncWhitelistOrderIdKey := fmt.Sprintf("%s%v", cacheQncWhitelistOrderIdPrefix, data.Id)
|
||||||
|
qncWhitelistOrderOrderNoKey := fmt.Sprintf("%s%v", cacheQncWhitelistOrderOrderNoPrefix, 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)
|
||||||
|
}, qncWhitelistOrderIdKey, qncWhitelistOrderOrderNoKey)
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
qncWhitelistOrderIdKey := fmt.Sprintf("%s%v", cacheQncWhitelistOrderIdPrefix, id)
|
||||||
|
qncWhitelistOrderOrderNoKey := fmt.Sprintf("%s%v", cacheQncWhitelistOrderOrderNoPrefix, 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)
|
||||||
|
}, qncWhitelistOrderIdKey, qncWhitelistOrderOrderNoKey)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
func (m *defaultWhitelistOrderModel) formatPrimary(primary interface{}) string {
|
||||||
|
return fmt.Sprintf("%s%v", cacheQncWhitelistOrderIdPrefix, 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
|
||||||
|
}
|
||||||
@@ -10,6 +10,14 @@ $HOME_DIR = Join-Path $PSScriptRoot "..\template"
|
|||||||
|
|
||||||
# 表名列表
|
# 表名列表
|
||||||
$tables = @(
|
$tables = @(
|
||||||
|
# ============================================
|
||||||
|
# 统计/白名单/成本价 同步用(执行 sync_whitelist_cost_tables.sql 后再生成)
|
||||||
|
# ============================================
|
||||||
|
"feature",
|
||||||
|
"tianyuanapi_call_log",
|
||||||
|
"user_feature_whitelist",
|
||||||
|
"whitelist_order",
|
||||||
|
"whitelist_order_item"
|
||||||
# ============================================
|
# ============================================
|
||||||
# 新代理系统表
|
# 新代理系统表
|
||||||
# ============================================
|
# ============================================
|
||||||
@@ -56,7 +64,7 @@ $tables = @(
|
|||||||
# "query_cleanup_config",
|
# "query_cleanup_config",
|
||||||
# "query_cleanup_detail",
|
# "query_cleanup_detail",
|
||||||
# "query_cleanup_log",
|
# "query_cleanup_log",
|
||||||
"user"
|
# "user"
|
||||||
# "user_auth"
|
# "user_auth"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user