Browse Source

冲突解决

曹鹤洋 1 year ago
parent
commit
0753e9ddb2

+ 1554 - 0
application/api/controller/Facility.php

@@ -0,0 +1,1554 @@
+<?php
+
+namespace app\api\controller;
+
+
+use app\common\controller\Api;
+use think\Db;
+use think\Request;
+
+/**
+ * 设备运行跟踪
+ */
+
+class Facility extends Api
+{
+    protected $noNeedLogin = ['*'];
+    protected $noNeedRight = ['*'];
+
+
+    /**
+     * 左侧菜单栏
+     * @ApiMethod (GET)
+     * @return void
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+    public function getTab()
+    {
+        if ($this->request->isGet() === false){
+            $this->error('请求错误');
+        }
+        $data = [];
+        $date = date('Y-m-d 00:00:00',time()-3888000);
+        $department = \db('设备_基本资料')
+            ->distinct(true)
+            ->where('使用部门','<>','研发中心')
+            ->where('设备编组','<>','')
+            ->order('设备编组')
+            ->column('rtrim(使用部门) as 使用部门');
+        if (empty($department)){
+            $this->success('为获取到机台数据');
+        }
+        $list = \db('设备_产量计酬')
+            ->field([
+                'DISTINCT(sczl_rq)' => '时间',
+                'rtrim(sczl_jtbh)' => '机台编号'
+            ])
+            ->where('sczl_rq','>',$date)
+            ->cache(true,86400)
+            ->order('sczl_rq desc')
+            ->select();
+        if (empty($list)){
+            $this->success('未找到机台生产记录');
+        }
+        foreach ($department as $value){
+            $machine = \db('设备_基本资料')->where('使用部门',$value)->where('sys_sbID','<>','')->where('使用部门',$value)->field('rtrim(设备编号) as 设备编号,rtrim(设备名称) as 设备名称')->cache(true)->select();
+            foreach ($machine as $k=>$v){
+                $data[rtrim($value)][$v['设备编号'].'-->'.$v['设备名称']] = [];
+                foreach ($list as $kk=>$vv){
+                    if ($v['设备编号'] === $vv['机台编号']){
+                        array_push($data[rtrim($value)][$v['设备编号'].'-->'.$v['设备名称']],date('Y-m-d',strtotime($vv['时间'])));
+                    }
+                }
+            }
+        }
+        $this->success('成功',$data);
+    }
+
+
+    /**
+     * 机台每日产量
+     * @ApiMethod (GET)
+     * @param string $machine  机台编号
+     * @param string $date 日期
+     * @return void
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+    public function chanLiang()
+    {
+        if ($this->request->isGet() === false){
+            $this->error('请求错误');
+        }
+        $machine = input('machine');
+        $date = input('date');
+        $where = [
+            'sczl_jtbh' => $machine,
+            'sczl_rq' => date('Y-m-d H:i:s',strtotime($date.' 00:00:00')),
+        ];
+        $field = 'rtrim(sczl_gdbh) as 工单编号,rtrim(sczl_yjno) as yjno,rtrim(sczl_gxmc) as gxmc,rtrim(sczl_num) as num,rtrim(sczl_sj1) as sj1,
+        rtrim(sczl_sj2) as sj2,rtrim(sczl_cl) as 产量,rtrim(sczl_bzdh) as bzdh,rtrim(sczl_zcfp) as 制程废品,rtrim(sczl_zccp) as 制程次品,rtrim(sczl_前工序废) as 前工序废,rtrim(sczl_来料少数) as 来料异常,
+        rtrim(sczl_装版工时) as 装版工时,rtrim(sczl_保养工时) as 保养工时,rtrim(sczl_打样工时) as 打样工时,rtrim(sczl_异常停机工时) as 异常总工时,rtrim(sczl_设备运行工时) as 通电工时,
+        rtrim(码开始行) as 码开始行,rtrim(码结束行) as 码结束行,rtrim(码包) as 码包,rtrim(主电表) as 主电表,rtrim(辅电表) as 辅电表,rtrim(sczl_ms) as 色度数,
+        rtrim(sys_id) as 用户,rtrim(mod_rq) as 更新时间,rtrim(sczl_异常工时1) as 异常补时,rtrim(sczl_异常类型1) as 异常类型,sczl_bh1,sczl_bh2,
+        sczl_bh3,sczl_bh4,sczl_bh5,sczl_bh6,sczl_bh7,sczl_bh8,sczl_bh9,sczl_bh10,sczl_rate1,sczl_rate2,sczl_rate3,sczl_rate4,sczl_rate5,sczl_rate6,sczl_rate7,
+        sczl_rate8,sczl_rate9,sczl_rate10';
+        //机台信息
+        $machineDetail = \db('设备_基本资料')->where('设备编号',$machine)->field('rtrim(千件工价) as 千件工价,rtrim(日定额) as 日定额')->find();
+        //工单编号
+        $Gd_gdbh = \db('设备_产量计酬')->where($where)->distinct(true)->column('sczl_gdbh');
+        //产品名称
+        $productName = \db('工单_基本资料')->whereIn('Gd_gdbh',$Gd_gdbh)->field('rtrim(Gd_gdbh) as gdbh')->find();
+        //组员信息
+        $list = \db('设备_产量计酬')->where($where)->field($field)->cache(true,86400)->select();
+        $totalA = \db('设备_产量计酬')->where($where)->where('sczl_bzdh','A班')->field('SUM(sczl_cl) as 产量')->select();
+        $totalB = \db('设备_产量计酬')->where($where)->where('sczl_bzdh','B班')->field('SUM(sczl_cl) as 产量')->select();
+        if (empty($list)){
+            $this->success('',[]);
+        }
+        foreach ($list as $key=>$value){
+            $list[$key]['产品名称'] = $value['工单编号'].'---'.$productName['gdbh'];
+            if ($value['yjno']<10){
+                $list[$key]['yjno'] = '0'.$value['yjno'];
+            }
+            $list[$key]['工序'] = $list[$key]['yjno'].'-'.$list[$key]['gxmc'];
+            $list[$key]['备注'] = $value['bzdh'].'('.$value['num'].')'.date('H:i',strtotime($value['sj1'])).'<-->'.date('H:i',strtotime($value['sj2']));
+            $list[$key]['千件工价'] = $machineDetail['千件工价'];
+            $list[$key]['日定额'] = $machineDetail['日定额'];
+            for ($i=1;$i<11;$i++){
+                if (isset($value['sczl_bh'.$i])){
+                    $name = \db('人事_基本资料')->where('员工编号',$value['sczl_bh'.$i])->field('rtrim(员工姓名) as name')->find();
+                    if (isset($name['name'])){
+                        $list[$key]['组员'.$i] = $value['sczl_bh'.$i].$name['name'].'('.((float)$value['sczl_rate'.$i]*100).'%'.')';
+                    }
+                }
+                unset($list[$key]['sczl_bh'.$i],$list[$key]['sczl_rate'.$i]);
+            }
+            unset($list[$key]['工序编号'],$list[$key]['yjno'],$list[$key]['gxmc'],$list[$key]['num'],$list[$key]['sj1'],$list[$key]['sj2'],$list[$key]['bzdh']);
+        }
+        $list['totalA'] = $totalA[0]['产量'];
+        $list['totalB'] = $totalB[0]['产量'];
+        $this->success('成功',$list);
+    }
+
+    /**
+     * 当日制程检验记录
+     * @ApiMethod (GET)
+     * @param string $machine  机台编号
+     * @param string $date   日期
+     * @return void
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+    public function Inspect()
+    {
+        if ($this->request->isGet() === false){
+            $this->error('请求错误');
+        }
+        $machine = input('machine');
+        $date = input('date');
+        if (empty($machine) || empty($date)){
+            $this->error('参数错误');
+        }
+        $where = [
+            '设备编号' => $machine,
+            '开工时间' => ['between',[date('Y-m-d 08:00:00',strtotime($date)),date('Y-m-d 08:00:00',strtotime($date)+86400)]],
+            '类别' => ['in',['IPQC检验','机台检验']],
+        ];
+        $field = 'rtrim(工单编号) as 工单编号,rtrim(印件号) as 印件号,rtrim(工序名称) as 工序名称,提交时间,rtrim(检验项目) as 检验项目';
+        $list = \db('制程检验_记录')
+            ->where($where)
+            ->field($field)
+            ->select();
+        if (empty($list)){
+            $this->success('未找到检验记录');
+        }
+        $data = [];
+        foreach ($list as $key=>$value)
+        {
+            $data['item'][$key] = $value['检验项目'];
+            $data['InspectionTime'][$key] = date('H:i',strtotime($value['提交时间']));
+            $data['工单编号'][$key] = $value['工单编号'];
+        }
+        $data['item'] = array_unique($data['item']);
+        $data['InspectionTime'] = array_values(array_unique($data['InspectionTime']));
+        $data['工单编号'] = array_values(array_unique($data['工单编号']));
+        foreach ($data['工单编号'] as $key => $value){
+            foreach ($data['item'] as $k=>$v){
+                $time = '';
+                foreach ($list as $kk=>$vv){
+                    if ($vv['工单编号'] === $value && $vv['检验项目'] === $v){
+                        $time = $time.date('H:i',strtotime($vv['提交时间'])).',';
+                        $data['row'][$key][$k] = [
+                            '工单编号' => $value,
+                            '印件号' => $vv['印件号'],
+                            '工序名称' => $vv['工序名称'],
+                            '检验项目' => $v,
+                            'time' => substr($time,0,-1),
+                        ];
+                    }
+                }
+            }
+            $data['row'][$key] = array_values($data['row'][$key]);
+        }
+        unset($data['item'],$data['工单编号']);
+        $this->success('成功',$data);
+    }
+
+    /**
+     * 设备生产中工单信息
+     * @ApiMethod (GET)
+     * @param string $machine   机台编号
+     * @return void
+     * @throws \think\Exception
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+    public function Production()
+    {
+        if (Request::instance()->isGet() == false) {
+            $this->error('非法请求');
+        }
+        $params = Request::instance()->param();
+        if (!isset($params['machine']) || empty($params['machine'])) {
+            $this->error('参数错误');
+        }
+        $machine = $params['machine'];
+        $data = \db('设备_产量采集')->where('设备编号',$machine)->order('UniqId desc')->find();
+        $endTime = \db('工单_工艺资料')
+            ->where('Gy0_gdbh',$data['工单编号'])
+            ->where('Gy0_sbbh','like','%'.$machine.'%')
+            ->find();
+        $list = [];
+        if ($endTime['PD_WG'] === '1900-01-01 00:00:00'){
+            $list['工单编号'] = $data['工单编号'];
+            $list['印件号'] = $data['印件号'];
+            $name = \db('工单_基本资料')->where('Gd_Gdbh',$data['工单编号'])->value('成品名称');
+            $list['产品名称'] = rtrim($name);
+            $where['Gy0_gdbh'] = $data['工单编号'];
+            $where['Gy0_yjno'] = $data['印件号'];
+            $where['Gy0_gxh'] = $data['工序号'];
+            $gxmc = \db('工单_工艺资料')->where($where)->find();
+            if ((int)$gxmc['Gy0_gxh']<10){
+                $gxmc['Gy0_gxh'] = '0'.rtrim($gxmc['Gy0_gxh']);
+            }
+            if ($gxmc['Add_gxmc'] !== ''){
+                $printName = rtrim($gxmc['Gy0_gxh']).'-'.rtrim($gxmc['Gy0_gxmc']).'【'.rtrim($gxmc['Add_gxmc']).'】';
+            }else{
+                $printName = rtrim($gxmc['Gy0_gxh']).'-'.rtrim($gxmc['Gy0_gxmc']);
+            }
+            $list['工序名称'] = $printName;
+        }else{
+            $list['工单编号'] = '';
+            $list['印件号'] = 0;
+            $list['产品名称'] = '';
+            $list['工序名称'] = '';
+        }
+        $list['状态'] = rtrim($data['当前状态']);
+        $list['班组编号'] = rtrim($data['班组编号']);
+        $list['班组Id'] = rtrim($data['班组ID']);
+        $class = \db('设备_班组资料')->where('UniqId',$data['班组ID'])->field("rtrim(sczl_bh1) as bh1,rtrim(sczl_bh2) as bh2,rtrim(sczl_bh3) as bh3,rtrim(sczl_bh4) as bh4,
+        rtrim(sczl_bh5) as bh5,rtrim(sczl_bh6) as bh6,rtrim(sczl_bh7) as bh7,rtrim(sczl_bh8) as bh8,rtrim(sczl_bh9) as bh9,
+        rtrim(sczl_bh10) as bh10")->find();
+        $row = [];
+        for ($i=1;$i<11;$i++) {
+            if ($class['bh' . $i] != '' && $class['bh' . $i] != '000000') {
+                $name = \db('人事_基本资料')->where('员工编号', $class['bh' . $i])->field('rtrim(员工姓名) as 姓名')->find();
+                $row[$i] = [
+                    '编号' => $class['bh' . $i],
+                    '姓名' => $name['姓名']
+                ];
+            }
+        }
+        $row = array_values($row);
+        $list['班组成员'] = $row;
+        $this->success('成功',$list);
+    }
+
+    /**
+     * 设备工作清单
+     * @ApiMethod (GET)
+     * @param string $machine 机台编号
+     * @return void
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+
+    public function EquipmentWorklist()
+    {
+        if ($this->request->isGet() === false){
+            $this->error('请求错误');
+        }
+        $machine = input('machine');
+        if (empty($machine)){
+            $this->error('参数错误');
+        }
+        $sql = "SELECT
+                rtrim( b.Gy0_gdbh ) AS gdbh,
+                rtrim(b.质量要求) AS 质量信息,
+                rtrim( b.Gy0_yjno ) AS yjno,
+                rtrim( b.Gy0_gxh ) AS gxh,
+                rtrim( b.Gy0_gxmc ) AS gxmc,
+                rtrim( b.Add_gxmc ) AS add_gxmc,
+                rtrim( b.Gy0_辅助工时 ) AS 装版时数,
+                rtrim( b.Gy0_小时产能 ) AS 工序产能,
+                rtrim( b.Gy0_生产工时 ) AS 计划工时,
+                rtrim( b.Gy0_sj1 ) AS sj1,
+                rtrim( b.Gy0_sj2 ) AS sj2,
+                rtrim(b.工序备注) AS 排产备注,
+                RTRIM(d.yj_yjmc) AS 印件名称,
+                RTRIM(a.Gd_cpmc) AS 产品名称,
+                RTRIM(a.成品代号) AS 产品代号,
+                SUM(E.sczl_cl) AS 已完成,
+                rtrim(b.Gy0_计划接货数) AS 计划接货数,
+                RTRIM(b.Gy0_ls) AS ls 
+            FROM
+                `工单_基本资料` AS a
+                JOIN `工单_工艺资料` AS b ON a.Gd_gdbh = b.Gy0_gdbh
+                JOIN `产品_基本资料` AS c ON a.`成品代号` = c.`产品编号` 
+                JOIN `工单_印件资料` AS d ON a.Gd_gdbh = d.Yj_Gdbh
+                LEFT JOIN `设备_产量计酬` AS e ON e.sczl_gdbh = a.Gd_gdbh AND e.sczl_jtbh = b.Gy0_sbbh
+            WHERE
+                a.gd_statu = '2-生产中' 
+                AND a.`行号` = '1' 
+                AND b.Gy0_sbbh = '{$machine}' 
+                AND c.`状态` = '' 
+                AND b.PD_WG = '1900-01-01 00:00:00' 
+                AND b.Gy0_sj1 <> '1900-01-01 00:00:00'
+            GROUP BY a.Gd_gdbh
+            ORDER BY b.Gy0_sj1";
+        $orderList = Db::query($sql);
+        if (empty($orderList)){
+            $this->success('未找到排产工单');
+        }
+        foreach ($orderList as $key=>$value){
+            $orderList[$key]['工单编号|质量信息'] = $value['gdbh'].'|'.$value['质量信息'];
+            if ($value['yjno']<10){
+                $orderList[$key]['yjno'] = '0'.$value['yjno'];
+            }
+            if ($value['gxh']<10){
+                $orderList[$key]['gxh'] = '0'.$value['gxh'];
+            }
+            $orderList[$key]['印件资料'] = $orderList[$key]['yjno'].'-'.$value['印件名称'];
+            $orderList[$key]['工序名称'] = $orderList[$key]['gxh'].'-'.$value['gxmc'].'【'.$value['add_gxmc'].'】';
+            $orderList[$key]['计划产量/已完成'] = (int)($value['计划接货数']/$value['ls']).'/'.$value['已完成']=null?'':(int)$value['已完成'];
+            $orderList[$key]['计划生产时段'] =substr($value['sj1'],5,5).' '.substr($value['sj1'],11,5).'<-->'.substr($value['sj2'],5,5).' '.substr($value['sj2'],11,5);
+            unset($orderList[$key]['gdbh'],$orderList[$key]['质量信息'],$orderList[$key]['yjno'],$orderList[$key]['gxh'],$orderList[$key]['gxmc'],$orderList[$key]['add_gxmc'],$orderList[$key]['sj1'],$orderList[$key]['sj2'],$orderList[$key]['计划接货数'],$orderList[$key]['已完成'],$orderList[$key]['印件名称'],$orderList[$key]['ls']);
+        }
+        $this->success('成功',$orderList);
+    }
+
+
+
+    /**
+     * 工序、印件、完成数量
+     * @ApiMethod (GET)
+     * @param string $workOrder  工单编号
+     * @return void
+     * @throws \think\Exception
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+    public function Procedure()
+    {
+        if ($this->request->isGet() === false){
+            $this->error('请求错误');
+        }
+        $workOrder = input('Gd_gdbh');
+        if (empty($workOrder)){
+            $this->error('参数错误');
+        }
+        //右边工艺及完成数量
+        $Process = \db('设备_产量计酬')->where('sczl_gdbh',$workOrder)
+            ->distinct(true)->order('sczl_gxh')
+            ->column('sczl_gxh');
+        $data = [];
+        foreach ($Process as $k=>$v){
+            $res= \db('设备_产量计酬')->where('sczl_gdbh',$workOrder)
+                ->where('sczl_gxh',$v)
+                ->field('rtrim(sczl_yjno) as sczl_yjno,rtrim(sczl_gxmc) as sczl_gxmc')
+                ->find();
+            if ($res['sczl_yjno']<10){
+                $res['sczl_yjno'] = '0'.$res['sczl_yjno'];
+            }
+            $processList['process'] = $res['sczl_yjno'].'-'.$res['sczl_gxmc'];
+            $processList['completed'] = \db('设备_产量计酬')
+                ->where('sczl_gdbh',$workOrder)
+                ->where('sczl_gxh',$v)
+                ->count();
+            array_push($data,$processList);
+        }
+        $this->success('成功',$data);
+    }
+
+
+    /**
+     * 班组人员及分配比例
+     * @ApiMethod (GET)
+     * @param string $machine 机台编号
+     * @return void
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+
+    public function Team()
+    {
+        if ($this->request->isGet() === false){
+            $this->error('请求错误');
+        }
+        $machine = input('machine');
+        if (empty($machine)){
+            $this->error('参数错误');
+        }
+        $where = [
+            'sczl_jtbh' => $machine,
+        ];
+        $field = 'rtrim(sczl_bzdh) as 班组号,rtrim(sczl_bh1) as bh1,rtrim(sczl_bh2) as bh2,rtrim(sczl_bh3) as bh3,rtrim(sczl_bh4) as bh4,
+        rtrim(sczl_bh5) as bh5,rtrim(sczl_bh6) as bh6,rtrim(sczl_bh7) as bh7,rtrim(sczl_bh8) as bh8,rtrim(sczl_bh9) as bh9,
+        rtrim(sczl_bh10) as bh10,rtrim(sczl_rate1) as rate1,rtrim(sczl_rate2) as rate2,rtrim(sczl_rate3) as rate3,rtrim(sczl_rate4) as rate4,
+        rtrim(sczl_rate5) as rate5,rtrim(sczl_rate6) as rate6,rtrim(sczl_rate7) as rate7,rtrim(sczl_rate8) as rate8,
+        rtrim(sczl_rate9) as rate9,rtrim(sczl_rate10) as rate10,rtrim(UniqId) as ID';
+        $team = \db('设备_产量计酬')
+            ->where('sczl_jtbh',$machine)
+            ->field($field)
+            ->order('UniqId desc')
+            ->find();
+        $list = \db('设备_班组资料')->where($where)->field($field)->select();
+        $data = [];
+        foreach ($list as $k=>$v){
+            if ($team == $v){
+                $data[$k]['status'] = 1;
+            }else{
+                $data[$k]['status'] = 0;
+            }
+            $data[$k]['ID'] = $v['ID'];
+            $data[$k]['班组号'] = $v['班组号'];
+            for ($i=1;$i<11;$i++){
+                if ($v['bh'.$i] != '' && $v['bh'.$i] != '000000'){
+                    $name = \db('人事_基本资料')->where('员工编号',$v['bh'.$i])->field('rtrim(员工姓名) as 姓名')->find();
+                    $data[$k][$i-1] = $v['bh'.$i].' '.$name['姓名'].' ('.number_format($v['rate'.$i]*100,2).'%'.')';
+                }
+            }
+        }
+        $this->success('成功',$data);
+    }
+
+
+    /**
+     * 当班产量明细
+     * @ApiMethod (GET)
+     * @param string $machine  机台编号
+     * @param string $workOrder  工单编号
+     * @param string $team   班次
+     * @return void
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+    public function OutputDetail()
+    {
+        if ($this->request->isGet() === false){
+            $this->error('请求错误');
+        }
+        $machine = input('machine');
+        $workOrder = input('Gd_gdbh');
+        $team = input('team');
+        if (empty($machine) || empty($workOrder) || empty($team)){
+            $this->error('参数错误');
+        }
+        $name = \db('工单_基本资料')->where('Gd_gdbh',$workOrder)->field('rtrim(Gd_cpmc) as productName')->find();
+        $where = [
+            'sczl_gdbh' => $workOrder,
+            'sczl_jtbh' => $machine,
+            'sczl_cl' => ['<>',0.0],
+            'sczl_bzdh' => $team,
+        ];
+        $field = 'rtrim(sczl_gdbh) as 工单编号,rtrim(sczl_yjno) as yjno,rtrim(sczl_gxmc) as gxmc,rtrim(sczl_num) as 标牌号,rtrim(sczl_cl) as 产量,
+        rtrim(sczl_zcfp) as 制程废品,rtrim(sczl_zccp) as 制程次品,rtrim(sczl_前工序废) as 前工序废,rtrim(sczl_来料少数) as 来料异常,rtrim(sczl_装版工时) as 装版工时,
+        rtrim(sczl_保养工时) as 保养工时,rtrim(sczl_打样工时) as 打样工时,rtrim(sczl_异常停机工时) as 异常停机工时,rtrim(sczl_设备运行工时) as 通电工时,
+        rtrim(码开始行) as 码开始行,rtrim(码结束行) as 码结束行,rtrim(码包) as 码包,rtrim(主电表) as 主电表,rtrim(辅电表) as 辅电表,rtrim(sczl_ms) as 色度,
+        rtrim(sczl_sj1) as sj1,rtrim(sczl_sj2) as sj2';
+        $list = \db('设备_产量计酬')->where($where)->field($field)->order('UniqId desc')->select();
+        if (empty($list)){
+            $this->success('未找到生产记录');
+        }
+        foreach ($list as $k=>$v){
+            if ($v['yjno']<10){
+                $list[$k]['yjno'] = '0'.$v['yjno'];
+            }
+            $list[$k]['印件及工序'] = $list[$k]['yjno'].'-'.$v['gxmc'];
+            $list[$k]['生产时间段'] = substr($v['sj1'],5,5).' '.substr($v['sj1'],11,5).'<-->'.substr($v['sj2'],5,5).' '.substr($v['sj2'],11,5);
+            $list[$k]['产品名称'] = $name['productName'];
+            unset($list[$k]['yjno'],$list[$k]['gxmc'],$list[$k]['sj1'],$list[$k]['sj2']);
+        }
+        $field1 = 'SUM(sczl_cl) as 产量,SUM(sczl_zcfp) as 制程废品,SUM(sczl_zccp) as 制程次品,SUM(sczl_前工序废) as 前工序废,
+        SUM(sczl_来料少数) as 来料异常,SUM(sczl_装版工时) as 装版工时,SUM(sczl_保养工时) as 保养工时,SUM(sczl_打样工时) as 打样工时,
+        SUM(sczl_异常停机工时) as 异常停机工时,SUM(sczl_设备运行工时) as 通电工时,SUM(码开始行) as 码开始行,SUM(码结束行) as 码结束行,
+        SUM(码包) as 码包,SUM(主电表) as 主电表,SUM(辅电表) as 辅电表';
+        $total = \db('设备_产量计酬')->where($where)->field($field1)->order('UniqId desc')->select();
+        $total[0]['版数'] = count($list);
+        $list['total'] = $total[0];
+        $this->success('成功',$list);
+    }
+
+    /**
+     * 检验记录
+     * @ApiMethod (GET)
+     * @param string $machine  机台编号
+     * @param string $workOrder  工单编号
+     * @param string $team   班次
+     * @return void
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+    public function InspectionRecord()
+    {
+        if ($this->request->isGet() === false){
+            $this->error('请求失败');
+        }
+        $machine = input('machine');
+        $workOrder = input('Gd_gdbh');
+        $team = input('team');
+        if (empty($machine) || empty($workOrder) || empty($team)){
+            $this->error('参数错误');
+        }
+        $where = [
+            '设备编号' => $machine,
+            '工单编号' => $workOrder,
+            '班组编号' => $team,
+            '类别' => ['in',['IPQC检验','机台检验']],
+        ];
+        //检验项目筛选
+        $item = \db('制程检验_记录')->where($where)->distinct(true)->column('rtrim(检验项目)');
+        //检验时间
+        $InspectionTime = \db('制程检验_记录')->where($where)->distinct(true)->column('提交时间');
+        foreach ($InspectionTime as $k=>$v){
+            $InspectionTime[$k] = date('H:i',strtotime($v));
+        }
+        //检测记录详情
+        $field = 'rtrim(工单编号) as 工单编号,rtrim(印件号) as 印件号,rtrim(工序名称) as 工序名称';
+        $nameDetail = \db('制程检验_记录')->where($where)->field($field)->find();
+        $data = [];
+        //检测数据
+        foreach ($item as $key=>$value){
+            $SubmissionTime = \db('制程检验_记录')->where($where)
+                ->where('检验项目',$value)
+                ->where('检验结果','合格')
+                ->field('rtrim(提交时间) as 提交时间')
+                ->select();
+            $time = [];
+            foreach ($SubmissionTime as $k=>$v){
+                $time[$k] = date('H:i',strtotime($v['提交时间']));
+            }
+            $data[$key] = [
+                '工单编号' => $nameDetail['工单编号'],
+                '印件号' => $nameDetail['印件号'],
+                '工序名称' => $nameDetail['工序名称'],
+                '检验项目' => $value,
+                'inspectresult' => implode(',',$time),
+            ];
+        }
+        $data['inspectiontime'] = $InspectionTime;
+        $this->success('成功',$data);
+    }
+
+
+    /**
+     * 班组维护->班组添加
+     * @ApiMethod (GET)
+     * @param void
+     * @return void
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+    public function MachineTeamAdd()
+    {
+        if ($this->request->isGet() === false){
+            $this->error('请求错误');
+        }
+        $param = $this->request->param();
+        if (empty($param)){
+            $this->error('参数错误');
+        }
+        $teamDetail = \db('设备_班组资料')
+            ->where('UniqId',$param['UniqId'])
+            ->find();
+        if (empty($teamDetail)){
+            $this->error('数据错误');
+        }
+        $lastId = \db('设备_班组资料')
+            ->order('UniqId desc')
+            ->value('UniqId');
+        if ($lastId<100000){
+            $lastId = 1000000;
+        }
+        $teamDetail['sczl_jtbh'] = $param['machine'].'#';
+        $teamDetail['UniqId'] = $lastId + 1;
+        $teamDetail['sczl_bzdh'] = $param['team'];
+        $res = \db('设备_班组资料')->insert($teamDetail);
+        if ($res !== false){
+            $this->success('成功');
+        }else{
+            $this->error('失败');
+        }
+    }
+
+
+    /**
+     * 机台编号列表
+     * @ApiMethod  (GET)
+     * @return void
+     */
+    public function MachineList()
+    {
+        if ($this->request->isGet() === false){
+            $this->error('请求错误');
+        }
+        $list = \db('设备_基本资料')->field('rtrim(设备编号) as 设备编号,rtrim(设备名称) as 设备名称')->select();
+        if (empty($list)){
+            $this->success('未找到机台编号');
+        }
+        $data = [];
+        foreach ($list as $key=>$value){
+            $data[$key] = $value['设备编号'] . '||' . $value['设备名称'];
+        }
+        $this->success('成功',$data);
+    }
+
+    /**
+     * 删除班组信息
+     * @ApiMethod (GET)
+     * @param  void
+     * @return void
+     * @throws \think\Exception
+     * @throws \think\exception\PDOException
+     */
+    public function teamDel()
+    {
+        if (Request::instance()->isPost() === false){
+            $this->error('请求错误');
+        }
+        $param = Request::instance()->post();
+        if (empty($param)){
+            $this->error('参数错误');
+        }
+        $res = \db('设备_班组资料')
+            ->where('UniqId',$param['UniqId'])
+            ->delete();
+        if ($res !== false){
+            $this->success('成功');
+        }else{
+            $this->error('失败');
+        }
+
+    }
+
+    /**
+     * 管理人员现场巡检记录->展示
+     * @ApiMethod (GET)
+     * @param  void
+     * @return void
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+    public function FieldInspectionRecord()
+    {
+        if ($this->request->isGet() === false){
+            $this->error('请求错误');
+        }
+        $param = $this->request->param();
+        if (empty($param)){
+            $this->error('参数错误');
+        }
+        $date = date('Y-m-d H:i:s',time());
+        if (empty($param['start'])){
+            $startTime = date('Y-m-d 08:30:00',time());
+        }else{
+            $startTime = $param['start'];
+        }
+
+        if ($date<$startTime){
+            $startTime = date('Y-m-d H:i:s',strtotime($startTime)-86400);
+        }
+        $where = [
+            '工单编号' => $param['workOrder'],
+            '开工时间' => $startTime,
+            '类别' => '现场巡查记录',
+            '班组编号' => $param['team']
+        ];
+        $filed = 'rtrim(工单编号) as 工单编号,rtrim(印件号) as 印件号,rtrim(工序名称) as 工序名称,rtrim(流程单号) as 流程单号,
+        rtrim(设备编号) as 设备编号,rtrim(班组编号) as 班组编号,rtrim(检验项目) as 现场管理人员,rtrim(检验备注) as 检验备注,
+        rtrim(提交时间) as 提交时间,rtrim(开工时间) as 开工时间';
+        $list = \db('制程检验_记录')->where($where)
+            ->field($filed)
+            ->select();
+        if (empty($list)){
+            $this->success('',[]);
+        }
+        foreach ($list as $key=>$value){
+            $number = floor((strtotime($value['提交时间'])-strtotime($value['开工时间']))/(15*60));
+            $list[$key]['归属时段'] = $value['开工时间'];
+            $list[$key]['分钟差数'] = $number;
+            if ($number != 0){
+                $list[$key]['归属时段'] = date('Y-m-d H:i:s',strtotime($value['开工时间'])+$number*15*60);
+            }
+        }
+        $this->success('成功',$list);
+    }
+
+    /**
+     * 管理人员现场巡检记录->添加
+     * @ApiMethod (POST)
+     * @param  void
+     * @return void
+     */
+
+    public function FieldInspectionRecordAdd()
+    {
+        if (Request::instance()->isPost() === false){
+            $this->error('请求错误');
+        }
+        $param = Request::instance()->post();
+        if (empty($param)){
+            $this->error('参数错误');
+        }
+        if ($param['processCode']<10){
+            $param['processCode'] = '0'.$param['processCode'];
+        }
+        $date = date('Y-m-d H:i:s',time());
+        $startTime = date('Y-m-d 08:30:00',time());
+        if ($date<$startTime){
+            $startTime = date('Y-m-d H:i:s',strtotime($startTime)-86400);
+        }
+        $data = [
+            '类别' => $param['category'],
+            '工单编号' => $param['workOrder'],
+            '印件号' => $param['printCode'],
+            '工序名称' => $param['processCode'].'-'.$param['process'],
+            '流程单号' => $param['flowCode'],
+            '设备编号' => $param['machine'],
+            '班组编号' => $param['team'],
+            '检验项目' => '['.$param['employeeCode'].'/'.$param['employeeName'].']',
+            '相关标准' => '',
+            '量测仪器' => '',
+            '检验结果' => '',
+            '检验备注' => $param['remark'],
+            '提交时间' => date('Y-m-d H:i:s',time()),
+            '开工时间' => $startTime,
+            'sys_id' => '',
+            'sys_rq' => date('Y-m-d H:i:s',time()),
+            'mod_rq' => '0000-00-00 00:00:00',
+            'UniqId' => \db('制程检验_记录')->order('UniqId desc')->field('UniqId')->find()['UniqId']+1
+        ];
+        $sql = \db('制程检验_记录')->fetchSql(true)->insert($data);
+        $res = Db::query($sql);
+        if ($res !== false){
+            $this->success('成功');
+        }else{
+            $this->error('失败');
+        }
+    }
+
+    /**
+     * 设备点检->左侧菜单栏
+     * @ApiMethod (GET)
+     * @param  void
+     * @return void
+     */
+    public function SpotCheckItem()
+    {
+        if ($this->request->isGet() === false){
+            $this->error('请求错误');
+        }
+        $param = $this->request->param();
+        if (empty($param)){
+            $this->error('参数错误');
+        }
+        $list = \db('设备_点检项目')
+            ->where('适用机型','LIKE','%;'.$param['machine'].';%')
+            ->distinct(true)
+            ->column('部件名称','部件编号');
+        if (empty($list)){
+            $this->success('');
+        }
+        $this->success('成功',$list);
+    }
+
+    /**
+     * 设备点检->检测项目
+     * @ApiMethod (GET)
+     * @param  void
+     * @return void
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+    public function  InspectionItem()
+    {
+        if ($this->request->isGet() === false){
+            $this->error('请求错误');
+        }
+        $param = $this->request->param();
+        if (empty($param)){
+            $this->error('参数错误');
+        }
+        $list = \db('设备_点检项目')
+            ->where('部件名称',$param['unitName'])
+            ->where('适用机型','like','%'.$param['machine'].'#%')
+            ->field('rtrim(检验项目) as 检验项目,rtrim(判定标准) as 判定标准,rtrim(点检方法) as 点检方法')
+            ->select();
+        if (empty($list)){
+            $this->success('未找到检测项目');
+        }
+        $this->success('成功',$list);
+    }
+
+
+    /**
+     * 设备点检->检测记录添加
+     * @ApiMethod (POST)
+     * @param  void
+     * @return void
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+    public  function InspectionItemAdd()
+    {
+        if (Request::instance()->isPost()  === false){
+            $this->error('请求错误');
+        }
+        $param = Request::instance()->post();
+        if (empty($param)){
+            $this->error('参数错误');
+        }
+        $lastNumber =  \db("设备_点检记录")->field('Uniqid as ID')->order('Uniqid desc')->find()['ID'];
+        if ((int)$lastNumber>10000000){
+            $lastId = $lastNumber;
+        }else{
+            $lastId = 10000000;
+        }
+        $row = [];
+        foreach ($param as $key=>$value){
+            $unitCode = \db('设备_点检项目')->where('部件名称',$value['unitName'])->field('rtrim(部件编号) as 部件编号')->find();
+            $row[$key] = [
+                '日期' => date('Y-m-d 00:00:00',time()),
+                '班组编号' => $value['team'],
+                '点检设备' => $value['machine'],
+                '部件编号' => $unitCode['部件编号'],
+                '部件名称' => $value['unitName'],
+                '检验项目' => $value['itemName'],
+                '判定标准' => $value['standard'],
+                '点检方法' => $value['method'],
+                '点检结果' => $value['status'],
+                '备注说明' => $value['remark'],
+                'Sys_id'  =>'',
+                'Sys_rq'  => date('Y-m-d H:i:s',time()),
+                'Mod_rq'  => date('Y-m-d H:i:s',time()),
+                'Uniqid'  => $lastId+$key+1
+            ];
+
+        }
+        $sql = \db('设备_点检记录')->fetchSql(true)->insertAll($row);
+        $res = Db::query($sql);
+        if ($res !== false){
+            $this->success('成功');
+        }else{
+            $this->error('失败');
+        }
+    }
+
+    /**
+     * 机台印版领用->左侧菜单
+     * @ApiMethod (GET)
+     * @param  void
+     * @return void
+     */
+    public function PrintGetTab()
+    {
+        if ($this->request->isGet() === false){
+            $this->error('请求错误');
+        }
+        $param = $this->request->param();
+        if (empty($param)){
+            $this->error('参数错误');
+        }
+        $productCode = $param['productCode'];
+        $sql = "SELECT DISTINCT(RTRIM(b.`名称`)) as `印版分类`,RTRIM(b.`编号`) as `编号` FROM `产品_印版资料` as a
+                JOIN `物料_存货结构` as b ON b.`编号` = SUBSTRING(a.`存货编码`,1,4)
+                WHERE a.YB_Cpdh = '{$productCode}'";
+        $res = Db::query($sql);
+        if (empty($res)){
+            $this->success('');
+        }
+        $this->success('成功',$res);
+    }
+
+    /**
+     * 机台印版领用记录->数据详情
+     * @ApiMethod (GET)
+     * @param  void
+     * @return void
+     */
+    public function PrintDetail()
+    {
+        if ($this->request->isGet() === false){
+            $this->error('请求失败');
+        }
+        $param = $this->request->param();
+        if (empty($param)){
+            $this->error('参数错误');
+        }
+        $productCode = $param['productCode'];
+        $code = $param['code'].'%';
+        $workOrder = $param['workOrder'];
+        $sql = "SELECT 
+                RTRIM(a.`存货编码`) as `存货编码`,
+                RTRIM(c.`物料名称`) as `存货名称`,
+                RTRIM(b.`印版名称`) as `印版名称`,
+                RTRIM(b.`供方批号`) as `供方批号`,
+                RTRIM(b.`制造日期`) as `制造日期`,
+                SUM(d.`Yb_印数`) as `印数`,
+                RTRIM(e.`名称`) as `印版类别`,
+                SUBSTRING(a.YB_Cpdh,1,4) as `客户编号`,
+                RTRIM(f.`Gd_客户名称`) as `客户名称`,
+                RTRIM(a.YB_Cpdh) as `产品编号`,
+                RTRIM(f.Gd_cpmc) as `产品名称`
+                FROM `产品_印版资料` as a 
+                LEFT JOIN `产品_印版库` as b ON b.`存货编码` = a.`存货编码`
+                JOIN `物料_存货编码` as c ON c.`物料代码` = a.`存货编码`
+                LEFT JOIN `工单_印版领用记录` as d ON d.`Yb_供方批号` = b.`供方批号`
+                JOIN `物料_存货结构` as e ON e.`编号` = SUBSTRING(a.`存货编码`,1,4)
+                JOIN `工单_基本资料` as f ON a.YB_Cpdh = f.Gd_cpdh
+                WHERE a.YB_Cpdh = '{$productCode}' 
+                AND a.`存货编码` LIKE '{$code}'
+                AND f.Gd_gdbh = '{$workOrder}'
+                AND b.`报废日期` = '1900-01-01 00:00:00'
+                GROUP BY b.`供方批号`
+                ORDER BY a.`存货编码`";
+        $list = Db::query($sql);
+        if (empty($list)){
+            $this->success('');
+        }
+        $this->success('成功',$list);
+    }
+
+    /**
+     * 换型清场->左侧菜单栏
+     * @ApiMethod  (GET)
+     * @param  void
+     * @return void
+     */
+    public function remodelGetTab()
+    {
+        if ($this->request->isGet() === false){
+            $this->error('请求错误');
+        }
+        $date = date('Y-m-d 00:00:00',time()-3888000);
+        $nowTime = date('Y-m-d H:i:s',time());
+        $list = \db('设备_基本资料')->where('使用状态',1)->order('设备编号')->column('设备编号');
+        if (empty($list)){
+            $this->error('失败');
+        }
+        $sql = "SELECT RTRIM(a.`设备编号`) as `设备编号`,RTRIM(b.`日期`) as `日期`,RTRIM(b.UniqId) as UniqId FROM `设备_基本资料` as a 
+                LEFT JOIN `制程_换型清场` as b ON b.`机台编号` = a.`设备编号`
+                WHERE b.`日期` > '{$date}' AND b.日期 < '{$nowTime}' ORDER BY b.`UniqId`";
+        $res = Db::query($sql);
+        $data = $result = [];
+        foreach ($list as $key=>$value){
+            $data[$value] = $result[$value]= $time = [];
+            foreach ($res as $k=>$v){
+                if ($value === $v['设备编号']){
+                    $row = [
+                        '日期' => $v['日期'],
+                        'id' => $v['UniqId']
+                    ];
+                    array_push($data[$value],$row);
+
+                }
+            }
+            foreach ($data[$value] as $m=>$n){
+                $time[$m] = $n['日期'];
+            }
+            $time = array_values(array_unique($time));
+            foreach ($time as $kk=>$vv){
+                $i=1;
+                foreach ($data[$value] as $kkk=>$vvv){
+                    if ($kkk>=$kk  && $vv === $vvv['日期']){
+                        array_push($result[$value],date('Y-m-d',strtotime($vv)).'第'.$i.'次换型/'.$vvv['id']);
+                        $i++;
+                    }
+                }
+            }
+        }
+        $this->success('成功',$result);
+    }
+
+    /**
+     * 换型清场->详情
+     * @return void
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+    public function RemodelDetail()
+    {
+        if ($this->request->isGet() === false){
+            $this->error('请求错误');
+        }
+        $param = $this->request->param();
+        if (empty($param)){
+            $this->error('参数错误');
+        }
+        $field = 'rtrim(日期) as 日期,rtrim(班组) as 班组,rtrim(机台编号) as 机台编号,rtrim(工单编号A) as 工单编号A,rtrim(印件工序A) as 印件工序A,
+        rtrim(码包号A) as 码包号A,rtrim(工单编号B) as 工单编号B,rtrim(印件工序B) as 印件工序B,rtrim(码包号B) as 码包B,
+        rtrim(清场项目A) as 项目1,rtrim(清场项目B) as 项目2,rtrim(清场项目C) as 项目3,rtrim(清场项目D) as 项目4,rtrim(清场项目E) as 项目5,
+        rtrim(机长) as 机长,rtrim(班长) as 班长,rtrim(质量巡查员) as 质量巡查员';
+        $list = \db('制程_换型清场')->where('UniqId',$param['UniqId'])->field($field)->find();
+        if (empty($list)){
+            $this->success('未找到该条清场记录');
+        }
+        $list['日期'] = date('Y-m-d',strtotime($list['日期']));
+        $list['印件名称A'] = \db('工单_印件资料')->where('Yj_Gdbh',$list['工单编号A'])->field('rtrim(yj_yjmc) as yjmc')->find()['yjmc'];
+        $list['印件名称B'] = \db('工单_印件资料')->where('Yj_Gdbh',$list['工单编号B'])->field('rtrim(yj_yjmc) as yjmc')->find()['yjmc'];
+        $this->success('成功',$list);
+    }
+
+    /**
+     * 换型清场->当前设备清场记录
+     * @ApiMethod (GET)
+     * @param  void
+     * @return void
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+    public function ModelChangeRecord()
+    {
+        if ($this->request->isGet() === false){
+            $this->error('请求错误');
+        }
+        $param = $this->request->param();
+        if (empty($param)){
+            $this->error('参数错误');
+        }
+        $date = date('Y-m-d 00:00:00',time()-3888000);
+        $nowTime = date('Y-m-d H:i:s',time());
+        $where = [
+            '日期' =>['between',[$date,$nowTime]],
+            '机台编号' => $param['machine']
+        ];
+        $field = "rtrim(日期) as 日期,rtrim(机台编号) as 机台编号,rtrim(班组) as 班组,rtrim(工单编号A) as 工单编号A,rtrim(印件工序A) as 印件工序A,
+        rtrim(码包号A) as 码包号A,rtrim(工单编号B) as 工单编号B,rtrim(印件工序B) as 印件工序B,rtrim(码包号B) as 码包号B,rtrim(清场项目A) as 清场项目A,
+        rtrim(清场项目B) as 清场项目B,rtrim(清场项目C) as 清场项目C,rtrim(清场项目D) as 清场项目D,rtrim(清场项目E) as 清场项目E,rtrim(机长) as 机长,
+        rtrim(班长) as 班长,rtrim(质量巡查员) as 质量巡查员,rtrim(sys_rq) as 创建时间,rtrim(UniqId) as UNIQID";
+        $list = \db('制程_换型清场')
+            ->where($where)
+            ->field($field)
+            ->select();
+        if (empty($list)){
+            $this->success('未找到换型记录');
+        }
+        foreach ($list as $key=>$value){
+            $list[$key]['印件名称A'] = \db('工单_印件资料')->where('Yj_Gdbh',$value['工单编号A'])->field('rtrim(yj_yjmc) as yjmc')->find()['yjmc'];
+            $list[$key]['印件名称B'] = \db('工单_印件资料')->where('Yj_Gdbh',$value['工单编号B'])->field('rtrim(yj_yjmc) as yjmc')->find()['yjmc'];
+        }
+        $this->success('成功',$list);
+    }
+
+    /**
+     * 车间机台状态列表展示
+     * @ApiMethod (GET)
+     * @param  void
+     * @return void
+     * @throws \think\db\exception\BindParamException
+     * @throws \think\exception\PDOException
+     */
+    public function MachineDetailList()
+    {
+        if ($this->request->isGet() === false){
+            $this->error('请求错误');
+        }
+        $param = $this->request->param();
+        if (empty($param)){
+            $this->error('参数错误');
+        }
+        $workshop = $param['workshop'];
+        $sql = "SELECT
+                    RTRIM( a.`设备编号` ) AS 设备编号,
+                    RTRIM( a.`设备名称` ) AS 设备名称,
+                    RTRIM( d.`当前状态` ) AS 状态
+                FROM
+                    `设备_基本资料` AS a
+                    JOIN (
+                    SELECT
+                        b.`设备编号`,
+                        b.`当前状态`,
+                        b.`开工时间` 
+                    FROM
+                        `设备_产量采集` AS b
+                        JOIN ( SELECT `设备编号`, MAX( `UniqId` ) AS `UniqId` FROM `设备_产量采集` GROUP BY `设备编号` ) AS c ON b.`设备编号` = c.`设备编号` 
+                        AND b.`UniqId` = c.`UniqId`  
+                    ) AS d ON a.`设备编号` = d.`设备编号`
+                WHERE
+                    a.`使用部门` = '{$workshop}' 
+                GROUP BY
+                    a.`设备编号`";
+        $list = \db()->query($sql);
+        foreach ($list as $key=>$value){
+            if ($value['状态'] == ''){
+                $list[$key]['状态'] = '待单';
+            }
+        }
+        $this->success('成功',$list);
+    }
+
+    /**
+     * 机台当前参数展示
+     * @ApiMethod (GET)
+     * @return void
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+    public function MachineDetail()
+    {
+        if ($this->request->isGet() === false){
+            $this->error('请求错误');
+        }
+        $param = $this->request->param();
+        if (empty($param)){
+            $this->error('参数错误');
+        }
+        $data = [];
+        if ($param['start'] === ''){
+            if (date('Y-m-d H:i:s')>date('Y-m-d 08:30:00',time()) && date('Y-m-d H:i:s')<date('Y-m-d 20:30:00',time())){
+                $param['start'] = date('Y-m-d 08:30:00',time());
+            }elseif (date('Y-m-d H:i:s')>date('Y-m-d 20:30:00',time()) && date('Y-m-d H:i:s')<date('Y-m-d 23:59:59',time())){
+                $param['start'] = date('Y-m-d 20:30:00',time());
+            }else{
+                $param['start'] = date('Y-m-d 20:30:00',time()-86400);
+            }
+        }
+        $machineDetail = \db('设备_产量采集')
+            ->alias('a')
+            ->join('设备_基本资料 b','a.设备编号 = b.设备编号')
+            ->join('工单_工艺资料 c','a.工单编号 = c.Gy0_gdbh AND a.设备编号 = c.Gy0_sbbh')
+            ->join('工单_基本资料 d','a.工单编号 = d.Gd_gdbh')
+            ->field([
+                'rtrim(a.开工时间)' => '开工时间',
+                'rtrim(a.设备编号)' => '设备编号',
+                'rtrim(a.工单编号)' => '工单编号',
+                'rtrim(b.设备名称)' => '设备名称',
+                'rtrim(c.Gy0_gxh)' => '工序号',
+                'rtrim(c.Gy0_gxmc)' => '工序名称',
+                'rtrim(d.Gd_cpmc)' => '产品名称'
+            ])
+            ->where('a.设备编号', $param['machine'])
+            ->order('a.UniqId desc')
+            ->find();
+        $data['machine'] = [
+            '日期' => $machineDetail['开工时间'],
+            '设备' => $machineDetail['设备编号'].'-->'.$machineDetail['设备名称'],
+            '工单' => $machineDetail['工单编号'].'-->'.$machineDetail['产品名称'],
+            '工艺' => ($machineDetail['工序号']<10?'0'.$machineDetail['工序号']:$machineDetail['工序号']).'--'.$machineDetail['工序名称']
+        ];
+        //机台状态时间
+        $startTime = \db('设备_产量采集')
+            ->where('设备编号',$param['machine'])
+            ->where('开工时间',$param['start'])
+            ->field('rtrim(时间) as 时间,当班产量,rtrim(当前状态) as 状态,MAX(时间) as 最大时间,MAX(当班产量) as 最大产量')
+            ->group('当前状态')
+            ->select();
+        if (!empty($startTime)){
+            foreach ($startTime as $key=>$value){
+                $data['timeDifference'][$key] = [
+                    '时间' => round((strtotime($value['最大时间'])-strtotime($value['时间']))/3600,2),
+                    '状态' => $value['状态'] = null?'待单':$value['状态'],
+                ];
+                if ($value['状态'] === '生产'){
+                    $data['当班产量'] = $value['最大产量']-$value['当班产量'];
+                }
+            }
+        }else{
+            $data['timeDifference'][0] = [
+                '时间' => 0,
+                '状态' => '待单'
+            ];
+            $data['当班产量'] = 0;
+        }
+        //机台产能/时间明细
+        $row = \db('设备_产量采集')
+            ->where('设备编号',$param['machine'])
+            ->where('开工时间',$param['start'])
+            ->field('rtrim(时间) as 时间,rtrim(当班产量) as 产量,rtrim(当前状态) as 状态')
+            ->select();
+        if (empty($row)){
+            $data['row'] = [];
+        }
+        foreach ($row  as $key=>$value){
+            $data['row'][$key]['时间'] = date('Y-m-d H:i',strtotime($value['时间']));
+            $data['row'][$key]['状态'] = $value['状态'];
+            if ($key<2){
+                $data['row'][$key]['产能'] = 0;
+            }else{
+                $data['row'][$key]['产能'] = ($row[$key-1]['产量']-$row[$key-2]['产量'])*60;
+            }
+        }
+        //机台状态
+        $status = end($row);
+        if (empty($status['状态'])){
+            $data['status'] = '待单';
+        }else{
+            $data['status'] = $status['状态'];
+        }
+        //检验数据
+        $list = \db('制程检验_记录')
+            ->where('开工时间',$param['start'])
+            ->where('设备编号',$param['machine'])
+            ->where('sys_rq','>',$param['start'])
+            ->field('rtrim(类别) as 类别,提交时间')
+            ->select();
+        $data['首件'] = $data['自检'] = $data['IPQC'] = [];
+        if (!empty($list)){
+            foreach ($list as $key=>$value){
+                if ($value['类别'] == '首件与过程确认'){
+                    array_push($data['首件'],$value['提交时间']);
+                }
+                if ($value['类别'] == '机台检验'){
+                    array_push($data['自检'],$value['提交时间']);
+                }
+                if ($value['类别'] == 'IPQC检验'){
+                    array_push($data['IPQC'],$value['提交时间']);
+                }
+            }
+            $data['首件'] = array_values(array_unique($data['首件']));
+            $data['自检'] = array_values(array_unique($data['自检']));
+            $data['IPQC'] = array_values(array_unique($data['IPQC']));
+        }else{
+            $data['首件'] = [];
+            $data['自检'] = [];
+            $data['IPQC'] = [];
+        }
+        $this->success('成功',$data);
+    }
+
+    /**
+     * 制程检验记录->检验项目
+     * @ApiMethod (GET)
+     * @param void
+     * @return void
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+    public function ProcessInspectionRecordsItem()
+    {
+        if ($this->request->isGet() === false){
+            $this->error('请求错误');
+        }
+        $param = $this->request->param();
+        if (empty($param)){
+            $this->error('参数错误');
+        }
+        $list = \db('制程检验_项目')
+            ->where('工序','like','%'.$param['process'].'%')
+            ->select();
+        if (empty($list)){
+            $this->success('未找到检测项目');
+        }
+        $data = [];
+        foreach ($list as $key=>$value){
+            $data['首件']['指标检验'][$key] = [
+                '检验项目' => rtrim($value['检测项目']),
+                '检测方法' => rtrim($value['检测方法']),
+                '检验频率' => rtrim($value['首件签样要求']),
+                '相关标准' => rtrim($value['技术要求'])
+            ];
+            $data['机台检验']['指标检验'][$key] = [
+                '检验项目' => rtrim($value['检测项目']),
+                '检测方法' => rtrim($value['检测方法']),
+                '检验频率' => rtrim($value['机台自检频率']),
+                '相关标准' => rtrim($value['技术要求'])
+            ];
+            $data['IPQC']['指标检验'][$key] = [
+                '检验项目' => rtrim($value['检测项目']),
+                '检测方法' => rtrim($value['检测方法']),
+                '检验频率' => rtrim($value['IPQC检验频率']),
+                '相关标准' => rtrim($value['技术要求'])
+            ];
+        }
+        $row = \db('制程检验_项目附加')
+            ->where('工序','like','%'.$param['process'].'%')
+            ->select();
+        foreach ($row as $key=>$value){
+            $data['首件']['附加'][$key] = [
+                '缺陷备注' => rtrim($value['缺陷备注']),
+                '编号' => rtrim($value['编号'])
+            ];
+            $data['机台检验']['附加'][$key] = [
+                '缺陷备注' => rtrim($value['缺陷备注']),
+                '编号' => rtrim($value['编号'])
+            ];
+            $data['IPQC']['附加'][$key] = [
+                '缺陷备注' => rtrim($value['缺陷备注']),
+                '编号' => rtrim($value['编号'])
+            ];
+        }
+        $this->success('成功',$data);
+    }
+
+    /**
+     * 制程检验记录->检测记录添加
+     * @ApiMethod (POST)
+     * @param void
+     * @return void
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+    public function ProcessInspectionRecordsItemAdd()
+    {
+        if (Request::instance()->isPost() === false){
+            $this->error('请求错误');
+        }
+        $param = Request::instance()->post();
+        if (empty($param)){
+            $this->error('参数错误');
+        }
+        $startID = \db('制程检验_记录')->order('UniqId desc')->value('UniqId');
+        if ($startID<100000000){
+            $startID = 100000000;
+        }
+        $process = \db('工单_工艺资料')
+            ->where('Gy0_gdbh',$param[0]['workOrder'])
+            ->where('Gy0_sbbh','like','%'.$param[0]['machine'].'#'.'%')
+            ->field('rtrim(Gy0_gxh) as gxh,rtrim(Gy0_gxmc) as gxmc,rtrim(Add_gxmc) as add_gxmc')
+            ->find();
+        $startTime = \db('设备_产量采集')
+            ->where('设备编号','like','%'.$param[0]['machine'].'#%')
+            ->where('工单编号',$param[0]['workOrder'])
+            ->order('UniqId desc')
+            ->find();
+        if ((int)$process['gxh']<10){
+            $process['gxh'] = '0'.$process['gxh'];
+        }
+        if ($process['add_gxmc'] !== ''){
+            $printName = $process['gxh'].'-'.$process['gxmc'].'【'.$process['add_gxmc'].'】';
+        }else{
+            $printName = $process['gxh'].'-'.$process['gxmc'];
+        }
+        if (empty($process)){
+            $this->success('数据错误');
+        }
+        $data = [];
+        foreach ($param as $key=>$value){
+            $data[$key] = [
+                '类别' => $value['category'],
+                '工单编号' => $value['workOrder'],
+                '印件号' => $value['yjno'],
+                '工序名称' => $printName,
+                '流程单号' => $value['flow'],
+                '设备编号' => $value['machine'].'#',
+                '班组编号' => $startTime['班组编号'],
+                '检验项目' => $value['item'],
+                '相关标准' => $value['standard'],
+                '量测仪器' => $value['instrument'],
+                '检验结果' => $value['result'],
+                '检验备注' => $value['remark'],
+                '提交时间' => date('Y-m-d H:i:s',time()),
+                '开工时间' => rtrim($startTime['开工时间']),
+                'sys_id' => '',
+                'sys_rq' => date('Y-m-d H:i:s',time()),
+                'mod_rq' => '0000-00-00 00:00:00',
+                'UniqId' => $startID + $key +1
+            ];
+        }
+        $res = \db('制程检验_记录')->insertAll($data);
+        if ($res !== false){
+            $this->success('成功');
+        }else{
+            $this->error('失败');
+        }
+    }
+
+    /**
+     * 制程检验记录->附加检验记录添加
+     * @ApiMethod (POST)
+     * @param  void
+     * @return void
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+    public function AdditionalInspectionRecordAdd()
+    {
+        if (Request::instance()->isPost() === false){
+            $this->error('请求错误');
+        }
+        $param = Request::instance()->post();
+        if (empty($param)){
+            $this->error('参数错误');
+        }
+        $startID = \db('制程检验_记录附加')->order('UniqId desc')->value('UniqId');
+        if ($startID<100000000){
+            $startID = 100000000;
+        }
+        $process = \db('工单_工艺资料')
+            ->where('Gy0_gdbh',$param[0]['workOrder'])
+            ->where('Gy0_sbbh','like','%'.$param[0]['machine'].'#'.'%')
+            ->field('rtrim(Gy0_gxh) as gxh,rtrim(Gy0_gxmc) as gxmc,rtrim(Add_gxmc) as add_gxmc')
+            ->find();
+        $startTime = \db('设备_产量采集')
+            ->where('设备编号','like','%'.$param[0]['machine'].'#%')
+            ->where('工单编号',$param[0]['workOrder'])
+            ->order('UniqId desc')
+            ->find();
+        if ((int)$process['gxh']<10){
+            $process['gxh'] = '0'.$process['gxh'];
+        }
+        if ($process['add_gxmc'] !== ''){
+            $printName = $process['gxh'].'-'.$process['gxmc'].'【'.$process['add_gxmc'].'】';
+        }else{
+            $printName = $process['gxh'].'-'.$process['gxmc'];
+        }
+        if (empty($process)){
+            $this->success('数据错误');
+        }
+        $data = [];
+        foreach ($param as $key=>$value){
+            $data[$key] = [
+                '工单编号' => $value['workOrder'],
+                '印件号' => $value['yjno'],
+                '工序名称' => $printName,
+                '流程单号' => $value['flow'],
+                '设备编号' => $value['machine'],
+                '班组编号' => $startTime['班组编号'],
+                '缺陷备注' => $value['remark'],
+                '提交时间' => date('Y-m-d H:i:s',time()),
+                '开工时间' => rtrim($startTime['开工时间']),
+                'sys_id' => '',
+                'sys_rq' => date('Y-m-d H:i:s',time()),
+                'mod_rq' => '0000-00-00 00:00:00',
+                'UniqId' => $startID + $key +1
+            ];
+        }
+        $res = \db('制程检验_记录附加')->insertAll($data);
+        if ($res !== false){
+            $this->success('成功');
+        }else{
+            $this->error('失败');
+        }
+    }
+
+    /**
+     * 客诉记录
+     * @ApiMethod (GET)
+     * @param  void
+     * @return void
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+     public function ComplaintRecord()
+     {
+         if ($this->request->isGet() === false){
+             $this->error('请求错误');
+         }
+         $param = $this->request->param();
+         if (isset($param['productCode'])){
+             $where['产品编号'] = $param['productCode'];
+         }
+         $filed = "rtrim(产品编号) as 产品编号,rtrim(产品名称) as 产品名称,rtrim(客诉日期) as 客诉日期,rtrim(客诉单号) as 客诉单号,
+         rtrim(客诉方式) as 客诉方式,rtrim(订单编号) as 订单编号,rtrim(客户编号) as 客户编号,rtrim(客户名称) as 客户名称,
+         rtrim(客诉描述) as 客诉描述,rtrim(缺陷关键字) as 缺陷关键字,rtrim(客诉性质) as 客诉性质,rtrim(扣分) as 扣分,
+         rtrim(主要责任部门) as 主要责任部门,rtrim(次要责任部门) as 次要责任部门";
+         $list = \db('db_客诉记录')
+             ->where($where)
+             ->field($filed)
+             ->select();
+         if (empty($list)){
+             $this->success('未找到该产品客诉记录');
+         }
+         $this->success('成功',$list);
+     }
+
+    /**
+     * 设置机台班组信息
+     * @return void
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+
+    public function setMachineTeam()
+    {
+        if (Request::instance()->isPost() == false) {
+            $this->error('非法请求');
+        }
+        $params = Request::instance()->post();
+        if (!isset($params['machine']) || empty($params['machine'])) {
+            $this->error('参数不能为空');
+        }
+        $machine = $params['machine'] . '#';
+        $data = [];
+        $lastData = \db('设备_产量采集')
+            ->order('UniqId desc')
+            ->find();
+        if ($lastData['UniqId'] < 160000000) {
+            $id = 160000000;
+        } else {
+            $id = $lastData['UniqId'] + 1;
+        }
+        $data['当前状态'] = $params['status'];
+        $data['时间'] = date('Y-m-d H:i:s');
+        $data['设备编号'] = $machine;
+        $data['工单编号'] = $params['order'];
+        $data['印件号'] = $params['yjno'];
+        $data['工序号'] = (int)substr($params['gy_name'], 0, 2);
+        $data['工序名称'] = $params['gy_name'];
+        $data['当班产量'] = $params['production_now'];
+        $data['累计产量'] = $params['production_all'];
+        $data['班组编号'] = $params['sczl_bzdh'];
+        $data['班组ID'] = $params['team_id'];
+        // 获取当前时间
+        $current_time = time();
+        // 设置时间范围
+        $start_time1 = strtotime(date('Y-m-d') . ' 08:30:00');
+        $end_time1 = strtotime(date('Y-m-d') . ' 20:30:00');
+        $end_time2 = strtotime(date('Y-m-d') . ' 24:00:00');
+        $start_time3 = strtotime(date('Y-m-d', strtotime('+1 day')) . ' 08:30:00');
+        // 判断当前时间属于哪个时间范围
+        if ($current_time >= $start_time1 && $current_time <= $end_time1) {
+            $data['开工时间'] = date('Y-m-d') . ' 08:30:00';
+        } elseif ($current_time > $end_time1 && $current_time <= $end_time2) {
+            $data['开工时间'] = date('Y-m-d') . ' 20:30:00';
+
+        } elseif ($current_time > $end_time1 && $current_time <= $start_time3) {
+            $data['开工时间'] = date('Y-m-d', strtotime('+1 day')) . ' 08:30:00';
+        }
+        $option['Gy0_gdbh'] = $params['order'];
+        $option['Gy0_yjno'] = $params['yjno'];
+        $option['Gy0_gxh'] = $data['工序号'];
+        $data['任务ID'] = \db('工单_工艺资料')->where($option)->value('UniqId');
+        $data['UniqId'] = $id;
+        $sql = \db('设备_产量采集')->fetchSql(true)->insert($data);
+        $res = Db::query($sql);
+        if ($res === false) {
+            $this->error('设置失败');
+        } else {
+            $this->success('设置成功');
+        }
+    }
+}

+ 815 - 0
application/api/controller/OrderSuperLoss.php

@@ -0,0 +1,815 @@
+<?php
+
+namespace app\api\controller;
+
+use app\common\controller\Api;
+use think\Cache;
+use \think\Request;
+use \think\Db;
+/**
+ * 工单超节损核算接口
+ */
+class OrderSuperLoss extends Api
+{
+    protected $noNeedLogin = ['*'];
+    protected $noNeedRight = ['*'];
+
+    /**
+     * 首页
+     *
+     */
+    public function index()
+    {
+        $this->success('请求成功');
+    }
+    /**
+     * 获取左侧菜单栏
+     * @ApiMethod GET
+    */
+    public function getTab()
+    {
+        if (Request::instance()->isGet() == false) {
+            $this->error('非法请求');
+        }
+        $sql = "SELECT LEFT(a.jjcp_sj, 7) AS date,RTRIM(b.`编号`) AS 编号,RTRIM(b.`名称`) as 客户名称,COUNT(DISTINCT a.jjcp_gdbh) AS count
+                    FROM `成品入仓` a LEFT JOIN `物料_存货结构` b ON LEFT(a.`成品编码`, 4) = RTRIM(b.`编号`)
+                    WHERE LEFT(a.jjcp_sj, 7) >= LEFT(DATE_SUB(CURDATE(), INTERVAL 12 MONTH), 7) AND a.jjcp_smb = '末 板' AND a.`成品编码` != ''
+                    GROUP BY LEFT(a.jjcp_sj, 7), RTRIM(b.`编号`) ORDER BY date DESC, 编号 ASC";
+        $data = Db::query($sql);
+        // 创建一个新数组来存储整理后的数据
+        $organizedData = [];
+        // 遍历原始数据
+        foreach ($data as $entry) {
+            $date = date('Ym',strtotime($entry['date']));
+
+            // 检查日期是否在已整理数据中存在
+            if (isset($organizedData[$date])) {
+                // 如果日期存在,将数据追加到该日期下
+                $organizedData[$date][] = [
+                    '客户名称' => $entry['客户名称'],
+                    '客户编号' => $entry['编号'],
+                    'total' => $entry['count'],
+                ];
+                // 统计该日期下所有数据的总和
+                $organizedData[$date]['total_count'] += $entry['count'];
+            } else {
+                // 如果日期不存在,创建新的日期项并添加数据
+                $organizedData[$date] = [
+                    [
+                        '客户名称' => $entry['客户名称'],
+                        '客户编号' => $entry['编号'],
+                        'total' => $entry['count'],
+                    ]
+                ];
+                // 初始化该日期的总和
+                $organizedData[$date]['total_count'] = $entry['count'];
+            }
+        }
+
+        // 将整理后的数据调整为以日期和相加的总和为索引的格式
+        $finalData = [];
+        foreach ($organizedData as $date => $entries) {
+            $totalCount = $entries['total_count'];
+            $index = $date . '-' . $totalCount;
+            unset($entries['total_count']);
+            $finalData[$index] = $entries;
+        }
+        $this->success('请求成功',$finalData);
+    }
+    /**
+     * 获取超节损工单列表
+     * @ApiMethod GET
+     * @params string date
+     * @params string code
+     * 报废定额=(基础损耗+损耗率*计划产量)*损耗系数*计损色数(特定工序会有,如果无就不乘)
+     * 允损比例=报废定额/计划产量
+     * 目标合格率 = 100%-超节损工单中显示工序的允损比例之和
+     *
+    */
+    public function getList(){
+        if (Request::instance()->isGet() == false) {
+            $this->error('非法请求');
+        }
+        $params = Request::instance()->param();
+        $where = [];
+        if (!empty($params['code'])) {
+            if (!empty($params['search'])) {
+                $this->error('参数错误');
+            }
+//            $where['a.成品编码'] = $params['code'];
+        }
+        if (!empty($params['date'])) {
+            if (!empty($params['search'])) {
+                $this->error('参数错误');
+            }
+            $where['a.jjcp_sj' ] = array('like',$params['date'].'%');
+        }
+        if (!empty($params['search'])) {
+            if (!empty($params['date']) || !empty($params['code'])) {
+               $this->error('参数错误');
+            }
+            $where['a.成品名称'] = array('like','%'.$params['search'].'%');
+        }
+        $where['b.行号' ] = 1;
+        $where['a.jjcp_smb' ] = '末 板';
+        $limit = $params['limit'];
+        if (empty($limit)){
+            $limit = 15;
+        }
+        $pages = $params['page'];
+        if (empty($pages)){
+            $pages = 1;
+        }
+        $is_have_cache = false;
+        if ($is_have_cache === false){
+            if (isset($params['code'])){
+                $data = db('成品入仓')->alias('a')
+                    ->join('工单_基本资料 b', 'a.jjcp_gdbh = b.Gd_gdbh','left')
+                    ->join('工单_印件资料 c', 'a.jjcp_gdbh = c.Yj_Gdbh','left')
+                    ->where($where)
+                    ->where('LEFT(a.成品编码, 4) = '.$params['code'])
+                    ->field('DISTINCT(a.jjcp_gdbh) as Gd_gdbh,a.jjcp_yjno,rtrim(a.成品编码) as 成品编码,rtrim(a.成品名称) as 成品名称,a.jjcp_sj,a.jjcp_smb,b.计量单位,
+                b.Gd_khdh, b.实际投料,c.yj_Yjno, c.yj_ls')
+                    ->order('b.Gd_khdh,a.成品编码 asc,a.jjcp_sj desc')
+                    ->page($pages)
+                    ->limit($limit)
+                    ->select();
+                $total = db('成品入仓')->alias('a')
+                    ->join('工单_基本资料 b', 'a.jjcp_gdbh = b.Gd_gdbh','left')
+                    ->join('工单_印件资料 c', 'a.jjcp_gdbh = c.Yj_Gdbh','left')
+                    ->where($where)
+                    ->where('LEFT(a.成品编码,4) ='.$params['code'])
+                    ->count();
+            }else{
+                $data = db('成品入仓')->alias('a')
+                    ->join('工单_基本资料 b', 'a.jjcp_gdbh = b.Gd_gdbh','left')
+                    ->join('工单_印件资料 c', 'a.jjcp_gdbh = c.Yj_Gdbh','left')
+                    ->where($where)
+                    ->field('DISTINCT(a.jjcp_gdbh) as Gd_gdbh,a.jjcp_yjno,rtrim(a.成品编码) as 成品编码,rtrim(a.成品名称) as 成品名称,a.jjcp_sj,a.jjcp_smb,b.计量单位,
+                b.Gd_khdh, b.实际投料,c.yj_Yjno, c.yj_ls')
+                    ->order('b.Gd_khdh,a.成品编码 asc,a.jjcp_sj desc')
+                    ->page($pages)
+                    ->limit($limit)
+                    ->select();
+                $total = db('成品入仓')->alias('a')
+                    ->join('工单_基本资料 b', 'a.jjcp_gdbh = b.Gd_gdbh','left')
+                    ->join('工单_印件资料 c', 'a.jjcp_gdbh = c.Yj_Gdbh','left')
+                    ->where($where)
+                    ->count();
+            }
+            foreach ($data as $key => $value){
+                //查出成品数量及日期
+                $cp_sql = "SELECT SUM(jjcp_sl) as cp_sl,MAX(jjcp_sj) as jjcp_sj FROM `成品入仓` WHERE jjcp_gdbh = '{$value['Gd_gdbh']}' GROUP BY jjcp_gdbh";
+                $cp_data = Db::query($cp_sql);
+                $data[$key]['warehousing_num'] = $cp_data[0]['cp_sl'];
+                $data[$key]['warehousing_date'] = substr($cp_data[0]['jjcp_sj'],0,10);
+                //查出进入超节损的工序,有上报产量的工序就进入超节损
+                $gxh_sql = "SELECT sczl_gxh FROM 
+                        (SELECT sczl_gxh FROM 设备_产量计酬 WHERE sczl_gdbh = '{$value['Gd_gdbh']}' 
+                        UNION SELECT sczl_gxh FROM db_sczl WHERE sczl_gdbh = '{$value['Gd_gdbh']}') AS combined_result";
+                $gxh_arr = Db::query($gxh_sql);
+                $gxh_values = array_column($gxh_arr, 'sczl_gxh');
+                $gy_data =db('工单_工艺资料')->where('Gy0_gdbh',$value['Gd_gdbh'])->where('Gy0_gxh','in',$gxh_values)->field('Gy0_计划接货数,Gy0_计划损耗')->select();
+                $arr = [];
+                $plan_loss = [];//工单计划损耗
+                foreach ($gy_data as $k=>$v){
+                    $rate =  round($v['Gy0_计划损耗'] / $v['Gy0_计划接货数'],5);
+                    $arr[$k] = floor($rate * 10000) /10000;
+                    $plan_loss[$k] = $v['Gy0_计划损耗'];
+                }
+                $target_rate =  (1-array_sum($arr))*100;
+                $data[$key]['target_rate'] =$target_rate.'%'; //目标合格率
+                $real_rate = $cp_data[0]['cp_sl'] / ($value['实际投料'] * 10000) *100;
+                $data[$key]['real_rate'] = number_format($real_rate,2) . '%';//实际合格率
+                //奖惩系数及金额
+                $data[$key]['reward_rate'] = '1';
+                $data[$key]['reward_money'] = '';
+                //制程废品
+                $zzfp_data =db('设备_产量计酬')->where('sczl_gdbh',$value['Gd_gdbh'])->field('SUM(sczl_zcfp) as sczl_zcfp')->select();
+                $data[$key]['zcfp'] = $zzfp_data[0]['sczl_zcfp'] * $value['yj_ls'];//制程废品
+                //废品合计
+                $wasteTotal = db('db_qczl')->where('qczl_gdbh',$value['Gd_gdbh'])->sum('qczl_fp');
+                if (empty($wasteTotal)){
+                    $wasteTotal = 0;
+                }
+                $data[$key]['废品合计'] = $wasteTotal + $data[$key]['zcfp'];//废品合计
+                $data[$key]['工单无形损'] = (int)($value['实际投料'] *10000) - $cp_data[0]['cp_sl'] - $data[$key]['废品合计'];//工单无形损
+                $out_sql = "SELECT fp_sl1,fp_sl2,fp_sl3,fp_sl4,fp_sl5,fp_sl6,fp_sl7,fp_sl8,fp_sl9,fp_sl10,fp_sl11,fp_sl12,fp_sl13,
+                        fp_lb1,fp_lb2,fp_lb3,fp_lb4,fp_lb5,fp_lb6,fp_lb7,fp_lb8,fp_lb9,fp_lb10,fp_lb11,fp_lb12,fp_lb13, 
+                        fp_bh1,fp_bh2,fp_bh3,fp_bh4,fp_bh5,fp_bh6,fp_bh7,fp_bh8,fp_bh9,fp_bh10,fp_bh11,fp_bh12,fp_bh13,
+                        fp_gxmc1,fp_gxmc2,fp_gxmc3,fp_gxmc4,fp_gxmc5,fp_gxmc6,fp_gxmc7,fp_gxmc8,fp_gxmc9,fp_gxmc10,fp_gxmc11,fp_gxmc12,fp_gxmc13 
+                        FROM db_qczl WHERE qczl_gdbh = '{$value['Gd_gdbh']}'";
+                $waste_out = Db::query($out_sql);
+                $list = []; //外发废数组
+                $quality = [];//质检废数组
+                $material = [];//材料废数组
+                $change = [];//零头处理数组
+                $j = 0;
+                $m = 0;
+                $n = 0;
+                $l = 0;
+                foreach ($waste_out as $entry) {
+                    for ($i = 1; $i <= 13; $i++) {
+                        $labelKey = "fp_lb" . $i;
+                        $bhKey = "fp_bh" . $i;
+                        $gxmcKey = "fp_gxmc" . $i;
+                        $slKey = "fp_sl" . $i;
+                        if (!empty($entry[$labelKey])) {
+                            if (substr($entry[$gxmcKey],0,2) == '99'){
+                                $list[$j]= $entry[$slKey];
+                                $j++;
+                            }
+                            if (substr($entry[$labelKey],0,1) == 'L' ){
+                                $material[$n]= $entry[$slKey];
+                                $n++;
+                            }
+                            if (substr($entry[$labelKey],0,3) == 'M04' ){
+                                $change[$l]= $entry[$slKey];
+                                $l++;
+                            }
+                        }
+                        if (!empty($entry[$bhKey])) {
+                            if ($entry[$bhKey] != '000000' && $entry[$slKey] > 0){
+                                $quality[$m]= $entry[$slKey];
+                                $m++;
+                            }
+                        }
+                    }
+                }
+                $data[$key]['材料废'] = array_sum($material); //材料废
+                $data[$key]['零头处理'] = array_sum($change); //零头处理
+                $data[$key]['外发废'] = array_sum($list);//外发废
+                $data[$key]['分摊废'] = '';//分摊废
+                $data[$key]['工单计划损耗'] = array_sum($plan_loss);//工单计划损耗
+                $data[$key]['工单质检废'] =  array_sum($quality);  //质检废
+            }
+            $res = [
+                'data'=>$data,
+                'total' => $total
+            ];
+//            Cache::set('OrderSuperLoss/getList'.$params['date'],$res,3600);
+        }else{
+//            $res = Cache::get('OrderSuperLoss/getList'.$params['date']);
+        }
+
+        $this->success('请求成功',$res);
+    }
+    /**
+     * 获取工单超节损工艺
+     * @ApiMethod GET
+     * @params string order
+    */
+    public function getOrderSuperLossGy(){
+        if (Request::instance()->isGet() == false) {
+            $this->error('非法请求');
+        }
+        $params = Request::instance()->param();
+        if (!isset($params['order']) || empty($params['order'])) {
+            $this->error('参数错误');
+        }
+        $sql = "SELECT a.Gy0_gdbh,a.Gy0_yjno,a.Gy0_gxh,rtrim(a.Gy0_gxmc) as Gy0_gxmc,rtrim(a.Add_gxmc) as Add_gxmc,a.Gy0_ls,a.Gy0_Rate0,a.Gy0_Rate1,a.损耗系数,a.Gy0_ms,
+                a.Gy0_计划接货数,a.Gy0_计划损耗,sum(b.sczl_cl) as total_cl,sum(b.sczl_zcfp) as total_fp,sum(c.sczl_cl) as cl,SUM(c.sczl_fp) as fp FROM `工单_工艺资料` a
+                LEFT JOIN `设备_产量计酬` b ON a.Gy0_gdbh = b.sczl_gdbh AND a.Gy0_gxh = b.sczl_gxh
+                LEFT JOIN `db_sczl` c ON a.Gy0_gdbh = c.sczl_gdbh AND a.Gy0_gxh = c.sczl_gxh
+                WHERE a.Gy0_gdbh = '{$params['order']}' GROUP BY a.Gy0_gxh";
+        $data = Db::query($sql);
+        foreach ($data as $key=>$value){
+            if (!empty($value['total_cl'])){
+                $data[$key]['total_cl'] = $value['total_cl'] *$value['Gy0_ls'];
+            }else{
+                $data[$key]['total_cl'] =$value['cl'] *$value['Gy0_ls'];
+            }
+            if (!empty($value['total_fp'])){
+                $data[$key]['total_fp'] = $value['total_fp'] *$value['Gy0_ls'];
+            }else{
+                $data[$key]['total_fp'] = $value['fp'] *$value['Gy0_ls'];
+            }
+            unset($data[$key]['cl']);
+            unset($data[$key]['fp']);
+        }
+        $this->success('请求成功',$data);
+    }
+    /**
+     * 工单超节损统计
+     * @ApiMethod GET
+     * @params string order
+    */
+    public function getOrderSuperLossCount(){
+        if (Request::instance()->isGet() == false) {
+            $this->error('非法请求');
+        }
+        $params = Request::instance()->param();
+        if (!isset($params['order']) || empty($params['order'])) {
+            $this->error('参数错误');
+        }
+        $order = $params['order'];
+        $field = 'Gd_gdbh,rtrim(成品代号) as 成品代号,rtrim(成品名称) as 成品名称,rtrim(销售订单号) as 销售订单号,订单数量,实际投料';
+        $data =db('工单_基本资料')->where('Gd_Gdbh',$order)->where('行号',1)->field($field)->find();
+        //查出成品数量及日期
+        $cp_sql = "SELECT SUM(jjcp_sl) as cp_sl,MAX(jjcp_sj) as jjcp_sj FROM `成品入仓` WHERE jjcp_gdbh = '{$order}' GROUP BY jjcp_gdbh";
+        $cp_data = Db::query($cp_sql);
+        $data['warehousing_num'] = $cp_data[0]['cp_sl'];
+        $data['warehousing_date'] = substr($cp_data[0]['jjcp_sj'],0,10);
+        //查出进入超节损的工序,有上报产量的工序就进入超节损
+        $gxh_sql = "SELECT sczl_gxh FROM 
+                        (SELECT sczl_gxh FROM 设备_产量计酬 WHERE sczl_gdbh = '{$order}' 
+                        UNION SELECT sczl_gxh FROM db_sczl WHERE sczl_gdbh = '{$order}') AS combined_result";
+        $gxh_arr = Db::query($gxh_sql);
+        $gxh_values = array_column($gxh_arr, 'sczl_gxh');
+        $gy_data =db('工单_工艺资料')
+            ->alias('a')
+            ->field([
+                'a.Gy0_yjno', 'a.Gy0_gxh', 'RTRIM(a.Gy0_gxmc) as Gy0_gxmc','RTRIM(a.Add_gxmc) as Add_gxmc', 'a.Gy0_ls', 'a.Gy0_计划接货数',
+                'a.Gy0_计划损耗', 'a.超节损承担比例','SUM(b.sczl_zcfp) as total_fp','SUM(b.sczl_cl) as total_cl','SUM(c.sczl_cl) as cl','SUM(c.sczl_fp) as fp',
+            ])
+            ->join('设备_产量计酬 b', 'a.Gy0_gdbh = b.sczl_gdbh AND a.Gy0_gxh = b.sczl_gxh','left')
+            ->join('db_sczl c', 'a.Gy0_gdbh = c.sczl_gdbh AND a.Gy0_gxh = c.sczl_gxh','left')
+            ->where([
+                'a.Gy0_gdbh' => $order,
+                'a.Gy0_gxh' => ['in', $gxh_values]
+            ])
+            ->group('a.Gy0_gxh')
+            ->select();
+        $arr = [];
+        $plan_loss = [];//工单计划损耗
+        foreach ($gy_data as $k=>$v){
+            $rate =  round($v['Gy0_计划损耗'] / $v['Gy0_计划接货数'],5);
+            $arr[$k] = floor($rate * 10000) /10000;
+            $plan_loss[$k] = $v['Gy0_计划损耗'];
+        }
+        $target_rate =  (1-array_sum($arr))*100;
+        $data['target_rate'] =$target_rate.'%'; //目标合格率
+        $real_rate = $cp_data[0]['cp_sl'] / ($data['实际投料'] * 10000) *100;
+        $data['real_rate'] = number_format($real_rate,2) . '%';//实际合格率
+        //制程废品
+        $zzfp_data =db('设备_产量计酬')->where('sczl_gdbh',$order)->field('SUM(sczl_zcfp) as sczl_zcfp')->select();
+        //联数
+        $ls =db('工单_印件资料')->where('Yj_Gdbh',$order)->value('yj_ls');
+        //制程废品*ls
+        $data['zcfp'] = $zzfp_data[0]['sczl_zcfp'] * $ls;
+        //废品数量
+        $wasteTotal = db('db_qczl')->where('qczl_gdbh',$order)->sum('qczl_fp');
+        if (empty($wasteTotal)){
+            $wasteTotal = 0;
+        }
+        //废品合计
+        $waste_total = $data['zcfp'] + $wasteTotal;
+        //工单无形损
+        $data['intangible_loss'] = $data['实际投料'] *10000 - $cp_data[0]['cp_sl'] - $waste_total;
+        $out_sql = "SELECT fp_sl1,fp_sl2,fp_sl3,fp_sl4,fp_sl5,fp_sl6,fp_sl7,fp_sl8,fp_sl9,fp_sl10,fp_sl11,fp_sl12,fp_sl13,
+                        fp_lb1,fp_lb2,fp_lb3,fp_lb4,fp_lb5,fp_lb6,fp_lb7,fp_lb8,fp_lb9,fp_lb10,fp_lb11,fp_lb12,fp_lb13, 
+                        fp_bh1,fp_bh2,fp_bh3,fp_bh4,fp_bh5,fp_bh6,fp_bh7,fp_bh8,fp_bh9,fp_bh10,fp_bh11,fp_bh12,fp_bh13,
+                        fp_gxmc1,fp_gxmc2,fp_gxmc3,fp_gxmc4,fp_gxmc5,fp_gxmc6,fp_gxmc7,fp_gxmc8,fp_gxmc9,fp_gxmc10,fp_gxmc11,fp_gxmc12,fp_gxmc13
+                        FROM db_qczl WHERE qczl_gdbh = '{$order}'";
+        $waste_out = Db::query($out_sql);
+        $list = []; //外发废数组
+        $quality = [];//质检废数组
+        $material = [];//材料废数组
+        $change = [];//零头处理数组
+        $j = 0;
+        $m = 0;
+        $n = 0;
+        $l = 0;
+        foreach ($waste_out as $entry) {
+            for ($i = 1; $i <= 13; $i++) {
+                $labelKey = "fp_lb" . $i;
+                $bhKey = "fp_bh" . $i;
+                $gxmcKey = "fp_gxmc" . $i;
+                $slKey = "fp_sl" . $i;
+                if (!empty($entry[$labelKey])) {
+                    if (substr($entry[$gxmcKey],0,2) == '99'){
+                        $list[$j]= $entry[$slKey];
+                        $j++;
+                    }
+                    if (substr($entry[$labelKey],0,1) == 'L' ){
+                        $material[$n]= $entry[$slKey];
+                        $n++;
+                    }
+                    if (substr($entry[$labelKey],0,3) == 'M04' ){
+                        $change[$l]= $entry[$slKey];
+                        $l++;
+                    }
+                }
+                if (!empty($entry[$bhKey])) {
+                    if ($entry[$bhKey] != '000000' && $entry[$slKey] > 0){
+                        $quality[$m]= $entry[$slKey];
+                        $m++;
+                    }
+                }
+
+            }
+        }
+        $data['材料废'] = array_sum($material); //材料废
+        $data['零头处理'] = array_sum($change); //零头处理
+        $data['外发废'] = array_sum($list);//外发废
+        $data['工单质检废'] =  array_sum($quality);//质检废
+//        $data['分摊废'] = '';//分摊废
+        $plan_total =db('工单_工艺资料')->where(['Gy0_gdbh' => $order, 'Gy0_gxh' => ['in', $gxh_values]])->value('SUM(Gy0_计划损耗)');
+        //单据列表最后统计
+        $total = [];
+        $total['plan_loss'] = 0;
+        $total['total_fp'] = 0;
+        $total['waste_quality'] = 0;
+        $total['waste_intangible'] = 0;
+        //按工序打印
+        if ($params['type'] == 1){
+            $total['total_waste'] = 0;
+            $total['loss'] = 0;
+            foreach ($gy_data as $k=>$item){
+                $gy_data[$k]['waste_quality'] = 0;
+                $gy_data[$k]['total_fp'] = $item['total_fp'] * $item['Gy0_ls'];
+                $gy_data[$k]['total_cl'] = $item['total_cl'] * $item['Gy0_ls'];
+                $gy_data[$k]['intangible_loss'] = round($item['Gy0_计划损耗'] / $plan_total * $data['intangible_loss']);
+                foreach ($waste_out as $entry) {
+                    for ($i = 1; $i <= 13; $i++) {
+                        $gxmcKey = "fp_gxmc" . $i;
+                        $slKey = "fp_sl" . $i;
+                        if ((int)substr($entry[$gxmcKey],0,2) == $item['Gy0_gxh']){
+                            $gy_data[$k]['waste_quality'] += $entry[$slKey];
+
+                        }
+                    }
+                }
+                $gy_data[$k]['total_waste'] = $gy_data[$k]['waste_quality'] + $gy_data[$k]['intangible_loss'] +  $gy_data[$k]['total_fp'];
+                $gy_data[$k]['loss'] = $item['Gy0_计划损耗'] - $gy_data[$k]['total_waste'];
+                $gy_data[$k]['loss_rate'] = number_format($gy_data[$k]['loss'] / $item['Gy0_计划接货数'],4) * 100 .'%';
+                $gy_data[$k]['target_loss_rate'] = number_format($item['Gy0_计划损耗'] / $item['Gy0_计划接货数'],4) * 100 .'%';
+                $gy_data[$k]['actual_loss_rate'] = number_format($gy_data[$k]['total_waste'] / $item['Gy0_计划接货数'],4) * 100 .'%';
+                $gy_data[$k]['超节损承担比例'] = number_format($item['超节损承担比例'],4) * 100 .'%';
+
+                $total['plan_loss'] += $gy_data[$k]['Gy0_计划损耗'];
+                $total['total_fp'] += $gy_data[$k]['total_fp'];
+                $total['waste_quality'] += $gy_data[$k]['waste_quality'];
+                $total['waste_intangible'] += $gy_data[$k]['intangible_loss'];
+                $total['total_waste'] += $gy_data[$k]['total_waste'];
+                $total['loss'] += $gy_data[$k]['loss'];
+            }
+            $data['gy_data'] = $gy_data;
+            $data['total'] = $total;
+            $this->success('请求成功',$data);
+        }else{ //按班组打印
+            //总产量数据
+            $total_cl_data = \db('工单_工艺资料')->alias('a')
+                ->field(['a.Gy0_yjno', 'a.Gy0_gxh','a.Gy0_ls', 'SUM(b.sczl_cl) as total_cl', 'SUM(c.sczl_cl) as cl'])
+                ->join('设备_产量计酬 b', 'a.Gy0_gdbh = b.sczl_gdbh AND a.Gy0_gxh = b.sczl_gxh','left')
+                ->join('db_sczl c', 'a.Gy0_gdbh = c.sczl_gdbh AND a.Gy0_gxh = c.sczl_gxh','left')
+                ->where([
+                    'a.Gy0_gdbh' => $order,
+                    'a.Gy0_gxh' => ['IN', $gxh_values]
+                ])
+                ->group('b.sczl_gxh')
+                ->order('a.Gy0_gxh')
+                ->select();
+            //按班组分的产量数据
+            $gy_data =db('工单_工艺资料')
+                ->alias('a')
+                ->field([
+                    'a.Gy0_yjno', 'a.Gy0_gxh', 'a.Gy0_ls', 'a.Gy0_计划损耗', 'a.超节损承担比例', 'b.sczl_gxmc',
+                    'SUM(b.sczl_zcfp) as sczl_zcfp', 'SUM(b.sczl_cl) as total_cl',
+                    'b.sczl_bh1', 'b.sczl_bh2', 'b.sczl_bh3', 'b.sczl_bh4', 'b.sczl_bh5', 'b.sczl_bh6',
+                    'b.sczl_bh7', 'b.sczl_bh8', 'b.sczl_bh9', 'b.sczl_bh10',
+                    'rtrim(c.sczl_gxmc) as gxmc', 'SUM(c.sczl_cl) as cl', 'SUM(c.sczl_fp) as fp', 'c.sczl_bh1 as sczl_bh'
+                ])
+                ->join('设备_产量计酬 b', 'a.Gy0_gdbh = b.sczl_gdbh AND a.Gy0_gxh = b.sczl_gxh','left')
+                ->join('db_sczl c', 'a.Gy0_gdbh = c.sczl_gdbh AND a.Gy0_gxh = c.sczl_gxh','left')
+                ->where([
+                    'a.Gy0_gdbh' => $order,
+                    'a.Gy0_gxh' => ['in', $gxh_values]
+                ])
+                ->group('b.sczl_gxh, b.sczl_bh1, b.sczl_bh2, b.sczl_bh3, b.sczl_bh4, c.sczl_bh')
+                ->order('a.Gy0_gxh, b.UniqId DESC, c.UniqId DESC')
+                ->select();
+            foreach ($gy_data as $key=>$value){
+                $gy_data[$key]['Gy0_yjno'] = $value['Gy0_yjno'] > 10 ? $value['Gy0_yjno'] : '0'.$value['Gy0_yjno'];
+                //每道工序的产量(按班组分)
+                $gy_data[$key]['total_cl'] = $value['total_cl'] * $value['Gy0_ls'];
+                if (empty($value['total_cl'])){
+                    $gy_data[$key]['total_cl'] = $value['cl'] * $value['Gy0_ls'];
+                }
+                //计算每道工序的计划损耗
+                foreach ($total_cl_data as $k=>$v){
+                    //每道工序的总产量
+                    $cl = $v['total_cl'] * $v['Gy0_ls'];
+                    if (empty($cl)){
+                        $cl = $v['cl'] * $v['Gy0_ls'];
+                    }
+                    if ($value['Gy0_yjno'] == $v['Gy0_yjno'] && $value['Gy0_gxh'] == $v['Gy0_gxh']){
+                        $gy_data[$key]['计划损耗'] = round($gy_data[$key]['total_cl'] / $cl  * $value['Gy0_计划损耗']);
+                    }
+                }
+                //每道工序的制程废品(按班组分)
+                $gy_data[$key]['sczl_zcfp'] = $value['sczl_zcfp'] * $value['Gy0_ls'];
+                if (empty($value['sczl_zcfp'])){
+                    $gy_data[$key]['sczl_zcfp'] = $value['fp'] * $value['Gy0_ls'];
+                }
+                //计算每道工序的质检废(按班组)
+                $gy_data[$key]['sczl_gxmc'] = $value['sczl_gxmc'];
+                if (empty($value['sczl_gxmc'])){
+                    $gy_data[$key]['sczl_gxmc'] = $value['gxmc'];
+                }
+                if (empty($value['sczl_bh1']) || is_null($value['sczl_bh1'])){
+                    $value['sczl_bh1'] = $value['sczl_bh'];
+                }
+                $gy_data[$key]['sczl_bh1'] = $value['sczl_bh1'];
+                $gy_data[$key]['waste_quality'] = 0;
+                foreach ($waste_out as $entry) {
+                    for ($i = 1; $i <= 13; $i++) {
+                        $gxmcKey = "fp_gxmc" . $i;
+                        $slKey = "fp_sl" . $i;
+                        $bhKey = "fp_bh" . $i;
+                        if ((int)substr($entry[$gxmcKey],0,2) == $value['Gy0_gxh'] && $entry[$bhKey] == $value['sczl_bh1']){
+                            $gy_data[$key]['waste_quality'] += $entry[$slKey];
+
+                        }
+                    }
+                }
+                //无形损分摊
+                $gy_data[$key]['intangible_loss'] = round($gy_data[$key]['计划损耗'] / $plan_total * $data['intangible_loss']);
+                //节损数量
+                $total_waste = $gy_data[$key]['waste_quality'] + $gy_data[$key]['intangible_loss'] +  $gy_data[$key]['sczl_zcfp'];
+                $gy_data[$key]['loss'] = $gy_data[$key]['计划损耗'] - $total_waste;
+                $gy_data[$key]['超节损承担比例'] = number_format($value['超节损承担比例'],4) * 100 .'%';
+                //班组成员
+                $nameArr = [];
+                for ($j = 1; $j <= 10; $j++) {
+                    $bhKey = "sczl_bh" . $j;
+                    if (!empty($value[$bhKey])){
+                        $name = \db('人事_基本资料')->where('员工编号',$value[$bhKey])->value('rtrim(员工姓名)');
+                        array_push($nameArr,$name);
+                    }
+                }
+
+                $gy_data[$key]['member'] = implode(' ',$nameArr);
+                unset($gy_data[$key]['Gy0_计划损耗']);
+                unset($gy_data[$key]['gxmc']);
+                unset($gy_data[$key]['cl']);
+                unset($gy_data[$key]['fp']);
+                unset($gy_data[$key]['sczl_bh']);
+                $total['plan_loss'] += $gy_data[$key]['计划损耗'];
+                $total['total_fp'] += $gy_data[$key]['sczl_zcfp'];
+                $total['waste_quality'] += $gy_data[$key]['waste_quality'];
+                $total['waste_intangible'] += $gy_data[$key]['intangible_loss'];
+            }
+            $data['gy_data'] = $gy_data;
+            $data['total'] = $total;
+            $this->success('请求成功',$data);
+        }
+    }
+    /**
+     * 获取工单工艺
+     * @ApiMethod GET
+     * @params string order
+    */
+    public function getOrderGy(){
+        if (Request::instance()->isGet() == false) {
+            $this->error('非法请求');
+        }
+        $params = Request::instance()->param();
+        if (!isset($params['order']) || empty($params['order'])) {
+            $this->error('参数错误');
+        }
+        $order = $params['order'];
+        $field = 'Gy0_yjno,Gy0_gxh,rtrim(Gy0_gxmc) as Gy0_gxmc,rtrim(Add_gxmc) as Add_gxmc,Gy0_rate0,Gy0_rate1,损耗系数,无形损承担比例 as loss_one,超节损承担比例 as loss_two,超节损核算单价 as loss_thr,UniqId';
+        $data =db('工单_工艺资料')->where('Gy0_gdbh',$order)->field($field)->select();
+        $this->success('请求成功',$data);
+    }
+    /**
+     * 更新工单工艺
+     * @ApiMethod POST
+     * @params array data
+    */
+    public function updateOrderGy(){
+        if (Request::instance()->isPost() == false) {
+            $this->error('非法请求');
+        }
+        $params = Request::instance()->post();
+        if (!isset($params) || !isset($params[0]['UniqId'])){
+            $this->error('参数不能为空');
+        }
+        $i = 0;
+        foreach ($params as $key=>$value){
+            $data = [];
+            $data['无形损承担比例'] = $value['loss_one'];
+            $data['超节损承担比例'] = $value['loss_two'];
+            $data['超节损核算单价'] = $value['loss_thr'];
+            $sql =db('工单_工艺资料')->where('UniqId',$value['UniqId'])->fetchSql(true)->update($data);
+            $res = Db::query($sql);
+            if ($res !== false){
+                $i++;
+            }
+        }
+        if ($i !== 0){
+            $this->success('更新成功');
+        }else{
+            $this->error('更新失败');
+        }
+    }
+    /**
+     * 获取工单印件考核资料
+     * @ApiMethod GET
+     * @params string order
+    */
+    public function getOrderYj(){
+        if (Request::instance()->isGet() == false) {
+            $this->error('非法请求');
+        }
+        $params = Request::instance()->request();
+        if (!isset($params['order']) || empty($params['order'])) {
+            $this->error('参数错误');
+        }
+        $data =db('工单_印件资料')->where('Yj_gdbh',$params['order'])->field('Yj_gdbh,rtrim(yj_Yjdh) as yj_Yjdh,yj_Yjno,rtrim(yj_yjmc) as yj_yjmc,质量考核')->find();
+        $this->success('请求成功',$data);
+    }
+    /**
+     * 更新工单印件考核资料
+     * @ApiMethod POST
+     * @params array data
+    */
+    public function updateOrderYj(){
+        if (Request::instance()->isPost() == false) {
+            $this->error('非法请求');
+        }
+        $params = Request::instance()->request();
+        if (!isset($params['order'])){
+            $this->error('参数不能为空');
+        }
+        if (!isset($params['yj_yjno'])){
+            $this->error('参数不能为空');
+        }
+        if (!isset($params['examine'])){
+            $this->error('参数不能为空');
+        }
+        $where['Yj_gdbh'] = $params['order'];
+        $where['yj_Yjno'] = $params['yj_yjno'];
+        $res =db('工单_印件资料')->where($where)->setField('质量考核',$params['examine']);
+        if ($res !== false){
+            $this->success('更新成功');
+        }else{
+            $this->error('更新失败');
+        }
+    }
+    /**
+     * 获取修正工单实际投料列表
+     * @ApiMethod GET
+     * @params string year
+     * @params string month
+    */
+    public function getOrderFeedList(){
+        if (Request::instance()->isGet() == false) {
+            $this->error('非法请求');
+        }
+        $params = Request::instance()->request();
+        if (empty($params['year']) || empty($params['month'])) {
+            $this->error('参数错误');
+        }
+        $search = $params['year'].'.'.$params['month'];
+        $field = "a.Gd_gdbh,rtrim(c.yj_yjdh) as yj_yjdh,c.yj_Yjno, c.yj_ks,c.yj_ls,rtrim(c.yj_zzdh) as yj_zzdh,
+                  rtrim(b.BOM_物料名称) as BOM_物料名称,rtrim(c.yj_tlgg) as yj_tlgg,rtrim(b.BOM_投料单位) as BOM_投料单位,a.订单数量,c.yj_平张投料, b.BOM_实际用量,a.实际投料,a.投料确认,a.UniqId";
+        $data =db('工单_基本资料')->alias('a')
+            ->join('工单_印件资料 c','a.Gd_gdbh = c.Yj_Gdbh','left')
+            ->join('工单_bom资料 b','c.Yj_Gdbh = b.BOM_工单编号 AND c.yj_zzdh = b.BOM_物料编码','left')
+            ->where('a.投料确认','like','%'.$search.'%')
+            ->field($field)
+            ->group('a.Gd_gdbh')
+            ->order('b.BOM_投料单位,a.UniqId asc')
+            ->select();
+        if (empty($data)){
+            $this->success('请求成功');
+        }
+        foreach ($data as $key=>$value){
+            $len = stripos($value['yj_tlgg'],'/');
+            if ($len){
+                $name = substr($value['yj_tlgg'],0,$len);
+                $len_two = stripos($value['yj_tlgg'],'(');
+                if ($len_two){
+                    $name = substr($name,0,$len_two);
+                }
+                $data[$key]['yj_tlgg'] = $name;
+            }
+            $data[$key]['rate'] = '';
+        }
+        $this->success('请求成功',$data);
+    }
+    /**
+     * 更新工单实际投料
+     * @ApiMethod POST
+     * @params int UniqId
+     * @params string number
+    */
+    public function updateOrderFeed(){
+        if (Request::instance()->isPost() == false) {
+            $this->error('非法请求');
+        }
+        $params = Request::instance()->post();
+        if (!isset($params[0]['UniqId']) || empty($params[0]['UniqId'])){
+            $this->error('参数错误');
+        }
+        $i = 0;
+        foreach ($params as $key=>$value){
+            if (!empty($value['number'])){
+                $info = db('工单_基本资料')->where('UniqId',$value['UniqId'])->value('Gd_gdbh');
+                $res_sql = db('工单_基本资料')->where('UniqId',$value['UniqId'])->fetchSql(true)->setField('实际投料',$value['number']);
+                $res = Db::query($res_sql);
+                $data['yj_实际投料'] = $value['number'];
+                $yj_sql =db('工单_印件资料')->where('Yj_Gdbh',$info)->fetchSql(true)->update($data);
+                $yjRes = Db::query($yj_sql);
+                if (!$res && !$yjRes){
+                    $i++;
+                }
+            }
+        }
+        if ($i != 0){
+            $this->success('更新成功');
+        }else{
+            $this->error('更新失败');
+        }
+    }
+    /**
+     * 工单工序产量统计
+     * @ApiMethod GET
+     * @params string order
+    */
+    public function getOrderProcessCount(){
+        if (Request::instance()->isGet() == false) {
+            $this->error('非法请求');
+        }
+        $params = Request::instance()->request();
+        if (empty($params['order']) || empty($params['order'])) {
+            $this->error('参数错误');
+        }
+        $order = $params['order'];
+        $sql = "SELECT a.Gy0_yjno,a.Gy0_gxh,rtrim(a.Gy0_gxmc) as Gy0_gxmc,rtrim(a.Add_gxmc) as Add_gxmc,a.Gy0_计划接货数, a.Gy0_ls,a.Gy0_sbbh,a.PD_WG,SUM(b.sczl_cl) as sczl_cl,
+                SUM(b.sczl_zcfp) as sczl_zcfp,SUM(b.sczl_来料少数) as 来料异常,COUNT(DISTINCT b.sczl_num) as process_num,b.sczl_Pgcl,SUM(c.sczl_cl) as cl,b.sczl_rq
+                FROM `工单_工艺资料` a
+                LEFT JOIN `设备_产量计酬` b ON a.Gy0_gdbh = b.sczl_gdbh AND a.Gy0_gxh = b.sczl_gxh
+                LEFT JOIN db_sczl c ON a.Gy0_gdbh = c.sczl_gdbh AND a.Gy0_gxh = c.sczl_gxh
+                WHERE a.Gy0_gdbh = '{$order}' GROUP BY a.Gy0_gxh";
+        $data = Db::query($sql);
+        //手检数据
+        $handData =db('db_手工检验')->where('sczl_gdbh',$order)->field('sum(sczl_cl) as cl,rtrim(sczl_yjgx) as sczl_gxh')->select();
+        //包装及成品防护数据
+        $sql = "SELECT sczl_gdbh1,sczl_gdbh2,sczl_gdbh3,sczl_gdbh4,sczl_gdbh5,sczl_gdbh6,rtrim(sczl_gxmc1) as sczl_gxmc1,rtrim(sczl_gxmc2) as sczl_gxmc2,
+                rtrim(sczl_gxmc3) as sczl_gxmc3,rtrim(sczl_gxmc4) as sczl_gxmc4,rtrim(sczl_gxmc5) as sczl_gxmc5,rtrim(sczl_gxmc6) as sczl_gxmc6,
+                sczl_cl1,sczl_cl2,sczl_cl3,sczl_cl4,sczl_cl5,sczl_cl6,sczl_PgCl1,sczl_PgCl2,sczl_PgCl3,sczl_PgCl4,sczl_PgCl5,sczl_PgCl6
+                FROM `mesdb`.`db_包装计件` WHERE `sczl_gdbh1` LIKE '%{$order}%' OR `sczl_gdbh2` LIKE '%{$order}%' 
+                OR `sczl_gdbh3` LIKE '%{$order}%' OR `sczl_gdbh4` LIKE '%{$order}%' OR `sczl_gdbh5` LIKE '%{$order}%' OR `sczl_gdbh6` LIKE '%{$order}%'";
+        $package = Db::query($sql);
+        $list = [];
+        $j = 0;
+        foreach ($package as $value){
+            for ($i = 1; $i <= 6; $i++) {
+                $gdbhlKey = "sczl_gdbh" . $i;
+                $gxmcKey = "sczl_gxmc" . $i;
+                $clKey = "sczl_cl" . $i;
+                $pgclKey = "sczl_PgCl" . $i;
+                if ($value[$gdbhlKey] == '2311743' && $value[$clKey] > 0) {
+                    $list[$j]['sczl_gdbh'] = $value[$gdbhlKey];
+                    $list[$j]['sczl_gxmc'] =  $value[$gxmcKey];
+                    $list[$j]['sczl_cl'] =  $value[$clKey];
+                    $list[$j]['sczl_PgCl'] =  $value[$pgclKey];
+                    $j++;
+                }
+            }
+        }
+        // 创建一个关联数组,用于存储相同 sczl_gxmc 的值和对应的乘积之和
+        $sumArray = [];
+        foreach ($list as $item) {
+            $key = $item['sczl_gxmc'];
+            $cl = floatval($item['sczl_cl']);
+            $pgCl = intval($item['sczl_PgCl']);
+            $product = $cl * $pgCl;
+            if (!isset($sumArray[$key])) {
+                $sumArray[$key] = 0;
+            }
+            $sumArray[$key] += $product;
+        }
+        $handGxh = substr($handData[0]['sczl_gxh'],-2);
+        foreach ($data as $key=>$item){
+            $data[$key]['折算车头产量'] = round($item['Gy0_计划接货数']/$item['Gy0_ls']);
+            $data[$key]['制程废品率'] = '';
+            if ($item['sczl_zcfp'] > 0){
+                $data[$key]['制程废品率'] = number_format($item['sczl_zcfp']/$item['sczl_cl']*100,4).'%';
+            }
+            if ($item['cl'] > 0){
+                $data[$key]['sczl_cl'] = $item['cl'];
+            }
+            if ($item['sczl_Pgcl'] > 0){
+                $data[$key]['sczl_cl'] = $item['sczl_cl'] * $item['sczl_Pgcl'];
+            }
+            if ($item['Gy0_gxh'] == (int)$handGxh){
+                $data[$key]['sczl_cl'] = $handData[0]['cl'];
+            }
+            foreach ($sumArray as $k=>$v){
+                if ($item['Gy0_gxmc'] == $k){
+                    $data[$key]['sczl_cl'] = $v;
+                }
+            }
+            if (substr($item['PD_WG'],0,4) == '1900'){
+                $data[$key]['PD_WG'] = '计划';
+            }else{
+                $data[$key]['PD_WG'] = '完工';
+            }
+        }
+        $this->success('请求成功',$data);
+    }
+}

+ 1614 - 0
application/api/controller/WorkOrder.php

@@ -0,0 +1,1614 @@
+<?php
+
+namespace app\api\controller;
+
+
+use app\common\controller\Api;
+use Monolog\Handler\IFTTTHandler;
+use think\Db;
+use think\Request;
+
+/**
+ * 工单资料管理
+ */
+class WorkOrder extends Api
+{
+    protected $noNeedLogin = ['*'];
+    protected $noNeedRight = ['*'];
+
+    /**
+     * 工单资料菜单列表
+     *
+     * @ApiMethod (GET)
+     * @return false|string
+     * @throws \think\Exception
+     */
+    public function DataList()
+    {
+        if ($this->request->isGet() === false){
+            $this->error('请求错误');
+        }
+        //获取总计划中数量和总生产中数量
+        $productingAll = \db('工单_基本资料')->where('成品代号','<>','')->where('行号','1')->where('gd_statu','2-生产中')->cache(true)->count();
+        $progressAll = \db('工单_基本资料')->where('成品代号','<>','')->where('行号','1')->where('gd_statu','3-计划中')->cache(true)->count();
+        $data = [
+            'productingAll' => $productingAll,
+            'progressAll' => $progressAll
+        ];
+//        $sql = "SELECT
+//                    SUBSTRING( `成品代号`, 1, 4 ) AS prefix,
+//                    rtrim( Gd_khmc ) AS khmc,
+//                    RTRIM( `Gd_客户名称` ) AS 客户名称
+//                FROM
+//                    `工单_基本资料`
+//                WHERE
+//                    `成品代号` <> ''
+//                    AND ( `Gd_客户名称` <> '' OR Gd_khmc <> '' )
+//                GROUP BY
+//                    prefix
+//                ORDER BY
+//                    prefix";
+        $sql = "SELECT DISTINCT
+                    (客户编号),rtrim(客户名称 ) as 客户名称
+                FROM
+                    `产品_基本资料` 
+                GROUP BY
+                    客户编号
+                order by 
+                    客户编号";
+        $list = \db()->query($sql);
+        if (empty($list)){
+            $this->success('',[]);
+        }
+        foreach ($list as $key=>$value){
+            $value['客户编号'] = rtrim($value['客户编号']);
+            if ($value['客户编号'] == '1098'){
+                $value['客户名称'] = '打样专用';
+            }
+            //这条sql查出来的数据可能不对,试一下以下sql
+            //SELECT COUNT(*) FROM `工单_基本资料` WHERE (SUBSTRING( `成品代号`, 1, 4 ) = '1001' OR (`Gd_客户名称`='浙江中烟' AND `Gd_客户代号` = '1001')) AND gd_statu = '2-生产中' AND `行号` = '1'
+            $productIng = \db('工单_基本资料')->where('行号','1')->where('成品代号','LIKE',rtrim($value['客户编号']).'%')->where('gd_statu','2-生产中')->count();
+            $proGress = \db('工单_基本资料')->where('行号','1')->where('成品代号','LIKE',rtrim($value['客户编号']).'%')->where('gd_statu','3-计划中')->count();
+            $string = '';
+            if ($productIng != 0){
+                $string = $string."生产中:".$productIng;
+            }
+            if ($proGress != 0){
+                $string = $string."计划中:".$proGress;
+            }
+            if ($string !== ''){
+//                $data[$key] = $value['prefix'].'【'.$string.'】'.($value['客户名称']!==''?$value['客户名称']:$value['khmc']);
+                $data[$key] = $value['客户编号'].'【'.$string.'】'.$value['客户名称'];
+            }else{
+//                $data[$key] = $value['prefix'].($value['客户名称']!==''?$value['客户名称']:$value['khmc']);
+                $data[$key] = $value['客户编号'].$value['客户名称'];
+            }
+        }
+        $this->success('成功',$data);
+    }
+
+    /**
+     * 工单基本资料列表
+     * @ApiMethod (GET)
+     * @param string $limit 查询长度
+     * @param string $Gd_khdh 客户代号
+     * @param string $startTime 接单日期开始时间
+     * @param string $endTime  接单日期结束时间
+     * @return \think\response\Json
+     * @throws \think\exception\DbException
+     */
+    public function WorkList()
+    {
+        if ($this->request->isGet() === false){
+            $this->error('请求错误');
+        }
+        $search = input('search');
+        $clientNumber = input('Gd_khdh');
+        $startTime = input('start');
+        $endTime = input('end');
+        $page = input('page');
+        $limit = input('limit');
+        $where = [];
+        if (!empty($clientNumber)){
+            $where['成品代号'] = ['like',$clientNumber.'%'];
+        }
+        if (!empty($workOrder)){
+            $where['Gd_gdbh'] = $workOrder;
+        }
+        if (!empty($productCode)){
+            $where['Gd_cpdh'] = $productCode;
+        }
+        if (!empty($search)){
+            $where['Gd_lx|Gd_gdbh|Gd_客户代号|Gd_客户名称|Gd_khdh|Gd_khmc|Gd_cpdh|Gd_cpmc|成品代号|成品名称|产品版本号'] = ['like','%'.$search.'%'];
+        }
+        if (!empty($startTime) && !empty($endTime)){
+            $where['接单日期'] = ['between',[$startTime,$endTime]];
+        }
+        $total = \db('工单_基本资料')->where($where)->count();
+        $list = \db('工单_基本资料')
+            ->where($where)
+            ->order('Gd_statu desc')
+            ->limit(($page-1)*$limit,$limit)
+            ->select();
+        //工单基本资料数据整理
+        $data = [];
+        foreach ($list as $key=>$value){
+            $data[$key] = [
+                '工单编号' => rtrim($value['Gd_gdbh']),
+                '生产分类' => rtrim($value['Gd_生产分类']),
+                '销售订单号' => rtrim($value['销售订单号']),
+                '产品代号' => rtrim($value['Gd_cpdh']),
+                '产品名称' => rtrim($value['Gd_cpmc']),
+                '订单数量' => rtrim($value['订单数量']),
+                '单位' => rtrim($value['计量单位']),
+                '折合大箱' => rtrim((int)$value['投料大箱']),
+                '投料率' => rtrim($value['投料率']),
+                '平均合格率' => '',
+                '开单日期' => date('Y-m-d',strtotime(rtrim($value['接单日期']))),
+                '交货日期' => date('Y-m-d',strtotime(rtrim($value['交货日期']))),
+                '工单类型' => rtrim($value['Gd_lx']),
+                '工单状态' => rtrim($value['gd_statu']),
+                '当前生产工序' => '',
+                '产量提交时间' =>  '',
+                '建档用户' => rtrim($value['Sys_id']),
+                '建档时间' => rtrim($value['Sys_rq']),
+                '更新时间' => rtrim($value['Mod_rq']),
+                'Uniqid' => rtrim($value['Uniqid'])
+            ];
+            $number = \db('工单_工艺资料')->where('Gy0_gdbh',$data[$key]['工单编号'])->count();
+            if ($number === 0){
+                $data[$key]['status'] = '*';
+            }else{
+                $data[$key]['status'] = '';
+            }
+        }
+        $this->success('成功',['data'=>$data,'total'=>$total]);
+    }
+
+    /**
+     * 工单详情
+     * @ApiMethod  (GET)
+     * @param  void
+     * @return void
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+    public function workOrderListDetail()
+    {
+        if ($this->request->isGet() === false){
+            $this->error('请求错误');
+        }
+        $Gd_gdbh = input('Gd_gdbh');
+        if (empty($Gd_gdbh)){
+            $this->error('参数错误');
+        }
+        $data = [];
+        //印件资料
+        $printList = \db('工单_印件资料')
+            ->where('Yj_Gdbh',$Gd_gdbh)
+//            ->cache(true,84600)
+            ->select();
+        if (!empty($printList)){
+            foreach ($printList as $key=>$value){
+                $data['printList'][$key] = [
+                    '印件号' => rtrim($value['yj_Yjno']),
+                    '印件代号' => rtrim($value['yj_Yjdh']),
+                    '印件名称' => rtrim($value['yj_yjmc']),
+                    '纸张代号' => rtrim($value['yj_zzdh']),
+                    '纸张名称' => rtrim($value['yj_zzmc']),
+                    '投料规格' => rtrim($value['yj_tlgg']),
+                    '平张投料' => rtrim($value['yj_平张投料']),
+                    '开料规格' => rtrim($value['yj_klgg']),
+                    '开数*联数' => rtrim($value['yj_ks']).'*'.rtrim($value['yj_ls']),
+                    '建档用户' => rtrim($value['Sys_id']),
+                    '建档时间' => rtrim($value['Sys_rq']),
+                    '更新时间' => rtrim($value['Mod_rq']),
+                    'zzdh1'  => rtrim($value['yj_zzdh1']),
+                    'zzdh2'  => rtrim($value['yj_zzdh2']),
+                    'zzdh3'  => rtrim($value['yj_zzdh3']),
+                    'zzdh4'  => rtrim($value['yj_zzdh4']),
+                    'zzmc1'  => rtrim($value['yj_zzmc1']),
+                    'zzmc2'  => rtrim($value['yj_zzmc2']),
+                    'zzmc3'  => rtrim($value['yj_zzmc3']),
+                    'zzmc4'  => rtrim($value['yj_zzmc4']),
+                    '订单数量' => rtrim($value['yj_成品数量']),
+                    '万小张' => rtrim($value['yj_实际投料']),
+                    '开数' => rtrim($value['yj_ks']),
+                    '联数' => rtrim($value['yj_ls']),
+                    '核算规格' => rtrim($value['Yj_核算规格']),
+                    '备注' => rtrim($value['yj_desc']),
+                    'Uniqid' => rtrim($value['Uniqid'])
+                ];
+            }
+        }else{
+            $data['printList'] = [];
+        }
+
+        //工艺资料
+        $processList = \db('工单_工艺资料')
+            ->where('Gy0_gdbh',$Gd_gdbh)
+//            ->cache(true,84600)
+            ->select();
+        if (!empty($processList)){
+            foreach ($processList as $key=>$value){
+                if ($value['Gy0_yjno']<10){
+                    $value['Gy0_yjno'] = '0'.$value['Gy0_yjno'];
+                }
+                if ($value['Gy0_gxh']<10){
+                    $value['Gy0_gxh'] = '0'.$value['Gy0_gxh'];
+                }
+                if ((int)$value['Gy0_ms'] === 0){
+                    $scrap = ceil(($value['Gy0_Rate0']+((int)($value['Gy0_计划接货数']/$value['Gy0_ls']))*$value['Gy0_Rate1'])*$value['损耗系数']);
+                }else{
+                    $scrap = ceil(($value['Gy0_Rate0']+((int)($value['Gy0_计划接货数']/$value['Gy0_ls']))*$value['Gy0_Rate1'])*$value['损耗系数']*$value['Gy0_ms']);
+                }
+                $number = round(($scrap/((int)($value['Gy0_计划接货数']/$value['Gy0_ls'])))*100,2).'%';
+                if ($value['PD_WG'] !== '1900-01-01 00:00:00'){
+                    $status = '已完工';
+                }else{
+                    $status = '未完工';
+                }
+                $data['processList'][$key] = [
+                    '重点工序' => rtrim($value['重点工序']),
+                    '印件-工序' => rtrim($value['Gy0_yjno']).'-'.rtrim($value['Gy0_gxh']),
+                    '备选工序' => rtrim($value['备选工序']),
+                    '工序名称' => rtrim($value['Gy0_gxmc']).'【'.rtrim($value['Add_gxmc']).'】',
+                    '计划产量' => (int)($value['Gy0_计划接货数']/$value['Gy0_ls']),
+                    '基础损耗' => rtrim($value['Gy0_Rate0']),
+                    '损耗率' => rtrim($value['Gy0_Rate1']),
+                    '报废定额' => $scrap,
+                    '允损比例' => $number,
+                    '难度系数' => isset($value['工价系数'])?rtrim($value['工价系数']):'',
+                    '损耗系数' => isset($value['损耗系数'])?rtrim($value['损耗系数']):'',
+                    '人工检_次品板' => (int)$value['人工检_次品板']=0?'':$value['人工检_次品板'],
+                    '人工检_废检' => (int)$value['人工检_废检']=0?'':$value['人工检_废检'],
+                    '机检_正品板' => (int)$value['机检_正品板']=0?'':$value['机检_正品板'],
+                    '机检_次品板' => (int)$value['机检_次品板']=0?'':$value['机检_次品板'],
+                    '机检_废检' => (int)$value['机检_废检']=0?'':$value['机检_废检'],
+                    '开数*联数' => rtrim($value['Gy0_ks']).'*'.rtrim($value['Gy0_ls']),
+                    '备注' => isset($value['工序备注'])?rtrim($value['工序备注']):'',
+                    '印刷方式' => isset($value['印刷方式'])?rtrim($value['印刷方式']):'',
+                    '版距' => isset($value['版距'])?rtrim($value['版距']):'',
+                    '建档用户' => rtrim($value['Sys_id']),
+                    '建档日期' => isset($value['Sys_rq'])?rtrim($value['Sys_rq']):'',
+                    '更新时间' => isset($value['Mod_rq'])?rtrim($value['Mod_rq']):'',
+                    '车间名称' => rtrim($value['Gy0_SITE']),
+                    '质量要求' => rtrim($value['质量要求']),
+                    '质量隐患' => rtrim($value['质量隐患']),
+                    '开数' => rtrim($value['Gy0_ks']),
+                    '联数' => rtrim($value['Gy0_ls']),
+                    'UniqId' => rtrim($value['UniqId']),
+                    'shdh' => rtrim($value['Gy0_shdh']),
+                    '辅助工时' => rtrim($value['Gy0_辅助工时']),
+                    '小时产能' => rtrim($value['Gy0_小时产能']),
+                    'status' => $status
+                ];
+            }
+        }else{
+            $data['processList'] = [];
+        }
+
+        //BOM资料
+        $field = 'rtrim(BOM_方案) as 方案,rtrim(BOM_物料编码) as 物料编号,rtrim(BOM_物料名称) as 物料名称,BOM_投料单位,
+        BOM_投入数,BOM_产出数,BOM_产出单位,rtrim(BOM_计划用量) as 计划用量,rtrim(Sys_ID) as 建档用户,rtrim(Sys_rq) as 建档时间,rtrim(Mod_rq) as 更新时间';
+        $bomList = \db('工单_bom资料')
+            ->where('BOM_工单编号',$Gd_gdbh)
+            ->field($field)
+            ->select();
+        if (!empty($bomList)){
+            foreach ($bomList as $key=>$value){
+                $bomList[$key]['消耗定量'] = rtrim($value['BOM_投入数']).rtrim($value['BOM_投料单位']).'/'.rtrim($value['BOM_产出数']).rtrim($value['BOM_产出单位']);
+                unset($bomList[$key]['BOM_投料单位'],$bomList[$key]['BOM_投入数'],$bomList[$key]['BOM_产出数'],$bomList[$key]['BOM_产出单位']);
+                $bomList[$key]['计划用量'] = rtrim((float)$value['计划用量']);
+            }
+            $data['BOM'] = $bomList;
+        }else{
+            $data['BOM'] = [];
+        }
+
+        $this->success('成功',$data);
+    }
+
+    /**
+     * 编辑页面展示
+     * @ApiMethod (GET)
+     * @param string $workOrder   工单编号
+     * @return void
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+    public function DataCorrection()
+    {
+        if ($this->request->isGet() === false){
+            $this->error('请求错误');
+        }
+        $workOrder = input('Gd_gdbh');
+        if (empty($workOrder)){
+            $this->error('参数错误');
+        }
+        $field = 'rtrim(Gd_lx) as 重点工单,rtrim(Gd_gdbh) as 工单编号,rtrim(Gd_生产分类) as 生产类型,rtrim(Gd_khdh) as 客户代号,rtrim(Gd_客户名称) as 客户名称,
+        rtrim(Gd_cpdh) as 产品代号,rtrim(Gd_cpmc) as 产品名称,rtrim(接单日期) as 开单日期,rtrim(订单数量) as 订单数量,rtrim(交货日期) as 交货日期,
+        rtrim(投料率) as 投料率,rtrim(实际投料) as 万小张,rtrim(计量单位) as 单位,rtrim(投料大箱) as 投料大箱,rtrim(排产时库存) as 库存大箱,rtrim(警语版面) as 警语版面,
+        rtrim(销售订单号) as 销售订单号,rtrim(产品版本号) as 版本号,rtrim(客户ERP编码) as 客户ERP编码,rtrim(码源数量) as 码源数量,rtrim(进程备注) as 进程备注,rtrim(Gd_desc) as 备注,rtrim(Uniqid) as Uniqid';
+        $list = \db('工单_基本资料')->where('Gd_gdbh',$workOrder)->field($field)->find();
+        if (empty($list)){
+            $this->error('未找到该工单信息');
+        }
+        $printData = \db('工单_印件资料')
+            ->where('Yj_Gdbh',$workOrder)
+            ->field('rtrim(yj_yjmc) as 印件名称,rtrim(yj_Yjdh) as 印件代号,rtrim(yj_平张投料) as 平张投料,rtrim(Uniqid) as id')
+            ->cache(true,84600)
+            ->find();
+        if (empty($printData)){
+            $this->error('未找到该工单印件资料');
+        }
+        $list['印件名称'] = $printData['印件名称'];
+        $list['印件代号'] = $printData['印件代号'];
+        $list['平张投料'] = $printData['平张投料'];
+        $list['印件ID'] = $printData['id'];
+        $this->success('成功',$list);
+    }
+
+    /**
+     * 工单资料修改
+     * @ApiMethod (POST)
+     * @param  void
+     * @return void
+     * @throws \think\Exception
+     * @throws \think\exception\PDOException
+     */
+
+    public function WorkOrderEdit()
+    {
+        if (Request::instance()->isPost() === false){
+            $this->error('请求错误');
+        }
+        $param = Request::instance()->post();
+        if (empty($param) || isset($param['Uniqid']) === false){
+            $this->error('参数错误');
+        }
+        $row = [
+            'Gd_lx' => isset($param['lx'])?$param['lx']:'',
+            '开单日期' => isset($param['kdrq'])?$param['kdrq']:'',
+            'Gd_gdbh' => isset($param['gdbh'])?$param['gdbh']:'',
+            'Gd_生产分类' => isset($param['scfl'])?$param['scfl']:'',
+            'Gd_客户代号' => isset($param['khdh'])?$param['khdh']:'',
+            'Gd_客户名称' => isset($param['khmc'])?$param['khmc']:'',
+            '成品代号' => isset($param['cpdh'])?$param['cpdh']:'',
+            '成品名称' => isset($param['cpmc'])?$param['cpmc']:'',
+            '订单数量' => isset($param['ddsl'])?$param['ddsl']:'',
+            '交货日期' => isset($param['jhrq'])?$param['jhrq']:'',
+            '投料率' => isset($param['tll'])?$param['tll']:'',
+            '计划投料' => isset($param['jhtl'])?$param['jhtl']:'',
+            '实际投料' => isset($param['sjtl'])?$param['sjtl']:'',
+            '计量单位' => isset($param['jldw'])?$param['jldw']:'',
+            '投料大箱' => isset($param['tldx'])?$param['tldx']:'',
+            '销售订单号' => isset($param['xsddh'])?$param['xsddh']:'',
+            '警语版面' => isset($param['jymb'])?$param['jymb']:'',
+            '产品版本号' => isset($param['bbh'])?$param['bbh']:'',
+            '客户ERP编码' => isset($param['erp'])?$param['erp']:'',
+            '码源数量' => isset($param['ymsl'])?$param['ymsl']:'',
+            '进程备注' => isset($param['jcbz'])?$param['jcbz']:'',
+            'Gd_desc' => isset($param['desc'])?$param['desc']:'',
+            '排产时库存' => isset($param['kc'])?$param['kc']:'',
+            '平均合格率' => isset($param['avg'])?$param['avg']:'',
+        ];
+        $sql = \db('工单_基本资料')->where('Uniqid',$param['Uniqid'])->fetchSql(true)->update($row);
+        $res = Db::query($sql);
+        $printSql = \db('工单_印件资料')
+            ->where('Uniqid',$param['printID'])
+            ->fetchSql(true)
+            ->update(['yj_yjmc'=>$param['yjmc'],'yj_Yjdh'=>$param['yjdh'],'yj_平张投料'=>$param['jhtl']]);
+        $printRes = Db::query($printSql);
+        if ($res !== false && $printRes !== false){
+            $this->success('成功');
+        }else{
+            $this->error('失败');
+        }
+    }
+
+
+    /**
+     * U8投料试算
+     * @ApiMethod (GET)
+     * @param string  $processCode   产品编号
+     * @return void
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+
+    public function U8Trial()
+    {
+        if ($this->request->isGet() === false)
+        {
+            $this->error('请求错误');
+        }
+        $productCode = input('productCode');
+        if (empty($productCode)){
+            $this->error('参数错误');
+        }
+        $field = 'rtrim(Gy0_cpdh) as 产品代号,rtrim(Gy0_yjno) as 印件号,rtrim(Gy0_gxh) as 工序号,rtrim(gy0_gxmc) as gxmc,rtrim(Add_gxmc) as add_gxmc,
+        rtrim(Gy0_Ms) as 墨色数,rtrim(Gy0_shdh) as 损耗代号,rtrim(损耗系数) as 损耗系数,rtrim(Gy0_ls) as 加工联数';
+        $list = \db('产品_工艺资料')->where('Gy0_cpdh',$productCode)->field($field)->select();
+        if (empty($list)){
+            $this->success('未找到该产品工序');
+        }
+        foreach ($list as $key=>$value){
+            $data = \db('dic_lzsh')->where('sys_bh',$value['损耗代号'])->field('rtrim(sys_rate0) as rate0,rtrim(sys_rate1) as rate1')->cache(true)->find();
+            $list[$key]['调机损耗'] = isset($data['rate0'])?$data['rate0']:'';
+            $list[$key]['运行损耗率'] = isset($data['rate1'])?$data['rate1']:'';
+            if ($value['add_gxmc'] !== ''){
+                $list[$key]['工序名称'] = $value['gxmc'].'【'.$value['add_gxmc'].'】';
+            }else{
+                $list[$key]['工序名称'] = $value['gxmc'];
+            }
+            unset($list[$key]['gxmc'],$list[$key]['add_gxmc']);
+        }
+        $this->success('成功',$list);
+    }
+
+
+    /**
+     * 引用产品资料->获取产品资料
+     * @ApiMethod  (GET)
+     * @param  string $workOrder   工单编号
+     * @return void
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+
+    public function ProductInformation()
+    {
+        if ($this->request->isGet() === false)
+        {
+            $this->error('请求错误');
+        }
+        $workOrder = input('workOrder');
+        if (empty($workOrder)){
+            $this->error('参数错误');
+        }
+        $field = 'rtrim(Gd_gdbh) as 工单编号,rtrim(Gd_客户名称) as 客户名称,rtrim(成品代号) as 产品代号,rtrim(成品名称) as 产品名称';
+        $Detail = \db('工单_基本资料')->where('Gd_gdbh',$workOrder)->field($field)->find();
+        if (empty($Detail)){
+            $this->success('未找到工单信息');
+        }
+        $Detail['客户代号'] = substr($Detail['产品代号'],0,4);
+        $this->success('成功',$Detail);
+    }
+
+    /**
+     * 引用产品资料->复制产品工艺资料
+     * @ApiMethod  (POST)
+     * @param string $oldWorkOrder   被复制工单编号
+     * @param string $newWorkOrder   复制工单编号
+     * @return void
+     * @throws \think\Exception
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     * @throws \think\exception\PDOException
+     */
+
+    public function ProductInformationEdit()
+    {
+        if (Request::instance()->isPost() === false)
+        {
+            $this->error('请求错误');
+        }
+        $oldWorkOrder = input('oldWorkOrder');
+        $newWorkOrder = input('newWorkOrder');
+        if (empty($oldWorkOrder) || empty($newWorkOrder))
+        {
+            $this->error('参数错误');
+        }
+        $lastId = \db('工单_工艺资料')->order('UniqId desc')->value('UniqId');
+        if ($lastId<10000000){
+            $lastId = 10000000;
+        }else{
+            $lastId = $lastId + 1;
+        }
+        //获取原工单工艺资料
+        $oldProcessData = \db('工单_工艺资料')->where('Gy0_gdbh',$newWorkOrder)->select();
+        $ProsessUniqId = \db('工单_工艺资料')->field('UniqId')->order('UniqId desc')->find();
+        foreach ($oldProcessData as $k=>$v){
+            $oldProcessData[$k]['Gy0_gdbh']  = $oldWorkOrder;
+            $oldProcessData[$k]['Sys_id'] = '';
+            $oldProcessData[$k]['UniqId'] = $lastId + $k;
+            $oldProcessData[$k]['PD_WG'] = '1900-01-01 00:00:00';
+        }
+        if (\db('工单_工艺资料')->where('Gy0_gdbh',$oldWorkOrder)->find()){
+            \db('工单_工艺资料')->where('Gy0_gdbh',$oldWorkOrder)->delete();
+        }
+        //获取原工单印件资料
+        $lastUniqId = \db('工单_印件资料')->order('UniqId desc')->value('UniqId');
+        if ($lastUniqId<1000000){
+            $lastUniqId = 1000000;
+        }else{
+            $lastUniqId = $lastUniqId + 1;
+        }
+        $oldPrintData = \db('工单_印件资料')->where('Yj_Gdbh',$newWorkOrder)->select();
+        $PrintUniqId = \db('工单_印件资料')->field('Uniqid')->order('Uniqid desc')->find();
+        foreach ($oldPrintData as $k=>$v){
+            $oldPrintData[$k]['Yj_Gdbh']  = $oldWorkOrder;
+            $oldPrintData[$k]['Sys_id'] = '';
+            $oldPrintData[$k]['Uniqid'] = $lastUniqId +$k +1;
+        }
+        if (\db('工单_印件资料')->where('Yj_Gdbh',$oldWorkOrder)->find()){
+            \db('工单_印件资料')->where('Yj_Gdbh',$oldWorkOrder)->delete();
+        }
+        //复制印件、工艺资料
+        $ProcessSQL = \db('工单_工艺资料')->fetchSql(true)->insertAll($oldProcessData);
+        $ProcessRes = Db::query($ProcessSQL);
+        $PrintSQL = \db('工单_印件资料')->fetchSql(true)->insertAll($oldPrintData);
+        $PrintRes = Db::query($PrintSQL);
+        if ($ProcessRes !== false && $PrintRes !== false){
+            $this->success('成功');
+        }else{
+            $this->error('失败');
+        }
+    }
+
+
+    /**
+     * 工艺流程调成->获取当前工单工艺资料
+     * @ApiMethod (GET)
+     * @param string $workorder  当前工单编号
+     * @return void
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+    public function ProcessFlow()
+    {
+        if ($this->request->isGet() === false){
+            $this->error('请求错误');
+        }
+        $workOrder = input('workOrder');
+        if (empty($workOrder)){
+            $this->error('参数错误');
+        }
+        $list = \db('工单_基本资料')->where('Gd_gdbh',$workOrder)->field('rtrim(成品代号) as 成品编号,rtrim(成品名称) as 成品名称')->find();
+        if (empty($list)){
+            $this->success('未找到工单信息');
+        }
+        $filed = 'rtrim(Gy0_方案) as 方案,rtrim(Gy0_yjno) as 印件号,rtrim(Gy0_gxh) as 工序号,rtrim(Gy0_gxmc) as gxmc,rtrim(Add_gxmc) as add_gxmc,
+        rtrim(工价系数) as 工价系数,rtrim(损耗系数) as 损耗系数,rtrim(Gy0_ks) as ks,rtrim(Gy0_ls) as ls,rtrim(工序备注) as 备注,rtrim(Gy0_SITE) as 车间,
+        rtrim(Gy0_sbbh) as 设备编号,rtrim(Gy0_sbmc) as 设备名称,rtrim(Sys_id) as 建档用户,rtrim(Sys_rq) as 建档时间,rtrim(Mod_rq) as 更新时间,rtrim(UniqId) as UniqId';
+        $process = \db('工单_工艺资料')->where('Gy0_gdbh',$workOrder)->cache(true,84600)->field($filed)->select();
+        if (empty($process)){
+            $this->error('未找到该工单工艺资料');
+        }
+        foreach ($process as $key=>$value){
+            if (isset($value['add_gxmc'])){
+                $process[$key]['工序名称'] = $value['gxmc'] . '【'.$value['add_gxmc'].'】';
+            }else{
+                $process[$key]['工序名称'] = $value['gxmc'];
+            }
+            $process[$key]['工价系数'] = (float)$value['工价系数'];
+            $process[$key]['损耗系数'] = (float)$value['损耗系数'];
+            $process[$key]['开数*联数'] = $value['ks'].'*'.$value['ls'];
+        }
+        $list['process'] = $process;
+        $this->success('成功',$list);
+    }
+
+    /**
+     * 参照工单列表获取
+     * @ApiMethod (GET)
+     * @param string $workOrder  工单编号
+     * @param string $productCode   产品代号
+     * @return void
+     */
+    public function ReferenceWorkOrder()
+    {
+        if ($this->request->isGet() === false){
+            $this->error('请求错误');
+        }
+        $productCode = input('productCode');
+        $workOrder = input('workOrder');
+        if (empty($productCode) || empty($workOrder)){
+            $this->error('参数错误');
+        }
+        $list = \db('工单_基本资料')->where('成品代号',$productCode)->distinct(true)->where('Gd_gdbh','<>',$workOrder)->column('Gd_gdbh');
+        if (empty($list)){
+            $this->success('未获取该产品其他工单信息');
+        }
+        $this->success('成功',$list);
+    }
+
+    /**
+     * 工艺资料复制
+     * @ApiMethod (POST)
+     * @param  string $oldWorkOrder    被复制工单编号
+     * @param  string $newWorkOrder    复制工单编号
+     * @return void
+     * @throws \think\Exception
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     * @throws \think\exception\PDOException
+     *
+     */
+    public function ProcessCopy()
+    {
+        if (Request::instance()->isPost() === false){
+            $this->error('请求错误');
+        }
+        $param = Request::instance()->post();
+        if (empty($param)){
+            $this->error('参数错误');
+        }
+        $UniqId = [];
+        $lastId = \db('工单_工艺资料')->field('rtrim(UniqId) as id')->order('UniqId desc')->find();
+        if ($lastId['id']>10000000){
+            $lastUniqId = $lastId['id'];
+        }else{
+            $lastUniqId = 10000000;
+        }
+        foreach ($param as $key=>$value){
+            $UniqId[$key] = $value['UniqId'];
+        }
+        $processList = \db('工单_工艺资料')->where('UniqId','in',$UniqId)->select();
+        if (empty($processList)){
+            $this->success('未找到工艺资料');
+        }
+        $data = [];
+        foreach ($param as $key=>$value){
+            foreach ($processList as $k=>$v){
+                if ($value['UniqId'] = $v['UniqId']){
+                    $data[$key] = $v;
+                    $data[$key]['Gy0_gxh'] = $value['gxh'];
+                    $data[$key]['Gy0_gdbh'] = $value['workOrder'];
+                    $data[$key]['UniqId'] = $lastUniqId + $key + 1;
+                }
+            }
+        }
+        $res = \db('工单_工艺资料')->where(['Gy0_gdbh'=>$param[0]['workOrder']])->delete();
+        if ($res !== false){
+            $result = \db('工单_工艺资料')->insertAll($data);
+            if ($result !== false){
+                $this->success('成功');
+            }else{
+                $this->error('失败');
+            }
+        }else{
+            $this->error('失败');
+        }
+    }
+
+    /**
+     * U8工单列表
+     * @ApiMethod (GET)
+     * @param  void
+     * @return void
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+    public function U8workOrder()
+    {
+        if ($this->request->isGet() === false){
+            $this->error('请求错误');
+        }
+        $param = $this->request->param();
+        if (empty($param)){
+            $this->error('参数错误');
+        }
+        $filed = 'rtrim(Gd_gdbh) as 工单编号,rtrim(行号) as 行号,rtrim(Gd_客户代号) as 客户代号,rtrim(Gd_客户名称) as 客户名称,
+        rtrim(成品代号) as 成品代号,rtrim(成品名称) as 成品名称,rtrim(Mod_rq) as 获取日期,rtrim(Uniqid) as 序号';
+        $list = \db('工单_基本资料')->where('Gd_gdbh',$param['workOrder'])->field($filed)->select();
+        if (empty($list)){
+            $this->success('未找到工单');
+        }
+        $this->success('成功',$list);
+    }
+
+    /**
+     * U8工单资料删除
+     * @param string $workOrder  工单编号
+     * @return void
+     * @throws \think\Exception
+     * @throws \think\exception\PDOException
+     */
+    public function U8DataCorrection()
+    {
+        if($this->request->isGet() === false){
+            $this->error('请求错误');
+        }
+        $workOrder = input('Uniqid');
+        if (empty($workOrder)){
+            $this->error('参数错误');
+        }
+        $data = [];
+        if (strpos($workOrder,',')){
+            $data = explode(',',$workOrder);
+        }else{
+            $data[0] = $workOrder;
+        }
+        $res = \db('工单_基本资料')->where('Uniqid','in',$data)->delete();
+        if ($res !== false){
+            $this->success('成功');
+        }else{
+            $this->error('失败');
+        }
+    }
+
+
+    /**
+     * 产品废检系数调整->质检工艺数据获取
+     * @ApiMethod (GET)
+     * @param  string  $workOrder   工单编号
+     * @return void
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+    public function TestCoefficient()
+    {
+        if ($this->request->isGet() === false){
+            $this->error('请求错误');
+        }
+        $workOrder = input('workOrder');
+        if (empty($workOrder)){
+            $this->error('参数错误');
+        }
+        $where = [
+            'Gy0_gdbh' => $workOrder,
+            'Gy0_gxmc' => ['like','%检%']
+        ];
+        $filed = 'rtrim(Gy0_gdbh) as gdbh,rtrim(Gy0_yjno) as yjno,rtrim(Gy0_gxh) as gxh,rtrim(Gy0_gxmc) as gxmc,rtrim(人工检_正品板) as 人工正品板,
+        rtrim(人工检_次品板) as 人工次品板,rtrim(人工检_废检) as 人工废检,rtrim(机检_正品板) as 机检正品板,rtrim(机检_次品板) as 机检次品板,
+        rtrim(机检_废检) as 机检废检,rtrim(Gy0_sbbh) as 设备编号,rtrim(Uniqid) as Uniqid';
+        $list = \db('工单_工艺资料')->where($where)->field($filed)->select();
+        if (empty($list)){
+            $this->success('未找到该工单工艺');
+        }
+        $name = \db('工单_基本资料')
+            ->where('Gd_gdbh',$workOrder)
+            ->field('rtrim(Gd_cpdh) as 产品代号,rtrim(Gd_khmc) as 客户名称,rtrim(Gd_cpmc) as 产品名称')
+            ->find();
+        if (empty($name)){
+            $this->success('未找到该工单');
+        }
+        foreach ($list as $key=>$value){
+            if ($value['yjno']<10){
+                $value['yjno'] = '0'.$value['yjno'];
+            }
+            if ($value['gxh']<10){
+                $value['gxh'] = '0'.$value['gxh'];
+            }
+            $list[$key]['印件工序及工艺'] = $value['gdbh'].'-'.$value['yjno'].'-'.$value['gxh'].'-'.$value['gxmc'];
+            unset($list[$key]['gdbh'],$list[$key]['yjno'],$list[$key]['gxmc']);
+            $list[$key]['产品编号'] = $name['产品代号'];
+            $list[$key]['产品名称'] = $name['产品名称'];
+            $list[$key]['客户名称'] = $name['客户名称'];
+        }
+        $this->success('成功',$list);
+    }
+
+    /**
+     * 产品质检系数调整->系数修改
+     * @ApiMethod (GET)
+     * @param string $workorder   工单编号
+     * @param string $processCode  工序号
+     * @param float $code1  人工正品板
+     * @param float $code2  人工次品板
+     * @param float $code3  人工废检
+     * @param float $code4  机检正品板
+     * @param float $code5  机检次品板
+     * @param float $code6  机检废检
+     * @return void
+     * @throws \think\Exception
+     * @throws \think\exception\PDOException
+     */
+    public function TestCoefficientEdit()
+    {
+        if (Request::instance()->isPost() === false){
+            $this->error('请求错误');
+        }
+        $workOrder = input('workOrder');
+        $processCode = input('processCode');
+        $row = [
+            '人工检_正品板' => input('code1'),
+            '人工检_次品板' => input('code2'),
+            '人工检_废检'   => input('code3'),
+            '机检_正品板' => input('code4'),
+            '机检_次品板' => input('code5'),
+            '机检_废检' => input('code6'),
+        ];
+        if (empty($workOrder) || empty($processCode)){
+            $this->error('参数错误');
+        }
+        $where = [
+            'Gy0_gdbh' => $workOrder,
+            'Gy0_gxh' => $processCode
+        ];
+        $sql = \db('工单_工艺资料')->where($where)->fetchSql(true)->update($row);
+        $res = Db::query($sql);
+        if ($res !== false){
+            $this->success('成功');
+        }else{
+            $this->error('失败');
+        }
+    }
+
+
+    /**
+     * 修正工单核算参数->数据获取
+     * @ApiMethod (GET)
+     * @param string $workOrder  工单编号
+     * @return void
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+    public function AccountingParameter()
+    {
+        if ($this->request->isGet() === false){
+            $this->error('请求错误');
+        }
+        $workOrder = input('workOrder');
+        if (empty($workOrder)){
+            $this->error('参数错误');
+        }
+        $field = 'rtrim(Gy0_方案) as 方案,rtrim(Gy0_yjno) as yjno,rtrim(Gy0_gxh) as gxh,rtrim(Gy0_gxmc) as gxmc,rtrim(Add_gxmc) as add_gxmc,
+        rtrim(Gy0_sbbh) as 参照设备,rtrim(工价系数) as 难度系数,rtrim(Gy0_shdh) as 损耗代号,rtrim(Gy0_Rate0) as 基础损耗,rtrim(Gy0_Rate1) as 损耗率,
+        rtrim(印刷方式) as 印刷方式,rtrim(版距) as 版距,rtrim(Gy0_ms) as 计损色数,rtrim(损耗系数) as 损耗系数,rtrim(UniqId) as UniqId';
+        $list = \db('工单_工艺资料')->where('Gy0_gdbh',$workOrder)->field($field)->select();
+        if (empty($list)){
+            $this->success('未找到该工单工艺资料');
+        }
+        foreach ($list as $key=>$value){
+            if ($value['yjno']<10){
+                $value['yjno'] = '0'.$value['yjno'];
+            }
+            if ($value['gxh']<10){
+                $value['gxh'] = '0'.$value['gxh'];
+            }
+            $list[$key]['印件号及工序名称'] = $value['yjno'].'-'.$value['gxh'].$value['gxmc'].'('.$value['add_gxmc'].')';
+            unset($list[$key]['yjno'],$list[$key]['gxmc'],$list[$key]['add_gxmc']);
+        }
+        $this->success('成功',$list);
+    }
+
+
+    /**
+     * 修正工单核算参数->参数修改
+     * @ApiMethod (POST)
+     * @param  void
+     * @return void
+     * @throws \think\Exception
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     * @throws \think\exception\PDOException
+     */
+    public function AccountingParameterEdit()
+    {
+        if (Request::instance()->isPost() === false){
+            $this->error('请求错误');
+        }
+        $param = Request::instance()->post();
+        if (empty($param) || isset($param[0]['Uniqid']) === false){
+            $this->error('参数错误');
+        }
+        $i = 0;
+        foreach ($param as $key=>$value){
+            if (!empty($value['loss'])){
+                $data = \db('dic_lzsh')->where('sys_bh',$value['loss'])->field('rtrim(sys_rate0) as rate0,rtrim(sys_rate1) as rate1')->find();
+            }
+            $row = [
+                '工价系数' => $value['difficulty']?:'',
+                'Gy0_shdh' => $value['loss']?:'',
+                '印刷方式' => $value['printMode']?:'',
+                '版距' => $value['plate']?:'',
+                'Gy0_ms' => $value['chromatic']?:'',
+                '损耗系数' => $value['wastage']?:'',
+                'Gy0_Rate0' => $data['rate0'],
+                'Gy0_Rate1' => $data['rate1']
+            ];
+            $sql = \db('工单_工艺资料')->where('Uniqid',$value['Uniqid'])->fetchSql(true)->update($row);
+            $res = Db::query($sql);
+            if ($res !== false){
+                $i++;
+            }
+        }
+        if ($i !== 0){
+            $this->success('成功');
+        }else{
+            $this->error('失败');
+        }
+    }
+
+    /**
+     * 印件资料修改
+     * @ApiMethod (POST)
+     * @param  void
+     * @return void
+     * @throws \think\Exception
+     * @throws \think\exception\PDOException
+     */
+
+    public function PrintedEdit()
+    {
+        if (Request::instance()->isPost() === false){
+            $this->error('请求错误');
+        }
+        $param = Request::instance()->post();
+        if (empty($param) || isset($param['Uniqid']) === false){
+            $this->error('参数错误');
+        }
+        $data = [
+            'yj_Yjno' => isset($param['yjno'])?$param['yjno']:'',
+            'yj_Yjdh' => isset($param['yjdh'])?$param['yjdh']:'',
+            'yj_yjmc' => isset($param['yjmc'])?$param['yjmc']:'',
+            'yj_zzdh' => isset($param['zzdh'])?$param['zzdh']:'',
+            'yj_zzdh1' => isset($param['zzdh1'])?$param['zzdh1']:'',
+            'yj_zzdh2' => isset($param['zzdh2'])?$param['zzdh2']:'',
+            'yj_zzdh3' => isset($param['zzdh3'])?$param['zzdh3']:'',
+            'yj_zzdh4' => isset($param['zzdh4'])?$param['zzdh4']:'',
+            'yj_zzmc' => isset($param['zzmc'])?$param['zzmc']:'',
+            'yj_zzmc1' => isset($param['zzmc1'])?$param['zzmc1']:'',
+            'yj_zzmc2' => isset($param['zzmc2'])?$param['zzmc2']:'',
+            'yj_zzmc3' => isset($param['zzmc3'])?$param['zzmc3']:'',
+            'yj_zzmc4' => isset($param['zzmc4'])?$param['zzmc4']:'',
+            'yj_成品数量' => isset($param['cpsl'])?$param['cpsl']:'',
+            'yj_实际投料' => isset($param['sjtl'])?$param['sjtl']:'',
+            'yj_平张投料' => isset($param['pztl'])?$param['pztl']:'',
+            'yj_tlgg' => isset($param['tlgg'])?$param['tlgg']:'',
+            'yj_klgg' => isset($param['klgg'])?$param['klgg']:'',
+            'Yj_核算规格' => isset($param['hsgg'])?$param['hsgg']:'',
+            'yj_ks' => isset($param['ks'])?$param['ks']:'',
+            'yj_ls' => isset($param['ls'])?$param['ls']:'',
+            'yj_desc' => isset($param['desc'])?$param['desc']:'',
+        ];
+        $sql = \db('工单_印件资料')->where('Uniqid',$param['Uniqid'])->fetchSql(true)->update($data);
+        $res = Db::query($sql);
+        if ($res !== false){
+            $this->success('成功');
+        }else{
+            $this->error('失败');
+        }
+
+    }
+
+    /**
+     * 工艺资料修改
+     * @ApiMethod (POST)
+     * @param void
+     * @return void
+     * @throws \think\Exception
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     * @throws \think\exception\PDOException
+     */
+    public function ProcessDetailEdit()
+    {
+        if (Request::instance()->isPost() === false){
+            $this->error('请求错误');
+        }
+        $param = Request::instance()->post();
+        if (empty($param) || isset($param['UniqId']) === false){
+            $this->error('参数错误');
+        }
+        $rate = \db('dic_lzsh')->where('sys_bh',$param['shdh'])->field('rtrim(sys_rate0) as rate0,rtrim(sys_rate1) as rate1')->find();
+        $data = [
+            '重点工序' => isset($param['zdgx'])?$param['zdgx']:'',
+            '备选工序' => isset($param['bxgx'])?$param['bxgx']:'',
+            'Gy0_sbbh' => isset($param['sbbh'])?$param['sbbh']:'',
+            'Gy0_Rate0' => isset($rate['rate0'])?$rate['rate0']:'',
+            'Gy0_Rate1' => isset($rate['rate1'])?$rate['rate1']:'',
+            'Gy0_shdh' => isset($param['shdh'])?$param['shdh']:'',
+            '损耗系数' => isset($param['shxs'])?$param['shxs']:'',
+            '工价系数' => isset($param['ndxs'])?$param['ndxs']:'',
+            'Gy0_小时产能' => $param['xscn'],
+            'Mod_rq' => date('Y-m-d H:i:s',time()),
+        ];
+        $sql = \db('工单_工艺资料')->where('UniqId',$param['UniqId'])->fetchSql(true)->update($data);
+        $res = Db::query($sql);
+        $status = \db('工单_基本资料')->where('Gd_gdbh',$param['workOrder'])->field('rtrim(gd_statu) as status')->find();
+        if ($status['status'] !== '2-生产中'){
+            $statusSql = \db('工单_基本资料')->where('Gd_gdbh',$param['workOrder'])->fetchSql(true)->update(['gd_statu'=>'2-生产中']);
+            Db::query($statusSql);
+        }
+        if ($res !== false){
+            $this->success('成功');
+        }else{
+            $this->error('失败');
+        }
+    }
+
+    /**
+     * 工艺资料编辑->机台列表获取
+     * @return void
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+    public function MachineList()
+    {
+        if ($this->request->isGet() === false){
+            $this->error('请求错误');
+        }
+        $param = $this->request->param();
+        if (empty($param)){
+            $this->error('参数错误');
+        }
+        $list = \db('设备_基本资料')
+            ->where('存放地点',$param['address'])
+            ->field('rtrim(设备编号) as 设备编号,rtrim(设备名称) as 设备名称')
+            ->select();
+        if (empty($list)){
+            $this->success('未找到该车间机台');
+        }
+        $data = [];
+        foreach ($list as $key=>$value){
+            $data[$key] = $value['设备编号'].'-->'.$value['设备名称'];
+        }
+        $this->success('成功',$data);
+    }
+
+    /**
+     * 打印作业通知单->工单印件和工序获取
+     * @ApiMethod (GET)
+     * @return void
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+    public function PrintCodeList()
+    {
+        if ($this->request->isGet() === false){
+            $this->error('请求错误');
+        }
+        $param = $this->request->param();
+        if (empty($param)){
+            $this->error('参数错误');
+        }
+        $list = \db('工单_印件资料')
+            ->field([
+                'rtrim(yj_Yjno)' => '印件号',
+                'rtrim(yj_yjmc)' => '印件名称'
+            ])
+            ->where('Yj_Gdbh',$param['workOrder'])
+            ->select();
+        $this->success('成功',$list);
+    }
+
+    /**
+     * 打印作业通知单->工艺编号获取
+     * @ApiMethod (GET)
+     * @return void
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+    public function ProcessCodeList()
+    {
+        if ($this->request->isGet() === false){
+            $this->error('请求错误');
+        }
+        $param = $this->request->param();
+        if (empty($param)){
+            $this->error('参数错误');
+        }
+        $list = \db('工单_工艺资料')
+            ->field('rtrim(Gy0_gxh) as 工序号')
+            ->where([
+                'Gy0_gdbh' => $param['workOrder'],
+                'Gy0_yjno' => $param['yjno']
+            ])
+            ->select();
+        $this->success('成功',$list);
+    }
+    /**
+     * 打印作业通知单
+     * @ApiMethod (POST)
+     * @param  void
+     * @return void
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+    public function PrintJobOrder()
+    {
+        if ($this->request->isGet() === false) {
+            $this->error('请求错误');
+        }
+        $param = $this->request->param();
+        if (empty($param)){
+            $this->error('参数错误');
+        }
+        $data = $this->workOrderDetailGet($param['workOrder'],$param['yjno']);
+        if (empty($data)){
+            $this->success('未找到工单信息');
+        }
+        $materiel = $this->MaterielDetailGet($param['workOrder']);
+        if (empty($materiel)){
+            $this->success('未找到物料信息');
+        }
+        $printDetail = $this->PrintDetailGet($param['workOrder'],$param['yjno'],$param['gxh']);
+        if (empty($printDetail)){
+            $this->success('未找到工艺信息');
+        }
+        $number = 0;
+        foreach ($printDetail as $key=>$value){
+            $value['允损比例'] = (float)substr($value['允损比例'],0,-1);
+            $number = $number+$value['允损比例'];
+        }
+        $data['制单'] = $param['PrepareDocument'];
+        $data['审核'] = $param['examine'];
+        $data['目标合格率'] = 100-$number.'%';
+        $data['materiel'] = $materiel;
+        $data['printDetail'] = $printDetail;
+        $this->success('成功',$data);
+    }
+
+    /**
+     * 打印作业通知单->工单及印件资料获取
+     * @param $workOrder
+     * @return mixed
+     */
+    public function workOrderDetailGet($workOrder,$yjno)
+    {
+        $sql = "SELECT
+                RTRIM( a.Gd_lx) AS  工单类型,
+                RTRIM( a.Gd_gdbh ) AS 生产批次号,
+                RTRIM( a.销售订单号 ) AS 销售订单号,
+                RTRIM( a.Gd_客户代号 ) AS 客户代号,
+                RTRIM( a.Gd_客户名称 ) AS 客户名称,
+                RTRIM( a.成品代号 ) AS 产品代码,
+                RTRIM( a.成品名称 ) AS 产品名称,
+                RTRIM( a.产品版本号 ) AS 版本号,
+                RTRIM( a.警语版面 ) AS 警语版面,
+                RTRIM( a.码源数量 ) AS 码源数量,
+                RTRIM( a.客户ERP编码 ) AS 客户ERP编码,
+                RTRIM( a.接单日期 ) AS 开单日期,
+                RTRIM( a.交货日期 ) AS 交货日期,
+                RTRIM( a.Gd_desc ) AS 工单说明,
+                RTRIM( a.投料率 ) AS 投料率,
+                RTRIM( a.平均合格率 ) AS 平均合格率,
+                RTRIM( a.投料大箱 ) AS 订货数量,
+                RTRIM( a.排产时库存 ) AS 排产时库存,
+                RTRIM( b.yj_Yjno ) AS 印件,
+                RTRIM( b.yj_Yjdh ) AS 印件代号,
+                RTRIM( b.yj_yjmc ) AS 印件名称,
+                RTRIM( b.yj_平张投料 ) AS 平张投料量,
+                RTRIM( b.yj_zzmc ) AS 纸张名称,
+                RTRIM( b.yj_tlgg ) AS 投料规格,
+                RTRIM( b.yj_ks ) AS 开数,
+                RTRIM( b.yj_ls ) AS 联数,
+                RTRIM( b.yj_desc ) AS 印件备注 
+            FROM
+                `工单_基本资料` AS a
+                JOIN `工单_印件资料` AS b ON b.Yj_Gdbh = a.Gd_gdbh 
+            WHERE
+                a.Gd_gdbh = '{$workOrder}' AND a.行号 = 1 AND b.yj_Yjno = '{$yjno}'";
+        $list = Db::query($sql);
+        if (empty($list)){
+            $this->success('未找到订单数据');
+        }
+        $list[0]['开单日期'] = date('Y-m-d',strtotime($list[0]['开单日期']));
+        $list[0]['交货日期'] = date('Y-m-d',strtotime($list[0]['交货日期']));
+        $list[0]['订货数量'] = (int)$list[0]['订货数量'];
+        $list[0]['联数'] = (int)$list[0]['联数'];
+        $list[0]['印件代号及名称']  = $list[0]['印件代号'].' '.$list[0]['印件名称'];
+        $list[0]['投料数量'] = $list[0]['订货数量'];
+        unset($list[0]['印件代号'],$list[0]['印件名称']);
+        return($list[0]);
+    }
+
+    /**打印作业流程单->物料资料获取
+     * @param $workOrder
+     * @return bool|\PDOStatement|string|\think\Collection
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+    public function MaterielDetailGet($workOrder)
+    {
+        $where = [
+            'BOM_工单编号' => $workOrder,
+        ];
+        $filed = 'rtrim(BOM_物料编码) as 物料编码,rtrim(BOM_物料名称) as 物料名称,rtrim(BOM_投料单位) as 投料单位,rtrim(BOM_计划用量) as 计划用量';
+        $list = \db('工单_bom资料')->where($where)->field($filed)->select();
+        if (empty($list)){
+            $this->success('未找到物料资料信息');
+        }
+        foreach ($list as $key=>$value){
+            $list[$key]['物料代码及名称'] = $value['物料编码'].' '.$value['物料名称'];
+            $list[$key]['计划用量'] = (float)$value['计划用量'];
+            unset($list[$key]['物料编码'],$list[$key]['物料名称']);
+        }
+        return $list;
+    }
+
+    /**
+     * 打印作业流程单->工艺资料获取
+     * @param $workOrder
+     * @return bool|\PDOStatement|string|\think\Collection
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+    public function PrintDetailGet($workOrder,$yjno,$gxh)
+    {
+        $where = [
+            'Gy0_gdbh' => $workOrder,
+            'Gy0_yjno' => $yjno,
+            'Gy0_gxh'  => ['<=',$gxh]
+        ];
+        $filed = 'rtrim(Gy0_yjno) as yjno,rtrim(Gy0_gxh) as gxh,rtrim(Gy0_gxmc) as gxmc,rtrim(Add_gxmc) as add_gxmc,
+        rtrim(损耗系数) as 损耗系数,rtrim(Gy0_ls) as ls,rtrim(Gy0_计划接货数) as 计划接货数,rtrim(Gy0_计划损耗) as 计划损耗,
+        rtrim(Gy0_辅助工时) as 装版工时,rtrim(Gy0_小时产能) as 小时定额,rtrim(Gy0_生产工时) as 生产工时,rtrim(工序备注) as 工序备注';
+        $list = \db('工单_工艺资料')
+            ->where($where)
+            ->field($filed)
+            ->select();
+        if (empty($list)){
+            $this->success('工单工艺为空');
+        }
+        foreach ($list  as $key=>$value){
+            if ($value['yjno']<10){
+                $value['yjno'] = '0'.$value['yjno'];
+            }
+            if ($value['gxh']<10){
+                $value['gxh'] = '0'.$value['gxh'];
+            }
+            if ($value['add_gxmc'] !== null){
+
+                $list[$key]['印件及工序名称'] = $value['yjno'].'-'.$value['gxh'].'-->'.$value['gxmc'].'【'.$value['add_gxmc'].'】';
+            }else{
+                $list[$key]['印件及工序名称'] = $value['yjno'].'-'.$value['gxh'].'-->'.$value['gxmc'];
+            }
+            $list[$key]['转序数'] = (int)($value['计划接货数']/$value['ls']);
+            $list[$key]['报废定额'] = (int)($value['计划损耗']/$value['ls']);
+            $list[$key]['允损比例'] = round(($value['计划损耗']/$value['计划接货数'])*100,2).'%';
+            unset($list[$key]['yjno'],$list[$key]['gxh'],$list[$key]['gxmc'],$list[$key]['add_gxmc'],$list[$key]['计划接货数'],$list[$key]['计划损耗']);
+        }
+        return $list;
+    }
+
+    /**
+     * 获取小时产能
+     * @ApiMethod  (GET)
+     * @param  void
+     * @return void
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+
+    public function capacityList()
+    {
+        if ($this->request->isGet() === false){
+            $this->error('请求错误');
+        }
+        $param = $this->request->param();
+        if (empty($param)){
+            $this->error('参数错误');
+        }
+        $machine = explode(' ',$param['machine'])[0];
+        $number = \db('设备_基本资料')->where('设备编号',$machine)->field('rtrim(排单小时定额) as 小时产能')->find();
+        if (empty($number)){
+            $this->error('未找到小时产能');
+        }
+        $this->success('成功',$number['小时产能']);
+    }
+
+
+    /**
+     * 新增工单->添加工单
+     * @ApiMethod (POST)
+     * @param 
+     * @return void
+     * @throws \think\Exception
+     * @throws \think\db\exception\BindParamException
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     * @throws \think\exception\PDOException
+     */
+
+    public function WorkOrderAdd()
+    {
+        if (Request::instance()->isPost() === false){
+            $this->error('请求错误');
+        }
+        $param = Request::instance()->post();
+        if (empty($param)){
+            $this->error('参数错误');
+        }
+        $num = \db('工单_基本资料')->where('Gd_gdbh',$param['gdbh'])->count();
+        $productDetail = \db('产品_基本资料')->where('产品编号',$param['cpdh'])->find();
+        $lastId = \db('工单_基本资料')->order('Uniqid desc')->value('Uniqid');
+        if ($lastId<1000000000){
+            $lastId = 1000000000;
+        }
+        $data = [
+            'Gd_lx' =>$param['zdgd'],
+            'Gd_生产分类' =>$param['sclx'],
+            '成本处理类别' =>'',
+            'Gd_gdbh' =>$param['gdbh'],
+            '行号' =>$num+1 ,
+            'Gd_客户代号' =>$param['khdh'],
+            'Gd_客户名称' =>$param['khmc'],
+            'Gd_khdh' =>$param['khdh'],
+            'Gd_khmc' =>$param['khmc'],
+            '客户料号' =>rtrim($productDetail['客户料号']),
+            '客户ERP编码' =>$param['erp'],
+            'Gd_cpdh' =>$param['cpdh'],
+            'Gd_cpmc' =>$param['cpmc'],
+            '成品代号' =>$param['cpdh'],
+            '成品名称' =>$param['cpmc'],
+            '产品版本号' =>$param['bbh'],
+            '销售订单号' =>$param['xsddh'],
+            '警语版面' =>$param['jybm'],
+            '码源数量' =>$param['mysl'],
+            '排产时库存' =>$param['kcdx'],
+            '投料大箱' =>$param['tldx'],
+            '投料率' =>$param['tll'],
+            '平均合格率' =>$param['hgl'],
+            '进程备注' =>$param['jcbz'],
+            'Gd_desc' =>$param['remark'],
+            '开单日期' =>date('Y-m-d H:i:s',time()),
+            '接单日期' =>$param['start'],
+            '交货日期' =>$param['end'],
+            '订单数量' =>$param['number'],
+            '计量单位' =>$param['tldw'],
+            '计划投料' =>$param['pztl'],
+            '实际投料' =>$param['wxz'],
+            '产品单价' =>0,
+            '入仓日期' =>'1900-01-01 00:00:00',
+            '工单入仓数量' =>0,
+            '工单制程废品' => 0,
+            '工单质检废品' => 0,
+            '工单无形损' => 0,
+            '工单计划损耗' => 0,
+            '工单完工日期' => $param['end'],
+            '投料确认' => '',
+            'gd_statu' => '3-计划中',
+            '直接人工' => 0,
+            '分摊人工' => 0,
+            '直接材料' => 0,
+            '考核直接材料' => 0,
+            '分摊材料' => 0,
+            '考核分摊材料' => 0,
+            '直接折旧' => 0,
+            '水电气费' => 0,
+            '分摊空调' => 0,
+            '分摊锅炉' => 0,
+            '分摊废气处理' => 0,
+            '分摊空压机' => 0,
+            '分摊鼓风机' => 0,
+            '分摊其他' => 0,
+            '待摊人工' => 0,
+            '待摊折旧' => 0,
+            '待摊场地租金' => 0,
+            '待摊其他费用' => 0,
+            '加工费' => 0,
+            '加工费单价' => 0,
+            '成本考核_胶印' => 0,
+            '成本考核_凹印' => 0,
+            '成本考核_丝印' => 0,
+            '成本考核_模切' => 0,
+            '成本考核_检验' => 0,
+            '印版费' => 0,
+            'V23制造成本' => 0,
+            'Prt_rq' => date('Y-m-d H:i:s',time()),
+            'Sys_id' => '',
+            'Sys_rq' => date('Y-m-d H:i:s',time()),
+            'Mod_rq' => date('Y-m-d H:i:s',time()),
+            'U8UID' => '',
+            'Uniqid' => $lastId+1,
+            '工序加工费' => 0,
+        ];
+        $sql= \db('工单_基本资料')->fetchSql(true)->insert($data);
+        $res = \db()->query($sql);
+        if ($res !== false){
+            $this->success('成功');
+        }else{
+            $this->error('失败');
+        }
+    }
+
+    /**
+     * 新增工单->客户代号列表获取
+     * @return void
+     * @throws \think\db\exception\BindParamException
+     * @throws \think\exception\PDOException
+     */
+    public function ClientList()
+    {
+        if ($this->request->isGet() === false){
+            $this->error('请求错误');
+        }
+        $sql = "SELECT DISTINCT
+                    (客户编号),rtrim(客户名称 ) as 客户名称
+                FROM
+                    `产品_基本资料` 
+                GROUP BY
+                    客户编号
+                order by 
+                    客户编号";
+        $list = \db()->query($sql);
+        if (empty($list)){
+            $this->success('未找到客户列表');
+        }
+        foreach ($list as $key=>$value){
+            $list[$key]['客户编号'] = rtrim($value['客户编号']);
+            if ($value['客户编号'] == '1098'){
+                $list[$key]['客户名称'] = '打样专用';
+            }
+        }
+        $this->success('成功',$list);
+    }
+
+    /**
+     * 新增工单->产品代号获取
+     * @ApiMethod (GET)
+     * @param  void
+     * @return void
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+    public function ProductCodeList()
+    {
+        if ($this->request->isGet() === false){
+            $this->error('请求错误');
+        }
+        $param = $this->request->param();
+        if (empty($param)){
+            $this->error('参数错误');
+        }
+        $list = \db('产品_基本资料')
+            ->where('客户编号',$param['cilent'])
+            ->field('rtrim(产品编号) as 产品编号,rtrim(产品名称) as 产品名称')
+            ->select();
+        if (empty($list)){
+            $this->success('未获取到产品数据');
+        }
+        $this->success('成功',$list);
+    }
+
+    /**
+     * 新增印件资料->印件资料添加
+     * @return void
+     * @throws \think\db\exception\BindParamException
+     * @throws \think\exception\PDOException
+     */
+    public function PrintDetailAdd()
+    {
+        if (Request::instance()->isPost() === false){
+            $this->error('请求错误');
+        }
+        $param = Request::instance()->post();
+        if (empty($param)){
+            $this->error('参数错误');
+        }
+        $lastId = \db('工单_印件资料')->order('Uniqid desc')->value('Uniqid');
+        if ($lastId<1000000){
+            $lastId = 1000000;
+        }else{
+            $lastId = $lastId + 1;
+        }
+        $param['Uniqid'] = $lastId;
+        $param['Sys_rq'] = date('Y-m-d H:i:s',time());
+        $param['Mod_rq'] = date('Y-m-d H:i:s',time());
+        $sql = \db('工单_印件资料')->fetchSql(true)->insert($param);
+        $res = \db()->query($sql);
+        if ($res !== false){
+            $this->success('成功');
+        }else{
+            $this->error('失败');
+        }
+    }
+
+
+    //新增工艺资料->工艺资料添加
+
+    public function ProcessDetailAdd()
+    {
+        if (Request::instance()->isPost() === false){
+            $this->error('请求错误');
+        }
+        $param = Request::instance()->post();
+        if (empty($param)){
+            $this->error('参数错误');
+        }
+        $lastId = \db('工单_工艺资料')->order('UniqId desc')->value('UniqId');
+        if ($lastId<100000000){
+            $lastId = 100000000;
+        }else{
+            $lastId = $lastId + 1;
+        }
+
+    }
+
+    /**
+     * 新增工艺资料->印件编号获取
+     * @return void
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+    public function PrintDetailList()
+    {
+        if ($this->request->isGet() === false){
+            $this->error('请求错误');
+        }
+        $param = $this->request->param();
+        if (empty($param)){
+            $this->error('参数错误');
+        }
+        $printList = \db('工单_印件资料')
+            ->where('Yj_Gdbh',$param['workOrder'])
+            ->order('yj_Yjno')
+            ->select();
+        if (empty($printList)){
+            $this->success('未找到该工单印件资料');
+        }
+        $list = [];
+        foreach ($printList as $key=>$value){
+            $list[$key]['name'] = rtrim($value['yj_Yjno']).'-->'.rtrim($value['yj_yjmc']);
+            $list[$key]['no'] = rtrim($value['yj_Yjno']);
+        }
+        $this->success('成功',$list);
+    }
+
+    /**
+     * 工单资料管理->印件资料删除
+     * @return void
+     * @throws \think\Exception
+     * @throws \think\exception\PDOException
+     */
+    public function PrintDetailDel()
+    {
+        if ($this->request->isGet() === false){
+            $this->error('请求错误');
+        }
+        $param = $this->request->param();
+        if (isset($param['UniqId']) === false){
+            $this->error('参数错误');
+        }
+        $res = \db('工单_印件资料')
+            ->where('Uniqid',$param['UniqId'])
+            ->delete();
+        if ($res !== false){
+            $this->success('删除成功');
+        }else{
+            $this->error('删除失败');
+        }
+    }
+
+    /**
+     * 工单资料管理->工艺资料删除
+     * @return void
+     * @throws \think\Exception
+     * @throws \think\exception\PDOException
+     */
+    public function ProcessDetailDel()
+    {
+        if ($this->request->isGet() === false){
+            $this->error('请求错误');
+        }
+        $param = $this->request->param();
+        if (isset($param['UniqId']) === false){
+            $this->error('参数错误');
+        }
+        $res = \db('工单_工艺资料')
+            ->where('UniqId',$param['UniqId'])
+            ->delete();
+        if ($res !== false){
+            $this->success('删除成功');
+        }else{
+            $this->error('删除失败');
+        }
+    }
+}

+ 912 - 0
application/api/controller/WorkOrderVerification.php

@@ -0,0 +1,912 @@
+<?php
+
+namespace app\api\controller;
+
+use app\common\controller\Api;
+use \think\Request;
+use \think\Db;
+use \think\cache;
+/**
+ * 工单核验单维护接口
+ */
+class WorkOrderVerification extends Api
+{
+    protected $noNeedLogin = ['*'];
+    protected $noNeedRight = ['*'];
+
+    /**
+     * 首页
+     *
+     */
+    public function index()
+    {
+        $this->success('请求成功');
+    }
+
+    /**
+     * 获取工单核验单侧边栏
+     * @ApiMethod (GET)
+     */
+    public function getTab()
+    {
+        //get请求
+        if(!$this->request->isGet()){
+            $this->error('请求方式错误');
+        }
+        $is_have_cache = Cache::get('WorkOrderVerification/getTab');
+        if ($is_have_cache === false){
+            $rows = db()->table('db_qczl')
+                ->field('LEFT(sys_rq, 10) as date, COUNT(*) as counts')
+                ->group('date')
+                ->order('UniqId desc')
+                ->limit(30)
+                ->select();
+
+            $arr = db()->table('db_qczl')
+                ->field('LEFT(sys_rq, 10) as date, rtrim(sys_id) as sys_id, COUNT(*) as count')
+                ->where('sys_rq','>=',$rows[count($rows)-1]['date'])
+                ->group('date, sys_id')
+                ->select();
+
+            foreach($rows as $key=>$value){
+                $rows[$key]['sys'] = [];
+                foreach($arr as $k=>$v){
+                    if($value['date'] == $v['date']){
+                        unset($v['date']);
+                        array_push($rows[$key]['sys'],$v);
+                        unset($arr[$k]);
+                    }
+                }
+                $rows[$key]['date'] = str_replace('-', '.', $rows[$key]['date']);
+            }
+            Cache::set('WorkOrderVerification/getTab',$rows,86400);
+        }else{
+            $rows = Cache::get('WorkOrderVerification/getTab');
+        }
+
+        $this->success('成功',$rows);
+    }
+
+    /**
+     * 获取工单核验单侧边栏通过工单编号
+     * @ApiMethod (GET)
+     */
+    public function getTabByGdbh()
+    {
+        //get请求
+        if(!$this->request->isGet()){
+            $this->error('请求方式错误');
+        }
+        $date = date('Y-m-d',strtotime("-1 year"));
+
+        $rows = db()->table('db_qczl')->alias('d')->cache(true)
+            ->field('d.qczl_gdbh, rtrim(y.Gd_cpmc) as Gd_cpmc')
+            ->join('工单_基本资料 y','y.Gd_gdbh = d.qczl_gdbh','left')
+            ->where('d.sys_rq','>=',$date)
+            ->group('d.qczl_gdbh')
+            ->order('d.qczl_gdbh desc')
+            ->limit(65)
+            ->select();
+        $arr = db()->table('db_qczl')->cache(true)
+            ->field('qczl_gdbh, rtrim(sys_id) as sys_id, COUNT(*) as count')
+            ->where('qczl_gdbh','>=',$rows[count($rows)-1]['qczl_gdbh'])
+            ->group('qczl_gdbh, sys_id')
+            ->select();
+        foreach($rows as $key=>$value){
+            $rows[$key]['sys'] = [];
+            foreach($arr as $k=>$v){
+                if($value['qczl_gdbh'] == $v['qczl_gdbh']){
+                    unset($v['qczl_gdbh']);
+                    array_push($rows[$key]['sys'],$v);
+                    unset($arr[$k]);
+                }
+            }
+        }
+
+        $this->success('成功',$rows);
+    }
+
+    /**
+     * 获取工单核验单列表
+     * @ApiMethod (GET)
+     * @param string $date 时间
+     * @param string $sys_id 用户
+     */
+    public function getList()
+    {
+        //get请求
+        if(!$this->request->isGet()){
+            $this->error('请求方式错误');
+        }
+        $req = $this->request->param();
+
+        $page = 1;
+        $limit = 15;
+        if (isset($req['page']) && !empty($req['page'])) $page = $req['page'];
+        if (isset($req['limit']) && !empty($req['limit'])) $limit = $req['limit'];
+
+        $where = [];
+        if (isset($req['date']) && !empty($req['date'])){
+            $where['sys_rq'] = ['LIKE',$req['date'].'%'];
+        }
+        if (isset($req['sys_id']) && !empty($req['sys_id'])) $where['sys_id'] = ['LIKE',$req['sys_id'].'%'];
+        if (isset($req['order']) && !empty($req['order'])) $where['qczl_gdbh'] = $req['order'];
+        if (isset($req['cpmc']) && !empty($req['cpmc'])){
+            //查询工单表
+            $gd = db('工单_基本资料')
+                ->where('Gd_cpmc', 'LIKE', '%'.$req['cpmc'].'%')
+                ->column('Gd_gdbh');
+            $where['qczl_gdbh'] = ['in', $gd];
+        }
+        $rows = db()->table('db_qczl')
+            ->field('qczl_gdbh, qczl_yjno, LEFT(qczl_rq, 10) as qczl_rq, qczl_num, rtrim(qczl_NumDesc) as qczl_NumDesc, qczl_fp, 
+            fp_lb1, fp_lb2, fp_lb3, fp_lb4, fp_lb5, fp_lb6, fp_lb7, fp_lb8, fp_lb9, fp_lb10, fp_lb11, fp_lb12, fp_lb13, fp_lb14, fp_lb15, fp_lb16, fp_lb17, 
+            fp_sl1, fp_sl2, fp_sl3, fp_sl4, fp_sl5, fp_sl6, fp_sl7, fp_sl8, fp_sl9, fp_sl10, fp_sl11, fp_sl12, fp_sl13, fp_sl14, fp_sl15, fp_sl16, fp_sl17, 
+            rtrim(sys_id) as sys_id,UniqId')
+            ->where($where)
+            ->order('UniqId desc')
+//            ->cache(true,300)
+            ->page($page,$limit)
+            ->select();
+
+        $total = db()->table('db_qczl')->where($where)->count();
+        $gd = db()->table('工单_基本资料')->column('Gd_gdbh, Gd_cpmc');
+        
+        foreach ($rows as $key=>$value){
+            $rows[$key]['Gd_cpmc'] = array_key_exists($value['qczl_gdbh'],$gd) ? sprintf("%02d", $value['qczl_yjno']).'-'.trim($gd[$value['qczl_gdbh']]) : '';
+
+            for ($i=1;$i<=17;$i++){
+                if ($value['fp_sl'.$i]==0){
+                    $rows[$key]['sl_lb'.$i] = '';
+                }else{
+                    $rows[$key]['sl_lb'.$i] = trim($value['fp_sl'.$i].'-->'.$value['fp_lb'.$i]);
+                }
+                unset($rows[$key]['fp_sl'.$i]);
+                unset($rows[$key]['fp_lb'.$i]);
+            }
+        }
+
+        $data = [
+            'total'          => $total,
+            'rows'          => $rows,
+        ];
+        $this->success('成功',$data);
+    }
+
+    /**
+     * 获取工单核验单信息
+     * @ApiMethod (GET)
+     * @param string $UniqId UniqId
+     */
+    public function getInfo()
+    {
+        //get请求
+        if(!$this->request->isGet()){
+            $this->error('请求方式错误');
+        }
+        $req = $this->request->param();
+        if (isset($req['UniqId']) && !empty($req['UniqId'])){
+            $UniqId = $req['UniqId'];
+        }else{
+            $this->error('参数错误');
+        }
+
+        $rows = db()->table('db_qczl')->alias('d')
+            ->field('d.*, ')
+            ->join('工单_基本资料 g', 'd.')
+            ->where('d.UniqId',$UniqId)
+            ->select();
+
+
+        $this->success('成功',$rows);
+    }
+    /**
+     * 获取单个工单核检单信息
+     * @ApiMethod GET
+     * @params string UniqId
+    */
+    public function getOneWorkOrder(){
+        if (Request::instance()->isGet() == false){
+            $this->error('非法请求');
+        }
+        $params = Request::instance()->param();
+        if (!isset($params['UniqId']) || empty($params['UniqId'])){
+            $this->error('参数错误');
+        }
+        $field = 'qczl_gdbh,qczl_Pygd,qczl_yjno,qczl_gxh,qczl_gxmc,qczl_type,qczl_rq,qczl_num,qczl_fp,
+        qczl_NumDesc,qczl_NumDesc1,qczl_NumDesc2,qczl_NumDesc3,qczl_NumDesc4,qczl_NumDesc5,qczl_NumDesc6,qczl_NumDesc7,qczl_NumDesc8,
+        fp_lb1,fp_lb2,fp_lb3,fp_lb4,fp_lb5,fp_lb6,fp_lb7,fp_lb8,fp_lb9,fp_lb10,fp_lb11,fp_lb12,fp_lb13,trim(fp_lb14) as fp_lb14,trim(fp_lb15) as fp_lb15,trim(fp_lb16) as fp_lb16,trim(fp_lb17) as fp_lb17,
+        fp_sl1,fp_sl2,fp_sl3,fp_sl4,fp_sl5,fp_sl6,fp_sl7,fp_sl8,fp_sl9,fp_sl10,fp_sl11,fp_sl12,fp_sl13,fp_sl14,fp_sl15,fp_sl16,fp_sl17
+        fp_bh1,fp_bh2,fp_bh3,fp_bh4,fp_bh5,fp_bh6,fp_bh7,fp_bh8,fp_bh9,fp_bh10,fp_bh11,fp_bh12,fp_bh13,
+        fp_bz1,fp_bz2,fp_bz3,fp_bz4,fp_bz5,fp_bz6,fp_bz7,fp_bz8,fp_bz9,fp_bz10,fp_bz11,fp_bz12,fp_bz13,
+        fp_gxmc1,fp_gxmc2,fp_gxmc3,fp_gxmc4,fp_gxmc5,fp_gxmc6,fp_gxmc7,fp_gxmc8,fp_gxmc9,fp_gxmc10,fp_gxmc11,fp_gxmc12,fp_gxmc13,
+        sys_id,rtrim(sys_rq) as sys_rq,UniqId';
+        $list = db('db_qczl')->where('UniqId',$params['UniqId'])->field($field)->find();
+        $list['fp_name1'] = '';
+        if (!empty($list['fp_bh1'])){
+            $list['fp_name1'] = db('人事_基本资料')->where('员工编号',$list['fp_bh1'])->value('rtrim(员工姓名)');
+        }
+        $list['fp_name2'] = '';
+        if (!empty($list['fp_bh2'])){
+            $list['fp_name2'] = db('人事_基本资料')->where('员工编号',$list['fp_bh2'])->value('rtrim(员工姓名)');
+        }
+        $list['fp_name3'] = '';
+        if (!empty($list['fp_bh3'])){
+            $list['fp_name3'] = db('人事_基本资料')->where('员工编号',$list['fp_bh3'])->value('rtrim(员工姓名)');
+        }
+        $list['fp_name4'] = '';
+        if (!empty($list['fp_bh4'])){
+            $list['fp_name4'] = db('人事_基本资料')->where('员工编号',$list['fp_bh4'])->value('rtrim(员工姓名)');
+        }
+        $list['fp_name5'] = '';
+        if (!empty($list['fp_bh5'])){
+            $list['fp_name5'] = db('人事_基本资料')->where('员工编号',$list['fp_bh5'])->value('rtrim(员工姓名)');
+        }
+        $list['fp_name6'] = '';
+        if (!empty($list['fp_bh6'])){
+            $list['fp_name6'] = db('人事_基本资料')->where('员工编号',$list['fp_bh6'])->value('rtrim(员工姓名)');
+        }
+        $list['fp_name7'] = '';
+        if (!empty($list['fp_bh7'])){
+            $list['fp_name7'] = db('人事_基本资料')->where('员工编号',$list['fp_bh7'])->value('rtrim(员工姓名)');
+        }
+        $list['fp_name8'] = '';
+        if (!empty($list['fp_bh8'])){
+            $list['fp_name8'] = db('人事_基本资料')->where('员工编号',$list['fp_bh8'])->value('rtrim(员工姓名)');
+        }
+        $list['fp_name9'] = '';
+        if (!empty($list['fp_bh9'])){
+            $list['fp_name9'] = db('人事_基本资料')->where('员工编号',$list['fp_bh9'])->value('rtrim(员工姓名)');
+        }
+        $list['fp_name10'] = '';
+        if (!empty($list['fp_bh10'])){
+            $list['fp_name10'] = db('人事_基本资料')->where('员工编号',$list['fp_bh10'])->value('rtrim(员工姓名)');
+        }
+        $list['fp_name11'] = '';
+        if (!empty($list['fp_bh11'])){
+            $list['fp_name11'] = db('人事_基本资料')->where('员工编号',$list['fp_bh11'])->value('rtrim(员工姓名)');
+        }
+        $list['fp_name12'] = '';
+        if (!empty($list['fp_bh12'])){
+            $list['fp_name12'] = db('人事_基本资料')->where('员工编号',$list['fp_bh12'])->value('rtrim(员工姓名)');
+        }
+        $list['fp_name13'] = '';
+        if (!empty($list['fp_bh13'])){
+            $list['fp_name13'] = db('人事_基本资料')->where('员工编号',$list['fp_bh13'])->value('rtrim(员工姓名)');
+        }
+        $max = db('设备_产量计酬')->where('sczl_gdbh',$list['qczl_gdbh'])->field('MAX(sczl_num) as sczl_num')->find();
+        $list['total_liucheng'] = $max['sczl_num'];
+        $this->success('请求成功',$list);
+    }
+    /**
+     * 获取工单基本信息
+     * @ApiMethod GET
+     * @params string order
+     */
+    public function getOrderInfo(){
+        if (Request::instance()->isGet() == false){
+            $this->error('非法请求');
+        }
+        $params = Request::instance()->param();
+        if (!isset($params['order']) || empty($params['order'])){
+            $this->error('参数错误');
+        }
+        $list = db('工单_基本资料')->alias('a')
+            ->join('工单_印件资料 b','a.Gd_gdbh = b.Yj_Gdbh','left')
+            ->where('a.Gd_gdbh',$params['order'])
+            ->where('a.行号',1)
+            ->field('a.Gd_cpmc,b.yj_Yjno,b.yj_yjmc')
+            ->find();
+        $this->success('请求成功',$list);
+    }
+    /**
+     * 获取印件名称及工序
+     * @ApiMethod GET
+     * @params string order
+     * @params string yj_no
+    */
+    public function getYjInfo(){
+        if (Request::instance()->isGet() == false){
+            $this->error('非法请求');
+        }
+        $params = Request::instance()->param();
+        if (!isset($params['order']) || empty($params['order'])){
+            $this->error('参数错误');
+        }
+        if (!isset($params['yj_no']) || empty($params['yj_no'])){
+            $this->error('参数错误');
+        }
+        $where['Yj_Gdbh'] = $params['order'];
+        $where['yj_Yjno'] = $params['yj_no'];
+        $list = db('工单_印件资料')->where($where)->field('yj_yjmc')->find();
+        $option['Gy0_gdbh'] = $params['order'];
+        $option['Gy0_yjno'] = $params['yj_no'];
+        $option['Gy0_site'] = '检验车间';
+        $option['Gy0_gxmc'] = array('not in',['包装','外发加工','废挑正','成品防护']);
+        $gxList = db('工单_工艺资料')->where($option)->field('Gy0_gxh,rtrim(Gy0_gxmc) as Gy0_gxmc,rtrim(Add_gxmc) as Add_gxmc')->select();
+        $max = db('设备_产量计酬')->where('sczl_gdbh',$params['order'])->where('sczl_yjno',$params['yj_no'])->field('MAX(sczl_num) as sczl_num')->value('sczl_num');
+        $list['gx_data'] = $gxList;
+        $list['max_num'] = $max;
+        $this->success('请求成功',$list);
+
+    }
+    /**
+     * 获取废品分类
+     * @ApiMethod GET
+     * @params string search
+    */
+    public function getWastInfo(){
+        if (Request::instance()->isGet() == false){
+            $this->error('非法请求');
+        }
+        $params = Request::instance()->param();
+        if (!isset($params['search']) || empty($params['search'])){
+            $this->error('参数错误');
+        }
+        $where['分类'] = '废品分类';
+        $where['名称'] = array('like','%'.$params['search'].'%');
+        $data = db('erp_常用字典')->where($where)->column('名称');
+        // 分割字符串并合并相同项
+        $resultArray = [];
+        foreach ($data as $item) {
+            $parts = explode('_', $item);
+            // 使用第一个部分作为一级键,第二个部分作为二级键
+            $firstKey = $parts[0];
+            $secondKey = $parts[1];
+            $thirdValue = $parts[2];
+
+            $resultArray[$firstKey][$secondKey][] = $thirdValue;
+        }
+        // 对废品分类下的数组进行升序排序
+        if (isset($resultArray['data']['废品分类'])) {
+            foreach ($resultArray['data']['废品分类'] as &$category) {
+                // 判断是关联数组(单凹等)还是索引数组(分切等)
+                if (is_array($category) && !empty($category) && is_array(current($category))) {
+                    foreach ($category as &$subCategory) {
+                        ksort($subCategory);
+                    }
+                } else {
+                    ksort($category);
+                }
+            }
+        }
+        $this->success('请求成功',$resultArray);
+    }
+    /**
+     *获取工序及责任组长
+     * @ApiMethod GET
+     * @params string type
+     * @params string order
+    */
+    public function getGxAndLeader(){
+        if (Request::instance()->isGet() == false){
+            $this->error('非法请求');
+        }
+        $params = Request::instance()->param();
+        if (!isset($params['type']) || empty($params['type'])){
+            $this->error('参数错误');
+        }
+        if (!isset($params['order']) || empty($params['order'])){
+            $this->error('参数错误');
+        }
+        $type = trim($params['type']);
+        $waste = db('erp_常用字典')->where('名称','like','%'.$type.'%')->find();
+        if (empty($waste)){
+            $this->error('未查询到废品分类');
+        }
+        $wasteType = explode('_',substr($waste['名称'],0,-1));
+        $searchArr = explode('-',$wasteType[1]);
+        $search = substr($searchArr[1],0,6);
+        $where['a.sczl_gdbh'] = $params['order'];
+        $where['a.sczl_type'] = array('like','%'.$search.'%');
+        $list = db('设备_产量计酬')->alias('a')
+            ->join('人事_基本资料 b','a.sczl_bh1 = b.员工编号','left')
+            ->where($where)->cache(true,86400)->field('distinct(a.sczl_gxmc),a.sczl_bzdh,a.sczl_jtbh,a.sczl_bh1,b.员工姓名 as name')
+            ->select();
+        $count = count($list);
+        $list[$count]['sczl_gxmc'] = '99-外发加工';
+        $list[$count]['sczl_bzdh'] = 'A班';
+        $list[$count]['sczl_jtbh'] = '';
+        $list[$count]['sczl_bh1'] = '000000';
+        $list[$count]['name'] = '计时工';
+        $this->success('请求成功',$list);
+    }
+    /**
+     * 修改工单核检单
+     * @ApiMethod POST
+     * @params array data
+    */
+    public function edit(){
+        if (Request::instance()->isPost() == false){
+            $this->error('非法请求');
+        }
+        $params = Request::instance()->post();
+        if (!isset($params['UniqId'])){
+            $this->error('参数不能为空');
+        }
+        $id = $params['UniqId'];
+        unset($params['UniqId']);
+        $sql = db('db_qczl')->where('UniqId',$id)->fetchSql(true)->update($params);
+        $res = Db::query($sql);
+        if ($res !== 0){
+            $this->success('更新成功');
+        }else{
+            $this->error('更新失败');
+        }
+    }
+    /**
+     * 新增工单核检单
+     * @ApiMethod POST
+     * @params array data
+    */
+    public function add(){
+        if (Request::instance()->isPost() == false){
+            $this->error('非法请求');
+        }
+        $params = Request::instance()->post();
+        $UniqId = db('db_qczl')->order('UniqId desc')->value('UniqId');
+        if ($UniqId < 10000000){
+            $UniqId = 10000000;
+        }else{
+            $UniqId = $UniqId + 1;
+        }
+        $params['UniqId'] = $UniqId;
+        $params['sys_rq'] = date('Y-m-d H:i:s');
+        $res = \db('db_qczl')->insert($params);
+        if ($res !== false){
+            $this->success('新增成功');
+        }else{
+            $this->error('新增失败');
+        }
+    }
+    /**
+     * 工单核检废品分布
+     * @ApiMethod GET
+     * @params string order
+    */
+    public function wasteDistribution(){
+        if (Request::instance()->isGet() == false){
+            $this->error('非法请求');
+        }
+        $params = Request::instance()->param();
+        if (!isset($params['order']) || empty($params['order'])){
+            $this->error('参数错误');
+        }
+        $field = '
+        rtrim(fp_lb1) as fp_lb1,rtrim(fp_lb2) as fp_lb2,rtrim(fp_lb3) as fp_lb3,rtrim(fp_lb4) as fp_lb4,rtrim(fp_lb5) as fp_lb5,rtrim(fp_lb6) as fp_lb6,rtrim(fp_lb7) as fp_lb7,
+        rtrim(fp_lb8) as fp_lb8,rtrim(fp_lb9) as fp_lb9,rtrim(fp_lb10) as fp_lb10,rtrim(fp_lb11) as fp_lb11,rtrim(fp_lb12) as fp_lb12,rtrim(fp_lb13) as fp_lb13,
+        fp_sl1,fp_sl2,fp_sl3,fp_sl4,fp_sl5,fp_sl6,fp_sl7,fp_sl8,fp_sl9,fp_sl10,fp_sl11,fp_sl12,fp_sl13
+        ';
+        $data = db('db_qczl')->name('db_qczl')->where('qczl_gdbh',$params['order'])->field($field)->select();
+        if (empty($data)){
+            $this->error('暂无废品数据');
+        }
+        // 用于存储废品类别和对应废品数量的数组
+        $categories = array();
+        // 循环遍历原始数组
+        foreach ($data as $item) {
+            // 提取废品类别和对应废品数量
+            foreach ($item as $key => $value) {
+                if (strpos($key, "fp_lb") === 0) {
+                    $categoryKey = $key;
+                    $quantityKey = str_replace("fp_lb", "fp_sl", $key);
+                    $quantityValue = $item[$quantityKey];
+
+                    if (!isset($categories[$value])) {
+                        $categories[$value] = 0;
+                    }
+
+                    $categories[$value] += (int)$quantityValue;
+                }
+            }
+        }
+        ksort($categories);
+        $wasteTotal = db('db_qczl')->where('qczl_gdbh',$params['order'])->sum('qczl_fp');
+        if (empty($wasteTotal)){
+            $wasteTotal = 0;
+        }
+        $where['a.Gd_gdbh'] = $params['order'];
+        $where['a.行号'] = 1;
+        $gdInfo = db('工单_基本资料')->alias('a')
+            ->join('工单_印件资料 b','a.Gd_gdbh = b.Yj_Gdbh','left')
+            ->where($where)->field('a.Gd_gdbh,a.实际投料,b.yj_Yjno,b.yj_yjmc')->find();
+        $gdInfo['yj_Yjno'] = $gdInfo['yj_Yjno'] > 10 ? $gdInfo['yj_Yjno']:'0'.$gdInfo['yj_Yjno'];
+        $gdInfo['实际投料'] = (int)($gdInfo['实际投料'] * 10000);
+        $gdInfo['wasteTotal'] = $wasteTotal;
+        $finishNum = db('成品入仓')->where('jjcp_gdbh',$params['order'])->sum('jjcp_sl');
+        $gdInfo['passRate'] = '';
+        if (!empty($finishNum)){
+            $gdInfo['passRate'] = number_format((int)$finishNum/$gdInfo['实际投料']*100,2).'%';
+        }
+        //左侧废品数据
+        $wasteData = array();
+        $i = 0;
+        foreach ($categories as $key=>$value){
+            if ($value != 0){
+                $wasteData[$i]['type'] = $key;
+                $wasteData[$i]['num'] = $value;
+                $wasteData[$i]['lossesRate'] = number_format($value/$gdInfo['实际投料']*100,4).'%';
+                $wasteData[$i]['wasteRate'] = number_format($value/$wasteTotal*100,2).'%';
+                $i++;
+            }
+        }
+        // 按首字母相同的键将值相加
+        $newArray = array();
+        foreach ($categories as $key => $value) {
+            $firstLetter = strtoupper(substr($key, 0, 1)); // 获取首字母并转换为大写
+
+            if (!isset($newArray[$firstLetter])) {
+                $newArray[$firstLetter] = 0;
+            }
+
+            $newArray[$firstLetter] += $value;
+        }
+        // 去掉值为零的项
+        $newArray = array_filter($newArray, function($value) {
+            return $value !== 0;
+        });
+        //右侧废品数据
+        $rightData = array();
+        $i = 0;
+        $name = array();
+        foreach ($newArray as $key=>$value){
+            $item = db('erp_常用字典')->where('名称','like','%'.$key.'%')->value('名称');
+            $item = explode('_',substr($item,0,-1));
+            $rightData[$i]['type'] = $item[1];
+            $rightData[$i]['rate'] = number_format($value/$wasteTotal*100,0).'%';
+            $name[$i] = $item[1];
+            $i++;
+        }
+        $gdInfo['wasteData'] = $wasteData;
+        $gdInfo['rightData'] = $rightData;
+        $gdInfo['rightTitle'] = $name;
+        $this->success('请求成功',$gdInfo);
+    }
+    /**
+     * 获取工单工序状态
+     * @ApiMethod GET
+     * @params string order
+     * 计划产量计算方式:上个工序计划产量-(基础损耗+损耗率*上个工序计划产量)*损耗系数*计损色数)
+     * lastNum - (Gy0_Rate0 + Gy0_Rate1 * lastNum )* 损耗系数(Gy0_Rate3) * Gy0_Ms
+    */
+    public function getOrderDate(){
+        if (Request::instance()->isGet() == false){
+            $this->error('非法请求');
+        }
+        $params = Request::instance()->param();
+        if (!isset($params['order']) || empty($params['order'])){
+            $this->error('参数错误');
+        }
+        $where['a.Gy0_gdbh'] = $params['order'];
+        $where['a.Gy0_sbbh'] = array('neq',' ');
+        $productNum = db('工单_基本资料')->where('Gd_gdbh',$params['order'])->value('计划投料');
+        $gyData = db('工单_工艺资料')->alias('a')
+            ->join('设备_产量计酬 b','a.Gy0_gdbh = b.sczl_gdbh and a.Gy0_gxh = b.sczl_gxh','left')
+            ->where($where)
+            ->field('a.Gy0_yjno,a.Gy0_gxh,rtrim(a.Gy0_gxmc) as Gy0_gxmc,a.Gy0_sbbh,a.Gy0_Rate0,a.Gy0_Rate1,a.损耗系数 as Gy0_Rate3,a.Gy0_Ms,a.Gy0_SITE,a.Gy0_计划接货数,a.PD_WG,
+            a.UniqId,sum(b.sczl_cl) as cl')
+            ->group('a.Gy0_gxh')
+            ->select();
+        $lastNum = $productNum;
+        $res = [];
+        foreach ($gyData as $key=> $process) {
+            $res[$key]['UniqId'] = $process['UniqId'];
+            $res[$key]['Gy0_yjno'] = $process['Gy0_yjno'] > 10 ? $process['Gy0_yjno'] : '0'.$process['Gy0_yjno'];
+            $res[$key]['Gy0_gxh'] = $process['Gy0_gxh'] > 10 ? $process['Gy0_gxh'] : '0'.$process['Gy0_gxh'];
+            $res[$key]['Gy0_gxmc'] = $process['Gy0_gxmc'];
+            $res[$key]['Gy0_sbbh'] = rtrim($process['Gy0_sbbh']);
+            $res[$key]['PD_WG'] = $process['PD_WG'];
+            $res[$key]['finish'] = empty($process['cl']) ? 0: (int)$process['cl'];
+            // 计算工序计划产量
+            if ($process["Gy0_gxh"] == "1") {
+                // 第一道工序直接使用初始计划产量
+                $Num = $lastNum;
+            } else {
+                $Gy0_Ms = $gyData[$key-1]['Gy0_Ms'];
+                $Gy0_Rate0 = $gyData[$key-1]['Gy0_Rate0'];
+                $Gy0_Rate1 = $gyData[$key-1]['Gy0_Rate1'];
+                $Gy0_Rate3 = $gyData[$key-1]['Gy0_Rate3'];
+                // 大于第一道工序,使用上一道工序的计划产量
+                // 根据公式计算工序计划产量
+                if ($Gy0_Ms != "0.00") {
+                    $Num = $lastNum - ($Gy0_Rate0 + $Gy0_Rate1 * $lastNum) * $Gy0_Rate3 * $Gy0_Ms;
+                } else {
+                    $Num = $lastNum - ($Gy0_Rate0 + $Gy0_Rate1 * $lastNum) * $Gy0_Rate3;
+                }
+            }
+            if (trim($process['Gy0_SITE']) == '检验车间'){
+                $res[$key]['plan'] = (int)$process['Gy0_计划接货数'];
+            }else{
+                $res[$key]['plan'] = (int)round($Num);
+            }
+            $finish_rate = $res[$key]['finish']/$res[$key]['plan'];
+            $res[$key]['finish_rate'] = '';
+            if ($finish_rate != 0){
+                $res[$key]['finish_rate'] = number_format($finish_rate*100,2).'%';
+            }
+
+            // 更新 $lastNum 为当前工序的计划产量
+            $lastNum = $Num;
+        }
+        $this->success('请求成功',$res);
+    }
+    /**
+     * 工单工序状态更正
+     * @ApiMethod POST
+     * @params string UniqId
+     * @params string date
+    */
+    public function editOrderFinishDate(){
+        if (Request::instance()->isPost() == false){
+            $this->error('非法请求');
+        }
+        $params = Request::instance()->post();
+        if (!isset($params['UniqId']) || !isset($params['date'])){
+            $this->error('参数错误');
+        }
+        if (empty($params['UniqId'])){
+            $this->error('参数不能为空');
+        }
+        if (empty($params['date'])){
+            $params['date'] = '1900-01-01 00:00:00';
+        }
+        $res = db('工单_工艺资料')->where('UniqId',$params['UniqId'])->setField('PD_WG',$params['date']);
+        if ($res != false){
+            $this->success('更新成功');
+        }else{
+            $this->error('更新失败');
+        }
+    }
+    /**
+     * 工单工序生产进程菜单栏
+     * @ApiMethod GET
+     * @params string order
+    */
+    public function getOrderProcessLeft(){
+        if (Request::instance()->isGet() == false){
+            $this->error('非法请求');
+        }
+        $params = Request::instance()->param();
+        if (!isset($params['order']) || empty($params['order'])){
+            $this->error('参数错误');
+        }
+        $where['Gd_gdbh'] = $params['order'];
+        $where['行号'] = 1;
+        //工单基本资料
+        $info = db('工单_基本资料')->where($where)->field('rtrim(成品代号)  as code,rtrim(成品名称) as name')->find();
+        //工艺资料
+        $option['Gy0_gdbh'] = $params['order'];
+        $gyInfo = db('工单_工艺资料')
+            ->where($option)
+            ->where(function ($query) {
+                $query->where('Gy0_sbbh', '<>', '')
+                    ->whereOr('Gy0_gxmc', '核检')
+                    ->whereOr('Gy0_gxmc', '成品防护');
+            })
+            ->field('Gy0_yjno,Gy0_gxh,rtrim(Gy0_gxmc) as Gy0_gxmc')
+            ->select();
+        foreach ($gyInfo as $key=>$value){
+            $gyInfo[$key]['Gy0_yjno'] = $value['Gy0_yjno'] > 10 ? $value['Gy0_yjno'] : '0'.$value['Gy0_yjno'];
+            $gyInfo[$key]['Gy0_gxh'] = $value['Gy0_gxh'] > 10 ? $value['Gy0_gxh'] : '0'.$value['Gy0_gxh'];
+        }
+        $res['Gd_info'] = $info;
+        $res['Gy_info'] = $gyInfo;
+        $this->success('请求成功',$res);
+    }
+    /**
+     * 工单工序生产进程右侧
+     * @ApiMethod GET
+     * @params string order
+     * @params string gxNo
+    */
+    public function getOrderProcessRight(){
+        if (Request::instance()->isGet() == false){
+            $this->error('非法请求');
+        }
+        $params = Request::instance()->param();
+        if (!isset($params['order']) || empty($params['order'])){
+            $this->error('参数错误');
+        }
+        if (!isset($params['gxNo']) || empty($params['gxNo'])){
+            $this->error('参数错误');
+        }
+        $total = db('设备_产量计酬')->where('sczl_gdbh',$params['order'])->order('sczl_num')->column('distinct(sczl_num)');
+        $where['sczl_gxh'] = (int)$params['gxNo'];
+        $where['sczl_gdbh'] = $params['order'];
+        $process = db('设备_产量计酬')->where($where)->order('sczl_num')->column('distinct(sczl_num)');
+        $res['total_process'] = $total;
+        $res['process'] = $process;
+        $this->success('请求成功',$res);
+    }
+    /**
+     * 核检废品日统计
+     * @ApiMethod GET
+     * @params date start_date
+     * @params date end_date
+    */
+    public function getDaysWast()
+    {
+        if (Request::instance()->isGet() == false) {
+            $this->error('非法请求');
+        }
+        $params = Request::instance()->param();
+        if (!isset($params['start_date']) || empty($params['start_date'])) {
+            $this->error('参数错误');
+        }
+        if (!isset($params['end_date']) || empty($params['end_date'])) {
+            $this->error('参数错误');
+        }
+        $where['qczl_rq'] = array('between time', [$params['start_date'], $params['end_date']]);
+        $field = '
+        rtrim(fp_lb1) as fp_lb1,rtrim(fp_lb2) as fp_lb2,rtrim(fp_lb3) as fp_lb3,rtrim(fp_lb4) as fp_lb4,rtrim(fp_lb5) as fp_lb5,rtrim(fp_lb6) as fp_lb6,rtrim(fp_lb7) as fp_lb7,
+        rtrim(fp_lb8) as fp_lb8,rtrim(fp_lb9) as fp_lb9,rtrim(fp_lb10) as fp_lb10,rtrim(fp_lb11) as fp_lb11,rtrim(fp_lb12) as fp_lb12,rtrim(fp_lb13) as fp_lb13,
+        fp_sl1,fp_sl2,fp_sl3,fp_sl4,fp_sl5,fp_sl6,fp_sl7,fp_sl8,fp_sl9,fp_sl10,fp_sl11,fp_sl12,fp_sl13,
+        fp_bh1,fp_bh2,fp_bh3,fp_bh4,fp_bh5,fp_bh6,fp_bh7,fp_bh8,fp_bh9,fp_bh10,fp_bh11,fp_bh12,fp_bh13,
+        rtrim(fp_bz1) as fp_bz1, rtrim(fp_bz2) as fp_bz2, rtrim(fp_bz3) as fp_bz3, rtrim(fp_bz4) as fp_bz4, rtrim(fp_bz5) as fp_bz5, rtrim(fp_bz6) as fp_bz6, rtrim(fp_bz7) as fp_bz7,
+        rtrim(fp_bz8) as fp_bz8, rtrim(fp_bz9) as fp_bz9, rtrim(fp_bz10) as fp_bz10, rtrim(fp_bz11) as fp_bz11, rtrim(fp_bz12) as fp_bz12, rtrim(fp_bz13) as fp_bz13,
+        qczl_rq
+        ';
+        $resultArray = array();
+        $key = 'getDaysWast'.$params['start_date'].'/'.$params['end_date'];
+        $is_have_cache = Cache::has($key);
+        if ($is_have_cache === false){
+            $data = db('db_qczl')
+                ->where($where)
+                ->where(function ($query) {
+                    for ($i = 1; $i <= 13; $i++) {
+                        $query->whereOr("fp_lb$i", 'like', '%K%','AND',"fp_sl$i",'>',0);
+                    }
+                })
+                ->field($field)->select();
+            $list = [];
+            $j = 0;
+            foreach ($data as $entry) {
+                for ($i = 1; $i <= 13; $i++) {
+                    $labelKey = "fp_lb" . $i;
+                    $slKey = "fp_sl" . $i;
+                    $bhKey = "fp_bh" . $i;
+                    $bzKey = "fp_bz" . $i;
+                    if (!empty($entry[$labelKey])) {
+                        if ((substr($entry[$labelKey],0,3) == 'K02' || substr($entry[$labelKey],0,3) == 'K01') && $entry[$slKey] != '0'){
+                            $list[$j]['fp_lb'] = $entry[$labelKey];
+                            $list[$j]['fp_sl'] = $entry[$slKey];
+                            $list[$j]['fp_bh'] = $entry[$bhKey];
+                            $name = db('人事_基本资料')->where('员工编号',$entry[$bhKey])->value('rtrim(员工姓名)');
+                            $list[$j]['fp_name'] = empty($name) ? '计时工' : $name;
+                            $list[$j]['fp_bz'] = $entry[$bzKey];
+                            $list[$j]['qczl_rq'] = $entry['qczl_rq'];
+                            $j++;
+                        }
+                    }
+                }
+            }
+            foreach ($list as $item) {
+                $found = false;
+                foreach ($resultArray as &$resultItem) {
+                    if ($item["fp_lb"] === $resultItem["fp_lb"] && $item["fp_bh"] === $resultItem["fp_bh"]) {
+                        $resultItem["fp_sl"] += (int)$item["fp_sl"];
+                        $found = true;
+                        break;
+                    }
+                }
+                if (!$found) {
+                    $resultArray[] = $item;
+                }
+            }
+            // 使用usort进行排序
+            usort($resultArray, function($a, $b) {
+                // First, sort by fp_lb (K01/K02)
+                $compareLb = strcmp($a['fp_lb'], $b['fp_lb']);
+                if ($compareLb !== 0) {
+                    return $compareLb;
+                }
+
+                // If fp_lb is the same, prioritize B班 over A班
+                $compareBz = strcmp($a['fp_bz'], $b['fp_bz']);
+                if ($compareBz !== 0) {
+                    return (trim($a['fp_bz']) === 'B班') ? -1 : 1;
+                }
+
+                // If fp_bz is the same, sort by fp_bh
+                $compareBh = strcmp($a['fp_bh'], $b['fp_bh']);
+                return $compareBh;
+            });
+            Cache::set($key,$resultArray,86400);
+        }else{
+            $resultArray = Cache::get($key);
+        }
+
+        $this->success('请求成功',$resultArray);
+    }
+    /**
+     * 月度核检废品责任人统计
+     * @ApiMethod GET
+     * @params string date
+    */
+    public function getMonthPeopleTotal(){
+        if (Request::instance()->isGet() == false) {
+            $this->error('非法请求');
+        }
+        $params = Request::instance()->param();
+        if (!isset($params['date']) || empty($params['date'])) {
+            $this->error('参数错误');
+        }
+
+    }
+    /**
+     * 工单质检废品统计
+     * @ApiMethod GET
+     * @params string order
+    */
+    public function getOrderWasteTotal(){
+        if (Request::instance()->isGet() == false) {
+            $this->error('非法请求');
+        }
+        $params = Request::instance()->param();
+        if (!isset($params['order']) || empty($params['order'])) {
+            $this->error('参数错误');
+        }
+        $field = '
+        rtrim(a.fp_lb1) as fp_lb1,rtrim(a.fp_lb2) as fp_lb2,rtrim(a.fp_lb3) as fp_lb3,rtrim(a.fp_lb4) as fp_lb4,rtrim(a.fp_lb5) as fp_lb5,rtrim(a.fp_lb6) as fp_lb6,rtrim(a.fp_lb7) as fp_lb7,
+        rtrim(a.fp_lb8) as fp_lb8,rtrim(a.fp_lb9) as fp_lb9,rtrim(a.fp_lb10) as fp_lb10,rtrim(a.fp_lb11) as fp_lb11,rtrim(a.fp_lb12) as fp_lb12,rtrim(a.fp_lb13) as fp_lb13,
+        a.fp_sl1,a.fp_sl2,a.fp_sl3,a.fp_sl4,a.fp_sl5,a.fp_sl6,a.fp_sl7,a.fp_sl8,a.fp_sl9,a.fp_sl10,a.fp_sl11,a.fp_sl12,a.fp_sl13,
+        a.fp_bh1,a.fp_bh2,a.fp_bh3,a.fp_bh4,a.fp_bh5,a.fp_bh6,a.fp_bh7,a.fp_bh8,a.fp_bh9,a.fp_bh10,a.fp_bh11,a.fp_bh12,a.fp_bh13,
+        rtrim(a.fp_gxmc1) as fp_gxmc1, rtrim(a.fp_gxmc2) as fp_gxmc2, rtrim(a.fp_gxmc3) as fp_gxmc3, rtrim(a.fp_gxmc4) as fp_gxmc4, rtrim(a.fp_gxmc5) as fp_gxmc5, rtrim(a.fp_gxmc6) as fp_gxmc6, 
+        rtrim(a.fp_gxmc7) as fp_gxmc7,rtrim(a.fp_gxmc8) as fp_gxmc8, rtrim(a.fp_gxmc9) as fp_gxmc9, rtrim(a.fp_gxmc10) as fp_gxmc10, rtrim(a.fp_gxmc11) as fp_gxmc11, rtrim(a.fp_gxmc12) as fp_gxmc12, 
+        rtrim(a.fp_gxmc13) as fp_gxmc13,a.qczl_num,a.qczl_yjno,rtrim(b.成品代号) as product_code,rtrim(b.成品名称) as product_name,b.订单数量,rtrim(b.计量单位) as 计量单位,b.实际投料,b.交货日期,
+        c.yj_ls,d.jjcp_sl,d.jjcp_sj
+        ';
+        $where['a.qczl_gdbh'] = $params['order'];
+        $where['b.行号'] = 1;
+        $data = db('db_qczl')->alias('a')
+            ->join('工单_基本资料 b','a.qczl_gdbh = b.Gd_gdbh','left')
+            ->join('工单_印件资料 c','a.qczl_gdbh = c.Yj_Gdbh','left')
+            ->join('成品入仓 d','a.qczl_gdbh = d.jjcp_gdbh','left')
+            ->where($where)
+            ->field($field)->select();
+        $list = [];
+        $j = 0;
+        foreach ($data as $entry) {
+            for ($i = 1; $i <= 13; $i++) {
+                $labelKey = "fp_lb" . $i;
+                $slKey = "fp_sl" . $i;
+                $bhKey = "fp_bh" . $i;
+                $gxhKey = "fp_gxmc". $i;
+                if (!empty($entry[$labelKey]) && $entry[$slKey] > 0) {
+                    $list[$j]['fp_lb'] = $entry[$labelKey];
+                    $list[$j]['fp_sl'] = $entry[$slKey];
+                    $list[$j]['fp_bh'] = $entry[$bhKey];
+                    $name = db('人事_基本资料')->where('员工编号',$entry[$bhKey])->value('rtrim(员工姓名)');
+                    $list[$j]['fp_name'] =  $name;
+                    $list[$j]['fp_gxh'] = empty(substr($entry[$gxhKey],0,2)) ? "0" : substr($entry[$gxhKey],0,2);
+                    $list[$j]['qczl_num'] = $entry['qczl_num'];
+                    $list[$j]['qczl_yjno'] = $entry['qczl_yjno'];
+                    $list[$j]['product_code'] = $entry['product_code'];
+                    $list[$j]['product_name'] = $entry['product_name'];
+                    $list[$j]['订单数量'] = $entry['订单数量'];
+                    $list[$j]['计量单位'] = $entry['计量单位'];
+                    $list[$j]['交货日期'] = substr($entry['交货日期'],0,10);
+                    $list[$j]['yj_ls'] = $entry['yj_ls'];
+                    $list[$j]['jjcp_sl'] = $entry['jjcp_sl'];
+                    $list[$j]['jjcp_sj'] = substr($entry['jjcp_sj'],0,10);
+                    $j++;
+                }
+            }
+        }
+        $summedData = [];
+        foreach ($list as $item) {
+            $key = $item['qczl_num'] . $item['fp_lb'];
+            if (!isset($summedData[$key])) {
+                $summedData[$key] = $item;
+            } else {
+                $summedData[$key]['fp_sl'] += $item['fp_sl'];
+            }
+        }
+        $fpGxhColumn = array_column($summedData, 'fp_gxh');
+        $qczlNumColumn = array_column($summedData, 'qczl_num');
+        $fpLbColumn = array_column($summedData, 'fp_lb');
+        array_multisort($fpGxhColumn, SORT_ASC, $qczlNumColumn, SORT_ASC, $fpLbColumn, SORT_ASC, $summedData);
+        $summedData = array_values($summedData);
+        $this->success('请求成功',$summedData);
+    }
+}