Просмотр исходного кода

工单生产进程管理优化

qiuenguang 3 часов назад
Родитель
Сommit
2d3210c2ee
1 измененных файлов с 151 добавлено и 0 удалено
  1. 151 0
      application/api/controller/Course.php

+ 151 - 0
application/api/controller/Course.php

@@ -244,6 +244,157 @@ class Course extends Api
         $this->success('成功', $list);
     }
 
+    /**
+     * 工单印件的全部工艺及报工条数
+     * 参数:工单编号、印件编号
+     */
+    public function workOrderProcess()
+    {
+        if ($this->request->isGet() === false) {
+            $this->error('请求错误');
+        }
+        $param = $this->request->param();
+        $workOrderNo = trim((string)($param['工单编号'] ?? ''));
+        $printNo = trim((string)($param['印件编号'] ?? ''));
+        if ($workOrderNo === '' || $printNo === '') {
+            $this->error('参数错误');
+        }
+        $printNos = $this->coursePrintNoValues($printNo);
+        $processes = \db('工单_工艺资料')
+            ->where('Gy0_gdbh', $workOrderNo)
+            ->where('Gy0_yjno', 'in', $printNos)
+            ->field('rtrim(Gy0_gxh) as 工序号, rtrim(Gy0_gxmc) as 工序名称')
+            ->orderRaw('Gy0_gxh+0 asc, Gy0_gxh asc')
+            ->select();
+        $reportCounts = \db('设备_产量计酬')
+            ->where('sczl_gdbh', $workOrderNo)
+            ->where('sczl_yjno', 'in', $printNos)
+            ->field('rtrim(sczl_gxh) as 工序号, COUNT(*) as 报工条数')
+            ->group('sczl_gxh')
+            ->select();
+        $countMap = [];
+        foreach ($reportCounts as $row) {
+            $countMap[$this->courseProcessKey($row['工序号'])] = (int)$row['报工条数'];
+        }
+        $data = [];
+        $seen = [];
+        foreach ($processes as $process) {
+            $processNo = rtrim((string)$process['工序号']);
+            $processKey = $this->courseProcessKey($processNo);
+            if (isset($seen[$processKey])) {
+                continue;
+            }
+            $seen[$processKey] = true;
+            $processName = rtrim((string)$process['工序名称']);
+            $count = $countMap[$processKey] ?? 0;
+            $data[] = [
+                '工序号' => $processNo,
+                '工序名称' => $processName,
+                '报工条数' => $count,
+                '工艺' => $processNo . '-' . $processName . '(' . $count . ')',
+            ];
+        }
+        $this->success('成功', $data);
+    }
+
+    /**
+     * 某道工艺的报工明细,按流程单号从小到大
+     * 参数:工单编号、印件编号、工序号
+     */
+    public function processReport()
+    {
+        if ($this->request->isGet() === false) {
+            $this->error('请求错误');
+        }
+        $param = $this->request->param();
+        $workOrderNo = trim((string)($param['工单编号'] ?? ''));
+        $printNo = trim((string)($param['印件编号'] ?? ''));
+        $processNo = trim((string)($param['工序号'] ?? ''));
+        if ($workOrderNo === '' || $printNo === '' || $processNo === '') {
+            $this->error('参数错误');
+        }
+        $rows = \db('设备_产量计酬')
+            ->alias('a')
+            ->join('设备_基本资料 m', 'a.sczl_jtbh = m.设备编号', 'left')
+            ->where('a.sczl_gdbh', $workOrderNo)
+            ->where('a.sczl_yjno', 'in', $this->coursePrintNoValues($printNo))
+            ->where('a.sczl_gxh', 'in', $this->coursePrintNoValues($processNo))
+            ->field('rtrim(a.sczl_num) as 流程单号, a.sczl_cl as 产量, a.sczl_zcfp as 制程废品, rtrim(a.sczl_jtbh) as 机台编号, rtrim(m.设备名称) as 机台名称, rtrim(a.sczl_bzdh) as 班组代号, a.sys_rq as 上报时间, rtrim(a.sys_id) as 上报人员, rtrim(a.sczl_bh1) as bh1, rtrim(a.sczl_bh2) as bh2, rtrim(a.sczl_bh3) as bh3, rtrim(a.sczl_bh4) as bh4, rtrim(a.sczl_bh5) as bh5, rtrim(a.sczl_bh6) as bh6, rtrim(a.sczl_bh7) as bh7, rtrim(a.sczl_bh8) as bh8, rtrim(a.sczl_bh9) as bh9, rtrim(a.sczl_bh10) as bh10')
+            ->orderRaw('a.sczl_num+0 asc, a.sczl_num asc, a.sys_rq asc')
+            ->select();
+        $employeeCodes = [];
+        foreach ($rows as $row) {
+            for ($i = 1; $i <= 10; $i++) {
+                $code = rtrim((string)$row['bh' . $i]);
+                if ($code !== '' && $code !== '000000') {
+                    $employeeCodes[$code] = $code;
+                }
+            }
+        }
+        $employeeNames = [];
+        if (!empty($employeeCodes)) {
+            $people = \db('人事_基本资料')
+                ->where('员工编号', 'in', array_values($employeeCodes))
+                ->field('rtrim(员工编号) as 员工编号, rtrim(员工姓名) as 员工姓名')
+                ->select();
+            foreach ($people as $person) {
+                $employeeNames[rtrim((string)$person['员工编号'])] = rtrim((string)$person['员工姓名']);
+            }
+        }
+        $data = [];
+        foreach ($rows as $row) {
+            $members = [];
+            for ($i = 1; $i <= 10; $i++) {
+                $code = rtrim((string)$row['bh' . $i]);
+                if ($code === '' || $code === '000000') {
+                    continue;
+                }
+                $members[] = $employeeNames[$code] ?? $code;
+            }
+            $machineNo = rtrim((string)$row['机台编号']);
+            $machineName = rtrim((string)$row['机台名称']);
+            $data[] = [
+                '流程单号' => rtrim((string)$row['流程单号']),
+                '产量' => $row['产量'],
+                '制程废品' => $row['制程废品'],
+                '生产机台' => $machineName !== '' ? $machineNo . ' ' . $machineName : $machineNo,
+                '班组代号' => rtrim((string)$row['班组代号']),
+                '班组人员' => implode(' ', $members),
+                '上报人员' => rtrim((string)$row['上报人员']),
+                '上报时间' => rtrim((string)$row['上报时间']),
+            ];
+        }
+        $totalQty = 0.0;
+        foreach ($data as $item) {
+            $totalQty += (float)$item['产量'];
+        }
+        $this->success('成功', [
+            '产量合计' => floor($totalQty) == $totalQty ? (int)$totalQty : $totalQty,
+            '报工' => $data,
+        ]);
+    }
+
+    private function coursePrintNoValues($value)
+    {
+        $value = rtrim((string)$value);
+        $values = [$value];
+        if ($value !== '' && is_numeric($value)) {
+            $number = (string)(int)$value;
+            $values[] = $number;
+            $values[] = str_pad($number, 2, '0', STR_PAD_LEFT);
+        }
+        return array_values(array_unique($values));
+    }
+
+    private function courseProcessKey($value)
+    {
+        $value = rtrim((string)$value);
+        if ($value !== '' && is_numeric($value)) {
+            return (string)(int)$value;
+        }
+        return $value;
+    }
+
     /**
      * 范围条件只在传入起或止时生效,日期止取到当天结束
      */