修复气站用户配送点归属展示
This commit is contained in:
@@ -11,19 +11,30 @@ import (
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// gasUserListItem 在用户主档上附加当前气站服务关系中的配送点归属。
|
||||
type gasUserListItem struct {
|
||||
models.UserAccount
|
||||
DeliveryBasicID uint64 `gorm:"column:delivery_basic_id" json:"delivery_basic_id"`
|
||||
}
|
||||
|
||||
// scopedUserList 将用户列表与当前气站唯一有效服务关系绑定,避免返回跨站归属。
|
||||
func scopedUserList(databaseService *gorm.DB, gasBasicID uint64) *gorm.DB {
|
||||
return common.ActiveRecords(databaseService.Model(&models.UserAccount{})).
|
||||
Select("user_account.*, user_service_relation.delivery_basic_id AS delivery_basic_id").
|
||||
Joins("JOIN user_service_relation ON user_service_relation.user_account_id = user_account.id AND user_service_relation.status <> ?", common.StatusArchived).
|
||||
Where("user_service_relation.gas_basic_id = ?", gasBasicID)
|
||||
}
|
||||
|
||||
func ListUser(ctx *gin.Context) {
|
||||
station, ok := currentGas(ctx)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
page, size := common.PageSize(ctx)
|
||||
var list []models.UserAccount
|
||||
var list []gasUserListItem
|
||||
var total int64
|
||||
query := common.ApplyKeywordFilter(ctx,
|
||||
common.ActiveRecords(impl.DBService.Model(&models.UserAccount{})).
|
||||
Joins("JOIN user_service_relation ON user_service_relation.user_account_id = user_account.id AND user_service_relation.status <> ?",
|
||||
common.StatusArchived).
|
||||
Where("user_service_relation.gas_basic_id = ?", station.ID),
|
||||
scopedUserList(impl.DBService, station.ID),
|
||||
&models.UserAccount{})
|
||||
if err := query.Count(&total).Error; err != nil {
|
||||
infra.Response.Error(ctx, err)
|
||||
|
||||
Reference in New Issue
Block a user