9
This commit is contained in:
@@ -34,26 +34,40 @@ class FriendCircleController extends BaseController{
|
||||
* @return void
|
||||
*/
|
||||
function info(Request $request): Response{
|
||||
$user = \support\Jwt::getUser();
|
||||
if (!$user) {
|
||||
return $this->fail('请先登录');
|
||||
$user_id = Input('user_id');
|
||||
if($user_id){
|
||||
$user_id = idDecode($user_id);
|
||||
$json= [
|
||||
'top_unread_items' =>[],
|
||||
'unread_item_ids' =>[],
|
||||
'unread_count' =>0,
|
||||
'settings' => Db::name('friend_circle_setting')->where('user_id',$user_id)->order('id','desc')->findOrEmpty()
|
||||
];
|
||||
return $this->success('ok',$json);
|
||||
}else{
|
||||
$user = \support\Jwt::getUser();
|
||||
if (!$user) {
|
||||
return $this->fail('请先登录');
|
||||
}
|
||||
$user_id = $user->id;
|
||||
$res = $this->newcount($request);
|
||||
$response = $res->rawBody();
|
||||
$json = json_decode($response,true);
|
||||
$json['data']['settings'] = Db::name('friend_circle_setting')->where('user_id',$user_id)->order('id','desc')->findOrEmpty();
|
||||
// [
|
||||
// 'bg' => '',
|
||||
// ];
|
||||
$top_unread_items = FriendCircleModel::whereIn('id',$json['data']['unread_item_ids'])
|
||||
->with(['user' => function($query) {
|
||||
$query->field('id,nickname,avatar');
|
||||
}])
|
||||
->order('id', 'desc')
|
||||
->limit(0,3)
|
||||
->select();
|
||||
$json['data']['top_unread_items'] = $top_unread_items ?: [];
|
||||
$res->withBody(json_encode($json));
|
||||
return $res;
|
||||
}
|
||||
$res = $this->newcount($request);
|
||||
$response = $res->rawBody();
|
||||
$json = json_decode($response,true);
|
||||
$json['data']['settings'] = [
|
||||
'bg' => '',
|
||||
];
|
||||
$top_unread_items = FriendCircleModel::whereIn('id',$json['data']['unread_item_ids'])
|
||||
->with(['user' => function($query) {
|
||||
$query->field('id,nickname,avatar');
|
||||
}])
|
||||
->order('id', 'desc')
|
||||
->limit(0,3)
|
||||
->select();
|
||||
$json['data']['top_unread_items'] = $top_unread_items ?: [];
|
||||
$res->withBody(json_encode($json));
|
||||
return $res;
|
||||
}
|
||||
/**
|
||||
* @Apidoc\Title("列表")
|
||||
@@ -66,9 +80,12 @@ class FriendCircleController extends BaseController{
|
||||
{
|
||||
$current_user = \support\Jwt::getUser();
|
||||
$current_user_id = $current_user ? $current_user->id : 0;
|
||||
$page = (int)$request->get('page', 1);
|
||||
$limit = (int)$request->get('limit', 10);
|
||||
$user_id = $request->get('user_id', 0);
|
||||
$page = (int)Input('page', 1);
|
||||
$limit = (int)Input('limit', 10);
|
||||
$user_id = Input('user_id', 0);
|
||||
if($user_id){
|
||||
$user_id = idDecode($user_id);
|
||||
}
|
||||
|
||||
$query = FriendCircleModel::where('status', 1)
|
||||
->whereIn('user_id',$this->getFriendUserIds($current_user_id))
|
||||
@@ -86,16 +103,18 @@ class FriendCircleController extends BaseController{
|
||||
'list_rows' => $limit,
|
||||
'page' => $page,
|
||||
]);
|
||||
cache('circle_last_read_id',$list[0]['id']);
|
||||
if(!$user_id){
|
||||
cache('circle_last_read_id_'.$current_user_id,$list[0]['id']);
|
||||
}
|
||||
|
||||
|
||||
// 处理每条朋友圈数据
|
||||
$items = $list->items();
|
||||
$list->each(function($item) use ($current_user_id){
|
||||
// 获取点赞列表
|
||||
$likes = Db::name('friend_circle')->alias('f')
|
||||
$likes = Db::name('friend_circle_like')->alias('f')
|
||||
->join('user u','u.id=f.user_id')
|
||||
->where('f.id', $item->id)
|
||||
->where('f.circle_id', $item->id)
|
||||
->field('f.*,u.avatar,u.nickname')
|
||||
->order('f.created_at', 'desc')
|
||||
->limit(20)
|
||||
@@ -182,11 +201,11 @@ class FriendCircleController extends BaseController{
|
||||
if (!$user) {
|
||||
return $this->fail('请先登录');
|
||||
}
|
||||
|
||||
$circle_last_read_id = cache('circle_last_read_id') ?: 0;
|
||||
$user_id = $user->id;
|
||||
$circle_last_read_id = cache('circle_last_read_id_'.$user_id) ?: 0;
|
||||
// 统计从上次查看时间到现在新增的朋友圈数量
|
||||
$unread_item_ids = FriendCircleModel::where('status', 1)
|
||||
->whereIn('user_id',$this->getFriendUserIds($user->id))
|
||||
->whereIn('user_id',$this->getFriendUserIds($user_id))
|
||||
->where('id', '>', $circle_last_read_id)
|
||||
->order('id', 'desc')
|
||||
->column('id');
|
||||
@@ -250,7 +269,7 @@ class FriendCircleController extends BaseController{
|
||||
'status' => 1,
|
||||
]);
|
||||
|
||||
return $this->success('发布成功', ['id' => $circle->id]);
|
||||
return $this->success('发布成功', ['id' => $circle->id,'data' => $circle]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -371,15 +390,56 @@ class FriendCircleController extends BaseController{
|
||||
if (!$user_id) {
|
||||
return [];
|
||||
}
|
||||
$result = cache('friend_id_list') ?: [];
|
||||
$cache_key = 'friend_id_list_'.$user_id;
|
||||
$result = cache($cache_key) ?: [];
|
||||
if(count($result) === 0){
|
||||
$res = request()->IM->friend->getFriendList($user_id.'');
|
||||
$res = request()->IM->friend->getFriendList(idEncode($user_id));
|
||||
$friendsInfo = $res['friendsInfo'];
|
||||
foreach($friendsInfo as $k=>$v){
|
||||
array_push($result,$v['friendUser']['userID']);
|
||||
}
|
||||
cache('friend_id_list',$result,3600);
|
||||
cache($cache_key,$result,3600);
|
||||
}
|
||||
$result[] = $user_id;
|
||||
return $result;
|
||||
}
|
||||
function delete(Request $request): Response{
|
||||
$id = $request->post('id');
|
||||
$user = \support\Jwt::getUser();
|
||||
if (!$user) {
|
||||
return $this->fail('请先登录');
|
||||
}
|
||||
if($id){
|
||||
FriendCircleModel::where('id',$id)->where('user_id',$user->id)->delete();
|
||||
}
|
||||
return $this->success('删除成功');
|
||||
}
|
||||
|
||||
function upload_bg(Request $request){
|
||||
try {
|
||||
$user = \support\Jwt::getUser();
|
||||
if (!$user) {
|
||||
return $this->fail('请先登录');
|
||||
}
|
||||
$res = $this->_upload($request);
|
||||
if(is_string($res)){
|
||||
return $this->fail( $res);
|
||||
}
|
||||
|
||||
Db::name('friend_circle_setting')->replace()->insert([
|
||||
'user_id' => $user->id,
|
||||
'bg' => $res[0]['file_name'],
|
||||
'allow_days'=>0,
|
||||
'created_at'=>0
|
||||
]);
|
||||
//$result->ss = cdnurl($result->url);
|
||||
//P($result);
|
||||
return $this->success(__('successful'),[
|
||||
'url'=>$res[0]['file_name']
|
||||
]);
|
||||
}catch (\Exception $e){
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user