71 lines
2.0 KiB
PHP
71 lines
2.0 KiB
PHP
<?php
|
|
namespace app\cunkebao\controller\friend;
|
|
|
|
use app\common\model\Device as DeviceModel;
|
|
use app\common\model\DeviceUser as DeviceUserModel;
|
|
use app\common\model\WechatFriend;
|
|
use app\cunkebao\controller\BaseController;
|
|
|
|
/**
|
|
* 设备管理控制器
|
|
*/
|
|
class GetFriendListV1Controller extends BaseController
|
|
{
|
|
|
|
|
|
/**
|
|
* 获取好友列表
|
|
* @return \think\response\Json
|
|
*/
|
|
public function index()
|
|
{
|
|
$page = $this->request->param('page',1);
|
|
$limit = $this->request->param('limit',20);
|
|
$keyword = $this->request->param('keyword','');
|
|
try {
|
|
|
|
$where = [];
|
|
if ($this->getUserInfo('isAdmin') == 1) {
|
|
$where['wf.companyId'] = $this->getUserInfo('companyId');
|
|
$where['wf.deleteTime'] = 0;
|
|
} else {
|
|
$where['wf.companyId'] = $this->getUserInfo('companyId');
|
|
$where['wf.deleteTime'] = 0;
|
|
//$where['userId'] = $this->getUserInfo('id');
|
|
}
|
|
|
|
|
|
|
|
if($keyword){
|
|
$where['wa1.nickname'] = ['like','%'.$keyword.'%'];
|
|
}
|
|
|
|
|
|
$data = WechatFriend::alias('wf')
|
|
->field(['wa1.nickname','wa1.avatar','wa1.alias','wf.wechatId','wa2.nickname as ownerNickname','wa2.alias as ownerAlias','wa2.wechatId as ownerWechatId','wf.createTime'])
|
|
->Join('wechat_account wa1','wf.wechatId = wa1.wechatId')
|
|
->Join('wechat_account wa2','wf.ownerWechatId = wa2.wechatId')
|
|
->where($where);
|
|
|
|
$total = $data->count();
|
|
$list = $data->page($page, $limit)->select();
|
|
|
|
|
|
|
|
|
|
return json([
|
|
'code' => 200,
|
|
'msg' => '获取成功',
|
|
'data' => [
|
|
'list' => $list,
|
|
'total' => $total,
|
|
]
|
|
]);
|
|
} catch (\Exception $e) {
|
|
return json([
|
|
'code' => $e->getCode(),
|
|
'msg' => $e->getMessage()
|
|
]);
|
|
}
|
|
}
|
|
}
|