HomeController.php 2.6 KB

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