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

namespace app\api\model;

use think\Model;

class Cyd extends Model
{
    function production()
    {
        return $this->belongsTo('production', 'product_unit','id');
    }

    function unitsTest()
    {
        return $this->belongsTo('unitsTest', 'units_id', 'id');
    }


    public function selectSampleListByTaskIdAndUid($where,$pageNum=1,$pageSize=null)
    {
        $cyd = (new Cyd());
        $data = $cyd->with(['Production', 'UnitsTest'])->where($where)->page($pageNum,$pageSize)->select();
        return $data;
    }
    public function countSampleListByTaskIdAndUid($where)
    {
        $cyd = (new Cyd());
        $count = $cyd->with(['Production', 'UnitsTest'])->where($where)->count();
        return $count;
    }

    public function createSample($cyd_data)
    {
        $result = $this->insertGetId($cyd_data);
        return $result;
    }

    public function updateCydDataByID($id, $data)
    {
        $result = $this->where('id','=',$id)->save($data);
        return $result;
    }


    //用于生成抽样单编号的
    public function countSampleCreateID()
    {
        return $this->whereDay('createtime','today')->count();
    }
}