diff --git a/app/adminapi/lists/user/UserLists.php b/app/adminapi/lists/user/UserLists.php index 128a6720..b6f7005f 100644 --- a/app/adminapi/lists/user/UserLists.php +++ b/app/adminapi/lists/user/UserLists.php @@ -40,9 +40,8 @@ class UserLists extends BaseAdminDataLists implements ListsExcelInterface */ public function setSearch(): array { - return [ - '=' => ['keyword', 'create_time_start', 'create_time_end', 'province', 'city', 'area', 'street', 'village'] - ]; + $allowSearch = ['keyword', 'channel', '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"; - $lists = User::where($this->searchWhere) + $lists = User::withSearch($this->setSearch(), $this->params) ->append(['role_name']) ->with(['company']) ->withAttr('role_name', function ($value, $data){ @@ -93,7 +92,7 @@ class UserLists extends BaseAdminDataLists implements ListsExcelInterface */ public function count(): int { - return User::where($this->searchWhere)->count(); + return User::withSearch($this->setSearch(), $this->params)->count(); } diff --git a/app/common/model/user/User.php b/app/common/model/user/User.php index ac4a3807..c1de6410 100644 --- a/app/common/model/user/User.php +++ b/app/common/model/user/User.php @@ -110,6 +110,40 @@ class User extends BaseModel $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); + } + } /**