cqp 2 ay önce
ebeveyn
işleme
e0676fe9ed

+ 36 - 0
app/Service/ArchiveService.php

@@ -123,4 +123,40 @@ class ArchiveService extends Service
 
         return [true, ''];
     }
+
+    public static function fillIsArchive($months, $user)
+    {
+        // 1. 统一转为数组并去重(避免重复计算)
+        $rawMonths = is_array($months) ? array_unique($months) : [$months];
+
+        // 2. 建立 原始输入 -> 归一化时间戳 的中间映射
+        $lookup = [];
+        foreach ($rawMonths as $rawTime) {
+            $timestamp = is_numeric($rawTime) ? (int)$rawTime : strtotime($rawTime);
+            // 归一化为当月1号用于数据库对比
+            $lookup[$rawTime] = strtotime(date('Y-m-01', $timestamp));
+        }
+
+        // 3. 获取所有需要查询的归一化月份(去重后)
+        $normalizedToQuery = array_unique(array_values($lookup));
+
+        // 4. 批量查询数据库
+        $dbArchived = Archive::where('del_time', 0)
+            ->where('top_depart_id', $user['top_depart_id'])
+            ->whereIn('month', $normalizedToQuery)
+            ->pluck('month')
+            ->toArray();
+
+        // 转换成 Set 结构(以时间戳为键),提高后续查询性能
+        $dbArchivedSet = array_flip($dbArchived);
+
+        // 5. 构建最终 Map:原始时间戳 => 布尔值
+        $archiveMap = [];
+        foreach ($lookup as $rawTime => $normalizedTs) {
+            // 只要归一化后的时间戳在数据库里,原始时间戳对应的状态就是 true
+            $archiveMap[$rawTime] = isset($dbArchivedSet[$normalizedTs]);
+        }
+
+        return $archiveMap;
+    }
 }

+ 6 - 3
app/Service/AuxiliaryAccountService.php

@@ -20,7 +20,7 @@ class AuxiliaryAccountService extends Service
     public function auxiliaryAccountList($data,$user){
         $model = $this->setCommon($data, $user);
         $list = $this->limit($model,'',$data);
-        $list = $this->fillData($list);
+        $list = $this->fillData($list, $user);
 
         return [true, $list];
     }
@@ -43,15 +43,16 @@ class AuxiliaryAccountService extends Service
         return $model;
     }
 
