Skip to content

Commit

Permalink
feat: getManyByWhere 根据where条件查询多条
Browse files Browse the repository at this point in the history
  • Loading branch information
cexll committed Feb 17, 2022
1 parent f887a28 commit 3601b87
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Command/stubs/Service.stub
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ class #MODEL#Service extends AbstractService implements #MODEL#ServiceInterface
return $this->model->getAllById($ids, $columns);
}

/**
* {@inheritdoc}
*/
public function get#MODEL_PLURA#ByWhere(array $where, array $columns = ['*'], array $options = []): array
{
return $this->model->getManyByWhere($where, $columns, $options);
}

/**
* {@inheritdoc}
*/
Expand Down
9 changes: 9 additions & 0 deletions src/Command/stubs/ServiceInterface.stub
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ interface #INTERFACE#
*/
public function get#MODEL_PLURA#ById(array $ids, array $columns = ['*']): array;

/**
* 根据Where条件查询多条
* @param array $where 查询条件
* @param array $columns 查询字段
* @param array 可选项 ['orderByRaw'=> 'id asc', 'with' = [], 'selectRaw' => 'count(*) as count']
* @return array 数组
*/
public function get#MODEL_PLURA#ByWhere(array $where, array $columns = ['*'], array $options = []): array;

/**
* 多条分页.
* @param array $where 查询条件
Expand Down
10 changes: 10 additions & 0 deletions src/Model/AbstractModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ public function getAllById(array $ids, array $columns = ['*']): array
return $data->toArray();
}

/**
* 根据Where条件查询多条
*/
public function getManyByWhere(array $where, array $columns = ['*'], array $options = [])
{
$data = $this->optionWhere($where, $options)->get($columns);
$data || $data = collect([]);
return $data->toArray();
}

/**
* 多条分页.
* @param array $where 查询条件
Expand Down

0 comments on commit 3601b87

Please sign in to comment.