优化朋友圈
This commit is contained in:
@@ -40,7 +40,7 @@ class FriendCircleController extends BaseController{
|
|||||||
'top_unread_items' =>[],
|
'top_unread_items' =>[],
|
||||||
'unread_item_ids' =>[],
|
'unread_item_ids' =>[],
|
||||||
'unread_count' =>0,
|
'unread_count' =>0,
|
||||||
'settings' => Db::name('friend_circle_setting')->where('user_id',$user_id)->order('id','desc')->findOrEmpty()
|
'settings' => Db::name('user_extend')->where('user_id',$user_id)->findOrEmpty()
|
||||||
];
|
];
|
||||||
return $this->success('ok',$json);
|
return $this->success('ok',$json);
|
||||||
}else{
|
}else{
|
||||||
@@ -52,7 +52,7 @@ class FriendCircleController extends BaseController{
|
|||||||
$res = $this->newcount($request);
|
$res = $this->newcount($request);
|
||||||
$response = $res->rawBody();
|
$response = $res->rawBody();
|
||||||
$json = json_decode($response,true);
|
$json = json_decode($response,true);
|
||||||
$json['data']['settings'] = Db::name('friend_circle_setting')->where('user_id',$user_id)->order('id','desc')->findOrEmpty();
|
$json['data']['settings'] = Db::name('user_extend')->where('user_id',$user_id)->findOrEmpty();
|
||||||
// [
|
// [
|
||||||
// 'bg' => '',
|
// 'bg' => '',
|
||||||
// ];
|
// ];
|
||||||
@@ -425,11 +425,8 @@ class FriendCircleController extends BaseController{
|
|||||||
return $this->fail( $res);
|
return $this->fail( $res);
|
||||||
}
|
}
|
||||||
|
|
||||||
Db::name('friend_circle_setting')->replace()->insert([
|
Db::name('user_extend')->where('user_id',$user->id)->save([
|
||||||
'user_id' => $user->id,
|
'moments_banner' => $res[0]['file_name']
|
||||||
'bg' => $res[0]['file_name'],
|
|
||||||
'allow_days'=>0,
|
|
||||||
'created_at'=>0
|
|
||||||
]);
|
]);
|
||||||
//$result->ss = cdnurl($result->url);
|
//$result->ss = cdnurl($result->url);
|
||||||
//P($result);
|
//P($result);
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace app\api\controller;
|
namespace app\api\controller;
|
||||||
|
|
||||||
use app\model\User as UserModel;
|
use app\model\User as UserModel;
|
||||||
use app\model\FriendCircle as FriendCircleModel;
|
use app\model\FriendCircle as FriendCircleModel;
|
||||||
use app\model\FriendCircleLike as FriendCircleLikeModel;
|
use app\model\FriendCircleLike as FriendCircleLikeModel;
|
||||||
@@ -12,25 +13,34 @@ use hg\apidoc\annotation as Apidoc;
|
|||||||
/**
|
/**
|
||||||
* 新朋友圈
|
* 新朋友圈
|
||||||
*/
|
*/
|
||||||
class MomentsController extends BaseController{
|
class MomentsController extends BaseController
|
||||||
/**
|
{
|
||||||
* 不需要鉴权的方法
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
public $noNeedAuth = ['*'];
|
public $noNeedAuth = ['*'];
|
||||||
|
|
||||||
/**
|
|
||||||
* 无需登录及鉴权的方法
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
public $noNeedLogin = [];
|
public $noNeedLogin = [];
|
||||||
public $user_display_fields = 'id,userID,nickname,avatar';
|
public $user_display_fields = 'id,userID,nickname,avatar';
|
||||||
/**
|
|
||||||
* 朋友圈设置
|
protected function getUserSettings(int $user_id): array
|
||||||
* @param string $userID 用户userID,可选,不填就查询自己
|
{
|
||||||
* @return void
|
$result = Db::name('user_extend')
|
||||||
*/
|
->where('user_id', $user_id)
|
||||||
function info(Request $request): Response{
|
->field('moments_allow_view_days,moments_banner')
|
||||||
|
->findOrEmpty();
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function processAvatar($data): void
|
||||||
|
{
|
||||||
|
if (is_array($data)) {
|
||||||
|
if (!empty($data['avatar'])) {
|
||||||
|
$data['avatar'] = cdnurl($data['avatar']);
|
||||||
|
}
|
||||||
|
} elseif (is_object($data) && !empty($data->avatar)) {
|
||||||
|
$data->avatar = cdnurl($data->avatar);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function info(Request $request): Response
|
||||||
|
{
|
||||||
$userID = Input('userID');
|
$userID = Input('userID');
|
||||||
if ($userID) {
|
if ($userID) {
|
||||||
$user_id = \support\Encrypt::userIDDecode($userID);
|
$user_id = \support\Encrypt::userIDDecode($userID);
|
||||||
@@ -38,19 +48,20 @@ class MomentsController extends BaseController{
|
|||||||
'top_unread_items' => [],
|
'top_unread_items' => [],
|
||||||
'unread_item_ids' => [],
|
'unread_item_ids' => [],
|
||||||
'unread_count' => 0,
|
'unread_count' => 0,
|
||||||
'settings' => Db::name('user_extend')->where('user_id',$user_id)->field('moments_allow_view_days,moments_banner')->findOrEmpty()
|
'settings' => $this->getUserSettings($user_id)
|
||||||
];
|
];
|
||||||
return $this->success('ok', $json);
|
return $this->success('ok', $json);
|
||||||
}else{
|
}
|
||||||
|
|
||||||
$user = \support\Jwt::getUser();
|
$user = \support\Jwt::getUser();
|
||||||
if (!$user) {
|
if (!$user) {
|
||||||
return $this->fail('请先登录');
|
return $this->fail('请先登录');
|
||||||
}
|
}
|
||||||
$userID = $user->userID;
|
|
||||||
$res = $this->newcount($request);
|
$res = $this->newcount($request);
|
||||||
$response = $res->rawBody();
|
$response = $res->rawBody();
|
||||||
$json = json_decode($response, true);
|
$json = json_decode($response, true);
|
||||||
$json['data']['settings'] = Db::name('user_extend')->where('user_id',$user->id)->field('moments_allow_view_days,moments_banner')->findOrEmpty();
|
$json['data']['settings'] = $this->getUserSettings($user->id);
|
||||||
|
|
||||||
$top_unread_items = FriendCircleModel::whereIn('id', $json['data']['unread_item_ids'])
|
$top_unread_items = FriendCircleModel::whereIn('id', $json['data']['unread_item_ids'])
|
||||||
->with(['user' => function ($query) {
|
->with(['user' => function ($query) {
|
||||||
@@ -63,7 +74,7 @@ class MomentsController extends BaseController{
|
|||||||
$res->withBody(json_encode($json));
|
$res->withBody(json_encode($json));
|
||||||
return $res;
|
return $res;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
/**
|
/**
|
||||||
* @Apidoc\Title("列表")
|
* @Apidoc\Title("列表")
|
||||||
* @Apidoc\Method("GET")
|
* @Apidoc\Method("GET")
|
||||||
@@ -78,33 +89,35 @@ class MomentsController extends BaseController{
|
|||||||
$page = (int)Input('page', 1);
|
$page = (int)Input('page', 1);
|
||||||
$limit = (int)Input('limit', 10);
|
$limit = (int)Input('limit', 10);
|
||||||
$userID = Input('userID');
|
$userID = Input('userID');
|
||||||
|
|
||||||
$query = FriendCircleModel::where('status', 1)
|
$query = FriendCircleModel::where('status', 1)
|
||||||
->with(['user' => function ($query) {
|
->with(['user' => function ($query) {
|
||||||
$query->field($this->user_display_fields);
|
$query->field($this->user_display_fields);
|
||||||
}])
|
}])
|
||||||
->order('created_at', 'desc');
|
->order('created_at', 'desc');
|
||||||
|
|
||||||
if ($userID) {
|
if ($userID) {
|
||||||
// 如果指定了用户ID,只获取该用户的朋友圈
|
|
||||||
$user_id = \support\Encrypt::userIDDecode($userID);
|
$user_id = \support\Encrypt::userIDDecode($userID);
|
||||||
$query->where('user_id', $user_id);
|
$query->where('user_id', $user_id);
|
||||||
} else {
|
} else {
|
||||||
$current_userID = \support\Encrypt::userIDencode($current_user_id);
|
$current_userID = $current_user_id > 0 ? \support\Encrypt::userIDencode($current_user_id) : '';
|
||||||
$query->whereIn('user_id',$this->getFriendUserIds($current_userID));
|
$friendIds = $this->getFriendUserIds($current_userID);
|
||||||
|
if (empty($friendIds)) {
|
||||||
|
return $this->success('ok', []);
|
||||||
|
}
|
||||||
|
$query->whereIn('user_id', $friendIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
$list = $query->paginate([
|
$list = $query->paginate([
|
||||||
'list_rows' => $limit,
|
'list_rows' => $limit,
|
||||||
'page' => $page,
|
'page' => $page,
|
||||||
]);
|
]);
|
||||||
if(!$userID){
|
|
||||||
|
if (!$userID && $list->count() > 0) {
|
||||||
cache('circle_last_read_id_' . $current_user_id, $list[0]['id']);
|
cache('circle_last_read_id_' . $current_user_id, $list[0]['id']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// 处理每条朋友圈数据
|
|
||||||
$items = $list->items();
|
|
||||||
$list->each(function ($item) use ($current_user_id) {
|
$list->each(function ($item) use ($current_user_id) {
|
||||||
// 获取点赞列表
|
|
||||||
$likes = Db::name('friend_circle_like')->alias('f')
|
$likes = Db::name('friend_circle_like')->alias('f')
|
||||||
->join('user u', 'u.id=f.user_id')
|
->join('user u', 'u.id=f.user_id')
|
||||||
->where('f.circle_id', $item->id)
|
->where('f.circle_id', $item->id)
|
||||||
@@ -113,19 +126,14 @@ class MomentsController extends BaseController{
|
|||||||
->limit(20)
|
->limit(20)
|
||||||
->select();
|
->select();
|
||||||
$likes = $likes ? $likes->toArray() : [];
|
$likes = $likes ? $likes->toArray() : [];
|
||||||
// 检查当前用户是否已点赞
|
|
||||||
$is_liked = false;
|
$is_liked = false;
|
||||||
if ($current_user_id > 0) {
|
if ($current_user_id > 0) {
|
||||||
$is_liked = null !== array_find($likes,function($item)use($current_user_id){
|
$is_liked = null !== array_find($likes, function ($like) use ($current_user_id) {
|
||||||
return $item['user_id'] == $current_user_id;
|
return $like['user_id'] == $current_user_id;
|
||||||
});
|
});
|
||||||
// FriendCircleLikeModel::where('circle_id', $item->id)
|
|
||||||
// ->where('user_id', $current_user_id)
|
|
||||||
// ->count() > 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// 获取评论列表(最新10条)
|
|
||||||
$comments = FriendCircleCommentModel::where('circle_id', $item->id)
|
$comments = FriendCircleCommentModel::where('circle_id', $item->id)
|
||||||
->where('status', 1)
|
->where('status', 1)
|
||||||
->with(['user' => function ($query) {
|
->with(['user' => function ($query) {
|
||||||
@@ -137,38 +145,28 @@ class MomentsController extends BaseController{
|
|||||||
->limit(10)
|
->limit(10)
|
||||||
->select();
|
->select();
|
||||||
|
|
||||||
// 格式化数据
|
|
||||||
$item->is_liked = $is_liked;
|
$item->is_liked = $is_liked;
|
||||||
$item->likes = $likes;
|
$item->likes = $likes;
|
||||||
$item->comments = $comments;
|
$item->comments = $comments;
|
||||||
|
|
||||||
// 处理图片URL
|
|
||||||
if (!empty($item->files)) {
|
if (!empty($item->files)) {
|
||||||
$files = is_array($item->files) ? $item->files : json_decode($item->files, true);
|
$files = is_array($item->files) ? $item->files : json_decode($item->files, true);
|
||||||
if (is_array($files)) {
|
$item->files = is_array($files) ? array_map('cdnurl', $files) : [];
|
||||||
$item->files = array_map(function($file) {
|
|
||||||
return cdnurl($file);
|
|
||||||
}, $files);
|
|
||||||
} else {
|
|
||||||
$item->files = [];
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
$item->files = [];
|
$item->files = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
// 处理用户头像
|
|
||||||
if ($item->user && $item->user->avatar) {
|
if ($item->user && $item->user->avatar) {
|
||||||
$item->user->avatar = cdnurl($item->user->avatar);
|
$item->user->avatar = cdnurl($item->user->avatar);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 处理点赞用户头像
|
foreach ($item->likes as &$like) {
|
||||||
foreach ($item->likes as $like) {
|
if (!empty($like['avatar'])) {
|
||||||
if ($like->user) {
|
$like['avatar'] = cdnurl($like['avatar']);
|
||||||
$like->avatar = cdnurl($like->avatar);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
unset($like);
|
||||||
|
|
||||||
// 处理评论用户头像
|
|
||||||
foreach ($item->comments as $comment) {
|
foreach ($item->comments as $comment) {
|
||||||
if ($comment->user && $comment->user->avatar) {
|
if ($comment->user && $comment->user->avatar) {
|
||||||
$comment->user->avatar = cdnurl($comment->user->avatar);
|
$comment->user->avatar = cdnurl($comment->user->avatar);
|
||||||
@@ -177,6 +175,7 @@ class MomentsController extends BaseController{
|
|||||||
$comment->replyUser->avatar = cdnurl($comment->replyUser->avatar);
|
$comment->replyUser->avatar = cdnurl($comment->replyUser->avatar);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $item;
|
return $item;
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -194,17 +193,17 @@ class MomentsController extends BaseController{
|
|||||||
if (!$user) {
|
if (!$user) {
|
||||||
return $this->fail('请先登录');
|
return $this->fail('请先登录');
|
||||||
}
|
}
|
||||||
|
|
||||||
$user_id = $user->id;
|
$user_id = $user->id;
|
||||||
$circle_last_read_id = cache('circle_last_read_id_' . $user_id) ?: 0;
|
$circle_last_read_id = cache('circle_last_read_id_' . $user_id) ?: 0;
|
||||||
$userID = \support\Encrypt::userIDencode($user_id);
|
$userID = \support\Encrypt::userIDencode($user_id);
|
||||||
// 统计从上次查看时间到现在新增的朋友圈数量
|
|
||||||
$unread_item_ids = FriendCircleModel::where('status', 1)
|
$unread_item_ids = FriendCircleModel::where('status', 1)
|
||||||
->whereIn('user_id', $this->getFriendUserIds($userID))
|
->whereIn('user_id', $this->getFriendUserIds($userID))
|
||||||
->where('id', '>', $circle_last_read_id)
|
->where('id', '>', $circle_last_read_id)
|
||||||
->order('id', 'desc')
|
->order('id', 'desc')
|
||||||
->column('id');
|
->column('id');
|
||||||
|
|
||||||
|
|
||||||
return $this->success('ok', [
|
return $this->success('ok', [
|
||||||
'unread_count' => count($unread_item_ids),
|
'unread_count' => count($unread_item_ids),
|
||||||
'unread_item_ids' => $unread_item_ids
|
'unread_item_ids' => $unread_item_ids
|
||||||
@@ -228,13 +227,11 @@ class MomentsController extends BaseController{
|
|||||||
$files = $request->post('files', '');
|
$files = $request->post('files', '');
|
||||||
$address = $request->post('address', '');
|
$address = $request->post('address', '');
|
||||||
$releaseType = $request->post('releaseType', '');
|
$releaseType = $request->post('releaseType', '');
|
||||||
// 验证内容
|
|
||||||
if (empty($body)) {
|
if (empty($body)) {
|
||||||
return $this->fail('什么内容都木有啊');
|
return $this->fail('什么内容都木有啊');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// 处理图片列表
|
|
||||||
$files_array = [];
|
$files_array = [];
|
||||||
if (!empty($files)) {
|
if (!empty($files)) {
|
||||||
if (is_string($files)) {
|
if (is_string($files)) {
|
||||||
@@ -247,13 +244,11 @@ class MomentsController extends BaseController{
|
|||||||
return $this->fail('图片列表格式错误');
|
return $this->fail('图片列表格式错误');
|
||||||
}
|
}
|
||||||
|
|
||||||
// 限制图片数量
|
|
||||||
if (count($files_array) > 9) {
|
if (count($files_array) > 9) {
|
||||||
return $this->fail('最多只能上传9张图片');
|
return $this->fail('最多只能上传9张图片');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 创建朋友圈动态
|
|
||||||
$circle = FriendCircleModel::create([
|
$circle = FriendCircleModel::create([
|
||||||
'user_id' => $user->id,
|
'user_id' => $user->id,
|
||||||
'releaseType' => $releaseType,
|
'releaseType' => $releaseType,
|
||||||
@@ -282,7 +277,7 @@ class MomentsController extends BaseController{
|
|||||||
|
|
||||||
$body = $request->post('body', '');
|
$body = $request->post('body', '');
|
||||||
$circle_id = (int)$request->post('id');
|
$circle_id = (int)$request->post('id');
|
||||||
$reply_userID = (int)$request->post('reply_userID');
|
$reply_userID = $request->post('reply_userID', '');
|
||||||
|
|
||||||
if (empty($body)) {
|
if (empty($body)) {
|
||||||
return $this->fail('评论内容不能为空');
|
return $this->fail('评论内容不能为空');
|
||||||
@@ -292,7 +287,6 @@ class MomentsController extends BaseController{
|
|||||||
return $this->fail('朋友圈动态ID错误');
|
return $this->fail('朋友圈动态ID错误');
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查朋友圈动态是否存在
|
|
||||||
$circle = FriendCircleModel::where('id', $circle_id)
|
$circle = FriendCircleModel::where('id', $circle_id)
|
||||||
->where('status', 1)
|
->where('status', 1)
|
||||||
->find();
|
->find();
|
||||||
@@ -301,11 +295,11 @@ class MomentsController extends BaseController{
|
|||||||
return $this->fail('朋友圈动态不存在');
|
return $this->fail('朋友圈动态不存在');
|
||||||
}
|
}
|
||||||
|
|
||||||
// 如果回复评论,检查被回复的用户是否存在
|
|
||||||
$reply_user_id = 0;
|
$reply_user_id = 0;
|
||||||
if ($reply_userID ) {
|
if (!empty($reply_userID)) {
|
||||||
$reply_user_id = \support\Encrypt::userIDDecode($reply_userID);
|
$reply_user_id = (int)\support\Encrypt::userIDDecode($reply_userID);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($reply_user_id > 0) {
|
if ($reply_user_id > 0) {
|
||||||
$reply_user = UserModel::where('id', $reply_user_id)->find();
|
$reply_user = UserModel::where('id', $reply_user_id)->find();
|
||||||
if (!$reply_user) {
|
if (!$reply_user) {
|
||||||
@@ -313,7 +307,6 @@ class MomentsController extends BaseController{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 创建评论
|
|
||||||
$comment = FriendCircleCommentModel::create([
|
$comment = FriendCircleCommentModel::create([
|
||||||
'circle_id' => $circle_id,
|
'circle_id' => $circle_id,
|
||||||
'user_id' => $user->id,
|
'user_id' => $user->id,
|
||||||
@@ -322,16 +315,17 @@ class MomentsController extends BaseController{
|
|||||||
'status' => 1,
|
'status' => 1,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// 更新朋友圈评论数
|
|
||||||
$circle->comment_count = FriendCircleCommentModel::where('circle_id', $circle_id)
|
$circle->comment_count = FriendCircleCommentModel::where('circle_id', $circle_id)
|
||||||
->where('status', 1)
|
->where('status', 1)
|
||||||
->count();
|
->count();
|
||||||
$circle->save();
|
$circle->save();
|
||||||
|
|
||||||
$comment->user = Db::name('user')->field($this->user_display_fields)->where('id', $comment->user_id)->find();
|
$comment->user = Db::name('user')->field($this->user_display_fields)->where('id', $comment->user_id)->find();
|
||||||
$comment->replyUser = null;
|
$comment->replyUser = null;
|
||||||
if ($comment->reply_user_id) {
|
if ($comment->reply_user_id) {
|
||||||
$comment->replyUser = Db::name('user')->field($this->user_display_fields)->where('id', $comment->reply_user_id)->find();
|
$comment->replyUser = Db::name('user')->field($this->user_display_fields)->where('id', $comment->reply_user_id)->find();
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->success('评论成功', $comment);
|
return $this->success('评论成功', $comment);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -353,7 +347,6 @@ class MomentsController extends BaseController{
|
|||||||
return $this->fail('朋友圈动态ID错误');
|
return $this->fail('朋友圈动态ID错误');
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查朋友圈动态是否存在
|
|
||||||
$circle = FriendCircleModel::where('id', $circle_id)
|
$circle = FriendCircleModel::where('id', $circle_id)
|
||||||
->where('status', 1)
|
->where('status', 1)
|
||||||
->find();
|
->find();
|
||||||
@@ -362,19 +355,17 @@ class MomentsController extends BaseController{
|
|||||||
return $this->fail('朋友圈动态不存在');
|
return $this->fail('朋友圈动态不存在');
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查是否已点赞
|
|
||||||
$like = FriendCircleLikeModel::where('circle_id', $circle_id)
|
$like = FriendCircleLikeModel::where('circle_id', $circle_id)
|
||||||
->where('user_id', $user->id)
|
->where('user_id', $user->id)
|
||||||
->find();
|
->find();
|
||||||
|
|
||||||
if ($like) {
|
if ($like) {
|
||||||
// 取消点赞
|
|
||||||
$like->delete();
|
$like->delete();
|
||||||
$circle->like_count = max(0, $circle->like_count - 1);
|
$circle->like_count = max(0, $circle->like_count - 1);
|
||||||
$circle->save();
|
$circle->save();
|
||||||
return $this->success('取消点赞成功', ['is_liked' => false]);
|
return $this->success('取消点赞成功', ['is_liked' => false]);
|
||||||
} else {
|
}
|
||||||
// 添加点赞
|
|
||||||
FriendCircleLikeModel::create([
|
FriendCircleLikeModel::create([
|
||||||
'circle_id' => $circle_id,
|
'circle_id' => $circle_id,
|
||||||
'user_id' => $user->id,
|
'user_id' => $user->id,
|
||||||
@@ -383,69 +374,91 @@ class MomentsController extends BaseController{
|
|||||||
$circle->save();
|
$circle->save();
|
||||||
return $this->success('点赞成功', ['is_liked' => true]);
|
return $this->success('点赞成功', ['is_liked' => true]);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
protected function getFriendUserIds($userID):array{
|
protected function getFriendUserIds($userID): array
|
||||||
|
{
|
||||||
if (!$userID) {
|
if (!$userID) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
$cache_key = 'friend_id_list_' . $userID;
|
$cache_key = 'friend_id_list_' . $userID;
|
||||||
$result = cache($cache_key) ?: [];
|
$result = cache($cache_key) ?: [];
|
||||||
|
|
||||||
if (count($result) === 0) {
|
if (count($result) === 0) {
|
||||||
$res = request()->IM->friend->getFriendList($userID);
|
$res = request()->IM->friend->getFriendList($userID);
|
||||||
$friendsInfo = $res['friendsInfo'];
|
$friendsInfo = $res['friendsInfo'] ?? [];
|
||||||
foreach($friendsInfo as $k=>$v){
|
foreach ($friendsInfo as $v) {
|
||||||
array_push($result,\support\Encrypt::userIDDecode($v['friendUser']['userID']));
|
$result[] = \support\Encrypt::userIDDecode($v['friendUser']['userID']);
|
||||||
}
|
}
|
||||||
cache($cache_key, $result, 3600);
|
cache($cache_key, $result, 3600);
|
||||||
}
|
}
|
||||||
|
|
||||||
$result[] = \support\Encrypt::userIDDecode($userID);
|
$result[] = \support\Encrypt::userIDDecode($userID);
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除朋友圈
|
* 删除朋友圈
|
||||||
* @Apidoc\Method("POST")
|
* @Apidoc\Method("POST")
|
||||||
* @Apidoc\Param("id", type="int", require=true, desc="朋友圈动态ID")
|
* @Apidoc\Param("id", type="int", require=true, desc="朋友圈动态ID")
|
||||||
* @return Response
|
* @return Response
|
||||||
*/
|
*/
|
||||||
function delete(Request $request): Response{
|
function delete(Request $request): Response
|
||||||
$id = $request->post('id');
|
{
|
||||||
|
$id = (int)$request->post('id');
|
||||||
$user = \support\Jwt::getUser();
|
$user = \support\Jwt::getUser();
|
||||||
if (!$user) {
|
if (!$user) {
|
||||||
return $this->fail('请先登录');
|
return $this->fail('请先登录');
|
||||||
}
|
}
|
||||||
if($id){
|
|
||||||
|
if ($id > 0) {
|
||||||
FriendCircleModel::where('id', $id)->where('user_id', $user->id)->delete();
|
FriendCircleModel::where('id', $id)->where('user_id', $user->id)->delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->success('删除成功');
|
return $this->success('删除成功');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置朋友圈背景
|
* 设置朋友圈背景
|
||||||
* @param Request $request
|
* @param Request $request
|
||||||
* @return Response
|
* @return Response
|
||||||
*/
|
*/
|
||||||
function upload_bg(Request $request){
|
function upload_bg(Request $request): Response
|
||||||
|
{
|
||||||
return $this->setBanner($request);
|
return $this->setBanner($request);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置朋友圈背景
|
* 设置朋友圈背景
|
||||||
* @Apidoc\Method("POST")
|
* @Apidoc\Method("POST")
|
||||||
* @Apidoc\Param("file", type="File", require=true, desc="文件")
|
* @Apidoc\Param("file", type="File", require=true, desc="文件")
|
||||||
* @return Response
|
* @return Response
|
||||||
*/
|
*/
|
||||||
function setBanner(Request $request){
|
function setBanner(Request $request): Response
|
||||||
|
{
|
||||||
try {
|
try {
|
||||||
$user = \support\Jwt::getUser();
|
$user = \support\Jwt::getUser();
|
||||||
if (!$user) {
|
if (!$user) {
|
||||||
return $this->fail('请先登录');
|
return $this->fail('请先登录');
|
||||||
}
|
}
|
||||||
|
|
||||||
$res = $this->_upload($request);
|
$res = $this->_upload($request);
|
||||||
if (is_string($res)) {
|
if (is_string($res)) {
|
||||||
return $this->fail($res);
|
return $this->fail($res);
|
||||||
}
|
}
|
||||||
|
|
||||||
Db::name('user_extend')->where('user_id',$user->id)->save([
|
$exist = Db::name('user_extend')->where('user_id', $user->id)->find();
|
||||||
|
if ($exist) {
|
||||||
|
Db::name('user_extend')
|
||||||
|
->where('user_id', $user->id)
|
||||||
|
->update(['moments_banner' => $res[0]['file_name']]);
|
||||||
|
} else {
|
||||||
|
Db::name('user_extend')->insert([
|
||||||
|
'user_id' => $user->id,
|
||||||
'moments_banner' => $res[0]['file_name'],
|
'moments_banner' => $res[0]['file_name'],
|
||||||
]);
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
return $this->success(__('successful'), [
|
return $this->success(__('successful'), [
|
||||||
'url' => $res[0]['file_name']
|
'url' => $res[0]['file_name']
|
||||||
]);
|
]);
|
||||||
@@ -453,5 +466,4 @@ class MomentsController extends BaseController{
|
|||||||
return $this->error($e->getMessage());
|
return $this->error($e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user