cqp 3 tygodni temu
rodzic
commit
131032a215
1 zmienionych plików z 70 dodań i 4 usunięć
  1. 70 4
      app/Service/ItemService.php

+ 70 - 4
app/Service/ItemService.php

@@ -817,7 +817,7 @@ class ItemService extends Service
         $customer['node_list'] = $this->itemNodeBoard($data, $user);
 
         //文件归档
-        $customer['file_list'] = $this->getNodeFile($data, $user, $customer);
+        $customer['file_list'] = $this->getFile($data, $user, $customer);
 
         return [true, $customer];
     }
@@ -852,7 +852,7 @@ class ItemService extends Service
         return $list;
     }
 
-    public function getNodeFile($data,$user, $item){
+    public function getFile($data,$user, $item){
         $file = ItemFile::where('del_time',0)
             ->where('item_id', $data['id'])
             ->get()->toArray();
@@ -860,6 +860,23 @@ class ItemService extends Service
         $employee_id = array_unique(array_merge_recursive(array_column($file,'crt_id'), array_column($item['custom_fields'],'crt_id')));
         $map = (new EmployeeService())->getEmployeeMap($employee_id);
 
+        $nodeIds = [];
+        $missionIds = [];
+
+        // 分类收集附件对应的来源 ID
+        foreach ($file as $v) {
+            if ($v['from'] == ItemFile::from_two) {
+                $nodeIds[] = $v['item_node_id'];
+            } elseif ($v['from'] == ItemFile::from_three) {
+                $missionIds[] = $v['item_node_mission_id'];
+            }
+        }
+
+        // 批量捞出各自表的名字映射 (Id => Title)
+        $itemMap    = !empty($itemIds) ? Item::where('id', $data['id'])->pluck('title', 'id')->toArray() : [];
+        $nodeMap    = !empty($nodeIds) ? ItemNode::whereIn('id', array_unique($nodeIds))->pluck('title', 'id')->toArray() : [];
+        $missionMap = !empty($missionIds) ? ItemNodeMission::whereIn('id', array_unique($missionIds))->pluck('title', 'id')->toArray() : [];
+
         $return = [];
         if(! empty($item['custom_fields'])){
             foreach ($item['custom_fields'] as $value){
@@ -873,6 +890,7 @@ class ItemService extends Service
                         'type_name_2' => CustomFieldValue::type[CustomFieldValue::type_two],
                         'type' => 'custom_fields',
                         'from' => ItemFile::from_one,
+                        'from_name' => $itemMap[$value['model_id']] ?? "",
                         'crt_name' => $map[$value['crt_id']],
                         'crt_time' => date("Y-m-d", $value['crt_time']),
                         'crt_id' => $value['crt_id'],
@@ -885,6 +903,14 @@ class ItemService extends Service
         if(! empty($file)){
             $fileUploadService = new FileUploadService();
             foreach ($file as $value){
+                $fromName = '';
+                if ($value['from'] == ItemFile::from_one) {
+                    $fromName = $itemMap[$value['item_id']] ?? '';
+                } elseif ($value['from'] == ItemFile::from_two) {
+                    $fromName = $nodeMap[$value['item_node_id']] ?? '';
+                } elseif ($value['from'] == ItemFile::from_three) {
+                    $fromName = $missionMap[$value['item_node_mission_id']] ?? '';
+                }
                 $return[] = [
                     'id' => $value['id'],
                     'url' => $value['url'],
@@ -894,6 +920,7 @@ class ItemService extends Service
                     'type_name_2' => ItemFile::type[$value['type']],
                     'type' => 'item_file',
                     'from' => $value['from'],
+                    'from_name' => $fromName,
                     'crt_name' => $map[$value['crt_id']],
                     'crt_time' => date("Y-m-d", $value['crt_time']),
                     'crt_id' => $value['crt_id'],
@@ -1604,7 +1631,7 @@ class ItemService extends Service
         $customer['mission_list'] = $this->itemMissionBoard($data, $user);
 
         //文件归档
-        $customer['file_list'] = $this->getMissionFile($data, $user, $customer);
+        $customer['file_list'] = $this->getNodeFile($data, $user, $customer);
 
         return [true, $customer];
     }
@@ -1639,7 +1666,7 @@ class ItemService extends Service
         return $list;
     }
 
-    public function getMissionFile($data, $user, $item){
+    public function getNodeFile($data, $user, $item){
         $file = ItemFile::where('del_time',0)
             ->where('item_node_id', $data['id'])
             ->get()->toArray();
@@ -1647,6 +1674,19 @@ class ItemService extends Service
         $employee_id = array_unique(array_merge_recursive(array_column($file,'crt_id'), array_column($item['custom_fields'],'crt_id')));
         $map = (new EmployeeService())->getEmployeeMap($employee_id);
 
+        $missionIds = [];
+
+        // 分类收集附件对应的来源 ID
+        foreach ($file as $v) {
+            if ($v['from'] == ItemFile::from_three) {
+                $missionIds[] = $v['item_node_mission_id'];
+            }
+        }
+
+        // 批量捞出各自表的名字映射 (Id => Title)
+        $nodeMap    = !empty($nodeIds) ? ItemNode::where('id', $data['id'])->pluck('title', 'id')->toArray() : [];
+        $missionMap = !empty($missionIds) ? ItemNodeMission::whereIn('id', array_unique($missionIds))->pluck('title', 'id')->toArray() : [];
+
         $return = [];
         if(! empty($item['custom_fields'])){
             foreach ($item['custom_fields'] as $value){
@@ -1660,6 +1700,7 @@ class ItemService extends Service
                         'type_name_2' => CustomFieldValue::type[CustomFieldValue::type_two],
                         'type' => 'custom_fields',
                         'from' => ItemFile::type_two,
+                        'from_name' => $nodeMap[$value['model_id']] ?? '',
                         'crt_name' => $map[$value['crt_id']],
                         'crt_time' => date("Y-m-d", $value['crt_time']),
                         'crt_id' => $value['crt_id'],
@@ -1672,6 +1713,12 @@ class ItemService extends Service
         if(! empty($file)){
             $fileUploadService = new FileUploadService();
             foreach ($file as $value){
+                $fromName = '';
+                if ($value['from'] == ItemFile::from_two) {
+                    $fromName = $nodeMap[$value['item_node_id']] ?? '';
+                } elseif ($value['from'] == ItemFile::from_three) {
+                    $fromName = $missionMap[$value['item_node_mission_id']] ?? '';
+                }
                 $return[] = [
                     'id' => $value['id'],
                     'url' => $value['url'],
@@ -1681,6 +1728,7 @@ class ItemService extends Service
                     'type_name_2' => ItemFile::type[$value['type']],
                     'type' => 'item_file',
                     'from' => $value['from'],
+                    'from_name' => $fromName,
                     'crt_name' => $map[$value['crt_id']],
                     'crt_time' => date("Y-m-d", $value['crt_time']),
                     'crt_id' => $value['crt_id'],
@@ -2377,6 +2425,18 @@ class ItemService extends Service
         $employee_id = array_unique(array_merge_recursive(array_column($file,'crt_id'), array_column($item['custom_fields'],'crt_id')));
         $map = (new EmployeeService())->getEmployeeMap($employee_id);
 
+        $missionIds = [];
+
+        // 分类收集附件对应的来源 ID
+        foreach ($file as $v) {
+            if ($v['from'] == ItemFile::from_three) {
+                $missionIds[] = $v['item_node_mission_id'];
+            }
+        }
+
+        // 批量捞出各自表的名字映射 (Id => Title)
+        $missionMap = !empty($missionIds) ? ItemNodeMission::whereIn('id', array_unique($missionIds))->pluck('title', 'id')->toArray() : [];
+
         $return = [];
         if(! empty($item['custom_fields'])){
             foreach ($item['custom_fields'] as $value){
@@ -2390,6 +2450,7 @@ class ItemService extends Service
                         'type_name_2' => CustomFieldValue::type[CustomFieldValue::type_two],
                         'type' => 'custom_fields',
                         'from' => ItemFile::type_two,
+                        'from_name' =>$missionMap[$value['model_id']] ?? '',
                         'crt_name' => $map[$value['crt_id']],
                         'crt_time' => date("Y-m-d", $value['crt_time']),
                         'crt_id' => $value['crt_id'],
@@ -2402,6 +2463,10 @@ class ItemService extends Service
         if(! empty($file)){
             $fileUploadService = new FileUploadService();
             foreach ($file as $value){
+                $fromName = '';
+                if ($value['from'] == ItemFile::from_three) {
+                    $fromName = $missionMap[$value['item_node_mission_id']] ?? '';
+                }
                 $return[] = [
                     'id' => $value['id'],
                     'url' => $value['url'],
@@ -2411,6 +2476,7 @@ class ItemService extends Service
                     'type_name_2' => ItemFile::type[$value['type']],
                     'type' => 'item_file',
                     'from' => $value['from'],
+                    'from_name' => $fromName,
                     'crt_name' => $map[$value['crt_id']],
                     'crt_time' => date("Y-m-d", $value['crt_time']),
                     'crt_id' => $value['crt_id'],