UserService.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. /**
  3. * @Name
  4. * @Description
  5. * @Author 刘学玺
  6. * @Date 2024/9/10 16:07
  7. */
  8. namespace App\Http\Services\Frontend\Client\Coach;
  9. use App\Http\Services\Service;
  10. use App\Models\Coach\User;
  11. use App\Models\Service\Category;
  12. use App\Models\Service\Project;
  13. use Illuminate\Support\Facades\DB;
  14. class UserService extends Service
  15. {
  16. protected $select_column = ['id', 'name', 'avatar', 'sex', 'brief', 'total_order_num as totalOrderNum'];
  17. protected $show_column = ['license', 'work_img as workImg', 'self_img as selfImg'];
  18. public function getUserPage($params): array
  19. {
  20. $category_id = $params['categoryId'] ?? 1;
  21. $project_ids = DB::table('service_project_has_category')->where('category_id', $category_id)->pluck('project_id');
  22. $project_ids = Project::query()->whereIn('id', $project_ids)->where('status', 0)->pluck('id');
  23. $coach_ids = DB::table('service_project_has_coach')->whereIn('project_id', $project_ids)->pluck('coach_id');
  24. $userWhere = ['status' => 1, 'auth_status' => 2];
  25. $userPage = User::query()->whereIn('id', $coach_ids)->where($userWhere)->select($this->select_column)->paginate();
  26. return ['list' => $userPage->items(), 'total' => $userPage->total()];
  27. // $project = Project::query();
  28. // $category_id = $params['categoryId'] ?? 1;
  29. // $project_ids = DB::table('service_project_has_category')->where('category_id', $category_id)->pluck('project_id');
  30. // !$project_ids->isEmpty() && $project->whereIn('id', $project_ids);
  31. // $where['status'] = 0;
  32. // $projectPage = $project->where($where)->paginate();
  33. // return ['list' => $projectPage->items(), 'total' => $projectPage->total()];
  34. }
  35. public function getUser(array $params, int $id)
  36. {
  37. $category_id = $params['categoryId'] ?? 0;
  38. $user = User::query()->select([...$this->select_column, ...$this->show_column])->find($id);
  39. $category_id && ($user['project'] = $user->getProject($category_id));
  40. return $user;
  41. }
  42. }