<?php
namespace app\api\model;

use think\facade\Db;
use think\Model;

/**
 * Created by PhpStorm
 * Author: ihavoc
 * Date: 2020/11/22
 * Time: 16:24
 *
 */
class Orgs extends Model {

    protected $table = 't_orgs';
    protected $pk = 'id';



    //添加任务 返回添加数据的主键id
    public function createOrgsInfo($data)
    {
        return $this->insertAll($data);
    }

    //连表查询对应的ccjc信息
    public function selectCcjcData($where,$pageNum=1,$pageSize=10)
    {        //todo 模型我写不出来，只能用db了
        $result= Db::name("orgs")
            ->join('t_ccjc','t_orgs.task_id=t_ccjc.id')
            ->where($where)
            ->page((int)$pageNum,(int)$pageSize)
            ->select();
        return $result;
    }
    public function countCcjcData($where)
    {        //todo 模型我写不出来，只能用db了
        $result= Db::name("orgs")
            ->Join('t_ccjc','t_orgs.task_id=t_ccjc.id')
            ->where($where)
            ->count();
        return $result;
    }

    public function getUnitIdByTaskID($task_id)
    {
        if (empty($task_id)) {
            return false;
        }
        return $this->where('task_id', '=', $task_id)->find();
    }

}