亿垚科技 -model - advert
// advert 广告表
// machine 机器表
public function getAllAdvert($sort='3',$num = 10 ,$status='',$address='')
{
if (!empty($searchKey) && !empty($searchData)){
$res = $this->withSearch($searchKey , $searchData);
}else{
$res = $this;
}
$where = [
'sort' => $sort
];
$order = [
'nkey' => 'desc',
'id' => 'desc',
];
if (!empty($address)){
//$whereAddress[] 方括号是重点 产生(address like %$address% OR address like %$address%)
$whereAddress[] = ['address|webpositionlist', 'like' ,'%'.$address.'%'];
}
if (!empty($status)){
$where+=['advert.status' => $status]; //多表查询,相同字段,加上表名
}
$list = $res->withJoin('machine')->where($where)->where($whereAddress)->order($order)->paginate($num);
return $list;
}
/**
* 关联
* @return \think\model\relation\HasMany
*/
public function machine()
{
return $this->hasOne(Machine::class ,'id','Eid');
}