作者 jinglong
1 个管道 的构建 通过 耗费 2 秒

增加搜索产品列表

... ... @@ -57,4 +57,16 @@ return array (
'page.number' => '分页页码必须是数字',
]
],
//产品系列搜索
'search' => [
'rule' => [
'keyword' => 'require',
'page' => 'require|number',
],
'msg' => [
'keyword.require' => '关键字不能为空',
'page.require' => '分页页码不能为空',
'page.number' => '分页页码必须是数字',
]
],
);
\ No newline at end of file
... ...
... ... @@ -9,6 +9,8 @@
namespace api\home\controller;
use cmf\controller\RestBaseController;
use think\Db;
use think\Validate;
/**
* @title 首页
*/
... ... @@ -110,4 +112,54 @@ class IndexController extends RestBaseController
$this->success('成功',$arr);
}
/**
* @title 搜索产品系列(若没有数据提示:暂无数据,请联系客服)
* @description 接口说明
* @author 开发者
* @url /api/home/index/searchSeriesList
* @method GET
*
* @param name:language type:string require:0 default: other desc:语言切换(英文传递此字段(en),中文无需传递)
* @param name:keyword type:string require:1 default: other desc:关键字
* @param name:page type:inter require:1 default: other desc:分页页码
*
* @return data:产品系列列表@
* @data id:产品系列id thumbnail:图片路径 title:系列名称
*
* @return count_page:总页码
*/
public function searchSeriesList(){
$language = $this->request->param('language');
$keyword = $this->request->param('keyword');
$page = $this->request->param('page');//分页
//验证
$rule = config('site.search');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check(['keyword'=>$keyword,'page'=>$page])) {
$this->error($validate->getError());
}
if(isset($language) && !empty($language)){
//英文
$field_series = 'id,thumbnail,title_en title';
$where = ['title_en'=>['like','%'.$keyword.'%']];
}else{
//中文
$field_series = 'id,thumbnail,title';
$where = ['title'=>['like','%'.$keyword.'%']];
}
//查找二级分类
$limit = CommonController::series_limit;
$res = Db::name('series')
->where($where);
$data = $res->field($field_series)
->page($page,$limit)
->order('id desc')
->select()
->toArray();
$count = $res->count()/$limit;
$count_page = ceil($count/$limit);
$this->success('成功',['data'=>$data,'count_page'=>$count_page]);
}
}
... ...