<?php
/**
 *
 *User:Administrator
 *Date:2021/10/13
 */

namespace app\api\model;

use think\Model;

class Undertake extends Model
{
    public function insert(array $data = [], bool $getLastInsID = false)
    {
        return parent::insert($data, $getLastInsID); // TODO: Change the autogenerated stub
    }

    public function deleteInfoByID($id_arr)
    {
        return $this->select($id_arr)->delete();
    }


    public function selectUndertakeInfoByTaskIdAndUnitId($task_id,$unit_id='',$bear_id='',$report_id='',$pageNum=1,$pageSize=null)
    {
        $where=[
            ['task_id', '=', $task_id],
        ];

        if ($unit_id!='') {
            array_push($where, ['unit_id', '=', $unit_id]);
        }
        if ($bear_id!='') {
            array_push($where, ['bear_id', '=', $bear_id]);
        }
        if ($report_id!='') {
            array_push($where,['report_id', '=', $report_id]);

        }
        return $this->where($where)->page($pageNum,$pageSize)->select();
    }

    public function countUndertakeInfoByTaskIdAndUnitId($task_id,$unit_id='',$bear_id='',$report_id='')
    {
        $where=[
            ['task_id', '=', $task_id],
        ];

        if ($unit_id != '') {
            array_push($where, ['unit_id', '=', $unit_id]);
        }
        if ($bear_id != '') {
            array_push($where, ['bear_id', '=', $bear_id]);
        }
        if ($report_id != '') {
            array_push($where,['report_id', '=', $report_id]);

        }
        return $this->where($where)->count();
    }

}