first commit
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
package admin_agent
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"hm-server/app/main/api/internal/svc"
|
||||
"hm-server/app/main/api/internal/types"
|
||||
|
||||
"github.com/Masterminds/squirrel"
|
||||
"github.com/jinzhu/copier"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type AdminGetAgentCommissionDeductionListLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewAdminGetAgentCommissionDeductionListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AdminGetAgentCommissionDeductionListLogic {
|
||||
return &AdminGetAgentCommissionDeductionListLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *AdminGetAgentCommissionDeductionListLogic) AdminGetAgentCommissionDeductionList(req *types.AdminGetAgentCommissionDeductionListReq) (resp *types.AdminGetAgentCommissionDeductionListResp, err error) {
|
||||
builder := l.svcCtx.AgentCommissionDeductionModel.SelectBuilder()
|
||||
if req.AgentId != nil {
|
||||
builder = builder.Where(squirrel.Eq{"agent_id": *req.AgentId})
|
||||
}
|
||||
if req.Type != nil && *req.Type != "" {
|
||||
builder = builder.Where(squirrel.Eq{"type": *req.Type})
|
||||
}
|
||||
if req.Status != nil {
|
||||
builder = builder.Where(squirrel.Eq{"status": *req.Status})
|
||||
}
|
||||
// 产品名筛选需先查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}), "")
|
||||
if err != nil || len(products) == 0 {
|
||||
return &types.AdminGetAgentCommissionDeductionListResp{Total: 0, Items: []types.AgentCommissionDeductionListItem{}}, nil
|
||||
}
|
||||
builder = builder.Where("product_id = ?", products[0].Id)
|
||||
}
|
||||
|
||||
list, total, err := l.svcCtx.AgentCommissionDeductionModel.FindPageListByPageWithTotal(l.ctx, builder, req.Page, req.PageSize, "create_time DESC")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 批量查product_id->name
|
||||
productIds := make(map[int64]struct{})
|
||||
for _, v := range list {
|
||||
productIds[v.ProductId] = struct{}{}
|
||||
}
|
||||
productIdArr := make([]int64, 0, len(productIds))
|
||||
for id := range productIds {
|
||||
productIdArr = append(productIdArr, id)
|
||||
}
|
||||
productNameMap := make(map[int64]string)
|
||||
if len(productIdArr) > 0 {
|
||||
build := l.svcCtx.ProductModel.SelectBuilder().Where(squirrel.Eq{"id": productIdArr})
|
||||
products, _ := l.svcCtx.ProductModel.FindAll(l.ctx, build, "")
|
||||
for _, p := range products {
|
||||
productNameMap[p.Id] = p.ProductName
|
||||
}
|
||||
}
|
||||
|
||||
items := make([]types.AgentCommissionDeductionListItem, 0, len(list))
|
||||
for _, v := range list {
|
||||
item := types.AgentCommissionDeductionListItem{}
|
||||
_ = 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.AdminGetAgentCommissionDeductionListResp{
|
||||
Total: total,
|
||||
Items: items,
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
package admin_agent
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"hm-server/app/main/api/internal/svc"
|
||||
"hm-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对应的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}), "")
|
||||
if err != nil || len(products) == 0 {
|
||||
return &types.AdminGetAgentCommissionListResp{Total: 0, Items: []types.AgentCommissionListItem{}}, nil
|
||||
}
|
||||
productIdFilter = products[0].Id
|
||||
builder = builder.Where("product_id = ?", productIdFilter)
|
||||
}
|
||||
|
||||
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,86 @@
|
||||
package admin_agent
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"hm-server/app/main/api/internal/svc"
|
||||
"hm-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)
|
||||
}
|
||||
|
||||
// 先查出所有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}), "")
|
||||
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)
|
||||
}
|
||||
|
||||
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{
|
||||
AgentId: link.AgentId,
|
||||
ProductName: productNameMap[link.ProductId],
|
||||
Price: link.Price,
|
||||
LinkIdentifier: link.LinkIdentifier,
|
||||
CreateTime: link.CreateTime.Format("2006-01-02 15:04:05"),
|
||||
})
|
||||
}
|
||||
|
||||
resp = &types.AdminGetAgentLinkListResp{
|
||||
Total: total,
|
||||
Items: items,
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
package admin_agent
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"hm-server/app/main/api/internal/svc"
|
||||
"hm-server/app/main/api/internal/types"
|
||||
"hm-server/app/main/model"
|
||||
"hm-server/common/xerr"
|
||||
"hm-server/pkg/lzkit/crypto"
|
||||
|
||||
"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()
|
||||
if req.Mobile != nil && *req.Mobile != "" {
|
||||
builder = builder.Where("mobile = ?", *req.Mobile)
|
||||
}
|
||||
if req.Region != nil && *req.Region != "" {
|
||||
builder = builder.Where("region = ?", *req.Region)
|
||||
}
|
||||
|
||||
// 新增:如果传入ParentAgentId,则查找其所有1级下级代理
|
||||
if req.ParentAgentId != nil {
|
||||
closureBuilder := l.svcCtx.AgentClosureModel.SelectBuilder().Where("ancestor_id = ? AND depth = 1", *req.ParentAgentId)
|
||||
closures, cerr := l.svcCtx.AgentClosureModel.FindAll(l.ctx, closureBuilder, "")
|
||||
if cerr != nil {
|
||||
return nil, cerr
|
||||
}
|
||||
if len(closures) == 0 {
|
||||
resp = &types.AdminGetAgentListResp{Total: 0, Items: []types.AgentListItem{}}
|
||||
return resp, nil
|
||||
}
|
||||
ids := make([]int64, 0, len(closures))
|
||||
for _, c := range closures {
|
||||
ids = append(ids, c.DescendantId)
|
||||
}
|
||||
builder = builder.Where("id IN (?)", ids)
|
||||
}
|
||||
|
||||
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 {
|
||||
item := types.AgentListItem{
|
||||
Id: agent.Id,
|
||||
UserId: agent.UserId,
|
||||
LevelName: agent.LevelName,
|
||||
Region: agent.Region,
|
||||
CreateTime: agent.CreateTime.Format("2006-01-02 15:04:05"),
|
||||
}
|
||||
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)
|
||||
}
|
||||
item.Mobile = agent.Mobile
|
||||
if agent.MembershipExpiryTime.Valid {
|
||||
item.MembershipExpiryTime = agent.MembershipExpiryTime.Time.Format("2006-01-02 15:04:05")
|
||||
}
|
||||
|
||||
// 查询钱包信息
|
||||
wallet, _ := l.svcCtx.AgentWalletModel.FindOneByAgentId(l.ctx, agent.Id)
|
||||
if wallet != nil {
|
||||
item.Balance = wallet.Balance
|
||||
item.TotalEarnings = wallet.TotalEarnings
|
||||
item.FrozenBalance = wallet.FrozenBalance
|
||||
item.WithdrawnAmount = wallet.WithdrawnAmount
|
||||
}
|
||||
|
||||
// 查询实名认证信息
|
||||
realNameInfo, _ := l.svcCtx.AgentRealNameModel.FindOneByAgentId(l.ctx, agent.Id)
|
||||
if realNameInfo != nil {
|
||||
item.IsRealNameVerified = realNameInfo.Status == model.AgentRealNameStatusApproved
|
||||
item.RealName = realNameInfo.Name
|
||||
item.IdCard = realNameInfo.IdCard
|
||||
item.RealNameStatus = realNameInfo.Status
|
||||
} else {
|
||||
item.IsRealNameVerified = false
|
||||
item.RealName = ""
|
||||
item.IdCard = ""
|
||||
item.RealNameStatus = ""
|
||||
}
|
||||
|
||||
items = append(items, item)
|
||||
}
|
||||
|
||||
resp = &types.AdminGetAgentListResp{
|
||||
Total: total,
|
||||
Items: items,
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package admin_agent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"hm-server/app/main/api/internal/svc"
|
||||
"hm-server/app/main/api/internal/types"
|
||||
|
||||
"github.com/Masterminds/squirrel"
|
||||
"github.com/jinzhu/copier"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type AdminGetAgentMembershipConfigListLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewAdminGetAgentMembershipConfigListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AdminGetAgentMembershipConfigListLogic {
|
||||
return &AdminGetAgentMembershipConfigListLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *AdminGetAgentMembershipConfigListLogic) AdminGetAgentMembershipConfigList(req *types.AdminGetAgentMembershipConfigListReq) (resp *types.AdminGetAgentMembershipConfigListResp, err error) {
|
||||
builder := l.svcCtx.AgentMembershipConfigModel.SelectBuilder()
|
||||
if req.LevelName != nil && *req.LevelName != "" {
|
||||
builder = builder.Where(squirrel.Eq{"level_name": *req.LevelName})
|
||||
}
|
||||
list, total, err := l.svcCtx.AgentMembershipConfigModel.FindPageListByPageWithTotal(l.ctx, builder, req.Page, req.PageSize, "id DESC")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items := make([]types.AgentMembershipConfigListItem, 0, len(list))
|
||||
for _, v := range list {
|
||||
var item types.AgentMembershipConfigListItem
|
||||
if err := copier.Copy(&item, v); err != nil {
|
||||
l.Logger.Errorf("copy error: %v", err)
|
||||
continue
|
||||
}
|
||||
item.CreateTime = v.CreateTime.Format("2006-01-02 15:04:05")
|
||||
items = append(items, item)
|
||||
}
|
||||
resp = &types.AdminGetAgentMembershipConfigListResp{
|
||||
Total: total,
|
||||
Items: items,
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package admin_agent
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"hm-server/app/main/api/internal/svc"
|
||||
"hm-server/app/main/api/internal/types"
|
||||
|
||||
"github.com/Masterminds/squirrel"
|
||||
"github.com/jinzhu/copier"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type AdminGetAgentMembershipRechargeOrderListLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewAdminGetAgentMembershipRechargeOrderListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AdminGetAgentMembershipRechargeOrderListLogic {
|
||||
return &AdminGetAgentMembershipRechargeOrderListLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *AdminGetAgentMembershipRechargeOrderListLogic) AdminGetAgentMembershipRechargeOrderList(req *types.AdminGetAgentMembershipRechargeOrderListReq) (resp *types.AdminGetAgentMembershipRechargeOrderListResp, err error) {
|
||||
builder := l.svcCtx.AgentMembershipRechargeOrderModel.SelectBuilder()
|
||||
if req.UserId != nil {
|
||||
builder = builder.Where(squirrel.Eq{"user_id": *req.UserId})
|
||||
}
|
||||
if req.AgentId != nil {
|
||||
builder = builder.Where(squirrel.Eq{"agent_id": *req.AgentId})
|
||||
}
|
||||
if req.OrderNo != nil && *req.OrderNo != "" {
|
||||
builder = builder.Where(squirrel.Eq{"order_no": *req.OrderNo})
|
||||
}
|
||||
if req.PlatformOrderId != nil && *req.PlatformOrderId != "" {
|
||||
builder = builder.Where(squirrel.Eq{"platform_order_id": *req.PlatformOrderId})
|
||||
}
|
||||
if req.Status != nil && *req.Status != "" {
|
||||
builder = builder.Where(squirrel.Eq{"status": *req.Status})
|
||||
}
|
||||
if req.PaymentMethod != nil && *req.PaymentMethod != "" {
|
||||
builder = builder.Where(squirrel.Eq{"payment_method": *req.PaymentMethod})
|
||||
}
|
||||
list, total, err := l.svcCtx.AgentMembershipRechargeOrderModel.FindPageListByPageWithTotal(l.ctx, builder, req.Page, req.PageSize, "create_time DESC")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items := make([]types.AgentMembershipRechargeOrderListItem, 0, len(list))
|
||||
for _, v := range list {
|
||||
item := types.AgentMembershipRechargeOrderListItem{}
|
||||
_ = copier.Copy(&item, v)
|
||||
item.CreateTime = v.CreateTime.Format("2006-01-02 15:04:05")
|
||||
items = append(items, item)
|
||||
}
|
||||
resp = &types.AdminGetAgentMembershipRechargeOrderListResp{
|
||||
Total: total,
|
||||
Items: items,
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package admin_agent
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"hm-server/app/main/api/internal/svc"
|
||||
"hm-server/app/main/api/internal/types"
|
||||
|
||||
"github.com/Masterminds/squirrel"
|
||||
"github.com/jinzhu/copier"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type AdminGetAgentPlatformDeductionListLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewAdminGetAgentPlatformDeductionListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AdminGetAgentPlatformDeductionListLogic {
|
||||
return &AdminGetAgentPlatformDeductionListLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *AdminGetAgentPlatformDeductionListLogic) AdminGetAgentPlatformDeductionList(req *types.AdminGetAgentPlatformDeductionListReq) (resp *types.AdminGetAgentPlatformDeductionListResp, err error) {
|
||||
builder := l.svcCtx.AgentPlatformDeductionModel.SelectBuilder()
|
||||
if req.AgentId != nil {
|
||||
builder = builder.Where(squirrel.Eq{"agent_id": *req.AgentId})
|
||||
}
|
||||
if req.Type != nil && *req.Type != "" {
|
||||
builder = builder.Where(squirrel.Eq{"type": *req.Type})
|
||||
}
|
||||
if req.Status != nil {
|
||||
builder = builder.Where(squirrel.Eq{"status": *req.Status})
|
||||
}
|
||||
|
||||
list, total, err := l.svcCtx.AgentPlatformDeductionModel.FindPageListByPageWithTotal(l.ctx, builder, req.Page, req.PageSize, "create_time DESC")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
items := make([]types.AgentPlatformDeductionListItem, 0, len(list))
|
||||
for _, v := range list {
|
||||
item := types.AgentPlatformDeductionListItem{}
|
||||
_ = copier.Copy(&item, v)
|
||||
item.CreateTime = v.CreateTime.Format("2006-01-02 15:04:05")
|
||||
items = append(items, item)
|
||||
}
|
||||
resp = &types.AdminGetAgentPlatformDeductionListResp{
|
||||
Total: total,
|
||||
Items: items,
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package admin_agent
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"hm-server/app/main/api/internal/svc"
|
||||
"hm-server/app/main/api/internal/types"
|
||||
|
||||
"github.com/Masterminds/squirrel"
|
||||
"github.com/jinzhu/copier"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type AdminGetAgentProductionConfigListLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewAdminGetAgentProductionConfigListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AdminGetAgentProductionConfigListLogic {
|
||||
return &AdminGetAgentProductionConfigListLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *AdminGetAgentProductionConfigListLogic) AdminGetAgentProductionConfigList(req *types.AdminGetAgentProductionConfigListReq) (resp *types.AdminGetAgentProductionConfigListResp, err error) {
|
||||
builder := l.svcCtx.AgentProductConfigModel.SelectBuilder()
|
||||
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}), "")
|
||||
if err != nil || len(products) == 0 {
|
||||
return &types.AdminGetAgentProductionConfigListResp{Total: 0, Items: []types.AgentProductionConfigItem{}}, nil
|
||||
}
|
||||
builder = builder.Where(squirrel.Eq{"product_id": products[0].Id})
|
||||
}
|
||||
if req.Id != nil {
|
||||
builder = builder.Where(squirrel.Eq{"id": *req.Id})
|
||||
}
|
||||
list, total, err := l.svcCtx.AgentProductConfigModel.FindPageListByPageWithTotal(l.ctx, builder, req.Page, req.PageSize, "create_time DESC")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// 查询所有涉及到的product_id对应的product_name
|
||||
productIdSet := make(map[int64]struct{})
|
||||
for _, v := range list {
|
||||
productIdSet[v.ProductId] = struct{}{}
|
||||
}
|
||||
productIdArr := make([]int64, 0, len(productIdSet))
|
||||
for id := range productIdSet {
|
||||
productIdArr = append(productIdArr, id)
|
||||
}
|
||||
productNameMap := make(map[int64]string)
|
||||
if len(productIdArr) > 0 {
|
||||
build := l.svcCtx.ProductModel.SelectBuilder().Where(squirrel.Eq{"id": productIdArr})
|
||||
products, _ := l.svcCtx.ProductModel.FindAll(l.ctx, build, "")
|
||||
for _, p := range products {
|
||||
productNameMap[p.Id] = p.ProductName
|
||||
}
|
||||
}
|
||||
items := make([]types.AgentProductionConfigItem, 0, len(list))
|
||||
for _, v := range list {
|
||||
item := types.AgentProductionConfigItem{}
|
||||
_ = 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.AdminGetAgentProductionConfigListResp{
|
||||
Total: total,
|
||||
Items: items,
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package admin_agent
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"hm-server/app/main/api/internal/svc"
|
||||
"hm-server/app/main/api/internal/types"
|
||||
|
||||
"github.com/Masterminds/squirrel"
|
||||
"github.com/jinzhu/copier"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type AdminGetAgentRewardListLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewAdminGetAgentRewardListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AdminGetAgentRewardListLogic {
|
||||
return &AdminGetAgentRewardListLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *AdminGetAgentRewardListLogic) AdminGetAgentRewardList(req *types.AdminGetAgentRewardListReq) (resp *types.AdminGetAgentRewardListResp, err error) {
|
||||
builder := l.svcCtx.AgentRewardsModel.SelectBuilder()
|
||||
if req.AgentId != nil {
|
||||
builder = builder.Where(squirrel.Eq{"agent_id": *req.AgentId})
|
||||
}
|
||||
if req.RelationAgentId != nil {
|
||||
builder = builder.Where(squirrel.Eq{"relation_agent_id": *req.RelationAgentId})
|
||||
}
|
||||
if req.Type != nil && *req.Type != "" {
|
||||
builder = builder.Where(squirrel.Eq{"type": *req.Type})
|
||||
}
|
||||
list, total, err := l.svcCtx.AgentRewardsModel.FindPageListByPageWithTotal(l.ctx, builder, req.Page, req.PageSize, "create_time DESC")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items := make([]types.AgentRewardListItem, 0, len(list))
|
||||
for _, v := range list {
|
||||
item := types.AgentRewardListItem{}
|
||||
_ = copier.Copy(&item, v)
|
||||
item.CreateTime = v.CreateTime.Format("2006-01-02 15:04:05")
|
||||
if v.RelationAgentId.Valid {
|
||||
item.RelationAgentId = v.RelationAgentId.Int64
|
||||
}
|
||||
items = append(items, item)
|
||||
}
|
||||
resp = &types.AdminGetAgentRewardListResp{
|
||||
Total: total,
|
||||
Items: items,
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package admin_agent
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"hm-server/app/main/api/internal/svc"
|
||||
"hm-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,96 @@
|
||||
package admin_agent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
|
||||
"hm-server/app/main/api/internal/svc"
|
||||
"hm-server/app/main/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type AdminUpdateAgentMembershipConfigLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewAdminUpdateAgentMembershipConfigLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AdminUpdateAgentMembershipConfigLogic {
|
||||
return &AdminUpdateAgentMembershipConfigLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *AdminUpdateAgentMembershipConfigLogic) AdminUpdateAgentMembershipConfig(req *types.AdminUpdateAgentMembershipConfigReq) (resp *types.AdminUpdateAgentMembershipConfigResp, err error) {
|
||||
cfg, err := l.svcCtx.AgentMembershipConfigModel.FindOne(l.ctx, req.Id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
cfg.LevelName = req.LevelName
|
||||
cfg.Price = sql.NullFloat64{Float64: req.Price, Valid: true}
|
||||
cfg.ReportCommission = sql.NullFloat64{Float64: req.ReportCommission, Valid: true}
|
||||
if req.LowerActivityReward == nil {
|
||||
cfg.LowerActivityReward = sql.NullFloat64{Valid: false}
|
||||
} else {
|
||||
cfg.LowerActivityReward = sql.NullFloat64{Float64: *req.LowerActivityReward, Valid: true}
|
||||
}
|
||||
if req.NewActivityReward == nil {
|
||||
cfg.NewActivityReward = sql.NullFloat64{Valid: false}
|
||||
} else {
|
||||
cfg.NewActivityReward = sql.NullFloat64{Float64: *req.NewActivityReward, Valid: true}
|
||||
}
|
||||
if req.LowerStandardCount == nil {
|
||||
cfg.LowerStandardCount = sql.NullInt64{Valid: false}
|
||||
} else {
|
||||
cfg.LowerStandardCount = sql.NullInt64{Int64: *req.LowerStandardCount, Valid: true}
|
||||
}
|
||||
if req.NewLowerStandardCount == nil {
|
||||
cfg.NewLowerStandardCount = sql.NullInt64{Valid: false}
|
||||
} else {
|
||||
cfg.NewLowerStandardCount = sql.NullInt64{Int64: *req.NewLowerStandardCount, Valid: true}
|
||||
}
|
||||
if req.LowerWithdrawRewardRatio == nil {
|
||||
cfg.LowerWithdrawRewardRatio = sql.NullFloat64{Valid: false}
|
||||
} else {
|
||||
cfg.LowerWithdrawRewardRatio = sql.NullFloat64{Float64: *req.LowerWithdrawRewardRatio, Valid: true}
|
||||
}
|
||||
if req.LowerConvertVipReward == nil {
|
||||
cfg.LowerConvertVipReward = sql.NullFloat64{Valid: false}
|
||||
} else {
|
||||
cfg.LowerConvertVipReward = sql.NullFloat64{Float64: *req.LowerConvertVipReward, Valid: true}
|
||||
}
|
||||
if req.LowerConvertSvipReward == nil {
|
||||
cfg.LowerConvertSvipReward = sql.NullFloat64{Valid: false}
|
||||
} else {
|
||||
cfg.LowerConvertSvipReward = sql.NullFloat64{Float64: *req.LowerConvertSvipReward, Valid: true}
|
||||
}
|
||||
if req.ExemptionAmount == nil {
|
||||
cfg.ExemptionAmount = sql.NullFloat64{Valid: false}
|
||||
} else {
|
||||
cfg.ExemptionAmount = sql.NullFloat64{Float64: *req.ExemptionAmount, Valid: true}
|
||||
}
|
||||
if req.PriceIncreaseMax == nil {
|
||||
cfg.PriceIncreaseMax = sql.NullFloat64{Valid: false}
|
||||
} else {
|
||||
cfg.PriceIncreaseMax = sql.NullFloat64{Float64: *req.PriceIncreaseMax, Valid: true}
|
||||
}
|
||||
if req.PriceRatio == nil {
|
||||
cfg.PriceRatio = sql.NullFloat64{Valid: false}
|
||||
} else {
|
||||
cfg.PriceRatio = sql.NullFloat64{Float64: *req.PriceRatio, Valid: true}
|
||||
}
|
||||
if req.PriceIncreaseAmount == nil {
|
||||
cfg.PriceIncreaseAmount = sql.NullFloat64{Valid: false}
|
||||
} else {
|
||||
cfg.PriceIncreaseAmount = sql.NullFloat64{Float64: *req.PriceIncreaseAmount, Valid: true}
|
||||
}
|
||||
_, err = l.svcCtx.AgentMembershipConfigModel.Update(l.ctx, nil, cfg)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp = &types.AdminUpdateAgentMembershipConfigResp{Success: true}
|
||||
return
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package admin_agent
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"hm-server/app/main/api/internal/svc"
|
||||
"hm-server/app/main/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type AdminUpdateAgentProductionConfigLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewAdminUpdateAgentProductionConfigLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AdminUpdateAgentProductionConfigLogic {
|
||||
return &AdminUpdateAgentProductionConfigLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *AdminUpdateAgentProductionConfigLogic) AdminUpdateAgentProductionConfig(req *types.AdminUpdateAgentProductionConfigReq) (resp *types.AdminUpdateAgentProductionConfigResp, err error) {
|
||||
cfg, err := l.svcCtx.AgentProductConfigModel.FindOne(l.ctx, req.Id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
cfg.CostPrice = req.CostPrice
|
||||
cfg.PriceRangeMin = req.PriceRangeMin
|
||||
cfg.PriceRangeMax = req.PriceRangeMax
|
||||
cfg.PricingStandard = req.PricingStandard
|
||||
cfg.OverpricingRatio = req.OverpricingRatio
|
||||
_, err = l.svcCtx.AgentProductConfigModel.Update(l.ctx, nil, cfg)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp = &types.AdminUpdateAgentProductionConfigResp{Success: true}
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user