success('请求成功'); } /** * 获取报工历史几记录 * */ public function getTab(){ //get请求 if(!$this->request->isGet()){ $this->error('请求方式错误'); } $param = $this->request->param(); $where = [ '子订单编号' => $param['order_id'], 'sczl_jtbh' => $param['sczl_jtbh'] ]; //通过当前子订单编号和机台查看历史记录数据 $table_list = \db('设备_产量计酬')->alias('c') ->field('c.订单编号, c.子订单编号, c.款号, c.工序编号, c.工序名称, c.尺码, c.数量, c.sczl_jtbh, c.尾包,c.UniqId,c.ci_num,c.s_num, c.sys_rq, c.serial, y.zdtotal, y.sctotal, j.款式, y.颜色') ->join('工单_印件资料 y', 'c.子订单编号 = y.子订单编号', 'left') ->join('工单_基本资料 j', 'c.订单编号 = j.订单编号', 'left') ->where('c.子订单编号', $param['order_id']) ->where('c.sczl_jtbh', $param['sczl_jtbh']) ->whereNull('c.mod_rq') // 查询未删除数据 ->where(function($query) { $query->whereNotNull('y.ck_rq')->where('y.ck_rq', '<>', ''); }) // 查询出库数据 ->order('c.UniqId', 'desc') ->distinct('c.子订单编号') ->select(); $output = []; foreach ($table_list as $record) { $output[] = [ 'serial' => $record['serial'], 'sys_rq' => $record['sys_rq'], '订单编号' => $record['订单编号'], '子订单编号' => $record['子订单编号'], '颜色' => $record['颜色'], '尺码' => $record['尺码'], '数量' => $record['数量'], '上报数量' => $record['s_num'], '尾包' => $record['尾包'], '组别' => $record['sczl_jtbh'], ]; } $this->success('请求成功', [ 'records' => $output ]); } /** * 记录报工日志历史记录 */ public function getTabByGdbh() { if (Request::instance()->isPost() === false){ $this->error('请求错误'); } $param = Request::instance()->post(); if (empty($param)){ $this->error('参数错误'); } $rows = db()->table('工单_基本资料') ->where('订单编号',$param['订单编号']) ->find(); $param['客户编号'] = $rows['客户编号']; $sql= \db('设备_报工记录')->fetchSql(true)->insert($param); $res = \db()->query($sql); if ($res !== false){ $this->success('成功'); }else{ $this->error('失败'); } } /** * 获取报工日志 * @ApiMethod (GET) */ public function getList() { if(!$this->request->isGet()){ $this->error('请求方式错误'); } $param = $this->request->param(); // 判断订单编号是否包含 '-' if (strpos($param['order'], '-') !== false) { // 如果订单包含 '-',则按子订单编号精确匹配 $where['子订单编号'] = $param['order']; } else { // 如果订单不包含 '-',则按订单编号进行模糊匹配 $where['订单编号'] = ['like', '%' . $param['order'] . '%']; } // 过滤条件中的 code $where['code'] = $param['code']; // 查询数据库 $rows = db()->table('设备_报工记录') ->where($where) ->order('子订单编号 desc') ->select(); // 提取 cm1 到 cm10 的数据 $headers = []; if (!empty($rows)) { foreach ($rows as $row) { for ($i = 1; $i <= 10; $i++) { $cmField = 'cm' . $i; if (isset($row[$cmField]) && $row[$cmField] !== '') { // 仅在字段不为空时添加到 headers $headers[] = $row[$cmField]; } } } // 去重,避免重复值 $headers = array_unique($headers); sort($headers); } $data = [ 'table' => $rows, 'headers' => $headers, 'total' => count($rows), ]; $this->success('成功', $data); } /** * 生产产量进度月报表(Excel) */ public function getOneWorkOrder() { if (!$this->request->isGet()) { $this->error('请求方式错误'); } $param = $this->request->param(); $currentMonth = date('Y-m', strtotime($param['riqi'])); // 获取前端传来的日期所在月份,格式为 Y-m $lastMonth = date('Y-m', strtotime($param['riqi'] . ' -1 month')); // 获取前端日期的上个月,格式为 Y-m // 当前月份的查询条件 $where['c.sczl_rq'] = ['like', '%' . $currentMonth . '%']; // 查询当前订单的生产总数和整单总数 $totals = db()->table('工单_印件资料')->alias('y') ->field('y.订单编号, SUM(y.sctotal) as sctotal, SUM(y.zdtotal) as zdtotal') ->group('y.订单编号') ->order('y.订单编号') ->select(); // 保存当前订单的生产总数和整单总数到一个数组,以便后续关联 $totalsMap = []; foreach ($totals as $total) { $totalsMap[$total['订单编号']] = [ 'sctotal' => $total['sctotal'], 'zdtotal' => $total['zdtotal'], ]; } // 查询上月累计数据 $wheres['sczl_rq'] = ['like', '%' . $lastMonth . '%']; $sql = db()->table('设备_产量计酬') ->field('订单编号, SUM(数量) as 上月累计') // 使用SUM函数统计上月累计数量 ->where($wheres) ->group('订单编号') ->select(); // 将上个月的累计数据保存到一个数组 $lastMonthMap = []; foreach ($sql as $lastRow) { $lastMonthMap[$lastRow['订单编号']] = $lastRow['上月累计']; } // 查询每天的上报数量,并关联生产总数和整单总数 $rows = db()->table('设备_产量计酬')->alias('c') ->join('工单_基本资料 j', 'c.订单编号 = j.订单编号', 'left') ->field(' c.订单编号, j.款式, j.生产款号, j.客户编号, c.sczl_jtbh, c.工序名称 as 工序,c.sczl_bh, c.数量 as 上报数量, c.sczl_rq as 上报时间 ') ->where($where) ->order('c.sczl_rq desc') ->select(); // 初始化 $result = []; // 处理当前月份的数据 foreach ($rows as $row) { $key = $row['款式'] . '_' . $row['生产款号'] . '_' . $row['订单编号'] . '_' . $row['sczl_jtbh']; // 获取当前订单编号的生产总数和整单总数 $sctotal = isset($totalsMap[$row['订单编号']]) ? $totalsMap[$row['订单编号']]['sctotal'] : 0; $zdtotal = isset($totalsMap[$row['订单编号']]) ? $totalsMap[$row['订单编号']]['zdtotal'] : 0; // 获取上个月的累计数量 $lastMonthTotal = isset($lastMonthMap[$row['订单编号']]) ? $lastMonthMap[$row['订单编号']] : 0; // 初始化当前订单编号和组别的数据 if (!isset($result[$key])) { $result[$key] = [ '订单编号' => $row['订单编号'], '客户编号' => $row['客户编号'], '机台号' => $row['sczl_jtbh'], '款式' => $row['款式'], '款号' => $row['生产款号'], '工序' => $row['工序'], '组别' => $row['sczl_bh'], '制单数' => $zdtotal, '裁剪数' => $sctotal, '上个月累计数量' => $lastMonthTotal, // 上个月累计数量 '上报数量' => 0, ]; // 初始化每一天的数据 for ($day = 1; $day <= 31; $day++) { $result[$key][$day] = 0; } } // 获取上报的具体日期 $day = (int)date('d', strtotime($row['上报时间'])); // 按天累加上报数量 $result[$key][$day] += (int)$row['上报数量']; // 累计上报数量 $result[$key]['上报数量'] += (int)$row['上报数量']; } // 计算本月累计数据 foreach ($result as &$item) { $item['本月累计'] = 0; // 累计本月每天的数据 for ($day = 1; $day <= 31; $day++) { $item['本月累计'] += $item[$day]; if ($item[$day] === 0) { $item[$day] = ''; } } } //排序 usort($result, function ($a, $b) { $clientComparison = strcmp($a['客户编号'], $b['客户编号']); if ($clientComparison !== 0) { return $clientComparison; } $groupComparison = strcmp($a['组别'], $b['组别']); if ($groupComparison !== 0) { return $groupComparison; } return strcmp($a['订单编号'], $b['订单编号']); }); $result = array_values($result); $this->success('成功', $result); } /** * */ public function getInfo() { } /** * */ public function getOrderInfo(){ } /** * */ public function getYjInfo(){ } /** * */ public function getWastInfo(){ } /** * */ public function getGxAndLeader(){ } /** * */ public function edit(){ } /** * */ public function add(){ } /** * */ public function wasteDistribution(){ } /** * */ public function getOrderDate(){ } /** * */ public function editOrderFinishDate(){ } /** * */ public function getOrderProcessLeft(){ } /** * */ public function getOrderProcessRight(){ } /** * */ public function getDaysWast() { } /** * */ public function getMonthPeopleTotal(){ } /** * */ public function getOrderWasteTotal(){ } /** * */ public function del() { } }