add config
This commit is contained in:
@@ -92,7 +92,8 @@ type YushanConfig struct {
|
||||
Url string
|
||||
}
|
||||
type SystemConfig struct {
|
||||
ThreeVerify bool
|
||||
ThreeVerify bool // 是否开启三级实名认证
|
||||
CommissionSafeMode bool // 佣金安全防御模式:true-冻结模式(status=1,进入frozen_balance),false-直接结算(status=0,进入balance)
|
||||
}
|
||||
type WechatH5Config struct {
|
||||
AppID string
|
||||
|
||||
@@ -3,12 +3,13 @@ package admin_agent
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"tydata-server/app/main/api/internal/logic/admin_agent"
|
||||
"tydata-server/app/main/api/internal/svc"
|
||||
"tydata-server/app/main/api/internal/types"
|
||||
"tydata-server/common/result"
|
||||
"tydata-server/pkg/lzkit/validator"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
)
|
||||
|
||||
func AdminBatchUnfreezeAgentCommissionHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package admin_agent
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"tydata-server/app/main/api/internal/logic/admin_agent"
|
||||
"tydata-server/app/main/api/internal/svc"
|
||||
"tydata-server/common/result"
|
||||
)
|
||||
|
||||
func AdminGetSystemConfigHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
l := admin_agent.NewAdminGetSystemConfigLogic(r.Context(), svcCtx)
|
||||
resp, err := l.AdminGetSystemConfig()
|
||||
result.HttpResult(r, w, resp, err)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package admin_agent
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"tydata-server/app/main/api/internal/logic/admin_agent"
|
||||
"tydata-server/app/main/api/internal/svc"
|
||||
"tydata-server/app/main/api/internal/types"
|
||||
"tydata-server/common/result"
|
||||
"tydata-server/pkg/lzkit/validator"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
)
|
||||
|
||||
func AdminUpdateSystemConfigHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.AdminUpdateSystemConfigReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
result.ParamErrorResult(r, w, err)
|
||||
return
|
||||
}
|
||||
if err := validator.Validate(req); err != nil {
|
||||
result.ParamValidateErrorResult(r, w, err)
|
||||
return
|
||||
}
|
||||
l := admin_agent.NewAdminUpdateSystemConfigLogic(r.Context(), svcCtx)
|
||||
resp, err := l.AdminUpdateSystemConfig(&req)
|
||||
result.HttpResult(r, w, resp, err)
|
||||
}
|
||||
}
|
||||
@@ -132,6 +132,16 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||
Path: "/statistics",
|
||||
Handler: admin_agent.AdminGetAgentStatisticsHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/system-config",
|
||||
Handler: admin_agent.AdminGetSystemConfigHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Path: "/system-config",
|
||||
Handler: admin_agent.AdminUpdateSystemConfigHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/wallet/:agent_id",
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
package admin_agent
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"tydata-server/app/main/api/internal/svc"
|
||||
"tydata-server/app/main/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type AdminGetSystemConfigLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewAdminGetSystemConfigLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AdminGetSystemConfigLogic {
|
||||
return &AdminGetSystemConfigLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *AdminGetSystemConfigLogic) AdminGetSystemConfig() (resp *types.AdminGetSystemConfigResp, err error) {
|
||||
resp = &types.AdminGetSystemConfigResp{
|
||||
CommissionSafeMode: l.svcCtx.Config.SystemConfig.CommissionSafeMode,
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package admin_agent
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"tydata-server/app/main/api/internal/svc"
|
||||
"tydata-server/app/main/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type AdminUpdateSystemConfigLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewAdminUpdateSystemConfigLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AdminUpdateSystemConfigLogic {
|
||||
return &AdminUpdateSystemConfigLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *AdminUpdateSystemConfigLogic) AdminUpdateSystemConfig(req *types.AdminUpdateSystemConfigReq) (resp *types.AdminUpdateSystemConfigResp, err error) {
|
||||
// 更新佣金安全防御模式配置
|
||||
if req.CommissionSafeMode != nil {
|
||||
l.svcCtx.Config.SystemConfig.CommissionSafeMode = *req.CommissionSafeMode
|
||||
logx.Infof("更新系统配置:佣金安全防御模式设置为 %v", *req.CommissionSafeMode)
|
||||
}
|
||||
|
||||
resp = &types.AdminUpdateSystemConfigResp{
|
||||
Success: true,
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -142,19 +142,28 @@ func (l *AgentService) AgentProcess(ctx context.Context, order *model.Order) err
|
||||
if findAgentWalletModelErr != nil {
|
||||
return findAgentWalletModelErr
|
||||
}
|
||||
// 奖励不冻结
|
||||
// 奖励不冻结,直接进入balance
|
||||
ancestorWallet.Balance += ancestorCommissionReward
|
||||
|
||||
// 冻结
|
||||
ancestorWallet.FrozenBalance += ancestorCommissionAmount
|
||||
// 根据安全防御模式配置决定佣金处理方式
|
||||
var commissionStatus int64
|
||||
if l.config.SystemConfig.CommissionSafeMode {
|
||||
// 安全防御模式:佣金冻结在frozen_balance中
|
||||
ancestorWallet.FrozenBalance += ancestorCommissionAmount
|
||||
commissionStatus = 1 // 冻结状态
|
||||
} else {
|
||||
// 非安全防御模式:佣金直接进入balance
|
||||
ancestorWallet.Balance += ancestorCommissionAmount
|
||||
commissionStatus = 0 // 已结算状态
|
||||
}
|
||||
|
||||
// 为上级创建佣金记录(冻结金额)
|
||||
// 为上级创建佣金记录
|
||||
ancestorCommissionRecord := model.AgentCommission{
|
||||
AgentId: AncestorId,
|
||||
OrderId: order.Id,
|
||||
Amount: ancestorCommissionAmount,
|
||||
ProductId: order.ProductId,
|
||||
Status: 1, // 设置为冻结状态
|
||||
Status: commissionStatus,
|
||||
}
|
||||
_, insertAncestorCommissionErr := l.AgentCommissionModel.Insert(transCtx, session, &ancestorCommissionRecord)
|
||||
if insertAncestorCommissionErr != nil {
|
||||
@@ -182,13 +191,15 @@ func (l *AgentService) AgentProcess(ctx context.Context, order *model.Order) err
|
||||
return transErr
|
||||
}
|
||||
|
||||
// 在事务提交后,触发解冻任务(3天后自动解冻)
|
||||
// 注意:这里发送的是任务,实际解冻将在3天后由队列处理
|
||||
if l.AsynqService != nil {
|
||||
// 在事务提交后,仅在安全防御模式下触发解冻任务
|
||||
// 注意:这里发送的是任务,实际解冻将在指定时间后由队列处理
|
||||
if l.AsynqService != nil && l.config.SystemConfig.CommissionSafeMode {
|
||||
// 仅在安全防御模式下,才需要发送解冻任务
|
||||
// 获取刚创建的佣金记录ID
|
||||
// 由于我们需要佣金记录ID来触发解冻任务,但事务中无法获取,我们可以在事务后查询
|
||||
builder := l.AgentCommissionModel.SelectBuilder().
|
||||
Where("order_id = ?", order.Id).
|
||||
Where("status = ?", 1). // 只查询状态为冻结的佣金
|
||||
Where("del_state = ?", globalkey.DelStateNo)
|
||||
|
||||
commissions, findErr := l.AgentCommissionModel.FindAll(ctx, builder, "")
|
||||
@@ -198,7 +209,7 @@ func (l *AgentService) AgentProcess(ctx context.Context, order *model.Order) err
|
||||
}
|
||||
|
||||
if len(commissions) > 0 {
|
||||
// 为所有新创建的佣金记录触发解冻任务
|
||||
// 为所有新创建的冻结佣金记录触发解冻任务
|
||||
for _, commission := range commissions {
|
||||
// 发送解冻任务,将在10小时后执行
|
||||
sendTaskErr := l.AsynqService.SendUnfreezeCommissionTask(commission.Id)
|
||||
@@ -224,15 +235,29 @@ func (l *AgentService) AgentCommission(ctx context.Context, agentID int64, order
|
||||
}
|
||||
// 推广人最终获得代理佣金
|
||||
finalCommission := order.Amount - deductedAmount
|
||||
agentWalletModel.FrozenBalance += finalCommission
|
||||
|
||||
// 根据安全防御模式配置决定佣金状态和钱包操作
|
||||
if l.config.SystemConfig.CommissionSafeMode {
|
||||
// 安全防御模式:佣金冻结在frozen_balance中
|
||||
agentWalletModel.FrozenBalance += finalCommission
|
||||
} else {
|
||||
// 非安全防御模式:佣金直接进入balance
|
||||
agentWalletModel.Balance += finalCommission
|
||||
}
|
||||
agentWalletModel.TotalEarnings += finalCommission
|
||||
|
||||
// 根据安全防御模式配置决定佣金状态
|
||||
commissionStatus := int64(1) // 默认为冻结状态
|
||||
if !l.config.SystemConfig.CommissionSafeMode {
|
||||
commissionStatus = 0 // 非安全模式直接设置为已结算
|
||||
}
|
||||
|
||||
agentCommission := model.AgentCommission{
|
||||
AgentId: agentID,
|
||||
OrderId: order.Id,
|
||||
Amount: finalCommission,
|
||||
ProductId: order.ProductId,
|
||||
Status: 1, // 设置为冻结状态
|
||||
Status: commissionStatus,
|
||||
}
|
||||
insertResult, insertAgentCommissionErr := l.AgentCommissionModel.Insert(ctx, session, &agentCommission)
|
||||
if insertAgentCommissionErr != nil {
|
||||
|
||||
@@ -691,6 +691,10 @@ type AdminGetRoleApiListResp struct {
|
||||
Items []AdminRoleApiInfo `json:"items"`
|
||||
}
|
||||
|
||||
type AdminGetSystemConfigResp struct {
|
||||
CommissionSafeMode bool `json:"commission_safe_mode"` // 佣金安全防御模式
|
||||
}
|
||||
|
||||
type AdminGetUserDetailReq struct {
|
||||
Id int64 `path:"id"` // 用户ID
|
||||
}
|
||||
@@ -976,6 +980,14 @@ type AdminUpdateRoleApiResp struct {
|
||||
Success bool `json:"success"`
|
||||
}
|
||||
|
||||
type AdminUpdateSystemConfigReq struct {
|
||||
CommissionSafeMode *bool `json:"commission_safe_mode,optional"` // 佣金安全防御模式:true-冻结模式,false-直接结算模式
|
||||
}
|
||||
|
||||
type AdminUpdateSystemConfigResp struct {
|
||||
Success bool `json:"success"` // 是否成功
|
||||
}
|
||||
|
||||
type AdminUpdateUserReq struct {
|
||||
Id int64 `path:"id"` // 用户ID
|
||||
Username *string `json:"username,optional"` // 用户名
|
||||
|
||||
Reference in New Issue
Block a user