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

namespace app\api\controller\v1;

use app\api\business\SampleBus;

class Sample
{

    public function selectSampleList()
    {
        $data=[
            'pageNum' => request()->param('pageNum',1,'int'),//页码
            'pageSize' => request()->param('pageSize',10,'int'),//每页显示数量
            'task_id' => request()->param('task_id',null,'int'),//任务id
            'undertake_id' => request()->param('undertake_id', null, 'int'),//当前任务对应的承担信息，在undertake表中的id

//注释掉的是原来的搜索功能
//            'sample_name' => request()->param('sample_name','','trim'),//样品名称
//            'sample_id' => request()->param('sample_id','','trim'),//样品编码
//            'unit_test_name' => request()->param('unit_test_name','','trim'),//受检单位
//            'unit_sample_name' => request()->param('unit_sample_name','','trim'),//抽样单位
//            'unit_production_name' => request()->param('unit_production_name', '', 'trim'),//生产单位
//            'sample_data' => request()->param('sample_data','','trim'),//抽样日期
//            'sample_ground' => request()->param('sample_ground','','trim'),//抽样场所
        ];

        $result = (new SampleBus())->selectSampleList($data);
        return showSuccess($result);
    }

    public function getSampleObj()
    {
        $data =[
            'task_id' => request()->param('task_id', '', 'int'),
            'undertake_id'=>request()->param('undertake_id','','int')
        ];
        $task_id = request()->param('task_id','','int');
        $under_task_id = request()->param('undertake_id', '', 'int');

        if ($data['task_id'] == '' || $data['undertake_id'] == '') {
            return showError(config('status.none_valid_data'));
        }

        $result = (new SampleBus())->getSampleObj($data);
        return showSuccess($result);
    }

    public function createSampleId()
    {
        $task_id = request()->param('task_id', '', 'int');
        $result = (new SampleBus())->createSampleId($task_id);
        return showSuccess($result);
    }

    public function createSample()
    {

        //受检单位信息
        $unit_test = [
            'unit_test_name' => request()->param('unit_test.unit_name','','trim'),//单位名称
            'address' => request()->param('unit_test.address'),//通讯地址
            'represent_name' => request()->param('unit_test.represent_name','','trim'),//法定代表人
            'user_name' => request()->param('unit_test.user_name','','trim'),//*受检人
            'phone' => request()->param('unit_test.phone','','trim'),//电话
            'fax' => request()->param('unit_test.fax','','trim'),//传真
        ];

        //生产单位信息
        $unit_production = [
            'unit_production_name' =>request()->param('unit_production.production_name','','trim'),//单位名称
            'address' =>request()->param('unit_production.address','','trim'),//通讯地址
            'postcode' =>request()->param('unit_production.postcode','','trim'),//邮编
            'user_name' =>request()->param('unit_production.user_name','','trim'),//联系人
            'phone' =>request()->param('unit_production.phone','','trim'),//电话
            'fax' =>request()->param('unit_production.fax','','trim'),//传真
            'production_class' =>request()->param('unit_production.production_class','','trim'),//生产方式
        ];

        //抽样单位信息
        $unit_sample = [
            'unit_sample_name' => request()->param('unit_sample.unit_name','','trim'),//单位名称
            'unit_user' => request()->param('unit_sample.unit_user','','trim'),//联系人
            'address' => request()->param('unit_sample.address','','trim'),//通讯地址
            'postcode' => request()->param('unit_sample.postcode','','trim'),//邮编
            'phone' => request()->param('unit_sample.phone','','trim'),//联系电话
            'fax' => request()->param('unit_sample.fax','','trim'),//传真
            'email' => request()->param('unit_sample.email','','trim'),//Email
        ];

        //抽样单cyd信息
        $cyd_data = [
            'undertake_id' => request()->param('cyd_data.undertake_id', '', 'trim'),//抽样单对应的undertake表单的id
            'sample_id' => request()->param('cyd_data.sample_id','','trim'),//抽样单的id///todo
            'task_id' => request()->param('cyd_data.task_id','','trim'),//关联任务id todo
            'test_id' => request()->param('test_id','','trim'),//检测单位id----todo 未赋值

//            'units_id' => request()->param('units_id','','trim'),//受检单位id---在business中赋值
//            'product_unit' => request()->param('product_unit','','trim'),//生产单位id---在business中赋值
//            'sample_unit' => request()->param('sample_unit','','trim'),//抽样单位id---在business中赋值

            'sample_name' => request()->param('cyd_data.sample_name','','trim'),//样品名称
            'brand' => request()->param('cyd_data.brand','','trim'),//商标
            'ispack' => request()->param('cyd_data.ispack','','trim'),//包装
            'type' => request()->param('cyd_data.type','','trim'),//型号规格
            'standard' => request()->param('cyd_data.standard','','trim'),//执行标准
            'production_date' => request()->param('cyd_data.production_date','','trim'),//生产日期或批号
            'place' => request()->param('cyd_data.place','','trim'),//	产地
            'certicfie' => request()->param('cyd_data.certicfie','','trim'),//*产品认证情况
            'certifie_num' => request()->param('cyd_data.certifie_num','','trim'),//证书编号
            'sample_num' => request()->param('cyd_data.sample_num','','trim'),//*抽样数量
            'sample_num_unit' => request()->param('cyd_data.sample_num_unit','','trim'),//*抽样数量单位
            'sample_base' => request()->param('cyd_data.sample_base','','trim'),//抽样基数
            'sample_base_unit' => request()->param('cyd_data.sample_base_unit','','trim'),//抽样基数单位
            'sample_ground' => request()->param('cyd_data.sample_ground','','trim'),//*抽样场所
            'base' => request()->param('cyd_data.base', '', 'trim'),//检测任务依据
            'sample_date'=>request()->param('cyd_data.sample_date','','trim'),//抽样时间
            'file_name' => request()->param('cyd_data.file_name','','trim'),//文件名
            'file_url' => request()->param('cyd_data.file_url','','trim'),//文件链接
        ];

        $result = (new SampleBus())->createSample($unit_test, $unit_production, $unit_sample, $cyd_data);
        return showSuccess($result);
    }

}