f
This commit is contained in:
@@ -2,6 +2,7 @@ package admin_agent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
|
||||
"bdrp-server/app/main/api/internal/svc"
|
||||
"bdrp-server/app/main/api/internal/types"
|
||||
@@ -38,11 +39,19 @@ func (l *AdminGetAgentCommissionDeductionListLogic) AdminGetAgentCommissionDeduc
|
||||
}
|
||||
// 产品名筛选需先查product_id
|
||||
if req.ProductName != nil && *req.ProductName != "" {
|
||||
products, err := l.svcCtx.ProductModel.FindAll(l.ctx, l.svcCtx.ProductModel.SelectBuilder().Where(squirrel.Eq{"product_name": *req.ProductName}), "")
|
||||
products, err := l.svcCtx.ProductModel.FindAll(
|
||||
l.ctx,
|
||||
l.svcCtx.ProductModel.SelectBuilder().Where(squirrel.Like{"product_name": "%" + strings.TrimSpace(*req.ProductName) + "%"}),
|
||||
"",
|
||||
)
|
||||
if err != nil || len(products) == 0 {
|
||||
return &types.AdminGetAgentCommissionDeductionListResp{Total: 0, Items: []types.AgentCommissionDeductionListItem{}}, nil
|
||||
}
|
||||
builder = builder.Where("product_id = ?", products[0].Id)
|
||||
productIds := make([]int64, 0, len(products))
|
||||
for _, product := range products {
|
||||
productIds = append(productIds, product.Id)
|
||||
}
|
||||
builder = builder.Where(squirrel.Eq{"product_id": productIds})
|
||||
}
|
||||
|
||||
list, total, err := l.svcCtx.AgentCommissionDeductionModel.FindPageListByPageWithTotal(l.ctx, builder, req.Page, req.PageSize, "create_time DESC")
|
||||
|
||||
@@ -2,6 +2,7 @@ package admin_agent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
|
||||
"bdrp-server/app/main/api/internal/svc"
|
||||
"bdrp-server/app/main/api/internal/types"
|
||||
@@ -30,19 +31,25 @@ func (l *AdminGetAgentLinkListLogic) AdminGetAgentLinkList(req *types.AdminGetAg
|
||||
builder = builder.Where("agent_id = ?", *req.AgentId)
|
||||
}
|
||||
if req.LinkIdentifier != nil && *req.LinkIdentifier != "" {
|
||||
builder = builder.Where("link_identifier = ?", *req.LinkIdentifier)
|
||||
builder = builder.Where("link_identifier LIKE ?", "%"+strings.TrimSpace(*req.LinkIdentifier)+"%")
|
||||
}
|
||||
|
||||
// 先查出所有product_id对应的product_name(如有product_name筛选,需反查id)
|
||||
var productIdFilter int64
|
||||
if req.ProductName != nil && *req.ProductName != "" {
|
||||
// 只支持精确匹配,如需模糊可扩展
|
||||
products, err := l.svcCtx.ProductModel.FindAll(l.ctx, l.svcCtx.ProductModel.SelectBuilder().Where(squirrel.Eq{"product_name": *req.ProductName}), "")
|
||||
products, err := l.svcCtx.ProductModel.FindAll(
|
||||
l.ctx,
|
||||
l.svcCtx.ProductModel.SelectBuilder().Where("product_name LIKE ?", "%"+strings.TrimSpace(*req.ProductName)+"%"),
|
||||
"",
|
||||
)
|
||||
if err != nil || len(products) == 0 {
|
||||
return &types.AdminGetAgentLinkListResp{Total: 0, Items: []types.AgentLinkListItem{}}, nil
|
||||
}
|
||||
productIdFilter = products[0].Id
|
||||
builder = builder.Where("product_id = ?", productIdFilter)
|
||||
|
||||
productIds := make([]int64, 0, len(products))
|
||||
for _, product := range products {
|
||||
productIds = append(productIds, product.Id)
|
||||
}
|
||||
builder = builder.Where(squirrel.Eq{"product_id": productIds})
|
||||
}
|
||||
|
||||
links, total, err := l.svcCtx.AgentLinkModel.FindPageListByPageWithTotal(l.ctx, builder, req.Page, req.PageSize, "id DESC")
|
||||
|
||||
@@ -2,15 +2,14 @@ package admin_agent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
|
||||
"bdrp-server/app/main/api/internal/svc"
|
||||
"bdrp-server/app/main/api/internal/types"
|
||||
"bdrp-server/app/main/model"
|
||||
"bdrp-server/common/tool"
|
||||
"bdrp-server/common/xerr"
|
||||
"bdrp-server/pkg/lzkit/crypto"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
@@ -30,13 +29,20 @@ func NewAdminGetAgentListLogic(ctx context.Context, svcCtx *svc.ServiceContext)
|
||||
|
||||
func (l *AdminGetAgentListLogic) AdminGetAgentList(req *types.AdminGetAgentListReq) (resp *types.AdminGetAgentListResp, err error) {
|
||||
builder := l.svcCtx.AgentModel.SelectBuilder()
|
||||
if req.Mobile != nil && *req.Mobile != "" {
|
||||
builder = builder.Where("mobile = ?", *req.Mobile)
|
||||
secretKey := l.svcCtx.Config.Encrypt.SecretKey
|
||||
mobileKeyword := ""
|
||||
if req.Mobile != nil {
|
||||
mobileKeyword = strings.TrimSpace(*req.Mobile)
|
||||
}
|
||||
if req.Region != nil && *req.Region != "" {
|
||||
builder = builder.Where("region = ?", *req.Region)
|
||||
builder = builder.Where("region LIKE ?", "%"+strings.TrimSpace(*req.Region)+"%")
|
||||
}
|
||||
if req.CreateTimeStart != nil && *req.CreateTimeStart != "" {
|
||||
builder = builder.Where("create_time >= ?", *req.CreateTimeStart)
|
||||
}
|
||||
if req.CreateTimeEnd != nil && *req.CreateTimeEnd != "" {
|
||||
builder = builder.Where("create_time <= ?", *req.CreateTimeEnd)
|
||||
}
|
||||
|
||||
// 新增:如果传入ParentAgentId,则查找其所有1级下级代理
|
||||
if req.ParentAgentId != nil {
|
||||
closureBuilder := l.svcCtx.AgentClosureModel.SelectBuilder().Where("ancestor_id = ? AND depth = 1", *req.ParentAgentId)
|
||||
@@ -61,9 +67,49 @@ func (l *AdminGetAgentListLogic) AdminGetAgentList(req *types.AdminGetAgentListR
|
||||
builder = builder.Where("id IN ("+tool.InPlaceholders(len(interfaceIds))+")", interfaceIds...)
|
||||
}
|
||||
|
||||
agents, total, err := l.svcCtx.AgentModel.FindPageListByPageWithTotal(l.ctx, builder, req.Page, req.PageSize, "id DESC")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
var (
|
||||
agents []*model.Agent
|
||||
total int64
|
||||
)
|
||||
if mobileKeyword == "" {
|
||||
agents, total, err = l.svcCtx.AgentModel.FindPageListByPageWithTotal(l.ctx, builder, req.Page, req.PageSize, "id DESC")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
allAgents, findErr := l.svcCtx.AgentModel.FindAll(l.ctx, builder, "id DESC")
|
||||
if findErr != nil {
|
||||
return nil, findErr
|
||||
}
|
||||
|
||||
filteredAgents := make([]*model.Agent, 0, len(allAgents))
|
||||
for _, agent := range allAgents {
|
||||
decryptedMobile, decryptErr := crypto.DecryptMobile(agent.Mobile, secretKey)
|
||||
if decryptErr != nil {
|
||||
// 单条手机号异常时忽略该条匹配,避免影响整页结果
|
||||
continue
|
||||
}
|
||||
if strings.Contains(decryptedMobile, mobileKeyword) {
|
||||
agent.Mobile = decryptedMobile
|
||||
filteredAgents = append(filteredAgents, agent)
|
||||
}
|
||||
}
|
||||
|
||||
total = int64(len(filteredAgents))
|
||||
if total > 0 && req.PageSize > 0 {
|
||||
page := req.Page
|
||||
if page < 1 {
|
||||
page = 1
|
||||
}
|
||||
offset := (page - 1) * req.PageSize
|
||||
if offset < total {
|
||||
end := offset + req.PageSize
|
||||
if end > total {
|
||||
end = total
|
||||
}
|
||||
agents = filteredAgents[offset:end]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
items := make([]types.AgentListItem, 0, len(agents))
|
||||
@@ -79,9 +125,13 @@ func (l *AdminGetAgentListLogic) AdminGetAgentList(req *types.AdminGetAgentListR
|
||||
if req.ParentAgentId != nil {
|
||||
item.ParentAgentId = *req.ParentAgentId
|
||||
}
|
||||
agent.Mobile, err = crypto.DecryptMobile(agent.Mobile, l.svcCtx.Config.Encrypt.SecretKey)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "获取代理信息, 解密手机号失败: %v", err)
|
||||
if mobileKeyword == "" {
|
||||
decryptedMobile, decryptErr := crypto.DecryptMobile(agent.Mobile, secretKey)
|
||||
if decryptErr != nil {
|
||||
agent.Mobile = "-"
|
||||
} else {
|
||||
agent.Mobile = decryptedMobile
|
||||
}
|
||||
}
|
||||
item.Mobile = agent.Mobile
|
||||
if agent.MembershipExpiryTime.Valid {
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
package admin_agent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"regexp"
|
||||
"time"
|
||||
|
||||
"bdrp-server/app/main/api/internal/svc"
|
||||
"bdrp-server/app/main/api/internal/types"
|
||||
"bdrp-server/common/xerr"
|
||||
"bdrp-server/pkg/lzkit/crypto"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type AdminUpdateAgentLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewAdminUpdateAgentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AdminUpdateAgentLogic {
|
||||
return &AdminUpdateAgentLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *AdminUpdateAgentLogic) AdminUpdateAgent(req *types.AdminUpdateAgentReq) (resp *types.AdminUpdateAgentResp, err error) {
|
||||
agent, err := l.svcCtx.AgentModel.FindOne(l.ctx, req.Id)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "查询代理失败 err: %v", err)
|
||||
}
|
||||
|
||||
if ok, _ := regexp.MatchString(`^1[3-9]\d{9}$`, req.Mobile); !ok {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.REUQEST_PARAM_ERROR), "手机号格式错误: %s", req.Mobile)
|
||||
}
|
||||
|
||||
encryptedMobile, err := crypto.EncryptMobile(req.Mobile, l.svcCtx.Config.Encrypt.SecretKey)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "加密手机号失败: %v", err)
|
||||
}
|
||||
|
||||
expiryTime, err := time.ParseInLocation("2006-01-02 15:04:05", req.MembershipExpiryTime, time.Local)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.REUQEST_PARAM_ERROR), "会员到期时间格式错误: %v", err)
|
||||
}
|
||||
|
||||
agent.Mobile = encryptedMobile
|
||||
agent.LevelName = req.LevelName
|
||||
agent.Region = req.Region
|
||||
agent.MembershipExpiryTime = sql.NullTime{
|
||||
Time: expiryTime,
|
||||
Valid: true,
|
||||
}
|
||||
|
||||
if _, err = l.svcCtx.AgentModel.Update(l.ctx, nil, agent); err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "更新代理失败 err: %v", err)
|
||||
}
|
||||
|
||||
return &types.AdminUpdateAgentResp{Success: true}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user