完善配送订单列表可读信息
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
// 功能描述:实现配送点范围内的合同、合同气瓶和配送订单接口。
|
||||
// 版本:v1.2.0。
|
||||
// 版本:v1.3.0。
|
||||
package delivery
|
||||
|
||||
import (
|
||||
@@ -364,10 +364,30 @@ func scopedOrder(ctx *gin.Context, identity string, pointID uint64) (models.Gaso
|
||||
|
||||
func ListOrder(ctx *gin.Context) {
|
||||
point, _, ok := currentScope(ctx)
|
||||
if ok {
|
||||
listScoped(ctx, &models.GasorderBasic{}, common.ActiveRecords(db().Model(&models.GasorderBasic{})).
|
||||
Where("delivery_basic_id = ?", point.ID), "gasorder_basic.created_at desc")
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
page, size := common.PageSize(ctx)
|
||||
query := common.ApplyKeywordFilter(ctx,
|
||||
common.ActiveRecords(db().Model(&models.GasorderBasic{})).Where("delivery_basic_id = ?", point.ID),
|
||||
&models.GasorderBasic{},
|
||||
)
|
||||
var total int64
|
||||
if err := query.Count(&total).Error; err != nil {
|
||||
infra.Response.Error(ctx, err)
|
||||
return
|
||||
}
|
||||
var orders []models.GasorderBasic
|
||||
if err := query.Order("gasorder_basic.created_at desc").Offset((page - 1) * size).Limit(size).Find(&orders).Error; err != nil {
|
||||
infra.Response.Error(ctx, err)
|
||||
return
|
||||
}
|
||||
response, err := platformgasorder.BuildGasorderListResponse(ctx, orders)
|
||||
if err != nil {
|
||||
infra.Response.Error(ctx, err)
|
||||
return
|
||||
}
|
||||
infra.Response.Success(ctx, gin.H{"total": total, "list": response})
|
||||
}
|
||||
|
||||
func GetOrder(ctx *gin.Context) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// 功能描述:为平台配送订单列表与详情补充关联名称、地址和合同气瓶摘要。
|
||||
// 版本:v1.1.0
|
||||
// 版本:v1.2.0
|
||||
package gasorder
|
||||
|
||||
import (
|
||||
@@ -62,18 +62,27 @@ func ListGasorderBasic(ctx *gin.Context) {
|
||||
infra.Response.Error(ctx, err)
|
||||
return
|
||||
}
|
||||
displays, err := buildGasorderListDisplays(orders)
|
||||
response, err := BuildGasorderListResponse(ctx, orders)
|
||||
if err != nil {
|
||||
infra.Response.Error(ctx, err)
|
||||
return
|
||||
}
|
||||
infra.Response.Success(ctx, gin.H{"total": total, "list": response})
|
||||
}
|
||||
|
||||
// BuildGasorderListResponse 为已经完成数据范围筛选的订单构造安全、可读的管理端列表响应。
|
||||
// 调用方必须先限定自身可见订单;本函数只补充派生名称、气瓶摘要并恢复订单地址快照。
|
||||
func BuildGasorderListResponse(ctx *gin.Context, orders []models.GasorderBasic) (any, error) {
|
||||
displays, err := buildGasorderListDisplays(orders)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
response, err := common.PublicResourceResponse(displays)
|
||||
if err != nil {
|
||||
infra.Response.Error(ctx, err)
|
||||
return
|
||||
return nil, err
|
||||
}
|
||||
protected := common.ProtectPreciseLocation(ctx, &models.GasorderBasic{}, response)
|
||||
infra.Response.Success(ctx, gin.H{"total": total, "list": restoreGasorderListAddresses(protected, orders)})
|
||||
return restoreGasorderListAddresses(protected, orders), nil
|
||||
}
|
||||
|
||||
// buildGasorderListDisplays 批量读取创建方与有效订单气瓶,避免列表逐行查询。
|
||||
|
||||
Reference in New Issue
Block a user