您当前的位置: 首页 > 

苗先生的PHP记录

暂无认证

  • 0浏览

    0关注

    190博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

多表查询 ,with ,多字段查询某字段的like操作

苗先生的PHP记录 发布时间:2020-08-06 16:59:34 ,浏览量:0

亿垚科技 -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');
    }
关注
打赏
1665468453
查看更多评论
立即登录/注册

微信扫码登录

0.0431s