ff
This commit is contained in:
@@ -138,8 +138,9 @@ type (
|
||||
|
||||
type (
|
||||
QueryListReq {
|
||||
Page int64 `form:"page"` // 页码
|
||||
PageSize int64 `form:"page_size"` // 每页数据量
|
||||
Page int64 `form:"page"` // 页码
|
||||
PageSize int64 `form:"page_size"` // 每页数据量
|
||||
Source string `form:"source,optional"` // 来源: miniapp 小程序过滤非车辆产品
|
||||
}
|
||||
QueryListResp {
|
||||
Total int64 `json:"total"` // 总记录数
|
||||
|
||||
@@ -2,6 +2,7 @@ package query
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
"tyc-server/app/main/api/internal/svc"
|
||||
"tyc-server/app/main/api/internal/types"
|
||||
"tyc-server/app/main/model"
|
||||
@@ -28,51 +29,81 @@ func NewQueryListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *QueryLi
|
||||
}
|
||||
}
|
||||
|
||||
// isVehicleProduct 判断 product_en 是否为车辆类产品
|
||||
func isVehicleProduct(productEn string) bool {
|
||||
vehiclePrefixes := []string{
|
||||
"toc_Vehicle",
|
||||
"toc_PersonVehicle",
|
||||
}
|
||||
for _, p := range vehiclePrefixes {
|
||||
if strings.HasPrefix(productEn, p) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (l *QueryListLogic) QueryList(req *types.QueryListReq) (resp *types.QueryListResp, err error) {
|
||||
userID, getUidErr := ctxdata.GetUidFromCtx(l.ctx)
|
||||
if getUidErr != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "报告列表查询, 获取用户信息失败, %+v", getUidErr)
|
||||
}
|
||||
|
||||
// 小程序端需要过滤非车辆产品,取更大分页后内存过滤
|
||||
pageSize := req.PageSize
|
||||
isMiniapp := req.Source == "miniapp"
|
||||
if isMiniapp && pageSize < 200 {
|
||||
pageSize = 200
|
||||
}
|
||||
|
||||
// 直接构建查询query表的条件
|
||||
build := l.svcCtx.QueryModel.SelectBuilder().Where(squirrel.Eq{
|
||||
"user_id": userID,
|
||||
})
|
||||
|
||||
// 直接从query表分页查询
|
||||
queryList, total, err := l.svcCtx.QueryModel.FindPageListByPageWithTotal(l.ctx, build, req.Page, req.PageSize, "create_time DESC")
|
||||
queryList, total, err := l.svcCtx.QueryModel.FindPageListByPageWithTotal(l.ctx, build, req.Page, pageSize, "create_time DESC")
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "报告列表查询, 查找报告列表错误, %+v", err)
|
||||
}
|
||||
|
||||
var list []types.Query
|
||||
if len(queryList) > 0 {
|
||||
for _, queryModel := range queryList {
|
||||
var query types.Query
|
||||
query.CreateTime = queryModel.CreateTime.Format("2006-01-02 15:04:05")
|
||||
query.UpdateTime = queryModel.UpdateTime.Format("2006-01-02 15:04:05")
|
||||
copyErr := copier.Copy(&query, queryModel)
|
||||
if copyErr != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "报告列表查询, 报告结构体复制失败, %+v", err)
|
||||
}
|
||||
product, findProductErr := l.svcCtx.ProductModel.FindOne(l.ctx, queryModel.ProductId)
|
||||
if findProductErr != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "报告列表查询, 获取商品信息失败, %+v", err)
|
||||
}
|
||||
|
||||
// 检查订单状态,如果订单已退款,则设置查询状态为已退款
|
||||
order, findOrderErr := l.svcCtx.OrderModel.FindOne(l.ctx, queryModel.OrderId)
|
||||
if findOrderErr == nil && order.Status == model.OrderStatusRefunded {
|
||||
query.QueryState = model.QueryStateRefunded
|
||||
}
|
||||
query.ProductName = product.ProductName
|
||||
query.Product = product.ProductEn
|
||||
list = append(list, query)
|
||||
for _, queryModel := range queryList {
|
||||
var query types.Query
|
||||
query.CreateTime = queryModel.CreateTime.Format("2006-01-02 15:04:05")
|
||||
query.UpdateTime = queryModel.UpdateTime.Format("2006-01-02 15:04:05")
|
||||
copyErr := copier.Copy(&query, queryModel)
|
||||
if copyErr != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "报告列表查询, 报告结构体复制失败, %+v", err)
|
||||
}
|
||||
product, findProductErr := l.svcCtx.ProductModel.FindOne(l.ctx, queryModel.ProductId)
|
||||
if findProductErr != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "报告列表查询, 获取商品信息失败, %+v", err)
|
||||
}
|
||||
|
||||
// 小程序端:过滤非车辆类产品(H5 端 source 为空,不做过滤)
|
||||
if isMiniapp && !isVehicleProduct(product.ProductEn) {
|
||||
continue
|
||||
}
|
||||
|
||||
// 检查订单状态,如果订单已退款,则设置查询状态为已退款
|
||||
order, findOrderErr := l.svcCtx.OrderModel.FindOne(l.ctx, queryModel.OrderId)
|
||||
if findOrderErr == nil && order.Status == model.OrderStatusRefunded {
|
||||
query.QueryState = model.QueryStateRefunded
|
||||
}
|
||||
query.ProductName = product.ProductName
|
||||
query.Product = product.ProductEn
|
||||
list = append(list, query)
|
||||
}
|
||||
|
||||
// H5 端返回数据库原始 total;小程序端返回过滤后的实际数量
|
||||
respTotal := total
|
||||
if isMiniapp {
|
||||
respTotal = int64(len(list))
|
||||
}
|
||||
|
||||
return &types.QueryListResp{
|
||||
Total: total,
|
||||
Total: respTotal,
|
||||
List: list,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -2017,8 +2017,9 @@ type QueryItem struct {
|
||||
}
|
||||
|
||||
type QueryListReq struct {
|
||||
Page int64 `form:"page"` // 页码
|
||||
PageSize int64 `form:"page_size"` // 每页数据量
|
||||
Page int64 `form:"page"` // 页码
|
||||
PageSize int64 `form:"page_size"` // 每页数据量
|
||||
Source string `form:"source,optional"` // 来源: miniapp 小程序过滤非车辆产品
|
||||
}
|
||||
|
||||
type QueryListResp struct {
|
||||
|
||||
Reference in New Issue
Block a user