update 用户首页

This commit is contained in:
chenbo 2024-01-24 09:40:14 +08:00
parent 153a7c9dd7
commit 31fc47f405
2 changed files with 38 additions and 5 deletions

View File

@ -40,9 +40,8 @@ class UserLists extends BaseAdminDataLists implements ListsExcelInterface
*/ */
public function setSearch(): array public function setSearch(): array
{ {
return [ $allowSearch = ['keyword', 'channel', 'create_time_start', 'create_time_end', 'province', 'city', 'area', 'street', 'village'];
'=' => ['keyword', 'create_time_start', 'create_time_end', 'province', 'city', 'area', 'street', 'village'] return array_intersect(array_keys($this->params), $allowSearch);
];
} }
@ -60,7 +59,7 @@ class UserLists extends BaseAdminDataLists implements ListsExcelInterface
$field = "id,id contract,sn,nickname,sex,avatar,account,mobile,channel,create_time,admin_id,company_id,street,street as street_name,is_contract,group_id,invite_code"; $field = "id,id contract,sn,nickname,sex,avatar,account,mobile,channel,create_time,admin_id,company_id,street,street as street_name,is_contract,group_id,invite_code";
$lists = User::where($this->searchWhere) $lists = User::withSearch($this->setSearch(), $this->params)
->append(['role_name']) ->append(['role_name'])
->with(['company']) ->with(['company'])
->withAttr('role_name', function ($value, $data){ ->withAttr('role_name', function ($value, $data){
@ -93,7 +92,7 @@ class UserLists extends BaseAdminDataLists implements ListsExcelInterface
*/ */
public function count(): int public function count(): int
{ {
return User::where($this->searchWhere)->count(); return User::withSearch($this->setSearch(), $this->params)->count();
} }

View File

@ -110,6 +110,40 @@ class User extends BaseModel
$query->where('create_time', '<=', strtotime($value)); $query->where('create_time', '<=', strtotime($value));
} }
} }
public function searchProvinceAttr($query, $value, $data)
{
if ($value) {
$query->where('province', '=', $value);
}
}
public function searchCityAttr($query, $value, $data)
{
if ($value) {
$query->where('city', '=', $value);
}
}
public function searchAreaAttr($query, $value, $data)
{
if ($value) {
$query->where('area', '=', $value);
}
}
public function searchStreetAttr($query, $value, $data)
{
if ($value) {
$query->where('street', '=', $value);
}
}
public function searchVillageAttr($query, $value, $data)
{
if ($value) {
$query->where('village', '=', $value);
}
}
/** /**