HomeController.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <?php
  2. namespace App\Http\Controllers\Api;
  3. use App\Http\Params\UserCommentParam;
  4. use App\Http\Params\UserLikeParam;
  5. use App\Models\UserComment;
  6. use App\Services\DynamicService;
  7. use App\Services\GeohashService;
  8. use App\Services\HomeService;
  9. use App\Services\RedisService;
  10. use http\Env\Response;
  11. use Illuminate\Filesystem\Cache;
  12. use Illuminate\Http\Request;
  13. use Illuminate\Support\Facades\DB;
  14. use PHPUnit\Util\Exception;
  15. class HomeController extends Controller
  16. {
  17. public $homeService;
  18. public function __construct()
  19. {
  20. $this->homeService = new HomeService();
  21. }
  22. /**
  23. * 获取位置信息,经纬度
  24. */
  25. public function get_location(Request $request){
  26. try {
  27. if(!isset($request->latitude) || $request->latitude==""){
  28. throw new Exception("参数错误");
  29. }
  30. if(!isset($request->longitude) || $request->longitude==""){
  31. throw new Exception("参数错误");
  32. }
  33. // if(!isset($request->uniqueID) || $request->uniqueID==""){
  34. // throw new Exception("参数错误");
  35. // }
  36. $user = auth('api')->user();
  37. if(!$user){
  38. RedisService::redis()->SETEX('user_location_' . $request->uniqueID, 600, json_encode(['latitude' => $request->latitude, 'longitude' => $request->longitude]));
  39. }
  40. }catch (\Exception $exception){
  41. return $this->response->errorForbidden($exception->getMessage());
  42. }
  43. return response()->json(['message'=>"请求成功"]);
  44. }
  45. /**
  46. * 返回首页信息
  47. * @param Request $request
  48. * @return \Illuminate\Http\JsonResponse|void
  49. */
  50. public function home(Request $request){
  51. try {
  52. $param['keyword'] = $request->post('keyword','');//关键词,昵称,标签
  53. $param['nearby'] = $request->post('nearby',1);//附近
  54. $param['online'] = $request->post('online',1);//在线
  55. $param['new'] = $request->post('new',1);//新人
  56. $param['latitude'] = $request->post('latitude','30.663436');//纬度
  57. $param['longitude'] = $request->post('longitude','104.072224');//经度
  58. $res = $this->homeService->get_list($param);
  59. }catch (\Exception $exception){
  60. return $this->response->errorForbidden($exception->getMessage());
  61. }
  62. return response()->json($res);
  63. }
  64. /**
  65. * 用户详情
  66. * @param Request $request
  67. * @return \Illuminate\Http\JsonResponse|void
  68. */
  69. public function user_detail(Request $request){
  70. try {
  71. $res = $this->homeService->user_detail($request->user_id);
  72. }catch (\Exception $exception){
  73. return $this->response->errorForbidden($exception->getMessage());
  74. }
  75. return response()->json($res);
  76. }
  77. /**
  78. * 用户动态
  79. * @param Request $request
  80. * @return \Illuminate\Http\JsonResponse|void
  81. */
  82. public function user_dynamic(Request $request){
  83. try {
  84. $where = array();
  85. $where['type'] = $request->post('type',1); //类型 type 1全部 2关注 3附近
  86. $where['look_type'] =$request->post('look_type',3);//查看类型 type 1只看男士 2只看女士 3全部
  87. $where['tag_id'] =$request->post('tag_id',0); //话题标签
  88. $where['user_id'] =$request->user_id;
  89. $dynamicService = new DynamicService();
  90. $res = $dynamicService->dynamic_list($where);
  91. }catch (\Exception $exception){
  92. return $this->response->errorForbidden($exception->getMessage());
  93. }
  94. return response()->json($res);
  95. }
  96. /**
  97. * 用户喜欢
  98. */
  99. public function do_like(Request $request){
  100. DB::beginTransaction();
  101. try {
  102. $user = auth('api')->user();
  103. $UserLikeParam = new UserLikeParam();
  104. $UserLikeParam->user_id = $user->id;
  105. $UserLikeParam->like_id = $request->user_id;
  106. $is_like = $this->homeService->do_like($UserLikeParam);
  107. DB::commit();
  108. }catch (\Exception $exception){
  109. DB::rollBack();
  110. return $this->response->errorForbidden($exception->getMessage());
  111. }
  112. return response()->json(['message'=>$is_like==1?"已喜欢":"取消喜欢",'is_like'=>$is_like]);
  113. }
  114. /**
  115. * 用户评价
  116. * @param Request $request
  117. * @return \Illuminate\Http\JsonResponse|void
  118. */
  119. public function do_comment(Request $request){
  120. try {
  121. $user = auth('api')->user();
  122. $UserComment = new UserCommentParam();
  123. $UserComment->user_id = $user->id;
  124. $UserComment->comment_id = $request->user_id;
  125. $UserComment->con1 = $request->con1;
  126. $UserComment->con2 = $request->con2;
  127. $UserComment->con3 = $request->con3;
  128. $UserComment->con4 = $request->con4;
  129. $is_like = $this->homeService->do_comment($UserComment);
  130. }catch (\Exception $exception){
  131. return $this->response->errorForbidden($exception->getMessage());
  132. }
  133. return response()->json(['message'=>'评价成功']);
  134. }
  135. /**
  136. * 解锁微信
  137. * @param Request $request
  138. * @return \Illuminate\Http\JsonResponse|void
  139. */
  140. public function get_weixin(Request $request){
  141. try {
  142. $res = $this->homeService->get_weixin($request->user_id);
  143. }catch (\Exception $exception){
  144. return $this->response->errorForbidden($exception->getMessage());
  145. }
  146. return response()->json(['weixin'=>$res]);
  147. }
  148. }