first commit
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
package admin_agent
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"ycc-server/app/main/api/internal/svc"
|
||||
"ycc-server/app/main/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type AdminAuditAgentLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewAdminAuditAgentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AdminAuditAgentLogic {
|
||||
return &AdminAuditAgentLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *AdminAuditAgentLogic) AdminAuditAgent(req *types.AdminAuditAgentReq) (resp *types.AdminAuditAgentResp, err error) {
|
||||
// todo: add your logic here and delete this line
|
||||
|
||||
return
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package admin_agent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"ycc-server/common/xerr"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"ycc-server/app/main/api/internal/svc"
|
||||
"ycc-server/app/main/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type AdminAuditRealNameLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewAdminAuditRealNameLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AdminAuditRealNameLogic {
|
||||
return &AdminAuditRealNameLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
// AdminAuditRealName 实名认证审核(已废弃:实名认证改为三要素核验,无需审核)
|
||||
func (l *AdminAuditRealNameLogic) AdminAuditRealName(req *types.AdminAuditRealNameReq) (resp *types.AdminAuditRealNameResp, err error) {
|
||||
// 该接口已废弃,实名认证现在通过三要素核验自动完成,无需人工审核
|
||||
return nil, errors.Wrapf(xerr.NewErrMsg("该接口已废弃,实名认证改为三要素核验,无需审核"), "")
|
||||
}
|
||||
@@ -0,0 +1,175 @@
|
||||
package admin_agent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"time"
|
||||
"ycc-server/common/globalkey"
|
||||
"ycc-server/common/xerr"
|
||||
"ycc-server/pkg/lzkit/lzUtils"
|
||||
|
||||
"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"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type AdminAuditWithdrawalLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewAdminAuditWithdrawalLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AdminAuditWithdrawalLogic {
|
||||
return &AdminAuditWithdrawalLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *AdminAuditWithdrawalLogic) AdminAuditWithdrawal(req *types.AdminAuditWithdrawalReq) (resp *types.AdminAuditWithdrawalResp, err error) {
|
||||
// 1. 查询提现记录
|
||||
withdrawal, err := l.svcCtx.AgentWithdrawalModel.FindOne(l.ctx, req.WithdrawalId)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "查询提现记录失败, %v", err)
|
||||
}
|
||||
|
||||
// 3. 检查状态(必须是待审核状态)
|
||||
if withdrawal.Status != 1 {
|
||||
return nil, errors.Wrapf(xerr.NewErrMsg("该提现记录已处理"), "")
|
||||
}
|
||||
|
||||
// 4. 使用事务处理审核
|
||||
err = l.svcCtx.AgentWithdrawalModel.Trans(l.ctx, func(transCtx context.Context, session sqlx.Session) error {
|
||||
if req.Status == 2 { // 审核通过
|
||||
// 4.1 更新提现记录状态为提现中
|
||||
withdrawal.Status = 4 // 提现中
|
||||
withdrawal.Remark = sql.NullString{String: req.Remark, Valid: true}
|
||||
if err := l.svcCtx.AgentWithdrawalModel.UpdateWithVersion(transCtx, session, withdrawal); err != nil {
|
||||
return errors.Wrapf(err, "更新提现记录失败")
|
||||
}
|
||||
|
||||
// 4.2 调用支付宝转账接口
|
||||
outBizNo := withdrawal.WithdrawNo
|
||||
transferResp, err := l.svcCtx.AlipayService.AliTransfer(transCtx, withdrawal.PayeeAccount, withdrawal.PayeeName, withdrawal.ActualAmount, "代理提现", outBizNo)
|
||||
if err != nil {
|
||||
// 转账失败,更新状态为失败
|
||||
withdrawal.Status = 6 // 提现失败
|
||||
withdrawal.Remark = sql.NullString{String: fmt.Sprintf("转账失败: %v", err), Valid: true}
|
||||
l.svcCtx.AgentWithdrawalModel.UpdateWithVersion(transCtx, session, withdrawal)
|
||||
|
||||
// 解冻余额
|
||||
wallet, err := l.svcCtx.AgentWalletModel.FindOneByAgentId(transCtx, withdrawal.AgentId)
|
||||
if err == nil {
|
||||
wallet.FrozenBalance -= withdrawal.Amount
|
||||
wallet.Balance += withdrawal.Amount
|
||||
l.svcCtx.AgentWalletModel.UpdateWithVersion(transCtx, session, wallet)
|
||||
}
|
||||
|
||||
return errors.Wrapf(err, "支付宝转账失败")
|
||||
}
|
||||
|
||||
// 4.3 根据转账结果更新状态
|
||||
switch transferResp.Status {
|
||||
case "SUCCESS":
|
||||
// 转账成功
|
||||
withdrawal.Status = 5 // 提现成功
|
||||
if err := l.svcCtx.AgentWithdrawalModel.UpdateWithVersion(transCtx, session, withdrawal); err != nil {
|
||||
return errors.Wrapf(err, "更新提现记录失败")
|
||||
}
|
||||
|
||||
// 更新钱包(解冻并扣除)
|
||||
wallet, err := l.svcCtx.AgentWalletModel.FindOneByAgentId(transCtx, withdrawal.AgentId)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "查询钱包失败")
|
||||
}
|
||||
wallet.FrozenBalance -= withdrawal.Amount
|
||||
wallet.WithdrawnAmount += withdrawal.Amount
|
||||
if err := l.svcCtx.AgentWalletModel.UpdateWithVersion(transCtx, session, wallet); err != nil {
|
||||
return errors.Wrapf(err, "更新钱包失败")
|
||||
}
|
||||
|
||||
// 更新扣税记录状态
|
||||
taxBuilder := l.svcCtx.AgentWithdrawalTaxModel.SelectBuilder().
|
||||
Where("withdrawal_id = ? AND del_state = ?", withdrawal.Id, globalkey.DelStateNo)
|
||||
taxRecords, err := l.svcCtx.AgentWithdrawalTaxModel.FindAll(transCtx, taxBuilder, "")
|
||||
if err == nil && len(taxRecords) > 0 {
|
||||
taxRecord := taxRecords[0]
|
||||
taxRecord.TaxStatus = 2 // 已扣税
|
||||
taxRecord.TaxTime = lzUtils.TimeToNullTime(time.Now())
|
||||
l.svcCtx.AgentWithdrawalTaxModel.UpdateWithVersion(transCtx, session, taxRecord)
|
||||
}
|
||||
|
||||
case "FAIL":
|
||||
// 转账失败
|
||||
withdrawal.Status = 6 // 提现失败
|
||||
errorMsg := l.mapAlipayError(transferResp.SubCode)
|
||||
withdrawal.Remark = sql.NullString{String: errorMsg, Valid: true}
|
||||
if err := l.svcCtx.AgentWithdrawalModel.UpdateWithVersion(transCtx, session, withdrawal); err != nil {
|
||||
return errors.Wrapf(err, "更新提现记录失败")
|
||||
}
|
||||
|
||||
// 解冻余额
|
||||
wallet, err := l.svcCtx.AgentWalletModel.FindOneByAgentId(transCtx, withdrawal.AgentId)
|
||||
if err == nil {
|
||||
wallet.FrozenBalance -= withdrawal.Amount
|
||||
wallet.Balance += withdrawal.Amount
|
||||
l.svcCtx.AgentWalletModel.UpdateWithVersion(transCtx, session, wallet)
|
||||
}
|
||||
|
||||
case "DEALING":
|
||||
// 处理中,保持提现中状态,后续通过轮询更新
|
||||
// 状态已经是4(提现中),无需更新
|
||||
}
|
||||
|
||||
} else if req.Status == 3 { // 审核拒绝
|
||||
// 4.1 更新提现记录状态为拒绝
|
||||
withdrawal.Status = 3 // 审核拒绝
|
||||
withdrawal.Remark = sql.NullString{String: req.Remark, Valid: true}
|
||||
if err := l.svcCtx.AgentWithdrawalModel.UpdateWithVersion(transCtx, session, withdrawal); err != nil {
|
||||
return errors.Wrapf(err, "更新提现记录失败")
|
||||
}
|
||||
|
||||
// 4.2 解冻余额
|
||||
wallet, err := l.svcCtx.AgentWalletModel.FindOneByAgentId(transCtx, withdrawal.AgentId)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "查询钱包失败")
|
||||
}
|
||||
wallet.FrozenBalance -= withdrawal.Amount
|
||||
wallet.Balance += withdrawal.Amount
|
||||
if err := l.svcCtx.AgentWalletModel.UpdateWithVersion(transCtx, session, wallet); err != nil {
|
||||
return errors.Wrapf(err, "更新钱包失败")
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &types.AdminAuditWithdrawalResp{
|
||||
Success: true,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// mapAlipayError 映射支付宝错误码
|
||||
func (l *AdminAuditWithdrawalLogic) mapAlipayError(code string) string {
|
||||
errorMapping := map[string]string{
|
||||
"PAYEE_USERINFO_ERROR": "收款方姓名或信息不匹配",
|
||||
"PAYEE_CARD_INFO_ERROR": "收款支付宝账号及户名不一致",
|
||||
"PAYEE_IDENTITY_NOT_MATCH": "收款方身份信息不匹配",
|
||||
"PAYEE_USER_IS_INST": "收款方为金融机构,不能使用提现功能",
|
||||
"PAYEE_USER_TYPE_ERROR": "该支付宝账号类型不支持提现",
|
||||
}
|
||||
if msg, ok := errorMapping[code]; ok {
|
||||
return msg
|
||||
}
|
||||
return "系统错误,请联系客服"
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
package admin_agent
|
||||
|
||||
import (
|
||||
"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"
|
||||
|
||||
"ycc-server/app/main/api/internal/svc"
|
||||
"ycc-server/app/main/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type AdminGenerateDiamondInviteCodeLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewAdminGenerateDiamondInviteCodeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AdminGenerateDiamondInviteCodeLogic {
|
||||
return &AdminGenerateDiamondInviteCodeLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *AdminGenerateDiamondInviteCodeLogic) AdminGenerateDiamondInviteCode(req *types.AdminGenerateDiamondInviteCodeReq) (resp *types.AdminGenerateDiamondInviteCodeResp, err error) {
|
||||
// 1. 验证生成数量
|
||||
if req.Count <= 0 || req.Count > 100 {
|
||||
return nil, errors.Wrapf(xerr.NewErrMsg("生成数量必须在1-100之间"), "")
|
||||
}
|
||||
|
||||
// 2. 生成钻石邀请码(平台发放,agent_id为NULL,target_level为3)
|
||||
codes := make([]string, 0, req.Count)
|
||||
var expireTime sql.NullTime
|
||||
if req.ExpireDays > 0 {
|
||||
expireTime = sql.NullTime{
|
||||
Time: time.Now().AddDate(0, 0, int(req.ExpireDays)),
|
||||
Valid: true,
|
||||
}
|
||||
}
|
||||
|
||||
err = l.svcCtx.AgentInviteCodeModel.Trans(l.ctx, func(transCtx context.Context, session sqlx.Session) error {
|
||||
for i := int64(0); i < req.Count; i++ {
|
||||
// 生成8位随机邀请码(大小写字母+数字)
|
||||
var code string
|
||||
maxRetries := 10 // 最大重试次数
|
||||
for retry := 0; retry < maxRetries; retry++ {
|
||||
code = tool.Krand(8, tool.KC_RAND_KIND_ALL)
|
||||
// 检查邀请码是否已存在
|
||||
_, err := l.svcCtx.AgentInviteCodeModel.FindOneByCode(transCtx, code)
|
||||
if err != nil {
|
||||
if errors.Is(err, model.ErrNotFound) {
|
||||
// 邀请码不存在,可以使用
|
||||
break
|
||||
}
|
||||
return errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "检查邀请码失败, %v", err)
|
||||
}
|
||||
// 邀请码已存在,继续生成
|
||||
if retry == maxRetries-1 {
|
||||
return errors.Wrapf(xerr.NewErrMsg("生成邀请码失败,请重试"), "")
|
||||
}
|
||||
}
|
||||
|
||||
// 创建邀请码记录(平台发放的钻石邀请码)
|
||||
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 != ""},
|
||||
}
|
||||
|
||||
_, err := l.svcCtx.AgentInviteCodeModel.Insert(transCtx, session, inviteCode)
|
||||
if err != nil {
|
||||
return errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "创建邀请码失败, %v", err)
|
||||
}
|
||||
|
||||
codes = append(codes, code)
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &types.AdminGenerateDiamondInviteCodeResp{
|
||||
Codes: codes,
|
||||
}, nil
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package admin_agent
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"ycc-server/app/main/api/internal/svc"
|
||||
"ycc-server/app/main/api/internal/types"
|
||||
|
||||
"github.com/Masterminds/squirrel"
|
||||
"github.com/jinzhu/copier"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type AdminGetAgentCommissionListLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewAdminGetAgentCommissionListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AdminGetAgentCommissionListLogic {
|
||||
return &AdminGetAgentCommissionListLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *AdminGetAgentCommissionListLogic) AdminGetAgentCommissionList(req *types.AdminGetAgentCommissionListReq) (resp *types.AdminGetAgentCommissionListResp, err error) {
|
||||
builder := l.svcCtx.AgentCommissionModel.SelectBuilder()
|
||||
if req.AgentId != nil {
|
||||
builder = builder.Where(squirrel.Eq{"agent_id": *req.AgentId})
|
||||
}
|
||||
if req.Status != nil {
|
||||
builder = builder.Where(squirrel.Eq{"status": *req.Status})
|
||||
}
|
||||
// 产品名称筛选功能已移除,如需可按product_id筛选
|
||||
|
||||
list, total, err := l.svcCtx.AgentCommissionModel.FindPageListByPageWithTotal(l.ctx, builder, req.Page, req.PageSize, "create_time DESC")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 批量查product_name
|
||||
productIds := make(map[int64]struct{})
|
||||
for _, v := range list {
|
||||
productIds[v.ProductId] = struct{}{}
|
||||
}
|
||||
productNameMap := make(map[int64]string)
|
||||
if len(productIds) > 0 {
|
||||
ids := make([]int64, 0, len(productIds))
|
||||
for id := range productIds {
|
||||
ids = append(ids, id)
|
||||
}
|
||||
builder := l.svcCtx.ProductModel.SelectBuilder().Where(squirrel.Eq{"id": ids})
|
||||
products, _ := l.svcCtx.ProductModel.FindAll(l.ctx, builder, "")
|
||||
for _, p := range products {
|
||||
productNameMap[p.Id] = p.ProductName
|
||||
}
|
||||
}
|
||||
|
||||
items := make([]types.AgentCommissionListItem, 0, len(list))
|
||||
for _, v := range list {
|
||||
item := types.AgentCommissionListItem{}
|
||||
_ = copier.Copy(&item, v)
|
||||
item.ProductName = productNameMap[v.ProductId]
|
||||
item.CreateTime = v.CreateTime.Format("2006-01-02 15:04:05")
|
||||
items = append(items, item)
|
||||
}
|
||||
resp = &types.AdminGetAgentCommissionListResp{
|
||||
Total: total,
|
||||
Items: items,
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
package admin_agent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
|
||||
"ycc-server/app/main/api/internal/svc"
|
||||
"ycc-server/app/main/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type AdminGetAgentConfigLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewAdminGetAgentConfigLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AdminGetAgentConfigLogic {
|
||||
return &AdminGetAgentConfigLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *AdminGetAgentConfigLogic) AdminGetAgentConfig() (resp *types.AdminGetAgentConfigResp, err error) {
|
||||
// 获取配置值的辅助函数
|
||||
getConfigFloat := func(key string) float64 {
|
||||
config, err := l.svcCtx.AgentConfigModel.FindOneByConfigKey(l.ctx, key)
|
||||
if err != nil {
|
||||
return 0
|
||||
}
|
||||
value, _ := strconv.ParseFloat(config.ConfigValue, 64)
|
||||
return value
|
||||
}
|
||||
|
||||
// 获取等级加成配置
|
||||
level1Bonus := getConfigFloat("level_1_bonus")
|
||||
level2Bonus := getConfigFloat("level_2_bonus")
|
||||
level3Bonus := getConfigFloat("level_3_bonus")
|
||||
|
||||
// 获取升级费用配置
|
||||
upgradeToGoldFee := getConfigFloat("upgrade_to_gold_fee")
|
||||
upgradeToDiamondFee := getConfigFloat("upgrade_to_diamond_fee")
|
||||
|
||||
// 获取升级返佣配置
|
||||
upgradeToGoldRebate := getConfigFloat("upgrade_to_gold_rebate")
|
||||
upgradeToDiamondRebate := getConfigFloat("upgrade_to_diamond_rebate")
|
||||
|
||||
return &types.AdminGetAgentConfigResp{
|
||||
BasePrice: getConfigFloat("base_price"),
|
||||
SystemMaxPrice: getConfigFloat("system_max_price"),
|
||||
PriceThreshold: getConfigFloat("price_threshold"),
|
||||
PriceFeeRate: getConfigFloat("price_fee_rate"),
|
||||
LevelBonus: types.LevelBonusConfig{
|
||||
Normal: int64(level1Bonus),
|
||||
Gold: int64(level2Bonus),
|
||||
Diamond: int64(level3Bonus),
|
||||
},
|
||||
UpgradeFee: types.UpgradeFeeConfig{
|
||||
NormalToGold: upgradeToGoldFee,
|
||||
NormalToDiamond: upgradeToDiamondFee,
|
||||
GoldToDiamond: upgradeToDiamondFee - upgradeToGoldFee,
|
||||
},
|
||||
UpgradeRebate: types.UpgradeRebateConfig{
|
||||
NormalToGoldRebate: upgradeToGoldRebate,
|
||||
ToDiamondRebate: upgradeToDiamondRebate,
|
||||
},
|
||||
TaxRate: getConfigFloat("tax_rate"),
|
||||
TaxExemptionAmount: getConfigFloat("tax_exemption_amount"),
|
||||
}, nil
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
package admin_agent
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"ycc-server/app/main/api/internal/svc"
|
||||
"ycc-server/app/main/api/internal/types"
|
||||
|
||||
"github.com/Masterminds/squirrel"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type AdminGetAgentLinkListLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewAdminGetAgentLinkListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AdminGetAgentLinkListLogic {
|
||||
return &AdminGetAgentLinkListLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *AdminGetAgentLinkListLogic) AdminGetAgentLinkList(req *types.AdminGetAgentLinkListReq) (resp *types.AdminGetAgentLinkListResp, err error) {
|
||||
builder := l.svcCtx.AgentLinkModel.SelectBuilder()
|
||||
if req.AgentId != nil {
|
||||
builder = builder.Where("agent_id = ?", *req.AgentId)
|
||||
}
|
||||
if req.LinkIdentifier != nil && *req.LinkIdentifier != "" {
|
||||
builder = builder.Where("link_identifier = ?", *req.LinkIdentifier)
|
||||
}
|
||||
|
||||
// 如果传入ProductId,添加筛选条件
|
||||
if req.ProductId != nil {
|
||||
builder = builder.Where("product_id = ?", *req.ProductId)
|
||||
}
|
||||
|
||||
links, total, err := l.svcCtx.AgentLinkModel.FindPageListByPageWithTotal(l.ctx, builder, req.Page, req.PageSize, "id DESC")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 批量查product_id->name,避免N+1
|
||||
productIdSet := make(map[int64]struct{})
|
||||
for _, link := range links {
|
||||
productIdSet[link.ProductId] = struct{}{}
|
||||
}
|
||||
productIdList := make([]int64, 0, len(productIdSet))
|
||||
for id := range productIdSet {
|
||||
productIdList = append(productIdList, id)
|
||||
}
|
||||
productNameMap := make(map[int64]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 {
|
||||
productNameMap[p.Id] = p.ProductName
|
||||
}
|
||||
}
|
||||
|
||||
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,
|
||||
ActualBasePrice: link.ActualBasePrice,
|
||||
LinkIdentifier: link.LinkIdentifier,
|
||||
CreateTime: link.CreateTime.Format("2006-01-02 15:04:05"),
|
||||
})
|
||||
}
|
||||
|
||||
resp = &types.AdminGetAgentLinkListResp{
|
||||
Total: total,
|
||||
Items: items,
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
package admin_agent
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"ycc-server/app/main/api/internal/svc"
|
||||
"ycc-server/app/main/api/internal/types"
|
||||
"ycc-server/common/xerr"
|
||||
"ycc-server/pkg/lzkit/crypto"
|
||||
|
||||
"github.com/Masterminds/squirrel"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type AdminGetAgentListLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewAdminGetAgentListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AdminGetAgentListLogic {
|
||||
return &AdminGetAgentListLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
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})
|
||||
}
|
||||
if req.Level != nil {
|
||||
builder = builder.Where(squirrel.Eq{"level": *req.Level})
|
||||
}
|
||||
if req.Mobile != nil && *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)
|
||||
}
|
||||
builder = builder.Where(squirrel.Eq{"mobile": encryptedMobile})
|
||||
}
|
||||
if req.Region != nil && *req.Region != "" {
|
||||
// 注意:region字段现在是可选的,查询时需要处理NULL值
|
||||
// 如果region字段是NULL,使用IS NULL查询;否则使用等值查询
|
||||
// 这里简化处理,直接使用等值查询(如果数据库中有NULL值,需要特殊处理)
|
||||
builder = builder.Where(squirrel.Eq{"region": *req.Region})
|
||||
}
|
||||
|
||||
agents, total, err := l.svcCtx.AgentModel.FindPageListByPageWithTotal(l.ctx, builder, req.Page, req.PageSize, "id DESC")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
items := make([]types.AgentListItem, 0, len(agents))
|
||||
|
||||
for _, agent := range agents {
|
||||
// 获取等级名称
|
||||
levelName := ""
|
||||
switch agent.Level {
|
||||
case 1:
|
||||
levelName = "普通"
|
||||
case 2:
|
||||
levelName = "黄金"
|
||||
case 3:
|
||||
levelName = "钻石"
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
// 查询钱包信息
|
||||
wallet, _ := l.svcCtx.AgentWalletModel.FindOneByAgentId(l.ctx, agent.Id)
|
||||
|
||||
// 查询实名认证信息
|
||||
realNameInfo, _ := l.svcCtx.AgentRealNameModel.FindOneByAgentId(l.ctx, agent.Id)
|
||||
isRealName := false
|
||||
if realNameInfo != nil && realNameInfo.VerifyTime.Valid {
|
||||
isRealName = true // verify_time不为空表示已通过三要素核验
|
||||
}
|
||||
|
||||
wechatId := ""
|
||||
if agent.WechatId.Valid {
|
||||
wechatId = agent.WechatId.String
|
||||
}
|
||||
teamLeaderId := int64(0)
|
||||
if agent.TeamLeaderId.Valid {
|
||||
teamLeaderId = agent.TeamLeaderId.Int64
|
||||
}
|
||||
|
||||
// 获取区域
|
||||
region := ""
|
||||
if agent.Region.Valid {
|
||||
region = agent.Region.String
|
||||
}
|
||||
|
||||
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,
|
||||
WithdrawnAmount: 0,
|
||||
IsRealName: isRealName,
|
||||
CreateTime: agent.CreateTime.Format("2006-01-02 15:04:05"),
|
||||
}
|
||||
|
||||
if wallet != nil {
|
||||
item.Balance = wallet.Balance
|
||||
item.TotalEarnings = wallet.TotalEarnings
|
||||
item.FrozenBalance = wallet.FrozenBalance
|
||||
item.WithdrawnAmount = wallet.WithdrawnAmount
|
||||
}
|
||||
|
||||
items = append(items, item)
|
||||
}
|
||||
|
||||
resp = &types.AdminGetAgentListResp{
|
||||
Total: total,
|
||||
Items: items,
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
package admin_agent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"ycc-server/common/globalkey"
|
||||
"ycc-server/common/xerr"
|
||||
|
||||
"github.com/Masterminds/squirrel"
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"ycc-server/app/main/api/internal/svc"
|
||||
"ycc-server/app/main/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type AdminGetAgentOrderListLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewAdminGetAgentOrderListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AdminGetAgentOrderListLogic {
|
||||
return &AdminGetAgentOrderListLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *AdminGetAgentOrderListLogic) AdminGetAgentOrderList(req *types.AdminGetAgentOrderListReq) (resp *types.AdminGetAgentOrderListResp, err error) {
|
||||
builder := l.svcCtx.AgentOrderModel.SelectBuilder().
|
||||
Where("del_state = ?", globalkey.DelStateNo)
|
||||
|
||||
if req.AgentId != nil {
|
||||
builder = builder.Where("agent_id = ?", *req.AgentId)
|
||||
}
|
||||
if req.OrderId != nil {
|
||||
builder = builder.Where("order_id = ?", *req.OrderId)
|
||||
}
|
||||
if req.ProcessStatus != nil {
|
||||
builder = builder.Where("process_status = ?", *req.ProcessStatus)
|
||||
}
|
||||
|
||||
// 分页查询
|
||||
page := req.Page
|
||||
if page <= 0 {
|
||||
page = 1
|
||||
}
|
||||
pageSize := req.PageSize
|
||||
if pageSize <= 0 {
|
||||
pageSize = 20
|
||||
}
|
||||
|
||||
orders, total, err := l.svcCtx.AgentOrderModel.FindPageListByPageWithTotal(l.ctx, builder, page, pageSize, "create_time DESC")
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "查询代理订单列表失败, %v", err)
|
||||
}
|
||||
|
||||
// 批量查询产品名称
|
||||
productIdSet := make(map[int64]struct{})
|
||||
for _, order := range orders {
|
||||
productIdSet[order.ProductId] = struct{}{}
|
||||
}
|
||||
productIdList := make([]int64, 0, len(productIdSet))
|
||||
for id := range productIdSet {
|
||||
productIdList = append(productIdList, id)
|
||||
}
|
||||
productNameMap := make(map[int64]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 {
|
||||
productNameMap[p.Id] = p.ProductName
|
||||
}
|
||||
}
|
||||
|
||||
// 组装响应
|
||||
items := make([]types.AgentOrderListItem, 0, len(orders))
|
||||
for _, order := range orders {
|
||||
items = append(items, types.AgentOrderListItem{
|
||||
Id: order.Id,
|
||||
AgentId: order.AgentId,
|
||||
OrderId: order.OrderId,
|
||||
ProductId: order.ProductId,
|
||||
ProductName: productNameMap[order.ProductId],
|
||||
OrderAmount: order.OrderAmount,
|
||||
SetPrice: order.SetPrice,
|
||||
ActualBasePrice: order.ActualBasePrice,
|
||||
PriceCost: order.PriceCost,
|
||||
AgentProfit: order.AgentProfit,
|
||||
ProcessStatus: order.ProcessStatus,
|
||||
CreateTime: order.CreateTime.Format("2006-01-02 15:04:05"),
|
||||
})
|
||||
}
|
||||
|
||||
return &types.AdminGetAgentOrderListResp{
|
||||
Total: total,
|
||||
Items: items,
|
||||
}, nil
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
package admin_agent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"ycc-server/common/globalkey"
|
||||
"ycc-server/common/xerr"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"ycc-server/app/main/api/internal/svc"
|
||||
"ycc-server/app/main/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type AdminGetAgentProductConfigListLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewAdminGetAgentProductConfigListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AdminGetAgentProductConfigListLogic {
|
||||
return &AdminGetAgentProductConfigListLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *AdminGetAgentProductConfigListLogic) AdminGetAgentProductConfigList(req *types.AdminGetAgentProductConfigListReq) (resp *types.AdminGetAgentProductConfigListResp, err error) {
|
||||
builder := l.svcCtx.AgentProductConfigModel.SelectBuilder().
|
||||
Where("del_state = ?", globalkey.DelStateNo)
|
||||
|
||||
if req.ProductId != nil {
|
||||
builder = builder.Where("product_id = ?", *req.ProductId)
|
||||
}
|
||||
|
||||
// 分页查询
|
||||
page := req.Page
|
||||
if page <= 0 {
|
||||
page = 1
|
||||
}
|
||||
pageSize := req.PageSize
|
||||
if pageSize <= 0 {
|
||||
pageSize = 20
|
||||
}
|
||||
|
||||
configs, total, err := l.svcCtx.AgentProductConfigModel.FindPageListByPageWithTotal(l.ctx, builder, page, pageSize, "id DESC")
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "查询产品配置列表失败, %v", err)
|
||||
}
|
||||
|
||||
// 组装响应
|
||||
items := make([]types.AgentProductConfigItem, 0, len(configs))
|
||||
for _, config := range configs {
|
||||
priceThreshold := 0.0
|
||||
if config.PriceThreshold.Valid {
|
||||
priceThreshold = config.PriceThreshold.Float64
|
||||
}
|
||||
|
||||
priceFeeRate := 0.0
|
||||
if config.PriceFeeRate.Valid {
|
||||
priceFeeRate = config.PriceFeeRate.Float64
|
||||
}
|
||||
|
||||
items = append(items, types.AgentProductConfigItem{
|
||||
Id: config.Id,
|
||||
ProductId: config.ProductId,
|
||||
ProductName: config.ProductName,
|
||||
BasePrice: config.BasePrice,
|
||||
PriceRangeMin: config.BasePrice, // 最低定价等于基础底价
|
||||
PriceRangeMax: config.SystemMaxPrice,
|
||||
PriceThreshold: priceThreshold,
|
||||
PriceFeeRate: priceFeeRate,
|
||||
CreateTime: config.CreateTime.Format("2006-01-02 15:04:05"),
|
||||
})
|
||||
}
|
||||
|
||||
return &types.AdminGetAgentProductConfigListResp{
|
||||
Total: total,
|
||||
Items: items,
|
||||
}, nil
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
package admin_agent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"ycc-server/common/globalkey"
|
||||
"ycc-server/common/xerr"
|
||||
"ycc-server/pkg/lzkit/crypto"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"ycc-server/app/main/api/internal/svc"
|
||||
"ycc-server/app/main/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type AdminGetAgentRealNameListLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewAdminGetAgentRealNameListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AdminGetAgentRealNameListLogic {
|
||||
return &AdminGetAgentRealNameListLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *AdminGetAgentRealNameListLogic) AdminGetAgentRealNameList(req *types.AdminGetAgentRealNameListReq) (resp *types.AdminGetAgentRealNameListResp, err error) {
|
||||
builder := l.svcCtx.AgentRealNameModel.SelectBuilder().
|
||||
Where("del_state = ?", globalkey.DelStateNo)
|
||||
|
||||
if req.AgentId != nil {
|
||||
builder = builder.Where("agent_id = ?", *req.AgentId)
|
||||
}
|
||||
if req.Status != nil {
|
||||
// 根据状态过滤:1=未验证(verify_time为NULL),2=已通过(verify_time不为NULL)
|
||||
switch *req.Status {
|
||||
case 1: // 未验证
|
||||
builder = builder.Where("verify_time IS NULL")
|
||||
case 2: // 已通过
|
||||
builder = builder.Where("verify_time IS NOT NULL")
|
||||
}
|
||||
}
|
||||
|
||||
// 分页查询
|
||||
page := req.Page
|
||||
if page <= 0 {
|
||||
page = 1
|
||||
}
|
||||
pageSize := req.PageSize
|
||||
if pageSize <= 0 {
|
||||
pageSize = 20
|
||||
}
|
||||
|
||||
realNames, total, err := l.svcCtx.AgentRealNameModel.FindPageListByPageWithTotal(l.ctx, builder, page, pageSize, "create_time DESC")
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "查询实名认证列表失败, %v", err)
|
||||
}
|
||||
|
||||
// 组装响应
|
||||
items := make([]types.AgentRealNameListItem, 0, len(realNames))
|
||||
for _, realName := range realNames {
|
||||
// 解密手机号(仅显示部分)
|
||||
mobile := ""
|
||||
if realName.Mobile != "" {
|
||||
decrypted, err := crypto.DecryptMobile(realName.Mobile, l.svcCtx.Config.Encrypt.SecretKey)
|
||||
if err == nil {
|
||||
mobile = decrypted
|
||||
}
|
||||
}
|
||||
|
||||
// 解密身份证号(仅显示部分)
|
||||
idCard := ""
|
||||
if realName.IdCard != "" {
|
||||
decrypted, err := crypto.DecryptIDCard(realName.IdCard, []byte(l.svcCtx.Config.Encrypt.SecretKey))
|
||||
if err == nil {
|
||||
// 脱敏显示
|
||||
if len(decrypted) > 10 {
|
||||
idCard = decrypted[:3] + "***********" + decrypted[len(decrypted)-4:]
|
||||
} else {
|
||||
idCard = decrypted
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 根据verify_time判断状态:NULL=未验证(1),不为NULL=已通过(2)
|
||||
statusInt := int64(1) // 默认未验证
|
||||
verifyTime := ""
|
||||
if realName.VerifyTime.Valid {
|
||||
statusInt = 2 // 已通过
|
||||
verifyTime = realName.VerifyTime.Time.Format("2006-01-02 15:04:05")
|
||||
}
|
||||
|
||||
item := types.AgentRealNameListItem{
|
||||
Id: realName.Id,
|
||||
AgentId: realName.AgentId,
|
||||
Name: realName.Name,
|
||||
IdCard: idCard,
|
||||
Mobile: mobile,
|
||||
Status: statusInt,
|
||||
CreateTime: realName.CreateTime.Format("2006-01-02 15:04:05"),
|
||||
}
|
||||
// TODO: 重新生成接口后,取消注释下面的代码
|
||||
item.VerifyTime = verifyTime
|
||||
items = append(items, item)
|
||||
}
|
||||
|
||||
return &types.AdminGetAgentRealNameListResp{
|
||||
Total: total,
|
||||
Items: items,
|
||||
}, nil
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
package admin_agent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"ycc-server/common/globalkey"
|
||||
"ycc-server/common/xerr"
|
||||
|
||||
"github.com/Masterminds/squirrel"
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"ycc-server/app/main/api/internal/svc"
|
||||
"ycc-server/app/main/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type AdminGetAgentRebateListLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewAdminGetAgentRebateListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AdminGetAgentRebateListLogic {
|
||||
return &AdminGetAgentRebateListLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *AdminGetAgentRebateListLogic) AdminGetAgentRebateList(req *types.AdminGetAgentRebateListReq) (resp *types.AdminGetAgentRebateListResp, err error) {
|
||||
builder := l.svcCtx.AgentRebateModel.SelectBuilder().
|
||||
Where("del_state = ?", globalkey.DelStateNo)
|
||||
|
||||
if req.AgentId != nil {
|
||||
builder = builder.Where("agent_id = ?", *req.AgentId)
|
||||
}
|
||||
if req.SourceAgentId != nil {
|
||||
builder = builder.Where("source_agent_id = ?", *req.SourceAgentId)
|
||||
}
|
||||
if req.RebateType != nil {
|
||||
builder = builder.Where("rebate_type = ?", *req.RebateType)
|
||||
}
|
||||
|
||||
// 分页查询
|
||||
page := req.Page
|
||||
if page <= 0 {
|
||||
page = 1
|
||||
}
|
||||
pageSize := req.PageSize
|
||||
if pageSize <= 0 {
|
||||
pageSize = 20
|
||||
}
|
||||
|
||||
rebates, total, err := l.svcCtx.AgentRebateModel.FindPageListByPageWithTotal(l.ctx, builder, page, pageSize, "create_time DESC")
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "查询返佣列表失败, %v", err)
|
||||
}
|
||||
|
||||
// 批量查询产品名称
|
||||
productIdSet := make(map[int64]struct{})
|
||||
for _, rebate := range rebates {
|
||||
productIdSet[rebate.ProductId] = struct{}{}
|
||||
}
|
||||
productIdList := make([]int64, 0, len(productIdSet))
|
||||
for id := range productIdSet {
|
||||
productIdList = append(productIdList, id)
|
||||
}
|
||||
productNameMap := make(map[int64]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 {
|
||||
productNameMap[p.Id] = p.ProductName
|
||||
}
|
||||
}
|
||||
|
||||
// 组装响应
|
||||
items := make([]types.AgentRebateListItem, 0, len(rebates))
|
||||
for _, rebate := range rebates {
|
||||
items = append(items, types.AgentRebateListItem{
|
||||
Id: rebate.Id,
|
||||
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"),
|
||||
})
|
||||
}
|
||||
|
||||
return &types.AdminGetAgentRebateListResp{
|
||||
Total: total,
|
||||
Items: items,
|
||||
}, nil
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
package admin_agent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"ycc-server/common/globalkey"
|
||||
"ycc-server/common/xerr"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"ycc-server/app/main/api/internal/svc"
|
||||
"ycc-server/app/main/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type AdminGetAgentUpgradeListLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewAdminGetAgentUpgradeListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AdminGetAgentUpgradeListLogic {
|
||||
return &AdminGetAgentUpgradeListLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *AdminGetAgentUpgradeListLogic) AdminGetAgentUpgradeList(req *types.AdminGetAgentUpgradeListReq) (resp *types.AdminGetAgentUpgradeListResp, err error) {
|
||||
builder := l.svcCtx.AgentUpgradeModel.SelectBuilder().
|
||||
Where("del_state = ?", globalkey.DelStateNo)
|
||||
|
||||
if req.AgentId != nil {
|
||||
builder = builder.Where("agent_id = ?", *req.AgentId)
|
||||
}
|
||||
if req.UpgradeType != nil {
|
||||
builder = builder.Where("upgrade_type = ?", *req.UpgradeType)
|
||||
}
|
||||
if req.Status != nil {
|
||||
builder = builder.Where("status = ?", *req.Status)
|
||||
}
|
||||
|
||||
// 分页查询
|
||||
page := req.Page
|
||||
if page <= 0 {
|
||||
page = 1
|
||||
}
|
||||
pageSize := req.PageSize
|
||||
if pageSize <= 0 {
|
||||
pageSize = 20
|
||||
}
|
||||
|
||||
upgrades, total, err := l.svcCtx.AgentUpgradeModel.FindPageListByPageWithTotal(l.ctx, builder, page, pageSize, "create_time DESC")
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "查询升级记录列表失败, %v", err)
|
||||
}
|
||||
|
||||
// 组装响应
|
||||
items := make([]types.AgentUpgradeListItem, 0, len(upgrades))
|
||||
for _, upgrade := range upgrades {
|
||||
items = append(items, types.AgentUpgradeListItem{
|
||||
Id: upgrade.Id,
|
||||
AgentId: upgrade.AgentId,
|
||||
FromLevel: upgrade.FromLevel,
|
||||
ToLevel: upgrade.ToLevel,
|
||||
UpgradeType: upgrade.UpgradeType,
|
||||
UpgradeFee: upgrade.UpgradeFee,
|
||||
RebateAmount: upgrade.RebateAmount,
|
||||
Status: upgrade.Status,
|
||||
CreateTime: upgrade.CreateTime.Format("2006-01-02 15:04:05"),
|
||||
})
|
||||
}
|
||||
|
||||
return &types.AdminGetAgentUpgradeListResp{
|
||||
Total: total,
|
||||
Items: items,
|
||||
}, nil
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package admin_agent
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"ycc-server/app/main/api/internal/svc"
|
||||
"ycc-server/app/main/api/internal/types"
|
||||
|
||||
"github.com/Masterminds/squirrel"
|
||||
"github.com/jinzhu/copier"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type AdminGetAgentWithdrawalListLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewAdminGetAgentWithdrawalListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AdminGetAgentWithdrawalListLogic {
|
||||
return &AdminGetAgentWithdrawalListLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *AdminGetAgentWithdrawalListLogic) AdminGetAgentWithdrawalList(req *types.AdminGetAgentWithdrawalListReq) (resp *types.AdminGetAgentWithdrawalListResp, err error) {
|
||||
builder := l.svcCtx.AgentWithdrawalModel.SelectBuilder()
|
||||
if req.AgentId != nil {
|
||||
builder = builder.Where(squirrel.Eq{"agent_id": *req.AgentId})
|
||||
}
|
||||
if req.Status != nil {
|
||||
builder = builder.Where(squirrel.Eq{"status": *req.Status})
|
||||
}
|
||||
if req.WithdrawNo != nil && *req.WithdrawNo != "" {
|
||||
builder = builder.Where(squirrel.Eq{"withdraw_no": *req.WithdrawNo})
|
||||
}
|
||||
list, total, err := l.svcCtx.AgentWithdrawalModel.FindPageListByPageWithTotal(l.ctx, builder, req.Page, req.PageSize, "create_time DESC")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items := make([]types.AgentWithdrawalListItem, 0, len(list))
|
||||
for _, v := range list {
|
||||
item := types.AgentWithdrawalListItem{}
|
||||
_ = copier.Copy(&item, v)
|
||||
item.Remark = ""
|
||||
if v.Remark.Valid {
|
||||
item.Remark = v.Remark.String
|
||||
}
|
||||
item.CreateTime = v.CreateTime.Format("2006-01-02 15:04:05")
|
||||
items = append(items, item)
|
||||
}
|
||||
resp = &types.AdminGetAgentWithdrawalListResp{
|
||||
Total: total,
|
||||
Items: items,
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
package admin_agent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"ycc-server/common/globalkey"
|
||||
"ycc-server/common/xerr"
|
||||
"ycc-server/pkg/lzkit/crypto"
|
||||
|
||||
"github.com/Masterminds/squirrel"
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"ycc-server/app/main/api/internal/svc"
|
||||
"ycc-server/app/main/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type AdminGetInviteCodeListLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewAdminGetInviteCodeListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AdminGetInviteCodeListLogic {
|
||||
return &AdminGetInviteCodeListLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *AdminGetInviteCodeListLogic) AdminGetInviteCodeList(req *types.AdminGetInviteCodeListReq) (resp *types.AdminGetInviteCodeListResp, err error) {
|
||||
// 1. 构建查询条件
|
||||
builder := l.svcCtx.AgentInviteCodeModel.SelectBuilder().
|
||||
Where("del_state = ?", globalkey.DelStateNo)
|
||||
|
||||
if req.Code != nil && *req.Code != "" {
|
||||
builder = builder.Where("code = ?", *req.Code)
|
||||
}
|
||||
if req.AgentId != nil {
|
||||
if *req.AgentId == 0 {
|
||||
// agent_id = 0 表示查询平台发放的邀请码(agent_id为NULL)
|
||||
builder = builder.Where("agent_id IS NULL")
|
||||
} else {
|
||||
builder = builder.Where("agent_id = ?", *req.AgentId)
|
||||
}
|
||||
}
|
||||
if req.TargetLevel != nil {
|
||||
builder = builder.Where("target_level = ?", *req.TargetLevel)
|
||||
}
|
||||
if req.Status != nil {
|
||||
builder = builder.Where("status = ?", *req.Status)
|
||||
}
|
||||
|
||||
// 2. 分页查询
|
||||
list, total, err := l.svcCtx.AgentInviteCodeModel.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)
|
||||
}
|
||||
|
||||
// 3. 批量查询代理信息(用于显示代理手机号)
|
||||
agentIds := make(map[int64]struct{})
|
||||
for _, v := range list {
|
||||
if v.AgentId.Valid && v.AgentId.Int64 > 0 {
|
||||
agentIds[v.AgentId.Int64] = struct{}{}
|
||||
}
|
||||
}
|
||||
|
||||
agentMobileMap := make(map[int64]string)
|
||||
if len(agentIds) > 0 {
|
||||
agentIdList := make([]int64, 0, len(agentIds))
|
||||
for id := range agentIds {
|
||||
agentIdList = append(agentIdList, id)
|
||||
}
|
||||
agents, _ := l.svcCtx.AgentModel.FindAll(l.ctx, l.svcCtx.AgentModel.SelectBuilder().Where(squirrel.Eq{"id": agentIdList}), "")
|
||||
secretKey := l.svcCtx.Config.Encrypt.SecretKey
|
||||
for _, agent := range agents {
|
||||
mobile, decErr := crypto.DecryptMobile(agent.Mobile, secretKey)
|
||||
if decErr == nil {
|
||||
agentMobileMap[agent.Id] = mobile
|
||||
} else {
|
||||
l.Logger.Errorf("解密代理手机号失败: %v", decErr)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 4. 格式化返回数据
|
||||
items := make([]types.InviteCodeListItem, 0, len(list))
|
||||
for _, v := range list {
|
||||
item := types.InviteCodeListItem{
|
||||
Id: v.Id,
|
||||
Code: v.Code,
|
||||
AgentId: 0,
|
||||
AgentMobile: "",
|
||||
TargetLevel: v.TargetLevel,
|
||||
Status: v.Status,
|
||||
CreateTime: v.CreateTime.Format("2006-01-02 15:04:05"),
|
||||
}
|
||||
|
||||
if v.AgentId.Valid {
|
||||
item.AgentId = v.AgentId.Int64
|
||||
item.AgentMobile = agentMobileMap[v.AgentId.Int64]
|
||||
}
|
||||
|
||||
if v.UsedUserId.Valid {
|
||||
item.UsedUserId = v.UsedUserId.Int64
|
||||
}
|
||||
if v.UsedAgentId.Valid {
|
||||
item.UsedAgentId = v.UsedAgentId.Int64
|
||||
}
|
||||
if v.UsedTime.Valid {
|
||||
item.UsedTime = v.UsedTime.Time.Format("2006-01-02 15:04:05")
|
||||
}
|
||||
if v.ExpireTime.Valid {
|
||||
item.ExpireTime = v.ExpireTime.Time.Format("2006-01-02 15:04:05")
|
||||
}
|
||||
if v.Remark.Valid {
|
||||
item.Remark = v.Remark.String
|
||||
}
|
||||
|
||||
items = append(items, item)
|
||||
}
|
||||
|
||||
return &types.AdminGetInviteCodeListResp{
|
||||
Total: total,
|
||||
Items: items,
|
||||
}, nil
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package admin_agent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
"ycc-server/common/xerr"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"ycc-server/app/main/api/internal/svc"
|
||||
"ycc-server/app/main/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type AdminUpdateAgentConfigLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewAdminUpdateAgentConfigLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AdminUpdateAgentConfigLogic {
|
||||
return &AdminUpdateAgentConfigLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *AdminUpdateAgentConfigLogic) AdminUpdateAgentConfig(req *types.AdminUpdateAgentConfigReq) (resp *types.AdminUpdateAgentConfigResp, err error) {
|
||||
// 更新配置的辅助函数
|
||||
updateConfig := func(key string, value *float64) error {
|
||||
if value == nil {
|
||||
return nil
|
||||
}
|
||||
config, err := l.svcCtx.AgentConfigModel.FindOneByConfigKey(l.ctx, key)
|
||||
if err != 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)
|
||||
}
|
||||
|
||||
// 更新各个配置项
|
||||
if err := updateConfig("base_price", req.BasePrice); err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "更新基础底价失败, %v", err)
|
||||
}
|
||||
if err := updateConfig("system_max_price", req.SystemMaxPrice); err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "更新系统价格上限失败, %v", err)
|
||||
}
|
||||
if err := updateConfig("price_threshold", req.PriceThreshold); err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "更新提价标准阈值失败, %v", err)
|
||||
}
|
||||
if err := updateConfig("price_fee_rate", req.PriceFeeRate); err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "更新提价手续费比例失败, %v", err)
|
||||
}
|
||||
if err := updateConfig("tax_rate", req.TaxRate); err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "更新税率失败, %v", err)
|
||||
}
|
||||
if err := updateConfig("tax_exemption_amount", req.TaxExemptionAmount); err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "更新免税额度失败, %v", err)
|
||||
}
|
||||
|
||||
return &types.AdminUpdateAgentConfigResp{
|
||||
Success: true,
|
||||
}, nil
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package admin_agent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"ycc-server/common/xerr"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"ycc-server/app/main/api/internal/svc"
|
||||
"ycc-server/app/main/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type AdminUpdateAgentProductConfigLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewAdminUpdateAgentProductConfigLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AdminUpdateAgentProductConfigLogic {
|
||||
return &AdminUpdateAgentProductConfigLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *AdminUpdateAgentProductConfigLogic) AdminUpdateAgentProductConfig(req *types.AdminUpdateAgentProductConfigReq) (resp *types.AdminUpdateAgentProductConfigResp, err error) {
|
||||
// 查询配置
|
||||
config, err := l.svcCtx.AgentProductConfigModel.FindOne(l.ctx, req.Id)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "查询产品配置失败, %v", err)
|
||||
}
|
||||
|
||||
// 更新配置字段
|
||||
config.BasePrice = req.BasePrice
|
||||
config.SystemMaxPrice = req.PriceRangeMax
|
||||
config.PriceThreshold = sql.NullFloat64{Float64: req.PriceThreshold, Valid: true}
|
||||
config.PriceFeeRate = sql.NullFloat64{Float64: req.PriceFeeRate, Valid: true}
|
||||
|
||||
// 更新配置
|
||||
if err := l.svcCtx.AgentProductConfigModel.UpdateWithVersion(l.ctx, nil, config); err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "更新产品配置失败, %v", err)
|
||||
}
|
||||
|
||||
return &types.AdminUpdateAgentProductConfigResp{
|
||||
Success: true,
|
||||
}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user