request->isGet()) { $this->error('请求错误'); } $data = $this->fetchAndFormatPlateChangeData(); empty($data) ? $this->error('未找到换版数据') : $this->success('成功', $data); } /** * 获取并格式化装版数据 */ private function fetchAndFormatPlateChangeData() { $departments = ['胶印车间', '凹丝印车间', '印后车间', '检验车间']; $list = \db('设备_装版工时') ->alias('a') ->join('设备_基本资料 b', 'a.jtbh = b.设备编号') ->field([ 'DATE_FORMAT(a.sys_rq, "%Y-%m-%d") as day', 'DATE_FORMAT(a.sys_rq, "%Y%m") as month', 'b.使用部门' ]) ->where('b.使用部门', 'in', $departments) ->group('day, b.使用部门') ->order('day DESC') ->select(); return array_reduce($list, function ($result, $item) { $month = $item['month']; $department = $item['使用部门']; $day = $item['day']; $result[$month][$department][] = $day; return $result; }, []); } /** * 装版工时审核数据 * @return void */ public function getMountList() { // 1. 请求验证 if (!$this->request->isGet()) { $this->error('请求错误'); } // 2. 参数验证 $params = $this->validateParams($this->request->param()); // 3. 获取数据 $list = $this->fetchMountData($params); if (empty($list)) { $this->error('未找到数据'); } // 4. 处理数据 $processedList = $this->processListData($list); $this->success('成功', $processedList); } /** * 参数验证 */ private function validateParams($params) { if (empty($params['day']) || empty($params['sist'])) { $this->error('参数错误:day和sist不能为空'); } // 验证日期格式 if (!preg_match('/^\d{4}-\d{2}-\d{2}$/', $params['day'])) { $this->error('参数错误:日期格式不正确'); } return [ 'day' => $params['day'], 'sist' => $params['sist'] ]; } /** * 获取装版数据 */ private function fetchMountData($params) { $fields = [ 'a.gdbh' => '工单编号', 'a.yjno' => '印件号', 'a.gxh' => '工序号', 'b.sczl_gxmc' => '工序名称', 'a.jtbh' => '机台编号', 'a.startTime' => '开始时间', 'a.endTime' => '结束时间', 'a.换版总工时' => '装版总工时', 'a.换版联拼数' => '装版联拼数', 'a.换版类型' => '装版类型', 'a.sys_rq' => '创建时间', 'a.coefficient' => '系数', 'a.装版补产工时', 'a.leader' => '班组长', 'a.leaderConfirm' => '班组长确认时间', 'a.statistics' => '统计人员', 'a.statisticsConfirm' => '统计确认时间', 'a.sys_id' => '上报机台', 'a.Uniqid', 'a.yieldUid' => '关联ID' ]; return \db('设备_装版工时') ->alias('a') ->join('设备_产量计酬 b', 'a.yieldUid = b.UniqId') ->join('设备_基本资料 c', 'a.jtbh = c.设备编号') ->field($fields) ->where('a.sys_rq', 'like', $params['day'] . '%') ->where('c.使用部门', $params['sist']) ->group('a.gdbh, a.yjno, a.gxh, a.jtbh, a.换版类型') ->order('a.jtbh') ->select(); } /** * 处理列表数据 */ private function processListData($list) { return array_map(function ($item) { return [ '工单编号' => $item['工单编号'], '印件号' => $item['印件号'], '工序号' => $item['工序号'], '工序名称' => $item['工序名称'], '机台编号' => $item['机台编号'], '开始时间' => $item['开始时间'], '结束时间' => $item['结束时间'], '装版总工时' => $item['装版总工时'], '装版联拼数' => $item['装版联拼数'], '装版类型' => $item['装版类型'], '创建时间' => $item['创建时间'], '系数' => $item['系数'], '装版补产工时' => $item['装版补产工时'], '班组长' => $item['班组长'], '班组长确认时间' => $item['班组长确认时间'], '统计人员' => $item['统计人员'], '统计确认时间' => $item['统计确认时间'], '上报机台' => $item['上报机台'], 'Uniqid' => $item['Uniqid'], '班组长确认状态' => $this->getConfirmationStatus($item['班组长'], $item['班组长确认时间']), '统计确认状态' => $this->getConfirmationStatus($item['统计人员'], $item['统计确认时间']), '关联ID' => $item['关联ID'], ]; }, $list); } /** * 获取确认状态 */ private function getConfirmationStatus($person, $confirmTime) { return !empty($person) && !empty($confirmTime) ? '已确认' : '未确认'; } /** * 班组长审核 * @return void * @throws BindParamException * @throws PDOException * @throws \think\Exception */ public function leaderConfirm() { if (!$this->request->isPost()) { $this->error('请求错误'); } $param = Request::instance()->post(); if (empty($param)) { $this->error('参数错误'); } $coefficient = $param['coefficient']; $leader = $param['leader']; $leaderConfirm = date('Y-m-d H:i:s'); $sql = \db('设备_装版工时') ->where('Uniqid', $param['Uniqid']) ->fetchSql(true) ->update([ 'coefficient' => $coefficient, 'leaderConfirm' => $leaderConfirm, 'leader' => $leader, '换版总工时' => $param['换版总工时'], '换版联拼数' => $param['换版联拼数'], '换版类型' => $param['换版类型'] ]); $res = \db()->query($sql); if ($res !== false) { $this->success('确认成功'); }else{ $this->error('确认失败'); } } /** * 统计员审核 * @return void * @throws BindParamException * @throws PDOException * @throws \think\Exception */ public function statisticsConfirm() { if (!$this->request->isPost()) { $this->error('请求错误'); } $param = Request::instance()->post(); if (empty($param)) { $this->error('参数错误'); } $statisticsConfirm = date('Y-m-d H:i:s',time()); $sql = \db('设备_装版工时') ->where('Uniqid', $param['Uniqid']) ->fetchSql(true) ->update(['装版补产工时' => $param['装版补产工时'], 'statisticsConfirm' => $statisticsConfirm, 'statistics' => $param['statistics']]); $res = \db()->query($sql); $clSql = \db('设备_产量计酬') ->where('UniqId', $param['yieldUid']) ->fetchSql(true) ->update(['sczl_装版工时' => $param['装版补产工时']]); $clRes = \db()->query($clSql); if ($res !== false && $clRes !== false) { $this->success('确认成功'); }else{ $this->error('确认失败'); } } }