| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- <?php
- namespace App\Http\Controllers\Api;
- use App\Services\GeohashService;
- use App\Services\HomeService;
- use App\Services\RedisService;
- use http\Env\Response;
- use Illuminate\Filesystem\Cache;
- use Illuminate\Http\Request;
- use PHPUnit\Util\Exception;
- class HomeController extends Controller
- {
- public $homeService;
- public function __construct()
- {
- $this->homeService = new HomeService();
- }
- /**
- * 获取位置信息,经纬度
- */
- public function get_location(Request $request){
- dd(RedisService::redis()->get('user_location_'.$request->uniqueID));
- try {
- if(!isset($request->latitude) || $request->latitude==""){
- throw new Exception("参数错误");
- }
- if(!isset($request->longitude) || $request->longitude==""){
- throw new Exception("参数错误");
- }
- if(!isset($request->uniqueID) || $request->uniqueID==""){
- throw new Exception("参数错误");
- }
- $user = auth('api')->user();
- if(!$user){
- RedisService::redis()->SETEX('user_location_' . $request->uniqueID, 600, json_encode(['latitude' => $request->latitude, 'longitude' => $request->longitude]));
- }
- }catch (\Exception $exception){
- return $this->response->errorForbidden($exception->getMessage());
- }
- return response()->json(['message'=>"请求成功"]);
- }
- /**
- * 返回首页信息
- * @param Request $request
- * @return \Illuminate\Http\JsonResponse|void
- */
- public function home(Request $request){
- try {
- $param['keyword'] = $request->post('keyword','');//关键词,昵称,标签
- $param['nearby'] = $request->post('nearby',1);//附近
- $param['online'] = $request->post('online',1);//在线
- $param['new'] = $request->post('new',1);//新人
- $param['latitude'] = $request->post('latitude','30.663436');//纬度
- $param['longitude'] = $request->post('longitude','104.072224');//经度
- $res = $this->homeService->get_list($param);
- }catch (\Exception $exception){
- return $this->response->errorForbidden($exception->getMessage());
- }
- return response()->json($res);
- }
- public function user_detail(Request $request){
- try {
- $res = $this->homeService->user_detail($request->user_id);
- }catch (\Exception $exception){
- return $this->response->errorForbidden($exception->getMessage());
- }
- return response()->json($res);
- }
- }
|