作者 Cool
1 个管道 的构建 通过 耗费 11 秒

公共搜索接口开发

... ... @@ -71,6 +71,140 @@ class Index extends Api
}
/**
* @ApiTitle (公共搜索接口)
* @ApiSummary (公共搜索接口)
* @ApiMethod (POST)
* @ApiRoute (/api/index/common_search)
*
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="keyword", type="string", required=false, description="关键字")
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1571492001",
"data": {
"times": //时间,
"info": [
{
"id": //文件夹id,
"url": //分享地址
"user_id": //用户id,
"folder_name": //文件夹名称,
"is_open": //是否公开1公开2私密
"is_up": //1上架2下架
"createtime": //日期,
"is_have": //是否有转存文件1有2没有
"nowtime": //文件创建时间
}
]
}
})
*/
public function common_search()
{
$user_id = $this->auth->id;
$where = [];
$keyword = $this->request->param('keyword');
if(empty($keyword)){
$this->error('请输入搜索内容');
}
$where_folder['folder_name'] = ['like',"%$keyword%"];
// 文件夹
$arrs = Db::name('folder')
->field('updatetime,pid',true)
->where('user_id',$user_id)
->where('pid',0)
->where($where_folder)
->order('is_up asc')
->select();
$tree = Tree::instance();
$tree->init(Db::name('folder')->select(), 'pid');
foreach ($arrs as &$v){
$list = $tree->getChildrenIds($v['id'],true);
$is_have = Db::name('rotor')
->where('user_id',$user_id)
->whereIn('folder_id',$list)
->find();
if(empty($is_have)){
$v['is_have'] = 2;
}else{
$v['is_have'] = 1;
}
$v['nowtime'] = date('Y-m-d',$v['createtime']);
$v['createtime'] = date('m-d',$v['createtime']);
}
// $arrs = array_values(array_unique(array_column($data,'createtime')));
// rsort($arrs);
// //将数据放到对应的时间分段
// $arrs = [];
// foreach ($times as $t_k=> $t_v){
// $arrs[$t_k]['times'] = $t_v;
// $k = 0;
// foreach ($data as $value){
// $k+=0;
// if($t_v == $value['createtime']){
// $arrs[$t_k]['info'][$k] = $value;
// $k++;
// }
// }
// }
// 笔记、图片、视频
//判断是否有关键字搜索
$where['name'] = ['like',"%$keyword%"];
$tiao['b.name'] = ['like',"%$keyword%"];
$history = Db::name('keyword')->where('user_id',$user_id)->where('keyword',$keyword)->find();
if(empty($history)){
//添加历史记录表
$tiao['b.name'] = ['like',"%$keyword%"];
$key['user_id'] = $user_id;
$key['keyword'] = $keyword;
$key['createtime'] = time();
$key['updatetime'] = time();
Db::name('keyword')->insertGetId($key);
}
//判断是否为全部还是 已上架/已下架
$tiao['b.is_up'] = ['eq',1];
$where['user_id'] = $user_id;
$where['folder_id'] = 0;
$tiao['a.folder_id'] = 0;
$tiao['a.user_id'] = $user_id;
//自己的笔记文件
$note = $this->myfile(1,$where);
//自己的图片文件
$pic = $this->myfile(2,$where);
//自己的视频文件
$video = $this->myfile(3,$where);
//转存的笔记文件
$rotor = $this->zhuan(1,$tiao);
//转存的图片文件
$rotor_pic = $this->zhuan(2,$tiao);
//转存的视频文件
$rotor_video = $this->zhuan(3,$tiao);
//笔记
$arr = $this->gong(1,$note,$rotor);
//图片
$arr_pic = $this->gong(2,$pic,$rotor_pic);
//视频
$arr_video = $this->gong(3,$video,$rotor_video);
$return = [
'folder' => $arrs,
'note' => $arr,
'pic' => $arr_pic,
'video' => $arr_video
];
$this->success('success',$return);
}
/**
* @ApiTitle (我的文件夹)
... ...
此 diff 太大无法显示。