|
|
@@ -427,37 +427,173 @@ class Decision extends Api
|
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
|
* @throws \think\exception\DbException
|
|
|
*/
|
|
|
+// public function ProcessOutputRate()
|
|
|
+// {
|
|
|
+// if ($this->request->isGet() === false){
|
|
|
+// $this->error('请求错误');
|
|
|
+// }
|
|
|
+// $param = $this->request->param();
|
|
|
+// if (empty($param)){
|
|
|
+// $this->error('参数错误');
|
|
|
+// }
|
|
|
+// //查询已经进入超节损的月份
|
|
|
+// $mouth = \db('工单_质量考核汇总')
|
|
|
+// ->where('sys_ny','like',$param['year'].'%')
|
|
|
+// ->column('distinct(sys_ny) as mouth');
|
|
|
+// //创建工序数组
|
|
|
+// $processType = ['胶印','卷凹','圆烫','圆切','烫金','模切','丝印','喷码','单凹'];
|
|
|
+// $result = $data = [];
|
|
|
+// foreach ($mouth as $key=>$value){
|
|
|
+// foreach ($processType as $item){
|
|
|
+// //查询进入超节损一年内所有数据
|
|
|
+// $list = \db('工单_质量考核汇总')
|
|
|
+// ->alias('a')
|
|
|
+// ->join('工单_工艺资料 b','a.Gy0_gdbh = b.Gy0_gdbh AND a.印件及工序 = b.Gy0_yjno AND a.工序 = b.Gy0_gxh')
|
|
|
+// ->join('工单_印件资料 c','a.Gy0_gdbh = c.Yj_Gdbh AND a.印件及工序 = c.yj_Yjno')
|
|
|
+// ->field('a.sys_ny,((sum(a.班组制程废品)/a.联数)+(sum(a.班组质检废品)/a.联数))/a.印件工序产量 as 废品率')
|
|
|
+// ->where('b.Gy0_gxmc','like',$item.'%')
|
|
|
+// ->where('a.sys_ny',$value)
|
|
|
+// ->group('a.Gy0_gdbh,b.Gy0_yjno,a.工序')
|
|
|
+// ->select();
|
|
|
+// $data[$value][$item] = $list;
|
|
|
+// }
|
|
|
+// }
|
|
|
+// $months = [
|
|
|
+// $param['year'].'01' => '01月',
|
|
|
+// $param['year'].'02' => '02月',
|
|
|
+// $param['year'].'03' => '03月',
|
|
|
+// $param['year'].'04' => '04月',
|
|
|
+// $param['year'].'05' => '05月',
|
|
|
+// $param['year'].'06' => '06月',
|
|
|
+// $param['year'].'07' => '07月',
|
|
|
+// $param['year'].'08' => '08月',
|
|
|
+// $param['year'].'09' => '09月',
|
|
|
+// $param['year'].'10' => '10月',
|
|
|
+// $param['year'].'11' => '11月',
|
|
|
+// $param['year'].'12' => '12月'
|
|
|
+// ];
|
|
|
+// //汇总数据
|
|
|
+// foreach ($processType as $index => $process) {
|
|
|
+// $result[$index] = array(
|
|
|
+// "工序类型" => $process,
|
|
|
+// "01月" => "",
|
|
|
+// "02月" => "",
|
|
|
+// "03月" => "",
|
|
|
+// "04月" => "",
|
|
|
+// "05月" => "",
|
|
|
+// "06月" => "",
|
|
|
+// "07月" => "",
|
|
|
+// "08月" => "",
|
|
|
+// "09月" => "",
|
|
|
+// "10月" => "",
|
|
|
+// "11月" => "",
|
|
|
+// "12月" => ""
|
|
|
+// );
|
|
|
+//
|
|
|
+// // 遍历月份
|
|
|
+// foreach ($months as $month => $monthName) {
|
|
|
+// if (isset($data[$month])){
|
|
|
+// $count = count($data[$month][$process]);
|
|
|
+// }
|
|
|
+//
|
|
|
+// $totalRate = 0;
|
|
|
+//
|
|
|
+// // 检查月份是否存在于数据中
|
|
|
+// if (isset($data[$month])) {
|
|
|
+// // 检查工序是否存在于月份数据中
|
|
|
+// if (isset($data[$month][$process])) {
|
|
|
+// // 累加废品率
|
|
|
+// foreach ($data[$month][$process] as $rate) {
|
|
|
+// $totalRate += floatval(1-$rate["废品率"]);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// if ($count > 0){
|
|
|
+// $rateNumber = $totalRate/$count;
|
|
|
+// }
|
|
|
+// // 格式化为百分比字符串,保留两位小数
|
|
|
+// if ($totalRate > 0) {
|
|
|
+// $result[$index][$monthName] = sprintf("%.2f%%", $rateNumber * 100);
|
|
|
+// } else {
|
|
|
+// $result[$index][$monthName] = ""; // 如果没有数据,则为空字符串
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// foreach ($result as &$item) {
|
|
|
+// $total = 0;
|
|
|
+// $count = 0;
|
|
|
+//
|
|
|
+// // 遍历月份,计算总和和数量
|
|
|
+// for ($i = 1; $i <= 12; $i++) {
|
|
|
+// $month = sprintf("%02d月", $i); // 格式化月份,例如 "01月"
|
|
|
+// if (isset($item[$month]) && $item[$month] !== "") {
|
|
|
+// // 移除百分号,并将字符串转换为浮点数
|
|
|
+// $value = floatval(str_replace("%", "", $item[$month]));
|
|
|
+// $total += $value;
|
|
|
+// $count++;
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 计算平均值
|
|
|
+// if ($count > 0) {
|
|
|
+// $average = $total / $count;
|
|
|
+// // 格式化为百分比字符串,保留两位小数
|
|
|
+// $item["平均值"] = sprintf("%.2f%%", $average);
|
|
|
+// } else {
|
|
|
+// $item["平均值"] = "0.00%"; // 如果没有数据,则为 0.00%
|
|
|
+// }
|
|
|
+// }
|
|
|
+// $this->success('成功',$result);
|
|
|
+// }
|
|
|
public function ProcessOutputRate()
|
|
|
{
|
|
|
- if ($this->request->isGet() === false){
|
|
|
+ if (!$this->request->isGet()) {
|
|
|
$this->error('请求错误');
|
|
|
}
|
|
|
+
|
|
|
$param = $this->request->param();
|
|
|
- if (empty($param)){
|
|
|
+ if (empty($param)) {
|
|
|
$this->error('参数错误');
|
|
|
}
|
|
|
- //查询已经进入超节损的月份
|
|
|
+
|
|
|
+ // 新版工序结构
|
|
|
+ $processOrder = [
|
|
|
+ 1 => ['name' => '胶印工序', 'keys' => ['胶印', '上光']],
|
|
|
+ 2 => ['name' => '凹印工序', 'keys' => ['卷凹']],
|
|
|
+ 3 => ['name' => '圆烫工序', 'keys' => ['圆烫']],
|
|
|
+ 4 => ['name' => '圆切工序', 'keys' => ['圆切']],
|
|
|
+ 5 => ['name' => '烫模工序', 'keys' => ['烫金', '模切', '凹凸']],
|
|
|
+ 6 => ['name' => '丝印工序', 'keys' => ['丝印']],
|
|
|
+ 7 => ['name' => '喷码工序', 'keys' => ['喷码']],
|
|
|
+ 8 => ['name' => '单凹工序', 'keys' => ['单凹']]
|
|
|
+ ];
|
|
|
+
|
|
|
+ // 获取存在数据的月份
|
|
|
$mouth = \db('工单_质量考核汇总')
|
|
|
- ->where('sys_ny','like',$param['year'].'%')
|
|
|
+ ->where('sys_ny', 'like', $param['year'].'%')
|
|
|
->column('distinct(sys_ny) as mouth');
|
|
|
- //创建工序数组
|
|
|
- $processType = ['胶印','卷凹','圆烫','圆切','烫金','模切','丝印','喷码','单凹'];
|
|
|
- $result = $data = [];
|
|
|
- foreach ($mouth as $key=>$value){
|
|
|
- foreach ($processType as $item){
|
|
|
- //查询进入超节损一年内所有数据
|
|
|
- $list = \db('工单_质量考核汇总')
|
|
|
+
|
|
|
+ $data = [];
|
|
|
+ foreach ($mouth as $month) {
|
|
|
+ foreach ($processOrder as $processId => $process) {
|
|
|
+ $query = \db('工单_质量考核汇总')
|
|
|
->alias('a')
|
|
|
- ->join('工单_工艺资料 b','a.Gy0_gdbh = b.Gy0_gdbh AND a.印件及工序 = b.Gy0_yjno AND a.工序 = b.Gy0_gxh')
|
|
|
- ->join('工单_印件资料 c','a.Gy0_gdbh = c.Yj_Gdbh AND a.印件及工序 = c.yj_Yjno')
|
|
|
- ->field('a.sys_ny,((sum(a.班组制程废品)/a.联数)+(sum(a.班组质检废品)/a.联数))/a.印件工序产量 as 废品率')
|
|
|
- ->where('b.Gy0_gxmc','like',$item.'%')
|
|
|
- ->where('a.sys_ny',$value)
|
|
|
- ->group('a.Gy0_gdbh,b.Gy0_yjno,a.工序')
|
|
|
- ->select();
|
|
|
- $data[$value][$item] = $list;
|
|
|
+ ->join('工单_工艺资料 b', 'a.Gy0_gdbh = b.Gy0_gdbh AND a.印件及工序 = b.Gy0_yjno AND a.工序 = b.Gy0_gxh')
|
|
|
+ ->join('工单_印件资料 c', 'a.Gy0_gdbh = c.Yj_Gdbh AND a.印件及工序 = c.yj_Yjno')
|
|
|
+ ->field('a.sys_ny, ((SUM(a.班组制程废品)/a.联数) + (SUM(a.班组质检废品)/a.联数)) / a.印件工序产量 as 废品率')
|
|
|
+ ->where(function($query) use ($process) {
|
|
|
+ foreach ($process['keys'] as $key) {
|
|
|
+ $query->whereOr('b.Gy0_gxmc', 'like', "%{$key}%");
|
|
|
+ }
|
|
|
+ })
|
|
|
+ ->where('a.sys_ny', $month)
|
|
|
+ ->group('a.Gy0_gdbh, b.Gy0_yjno, a.工序');
|
|
|
+
|
|
|
+ $data[$month][$processId] = $query->select();
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ // 构建月份模板
|
|
|
$months = [
|
|
|
$param['year'].'01' => '01月',
|
|
|
$param['year'].'02' => '02月',
|
|
|
@@ -472,13 +608,14 @@ class Decision extends Api
|
|
|
$param['year'].'11' => '11月',
|
|
|
$param['year'].'12' => '12月'
|
|
|
];
|
|
|
- //汇总数据
|
|
|
- foreach ($processType as $index => $process) {
|
|
|
- $result[$index] = array(
|
|
|
- "工序类型" => $process,
|
|
|
+
|
|
|
+ $result = [];
|
|
|
+ foreach ($processOrder as $processId => $process) {
|
|
|
+ $processData = [
|
|
|
+ "工序类型" => $process['name'],
|
|
|
"01月" => "",
|
|
|
"02月" => "",
|
|
|
- "03月" => "",
|
|
|
+ "03月" =>"",
|
|
|
"04月" => "",
|
|
|
"05月" => "",
|
|
|
"06月" => "",
|
|
|
@@ -487,64 +624,46 @@ class Decision extends Api
|
|
|
"09月" => "",
|
|
|
"10月" => "",
|
|
|
"11月" => "",
|
|
|
- "12月" => ""
|
|
|
- );
|
|
|
-
|
|
|
- // 遍历月份
|
|
|
- foreach ($months as $month => $monthName) {
|
|
|
- if (isset($data[$month])){
|
|
|
- $count = count($data[$month][$process]);
|
|
|
- }
|
|
|
+ "12月" => "",
|
|
|
+ "平均值" => "0.00%"
|
|
|
+ ];
|
|
|
|
|
|
- $totalRate = 0;
|
|
|
+ $totalAnnual = 0;
|
|
|
+ $monthCount = 0;
|
|
|
|
|
|
- // 检查月份是否存在于数据中
|
|
|
- if (isset($data[$month])) {
|
|
|
- // 检查工序是否存在于月份数据中
|
|
|
- if (isset($data[$month][$process])) {
|
|
|
- // 累加废品率
|
|
|
- foreach ($data[$month][$process] as $rate) {
|
|
|
- $totalRate += floatval(1-$rate["废品率"]);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- if ($count > 0){
|
|
|
- $rateNumber = $totalRate/$count;
|
|
|
- }
|
|
|
- // 格式化为百分比字符串,保留两位小数
|
|
|
- if ($totalRate > 0) {
|
|
|
- $result[$index][$monthName] = sprintf("%.2f%%", $rateNumber * 100);
|
|
|
- } else {
|
|
|
- $result[$index][$monthName] = ""; // 如果没有数据,则为空字符串
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- foreach ($result as &$item) {
|
|
|
- $total = 0;
|
|
|
+ foreach ($months as $sysMonth => $monthName) {
|
|
|
$count = 0;
|
|
|
+ $totalRate = 0;
|
|
|
|
|
|
- // 遍历月份,计算总和和数量
|
|
|
- for ($i = 1; $i <= 12; $i++) {
|
|
|
- $month = sprintf("%02d月", $i); // 格式化月份,例如 "01月"
|
|
|
- if (isset($item[$month]) && $item[$month] !== "") {
|
|
|
- // 移除百分号,并将字符串转换为浮点数
|
|
|
- $value = floatval(str_replace("%", "", $item[$month]));
|
|
|
- $total += $value;
|
|
|
- $count++;
|
|
|
+ if (isset($data[$sysMonth][$processId])) {
|
|
|
+ $records = $data[$sysMonth][$processId];
|
|
|
+ $count = count($records);
|
|
|
+
|
|
|
+ foreach ($records as $record) {
|
|
|
+ $totalRate += floatval(1 - $record['废品率']);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 计算平均值
|
|
|
if ($count > 0) {
|
|
|
- $average = $total / $count;
|
|
|
- // 格式化为百分比字符串,保留两位小数
|
|
|
- $item["平均值"] = sprintf("%.2f%%", $average);
|
|
|
+ $rateValue = ($totalRate / $count) * 100;
|
|
|
+ $processData[$monthName] = sprintf("%.2f%%", $rateValue);
|
|
|
+ $totalAnnual += $rateValue;
|
|
|
+ $monthCount++;
|
|
|
} else {
|
|
|
- $item["平均值"] = "0.00%"; // 如果没有数据,则为 0.00%
|
|
|
+ $processData[$monthName] = "";
|
|
|
}
|
|
|
}
|
|
|
- $this->success('成功',$result);
|
|
|
+
|
|
|
+ // 计算年度平均值
|
|
|
+ if ($monthCount > 0) {
|
|
|
+ $processData['平均值'] = sprintf("%.2f%%", $totalAnnual / $monthCount);
|
|
|
+ }
|
|
|
+
|
|
|
+ $result[] = $processData;
|
|
|
}
|
|
|
+
|
|
|
+ $this->success('成功', $result);
|
|
|
+}
|
|
|
/**
|
|
|
* 获取年分数据
|
|
|
* @return void
|