|
|
@@ -636,4 +636,378 @@ class Achievementatestatistics extends Api
|
|
|
$this->success('明细获取成功', $records);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 01.产品年度投入产出率统计->左侧菜单
|
|
|
+ */
|
|
|
+// public function left_Productyear() {
|
|
|
+// $list = \db('产品_基本资料')
|
|
|
+// ->field('客户编号,客户名称,Mod_rq')
|
|
|
+// ->group('客户编号,客户名称,Mod_rq')
|
|
|
+// ->where('客户编号','<>','')
|
|
|
+// ->order('客户编号')
|
|
|
+// ->select();
|
|
|
+//
|
|
|
+//
|
|
|
+// $data['翌星工单'] = [];
|
|
|
+// $data['MN工单'] = [];
|
|
|
+//
|
|
|
+// foreach ($list as $key => $value) {
|
|
|
+// $value['客户编号'] = rtrim($value['客户编号']);
|
|
|
+// $value['客户名称'] = rtrim($value['客户名称']);
|
|
|
+// if (empty($value['客户名称'])) {
|
|
|
+// continue;
|
|
|
+// }
|
|
|
+//
|
|
|
+// $name = $value['客户编号'] . '【' . $value['客户名称'] . '】';
|
|
|
+// $year = date('Y', strtotime($value['Mod_rq']));
|
|
|
+// $uniqueKey = $value['客户编号'] . '_' . $value['客户名称'] . '_' . $year;
|
|
|
+//
|
|
|
+// if (isset($seenEntries[$uniqueKey])) {
|
|
|
+// continue; // 如果已经存在,跳过重复项
|
|
|
+// }
|
|
|
+// $seenEntries[$uniqueKey] = true;
|
|
|
+//
|
|
|
+// if (strpos($value['客户编号'], 'J') !== false || strpos($value['客户编号'], 'Y') !== false) {
|
|
|
+// if (!isset($data['翌星工单'][$year])) {
|
|
|
+// $data['翌星工单'][$year] = [];
|
|
|
+// }
|
|
|
+// array_push($data['翌星工单'][$year], $name);
|
|
|
+// } else {
|
|
|
+// if (!isset($data['MN工单'][$year])) {
|
|
|
+// $data['MN工单'][$year] = [];
|
|
|
+// }
|
|
|
+// array_push($data['MN工单'][$year], $name);
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 按年份排序(从最新到最旧)
|
|
|
+// krsort($data['翌星工单']);
|
|
|
+// krsort($data['MN工单']);
|
|
|
+//
|
|
|
+// // 对每个年份内的数据进行排序(可选)
|
|
|
+// foreach ($data['翌星工单'] as $year => &$items) {
|
|
|
+// sort($items);
|
|
|
+// }
|
|
|
+// foreach ($data['MN工单'] as $year => &$items) {
|
|
|
+// sort($items);
|
|
|
+// }
|
|
|
+// $this->success('成功', $data);
|
|
|
+// }
|
|
|
+ public function left_Productyear() {
|
|
|
+ $list = \db('产品_基本资料')
|
|
|
+ ->field('客户编号,客户名称')
|
|
|
+ ->group('客户编号,客户名称')
|
|
|
+ ->where('客户编号','<>','')
|
|
|
+ ->order('客户编号')
|
|
|
+ ->select();
|
|
|
+
|
|
|
+ $data['翌星工单'] = [];
|
|
|
+ $data['MN工单'] = [];
|
|
|
+ $seenEntries = []; // 添加这个变量来跟踪已处理的条目
|
|
|
+
|
|
|
+ foreach ($list as $key => $value) {
|
|
|
+ $value['客户编号'] = rtrim($value['客户编号']);
|
|
|
+ $value['客户名称'] = rtrim($value['客户名称']);
|
|
|
+ if (empty($value['客户名称'])) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取工单信息,包含Sys_rq字段
|
|
|
+ $productIng = \db('工单_基本资料')
|
|
|
+ ->field('Sys_rq')
|
|
|
+ ->where('Gd_cpdh|成品代号', 'LIKE', rtrim($value['客户编号']) . '%')
|
|
|
+ ->order('Sys_rq DESC')
|
|
|
+ ->find();
|
|
|
+
|
|
|
+ // 如果没有找到相关工单,跳过
|
|
|
+ if (!$productIng || empty($productIng['Sys_rq'])) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ $name = $value['客户编号'] . '【' . $value['客户名称'] . '】';
|
|
|
+ $year = date('Y', strtotime($productIng['Sys_rq']));
|
|
|
+ $uniqueKey = $value['客户编号'] . '_' . $value['客户名称'] . '_' . $year;
|
|
|
+
|
|
|
+ if (isset($seenEntries[$uniqueKey])) {
|
|
|
+ continue; // 如果已经存在,跳过重复项
|
|
|
+ }
|
|
|
+ $seenEntries[$uniqueKey] = true;
|
|
|
+
|
|
|
+ if (strpos($value['客户编号'], 'J') !== false || strpos($value['客户编号'], 'Y') !== false) {
|
|
|
+ if (!isset($data['翌星工单'][$year])) {
|
|
|
+ $data['翌星工单'][$year] = [];
|
|
|
+ }
|
|
|
+ array_push($data['翌星工单'][$year], $name);
|
|
|
+ } else {
|
|
|
+ if (!isset($data['MN工单'][$year])) {
|
|
|
+ $data['MN工单'][$year] = [];
|
|
|
+ }
|
|
|
+ array_push($data['MN工单'][$year], $name);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 按年份排序(从最新到最旧)
|
|
|
+ krsort($data['翌星工单']);
|
|
|
+ krsort($data['MN工单']);
|
|
|
+
|
|
|
+ // 对每个年份内的数据进行排序(可选)
|
|
|
+ foreach ($data['翌星工单'] as $year => &$items) {
|
|
|
+ sort($items);
|
|
|
+ }
|
|
|
+ foreach ($data['MN工单'] as $year => &$items) {
|
|
|
+ sort($items);
|
|
|
+ }
|
|
|
+
|
|
|
+ $this->success('成功', $data);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 01.产品年度投入产出率统计->数据汇总表
|
|
|
+ */
|
|
|
+ public function list_Productyear() {
|
|
|
+ if ($this->request->isGet() === false) {
|
|
|
+ $this->error('请求错误');
|
|
|
+ }
|
|
|
+ $param = $this->request->param();
|
|
|
+ $rq = $param['rq'];
|
|
|
+
|
|
|
+ $where = [];
|
|
|
+ if (!empty($param['search'])){
|
|
|
+ $where['产品代号|产品名称'] = ['like','%'.$param['search'].'%'];
|
|
|
+ }
|
|
|
+ if (!empty($param['khdh'])){
|
|
|
+ $where['产品代号'] = ['like',$param['khdh'].'%'];
|
|
|
+ }
|
|
|
+
|
|
|
+ $qualityData = \db('工单_质量考核汇总')
|
|
|
+ ->field('Gy0_gdbh, 客户代号, 入仓日期 as sys_rq, 实际投料, 入仓数量, 产品代号, 产品名称, 销售订单号, 订单数量,计量单位')
|
|
|
+ ->where('YEAR(Sys_rq)', $rq)
|
|
|
+ ->where($where)
|
|
|
+ ->select();
|
|
|
+
|
|
|
+ if (empty($qualityData)) {
|
|
|
+ $this->success('未查询到数据', []);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 第一步:按工单去重,每个工单只取一条记录
|
|
|
+ $uniqueByGongdan = [];
|
|
|
+ foreach ($qualityData as $data) {
|
|
|
+ $gdbh = $data['Gy0_gdbh'];
|
|
|
+ if (!isset($uniqueByGongdan[$gdbh])) {
|
|
|
+ $uniqueByGongdan[$gdbh] = $data;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 第二步:按产品代号和月份分组并计算总和
|
|
|
+ $productMap = [];
|
|
|
+ foreach ($uniqueByGongdan as $gdbh => $data) {
|
|
|
+ $productCode = $data['产品代号'];
|
|
|
+ $sysRq = $data['sys_rq'];
|
|
|
+
|
|
|
+ // 提取月份1-12 的月份数字
|
|
|
+ $month = date('n', strtotime($sysRq));
|
|
|
+
|
|
|
+ if (!isset($productMap[$productCode])) {
|
|
|
+ $productMap[$productCode] = [
|
|
|
+ 'sys_rq' => substr($data['sys_rq'], 0, 4),
|
|
|
+ '计量单位' => $data['计量单位'],
|
|
|
+ '成品编码' => $data['产品代号'],
|
|
|
+ '成品名称' => $data['产品名称'],
|
|
|
+ 'months' => [],
|
|
|
+ '实际投料' => 0,
|
|
|
+ '入仓数量' => 0,
|
|
|
+ '工单列表' => [] // 记录包含的工单编号
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!isset($productMap[$productCode]['months'][$month])) {
|
|
|
+ $productMap[$productCode]['months'][$month] = [
|
|
|
+ '实际投料' => 0,
|
|
|
+ '入仓数量' => 0
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ //实际投料先乘以10000再累加
|
|
|
+ $adjustedActual = round($data['实际投料'] * 10000);
|
|
|
+
|
|
|
+ // 累加月度数据
|
|
|
+ $productMap[$productCode]['months'][$month]['实际投料'] += $adjustedActual;
|
|
|
+ $productMap[$productCode]['months'][$month]['入仓数量'] += $data['入仓数量'];
|
|
|
+
|
|
|
+ // 累加年度总量(实际投料已经乘以10000)
|
|
|
+ $productMap[$productCode]['实际投料'] += $adjustedActual;
|
|
|
+ $productMap[$productCode]['入仓数量'] += $data['入仓数量'];
|
|
|
+
|
|
|
+ // 记录工单编号
|
|
|
+ $productMap[$productCode]['工单列表'][] = $data['Gy0_gdbh'];
|
|
|
+ }
|
|
|
+
|
|
|
+ //月份
|
|
|
+ $monthNames = [
|
|
|
+ 1 => '1月', 2 => '2月', 3 => '3月', 4 => '4月',
|
|
|
+ 5 => '5月', 6 => '6月', 7 => '7月', 8 => '8月',
|
|
|
+ 9 => '9月', 10 => '10月', 11 => '11月', 12 => '12月'
|
|
|
+ ];
|
|
|
+
|
|
|
+ //合并数据并计算合格率
|
|
|
+ $result = [];
|
|
|
+ foreach ($productMap as $productCode => $productData) {
|
|
|
+ $resultItem = [
|
|
|
+ 'sys_rq' => $productData['sys_rq'],
|
|
|
+ '成品编码' => $productData['成品编码'],
|
|
|
+ '成品名称' => $productData['成品名称'],
|
|
|
+ '实际投料' => $productData['实际投料'],
|
|
|
+ '入仓数量' => $productData['入仓数量'],
|
|
|
+ '计量单位' => $productData['计量单位'],
|
|
|
+ '工单数量' => count($productData['工单列表']),
|
|
|
+ '工单列表' => implode(', ', $productData['工单列表'])
|
|
|
+ ];
|
|
|
+
|
|
|
+ // 初始化各月份数据
|
|
|
+ foreach ($monthNames as $monthNum => $monthName) {
|
|
|
+ $resultItem[$monthName] = '-';
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理该产品的月度数据
|
|
|
+ if (isset($productData['months'])) {
|
|
|
+ foreach ($productData['months'] as $month => $monthData) {
|
|
|
+ $adjustedActual = $monthData['实际投料'];
|
|
|
+ $delivery = $monthData['入仓数量'];
|
|
|
+
|
|
|
+ // 计算月度合格率
|
|
|
+ if ($adjustedActual > 0) {
|
|
|
+ $monthlyRate = round(($delivery / $adjustedActual) * 100, 2);
|
|
|
+ $resultItem[$monthNames[$month]] = $monthlyRate . '%';
|
|
|
+ } else if ($delivery > 0) {
|
|
|
+ $resultItem[$monthNames[$month]] = '100%';
|
|
|
+ } else {
|
|
|
+ $resultItem[$monthNames[$month]] = '0%';
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 计算年度综合合格率
|
|
|
+ if ($resultItem['实际投料'] > 0) {
|
|
|
+ $overallRate = round(($resultItem['入仓数量'] / $resultItem['实际投料']) * 100, 2);
|
|
|
+ $resultItem['综合合格率'] = $overallRate . '%';
|
|
|
+ } else if ($resultItem['入仓数量'] > 0) {
|
|
|
+ $resultItem['综合合格率'] = '100%';
|
|
|
+ } else {
|
|
|
+ $resultItem['综合合格率'] = '0%';
|
|
|
+ }
|
|
|
+
|
|
|
+ $result[] = $resultItem;
|
|
|
+ }
|
|
|
+
|
|
|
+ $this->success('成功', $result);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 01.产品年度投入产出率统计->数据明细表
|
|
|
+ */
|
|
|
+ public function list_Productmonth() {
|
|
|
+ if ($this->request->isGet() === false) {
|
|
|
+ $this->error('请求错误');
|
|
|
+ }
|
|
|
+
|
|
|
+ $param = $this->request->param();
|
|
|
+ $productCode = $param['product_code'] ?? '';
|
|
|
+ $year = $param['year'] ?? date('Y');
|
|
|
+
|
|
|
+ if (empty($productCode)) {
|
|
|
+ $this->error('请提供成品编码');
|
|
|
+ }
|
|
|
+
|
|
|
+ // 1. 查询对应的工单数据
|
|
|
+ $qualityData = \db('工单_质量考核汇总')
|
|
|
+ ->field('Gy0_gdbh as 工单编号, 订单数量, 入仓日期, 实际投料, 入仓数量, 客户代号, 客户名称, 产品代号, 产品名称, 销售订单号')
|
|
|
+ ->where('产品代号', $productCode)
|
|
|
+ ->where('YEAR(入仓日期)', $year)
|
|
|
+ ->order('入仓日期','desc')
|
|
|
+ ->select();
|
|
|
+
|
|
|
+ if (empty($qualityData)) {
|
|
|
+ $this->success('该产品无质量考核数据', []);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 2. 先按工单去重,每个工单只取一条记录
|
|
|
+ $uniqueByGongdan = [];
|
|
|
+ foreach ($qualityData as $data) {
|
|
|
+ $gdbh = $data['工单编号'];
|
|
|
+ if (!isset($uniqueByGongdan[$gdbh])) {
|
|
|
+ $uniqueByGongdan[$gdbh] = $data;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 3. 按月份分组累计数据
|
|
|
+ $monthlyData = [];
|
|
|
+ $monthNames = [
|
|
|
+ 1 => '1月', 2 => '2月', 3 => '3月', 4 => '4月',
|
|
|
+ 5 => '5月', 6 => '6月', 7 => '7月', 8 => '8月',
|
|
|
+ 9 => '9月', 10 => '10月', 11 => '11月', 12 => '12月'
|
|
|
+ ];
|
|
|
+
|
|
|
+ foreach ($uniqueByGongdan as $gdbh => $data) {
|
|
|
+ $sysRq = $data['入仓日期'];
|
|
|
+ $month = date('n', strtotime($sysRq)); // 1-12 的月份数字
|
|
|
+
|
|
|
+ // 初始化月份数据
|
|
|
+ if (!isset($monthlyData[$month])) {
|
|
|
+ $monthlyData[$month] = [
|
|
|
+ '月份' => $monthNames[$month],
|
|
|
+ '订单数量' => 0,
|
|
|
+ '实际投料' => 0,
|
|
|
+ '入仓数量' => 0,
|
|
|
+ '入仓日期' => $data['入仓日期'],
|
|
|
+ '客户代号' => $data['客户代号'],
|
|
|
+ '客户名称' => $data['客户名称'],
|
|
|
+ '产品代号' => $data['产品代号'],
|
|
|
+ '产品名称' => $data['产品名称'],
|
|
|
+ '销售订单号' => $data['销售订单号']
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ $monthlyData[$month]['订单数量'] += round($data['订单数量'] * 10000);
|
|
|
+ $monthlyData[$month]['实际投料'] += round($data['实际投料'] * 10000);
|
|
|
+ $monthlyData[$month]['入仓数量'] += round($data['入仓数量']);
|
|
|
+
|
|
|
+ // 记录工单编号
|
|
|
+ $monthlyData[$month]['工单编号'][] = $data['工单编号'];
|
|
|
+ }
|
|
|
+
|
|
|
+ // 4. 计算每个月的实际合格率并整理结果
|
|
|
+ $detailList = [];
|
|
|
+ foreach ($monthlyData as $month => $monthData) {
|
|
|
+ // 计算实际合格率
|
|
|
+ $actualRate = '-';
|
|
|
+ if ($monthData['实际投料'] > 0) {
|
|
|
+ $actualRate = round(($monthData['入仓数量'] / $monthData['实际投料']) * 100, 2) . '%';
|
|
|
+ } else if ($monthData['入仓数量'] > 0) {
|
|
|
+ $actualRate = '100%';
|
|
|
+ } else {
|
|
|
+ $actualRate = '0%';
|
|
|
+ }
|
|
|
+
|
|
|
+ $detailList[$month] = [
|
|
|
+ '日期' => $monthData['月份'],
|
|
|
+ '入仓日期' => substr($monthData['入仓日期'], 0, 10),
|
|
|
+ '订单数量' => $monthData['订单数量'],
|
|
|
+ '实际投料' => $monthData['实际投料'],
|
|
|
+ '入仓数量' => $monthData['入仓数量'],
|
|
|
+ '实际合格率' => $actualRate,
|
|
|
+ '客户代号' => $monthData['客户代号'],
|
|
|
+ '客户名称' => $monthData['客户名称'],
|
|
|
+ '产品代号' => $monthData['产品代号'],
|
|
|
+ '产品名称' => $monthData['产品名称'],
|
|
|
+ '销售订单号' => $monthData['销售订单号'],
|
|
|
+ '工单编号' => implode(', ', $monthData['工单编号'])
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ $this->success('成功', array_values($detailList));
|
|
|
+ }
|
|
|
+
|
|
|
}
|