HomeController.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace App\Http\Controllers\Api;
  3. use App\Services\HomeService;
  4. use http\Env\Response;
  5. use Illuminate\Http\Request;
  6. use PHPUnit\Util\Exception;
  7. class HomeController extends Controller
  8. {
  9. public $homeService;
  10. public function __construct()
  11. {
  12. $this->homeService = new HomeService();
  13. }
  14. /**
  15. * 获取位置信息,经纬度
  16. */
  17. public function get_location(Request $request){
  18. try {
  19. if(!isset($request->latitude) || $request->latitude==""){
  20. throw new Exception("参数错误");
  21. }
  22. if(!isset($request->longitude) || $request->longitude==""){
  23. throw new Exception("参数错误");
  24. }
  25. $user = auth('api')->user();
  26. if(!$user){
  27. }
  28. }catch (\Exception $exception){
  29. return $this->response->errorForbidden($exception->getMessage());
  30. }
  31. return response()->json(['message'=>"请求成功"]);
  32. }
  33. /**
  34. * 返回首页信息
  35. * @param Request $request
  36. * @return \Illuminate\Http\JsonResponse|void
  37. */
  38. public function home(Request $request){
  39. try {
  40. $param['keyword'] = $request->post('keyword','');//关键词,昵称,标签
  41. $param['nearby'] = $request->post('nearby',1);//附近
  42. $param['online'] = $request->post('online',1);//在线
  43. $param['new'] = $request->post('new',1);//新人
  44. $res = $this->homeService->get_list($param);
  45. }catch (\Exception $exception){
  46. return $this->response->errorForbidden($exception->getMessage());
  47. }
  48. return response()->json($res);
  49. }
  50. }