-    public function fillData($data){
+    public function fillData($data, $user){
         if(empty($data['data'])) return $data;
 
         $emp = (new EmployeeService())->getEmployeeMap(array_unique(array_column($data['data'],'crt_id')));
-
+        $map = ArchiveService::fillIsArchive(array_unique(array_column($data['data'],'month')), $user);
         foreach ($data['data'] as $key => $value){
             $data['data'][$key]['crt_time'] = $value['crt_time'] ? date('Y-m-d H:i:s',$value['crt_time']) : '';
             $data['data'][$key]['crt_name'] = $emp[$value['crt_id']] ?? '';
             $data['data'][$key]['month'] =  $value['month'] ? date('Y-m',$value['month']) : '';
+            $data['data'][$key]['is_archive'] = $map[$value['month']] ?? false;
         }
 
         return $data;
@@ -420,6 +421,8 @@ class AuxiliaryAccountService extends Service
         $customer = $customer->toArray();
         $customer['crt_name'] = Employee::where('id',$customer['crt_id'])->value('title');
         $customer['crt_time'] =$this->utcTime($customer['crt_time']);
+        $map = ArchiveService::fillIsArchive($customer['month'], $user);
+        $customer['is_archive'] = $map[$customer['month']] ?? false;
         $customer['month'] =$this->utcTime($customer['month']);
 
         $details = $this->getDetail($data['id']);

+ 7 - 2
app/Service/DeviceDepreciationService.php

@@ -155,6 +155,8 @@ class DeviceDepreciationService extends Service
         $customer = $customer->toArray();
         $customer['crt_name'] = Employee::where('id',$customer['crt_id'])->value('title');
         $customer['crt_time'] = $customer['crt_time'] ? date("Y-m-d H:i:s",$customer['crt_time']): '';
+        $map = ArchiveService::fillIsArchive($customer['month'], $user);
+        $customer['is_archive'] = $map[$customer['month']] ?? false;
         $customer['month'] = $customer['month'] ? date("Y-m",$customer['month']): '';
 
         $details = $this->getDetail($data['id']);
@@ -190,7 +192,7 @@ class DeviceDepreciationService extends Service
     public function monthlyDdOrderList($data,$user){
         $model = $this->monthlyDdOrderCommon($data, $user);
         $list = $this->limit($model,'',$data);
-        $list = $this->fillData($list);
+        $list = $this->fillData($list, $user);
 
         return [true, $list];
     }
@@ -233,14 +235,17 @@ class DeviceDepreciationService extends Service
         return [true, ''];
     }
 
-    public function fillData($data){
+    public function fillData($data, $user){
         if(empty($data['data'])) return $data;
 
         $emp = (new EmployeeService())->getEmployeeMap(array_unique(array_column($data['data'],'crt_id')));
+        $map = ArchiveService::fillIsArchive(array_unique(array_column($data['data'],'month')), $user);
+
         foreach ($data['data'] as $key => $value){
             $data['data'][$key]['crt_time'] = $value['crt_time'] ? date('Y-m-d H:i:s',$value['crt_time']) : '';
             $data['data'][$key]['month'] = $value['month'] ? date('Y-m',$value['month']) : '';
             $data['data'][$key]['crt_name'] = $emp[$value['crt_id']] ?? '';
+            $data['data'][$key]['is_archive'] = $map[$value['month']] ?? false;
         }
 
         return $data;

+ 12 - 3
app/Service/DeviceWorkService.php

@@ -165,6 +165,8 @@ class DeviceWorkService extends Service
         $customer = $customer->toArray();
         $customer['crt_name'] = Employee::where('id',$customer['crt_id'])->value('title');
         $customer['crt_time'] = $customer['crt_time'] ? date("Y-m-d H:i:s",$customer['crt_time']): '';
+        $map = ArchiveService::fillIsArchive($customer['month'], $user);
+        $customer['is_archive'] = $map[$customer['month']] ?? false;
         $customer['month'] = $customer['month'] ? date("Y-m",$customer['month']): '';
 
         $details = $this->getDetail($data['id']);
@@ -299,14 +301,17 @@ class DeviceWorkService extends Service
         return [true, ''];
     }
 
-    public function fillData($data){
+    public function fillData($data, $user){
         if(empty($data['data'])) return $data;
 
         $emp = (new EmployeeService())->getEmployeeMap(array_unique(array_column($data['data'],'crt_id')));
+        $map = ArchiveService::fillIsArchive(array_unique(array_column($data['data'],'month')), $user);
+
         foreach ($data['data'] as $key => $value){
             $data['data'][$key]['crt_time'] = $value['crt_time'] ? date('Y-m-d H:i:s',$value['crt_time']) : '';
             $data['data'][$key]['month'] = $value['month'] ? date('Y-m',$value['month']) : '';
             $data['data'][$key]['crt_name'] = $emp[$value['crt_id']] ?? '';
+            $data['data'][$key]['is_archive'] = $map[$value['month']] ?? false;
         }
 
         return $data;
@@ -535,6 +540,8 @@ class DeviceWorkService extends Service
         $item = Item::where('id', $customer['item_id'])->first();
         $customer['item_title'] = $item->title;
         $customer['item_code'] = $item->code;
+        $map = ArchiveService::fillIsArchive($customer['order_time'], $user);
+        $customer['is_archive'] = $map[$customer['order_time']] ?? false;
         $customer['order_time'] = $customer['order_time'] ? date("Y-m-d",$customer['order_time']): '';
 
         $details = $this->getDetailDaily($data['id']);
@@ -578,7 +585,7 @@ class DeviceWorkService extends Service
     public function dailyDwOrderList($data,$user){
         $model = $this->dailyDwOrderCommon($data, $user);
         $list = $this->limit($model,'',$data);
-        $list = $this->fillDataDaily($list);
+        $list = $this->fillDataDaily($list, $user);
 
         return [true, $list];
     }
@@ -688,11 +695,12 @@ class DeviceWorkService extends Service
         return [true, ''];
     }
 
-    public function fillDataDaily($data){
+    public function fillDataDaily($data, $user){
         if(empty($data['data'])) return $data;
 
         $emp = (new EmployeeService())->getEmployeeMap(array_unique(array_column($data['data'],'crt_id')));
         $item = (new ItemService())->getItemMap(array_unique(array_column($data['data'],'item_id')));
+        $map = ArchiveService::fillIsArchive(array_unique(array_column($data['data'],'month')), $user);
         foreach ($data['data'] as $key => $value){
             $data['data'][$key]['crt_time'] = $value['crt_time'] ? date('Y-m-d H:i:s',$value['crt_time']) : '';
             $data['data'][$key]['order_time'] = $value['order_time'] ? date('Y-m-d',$value['order_time']) : '';
@@ -700,6 +708,7 @@ class DeviceWorkService extends Service
             $item_tmp = $item[$value['item_id']] ?? [];
             $data['data'][$key]['item_title'] = $item_tmp['title'] ?? '';
             $data['data'][$key]['item_code'] = $item_tmp['code'] ?? '';
+            $data['data'][$key]['is_archive'] = $map[$value['order_time']] ?? false;
         }
 
         return $data;

+ 6 - 2
app/Service/ExpenseClaimsService.php

@@ -16,7 +16,7 @@ class ExpenseClaimsService extends Service
     {
         $model = $this->expenseClaimsSetCommon($data, $user);
         $list = $this->limit($model, '', $data);
-        $list = $this->fillData($list);
+        $list = $this->fillData($list, $user);
 
         return [true, $list];
     }
@@ -40,16 +40,18 @@ class ExpenseClaimsService extends Service
         return $model;
     }
 
-    public function fillData($data)
+    public function fillData($data, $user)
     {
         if (empty($data['data'])) return $data;
 
         $emp = (new EmployeeService())->getEmployeeMap(array_unique(array_column($data['data'], 'crt_id')));
+        $map = ArchiveService::fillIsArchive(array_unique(array_column($data['data'],'month')), $user);
 
         foreach ($data['data'] as $key => $value) {
             $data['data'][$key]['crt_time'] = $value['crt_time'] ? date('Y-m-d H:i:s', $value['crt_time']) : '';
             $data['data'][$key]['crt_name'] = $emp[$value['crt_id']] ?? '';
             $data['data'][$key]['month'] = $value['month'] ? date('Y-m', $value['month']) : '';
+            $data['data'][$key]['is_archive'] = $map[$value['month']] ?? false;
         }
 
         return $data;
@@ -266,6 +268,8 @@ class ExpenseClaimsService extends Service
         $customer = $customer->toArray();
         $customer['crt_name'] = Employee::where('id', $customer['crt_id'])->value('title');
         $customer['crt_time'] = $customer['crt_time'] ? date("Y-m-d H:i:s", $customer['crt_time']) : '';
+        $map = ArchiveService::fillIsArchive($customer['month'], $user);
+        $customer['is_archive'] = $map[$customer['month']] ?? false;
         $customer['month'] = $this->UtcTime($customer['month']);
         $details = $this->getDetail($data, $user);
         $customer["details"] = $details;

+ 7 - 2
app/Service/PLeaveOverService.php

@@ -165,6 +165,8 @@ class PLeaveOverService extends Service
         $customer['type_title'] = PLeaveOverOrder::Type[$customer['type']] ?? "";
         $customer['crt_name'] = Employee::where('id',$customer['crt_id'])->value('title');
         $customer['crt_time'] = $customer['crt_time'] ? date("Y-m-d H:i:s",$customer['crt_time']): '';
+        $map = ArchiveService::fillIsArchive($customer['order_time'], $user);
+        $customer['is_archive'] = $map[$customer['order_time']] ?? false;
         $customer['order_time'] = $customer['order_time'] ? date("Y-m-d",$customer['order_time']): '';
 
         $details = $this->getDetail($data['id']);
@@ -201,7 +203,7 @@ class PLeaveOverService extends Service
     public function pLeaveOverList($data,$user){
         $model = $this->pLeaveOverCommon($data, $user);
         $list = $this->limit($model,'',$data);
-        $list = $this->fillData($list);
+        $list = $this->fillData($list, $user);
 
         return [true, $list];
     }
@@ -387,15 +389,18 @@ class PLeaveOverService extends Service
         return [true, ''];
     }
 
-    public function fillData($data){
+    public function fillData($data, $user){
         if(empty($data['data'])) return $data;
 
         $emp = (new EmployeeService())->getEmployeeMap(array_unique(array_column($data['data'],'crt_id')));
+        $map = ArchiveService::fillIsArchive(array_unique(array_column($data['data'],'month')), $user);
+
         foreach ($data['data'] as $key => $value){
             $data['data'][$key]['crt_time'] = $value['crt_time'] ? date('Y-m-d H:i:s',$value['crt_time']) : '';
             $data['data'][$key]['order_time'] = $value['order_time'] ? date('Y-m-d',$value['order_time']) : '';
             $data['data'][$key]['crt_name'] = $emp[$value['crt_id']] ?? '';
             $data['data'][$key]['type_title'] = PLeaveOverOrder::Type[$value['type']] ?? "";
+            $data['data'][$key]['is_archive'] = $map[$value['order_time']] ?? false;
         }
 
         return $data;

+ 8 - 3
app/Service/RuleSetService.php

@@ -208,9 +208,11 @@ class RuleSetService extends Service
             ->first();
         if(empty($customer)) return [false,'规则配置单不存在或已被删除'];
         $customer = $customer->toArray();
-        $customer['month']  = ! empty($customer['month']) ? date("Y-m", $customer['month']) : "";
         $customer['crt_name'] = Employee::where('id',$customer['crt_id'])->value('title');
         $customer['crt_time'] = $customer['crt_time'] ? date("Y-m-d H:i:s",$customer['crt_time']): '';
+        $map = ArchiveService::fillIsArchive($customer['month'], $user);
+        $customer['is_archive'] = $map[$customer['month']] ?? false;
+        $customer['month']  = ! empty($customer['month']) ? date("Y-m", $customer['month']) : "";
 
         $details = $this->getDetail($data['id']);
         $customer = array_merge($customer, $details);
@@ -245,7 +247,7 @@ class RuleSetService extends Service
     public function ruleSetList($data,$user){
         $model = $this->ruleSetCommon($data, $user);
         $list = $this->limit($model,'',$data);
-        $list = $this->fillData($list);
+        $list = $this->fillData($list, $user);
 
         return [true, $list];
     }
@@ -340,14 +342,17 @@ class RuleSetService extends Service
         return [true, ''];
     }
 
-    public function fillData($data){
+    public function fillData($data, $user){
         if(empty($data['data'])) return $data;
 
         $emp = (new EmployeeService())->getEmployeeMap(array_unique(array_column($data['data'],'crt_id')));
+        $map = ArchiveService::fillIsArchive(array_unique(array_column($data['data'],'month')), $user);
+
         foreach ($data['data'] as $key => $value){
             $data['data'][$key]['crt_time'] = $value['crt_time'] ? date('Y-m-d H:i:s',$value['crt_time']) : '';
             $data['data'][$key]['month'] = $value['month'] ? date('Y-m',$value['month']) : '';
             $data['data'][$key]['crt_name'] = $emp[$value['crt_id']] ?? '';
+            $data['data'][$key]['is_archive'] = $map[$value['month']] ?? false;
         }
 
         return $data;