数据自处理-模糊搜索与tab筛选
关于搜索功能和tab功能筛选数据,单独自己数据匹配,相比较之前写的搜索功能都是利用laravel或tp中自带的自己从数据库模糊匹配的方式,而在ci中得自己去渲染匹配数据;
tab筛选的话,传过来的参数为"aa.bb.cc"格式 而后端每条数据也都是"aa.bb.cc"格式 有一个匹配则保留,其实就是取这两个字段的交集部分;
// 搜索系列活动
private function _search_serials_some($data)
{
#如果参数包含5和0则不返回
if(isset($data["material_type"]) && !empty($data["material_type"])){
$material = explode(",",$data["material_type"]);
$res = array_intersect([5,0],$material);
if(empty($res)) return [];
}
#未搜索则返回空数组
$kw = $data["keyword"];
if($kw == '') return [];
#获取数据源 0:全部课程 1:特色课 2:专项课 3 :延时班 4.整合活动
$data["classify"] = $data["classify"]==0?"":$data["classify"];
$where = "&select=&classify=" . $data['classify'];
$allPacks = $this->_getSomeAllPacks($where);
$buySerialIds = $this->get_buy_series($data['user']['client']);#查询园所购买系列详情
if(empty($allPacks)) return [];
#数据匹配
$out = array();
foreach($allPacks as $pack){
#type = 2为不开放类型::如果没有购买开不开放系列则跳过
if (($pack['type'] == 2) && !in_array($pack['pack_id'], $buySerialIds['buySerials'])) {
continue;
}
#关键词不匹配的跳过
if (strstr($pack['title'], $kw) == false) {
continue;
}
#筛选词不匹配跳过
if(!empty($data["tags"])){
$tags = explode(",",$data["tags"]);
//如果数据表没有设置当前数据标签,则当做不匹配跳过
if(!isset($pack["tags"]) || empty($pack["tags"])) continue;
$stags = explode(",",$pack["tags"]);
$arr = array_intersect($tags,$stags);//有交集则关联 无交集则空数组
if(empty($arr)) continue;
}
$class = array();
$themes = json_decode($pack['theme_setting'], true);
if (!empty($themes['age4']['theme'])) {
$class[] = '16';
}
if (!empty($themes['age5']['theme'])) {
$class[] = '32';
}
if (!empty($themes['age6']['theme'])) {
$class[] = '64';
}
$pack['class'] = $class;
$pack['project'] = $pack['pack_id'];
unset($pack['theme_setting']);
$out[] = $pack;
}
return $out;
}