public function search ()
{
// if(request()->isPost()){
//获取输入的类别
$where=[];
$where1=[];
$sousuo=input('sousuo');
// var_dump($sousuo);
$where['name']=['like',"%$sousuo"];
$where1['name']=['like',"$sousuo%"];
$sql=db('goodstype')->where($where)->whereOr($where1)->column('id');
// var_dump($sql);
//根据类别查商品
if($sql){
$isok=db('goodsadd')->where('tid','in',$sql)->order('id desc')->paginate(12, false, ['query' => ['sousuo' => $sousuo]])->each(function($items,$key){
$items['imgs'] = explode(',',$items['imgs']); //用逗号把字符转换为数组
return $items;
});
// var_dump($isok);
$this->assign('isok',$isok);
}else{
//查询商品名称
$where=[];
$where1=[];
$where['title']=['like',"%$sousuo"];
$where1['title']=['like',"$sousuo%"];
$where['shorttitle']=['like',"%$sousuo"];
$where1['shorttitle']=['like',"$sousuo%"];
$isok=db('goodsadd')->where($where)->whereOr($where1)->order('id desc')->paginate(12, false, ['query' => ['sousuo' => $sousuo]])->each(function($items,$key){
$items['imgs'] = explode(',',$items['imgs']);
return $items;
});;
// var_dump($isok);
$this->assign('isok',$isok);
}
$aa=$isok->render();
$this->assign('aa',$aa);
$this->assign('sousuo',$sousuo);
// }