<?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 selectByTaskIdAndWhere($task_id, $where='',$pageNum=1,$pageSize=null)
    {
        if ($task_id == '' || $where == '') {
            return false;
        }
        return $this->where([
            ['task_id', '=', $task_id],
            [$where]
        ])
            ->page($pageNum,$pageSize)
            ->select();
    }

    //获取抽样任务列表数量
    public function countByTaskIdAndWhere($task_id, $where='')
    {
        if ($task_id == '' || $where == '') {
            return false;
        }
        return $this->where([
            ['task_id', '=', $task_id],
            [$where]
        ])
            ->count();
    }


    public function selectTaskListByTaskIdAndUid($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 countTaskListByTaskIdAndUid($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();
    }

    public function getItemByUndertakeId($undertake_id)
    {
        return $this->where('id','=',$undertake_id)->find();
    }

}