2026-03-25 02:48:30 +08:00
|
|
|
<?php
|
|
|
|
|
namespace app\api\controller;
|
2026-04-06 03:36:41 +08:00
|
|
|
|
2026-03-25 02:48:30 +08:00
|
|
|
use app\model\User as UserModel;
|
|
|
|
|
use app\model\FriendCircle as FriendCircleModel;
|
|
|
|
|
use app\model\FriendCircleLike as FriendCircleLikeModel;
|
|
|
|
|
use app\model\FriendCircleComment as FriendCircleCommentModel;
|
|
|
|
|
use support\Request;
|
|
|
|
|
use support\Response;
|
|
|
|
|
use support\think\Db;
|
|
|
|
|
use hg\apidoc\annotation as Apidoc;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 新朋友圈
|
|
|
|
|
*/
|
2026-04-06 03:36:41 +08:00
|
|
|
class MomentsController extends BaseController
|
|
|
|
|
{
|
2026-03-25 02:48:30 +08:00
|
|
|
public $noNeedAuth = ['*'];
|
|
|
|
|
public $noNeedLogin = [];
|
|
|
|
|
public $user_display_fields = 'id,userID,nickname,avatar';
|
2026-04-06 03:36:41 +08:00
|
|
|
|
|
|
|
|
protected function getUserSettings(int $user_id): array
|
|
|
|
|
{
|
|
|
|
|
$result = Db::name('user_extend')
|
|
|
|
|
->where('user_id', $user_id)
|
|
|
|
|
->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
|
|
|
|
|
{
|
2026-03-25 02:48:30 +08:00
|
|
|
$userID = Input('userID');
|
2026-04-06 03:36:41 +08:00
|
|
|
if ($userID) {
|
2026-03-25 02:48:30 +08:00
|
|
|
$user_id = \support\Encrypt::userIDDecode($userID);
|
2026-04-06 03:36:41 +08:00
|
|
|
$json = [
|
|
|
|
|
'top_unread_items' => [],
|
|
|
|
|
'unread_item_ids' => [],
|
|
|
|
|
'unread_count' => 0,
|
|
|
|
|
'settings' => $this->getUserSettings($user_id)
|
2026-03-25 02:48:30 +08:00
|
|
|
];
|
2026-04-06 03:36:41 +08:00
|
|
|
return $this->success('ok', $json);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$user = \support\Jwt::getUser();
|
|
|
|
|
if (!$user) {
|
|
|
|
|
return $this->fail('请先登录');
|
2026-03-25 02:48:30 +08:00
|
|
|
}
|
2026-04-06 03:36:41 +08:00
|
|
|
|
|
|
|
|
$res = $this->newcount($request);
|
|
|
|
|
$response = $res->rawBody();
|
|
|
|
|
$json = json_decode($response, true);
|
|
|
|
|
$json['data']['settings'] = $this->getUserSettings($user->id);
|
|
|
|
|
|
|
|
|
|
$top_unread_items = FriendCircleModel::whereIn('id', $json['data']['unread_item_ids'])
|
|
|
|
|
->with(['user' => function ($query) {
|
|
|
|
|
$query->field($this->user_display_fields);
|
|
|
|
|
}])
|
|
|
|
|
->order('id', 'desc')
|
|
|
|
|
->limit(0, 3)
|
|
|
|
|
->select();
|
|
|
|
|
$json['data']['top_unread_items'] = $top_unread_items ?: [];
|
|
|
|
|
$res->withBody(json_encode($json));
|
|
|
|
|
return $res;
|
2026-03-25 02:48:30 +08:00
|
|
|
}
|
2026-04-06 03:36:41 +08:00
|
|
|
|
2026-03-25 02:48:30 +08:00
|
|
|
/**
|
|
|
|
|
* @Apidoc\Title("列表")
|
|
|
|
|
* @Apidoc\Method("GET")
|
|
|
|
|
* @Apidoc\Query("userID", type="string", require=false, desc="用户userID,不传则获取所有")
|
2026-04-06 03:36:41 +08:00
|
|
|
* @Apidoc\Query("page", type="int", require=true, desc="页码", default=1)
|
|
|
|
|
* @Apidoc\Query("limit", type="int", require=true, desc="分页大小", default=10)
|
2026-03-25 02:48:30 +08:00
|
|
|
*/
|
|
|
|
|
function list(Request $request): Response
|
|
|
|
|
{
|
|
|
|
|
$current_user = \support\Jwt::getUser();
|
|
|
|
|
$current_user_id = $current_user ? $current_user->id : 0;
|
|
|
|
|
$page = (int)Input('page', 1);
|
|
|
|
|
$limit = (int)Input('limit', 10);
|
|
|
|
|
$userID = Input('userID');
|
2026-04-06 03:36:41 +08:00
|
|
|
|
2026-03-25 02:48:30 +08:00
|
|
|
$query = FriendCircleModel::where('status', 1)
|
2026-04-06 03:36:41 +08:00
|
|
|
->with(['user' => function ($query) {
|
2026-03-25 02:48:30 +08:00
|
|
|
$query->field($this->user_display_fields);
|
|
|
|
|
}])
|
|
|
|
|
->order('created_at', 'desc');
|
2026-04-06 03:36:41 +08:00
|
|
|
|
|
|
|
|
if ($userID) {
|
2026-03-25 02:48:30 +08:00
|
|
|
$user_id = \support\Encrypt::userIDDecode($userID);
|
2026-04-06 03:36:41 +08:00
|
|
|
$query->where('user_id', $user_id);
|
|
|
|
|
} else {
|
|
|
|
|
$current_userID = $current_user_id > 0 ? \support\Encrypt::userIDencode($current_user_id) : '';
|
|
|
|
|
$friendIds = $this->getFriendUserIds($current_userID);
|
|
|
|
|
if (empty($friendIds)) {
|
|
|
|
|
return $this->success('ok', []);
|
|
|
|
|
}
|
|
|
|
|
$query->whereIn('user_id', $friendIds);
|
2026-03-25 02:48:30 +08:00
|
|
|
}
|
2026-04-06 03:36:41 +08:00
|
|
|
|
2026-03-25 02:48:30 +08:00
|
|
|
$list = $query->paginate([
|
|
|
|
|
'list_rows' => $limit,
|
|
|
|
|
'page' => $page,
|
|
|
|
|
]);
|
2026-04-06 03:36:41 +08:00
|
|
|
|
|
|
|
|
if (!$userID && $list->count() > 0) {
|
|
|
|
|
cache('circle_last_read_id_' . $current_user_id, $list[0]['id']);
|
2026-03-25 02:48:30 +08:00
|
|
|
}
|
2026-04-06 03:36:41 +08:00
|
|
|
|
|
|
|
|
$list->each(function ($item) use ($current_user_id) {
|
2026-03-25 02:48:30 +08:00
|
|
|
$likes = Db::name('friend_circle_like')->alias('f')
|
2026-04-06 03:36:41 +08:00
|
|
|
->join('user u', 'u.id=f.user_id')
|
2026-03-25 02:48:30 +08:00
|
|
|
->where('f.circle_id', $item->id)
|
|
|
|
|
->field('f.*,u.userID,u.avatar,u.nickname')
|
|
|
|
|
->order('f.created_at', 'desc')
|
|
|
|
|
->limit(20)
|
|
|
|
|
->select();
|
|
|
|
|
$likes = $likes ? $likes->toArray() : [];
|
2026-04-06 03:36:41 +08:00
|
|
|
|
2026-03-25 02:48:30 +08:00
|
|
|
$is_liked = false;
|
|
|
|
|
if ($current_user_id > 0) {
|
2026-04-06 03:36:41 +08:00
|
|
|
$is_liked = null !== array_find($likes, function ($like) use ($current_user_id) {
|
|
|
|
|
return $like['user_id'] == $current_user_id;
|
2026-03-25 02:48:30 +08:00
|
|
|
});
|
|
|
|
|
}
|
2026-04-06 03:36:41 +08:00
|
|
|
|
2026-03-25 02:48:30 +08:00
|
|
|
$comments = FriendCircleCommentModel::where('circle_id', $item->id)
|
|
|
|
|
->where('status', 1)
|
2026-04-06 03:36:41 +08:00
|
|
|
->with(['user' => function ($query) {
|
2026-03-25 02:48:30 +08:00
|
|
|
$query->field($this->user_display_fields);
|
2026-04-06 03:36:41 +08:00
|
|
|
}, 'replyUser' => function ($query) {
|
2026-03-25 02:48:30 +08:00
|
|
|
$query->field($this->user_display_fields);
|
|
|
|
|
}])
|
|
|
|
|
->order('created_at', 'asc')
|
|
|
|
|
->limit(10)
|
|
|
|
|
->select();
|
2026-04-06 03:36:41 +08:00
|
|
|
|
2026-03-25 02:48:30 +08:00
|
|
|
$item->is_liked = $is_liked;
|
|
|
|
|
$item->likes = $likes;
|
|
|
|
|
$item->comments = $comments;
|
2026-04-06 03:36:41 +08:00
|
|
|
|
2026-03-25 02:48:30 +08:00
|
|
|
if (!empty($item->files)) {
|
|
|
|
|
$files = is_array($item->files) ? $item->files : json_decode($item->files, true);
|
2026-04-06 03:36:41 +08:00
|
|
|
$item->files = is_array($files) ? array_map('cdnurl', $files) : [];
|
2026-03-25 02:48:30 +08:00
|
|
|
} else {
|
|
|
|
|
$item->files = [];
|
|
|
|
|
}
|
2026-04-06 03:36:41 +08:00
|
|
|
|
2026-03-25 02:48:30 +08:00
|
|
|
if ($item->user && $item->user->avatar) {
|
|
|
|
|
$item->user->avatar = cdnurl($item->user->avatar);
|
|
|
|
|
}
|
2026-04-06 03:36:41 +08:00
|
|
|
|
2026-04-06 04:35:35 +08:00
|
|
|
$likes = $item->likes;
|
|
|
|
|
if (is_array($likes) || $likes instanceof \Traversable) {
|
|
|
|
|
foreach ($likes as &$like) {
|
|
|
|
|
if (!empty($like['avatar'])) {
|
|
|
|
|
$like['avatar'] = cdnurl($like['avatar']);
|
|
|
|
|
}
|
2026-03-25 02:48:30 +08:00
|
|
|
}
|
2026-04-06 04:35:35 +08:00
|
|
|
unset($like);
|
|
|
|
|
$item->likes = $likes;
|
2026-03-25 02:48:30 +08:00
|
|
|
}
|
2026-04-06 03:36:41 +08:00
|
|
|
|
2026-03-25 02:48:30 +08:00
|
|
|
foreach ($item->comments as $comment) {
|
|
|
|
|
if ($comment->user && $comment->user->avatar) {
|
|
|
|
|
$comment->user->avatar = cdnurl($comment->user->avatar);
|
|
|
|
|
}
|
|
|
|
|
if ($comment->replyUser && $comment->replyUser->avatar) {
|
|
|
|
|
$comment->replyUser->avatar = cdnurl($comment->replyUser->avatar);
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-04-06 03:36:41 +08:00
|
|
|
|
2026-03-25 02:48:30 +08:00
|
|
|
return $item;
|
|
|
|
|
});
|
2026-04-06 03:36:41 +08:00
|
|
|
|
2026-03-25 02:48:30 +08:00
|
|
|
return $this->success('ok', $list);
|
|
|
|
|
}
|
2026-04-06 03:36:41 +08:00
|
|
|
|
2026-03-25 02:48:30 +08:00
|
|
|
/**
|
|
|
|
|
* @Apidoc\Title("最近更新的数量")
|
|
|
|
|
* @Apidoc\Method("POST")
|
2026-04-06 03:36:41 +08:00
|
|
|
* @Apidoc\Param("last_see", type="string", require=false, desc="最近查看的时间戳")
|
2026-03-25 02:48:30 +08:00
|
|
|
*/
|
|
|
|
|
function newcount(Request $request): Response
|
|
|
|
|
{
|
|
|
|
|
$user = \support\Jwt::getUser();
|
|
|
|
|
if (!$user) {
|
|
|
|
|
return $this->fail('请先登录');
|
|
|
|
|
}
|
2026-04-06 03:36:41 +08:00
|
|
|
|
2026-03-25 02:48:30 +08:00
|
|
|
$user_id = $user->id;
|
2026-04-06 03:36:41 +08:00
|
|
|
$circle_last_read_id = cache('circle_last_read_id_' . $user_id) ?: 0;
|
2026-03-25 02:48:30 +08:00
|
|
|
$userID = \support\Encrypt::userIDencode($user_id);
|
2026-04-06 03:36:41 +08:00
|
|
|
|
2026-03-25 02:48:30 +08:00
|
|
|
$unread_item_ids = FriendCircleModel::where('status', 1)
|
2026-04-06 03:36:41 +08:00
|
|
|
->whereIn('user_id', $this->getFriendUserIds($userID))
|
2026-03-25 02:48:30 +08:00
|
|
|
->where('id', '>', $circle_last_read_id)
|
|
|
|
|
->order('id', 'desc')
|
|
|
|
|
->column('id');
|
2026-04-06 03:36:41 +08:00
|
|
|
|
2026-03-25 02:48:30 +08:00
|
|
|
return $this->success('ok', [
|
|
|
|
|
'unread_count' => count($unread_item_ids),
|
2026-04-06 03:36:41 +08:00
|
|
|
'unread_item_ids' => $unread_item_ids
|
2026-03-25 02:48:30 +08:00
|
|
|
]);
|
|
|
|
|
}
|
2026-04-06 03:36:41 +08:00
|
|
|
|
2026-03-25 02:48:30 +08:00
|
|
|
/**
|
|
|
|
|
* @Apidoc\Title("发布朋友圈")
|
|
|
|
|
* @Apidoc\Method("POST")
|
2026-04-06 03:36:41 +08:00
|
|
|
* @Apidoc\Param("body", type="string", require=false, desc="内容")
|
|
|
|
|
* @Apidoc\Param("files", type="string", require=false, desc="图片列表(JSON数组)")
|
2026-03-25 02:48:30 +08:00
|
|
|
*/
|
|
|
|
|
function create(Request $request): Response
|
|
|
|
|
{
|
|
|
|
|
$user = \support\Jwt::getUser();
|
|
|
|
|
if (!$user) {
|
|
|
|
|
return $this->fail('请先登录');
|
|
|
|
|
}
|
2026-04-06 03:36:41 +08:00
|
|
|
|
2026-03-25 02:48:30 +08:00
|
|
|
$body = $request->post('content', '');
|
|
|
|
|
$files = $request->post('files', '');
|
|
|
|
|
$address = $request->post('address', '');
|
|
|
|
|
$releaseType = $request->post('releaseType', '');
|
2026-04-06 03:36:41 +08:00
|
|
|
|
2026-03-25 02:48:30 +08:00
|
|
|
if (empty($body)) {
|
|
|
|
|
return $this->fail('什么内容都木有啊');
|
|
|
|
|
}
|
2026-04-06 03:36:41 +08:00
|
|
|
|
2026-03-25 02:48:30 +08:00
|
|
|
$files_array = [];
|
|
|
|
|
if (!empty($files)) {
|
|
|
|
|
if (is_string($files)) {
|
|
|
|
|
$files_array = json_decode($files, true);
|
|
|
|
|
} elseif (is_array($files)) {
|
|
|
|
|
$files_array = $files;
|
|
|
|
|
}
|
2026-04-06 03:36:41 +08:00
|
|
|
|
2026-03-25 02:48:30 +08:00
|
|
|
if (!is_array($files_array)) {
|
|
|
|
|
return $this->fail('图片列表格式错误');
|
|
|
|
|
}
|
2026-04-06 03:36:41 +08:00
|
|
|
|
2026-03-25 02:48:30 +08:00
|
|
|
if (count($files_array) > 9) {
|
|
|
|
|
return $this->fail('最多只能上传9张图片');
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-04-06 03:36:41 +08:00
|
|
|
|
2026-03-25 02:48:30 +08:00
|
|
|
$circle = FriendCircleModel::create([
|
|
|
|
|
'user_id' => $user->id,
|
|
|
|
|
'releaseType' => $releaseType,
|
|
|
|
|
'body' => $body,
|
|
|
|
|
'files' => $files_array,
|
|
|
|
|
'address' => $address,
|
|
|
|
|
'status' => 1,
|
|
|
|
|
]);
|
2026-04-06 03:36:41 +08:00
|
|
|
|
|
|
|
|
return $this->success('发布成功', ['id' => $circle->id, 'data' => $circle]);
|
2026-03-25 02:48:30 +08:00
|
|
|
}
|
2026-04-06 03:36:41 +08:00
|
|
|
|
2026-03-25 02:48:30 +08:00
|
|
|
/**
|
|
|
|
|
* @Apidoc\Title("发表评论")
|
|
|
|
|
* @Apidoc\Method("POST")
|
2026-04-06 03:36:41 +08:00
|
|
|
* @Apidoc\Param("body", type="string", require=true, desc="内容")
|
|
|
|
|
* @Apidoc\Param("id", type="int", require=true, desc="朋友圈动态ID")
|
|
|
|
|
* @Apidoc\Param("reply_userID", type="string", require=false, desc="回复的用户userID(回复评论时使用)")
|
2026-03-25 02:48:30 +08:00
|
|
|
*/
|
|
|
|
|
function comment(Request $request): Response
|
|
|
|
|
{
|
|
|
|
|
$user = \support\Jwt::getUser();
|
|
|
|
|
if (!$user) {
|
|
|
|
|
return $this->fail('请先登录');
|
|
|
|
|
}
|
2026-04-06 03:36:41 +08:00
|
|
|
|
2026-03-25 02:48:30 +08:00
|
|
|
$body = $request->post('body', '');
|
|
|
|
|
$circle_id = (int)$request->post('id');
|
2026-04-06 03:36:41 +08:00
|
|
|
$reply_userID = $request->post('reply_userID', '');
|
|
|
|
|
|
2026-03-25 02:48:30 +08:00
|
|
|
if (empty($body)) {
|
|
|
|
|
return $this->fail('评论内容不能为空');
|
|
|
|
|
}
|
2026-04-06 03:36:41 +08:00
|
|
|
|
2026-03-25 02:48:30 +08:00
|
|
|
if ($circle_id <= 0) {
|
|
|
|
|
return $this->fail('朋友圈动态ID错误');
|
|
|
|
|
}
|
2026-04-06 03:36:41 +08:00
|
|
|
|
2026-03-25 02:48:30 +08:00
|
|
|
$circle = FriendCircleModel::where('id', $circle_id)
|
|
|
|
|
->where('status', 1)
|
|
|
|
|
->find();
|
2026-04-06 03:36:41 +08:00
|
|
|
|
2026-03-25 02:48:30 +08:00
|
|
|
if (!$circle) {
|
|
|
|
|
return $this->fail('朋友圈动态不存在');
|
|
|
|
|
}
|
2026-04-06 03:36:41 +08:00
|
|
|
|
2026-03-25 02:48:30 +08:00
|
|
|
$reply_user_id = 0;
|
2026-04-06 03:36:41 +08:00
|
|
|
if (!empty($reply_userID)) {
|
|
|
|
|
$reply_user_id = (int)\support\Encrypt::userIDDecode($reply_userID);
|
2026-03-25 02:48:30 +08:00
|
|
|
}
|
2026-04-06 03:36:41 +08:00
|
|
|
|
|
|
|
|
if ($reply_user_id > 0) {
|
2026-03-25 02:48:30 +08:00
|
|
|
$reply_user = UserModel::where('id', $reply_user_id)->find();
|
|
|
|
|
if (!$reply_user) {
|
|
|
|
|
return $this->fail('被回复的用户不存在');
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-04-06 03:36:41 +08:00
|
|
|
|
2026-03-25 02:48:30 +08:00
|
|
|
$comment = FriendCircleCommentModel::create([
|
|
|
|
|
'circle_id' => $circle_id,
|
|
|
|
|
'user_id' => $user->id,
|
|
|
|
|
'reply_user_id' => $reply_user_id,
|
|
|
|
|
'body' => $body,
|
|
|
|
|
'status' => 1,
|
|
|
|
|
]);
|
2026-04-06 03:36:41 +08:00
|
|
|
|
2026-03-25 02:48:30 +08:00
|
|
|
$circle->comment_count = FriendCircleCommentModel::where('circle_id', $circle_id)
|
|
|
|
|
->where('status', 1)
|
|
|
|
|
->count();
|
|
|
|
|
$circle->save();
|
2026-04-06 03:36:41 +08:00
|
|
|
|
|
|
|
|
$comment->user = Db::name('user')->field($this->user_display_fields)->where('id', $comment->user_id)->find();
|
|
|
|
|
$comment->replyUser = null;
|
|
|
|
|
if ($comment->reply_user_id) {
|
|
|
|
|
$comment->replyUser = Db::name('user')->field($this->user_display_fields)->where('id', $comment->reply_user_id)->find();
|
2026-03-25 02:48:30 +08:00
|
|
|
}
|
2026-04-06 03:36:41 +08:00
|
|
|
|
2026-03-25 02:48:30 +08:00
|
|
|
return $this->success('评论成功', $comment);
|
|
|
|
|
}
|
2026-04-06 03:36:41 +08:00
|
|
|
|
2026-03-25 02:48:30 +08:00
|
|
|
/**
|
|
|
|
|
* @Apidoc\Title("点赞")
|
|
|
|
|
* @Apidoc\Method("POST")
|
2026-04-06 03:36:41 +08:00
|
|
|
* @Apidoc\Param("id", type="int", require=true, desc="朋友圈动态ID")
|
2026-03-25 02:48:30 +08:00
|
|
|
*/
|
|
|
|
|
function like(Request $request): Response
|
|
|
|
|
{
|
|
|
|
|
$user = \support\Jwt::getUser();
|
|
|
|
|
if (!$user) {
|
|
|
|
|
return $this->fail('请先登录');
|
|
|
|
|
}
|
2026-04-06 03:36:41 +08:00
|
|
|
|
2026-03-25 02:48:30 +08:00
|
|
|
$circle_id = (int)$request->post('id', 0);
|
2026-04-06 03:36:41 +08:00
|
|
|
|
2026-03-25 02:48:30 +08:00
|
|
|
if ($circle_id <= 0) {
|
|
|
|
|
return $this->fail('朋友圈动态ID错误');
|
|
|
|
|
}
|
2026-04-06 03:36:41 +08:00
|
|
|
|
2026-03-25 02:48:30 +08:00
|
|
|
$circle = FriendCircleModel::where('id', $circle_id)
|
|
|
|
|
->where('status', 1)
|
|
|
|
|
->find();
|
2026-04-06 03:36:41 +08:00
|
|
|
|
2026-03-25 02:48:30 +08:00
|
|
|
if (!$circle) {
|
|
|
|
|
return $this->fail('朋友圈动态不存在');
|
|
|
|
|
}
|
2026-04-06 03:36:41 +08:00
|
|
|
|
2026-03-25 02:48:30 +08:00
|
|
|
$like = FriendCircleLikeModel::where('circle_id', $circle_id)
|
|
|
|
|
->where('user_id', $user->id)
|
|
|
|
|
->find();
|
2026-04-06 03:36:41 +08:00
|
|
|
|
2026-03-25 02:48:30 +08:00
|
|
|
if ($like) {
|
|
|
|
|
$like->delete();
|
|
|
|
|
$circle->like_count = max(0, $circle->like_count - 1);
|
|
|
|
|
$circle->save();
|
|
|
|
|
return $this->success('取消点赞成功', ['is_liked' => false]);
|
|
|
|
|
}
|
2026-04-06 03:36:41 +08:00
|
|
|
|
|
|
|
|
FriendCircleLikeModel::create([
|
|
|
|
|
'circle_id' => $circle_id,
|
|
|
|
|
'user_id' => $user->id,
|
|
|
|
|
]);
|
|
|
|
|
$circle->like_count = $circle->like_count + 1;
|
|
|
|
|
$circle->save();
|
|
|
|
|
return $this->success('点赞成功', ['is_liked' => true]);
|
2026-03-25 02:48:30 +08:00
|
|
|
}
|
2026-04-06 03:36:41 +08:00
|
|
|
|
|
|
|
|
protected function getFriendUserIds($userID): array
|
|
|
|
|
{
|
2026-03-25 02:48:30 +08:00
|
|
|
if (!$userID) {
|
|
|
|
|
return [];
|
|
|
|
|
}
|
2026-04-06 03:36:41 +08:00
|
|
|
|
|
|
|
|
$cache_key = 'friend_id_list_' . $userID;
|
2026-03-25 02:48:30 +08:00
|
|
|
$result = cache($cache_key) ?: [];
|
2026-04-06 03:36:41 +08:00
|
|
|
|
|
|
|
|
if (count($result) === 0) {
|
2026-03-25 02:48:30 +08:00
|
|
|
$res = request()->IM->friend->getFriendList($userID);
|
2026-04-06 03:36:41 +08:00
|
|
|
$friendsInfo = $res['friendsInfo'] ?? [];
|
|
|
|
|
foreach ($friendsInfo as $v) {
|
|
|
|
|
$result[] = \support\Encrypt::userIDDecode($v['friendUser']['userID']);
|
2026-03-25 02:48:30 +08:00
|
|
|
}
|
2026-04-06 03:36:41 +08:00
|
|
|
cache($cache_key, $result, 3600);
|
2026-03-25 02:48:30 +08:00
|
|
|
}
|
2026-04-06 03:36:41 +08:00
|
|
|
|
2026-03-25 02:48:30 +08:00
|
|
|
$result[] = \support\Encrypt::userIDDecode($userID);
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
2026-04-06 03:36:41 +08:00
|
|
|
|
2026-04-04 08:52:59 +08:00
|
|
|
/**
|
|
|
|
|
* 删除朋友圈
|
|
|
|
|
* @Apidoc\Method("POST")
|
2026-04-06 03:36:41 +08:00
|
|
|
* @Apidoc\Param("id", type="int", require=true, desc="朋友圈动态ID")
|
2026-04-04 08:52:59 +08:00
|
|
|
* @return Response
|
|
|
|
|
*/
|
2026-04-06 03:36:41 +08:00
|
|
|
function delete(Request $request): Response
|
|
|
|
|
{
|
|
|
|
|
$id = (int)$request->post('id');
|
2026-03-25 02:48:30 +08:00
|
|
|
$user = \support\Jwt::getUser();
|
|
|
|
|
if (!$user) {
|
|
|
|
|
return $this->fail('请先登录');
|
|
|
|
|
}
|
2026-04-06 03:36:41 +08:00
|
|
|
|
|
|
|
|
if ($id > 0) {
|
|
|
|
|
FriendCircleModel::where('id', $id)->where('user_id', $user->id)->delete();
|
2026-03-25 02:48:30 +08:00
|
|
|
}
|
2026-04-06 03:36:41 +08:00
|
|
|
|
2026-03-25 02:48:30 +08:00
|
|
|
return $this->success('删除成功');
|
|
|
|
|
}
|
2026-04-06 03:36:41 +08:00
|
|
|
|
2026-03-25 02:48:30 +08:00
|
|
|
/**
|
|
|
|
|
* 设置朋友圈背景
|
|
|
|
|
* @param Request $request
|
|
|
|
|
* @return Response
|
|
|
|
|
*/
|
2026-04-06 03:36:41 +08:00
|
|
|
function upload_bg(Request $request): Response
|
|
|
|
|
{
|
2026-03-25 02:48:30 +08:00
|
|
|
return $this->setBanner($request);
|
|
|
|
|
}
|
2026-04-06 03:36:41 +08:00
|
|
|
|
2026-03-25 02:48:30 +08:00
|
|
|
/**
|
|
|
|
|
* 设置朋友圈背景
|
2026-04-04 08:52:59 +08:00
|
|
|
* @Apidoc\Method("POST")
|
2026-04-06 03:36:41 +08:00
|
|
|
* @Apidoc\Param("file", type="File", require=true, desc="文件")
|
2026-03-25 02:48:30 +08:00
|
|
|
* @return Response
|
|
|
|
|
*/
|
2026-04-06 03:36:41 +08:00
|
|
|
function setBanner(Request $request): Response
|
|
|
|
|
{
|
2026-03-25 02:48:30 +08:00
|
|
|
try {
|
|
|
|
|
$user = \support\Jwt::getUser();
|
|
|
|
|
if (!$user) {
|
|
|
|
|
return $this->fail('请先登录');
|
|
|
|
|
}
|
2026-04-06 03:36:41 +08:00
|
|
|
|
2026-03-25 02:48:30 +08:00
|
|
|
$res = $this->_upload($request);
|
2026-04-06 03:36:41 +08:00
|
|
|
if (is_string($res)) {
|
|
|
|
|
return $this->fail($res);
|
2026-03-25 02:48:30 +08:00
|
|
|
}
|
2026-04-06 03:36:41 +08:00
|
|
|
|
|
|
|
|
$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'],
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $this->success(__('successful'), [
|
|
|
|
|
'url' => $res[0]['file_name']
|
2026-03-25 02:48:30 +08:00
|
|
|
]);
|
2026-04-06 03:36:41 +08:00
|
|
|
} catch (\Exception $e) {
|
2026-03-25 02:48:30 +08:00
|
|
|
return $this->error($e->getMessage());
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-04-06 03:36:41 +08:00
|
|
|
}
|