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() { // 检查是否为 GET 请求 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); } /** * 获取工单核验单信息 * @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); } /** * 生产产量进度月报表(Excel) * @params string UniqId */ public function getOneWorkOrder() { // 确认请求为 GET 请求 if (!$this->request->isGet()) { $this->error('请求方式错误'); } // 获取请求参数 $param = $this->request->param(); // 获取当前月份和上个月的月份 $currentMonth = date('Y-m', strtotime($param['riqi'])); // 当前月份 $previousMonth = date('Y-m', strtotime('-1 month', strtotime($param['riqi']))); // 上个月 // 查询当前月份的数据 $where['上报时间'] = ['like', $currentMonth . '%']; $rows = db()->table('设备_报工记录') ->field('款式,款号,订单编号,组别,客户编号,code as 工序,上报数量,sctotal as 裁剪数,zdtotal as 制单数,scsl1,scsl2,scsl3,scsl4,scsl5,scsl6,scsl7,scsl8,scsl9,scsl10,上报时间') ->where($where) ->select(); // 查询上个月的数据 $wherePrevious['上报时间'] = ['like', $previousMonth . '%']; $rowsPrevious = db()->table('设备_报工记录') ->field('款式,款号,订单编号,组别,客户编号,sctotal as 裁剪数,zdtotal as 制单数,scsl1,scsl2,scsl3,scsl4,scsl5,scsl6,scsl7,scsl8,scsl9,scsl10,上报时间') ->where($wherePrevious) ->select(); // 初始化结果数组 $result = []; // 处理当前月份的数据 foreach ($rows as $row) { // 使用“款式”、“款号”、“订单编号”、“组别”作为唯一标识 $key = $row['款式'] . '_' . $row['款号'] . '_' . $row['订单编号'] . '_' . $row['组别']; // 如果结果集中不存在该条目,则初始化 if (!isset($result[$key])) { $result[$key] = [ '款式' => $row['款式'], '款号' => $row['款号'], '订单编号' => $row['订单编号'], '组别' => $row['组别'], '客户编号' => $row['客户编号'], '工序' => $row['工序'], '裁剪数' => $row['裁剪数'] ?? 0, '制单数' => $row['制单数'] ?? 0, '上报数量' => 0, // 初始化上报数量累计 ]; // 初始化每日数据 for ($day = 1; $day <= 31; $day++) { $result[$key][$day . '号'] = 0; } } // 按天累计每日数据 $day = (int)date('d', strtotime($row['上报时间'])); // 检查 scsl1 到 scsl10 是否都是空 $allScslEmpty = true; for ($i = 1; $i <= 10; $i++) { $keyScsl = 'scsl' . $i; if (!empty($row[$keyScsl])) { $allScslEmpty = false; break; } } // 如果 scsl1-scsl10 全部为空,则累加上报数量 if ($allScslEmpty) { $result[$key][$day . '号'] += (int)$row['上报数量']; } else { // 如果有 scsl1-scsl10 的数据,则按原来的逻辑累加 for ($i = 1; $i <= 10; $i++) { $keyScsl = 'scsl' . $i; $result[$key][$day . '号'] += !empty($row[$keyScsl]) ? (int)$row[$keyScsl] : 0; } } // 累计“上报数量”(非裁剪和制单) $result[$key]['上报数量'] += (int)$row['上报数量']; } // 计算本月累计数据 foreach ($result as &$item) { $item['本月累计'] = 0; // 初始化本月累计 $item['上个月累计'] = 0; // 初始化上个月累计 // 累计本月每天的数据 for ($day = 1; $day <= 31; $day++) { $item['本月累计'] += $item[$day . '号']; // 如果当天数据为 0,则显示为空字符串 if ($item[$day . '号'] === 0) { $item[$day . '号'] = ''; } } // 注意:上个月的每日统计数据不需要处理,仅保留本月的累计。 } // 将结果转换为索引数组 $result = array_values($result); // 返回结果 $this->success('成功', $result); } // public function getOneWorkOrder() { // // 确认请求为 GET 请求 // if (!$this->request->isGet()) { // $this->error('请求方式错误'); // } // // // 获取请求参数 // $param = $this->request->param(); // // // 获取当前月份和上个月的月份 // $currentMonth = date('Y-m', strtotime($param['riqi'])); // 当前月份 // $previousMonth = date('Y-m', strtotime('-1 month', strtotime($param['riqi']))); // 上个月 // // // 查询当前月份的数据 // $where['上报时间'] = ['like', $currentMonth . '%']; // $rows = db()->table('设备_报工记录') // ->field('款式,款号,订单编号,组别,客户编号,code as 工序,上报数量,sctotal as 裁剪数,zdtotal as 制单数,scsl1,scsl2,scsl3,scsl4,scsl5,scsl6,scsl7,scsl8,scsl9,scsl10,上报时间') // ->where($where) // ->select(); // // // 查询上个月的数据 // $wherePrevious['上报时间'] = ['like', $previousMonth . '%']; // $rowsPrevious = db()->table('设备_报工记录') // ->field('款式,款号,订单编号,组别,客户编号,sctotal as 裁剪数,zdtotal as 制单数,scsl1,scsl2,scsl3,scsl4,scsl5,scsl6,scsl7,scsl8,scsl9,scsl10,上报时间') // ->where($wherePrevious) // ->select(); // // // 初始化结果数组 // $result = []; // // // 处理当前月份的数据 // foreach ($rows as $row) { // // 使用“款式”、“款号”、“订单编号”、“组别”作为唯一标识 // $key = $row['款式'] . '_' . $row['款号'] . '_' . $row['订单编号'] . '_' . $row['组别']; // // // 如果结果集中已经存在该条目,则进行累加 // if (!isset($result[$key])) { // // 初始化一个新的条目 // $result[$key] = [ // '款式' => $row['款式'], // '款号' => $row['款号'], // '订单编号' => $row['订单编号'], // '组别' => $row['组别'], // '客户编号' => $row['客户编号'], // '工序' => $row['工序'], // '裁剪数' => $row['裁剪数'] ?? 0, // '制单数' => $row['制单数'] ?? 0, // ]; // // // 初始化每日数据 // for ($day = 1; $day <= 31; $day++) { // $result[$key][$day . '号'] = 0; // } // } // // // 按天累计数据 // $day = (int)date('d', strtotime($row['上报时间'])); // for ($i = 1; $i <= 10; $i++) { // $keyScsl = 'scsl' . $i; // $result[$key][$day . '号'] += !empty($row[$keyScsl]) ? (int)$row[$keyScsl] : 0; // } // } // // // // // 计算本月和上个月的累计 // foreach ($result as &$item) { // $item['本月累计'] = 0; // $item['上个月累计'] = 0; // // // 本月累计 // for ($day = 1; $day <= 31; $day++) { // $item['本月累计'] += $item[$day . '号']; // // 如果当日数据为0,则替换为空字符串 // if ($item[$day . '号'] === 0) { // $item[$day . '号'] = ''; // } // } // // // 上个月累计 (不需要再统计上个月的数据,只保留本月的每日统计) // } // // // 将结果转换为索引数组 // $result = array_values($result); // // $this->success('成功', $result); // } /** * 获取工单基本信息 * @ApiMethod GET * @params string order */ public function getOrderInfo(){ } /** * 获取印件名称及工序 * @ApiMethod GET * @params string order * @params string yj_no */ public function getYjInfo(){ } /** * 获取废品分类 * @ApiMethod GET * @params string search */ public function getWastInfo(){ } /** *获取工序及责任组长 * @ApiMethod GET * @params string type * @params string order */ public function getGxAndLeader(){ } /** * 修改工单核检单 * @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){ cache('WorkOrderVerification-getTable',null); $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){ cache('WorkOrderVerification-getTable',null); $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('参数错误'); } if (!isset($params['yjno']) || empty($params['yjno'])){ $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,qczl_yjno '; // $data = db('db_qczl')->name('db_qczl')->where('qczl_gdbh',$params['order'])->field($field)->select(); $data = db('db_qczl')->name('db_qczl') ->where('qczl_gdbh',$params['order']) ->where('qczl_yjno', $params['yjno']) ->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('参数错误'); } if (!isset($params['yjno']) || empty($params['yjno'])){ $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']; $option['Gy0_yjno'] = $params['yjno']; $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['yjno']) || empty($params['yjno'])){ $this->error('参数错误'); } if (!isset($params['gxNo']) || empty($params['gxNo'])){ $this->error('参数错误'); } $total = db('设备_产量计酬')->where('sczl_gdbh',$params['order'])->where('sczl_gdbh',$params['yjno'])->order('sczl_num')->column('distinct(sczl_num)'); $where['sczl_gxh'] = (int)$params['gxNo']; $where['sczl_gdbh'] = $params['order']; $where['sczl_yjno'] = $params['yjno']; //机器设备数据 $process = db('设备_产量计酬')->where($where)->order('sczl_num')->column('distinct(sczl_num)'); //手工数据 $option['qczl_gdbh'] = $params['order']; $option['qczl_gxh'] = (int)$params['gxNo']; $option['qczl_yjno'] = $params['yjno']; $handProcess = db('db_qczl')->where($option)->field('qczl_num,qczl_NumDesc1,qczl_NumDesc2,qczl_NumDesc3,qczl_NumDesc4,qczl_NumDesc5,qczl_NumDesc6,qczl_NumDesc7,qczl_NumDesc8')->select(); // 提取数据 $result = array(); foreach ($handProcess as $subArray) { $qczl_num = $subArray["qczl_num"]; $result[] = $qczl_num; // 提取以qczl_NumDesc开头的键对应的值 for ($i = 1; $i <= 8; $i++) { $key = "qczl_NumDesc" . $i; if ($subArray[$key] != 0){ $result[] = $subArray[$key]; } } } // 去重 $result = array_unique($result); // 对结果进行排序 sort($result); $res['total_process'] = $total; $res['process'] = $process; if (empty($process)){ $res['process'] = $result; } $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['a.qczl_yjno'] = $params['yjno']; $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) // ->where('a.qczl_yjno','1') ->group('qczl_yjno,qczl_num') ->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); } /** * 工单核检单删除 * @return void * @throws \think\Exception * @throws \think\exception\PDOException */ public function del() { if ($this->request->isGet() === false){ $this->error('请求错误'); } $param = $this->request->param(); if (empty($param['UniqId'])){ $this->error('参数错误'); } $res = \db('db_qczl') ->where('UniqId',$param['UniqId']) ->delete(); if ($res !== false){ $this->success('删除成功'); }else{ $this->error('产出失败'); } } }