|
@@ -584,18 +584,126 @@ class Decision extends Api
|
|
|
$this->success('成功', $formattedData);
|
|
$this->success('成功', $formattedData);
|
|
|
}
|
|
}
|
|
|
/**
|
|
/**
|
|
|
- * 获取年分数据
|
|
|
|
|
- * @return void
|
|
|
|
|
|
|
+ * 生产中心统计左侧菜单:年份 → 报表类型 → 下一级节点(全部从数据库动态取)
|
|
|
|
|
+ * 10 个报表类型固定返回,下一级节点按报表类型从对应数据源取实际值:
|
|
|
|
|
+ * - month_* 月度类 (7个) → 工单_质量考核汇总.sys_ny / 设备_产量计酬.sczl_rq 的 YYYYMM
|
|
|
|
|
+ * - year_equipment_waste/box → 设备_基本资料.设备编组(有实际产量数据的)
|
|
|
|
|
+ * - day_output 产量日报 → 设备_产量计酬.sczl_rq 日期列表
|
|
|
*/
|
|
*/
|
|
|
public function GetYear()
|
|
public function GetYear()
|
|
|
{
|
|
{
|
|
|
- if ($this->request->isGet() === false){
|
|
|
|
|
|
|
+ if ($this->request->isGet() === false) {
|
|
|
$this->error('请求错误');
|
|
$this->error('请求错误');
|
|
|
}
|
|
}
|
|
|
- $data = \db('工单_质量考核汇总')
|
|
|
|
|
- ->group('year')
|
|
|
|
|
- ->column('YEAR(STR_TO_DATE(sys_ny, "%Y%m")) as year');
|
|
|
|
|
- $this->success('成功',$data);
|
|
|
|
|
|
|
+
|
|
|
|
|
+ // 10 个报表类型(固定顺序)
|
|
|
|
|
+ $reportTypes = [
|
|
|
|
|
+ 'month_output' => '产量月统计报表',
|
|
|
|
|
+ 'month_schedule' => '排产达成率月统计',
|
|
|
|
|
+ 'month_workhour' => '工时达成率月统计报表',
|
|
|
|
|
+ 'month_oee' => 'OEE月统计报表',
|
|
|
|
|
+ 'month_changeover' => '换型效率月统计报表',
|
|
|
|
|
+ 'month_ioi' => '投入产出率月统计报表',
|
|
|
|
|
+ 'month_processrate' => '工序产出率月统计报表',
|
|
|
|
|
+ 'year_equipment_waste' => '年度设备编组废品统计',
|
|
|
|
|
+ 'year_equipment_box' => '年度设备大箱数统计',
|
|
|
|
|
+ 'day_output' => '产量日报表统计',
|
|
|
|
|
+ ];
|
|
|
|
|
+
|
|
|
|
|
+ // 1. 工单_质量考核汇总 有数据的年份+月份(sys_ny = YYYYMM)
|
|
|
|
|
+ $khMonths = Db::query("SELECT DISTINCT sys_ny AS ym FROM `工单_质量考核汇总` WHERE sys_ny REGEXP '^[0-9]{6}$' ORDER BY ym DESC");
|
|
|
|
|
+ $khYears = [];
|
|
|
|
|
+ foreach ($khMonths as $r) {
|
|
|
|
|
+ $y = substr($r['ym'], 0, 4);
|
|
|
|
|
+ $khYears[$y][] = $r['ym'];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 2. 设备_产量计酬 有数据的年份+月份(过滤脏数据 0001xx)
|
|
|
|
|
+ $scMonths = Db::query("SELECT DISTINCT DATE_FORMAT(sczl_rq, '%Y%m') AS ym FROM `设备_产量计酬` WHERE sczl_rq >= '2000-01-01' AND sczl_rq IS NOT NULL ORDER BY ym DESC");
|
|
|
|
|
+ $scYears = [];
|
|
|
|
|
+ foreach ($scMonths as $r) {
|
|
|
|
|
+ $y = substr($r['ym'], 0, 4);
|
|
|
|
|
+ $scYears[$y][] = $r['ym'];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 3. 设备_产量计酬 有数据的日期列表(近 90 天,避免太长)
|
|
|
|
|
+ $days = Db::query("SELECT DISTINCT DATE_FORMAT(sczl_rq, '%Y-%m-%d') AS d FROM `设备_产量计酬` WHERE sczl_rq >= DATE_SUB(CURDATE(), INTERVAL 90 DAY) AND sczl_rq IS NOT NULL ORDER BY d DESC");
|
|
|
|
|
+
|
|
|
|
|
+ // 4. 设备_基本资料 有实际产量数据的设备编组
|
|
|
|
|
+ $groups = Db::query("SELECT DISTINCT RTRIM(b.设备编组) AS `group`
|
|
|
|
|
+ FROM `设备_产量计酬` s
|
|
|
|
|
+ INNER JOIN `设备_基本资料` b
|
|
|
|
|
+ ON RTRIM(b.设备编号) = RTRIM(s.sczl_jtbh)
|
|
|
|
|
+ WHERE b.设备编组 IS NOT NULL AND b.设备编组 <> '' AND s.sczl_rq >= '2000-01-01'
|
|
|
|
|
+ ORDER BY b.设备编组 ASC");
|
|
|
|
|
+
|
|
|
|
|
+ // 所有出现过的年份(取并集,倒序)
|
|
|
|
|
+ $allYears = array_unique(array_merge(array_keys($khYears), array_keys($scYears)));
|
|
|
|
|
+ rsort($allYears);
|
|
|
|
|
+
|
|
|
|
|
+ // 月份 label:从 YYYYMM 提取 MM
|
|
|
|
|
+ $monthLabel = function ($ym) {
|
|
|
|
|
+ return intval(substr($ym, 4, 2)) . '月';
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ $result = [];
|
|
|
|
|
+ foreach ($allYears as $year) {
|
|
|
|
|
+ $yearInt = intval($year);
|
|
|
|
|
+ $yearNode = [
|
|
|
|
|
+ 'key' => "year_{$yearInt}",
|
|
|
|
|
+ 'label' => "{$yearInt}年",
|
|
|
|
|
+ 'year' => $yearInt,
|
|
|
|
|
+ 'children' => [],
|
|
|
|
|
+ ];
|
|
|
|
|
+
|
|
|
|
|
+ foreach ($reportTypes as $typeKey => $typeLabel) {
|
|
|
|
|
+ $children = [];
|
|
|
|
|
+
|
|
|
|
|
+ if (strpos($typeKey, 'month_') === 0) {
|
|
|
|
|
+ // 月度类:优先用 质量考核汇总 的月份,没有则 fallback 到 产量计酬
|
|
|
|
|
+ $months = isset($khYears[$year]) ? $khYears[$year] : (isset($scYears[$year]) ? $scYears[$year] : []);
|
|
|
|
|
+ sort($months); // 升序
|
|
|
|
|
+ foreach ($months as $ym) {
|
|
|
|
|
+ $children[] = [
|
|
|
|
|
+ 'key' => "{$yearInt}_{$ym}",
|
|
|
|
|
+ 'label' => $monthLabel($ym),
|
|
|
|
|
+ 'ym' => $ym,
|
|
|
|
|
+ ];
|
|
|
|
|
+ }
|
|
|
|
|
+ } elseif (strpos($typeKey, 'year_') === 0) {
|
|
|
|
|
+ // 年度类:设备编组列表(每年份显示全部编组,数据按年份过滤在后端处理)
|
|
|
|
|
+ foreach ($groups as $g) {
|
|
|
|
|
+ $gname = $g['group'];
|
|
|
|
|
+ $children[] = [
|
|
|
|
|
+ 'key' => "{$yearInt}_" . md5($gname),
|
|
|
|
|
+ 'label' => $gname,
|
|
|
|
|
+ 'group' => $gname,
|
|
|
|
|
+ ];
|
|
|
|
|
+ }
|
|
|
|
|
+ } elseif ($typeKey === 'day_output') {
|
|
|
|
|
+ // 日报表:近 90 天日期
|
|
|
|
|
+ foreach ($days as $d) {
|
|
|
|
|
+ $dateStr = $d['d'];
|
|
|
|
|
+ $children[] = [
|
|
|
|
|
+ 'key' => "{$yearInt}_{$dateStr}",
|
|
|
|
|
+ 'label' => substr($dateStr, 5), // MM-DD
|
|
|
|
|
+ 'date' => $dateStr,
|
|
|
|
|
+ ];
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $yearNode['children'][] = [
|
|
|
|
|
+ 'key' => "year_{$yearInt}_{$typeKey}",
|
|
|
|
|
+ 'label' => $typeLabel,
|
|
|
|
|
+ 'typeKey' => $typeKey,
|
|
|
|
|
+ 'children' => $children,
|
|
|
|
|
+ ];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $result[] = $yearNode;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $this->success('成功', $result);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -1429,7 +1537,7 @@ class Decision extends Api
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 年度成品入仓统计右侧表格
|
|
* 年度成品入仓统计右侧表格
|
|
|
- * 产品取自成品入仓(成品编码/成品名称),大箱数取自 db_包装计件 的 sczl_cl1-6,按 sczl_rq 月份汇总
|
|
|
|
|
|
|
+ * 产品取自成品入仓(成品编码/成品名称),大箱数取自 db_包装产量预报 的 sczl_cl1-6,按 sczl_rq 月份汇总
|
|
|
*/
|
|
*/
|
|
|
public function YearcprctjList()
|
|
public function YearcprctjList()
|
|
|
{
|
|
{
|
|
@@ -1485,8 +1593,8 @@ class Decision extends Api
|
|
|
$this->success('成功', []);
|
|
$this->success('成功', []);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 2、包装计件:按 sczl_rq 的月份汇总对应工单的 sczl_cl1-6
|
|
|
|
|
- $packRows = \db('db_包装计件')
|
|
|
|
|
|
|
+ // 2、包装产量预报:按 sczl_rq 的月份汇总对应工单的 sczl_cl1-6
|
|
|
|
|
+ $packRows = \db('db_包装产量预报')
|
|
|
->field('sczl_rq, sczl_gdbh1, sczl_gdbh2, sczl_gdbh3, sczl_gdbh4, sczl_gdbh5, sczl_gdbh6, sczl_cl1, sczl_cl2, sczl_cl3, sczl_cl4, sczl_cl5, sczl_cl6')
|
|
->field('sczl_rq, sczl_gdbh1, sczl_gdbh2, sczl_gdbh3, sczl_gdbh4, sczl_gdbh5, sczl_gdbh6, sczl_cl1, sczl_cl2, sczl_cl3, sczl_cl4, sczl_cl5, sczl_cl6')
|
|
|
->where('sczl_rq', '>=', $start)
|
|
->where('sczl_rq', '>=', $start)
|
|
|
->where('sczl_rq', '<', $end)
|
|
->where('sczl_rq', '<', $end)
|
|
@@ -1969,29 +2077,73 @@ class Decision extends Api
|
|
|
"RTRIM(Gy0_sbbh) AS 设备编号",
|
|
"RTRIM(Gy0_sbbh) AS 设备编号",
|
|
|
"Gy0_计划接货数 AS 计划接货数",
|
|
"Gy0_计划接货数 AS 计划接货数",
|
|
|
"Gy0_ks AS 开数",
|
|
"Gy0_ks AS 开数",
|
|
|
- "Gy0_ls AS 印数",
|
|
|
|
|
|
|
+ "Gy0_ls AS 联数",
|
|
|
"Gy0_小时产能 AS 小时产能",
|
|
"Gy0_小时产能 AS 小时产能",
|
|
|
])
|
|
])
|
|
|
->whereIn('Gy0_gdbh', $gdbhs)
|
|
->whereIn('Gy0_gdbh', $gdbhs)
|
|
|
->order('工单编号, 印件号, 工序号')
|
|
->order('工单编号, 印件号, 工序号')
|
|
|
->select();
|
|
->select();
|
|
|
|
|
|
|
|
- // 3、实际工时:设备_产量计酬 中同工单+印件+工序、设备运行工时不为0的记录
|
|
|
|
|
|
|
+ // 3、实际工时:设备_产量计酬 中同工单+印件+工序的记录,按 sczl_sj1~sczl_sj2 时间区间合并计算
|
|
|
|
|
+ // 同一工单记录基本连续,不连续时中间换成其他工单的时间自然被排除(只做区间并集,不跨区间累加)
|
|
|
$actualRows = \db('设备_产量计酬')
|
|
$actualRows = \db('设备_产量计酬')
|
|
|
->field([
|
|
->field([
|
|
|
"RTRIM(sczl_gdbh) AS 工单编号",
|
|
"RTRIM(sczl_gdbh) AS 工单编号",
|
|
|
"FLOOR(sczl_yjno) AS 印件号",
|
|
"FLOOR(sczl_yjno) AS 印件号",
|
|
|
"FLOOR(sczl_gxh) AS 工序号",
|
|
"FLOOR(sczl_gxh) AS 工序号",
|
|
|
- "MAX(sczl_设备运行工时) AS 实际工时",
|
|
|
|
|
|
|
+ "sczl_sj1",
|
|
|
|
|
+ "sczl_sj2",
|
|
|
])
|
|
])
|
|
|
->whereIn('sczl_gdbh', $gdbhs)
|
|
->whereIn('sczl_gdbh', $gdbhs)
|
|
|
- ->where('sczl_设备运行工时', '<>', 0)
|
|
|
|
|
- ->group('RTRIM(sczl_gdbh), FLOOR(sczl_yjno), FLOOR(sczl_gxh)')
|
|
|
|
|
->select();
|
|
->select();
|
|
|
|
|
|
|
|
- $actualMap = [];
|
|
|
|
|
|
|
+ // 按 工单+印件+工序 收集时间区间
|
|
|
|
|
+ $intervalMap = [];
|
|
|
foreach ($actualRows as $row) {
|
|
foreach ($actualRows as $row) {
|
|
|
- $actualMap[$this->DyxlKey($row['工单编号'], $row['印件号'], $row['工序号'])] = (float)$row['实际工时'];
|
|
|
|
|
|
|
+ $t1 = strtotime(trim((string)$row['sczl_sj1']));
|
|
|
|
|
+ $t2 = strtotime(trim((string)$row['sczl_sj2']));
|
|
|
|
|
+ if ($t1 === false || $t2 === false || $t1 <= 0 || $t2 <= 0) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ if ($t2 < $t1) {
|
|
|
|
|
+ // 跨午夜:结束时间顺延一天
|
|
|
|
|
+ $t2 += 86400;
|
|
|
|
|
+ }
|
|
|
|
|
+ if ($t2 <= $t1) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ $key = $this->DyxlKey($row['工单编号'], $row['印件号'], $row['工序号']);
|
|
|
|
|
+ if (!isset($intervalMap[$key])) {
|
|
|
|
|
+ $intervalMap[$key] = [];
|
|
|
|
|
+ }
|
|
|
|
|
+ $intervalMap[$key][] = [$t1, $t2];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 合并时间区间并计算总时长(小时)
|
|
|
|
|
+ $actualMap = [];
|
|
|
|
|
+ foreach ($intervalMap as $key => $intervals) {
|
|
|
|
|
+ usort($intervals, function ($a, $b) {
|
|
|
|
|
+ return $a[0] - $b[0];
|
|
|
|
|
+ });
|
|
|
|
|
+ $total = 0;
|
|
|
|
|
+ $curStart = $intervals[0][0];
|
|
|
|
|
+ $curEnd = $intervals[0][1];
|
|
|
|
|
+ $count = count($intervals);
|
|
|
|
|
+ for ($i = 1; $i < $count; $i++) {
|
|
|
|
|
+ if ($intervals[$i][0] <= $curEnd) {
|
|
|
|
|
+ // 区间重叠或相连,合并
|
|
|
|
|
+ if ($intervals[$i][1] > $curEnd) {
|
|
|
|
|
+ $curEnd = $intervals[$i][1];
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 不连续:结算当前区间,中间其他工单时间不计入
|
|
|
|
|
+ $total += $curEnd - $curStart;
|
|
|
|
|
+ $curStart = $intervals[$i][0];
|
|
|
|
|
+ $curEnd = $intervals[$i][1];
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ $total += $curEnd - $curStart;
|
|
|
|
|
+ $actualMap[$key] = $total / 3600;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
$sumPlan = [];
|
|
$sumPlan = [];
|
|
@@ -2110,13 +2262,13 @@ class Decision extends Api
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * 计划工时 = 计划接货数 * 开数 * 印数 / 小时产能
|
|
|
|
|
|
|
+ * 计划工时 = 计划接货数 * 开数 * 联数 / 小时产能
|
|
|
*/
|
|
*/
|
|
|
private function DyxlPlanHours($craft)
|
|
private function DyxlPlanHours($craft)
|
|
|
{
|
|
{
|
|
|
$qty = (float)$craft['计划接货数'];
|
|
$qty = (float)$craft['计划接货数'];
|
|
|
$ks = (float)$craft['开数'];
|
|
$ks = (float)$craft['开数'];
|
|
|
- $ls = (float)$craft['印数'];
|
|
|
|
|
|
|
+ $ls = (float)$craft['联数'];
|
|
|
$capacity = (float)$craft['小时产能'];
|
|
$capacity = (float)$craft['小时产能'];
|
|
|
if ($qty <= 0 || $ks <= 0 || $ls <= 0 || $capacity <= 0) {
|
|
if ($qty <= 0 || $ks <= 0 || $ls <= 0 || $capacity <= 0) {
|
|
|
return null;
|
|
return null;
|
|
@@ -2510,9 +2662,10 @@ class Decision extends Api
|
|
|
$machine = trim((string)(isset($param['machine']) ? $param['machine'] : ''));
|
|
$machine = trim((string)(isset($param['machine']) ? $param['machine'] : ''));
|
|
|
|
|
|
|
|
// 以数据库最新日期为基准,取最近 7 天
|
|
// 以数据库最新日期为基准,取最近 7 天
|
|
|
- $maxDate = \db('设备_产量计酬')->max('sczl_rq');
|
|
|
|
|
|
|
+ // $maxDate = \db('设备_产量计酬')->max('sczl_rq');
|
|
|
|
|
+ $maxDate = "2026-10-11";
|
|
|
if (!$maxDate) {
|
|
if (!$maxDate) {
|
|
|
- $this->success('成功', ['summary' => [], 'detail' => [], 'range' => ['start' => '', 'end' => '']]);
|
|
|
|
|
|
|
+ $this->success('成功', ['summary' => [], 'detail' => [], 'days' => [], 'range' => ['start' => '', 'end' => '']]);
|
|
|
}
|
|
}
|
|
|
$maxTs = strtotime($maxDate);
|
|
$maxTs = strtotime($maxDate);
|
|
|
$end = date('Y-m-d', $maxTs);
|
|
$end = date('Y-m-d', $maxTs);
|
|
@@ -2520,41 +2673,90 @@ class Decision extends Api
|
|
|
$startTime = $start . ' 00:00:00';
|
|
$startTime = $start . ' 00:00:00';
|
|
|
$endTime = date('Y-m-d', $maxTs + 86400) . ' 00:00:00';
|
|
$endTime = date('Y-m-d', $maxTs + 86400) . ' 00:00:00';
|
|
|
|
|
|
|
|
- // 1、汇总:按机台编号聚合
|
|
|
|
|
- $summaryQuery = \db('设备_产量计酬')
|
|
|
|
|
- ->alias('s')
|
|
|
|
|
- ->join('设备_基本资料 b', 'RTRIM(b.设备编号) = RTRIM(s.sczl_jtbh)', 'LEFT')
|
|
|
|
|
|
|
+ // 7 天日期列表(新 -> 旧)
|
|
|
|
|
+ $days = [];
|
|
|
|
|
+ for ($i = 0; $i < 7; $i++) {
|
|
|
|
|
+ $days[] = date('Y-m-d', $maxTs - $i * 86400);
|
|
|
|
|
+ }
|
|
|
|
|
+ $dayLabels = [];
|
|
|
|
|
+ foreach ($days as $d) {
|
|
|
|
|
+ $dayLabels[] = date('m.d', strtotime($d));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 机台清单(与左侧树口径一致:排除研发中心、设备编组/机台编号为空)
|
|
|
|
|
+ $machineQuery = \db('设备_基本资料')
|
|
|
|
|
+ ->where('使用部门', '<>', '研发中心')
|
|
|
|
|
+ ->where('设备编组', '<>', '')
|
|
|
|
|
+ ->where('sys_sbID', '<>', '')
|
|
|
|
|
+ ->field('RTRIM(设备编号) AS 机台编号, RTRIM(设备名称) AS 设备名称')
|
|
|
|
|
+ ->order('设备编号');
|
|
|
|
|
+ if ($machine !== '') {
|
|
|
|
|
+ $machineQuery->where('设备编号', $machine);
|
|
|
|
|
+ }
|
|
|
|
|
+ $machineList = $machineQuery->select();
|
|
|
|
|
+
|
|
|
|
|
+ // 1、汇总:机台 x 日期 => 产量(当天汇总)+ 工时(sczl_sj2 - sczl_sj1 合计)
|
|
|
|
|
+ $recordQuery = \db('设备_产量计酬')
|
|
|
->field([
|
|
->field([
|
|
|
- 'RTRIM(s.sczl_jtbh) AS 机台编号',
|
|
|
|
|
- 'RTRIM(b.设备名称) AS 设备名称',
|
|
|
|
|
- 'RTRIM(b.使用部门) AS 使用部门',
|
|
|
|
|
- 'RTRIM(b.生产工序) AS 生产工序',
|
|
|
|
|
- 'RTRIM(b.设备编组) AS 设备编组',
|
|
|
|
|
- 'SUM(s.sczl_cl) AS 总产量',
|
|
|
|
|
- 'SUM(s.sczl_设备运行工时) AS 设备运行工时',
|
|
|
|
|
- 'SUM(s.sczl_装版工时) AS 装版工时',
|
|
|
|
|
- 'SUM(s.sczl_装版总工时) AS 装版总工时',
|
|
|
|
|
- 'SUM(s.sczl_保养工时) AS 保养工时',
|
|
|
|
|
- 'SUM(s.sczl_打样工时) AS 打样工时',
|
|
|
|
|
- 'SUM(s.sczl_打样总工时) AS 打样总工时',
|
|
|
|
|
- 'SUM(s.sczl_异常停机工时) AS 异常停机工时',
|
|
|
|
|
- 'SUM(s.sczl_zcfp) AS 制程废品',
|
|
|
|
|
- 'SUM(s.sczl_zccp) AS 制程次品',
|
|
|
|
|
- 'SUM(s.sczl_前工序废) AS 前工序废',
|
|
|
|
|
- 'SUM(s.sczl_来料少数) AS 来料少数',
|
|
|
|
|
- 'SUM(s.sczl_异常工时1) AS 异常补时',
|
|
|
|
|
|
|
+ 'RTRIM(sczl_jtbh) AS 机台编号',
|
|
|
|
|
+ "DATE_FORMAT(sczl_rq, '%Y-%m-%d') AS 日期",
|
|
|
|
|
+ 'sczl_cl',
|
|
|
|
|
+ 'sczl_sj1',
|
|
|
|
|
+ 'sczl_sj2',
|
|
|
])
|
|
])
|
|
|
- ->where('s.sczl_rq', '>=', $startTime)
|
|
|
|
|
- ->where('s.sczl_rq', '<', $endTime);
|
|
|
|
|
-
|
|
|
|
|
|
|
+ ->where('sczl_rq', '>=', $startTime)
|
|
|
|
|
+ ->where('sczl_rq', '<', $endTime);
|
|
|
if ($machine !== '') {
|
|
if ($machine !== '') {
|
|
|
- $summaryQuery->where('s.sczl_jtbh', $machine);
|
|
|
|
|
|
|
+ $recordQuery->where('sczl_jtbh', $machine);
|
|
|
}
|
|
}
|
|
|
|
|
+ $records = $recordQuery->select();
|
|
|
|
|
|
|
|
- $summary = $summaryQuery
|
|
|
|
|
- ->group('机台编号, 设备名称, 使用部门, 生产工序, 设备编组')
|
|
|
|
|
- ->order('机台编号')
|
|
|
|
|
- ->select();
|
|
|
|
|
|
|
+ $agg = [];
|
|
|
|
|
+ foreach ($records as $r) {
|
|
|
|
|
+ $code = trim((string)$r['机台编号']);
|
|
|
|
|
+ $day = trim((string)$r['日期']);
|
|
|
|
|
+ if ($code === '' || $day === '') {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!isset($agg[$code])) {
|
|
|
|
|
+ $agg[$code] = [];
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!isset($agg[$code][$day])) {
|
|
|
|
|
+ $agg[$code][$day] = ['产量' => 0, '工时' => 0];
|
|
|
|
|
+ }
|
|
|
|
|
+ $agg[$code][$day]['产量'] += (float)$r['sczl_cl'];
|
|
|
|
|
+ $t1 = strtotime(trim((string)$r['sczl_sj1']));
|
|
|
|
|
+ $t2 = strtotime(trim((string)$r['sczl_sj2']));
|
|
|
|
|
+ if ($t1 !== false && $t2 !== false && $t1 > 0 && $t2 > 0) {
|
|
|
|
|
+ if ($t2 < $t1) {
|
|
|
|
|
+ // 跨午夜:结束时间顺延一天
|
|
|
|
|
+ $t2 += 86400;
|
|
|
|
|
+ }
|
|
|
|
|
+ if ($t2 > $t1) {
|
|
|
|
|
+ $agg[$code][$day]['工时'] += ($t2 - $t1) / 3600;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $summary = [];
|
|
|
|
|
+ foreach ($machineList as $m) {
|
|
|
|
|
+ $code = trim((string)$m['机台编号']);
|
|
|
|
|
+ if ($code === '') {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ $row = [
|
|
|
|
|
+ '机台编号' => $code,
|
|
|
|
|
+ '设备名称' => trim((string)$m['设备名称']),
|
|
|
|
|
+ ];
|
|
|
|
|
+ foreach ($days as $idx => $day) {
|
|
|
|
|
+ $label = $dayLabels[$idx];
|
|
|
|
|
+ $cl = isset($agg[$code][$day]) ? $agg[$code][$day]['产量'] : 0;
|
|
|
|
|
+ $gs = isset($agg[$code][$day]) ? $agg[$code][$day]['工时'] : 0;
|
|
|
|
|
+ $row['产量_' . $label] = $cl == 0 ? '' : round($cl, 2);
|
|
|
|
|
+ $row['工时_' . $label] = $gs == 0 ? '' : round($gs, 2);
|
|
|
|
|
+ }
|
|
|
|
|
+ $summary[] = $row;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
// 2、明细:工单级(按 机台编号 + 工单编号 + 日期 聚合)
|
|
// 2、明细:工单级(按 机台编号 + 工单编号 + 日期 聚合)
|
|
|
$detailQuery = \db('设备_产量计酬')
|
|
$detailQuery = \db('设备_产量计酬')
|
|
@@ -2592,14 +2794,6 @@ class Decision extends Api
|
|
|
->select();
|
|
->select();
|
|
|
|
|
|
|
|
// 数值格式化(0 显示为空字符串)
|
|
// 数值格式化(0 显示为空字符串)
|
|
|
- foreach ($summary as &$row) {
|
|
|
|
|
- foreach (['总产量', '设备运行工时', '装版工时', '装版总工时', '保养工时', '打样工时', '打样总工时', '异常停机工时', '制程废品', '制程次品', '前工序废', '来料少数', '异常补时'] as $k) {
|
|
|
|
|
- $v = (float)$row[$k];
|
|
|
|
|
- $row[$k] = $v === 0 ? '' : round($v, 2);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- unset($row);
|
|
|
|
|
-
|
|
|
|
|
foreach ($detail as &$row) {
|
|
foreach ($detail as &$row) {
|
|
|
foreach (['产量', '设备运行工时', '装版工时', '保养工时', '打样工时', '异常停机工时', '制程废品', '制程次品'] as $k) {
|
|
foreach (['产量', '设备运行工时', '装版工时', '保养工时', '打样工时', '异常停机工时', '制程废品', '制程次品'] as $k) {
|
|
|
$v = (float)$row[$k];
|
|
$v = (float)$row[$k];
|
|
@@ -2611,6 +2805,7 @@ class Decision extends Api
|
|
|
$this->success('成功', [
|
|
$this->success('成功', [
|
|
|
'summary' => $summary,
|
|
'summary' => $summary,
|
|
|
'detail' => $detail,
|
|
'detail' => $detail,
|
|
|
|
|
+ 'days' => $dayLabels,
|
|
|
'range' => ['start' => $start, 'end' => $end],
|
|
'range' => ['start' => $start, 'end' => $end],
|
|
|
]);
|
|
]);
|
|
|
}
|
|
}
|
|
@@ -2625,15 +2820,26 @@ class Decision extends Api
|
|
|
$this->error('请求错误');
|
|
$this->error('请求错误');
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // 条件:近12个月内「末版入仓完工」的工单(末版入仓 jjcp_smb like 末% 即视为完工)
|
|
|
|
|
+ // 月份分组 = 末版入仓完工日期 MAX(jjcp_sj)
|
|
|
|
|
+ // 客户代号/客户名称:产品_基本资料(按成品编码 Gd_cpdh 关联),工单自身客户字段只做兜底
|
|
|
$sql = "SELECT
|
|
$sql = "SELECT
|
|
|
- DATE_FORMAT(a.接单日期, '%Y%m') AS date,
|
|
|
|
|
|
|
+ DATE_FORMAT(c.完工时间, '%Y%m') AS date,
|
|
|
COUNT(DISTINCT a.Gd_gdbh) AS cnt,
|
|
COUNT(DISTINCT a.Gd_gdbh) AS cnt,
|
|
|
- RTRIM(a.Gd_客户代号) AS code,
|
|
|
|
|
- RTRIM(a.Gd_客户名称) AS name
|
|
|
|
|
|
|
+ RTRIM(COALESCE(p.客户编号, a.Gd_客户代号)) AS code,
|
|
|
|
|
+ RTRIM(COALESCE(p.客户名称, a.Gd_客户名称)) AS name
|
|
|
FROM `工单_基本资料` a
|
|
FROM `工单_基本资料` a
|
|
|
- WHERE a.接单日期 >= DATE_SUB(CURDATE(), INTERVAL 12 MONTH)
|
|
|
|
|
- AND a.接单日期 IS NOT NULL
|
|
|
|
|
- AND (a.工单完工日期 IS NOT NULL OR EXISTS (SELECT 1 FROM `成品入仓` c WHERE c.jjcp_gdbh = a.Gd_gdbh))
|
|
|
|
|
|
|
+ LEFT JOIN `产品_基本资料` p
|
|
|
|
|
+ ON RTRIM(a.Gd_cpdh) = RTRIM(p.产品编号)
|
|
|
|
|
+ INNER JOIN (
|
|
|
|
|
+ SELECT jjcp_gdbh, jjcp_yjno, MAX(jjcp_sj) AS 完工时间
|
|
|
|
|
+ FROM `成品入仓`
|
|
|
|
|
+ WHERE jjcp_smb LIKE '末%'
|
|
|
|
|
+ GROUP BY jjcp_gdbh, jjcp_yjno
|
|
|
|
|
+ ) c
|
|
|
|
|
+ ON a.Gd_gdbh = c.jjcp_gdbh AND CAST(a.行号 AS UNSIGNED) = CAST(c.jjcp_yjno AS UNSIGNED)
|
|
|
|
|
+ WHERE c.完工时间 >= DATE_SUB(CURDATE(), INTERVAL 12 MONTH)
|
|
|
|
|
+ AND c.完工时间 IS NOT NULL
|
|
|
GROUP BY date, code, name
|
|
GROUP BY date, code, name
|
|
|
ORDER BY date DESC, code ASC";
|
|
ORDER BY date DESC, code ASC";
|
|
|
$rows = Db::query($sql);
|
|
$rows = Db::query($sql);
|
|
@@ -2691,16 +2897,15 @@ class Decision extends Api
|
|
|
$offset = ($page - 1) * $limit;
|
|
$offset = ($page - 1) * $limit;
|
|
|
|
|
|
|
|
$where = [];
|
|
$where = [];
|
|
|
- $where[] = "a.接单日期 >= DATE_SUB(CURDATE(), INTERVAL 12 MONTH)";
|
|
|
|
|
- $where[] = "a.接单日期 IS NOT NULL";
|
|
|
|
|
- $where[] = "(a.工单完工日期 IS NOT NULL AND a.工单完工日期 <> '1900-01-01 00:00:00') OR EXISTS (SELECT 1 FROM `成品入仓` c2 WHERE c2.jjcp_gdbh = a.Gd_gdbh)";
|
|
|
|
|
|
|
+ $where[] = "c.完工时间 >= DATE_SUB(CURDATE(), INTERVAL 12 MONTH)";
|
|
|
|
|
+ $where[] = "c.完工时间 IS NOT NULL";
|
|
|
|
|
|
|
|
if ($date !== '') {
|
|
if ($date !== '') {
|
|
|
- $where[] = "DATE_FORMAT(a.接单日期, '%Y%m') = " . intval($date);
|
|
|
|
|
|
|
+ $where[] = "DATE_FORMAT(c.完工时间, '%Y%m') = " . intval($date);
|
|
|
}
|
|
}
|
|
|
if ($code !== '') {
|
|
if ($code !== '') {
|
|
|
$escaped = str_replace("'", "''", $code);
|
|
$escaped = str_replace("'", "''", $code);
|
|
|
- $where[] = "UPPER(RTRIM(a.Gd_客户代号)) = UPPER(RTRIM('{$escaped}'))";
|
|
|
|
|
|
|
+ $where[] = "UPPER(RTRIM(COALESCE(p.客户编号, a.Gd_客户代号))) = UPPER(RTRIM('{$escaped}'))";
|
|
|
}
|
|
}
|
|
|
if ($search !== '') {
|
|
if ($search !== '') {
|
|
|
$escaped = str_replace("'", "''", $search);
|
|
$escaped = str_replace("'", "''", $search);
|
|
@@ -2709,19 +2914,37 @@ class Decision extends Api
|
|
|
|
|
|
|
|
$whereSql = implode(' AND ', $where);
|
|
$whereSql = implode(' AND ', $where);
|
|
|
|
|
|
|
|
- // 公共 FROM 段(与 a 表 1:1 关联,可用于统计总数)
|
|
|
|
|
|
|
+ // 公共 FROM 段(成品入仓只取末版 jjcp_smb like 末%,无末版入仓的工单不参与统计)
|
|
|
$fromSql = "FROM `工单_基本资料` a
|
|
$fromSql = "FROM `工单_基本资料` a
|
|
|
|
|
+ LEFT JOIN `产品_基本资料` p
|
|
|
|
|
+ ON RTRIM(a.Gd_cpdh) = RTRIM(p.产品编号)
|
|
|
LEFT JOIN `工单_印件资料` b
|
|
LEFT JOIN `工单_印件资料` b
|
|
|
- ON a.Gd_gdbh = b.Yj_Gdbh AND CAST(a.行号 AS UNSIGNED) = b.yj_Yjno
|
|
|
|
|
- LEFT JOIN (
|
|
|
|
|
|
|
+ ON a.Gd_gdbh = b.Yj_Gdbh AND CAST(a.行号 AS UNSIGNED) = CAST(b.yj_Yjno AS UNSIGNED)
|
|
|
|
|
+ INNER JOIN (
|
|
|
SELECT jjcp_gdbh, jjcp_yjno,
|
|
SELECT jjcp_gdbh, jjcp_yjno,
|
|
|
SUM(jjcp_sl) AS 入仓数量,
|
|
SUM(jjcp_sl) AS 入仓数量,
|
|
|
- MIN(jjcp_sj) AS 检验日期,
|
|
|
|
|
- MAX(jjcp_sj) AS 入仓完工日期
|
|
|
|
|
|
|
+ MIN(jjcp_sj) AS 检验时间,
|
|
|
|
|
+ MAX(jjcp_sj) AS 完工时间
|
|
|
FROM `成品入仓`
|
|
FROM `成品入仓`
|
|
|
|
|
+ WHERE jjcp_smb LIKE '末%'
|
|
|
GROUP BY jjcp_gdbh, jjcp_yjno
|
|
GROUP BY jjcp_gdbh, jjcp_yjno
|
|
|
) c
|
|
) c
|
|
|
- ON a.Gd_gdbh = c.jjcp_gdbh AND CAST(a.行号 AS UNSIGNED) = c.jjcp_yjno
|
|
|
|
|
|
|
+ ON a.Gd_gdbh = c.jjcp_gdbh AND CAST(a.行号 AS UNSIGNED) = CAST(c.jjcp_yjno AS UNSIGNED)
|
|
|
|
|
+ LEFT JOIN (
|
|
|
|
|
+ SELECT RTRIM(sczl_gdbh) AS gdbh, sczl_yjno,
|
|
|
|
|
+ MIN(sczl_rq) AS 生产开工时间,
|
|
|
|
|
+ MIN(CASE WHEN sczl_gxmc LIKE '%模切%' THEN sczl_rq END) AS 模切开工时间
|
|
|
|
|
+ FROM `设备_产量计酬`
|
|
|
|
|
+ WHERE sczl_rq >= DATE_SUB(CURDATE(), INTERVAL 13 MONTH)
|
|
|
|
|
+ GROUP BY RTRIM(sczl_gdbh), sczl_yjno
|
|
|
|
|
+ ) gy
|
|
|
|
|
+ ON a.Gd_gdbh = gy.gdbh AND CAST(a.行号 AS UNSIGNED) = CAST(gy.sczl_yjno AS UNSIGNED)
|
|
|
|
|
+ LEFT JOIN (
|
|
|
|
|
+ SELECT Gy0_gdbh, 印件及工序 AS 印件号, SUM(DISTINCT 计划损耗) AS 计划损耗
|
|
|
|
|
+ FROM `工单_质量考核汇总`
|
|
|
|
|
+ GROUP BY Gy0_gdbh, 印件及工序
|
|
|
|
|
+ ) q
|
|
|
|
|
+ ON a.Gd_gdbh = q.Gy0_gdbh AND CAST(a.行号 AS UNSIGNED) = CAST(q.印件号 AS UNSIGNED)
|
|
|
WHERE {$whereSql}";
|
|
WHERE {$whereSql}";
|
|
|
|
|
|
|
|
// 总数
|
|
// 总数
|
|
@@ -2738,47 +2961,63 @@ class Decision extends Api
|
|
|
a.实际投料,
|
|
a.实际投料,
|
|
|
RTRIM(a.计量单位) AS 计量单位,
|
|
RTRIM(a.计量单位) AS 计量单位,
|
|
|
IFNULL(c.入仓数量, 0) AS 入仓数量,
|
|
IFNULL(c.入仓数量, 0) AS 入仓数量,
|
|
|
- DATEDIFF(COALESCE(DATE(c.检验日期), DATE(a.工单完工日期)), DATE(a.接单日期)) AS 工单周期,
|
|
|
|
|
- DATE(COALESCE(c.检验日期, a.工单完工日期)) AS 检验日期,
|
|
|
|
|
- TIME(COALESCE(c.检验日期, a.工单完工日期)) AS 检验时间,
|
|
|
|
|
|
|
+ DATE(c.检验时间) AS 检验日期,
|
|
|
|
|
+ DATE(COALESCE(c.完工时间, NULLIF(a.入仓日期, '1900-01-01 00:00:00'), NULLIF(a.工单完工日期, '1900-01-01 00:00:00'))) AS 入仓完工日期,
|
|
|
DATE(a.接单日期) AS 接单日期,
|
|
DATE(a.接单日期) AS 接单日期,
|
|
|
- DATE(COALESCE(c.入仓完工日期, NULLIF(a.入仓日期, '1900-01-01 00:00:00'), a.工单完工日期)) AS 入仓完工日期,
|
|
|
|
|
- RTRIM(a.Gd_客户代号) AS 客户代号,
|
|
|
|
|
- RTRIM(a.Gd_客户名称) AS 客户名称,
|
|
|
|
|
|
|
+ DATE(gy.生产开工时间) AS 生产开工日期,
|
|
|
|
|
+ DATE(gy.模切开工时间) AS 模切开工日期,
|
|
|
|
|
+ IFNULL(q.计划损耗, 0) AS 计划损耗,
|
|
|
|
|
+ RTRIM(COALESCE(p.客户编号, a.Gd_客户代号)) AS 客户代号,
|
|
|
|
|
+ RTRIM(COALESCE(p.客户名称, a.Gd_客户名称)) AS 客户名称,
|
|
|
RTRIM(a.销售订单号) AS 销售订单号
|
|
RTRIM(a.销售订单号) AS 销售订单号
|
|
|
{$fromSql}
|
|
{$fromSql}
|
|
|
- ORDER BY COALESCE(c.检验日期, a.工单完工日期) DESC, a.Gd_gdbh DESC
|
|
|
|
|
|
|
+ ORDER BY COALESCE(c.完工时间, a.工单完工日期) DESC, a.Gd_gdbh DESC
|
|
|
LIMIT {$offset}, {$limit}";
|
|
LIMIT {$offset}, {$limit}";
|
|
|
|
|
|
|
|
$list = Db::query($sql);
|
|
$list = Db::query($sql);
|
|
|
|
|
|
|
|
- foreach ($list as &$row) {
|
|
|
|
|
- $row['生产公分'] = '';
|
|
|
|
|
- $row['工单公休'] = '';
|
|
|
|
|
- $row['计划开工日期'] = '';
|
|
|
|
|
- $row['实际开工日期'] = '';
|
|
|
|
|
- $row['目标合格率'] = '';
|
|
|
|
|
-
|
|
|
|
|
- foreach (['订单数量', '实际投料'] as $k) {
|
|
|
|
|
- $v = (float)$row[$k];
|
|
|
|
|
- $row[$k] = $v === 0 ? '' : number_format($v, 2);
|
|
|
|
|
- }
|
|
|
|
|
- $row['入仓数量'] = (int)$row['入仓数量'] === 0 ? '' : (int)$row['入仓数量'];
|
|
|
|
|
- $row['工单周期'] = $row['工单周期'] === null ? '' : (int)$row['工单周期'];
|
|
|
|
|
-
|
|
|
|
|
- $sl = (int)$row['入仓数量'];
|
|
|
|
|
- $tl = (float)$row['实际投料'];
|
|
|
|
|
- if ($sl > 0 && $tl > 0) {
|
|
|
|
|
- $row['实际合格率'] = number_format($sl / ($tl * 10000) * 100, 2) . '%';
|
|
|
|
|
- } else {
|
|
|
|
|
- $row['实际合格率'] = '';
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ // 月度公休记录(用于生产公休/检验公休/工单公休)
|
|
|
|
|
+ $holidayMap = $this->CopsHolidayMap();
|
|
|
|
|
|
|
|
- foreach (['检验日期', '检验时间', '接单日期', '入仓完工日期'] as $k) {
|
|
|
|
|
- if ($row[$k] === null || $row[$k] === '1900-01-01' || $row[$k] === '1900-01-01 00:00:00') {
|
|
|
|
|
|
|
+ foreach ($list as &$row) {
|
|
|
|
|
+ // 先取原始数值,避免格式化后再次转换出错
|
|
|
|
|
+ $rawOrder = (float)$row['订单数量'];
|
|
|
|
|
+ $rawActual = (float)$row['实际投料'];
|
|
|
|
|
+ $warehouseNum = (int)$row['入仓数量'];
|
|
|
|
|
+ $planLoss = (float)$row['计划损耗'];
|
|
|
|
|
+
|
|
|
|
|
+ $row['订单数量'] = $rawOrder == 0 ? '' : number_format($rawOrder, 2);
|
|
|
|
|
+ $row['实际投料'] = $rawActual == 0 ? '' : number_format($rawActual, 2);
|
|
|
|
|
+ $row['入仓数量'] = $warehouseNum === 0 ? '' : $warehouseNum;
|
|
|
|
|
+
|
|
|
|
|
+ // 目标合格率 = (实际投料*10000 - 计划损耗) / (实际投料*10000)
|
|
|
|
|
+ $row['目标合格率'] = $rawActual > 0
|
|
|
|
|
+ ? number_format(($rawActual * 10000 - $planLoss) / ($rawActual * 10000) * 100, 2) . '%'
|
|
|
|
|
+ : '';
|
|
|
|
|
+ // 实际合格率 = 入仓数量 / (实际投料*10000)
|
|
|
|
|
+ $row['实际合格率'] = ($warehouseNum > 0 && $rawActual > 0)
|
|
|
|
|
+ ? number_format($warehouseNum / ($rawActual * 10000) * 100, 2) . '%'
|
|
|
|
|
+ : '';
|
|
|
|
|
+
|
|
|
|
|
+ // 日期空值处理
|
|
|
|
|
+ foreach (['检验日期', '接单日期', '入仓完工日期', '生产开工日期', '模切开工日期'] as $k) {
|
|
|
|
|
+ $v = (string)$row[$k];
|
|
|
|
|
+ if ($v === '' || $v === '0000-00-00' || strpos($v, '1900-01-01') === 0) {
|
|
|
$row[$k] = '';
|
|
$row[$k] = '';
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ // 周期(自然日)
|
|
|
|
|
+ // $row['生产周期'] = $this->CopsCycle($row['生产开工日期'], $row['检验日期']);
|
|
|
|
|
+ // $row['检验周期'] = $this->CopsCycle($row['检验日期'], $row['入仓完工日期']);
|
|
|
|
|
+ $row['工单周期'] = $this->CopsCycle($row['接单日期'], $row['入仓完工日期']);
|
|
|
|
|
+
|
|
|
|
|
+ // // 公休天数(区间内 人事_班组公休记录 之和)
|
|
|
|
|
+ // $row['生产公休'] = $this->CopsHolidaySum($holidayMap, $row['生产开工日期'], $row['检验日期']);
|
|
|
|
|
+ // $row['检验公休'] = $this->CopsHolidaySum($holidayMap, $row['检验日期'], $row['入仓完工日期']);
|
|
|
|
|
+ // $row['工单公休'] = $this->CopsHolidaySum($holidayMap, $row['接单日期'], $row['入仓完工日期']);
|
|
|
|
|
+
|
|
|
|
|
+ unset($row['计划损耗']);
|
|
|
}
|
|
}
|
|
|
unset($row);
|
|
unset($row);
|
|
|
|
|
|
|
@@ -2789,4 +3028,59 @@ class Decision extends Api
|
|
|
'limit' => $limit,
|
|
'limit' => $limit,
|
|
|
]);
|
|
]);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 读取月度公休记录(人事_班组公休记录),返回 [Y-m-d => 公休天数]
|
|
|
|
|
+ */
|
|
|
|
|
+ private function CopsHolidayMap()
|
|
|
|
|
+ {
|
|
|
|
|
+ $map = [];
|
|
|
|
|
+ $rows = Db::query("SELECT DATE_FORMAT(公休_日期, '%Y-%m-%d') AS d, SUM(公休_天数) AS days
|
|
|
|
|
+ FROM `人事_班组公休记录`
|
|
|
|
|
+ WHERE 公休_日期 IS NOT NULL
|
|
|
|
|
+ GROUP BY d");
|
|
|
|
|
+ foreach ($rows as $r) {
|
|
|
|
|
+ $map[$r['d']] = (float)$r['days'];
|
|
|
|
|
+ }
|
|
|
|
|
+ return $map;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 统计区间 (start, end] 内的公休天数
|
|
|
|
|
+ */
|
|
|
|
|
+ private function CopsHolidaySum(array $map, $start, $end)
|
|
|
|
|
+ {
|
|
|
|
|
+ if (empty($start) || empty($end)) {
|
|
|
|
|
+ return '';
|
|
|
|
|
+ }
|
|
|
|
|
+ $s = strtotime($start);
|
|
|
|
|
+ $e = strtotime($end);
|
|
|
|
|
+ if ($s === false || $e === false || $e <= $s) {
|
|
|
|
|
+ return 0;
|
|
|
|
|
+ }
|
|
|
|
|
+ $sum = 0;
|
|
|
|
|
+ foreach ($map as $d => $days) {
|
|
|
|
|
+ $t = strtotime($d);
|
|
|
|
|
+ if ($t !== false && $t > $s && $t <= $e) {
|
|
|
|
|
+ $sum += $days;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return round($sum, 1);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 两个日期之间的自然日天数
|
|
|
|
|
+ */
|
|
|
|
|
+ private function CopsCycle($start, $end)
|
|
|
|
|
+ {
|
|
|
|
|
+ if (empty($start) || empty($end)) {
|
|
|
|
|
+ return '';
|
|
|
|
|
+ }
|
|
|
|
|
+ $s = strtotime($start);
|
|
|
|
|
+ $e = strtotime($end);
|
|
|
|
|
+ if ($s === false || $e === false) {
|
|
|
|
|
+ return '';
|
|
|
|
|
+ }
|
|
|
|
|
+ return (int)round(($e - $s) / 86400);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|