|
|
@@ -371,10 +371,19 @@ class StatisticService extends Service
|
|
|
|
|
|
private function commonRule($data)
|
|
|
{
|
|
|
- if(isset($data['time_range'])){
|
|
|
- $data['month_start'] = $data['time_range'][0] ?? null;
|
|
|
- $data['month_end'] = $data['time_range'][1] ?? null;
|
|
|
+ if(! empty($data['year'])){
|
|
|
+ $return = $this->getYearRangeInfo($data['year']);
|
|
|
+ if(is_null($return)) return [false, '年度格式错误'];
|
|
|
+ list($data['month_start'], $data['month_end']) = $return;
|
|
|
+ }else{
|
|
|
+ if(isset($data['time'])){
|
|
|
+ $start = $this->changeDateToDate($data['time'][0]);
|
|
|
+ $end = $this->changeDateToDate($data['time'][1], true);
|
|
|
+ $data['month_start'] = date("Y-m-d",$start);
|
|
|
+ $data['month_end'] = date("Y-m-d",$end);
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
if (!isset($data['month_start'])) $month_start = date('Y-01-01');
|
|
|
else $month_start = date('Y-m-01', strtotime($data['month_start']));
|
|
|
if (!isset($data['month_end'])) $month_end = date('Y-01-01', strtotime('+1 year', strtotime($month_start)));
|
|
|
@@ -387,6 +396,40 @@ class StatisticService extends Service
|
|
|
return [true, strtotime($month_start), strtotime($month_end)];
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 根据前端 ISO 时间字符串获取该年份的起止日期和时间戳
|
|
|
+ * 适配:2019-12-31T16:00:00.000Z 这种带时区的数据
|
|
|
+ *
|
|
|
+ * @param string $isoStr 前端传来的时间字符串
|
|
|
+ * @return array|null
|
|
|
+ */
|
|
|
+ public function getYearRangeInfo($isoStr)
|
|
|
+ {
|
|
|
+ if (empty($isoStr)) return null;
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 1. 解析 ISO 8601 字符串
|
|
|
+ $date = new \DateTime($isoStr);
|
|
|
+
|
|
|
+ // 2. 强制转为中国时区(PRC),处理 16:00:00Z 这种 UTC 偏移
|
|
|
+ $date->setTimezone(new \DateTimeZone('PRC'));
|
|
|
+
|
|
|
+ // 3. 提取年份
|
|
|
+ $year = $date->format('Y');
|
|
|
+
|
|
|
+ // 4. 构造日期字符串
|
|
|
+ $startDate = $year . "-01-01";
|
|
|
+ $endDate = $year . "-12-31";
|
|
|
+
|
|
|
+ return [
|
|
|
+ 'start_date' => $startDate,
|
|
|
+ 'end_date' => $endDate,
|
|
|
+ ];
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public function employeeAttendanceMonthStatistic($data, $user)
|
|
|
{
|
|
|
//项目编码、项目名称、项目状态、支出类型、允许加计扣除金额合计、人员人工费用、折旧费用、其他费用、前N项小计、其他相关费用合计、委内费用、委外费用、
|