v1.1
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
package agent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"ycc-server/app/main/model"
|
||||
"ycc-server/common/ctxdata"
|
||||
"ycc-server/common/globalkey"
|
||||
"ycc-server/common/xerr"
|
||||
|
||||
"github.com/jinzhu/copier"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
|
||||
"ycc-server/app/main/api/internal/svc"
|
||||
"ycc-server/app/main/api/internal/types"
|
||||
)
|
||||
|
||||
type GetPromotionQueryListLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewGetPromotionQueryListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetPromotionQueryListLogic {
|
||||
return &GetPromotionQueryListLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetPromotionQueryListLogic) GetPromotionQueryList(req *types.GetPromotionQueryListReq) (resp *types.GetPromotionQueryListResp, err error) {
|
||||
userID, err := ctxdata.GetUidFromCtx(l.ctx)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "获取用户信息失败, %v", err)
|
||||
}
|
||||
|
||||
agent, err := l.svcCtx.AgentModel.FindOneByUserId(l.ctx, userID)
|
||||
if err != nil {
|
||||
if errors.Is(err, model.ErrNotFound) {
|
||||
return nil, errors.Wrapf(xerr.NewErrMsg("您不是代理"), "")
|
||||
}
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "查询代理信息失败, %v", err)
|
||||
}
|
||||
|
||||
// 查询当前代理的代理订单,按创建时间倒序分页
|
||||
builder := l.svcCtx.AgentOrderModel.SelectBuilder().
|
||||
Where("agent_id = ? AND del_state = ?", agent.Id, globalkey.DelStateNo)
|
||||
|
||||
orders, _, err := l.svcCtx.AgentOrderModel.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)
|
||||
}
|
||||
|
||||
// 组装查询报告列表(只展示已创建的查询)
|
||||
list := make([]types.PromotionQueryItem, 0, len(orders))
|
||||
for _, ao := range orders {
|
||||
// 查询对应的报告
|
||||
q, qErr := l.svcCtx.QueryModel.FindOneByOrderId(l.ctx, ao.OrderId)
|
||||
if qErr != nil {
|
||||
if errors.Is(qErr, model.ErrNotFound) {
|
||||
// 订单对应的查询尚未创建,跳过展示
|
||||
continue
|
||||
}
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "查询报告失败, %v", qErr)
|
||||
}
|
||||
|
||||
// 获取产品名称
|
||||
product, pErr := l.svcCtx.ProductModel.FindOne(l.ctx, ao.ProductId)
|
||||
if pErr != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "查询产品信息失败, %v", pErr)
|
||||
}
|
||||
|
||||
item := types.PromotionQueryItem{}
|
||||
_ = copier.Copy(&item, q)
|
||||
item.Id = q.Id
|
||||
item.OrderId = q.OrderId
|
||||
item.ProductName = product.ProductName
|
||||
item.CreateTime = q.CreateTime.Format("2006-01-02 15:04:05")
|
||||
item.QueryState = q.QueryState
|
||||
list = append(list, item)
|
||||
}
|
||||
|
||||
return &types.GetPromotionQueryListResp{
|
||||
Total: int64(len(list)), // 前端仅展示已创建查询条目
|
||||
List: list,
|
||||
}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user