<?php

namespace app\api\controller\v1;

use app\api\business\CydBus;
use app\api\business\JcdBus;

class Jcd
{

    //获取检测单列表
    public function getJcdList()
    {
        $data = [
            'pageNum' => request()->param('pageNum', 1, 'int'),
            'pageSize' => request()->param('pageSize', null, 'int'),
            'undertake_id' => request()->param('underTake_id',null, 'int'),//当前的选中项的undertake_id,在数据库cyd中的undertake_id，undertake的id
        ];

        $result = (new JcdBus())->getJcdList($data);
        return showSuccess($result);
    }

    //填报检测单
    public function getJcdObjectItem()
    {
        $data = [
            'sample_id' => request()->param('sample_id', '', 'trim'),
        ];
        $result = (new JcdBus())->getJcdObjectItem($data['sample_id']);
        return showSuccess($result);
    }

    //上报检测单--是修改cyd中的test_status，0表示未检测，1表示已检测
    public function upJcdItem()
    {
        $sample_id = request()->param('sample_id', '', 'trim');
        $result = (new JcdBus())->upJcdItem($sample_id);
        //返回一个undertake_id，前端要用这个刷新页面
        $undertake_id = (new CydBus())->getCydItemBySampleId($sample_id);
        return showSuccess($undertake_id['undertake_id']);
    }

    //保存检测单
    public function saveJcdItem()
    {
        $sample_id = request()->param('sample_id', '', 'trim');
        $pesticides = request()->param('pesticides', '', 'trim');


        $result = (new JcdBus())->saveJcdItem($sample_id, $pesticides);
        return showSuccess($result);
    }

    //生成检测报告单(这是报告单下面的数据）
    public function createTestValue(){

        $sample_id = request()->param('sample_id', '', 'trim');
        $result = (new JcdBus())->createTestValue($sample_id);
        return showSuccess($result);

    }
}