cqp vor 1 Monat
Ursprung
Commit
854ca43f6a

+ 1 - 1
app/Exports/CompanyRdActivityExport.php

@@ -53,7 +53,7 @@ class CompanyRdActivityExport implements WithEvents, WithTitle
                         $index + 1,                 // A 序号
                         $index + 1,                 // A 序号
                         $row['activity_name']??'',  // B 研发活动名称
                         $row['activity_name']??'',  // B 研发活动名称
                         $row['time_range']??'',     // C 起止时间
                         $row['time_range']??'',     // C 起止时间
-                        '自有技术',                  // D 技术来源
+                        $row['from'],                  // D 技术来源
                         $row['budget']??0,          // E 研发预算
                         $row['budget']??0,          // E 研发预算
                         $row['actual_spending']??0, // F 实际支出
                         $row['actual_spending']??0, // F 实际支出
                         $row['tech_area']??'',      // G 技术领域
                         $row['tech_area']??'',      // G 技术领域

+ 7 - 7
app/Exports/ProjectStaffExport.php

@@ -34,7 +34,7 @@ class ProjectStaffExport implements WithEvents, WithTitle
 
 
                 // --- 1. 第一行:主标题(包含红色提示文字) ---
                 // --- 1. 第一行:主标题(包含红色提示文字) ---
                 $sheet->mergeCells('A1:I1');
                 $sheet->mergeCells('A1:I1');
-                $sheet->setCellValue('A1', "项目研发活动人员情况表    (这个主要针对项目中体现的人员情况)");
+                $sheet->setCellValue('A1', "项目研发活动人员情况表");
                 $sheet->getStyle('A1')->getFont()->setBold(true)->setSize(14);
                 $sheet->getStyle('A1')->getFont()->setBold(true)->setSize(14);
 
 
                 // --- 2. 第二行:表头设置 ---
                 // --- 2. 第二行:表头设置 ---
@@ -44,7 +44,7 @@ class ProjectStaffExport implements WithEvents, WithTitle
                     'C' => '学历',
                     'C' => '学历',
                     'D' => '专业',
                     'D' => '专业',
                     'E' => '职称',
                     'E' => '职称',
-                    'F' => "项目角色(不同\n行业不同定义)", // 提示列
+                    'F' => "项目", // 提示列
                     'G' => '项目角色',
                     'G' => '项目角色',
                     'H' => '部门',
                     'H' => '部门',
                     'I' => '承担职责'
                     'I' => '承担职责'
