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

namespace app\api\controller\v1;

use app\api\business\CydBus;
use app\api\business\SampleBus;
use think\exception\ValidateException;

class Cyd
{
    //监管端获取抽样单列表
    public function getCydList()
    {
        $task_id = request()->param('task_id', '', 'int');
//        try {
//            validate(\app\api\validate\Sample::class)->scene('get_cyd_list')->check($task_id);
//        } catch (ValidateException $exception) {
//            return show(config('status.err_validate'),$exception->getError());
//        }

        $result = (new CydBus())->getCydList($task_id);
//        if ($result['total'] == 0) {
//            return showError(config('status.none_cyd_info'));
//        }
        return showSuccess($result);
    }


    public function getCydDetail()
    {
        $sample_id = request()->param('sample_id', '', 'trim');
        $result = (new SampleBus())->getCydDetail($sample_id);
        return showSuccess($result);
    }

    public function upCydItem()
    {
        $sample_id = request()->param('sample_id', '', 'trim');
        $result = (new CydBus())->upCydItem($sample_id);
        //返回一个undertake_id，前端要用这个刷新页面
        $undertake_id = (new CydBus())->getCydItemBySampleId($sample_id);
        return showSuccess($undertake_id['undertake_id']);
    }

    public function getJgCydList()
    {
        $data = [
            'task_id' => request()->param('task_id', '', 'int'),//任务id
            'unit_id' => request()->param('unit_id', '', 'int'),//牵头单位id
        ];
        $page=[
            'pageNum' => request()->param('pageNum', 1, 'int'),
            'pageSize' => request()->param('pageSize', null, 'int'),

        ];
        $result = (new CydBus())->getCydByTaskIdAndUnitId($data,$page);
        return showSuccess($result);

    }


}