12345678910111213141516171819202122232425262728293031323334353637383940 |
- <?php
- namespace App\Services;
- use App\Models\Expert;
- use App\Traits\PageTrait;
- class ExpertService
- {
- use PageTrait;
- public function getList($condition, $sort = 'id', $sortable = 'desc')
- {
- $query = Expert::query();
- $query->select(
- 'id',
- 'username',
- 'avatar',
- 'name',
- 'status'
- );
- // 使用 whereIn 方法筛选 lecture_id 在 $lectureIdArr 数组中的记录
- $query->where('is_expert', 1);
- // 搜索
- if (isset($condition['keywords']) && $condition['keywords']) {
- $query->where('name', 'like', '%' . $condition['keywords'] . '%');
- }
- if (isset($condition['status']) && $condition['keywords'] !== '') {
- $query->where('name', 'like', '%' . $condition['keywords'] . '%');
- }
- // 排序
- $query->orderBy($sort, $sortable);
- // 执行查询并返回结果
- return self::JsonPage($query);
- }
-
- }
|