@@ -62,13 +62,13 @@ class ProjectStaffExport implements WithEvents, WithTitle
                 foreach ($this->data as $index => $row) {
                 foreach ($this->data as $index => $row) {
                     $sheet->fromArray([
                     $sheet->fromArray([
                         $index + 1,
                         $index + 1,
-                        $row['name'] ?? '',
+                        $row['title'] ?? '',
                         $row['education'] ?? '',
                         $row['education'] ?? '',
                         $row['major'] ?? '',
                         $row['major'] ?? '',
-                        $row['title'] ?? '',
-                        $row['role_desc'] ?? '', // 此列通常显示:项目负责人/技术负责人等
-                        $row['role_name'] ?? '',
-                        $row['dept'] ?? '',
+                        $row['p_title'] ?? '',
+                        $row['item_title'] ?? '',
+                        $row['item_role'] ?? '',
+                        $row['depart_title'] ?? '',
                         $row['duty'] ?? '',
                         $row['duty'] ?? '',
                     ], null, "A{$currentRow}");
                     ], null, "A{$currentRow}");
                     $currentRow++;
                     $currentRow++;

+ 33 - 28
app/Exports/TechnicalStaffExport.php

@@ -7,6 +7,7 @@ use Maatwebsite\Excel\Concerns\WithTitle;
 use Maatwebsite\Excel\Events\AfterSheet;
 use Maatwebsite\Excel\Events\AfterSheet;
 use PhpOffice\PhpSpreadsheet\Style\Alignment;
 use PhpOffice\PhpSpreadsheet\Style\Alignment;
 use PhpOffice\PhpSpreadsheet\Style\Border;
 use PhpOffice\PhpSpreadsheet\Style\Border;
+use PhpOffice\PhpSpreadsheet\Cell\DataType;
 
 
 class TechnicalStaffExport implements WithEvents, WithTitle
 class TechnicalStaffExport implements WithEvents, WithTitle
 {
 {
@@ -27,12 +28,12 @@ class TechnicalStaffExport implements WithEvents, WithTitle
         return [
         return [
             AfterSheet::class => function (AfterSheet $event) {
             AfterSheet::class => function (AfterSheet $event) {
                 $sheet = $event->sheet->getDelegate();
                 $sheet = $event->sheet->getDelegate();
-                $lastCol = 'I'; // A 到 I 共9列
+                $lastCol = 'H';
                 $dataCount = count($this->data);
                 $dataCount = count($this->data);
-                $lastRow = 2 + $dataCount; // 标题1行 + 表头1行 + 数据行
+                $lastRow = 2 + $dataCount;
 
 
                 // --- 1. 第一行:主标题 ---
                 // --- 1. 第一行:主标题 ---
-                $sheet->mergeCells('A1:I1');
+                $sheet->mergeCells('A1:H1');
                 $sheet->setCellValue('A1', "企业研究开发科技人员情况表");
                 $sheet->setCellValue('A1', "企业研究开发科技人员情况表");
                 $sheet->getStyle('A1')->getFont()->setBold(true)->setSize(16);
                 $sheet->getStyle('A1')->getFont()->setBold(true)->setSize(16);
 
 
@@ -45,26 +46,31 @@ class TechnicalStaffExport implements WithEvents, WithTitle
                     'E' => '专业',
                     'E' => '专业',
                     'F' => '职称/职业资格',
                     'F' => '职称/职业资格',
                     'G' => '部门/岗位',
                     'G' => '部门/岗位',
-                    'H' => '在职、临聘、兼职',
+                    'H' => '聘用类型',
                 ];
                 ];
                 foreach ($headers as $col => $title) {
                 foreach ($headers as $col => $title) {
                     $sheet->setCellValue("{$col}2", $title);
                     $sheet->setCellValue("{$col}2", $title);
                 }
                 }
-                $sheet->getStyle('A2:I2')->getFont()->setBold(true);
+                $sheet->getStyle('A2:H2')->getFont()->setBold(true);
 
 
-                // --- 3. 填充数据 (从第3行开始) ---
+                // --- 3. 填充数据 (解决科学计数法关键) ---
                 $currentRow = 3;
                 $currentRow = 3;
                 foreach ($this->data as $index => $row) {
                 foreach ($this->data as $index => $row) {
-                    $sheet->fromArray([
-                        $index + 1,                   // 序号
-                        $row['name'] ?? '',           // 姓名
-                        $row['id_card'] ?? '',        // 身份证号
-                        $row['education'] ?? '',      // 学历
-                        $row['major'] ?? '',          // 专业
-                        $row['title_level'] ?? '',    // 职称/职业资格
-                        $row['department_job'] ?? '', // 部门/岗位
-                        $row['employment_type'] ?? '',// 聘用类型
-                    ], null, "A{$currentRow}");
+                    // 序号、姓名正常填充
+                    $sheet->setCellValue("A{$currentRow}", $index + 1);
+                    $sheet->setCellValue("B{$currentRow}", $row['name'] ?? '');
+
+                    // 【关键点】显式设置身份证列为文本格式 (Explicitly set as String)
+                    $idCard = $row['id_card'] ?? '';
+                    $sheet->setCellValueExplicit("C{$currentRow}", $idCard, DataType::TYPE_STRING);
+
+                    // 其他字段
+                    $sheet->setCellValue("D{$currentRow}", $row['education'] ?? '');
+                    $sheet->setCellValue("E{$currentRow}", $row['major'] ?? '');
+                    $sheet->setCellValue("F{$currentRow}", $row['title_level'] ?? '');
+                    $sheet->setCellValue("G{$currentRow}", $row['department_job'] ?? '');
+                    $sheet->setCellValue("H{$currentRow}", $row['employment_type'] ?? '');
+
                     $currentRow++;
                     $currentRow++;
                 }
                 }
 
 
@@ -77,18 +83,17 @@ class TechnicalStaffExport implements WithEvents, WithTitle
                 ]);
                 ]);
 
 
                 // --- 5. 设置行高与列宽 ---
                 // --- 5. 设置行高与列宽 ---
-                $sheet->getRowDimension(1)->setRowHeight(40); // 主标题
-                $sheet->getRowDimension(2)->setRowHeight(30); // 表头
-
-                // 根据图片内容调整列宽
-                $sheet->getColumnDimension('A')->setWidth(8);  // 序号
-                $sheet->getColumnDimension('B')->setWidth(12); // 姓名
-                $sheet->getColumnDimension('C')->setWidth(25); // 身份证
-                $sheet->getColumnDimension('D')->setWidth(12); // 学历
-                $sheet->getColumnDimension('E')->setWidth(15); // 专业
-                $sheet->getColumnDimension('F')->setWidth(25); // 职称
-                $sheet->getColumnDimension('G')->setWidth(25); // 部门
-                $sheet->getColumnDimension('H')->setWidth(18); // 类型
+                $sheet->getRowDimension(1)->setRowHeight(40);
+                $sheet->getRowDimension(2)->setRowHeight(30);
+
+                $sheet->getColumnDimension('A')->setWidth(8);
+                $sheet->getColumnDimension('B')->setWidth(12);
+                $sheet->getColumnDimension('C')->setWidth(30); // 身份证列加宽
+                $sheet->getColumnDimension('D')->setWidth(12);
+                $sheet->getColumnDimension('E')->setWidth(15);
+                $sheet->getColumnDimension('F')->setWidth(25);
+                $sheet->getColumnDimension('G')->setWidth(25);
+                $sheet->getColumnDimension('H')->setWidth(18);
 
 
                 // --- 6. 全表加细边框 ---
                 // --- 6. 全表加细边框 ---
                 $sheet->getStyle("A1:{$lastCol}{$lastRow}")->getBorders()->getAllBorders()->setBorderStyle(Border::BORDER_THIN);
                 $sheet->getStyle("A1:{$lastCol}{$lastRow}")->getBorders()->getAllBorders()->setBorderStyle(Border::BORDER_THIN);

+ 38 - 0
app/Http/Controllers/Api/StatisticController.php

@@ -106,5 +106,43 @@ class StatisticController extends BaseController
     }
     }
 
 
 
 
