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.工序名称', '手工') // ->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 // ]); // } /** * 生产产量进度月报表(Excel) */ public function getOneWorkOrder() { if (!$this->request->isGet()) { $this->error('请求方式错误'); } $param = $this->request->param(); // 查询当前订单的生产总数和整单总数 $totals = db()->table('工单_印件资料')->alias('y') ->field('y.订单编号, SUM(y.sctotal) as sctotal, SUM(y.zdtotal) as zdtotal') ->group('y.订单编号') ->whereNull('y.Mod_rq') ->order('y.订单编号') ->select(); // 保存当前订单的生产总数和整单总数到一个数组,以便后续关联 $totalsMap = []; foreach ($totals as $total) { $totalsMap[$total['订单编号']] = [ 'sctotal' => $total['sctotal'], 'zdtotal' => $total['zdtotal'], ]; } // 获取上个月的日期,格式为 Y-m $lastMonth = date('Y-m', strtotime($param['riqi'] . ' -1 month')); // 构造查询条件 $wheres['sczl_rq'] = ['like', '%' . $lastMonth . '%']; // 查询上个月的数据 $wheres['sczl_bh'] = ['neq', '']; // 根据需要加上你想要的工序条件(假设 sczl_bh 是工序字段) $sql = db()->table('设备_产量计酬') ->field('订单编号, sczl_jtbh, sczl_bh, CASE WHEN 工序名称 IN ("裁剪", "车缝") THEN SUM(数量) ELSE SUM(s_num) END as 上月累计') // 加上工序字段 ->where($wheres) ->whereNull('mod_rq') // 确保 mod_rq 字段为空 ->group('订单编号, sczl_jtbh, sczl_bh') // 按 订单编号, sczl_jtbh, sczl_bh 分组 ->select(); // 将上个月的累计数据保存到一个数组,确保按订单编号和机台号保存 $lastMonthMap = []; foreach ($sql as $lastRow) { $lastMonthMap[$lastRow['订单编号']][$lastRow['sczl_jtbh']] = (int)$lastRow['上月累计']; } $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 . '%']; // 查询每天的上报数量,并关联生产总数和整单总数 $rows = db()->table('设备_产量计酬')->alias('c') ->join('工单_基本资料 j', 'c.订单编号 = j.订单编号', 'left') ->field(' c.订单编号, j.款式, j.生产款号, j.客户编号, c.sczl_jtbh, c.工序名称 as 工序, c.sczl_bh, CASE WHEN c.工序名称 IN ("裁剪", "车缝") THEN c.数量 ELSE c.s_num END as 上报数量, c.sczl_rq as 上报时间 ') ->where($where) ->whereNull('c.mod_rq') ->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['订单编号']][$row['sczl_jtbh']]) ? $lastMonthMap[$row['订单编号']][$row['sczl_jtbh']] : 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() { } }