course/app/common/service/ChatFriendService.php

45 lines
1.1 KiB
PHP

<?php
namespace app\common\service;
use app\common\model\ChatFriend;
use app\constant\ResponseCode;
use think\Exception;
class ChatFriendService
{
/**
* @desc 获取聊天朋友
* @param $request
* @return array
*/
public function getFriends($request)
{
try {
$data = $request->get();
$chat_friend = ChatFriend::where(['user_id' => $request->user->id])->with(['friend', 'photographer'])->order('latest_chat_time desc, id desc');
$page = isset($data['page']) ? $data['page'] : 1;
$limit = isset($data['limit']) ? $data['limit'] : 10;
$total = $chat_friend->count();
$list = $chat_friend->page($page, $limit)->select();
return [
'code' => ResponseCode::SUCCESS,
'data' => [
'list' => $list,
'total' => $total,
'page' => $page
]
];
} catch (Exception $e) {
return [
'code' => ResponseCode::FAIL,
'msg' => $e->getMessage()
];
}
}
}