+    public function enterpriseRdStatistic(Request $request)
+    {
+        $service = new StatisticService();
+        $user = $request->userData;
+        list($status,$data) = $service->enterpriseRdStatistic($request->all(),$user);
+
+        if($status){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+    }
+
+    public function enterpriseRdManStatistic(Request $request)
+    {
+        $service = new StatisticService();
+        $user = $request->userData;
+        list($status,$data) = $service->enterpriseRdManStatistic($request->all(),$user);
+
+        if($status){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+    }
+
+    public function enterpriseRdItemStatistic(Request $request)
+    {
+        $service = new StatisticService();
+        $user = $request->userData;
+        list($status,$data) = $service->enterpriseRdItemStatistic($request->all(),$user);
+
+        if($status){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+    }
 
 
 }
 }

+ 17 - 0
app/Model/DataScopeBaseModel.php

@@ -17,6 +17,23 @@ class DataScopeBaseModel extends Model
     //根据公司过滤
     //根据公司过滤
     public function scopeTopClear($query, $user, $search)
     public function scopeTopClear($query, $user, $search)
     {
     {
+        $top_depart_id = "top_depart_id";
+
+        // 获取当前查询的表名或别名(这样无论你起什么别名 i 还是 item_details 都能自适应)
+        $table = $query->getQuery()->from;
+
+        // 如果 $table 里包含 " as ",说明有别名,截取别名部分
+        if (strpos($table, ' as ') !== false) {
+            $segments = explode(' as ', $table);
+            $table = trim(end($segments));
+
+            $top_depart_id = $table . '.top_depart_id';
+        }
+
+        $query->where($top_depart_id, $user['top_depart_id']);
+
+        return $query;
+
         $query->where('top_depart_id', $user['top_depart_id']);
         $query->where('top_depart_id', $user['top_depart_id']);
 
 
         return $query;
         return $query;

+ 1 - 0
app/Model/Employee.php

@@ -12,6 +12,7 @@ class Employee extends DataScopeBaseModel
     const UPDATED_AT = 'upd_time';
     const UPDATED_AT = 'upd_time';
     protected $dateFormat = 'U';
     protected $dateFormat = 'U';
     public static $field = ['number','mobile','title','id','is_admin', 'account', 'crt_time', 'state', 'education', 'major', 'id_card','p_title','sex', 'entrust_type', 'man_type', 'position'];
     public static $field = ['number','mobile','title','id','is_admin', 'account', 'crt_time', 'state', 'education', 'major', 'id_card','p_title','sex', 'entrust_type', 'man_type', 'position'];
+    public static $report_field = ['title','id', 'state', 'education', 'major', 'id_card','p_title', 'position'];
     const SPECIAL_ADMIN = 1;
     const SPECIAL_ADMIN = 1;
     const USE = 1;
     const USE = 1;
     const NOT_USE = 2;
     const NOT_USE = 2;

+ 1 - 0
app/Model/Item.php

@@ -13,6 +13,7 @@ class Item extends DataScopeBaseModel
     const employee_column = "crt_id";
     const employee_column = "crt_id";
 
 
     public static $field = ['title','id','code','start_time','end_time','mark','crt_id','crt_time','state','budget','charge_id','item_attribute','field'];
     public static $field = ['title','id','code','start_time','end_time','mark','crt_id','crt_time','state','budget','charge_id','item_attribute','field'];
+    public static $report_field_1 = ['title','id','code','start_time','end_time','mark','budget','field'];
 
 
     const TYPE_ONE = 1;
     const TYPE_ONE = 1;
     const TYPE_TWO = 2;
     const TYPE_TWO = 2;

+ 122 - 0
app/Service/ExportFileService.php

@@ -8,8 +8,10 @@ use App\Exports\ItemSalarySheetExport;
 use App\Exports\ManMonthlyWorkHourMultipleSheetExport;
 use App\Exports\ManMonthlyWorkHourMultipleSheetExport;
 use App\Exports\MultiSheetExport;
 use App\Exports\MultiSheetExport;
 use App\Exports\ProjectDepreciationMultipleSheetExport;
 use App\Exports\ProjectDepreciationMultipleSheetExport;
+use App\Exports\ProjectStaffExport;
 use App\Exports\ResearchExpenseMultipleSheetExport;
 use App\Exports\ResearchExpenseMultipleSheetExport;
 use App\Model\Depart;
 use App\Model\Depart;
+use App\Model\Employee;
 use App\Model\PLeaveOverOrder;
 use App\Model\PLeaveOverOrder;
 use Maatwebsite\Excel\Facades\Excel;
 use Maatwebsite\Excel\Facades\Excel;
 
 
@@ -948,6 +950,126 @@ class ExportFileService extends Service
         return [true, $filename];
         return [true, $filename];
     }
     }
 
 
+    //业研究开发活动汇总表
+    public function exportEnterpriseRdStatistic(array $data, $user)
+    {
+        $service = new StatisticService();
+        list($status, $result) = $service->enterpriseRdStatistic($data, $user);
+        if (!$status) return [false, '获取统计数据失败'];
+
+        $exportData = [];
+        $totalBudget = 0;   // 预算总计累加器
+        $totalActual = 0;   // 支出总计累加器
+        foreach ($result as $row) {
+            $budget = (float)($row['budget'] ?? 0);
+            $actual = (float)($row['actual_expenditure'] ?? 0);
+
+            $totalBudget = bcadd($totalBudget, $budget, 2);
+            $totalActual = bcadd($totalActual, $actual, 2);
+
+            $exportData[] = [
+                'activity_name'   => $row['title'] ?? '',           // 研发活动名称
+                'time_range'      => $row['time_range'] ?? '',      // 起止时间
+                'from'      => $row['from'] ?? '自有技术',      // 起止时间
+                'budget'          => $budget,  // 研发预算
+                'actual_spending' => $actual, // 实际支出
+                'tech_area'       => $row['tech_field'] ?? '',      // 技术领域 (对应数据库字段)
+                'remark'          => $row['mark'] ?? '',          // 备注
+            ];
+        }
+        $exportData[] = [
+            'activity_name'   => '',
+            'time_range'      => '',
+            'from'      => '',
+            'budget'          => $totalBudget,
+            'actual_spending' => $totalActual,
+            'tech_area'       => '',
+            'remark'          => '',
+        ];
+
+        $file_name = "企业研究开发活动汇总表_" . date("YmdHis");
+        $filename = $file_name . '.xlsx';
+        $relative_path = "public/export/{$filename}";
+
+        \Maatwebsite\Excel\Facades\Excel::store(
+            new \App\Exports\CompanyRdActivityExport($exportData),
+            $relative_path
+        );
+
+        return [true, $filename];
+    }
+
+    //企业研究开发科技人员情况表
+    public function exportEnterpriseRdManStatistic(array $data, $user)
+    {
+        $service = new StatisticService();
+        list($status, $result) = $service->enterpriseRdManStatistic($data, $user);
+
+        if (!$status) return [false, '获取人员统计数据失败'];
+
+        // 2. 映射数据到导出类需要的字段格式
+        $exportData = [];
+        foreach ($result as $row) {
+            $exportData[] = [
+                'name'            => $row['title'] ?? '',          // 姓名 (对应模型里的 title 字段)
+                'id_card'         => $row['id_card'] ?? '',        // 身份证号码
+                'education'       => Employee::Education[$row['education']] ?? "", // 学历
+                'major'           => $row['major'] ?? '',          // 专业
+                'title_level'     => $row['p_title'] ?? '',    // 职称/职业资格
+                'department_job'  => $row['position_new'] ?? '',       // 部门/岗位
+                'employment_type' => Employee::State_Type[$row['state']] ?? "", // 聘用类型
+            ];
+        }
+
+        // 3. 定义文件名和路径
+        $file_name = "企业研究开发科技人员情况表_" . date("YmdHis");
+        $filename = $file_name . '.xlsx';
+        $relative_path = "public/export/{$filename}";
+
+        \Maatwebsite\Excel\Facades\Excel::store(
+            new \App\Exports\TechnicalStaffExport($exportData),
+            $relative_path
+        );
+
+        return [true, $filename];
+    }
+
+    //项目研发活动人员情况表
+    public function exportEnterpriseRdItemStatistic(array $data, $user)
+    {
+        $service = new StatisticService();
+        list($status, $result) = $service->enterpriseRdItemStatistic($data, $user);
+
+        if (!$status) return [false, '获取统计数据失败'];
+
+        // 2. 映射数据到导出类需要的字段格式
+        $exportData = [];
+        foreach ($result as $row) {
+            $exportData[] = [
+                'title'            => $row['title'] ?? '',          // 姓名 (对应模型里的 title 字段)
+                'education'       => Employee::Education[$row['education']] ?? "", // 学历
+                'major'           => $row['major'] ?? '',          // 专业
+                'p_title'     => $row['p_title'] ?? '',    // 职称/职业资格
+                'item_title'  => $row['item_title'] ?? '',       // 项目
+                'item_role'  => $row['item_role'] ?? '',       // 项目角色
+                'depart_title'  => $row['depart_title'] ?? '',       // 部门
+                'duty' => $row['duty'] ?? "", // 职责
+            ];
+        }
+
+        // 3. 定义文件名和路径
+        $file_name = "项目研发活动人员情况表_" . date("YmdHis");
+        $filename = $file_name . '.xlsx';
+        $relative_path = "public/export/{$filename}";
+
+        \Maatwebsite\Excel\Facades\Excel::store(
+            new \App\Exports\ProjectStaffExport($exportData),
+            $relative_path
+        );
+
+        return [true, $filename];
+    }
+
     public function saveExportData($data, $headers, $type = 'default',$file_name = ''){
     public function saveExportData($data, $headers, $type = 'default',$file_name = ''){
         if(empty($file_name)) $file_name = self::$filename . "_". date("Y-m-d") . "_". rand(1000,9999);
         if(empty($file_name)) $file_name = self::$filename . "_". date("Y-m-d") . "_". rand(1000,9999);
         $filename =  $file_name . '.' . 'xlsx';
         $filename =  $file_name . '.' . 'xlsx';

+ 128 - 0
app/Service/StatisticService.php

@@ -7,9 +7,12 @@ use App\Model\DailyDwOrderDetails;
 use App\Model\DailyPwOrderDetails;
 use App\Model\DailyPwOrderDetails;
 use App\Model\Device;
 use App\Model\Device;
 use App\Model\Employee;
 use App\Model\Employee;
+use App\Model\EmployeeDepartPermission;
+use App\Model\EmployeeRole;
 use App\Model\ExpenseClaimsDetails;
 use App\Model\ExpenseClaimsDetails;
 use App\Model\Fee;
 use App\Model\Fee;
 use App\Model\Item;
 use App\Model\Item;
+use App\Model\ItemDetails;
 use App\Model\MonthlyDdOrder;
 use App\Model\MonthlyDdOrder;
 use App\Model\MonthlyDdOrderDetails;
 use App\Model\MonthlyDdOrderDetails;
 use App\Model\MonthlyPsOrder;
 use App\Model\MonthlyPsOrder;
@@ -1418,5 +1421,130 @@ class StatisticService extends StatisticCommonService
         return [true, $item_month_list];
         return [true, $item_month_list];
     }
     }
 
 
+    public function enterpriseRdStatistic($data, $user){
+        $model = Item::TopClear($user,$data);
+        $model = $model->where('del_time',0)
+            ->select(Item::$report_field_1)
+            ->orderby('id', 'desc');
 
 
+        if(! empty($data['title'])) $model->where('title', 'LIKE', '%'.$data['title'].'%');
+        if(! empty($data['code'])) $model->where('code', 'LIKE', '%'.$data['code'].'%');
+        if(! empty($data['state'])) $model->where('state', $data['state']);
+
+        $list = $model->get()->toArray();
+        $list = $this->fillEnterpriseRdStatistic($list, $data, $user);
+
+        return [true, $list];
+    }
+
+    private function fillEnterpriseRdStatistic($list, $data, $user){
+        //项目实际支出 项目费用单
+        $expense = ExpenseClaimsDetails::Clear($user, $data);
+        $expense_map = $expense->where('del_time', 0)
+            ->whereIn('item_id', array_unique(array_column($list,'id')))
+            ->selectRaw('item_id, SUM(amount) as total_amount')
+            ->groupBy('item_id')
+            ->pluck('total_amount', 'item_id') // 这一步直接生成 item_id => total_amount 结构
+            ->toArray();
+
+        foreach ($list as $key => $value){
+            $list[$key]['actual_expenditure'] = $expense_map[$value['id']] ?? 0;
+            $start_time = $value['start_time'] ? date('Y-m-d', $value['start_time']) : '';
+            $end_time = $value['end_time'] ? date('Y-m-d', $value['end_time']) : '';
+            $list[$key]['time_range'] = $start_time . ' ' . $end_time;
+        }
+
+        return $list;
+    }
+
+    public function enterpriseRdManStatistic($data, $user){
+        $model = Employee::TopClear($user,$data);
+        $model = $model->where('del_time',0)
+            ->where('is_admin', '<>', Employee::IS_ADMIN_TWO)
+            ->select(Employee::$report_field)
+            ->orderBy('id','desc');
+
+        if(! empty($data['id_card'])) $model->where('id_card', 'LIKE', '%'.$data['id_card'].'%');
+        if(! empty($data['title'])) $model->where('title', 'LIKE', '%'.$data['title'].'%');
+        if(! empty($data['state'])) $model->where('state', $data['state']);
+        if(isset($data['education'])) $model->where('education', $data['education']);
+
+        $list = $model->get()->toArray();
+        $list = $this->fillEnterpriseRdManStatistic($list, $data, $user);
+
+        return [true, $list];
+    }
+
+    private function fillEnterpriseRdManStatistic($list, $data, $user){
+        $man = EmployeeDepartPermission::from('employee_depart_permission as a')
+            ->join('depart as b', 'b.id', '=', 'a.depart_id')
+            ->whereIn('a.employee_id', array_unique(array_column($list,'id')))
+            ->select('a.employee_id', 'b.title')
+            ->get()->toArray();
+        $man_map = [];
+        foreach ($man as $value){
+            if(isset($man_map[$value['employee_id']])){
+                $man_map[$value['employee_id']] .= ',' . $value['title'];
+            }else{
+                $man_map[$value['employee_id']] = $value['title'];
+            }
+        }
+
+        foreach ($list as $key => $value){
+            $depart_title = $man_map[$value['id']] ?? "";
+            $list[$key]['position_new'] = $depart_title . '/' . $value['position'];
+        }
+
+        return $list;
+    }
+
+    public function enterpriseRdItemStatistic($data, $user){
+        // 1. 先声明表名和别名
+        $model = ItemDetails::from('item_details as i');
+        // 2. 再调用 TopClear
+        $model = $model->TopClear($user, $data);
+        $model = $model->from('item_details as i')
+            ->where('i.del_time', 0)
+            ->where('i.type', ItemDetails::type_one);
+        $model = $model->leftJoin('employee as e', 'i.data_id', '=', 'e.id');
+
+        $fields = ['e.id', 'e.title', 'e.education', 'e.major','e.p_title','i.item_id'];
+
+        $list = $model->select($fields)
+            ->orderBy('i.id', 'desc')
+            ->get()
+            ->toArray();
+
+        $list = $this->fillEnterpriseRdItemStatistic($list, $data, $user);
+
+        return [true, $list];
+    }
+
+    private function fillEnterpriseRdItemStatistic($list, $data, $user){
+        $man = EmployeeDepartPermission::from('employee_depart_permission as a')
+            ->join('depart as b', 'b.id', '=', 'a.depart_id')
+            ->whereIn('a.employee_id', array_unique(array_column($list,'id')))
+            ->select('a.employee_id', 'b.title')
+            ->get()->toArray();
+        $man_map = [];
+        foreach ($man as $value){
+            if(isset($man_map[$value['employee_id']])){
+                $man_map[$value['employee_id']] .= ',' . $value['title'];
+            }else{
+                $man_map[$value['employee_id']] = $value['title'];
+            }
+        }
+
+        $item_map = Item::whereIn('id',array_unique(array_column($list,'item_id')))
+            ->pluck('title','id')
+            ->toArray();
+        foreach ($list as $key => $value){
+            $depart_title = $man_map[$value['id']] ?? "";
+            $list[$key]['depart_title'] = $depart_title;
+            $item_title = $item_map[$value['item_id']] ?? "";
+            $list[$key]['item_title'] = $item_title;
+        }
+
+        return $list;
+    }
 }
 }

+ 7 - 0
routes/api.php

@@ -214,6 +214,13 @@ Route::group(['middleware'=> ['checkLogin']],function ($route){
     $route->any('employeeAttendanceMonthStatistic', 'Api\StatisticController@employeeAttendanceMonthStatistic');
     $route->any('employeeAttendanceMonthStatistic', 'Api\StatisticController@employeeAttendanceMonthStatistic');
     ///年度研发支出辅助账汇总表(年)
     ///年度研发支出辅助账汇总表(年)
     $route->any('auxiliaryStatistic', 'Api\StatisticController@auxiliaryStatistic');
     $route->any('auxiliaryStatistic', 'Api\StatisticController@auxiliaryStatistic');
+    //企业研发开发活动汇总表
+    $route->any('enterpriseRdStatistic', 'Api\StatisticController@enterpriseRdStatistic');
+    //企业研究开发科技人员情况表
+    $route->any('enterpriseRdManStatistic', 'Api\StatisticController@enterpriseRdManStatistic');
+    //企业研发开发活动汇总表
+    $route->any('enterpriseRdItemStatistic', 'Api\StatisticController@enterpriseRdItemStatistic');
+
 
 
 
 
     //首页BI数据
     //首页BI数据