fix: 修复列表筛选空参与树数据展示
将后端 status/audit_status 筛选从 has() 改为 filled(),避免空字符串导致列表被误筛空;修复预定 status=0 筛选失效;前端兼容财务分类树形返回与菜单/字典数组返回,解决新增成功但列表空。
This commit is contained in:
@@ -17,7 +17,9 @@ trait BelongsToStore
|
||||
{
|
||||
// 查询自动过滤门店
|
||||
static::addGlobalScope('store', function (Builder $builder) {
|
||||
if ($storeId = self::getCurrentStoreId()) {
|
||||
// 超管:不带 X-Store-Id 时默认“总览”(不加 store 过滤)
|
||||
// 普通用户:按自身 store_id 过滤
|
||||
if ($storeId = self::getQueryStoreId()) {
|
||||
$builder->where($builder->getModel()->getTable() . '.store_id', $storeId);
|
||||
}
|
||||
});
|
||||
@@ -25,7 +27,10 @@ trait BelongsToStore
|
||||
// 创建时自动填入 store_id
|
||||
static::creating(function ($model) {
|
||||
if (empty($model->store_id)) {
|
||||
$model->store_id = self::getCurrentStoreId();
|
||||
// 创建时:超管若指定 X-Store-Id 则写入该门店;否则落到自身 store_id
|
||||
if ($storeId = self::getCreateStoreId()) {
|
||||
$model->store_id = $storeId;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -35,12 +40,35 @@ trait BelongsToStore
|
||||
return $this->belongsTo(Store::class);
|
||||
}
|
||||
|
||||
private static function getCurrentStoreId(): ?int
|
||||
private static function getQueryStoreId(): ?int
|
||||
{
|
||||
$user = auth()->user();
|
||||
if ($user && $user->is_super && request()->header('X-Store-Id')) {
|
||||
if (!$user) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 超管默认总览:不传 X-Store-Id 则不做门店过滤
|
||||
if ($user->is_super) {
|
||||
if (request()->header('X-Store-Id')) {
|
||||
return (int) request()->header('X-Store-Id');
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
return $user?->store_id;
|
||||
}
|
||||
|
||||
private static function getCreateStoreId(): ?int
|
||||
{
|
||||
$user = auth()->user();
|
||||
if (!$user) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($user->is_super && request()->header('X-Store-Id')) {
|
||||
return (int) request()->header('X-Store-Id');
|
||||
}
|
||||
|
||||
return $user?->store_id;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user