1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- <?php
- /**
- * @Name
- * @Description
- * @Author 刘学玺
- * @Date 2024/9/10 16:07
- */
- namespace App\Http\Services\Frontend\Client\Coach;
- use App\Http\Services\Service;
- use App\Models\Coach\User;
- use App\Models\Service\Category;
- use App\Models\Service\Project;
- use Illuminate\Support\Facades\DB;
- class UserService extends Service
- {
- protected $select_column = ['id', 'name', 'avatar', 'sex', 'brief', 'total_order_num as totalOrderNum'];
- protected $show_column = ['license', 'work_img as workImg', 'self_img as selfImg'];
- public function getUserPage($params): array
- {
- $category_id = $params['categoryId'] ?? 1;
- $project_ids = DB::table('service_project_has_category')->where('category_id', $category_id)->pluck('project_id');
- $project_ids = Project::query()->whereIn('id', $project_ids)->where('status', 0)->pluck('id');
- $coach_ids = DB::table('service_project_has_coach')->whereIn('project_id', $project_ids)->pluck('coach_id');
- $userWhere = ['status' => 1, 'auth_status' => 2];
- $userPage = User::query()->whereIn('id', $coach_ids)->where($userWhere)->select($this->select_column)->paginate();
- return ['list' => $userPage->items(), 'total' => $userPage->total()];
- // $project = Project::query();
- // $category_id = $params['categoryId'] ?? 1;
- // $project_ids = DB::table('service_project_has_category')->where('category_id', $category_id)->pluck('project_id');
- // !$project_ids->isEmpty() && $project->whereIn('id', $project_ids);
- // $where['status'] = 0;
- // $projectPage = $project->where($where)->paginate();
- // return ['list' => $projectPage->items(), 'total' => $projectPage->total()];
- }
- public function getUser(array $params, int $id)
- {
- $category_id = $params['categoryId'] ?? 0;
- $user = User::query()->select([...$this->select_column, ...$this->show_column])->find($id);
- $category_id && ($user['project'] = $user->getProject($category_id));
- return $user;
- }
- }
|