1. 程式人生 > >thinkphp檢視查詢

thinkphp檢視查詢

折騰了很糾結...

$map = array();

        //獲取公司cid
        $map['Staff_salary.cid'] = $params['cid'];

        $status = trim($request->post('status'));
        if(!empty($status)){
            $map['Staff_salary.status'] = $status;
        }

        $deptid = trim($request->post('deptid')); //部門
        if (!empty($deptid)) {
            $map['Staff_salary.deptid'] = $deptid;
        }

        $postid = trim($request->post('postid')); //崗位
        if (!empty($postid)) {
            $map['Staff_salary.postid'] = $postid;
        }

        //入職的區間查詢 就是說在此期間的日期入職就行
        $startime = trim($request->post('startime'));
        $endtime = trim($request->post('endtime'));
        if ($startime && $endtime) {
            $map['Staff_salary.start_time'] = ['between', [$startime, $endtime]];
        }elseif($startime){
            $map['Staff_salary.start_time'] = ['egt', $startime];
        }elseif($endtime){
            $map['Staff_salary.start_time'] = ['elt', $endtime];
        }

        $likedata = trim($request->post('search_val')); //員工姓名,工號,手機號
        if (!empty($likedata)) {
            //$map['Staff.zname|Staff.staff_num|Staff.mobile|Staff.zpinyin|Staff.zpy'] = ['like', '%'.$likedata.'%']; //封裝模糊查詢 賦值到陣列
            $map['Staff.zname|Staff.staff_num|Staff.mobile|Staff.zpinyin|Staff.zpy'] = ['like', '%'.$likedata.'%'];
        }   

        $said = trim($request->post('said'));
        if(!empty($said)){
            $map['said'] = $said;
        }

         $rel = db::view('Staff_salary','*')
            ->view('Company_dept','deptid,deptname','Company_dept.deptid = Staff_salary.deptid','LEFT')
            ->view('Company_postion','postid,postname','Company_postion.postid = Staff_salary.postid','LEFT')
            ->view('Staff','sid,zname,staff_num,zpinyin,zpy','Staff.sid =Staff_salary.sid','LEFT')
            ->where($map)
            ->paginate(10, false, ['type' => 'Ajaxbootstrap']);
 

  預設的檢視查詢 用的inner方式 所以不需要查詢條件不需要指定條件,但是用LEFT 和 RIGHT 就需要了....