v1.1
This commit is contained in:
@@ -1,20 +1,21 @@
|
||||
package admin_agent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"time"
|
||||
"ycc-server/app/main/model"
|
||||
"ycc-server/common/tool"
|
||||
"ycc-server/common/xerr"
|
||||
"context"
|
||||
"database/sql"
|
||||
"time"
|
||||
"ycc-server/app/main/model"
|
||||
"ycc-server/common/tool"
|
||||
"ycc-server/common/xerr"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
|
||||
"ycc-server/app/main/api/internal/svc"
|
||||
"ycc-server/app/main/api/internal/types"
|
||||
"ycc-server/app/main/api/internal/svc"
|
||||
"ycc-server/app/main/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
type AdminGenerateDiamondInviteCodeLogic struct {
|
||||
@@ -70,14 +71,15 @@ func (l *AdminGenerateDiamondInviteCodeLogic) AdminGenerateDiamondInviteCode(req
|
||||
}
|
||||
|
||||
// 创建邀请码记录(平台发放的钻石邀请码)
|
||||
inviteCode := &model.AgentInviteCode{
|
||||
Code: code,
|
||||
AgentId: sql.NullInt64{Valid: false}, // NULL表示平台发放
|
||||
TargetLevel: 3, // 钻石代理
|
||||
Status: 0, // 未使用
|
||||
ExpireTime: expireTime,
|
||||
Remark: sql.NullString{String: req.Remark, Valid: req.Remark != ""},
|
||||
}
|
||||
inviteCode := &model.AgentInviteCode{
|
||||
Id: uuid.NewString(),
|
||||
Code: code,
|
||||
AgentId: sql.NullString{Valid: false}, // NULL表示平台发放
|
||||
TargetLevel: 3, // 钻石代理
|
||||
Status: 0, // 未使用
|
||||
ExpireTime: expireTime,
|
||||
Remark: sql.NullString{String: req.Remark, Valid: req.Remark != ""},
|
||||
}
|
||||
|
||||
_, err := l.svcCtx.AgentInviteCodeModel.Insert(transCtx, session, inviteCode)
|
||||
if err != nil {
|
||||
|
||||
@@ -41,13 +41,13 @@ func (l *AdminGetAgentCommissionListLogic) AdminGetAgentCommissionList(req *type
|
||||
}
|
||||
|
||||
// 批量查product_name
|
||||
productIds := make(map[int64]struct{})
|
||||
productIds := make(map[string]struct{})
|
||||
for _, v := range list {
|
||||
productIds[v.ProductId] = struct{}{}
|
||||
}
|
||||
productNameMap := make(map[int64]string)
|
||||
productNameMap := make(map[string]string)
|
||||
if len(productIds) > 0 {
|
||||
ids := make([]int64, 0, len(productIds))
|
||||
ids := make([]string, 0, len(productIds))
|
||||
for id := range productIds {
|
||||
ids = append(ids, id)
|
||||
}
|
||||
|
||||
@@ -69,6 +69,8 @@ func (l *AdminGetAgentConfigLogic) AdminGetAgentConfig() (resp *types.AdminGetAg
|
||||
commissionFreezeThreshold := getConfigFloat("commission_freeze_threshold")
|
||||
commissionFreezeDays := getConfigInt("commission_freeze_days")
|
||||
|
||||
goldUplift := getConfigFloat("gold_max_uplift_amount")
|
||||
diamondUplift := getConfigFloat("diamond_max_uplift_amount")
|
||||
return &types.AdminGetAgentConfigResp{
|
||||
LevelBonus: types.LevelBonusConfig{
|
||||
Normal: int64(level1Bonus),
|
||||
@@ -78,7 +80,6 @@ func (l *AdminGetAgentConfigLogic) AdminGetAgentConfig() (resp *types.AdminGetAg
|
||||
UpgradeFee: types.UpgradeFeeConfig{
|
||||
NormalToGold: upgradeToGoldFee,
|
||||
NormalToDiamond: upgradeToDiamondFee,
|
||||
GoldToDiamond: upgradeToDiamondFee - upgradeToGoldFee,
|
||||
},
|
||||
UpgradeRebate: types.UpgradeRebateConfig{
|
||||
NormalToGoldRebate: upgradeToGoldRebate,
|
||||
@@ -95,7 +96,9 @@ func (l *AdminGetAgentConfigLogic) AdminGetAgentConfig() (resp *types.AdminGetAg
|
||||
Threshold: commissionFreezeThreshold,
|
||||
Days: commissionFreezeDays,
|
||||
},
|
||||
TaxRate: getConfigFloat("tax_rate"),
|
||||
TaxExemptionAmount: getConfigFloat("tax_exemption_amount"),
|
||||
TaxRate: getConfigFloat("tax_rate"),
|
||||
TaxExemptionAmount: getConfigFloat("tax_exemption_amount"),
|
||||
GoldMaxUpliftAmount: goldUplift,
|
||||
DiamondMaxUpliftAmount: diamondUplift,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -44,15 +44,15 @@ func (l *AdminGetAgentLinkListLogic) AdminGetAgentLinkList(req *types.AdminGetAg
|
||||
}
|
||||
|
||||
// 批量查product_id->name,避免N+1
|
||||
productIdSet := make(map[int64]struct{})
|
||||
productIdSet := make(map[string]struct{})
|
||||
for _, link := range links {
|
||||
productIdSet[link.ProductId] = struct{}{}
|
||||
}
|
||||
productIdList := make([]int64, 0, len(productIdSet))
|
||||
productIdList := make([]string, 0, len(productIdSet))
|
||||
for id := range productIdSet {
|
||||
productIdList = append(productIdList, id)
|
||||
}
|
||||
productNameMap := make(map[int64]string)
|
||||
productNameMap := make(map[string]string)
|
||||
if len(productIdList) > 0 {
|
||||
products, _ := l.svcCtx.ProductModel.FindAll(l.ctx, l.svcCtx.ProductModel.SelectBuilder().Where(squirrel.Eq{"id": productIdList}), "")
|
||||
for _, p := range products {
|
||||
@@ -63,14 +63,14 @@ func (l *AdminGetAgentLinkListLogic) AdminGetAgentLinkList(req *types.AdminGetAg
|
||||
items := make([]types.AgentLinkListItem, 0, len(links))
|
||||
for _, link := range links {
|
||||
items = append(items, types.AgentLinkListItem{
|
||||
Id: link.Id,
|
||||
AgentId: link.AgentId,
|
||||
ProductId: link.ProductId,
|
||||
ProductName: productNameMap[link.ProductId],
|
||||
SetPrice: link.SetPrice,
|
||||
Id: link.Id,
|
||||
AgentId: link.AgentId,
|
||||
ProductId: link.ProductId,
|
||||
ProductName: productNameMap[link.ProductId],
|
||||
SetPrice: link.SetPrice,
|
||||
ActualBasePrice: link.ActualBasePrice,
|
||||
LinkIdentifier: link.LinkIdentifier,
|
||||
CreateTime: link.CreateTime.Format("2006-01-02 15:04:05"),
|
||||
LinkIdentifier: link.LinkIdentifier,
|
||||
CreateTime: link.CreateTime.Format("2006-01-02 15:04:05"),
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ 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()
|
||||
|
||||
|
||||
// 如果传入TeamLeaderId,则查找该团队首领下的所有代理
|
||||
if req.TeamLeaderId != nil {
|
||||
builder = builder.Where(squirrel.Eq{"team_leader_id": *req.TeamLeaderId})
|
||||
@@ -78,7 +78,7 @@ func (l *AdminGetAgentListLogic) AdminGetAgentList(req *types.AdminGetAgentListR
|
||||
|
||||
// 查询钱包信息
|
||||
wallet, _ := l.svcCtx.AgentWalletModel.FindOneByAgentId(l.ctx, agent.Id)
|
||||
|
||||
|
||||
// 查询实名认证信息
|
||||
realNameInfo, _ := l.svcCtx.AgentRealNameModel.FindOneByAgentId(l.ctx, agent.Id)
|
||||
isRealName := false
|
||||
@@ -90,9 +90,9 @@ func (l *AdminGetAgentListLogic) AdminGetAgentList(req *types.AdminGetAgentListR
|
||||
if agent.WechatId.Valid {
|
||||
wechatId = agent.WechatId.String
|
||||
}
|
||||
teamLeaderId := int64(0)
|
||||
teamLeaderId := ""
|
||||
if agent.TeamLeaderId.Valid {
|
||||
teamLeaderId = agent.TeamLeaderId.Int64
|
||||
teamLeaderId = agent.TeamLeaderId.String
|
||||
}
|
||||
|
||||
// 获取区域
|
||||
@@ -102,22 +102,23 @@ func (l *AdminGetAgentListLogic) AdminGetAgentList(req *types.AdminGetAgentListR
|
||||
}
|
||||
|
||||
item := types.AgentListItem{
|
||||
Id: agent.Id,
|
||||
UserId: agent.UserId,
|
||||
Level: agent.Level,
|
||||
LevelName: levelName,
|
||||
Region: region,
|
||||
Mobile: agent.Mobile,
|
||||
WechatId: wechatId,
|
||||
TeamLeaderId: teamLeaderId,
|
||||
Balance: 0,
|
||||
TotalEarnings: 0,
|
||||
FrozenBalance: 0,
|
||||
Id: agent.Id,
|
||||
UserId: agent.UserId,
|
||||
Level: agent.Level,
|
||||
LevelName: levelName,
|
||||
Region: region,
|
||||
Mobile: agent.Mobile,
|
||||
WechatId: wechatId,
|
||||
TeamLeaderId: teamLeaderId,
|
||||
AgentCode: agent.AgentCode,
|
||||
Balance: 0,
|
||||
TotalEarnings: 0,
|
||||
FrozenBalance: 0,
|
||||
WithdrawnAmount: 0,
|
||||
IsRealName: isRealName,
|
||||
CreateTime: agent.CreateTime.Format("2006-01-02 15:04:05"),
|
||||
IsRealName: isRealName,
|
||||
CreateTime: agent.CreateTime.Format("2006-01-02 15:04:05"),
|
||||
}
|
||||
|
||||
|
||||
if wallet != nil {
|
||||
item.Balance = wallet.Balance
|
||||
item.TotalEarnings = wallet.TotalEarnings
|
||||
|
||||
@@ -58,15 +58,15 @@ func (l *AdminGetAgentOrderListLogic) AdminGetAgentOrderList(req *types.AdminGet
|
||||
}
|
||||
|
||||
// 批量查询产品名称
|
||||
productIdSet := make(map[int64]struct{})
|
||||
productIdSet := make(map[string]struct{})
|
||||
for _, order := range orders {
|
||||
productIdSet[order.ProductId] = struct{}{}
|
||||
}
|
||||
productIdList := make([]int64, 0, len(productIdSet))
|
||||
productIdList := make([]string, 0, len(productIdSet))
|
||||
for id := range productIdSet {
|
||||
productIdList = append(productIdList, id)
|
||||
}
|
||||
productNameMap := make(map[int64]string)
|
||||
productNameMap := make(map[string]string)
|
||||
if len(productIdList) > 0 {
|
||||
products, _ := l.svcCtx.ProductModel.FindAll(l.ctx, l.svcCtx.ProductModel.SelectBuilder().Where(squirrel.Eq{"id": productIdList}), "")
|
||||
for _, p := range products {
|
||||
|
||||
@@ -58,15 +58,15 @@ func (l *AdminGetAgentRebateListLogic) AdminGetAgentRebateList(req *types.AdminG
|
||||
}
|
||||
|
||||
// 批量查询产品名称
|
||||
productIdSet := make(map[int64]struct{})
|
||||
productIdSet := make(map[string]struct{})
|
||||
for _, rebate := range rebates {
|
||||
productIdSet[rebate.ProductId] = struct{}{}
|
||||
}
|
||||
productIdList := make([]int64, 0, len(productIdSet))
|
||||
productIdList := make([]string, 0, len(productIdSet))
|
||||
for id := range productIdSet {
|
||||
productIdList = append(productIdList, id)
|
||||
}
|
||||
productNameMap := make(map[int64]string)
|
||||
productNameMap := make(map[string]string)
|
||||
if len(productIdList) > 0 {
|
||||
products, _ := l.svcCtx.ProductModel.FindAll(l.ctx, l.svcCtx.ProductModel.SelectBuilder().Where(squirrel.Eq{"id": productIdList}), "")
|
||||
for _, p := range products {
|
||||
@@ -79,12 +79,12 @@ func (l *AdminGetAgentRebateListLogic) AdminGetAgentRebateList(req *types.AdminG
|
||||
for _, rebate := range rebates {
|
||||
items = append(items, types.AgentRebateListItem{
|
||||
Id: rebate.Id,
|
||||
AgentId: rebate.AgentId,
|
||||
AgentId: rebate.AgentId,
|
||||
SourceAgentId: rebate.SourceAgentId,
|
||||
OrderId: rebate.OrderId,
|
||||
RebateType: rebate.RebateType,
|
||||
Amount: rebate.RebateAmount,
|
||||
CreateTime: rebate.CreateTime.Format("2006-01-02 15:04:05"),
|
||||
OrderId: rebate.OrderId,
|
||||
RebateType: rebate.RebateType,
|
||||
Amount: rebate.RebateAmount,
|
||||
CreateTime: rebate.CreateTime.Format("2006-01-02 15:04:05"),
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -37,8 +37,8 @@ func (l *AdminGetInviteCodeListLogic) AdminGetInviteCodeList(req *types.AdminGet
|
||||
if req.Code != nil && *req.Code != "" {
|
||||
builder = builder.Where("code = ?", *req.Code)
|
||||
}
|
||||
if req.AgentId != nil {
|
||||
if *req.AgentId == 0 {
|
||||
if req.AgentId != nil && *req.AgentId != "" {
|
||||
if *req.AgentId == "0" {
|
||||
// agent_id = 0 表示查询平台发放的邀请码(agent_id为NULL)
|
||||
builder = builder.Where("agent_id IS NULL")
|
||||
} else {
|
||||
@@ -59,16 +59,16 @@ func (l *AdminGetInviteCodeListLogic) AdminGetInviteCodeList(req *types.AdminGet
|
||||
}
|
||||
|
||||
// 3. 批量查询代理信息(用于显示代理手机号)
|
||||
agentIds := make(map[int64]struct{})
|
||||
agentIds := make(map[string]struct{})
|
||||
for _, v := range list {
|
||||
if v.AgentId.Valid && v.AgentId.Int64 > 0 {
|
||||
agentIds[v.AgentId.Int64] = struct{}{}
|
||||
if v.AgentId.Valid && v.AgentId.String != "" {
|
||||
agentIds[v.AgentId.String] = struct{}{}
|
||||
}
|
||||
}
|
||||
|
||||
agentMobileMap := make(map[int64]string)
|
||||
agentMobileMap := make(map[string]string)
|
||||
if len(agentIds) > 0 {
|
||||
agentIdList := make([]int64, 0, len(agentIds))
|
||||
agentIdList := make([]string, 0, len(agentIds))
|
||||
for id := range agentIds {
|
||||
agentIdList = append(agentIdList, id)
|
||||
}
|
||||
@@ -90,7 +90,7 @@ func (l *AdminGetInviteCodeListLogic) AdminGetInviteCodeList(req *types.AdminGet
|
||||
item := types.InviteCodeListItem{
|
||||
Id: v.Id,
|
||||
Code: v.Code,
|
||||
AgentId: 0,
|
||||
AgentId: "",
|
||||
AgentMobile: "",
|
||||
TargetLevel: v.TargetLevel,
|
||||
Status: v.Status,
|
||||
@@ -98,15 +98,15 @@ func (l *AdminGetInviteCodeListLogic) AdminGetInviteCodeList(req *types.AdminGet
|
||||
}
|
||||
|
||||
if v.AgentId.Valid {
|
||||
item.AgentId = v.AgentId.Int64
|
||||
item.AgentMobile = agentMobileMap[v.AgentId.Int64]
|
||||
item.AgentId = v.AgentId.String
|
||||
item.AgentMobile = agentMobileMap[v.AgentId.String]
|
||||
}
|
||||
|
||||
if v.UsedUserId.Valid {
|
||||
item.UsedUserId = v.UsedUserId.Int64
|
||||
item.UsedUserId = v.UsedUserId.String
|
||||
}
|
||||
if v.UsedAgentId.Valid {
|
||||
item.UsedAgentId = v.UsedAgentId.Int64
|
||||
item.UsedAgentId = v.UsedAgentId.String
|
||||
}
|
||||
if v.UsedTime.Valid {
|
||||
item.UsedTime = v.UsedTime.Time.Format("2006-01-02 15:04:05")
|
||||
|
||||
@@ -2,6 +2,7 @@ package admin_agent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"strconv"
|
||||
"ycc-server/common/xerr"
|
||||
|
||||
@@ -9,6 +10,7 @@ import (
|
||||
|
||||
"ycc-server/app/main/api/internal/svc"
|
||||
"ycc-server/app/main/api/internal/types"
|
||||
"ycc-server/app/main/model"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
@@ -28,17 +30,77 @@ func NewAdminUpdateAgentConfigLogic(ctx context.Context, svcCtx *svc.ServiceCont
|
||||
}
|
||||
|
||||
func (l *AdminUpdateAgentConfigLogic) AdminUpdateAgentConfig(req *types.AdminUpdateAgentConfigReq) (resp *types.AdminUpdateAgentConfigResp, err error) {
|
||||
// 更新配置的辅助函数
|
||||
configTypeForKey := func(key string) string {
|
||||
switch key {
|
||||
case "level_1_bonus", "level_2_bonus", "level_3_bonus":
|
||||
return "bonus"
|
||||
case "upgrade_to_gold_fee", "upgrade_to_diamond_fee", "upgrade_to_gold_rebate", "upgrade_to_diamond_rebate":
|
||||
return "upgrade"
|
||||
case "direct_parent_amount_diamond", "direct_parent_amount_gold", "direct_parent_amount_normal", "max_gold_rebate_amount":
|
||||
return "rebate"
|
||||
case "commission_freeze_ratio", "commission_freeze_threshold", "commission_freeze_days":
|
||||
return "rebate"
|
||||
case "tax_rate", "tax_exemption_amount":
|
||||
return "tax"
|
||||
case "gold_max_uplift_amount", "diamond_max_uplift_amount":
|
||||
return "price"
|
||||
default:
|
||||
return "rebate"
|
||||
}
|
||||
}
|
||||
|
||||
updateConfig := func(key string, value *float64) error {
|
||||
if value == nil {
|
||||
return nil
|
||||
}
|
||||
valStr := strconv.FormatFloat(*value, 'f', -1, 64)
|
||||
config, err := l.svcCtx.AgentConfigModel.FindOneByConfigKey(l.ctx, key)
|
||||
if err != nil {
|
||||
if errors.Is(err, model.ErrNotFound) {
|
||||
cfg := &model.AgentConfig{
|
||||
ConfigKey: key,
|
||||
ConfigValue: valStr,
|
||||
ConfigType: configTypeForKey(key),
|
||||
Description: sql.NullString{},
|
||||
DeleteTime: sql.NullTime{},
|
||||
Version: 0,
|
||||
}
|
||||
_, insErr := l.svcCtx.AgentConfigModel.Insert(l.ctx, nil, cfg)
|
||||
if insErr != nil {
|
||||
return errors.Wrapf(insErr, "创建配置失败, key: %s", key)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
return errors.Wrapf(err, "查询配置失败, key: %s", key)
|
||||
}
|
||||
config.ConfigValue = strconv.FormatFloat(*value, 'f', -1, 64)
|
||||
return l.svcCtx.AgentConfigModel.UpdateWithVersion(l.ctx, nil, config)
|
||||
config.ConfigValue = valStr
|
||||
if uErr := l.svcCtx.AgentConfigModel.UpdateWithVersion(l.ctx, nil, config); uErr != nil {
|
||||
if errors.Is(uErr, model.ErrNoRowsUpdate) {
|
||||
latestByKey, reErr := l.svcCtx.AgentConfigModel.FindOneByConfigKey(l.ctx, key)
|
||||
if reErr != nil {
|
||||
if errors.Is(reErr, model.ErrNotFound) {
|
||||
cfg := &model.AgentConfig{
|
||||
ConfigKey: key,
|
||||
ConfigValue: valStr,
|
||||
ConfigType: configTypeForKey(key),
|
||||
Description: sql.NullString{},
|
||||
DeleteTime: sql.NullTime{},
|
||||
Version: 0,
|
||||
}
|
||||
_, insErr := l.svcCtx.AgentConfigModel.Insert(l.ctx, nil, cfg)
|
||||
if insErr != nil {
|
||||
return errors.Wrapf(insErr, "创建配置失败, key: %s", key)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
return errors.Wrapf(reErr, "查询最新配置失败, key: %s", key)
|
||||
}
|
||||
latestByKey.ConfigValue = valStr
|
||||
return l.svcCtx.AgentConfigModel.UpdateWithVersion(l.ctx, nil, latestByKey)
|
||||
}
|
||||
return uErr
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// 更新等级加成配置
|
||||
@@ -118,6 +180,13 @@ func (l *AdminUpdateAgentConfigLogic) AdminUpdateAgentConfig(req *types.AdminUpd
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "更新免税额度失败, %v", err)
|
||||
}
|
||||
|
||||
if err := updateConfig("gold_max_uplift_amount", req.GoldMaxUpliftAmount); err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "更新黄金代理最高价上调金额失败, %v", err)
|
||||
}
|
||||
if err := updateConfig("diamond_max_uplift_amount", req.DiamondMaxUpliftAmount); err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "更新钻石代理最高价上调金额失败, %v", err)
|
||||
}
|
||||
|
||||
return &types.AdminUpdateAgentConfigResp{
|
||||
Success: true,
|
||||
}, nil
|
||||
|
||||
Reference in New Issue
Block a user