最近距离,我的收藏
This commit is contained in:
@@ -28,6 +28,48 @@ class PostController extends BaseController
|
||||
{
|
||||
$this->service = new PostService();
|
||||
}
|
||||
/**
|
||||
* 获取列表
|
||||
*
|
||||
* @param Request $request 请求对象
|
||||
* @return mixed 返回分页数据及总数
|
||||
*/
|
||||
public function nearby(Request $request)
|
||||
{
|
||||
try {
|
||||
$raw = $this->service->serviceNearby($request);
|
||||
$records = $this->transformData($raw, method_exists($this, 'indexFormat')
|
||||
? [$this, 'indexFormat']
|
||||
: null);
|
||||
// $records = $data;
|
||||
foreach ($records as &$record) {
|
||||
$record = $this->indexFormat($record);
|
||||
if (!isset($record['id']))
|
||||
break;
|
||||
if(!empty($request->user) && !empty($request->user->uid)){
|
||||
$where = [
|
||||
'post_id' => $record['id'],
|
||||
'user_id' => $request->user->uid
|
||||
];
|
||||
$record['is_like'] = PostLike::where($where)->count();
|
||||
$record['is_favorite'] = PostFavorite::where($where)->count();
|
||||
$record['is_comment'] = PostComment::where($where)->count();
|
||||
}else{
|
||||
$record['is_like'] = 0;
|
||||
$record['is_favorite'] = 0;
|
||||
$record['is_comment'] = 0;
|
||||
}
|
||||
$created_at = strtotime($record['created_at']);
|
||||
$record['year'] = date('Y', $created_at);
|
||||
$record['month'] = date('m', $created_at);
|
||||
$record['day'] = date('d', $created_at);
|
||||
}
|
||||
$data['records'] = $records;
|
||||
return $this->success($data);
|
||||
} catch (\Throwable $e) {
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 获取列表
|
||||
*
|
||||
@@ -66,7 +108,7 @@ class PostController extends BaseController
|
||||
$data['records'] = $records;
|
||||
return $this->success($data);
|
||||
} catch (\Throwable $e) {
|
||||
return $this->error($e->getMessage().$e->getFile().$e->getLine());
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user