cqp 2 месяцев назад
Родитель
Сommit
00b59c66f8
3 измененных файлов с 52 добавлено и 9 удалено
  1. 4 4
      app/Service/ExpenseClaimsService.php
  2. 2 2
      app/Service/Service.php
  3. 46 3
      app/Service/StatisticService.php

+ 4 - 4
app/Service/ExpenseClaimsService.php

@@ -249,13 +249,13 @@ class ExpenseClaimsService extends Service
         $fee_ids = collect($data)->pluck('fee_id')->unique()->values()->all();
 
         $item = Item::Clear($user, $data);
-        $item_key_list = $item->wherein('id',$item_ids)->pluck('title','id');
+        $item_key_list = $item->whereIn('id',$item_ids)->pluck('title','id');
 
-        $item = Employee::Clear($user, $data);
-        $employee_key_list = $item->wherein('id',$employee_ids)->pluck('title','id');
+        $item = Employee::TopClear($user, $data);
+        $employee_key_list = $item->whereIn('id',$employee_ids)->pluck('title','id');
 
         $item = Fee::Clear($user, $data);
-        $fee_key_list = $item->wherein('id',$fee_ids)->pluck('title','id');
+        $fee_key_list = $item->whereIn('id',$fee_ids)->pluck('title','id');
 
         $fileUploadService = new FileUploadService();
         foreach ($data as &$v) {

+ 2 - 2
app/Service/Service.php

@@ -49,9 +49,9 @@ class Service
                     break;
                 case 'in':
                     if (is_array($data[$word])) {
-                        $db = $db->wherein($words, $data[$word]);
+                        $db = $db->whereIn($words, $data[$word]);
                     } else {
-                        $db = $db->wherein($words, explode(',', $data[$word]));
+                        $db = $db->whereIn($words, explode(',', $data[$word]));
                     }
 
                     break;

+ 46 - 3
app/Service/StatisticService.php

@@ -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项小计、其他相关费用合计、委内费用、委外费用、