ExportFileService.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652
  1. <?php
  2. namespace App\Service;
  3. use App\Exports\ExportOrder;
  4. use App\Exports\ItemSalaryFTMultipleSheetExport;
  5. use App\Exports\ItemSalarySheetExport;
  6. use App\Exports\ManMonthlyWorkHourMultipleSheetExport;
  7. use App\Exports\MultiSheetExport;
  8. use App\Exports\ProjectDepreciationMultipleSheetExport;
  9. use App\Model\Depart;
  10. use App\Model\PLeaveOverOrder;
  11. use Maatwebsite\Excel\Facades\Excel;
  12. class ExportFileService extends Service
  13. {
  14. public static $filename = "";
  15. //导出的方式 0 选择导出的数据 1 查询后 导出指定的数据(最多每次一千条)
  16. public static $export_type = [
  17. 0,
  18. 1
  19. ];
  20. public function exportAll($data,$user){
  21. if(empty($data['menu_id'])) return [false, 'menu_id不能为空'];
  22. if(empty($data['type'])) return [false, 'type不能为空'];
  23. $function = $data['type'];
  24. $name = $this->fillE($data['type'], $user);
  25. if (! method_exists(self::class, $function)) return [false, "导出方法不存在,请联系开发"];
  26. self::$filename = $name;
  27. $export_type = $data['export_type'] ?? 0;
  28. if(! isset(self::$export_type[$export_type])) return [false,'导出文件方式错误或者不存在'];
  29. if(empty($export_type)){
  30. if(empty($data['id'])) return [false,'请选择导出数据'];
  31. $search = $data;
  32. }else{
  33. if(empty($data['order_search'])) return [false,'搜索条件不能为空'];
  34. $search = $data['order_search'];
  35. if(empty($search['page_index'])) return [false,'请选择导出数据的开始页码'];
  36. if(empty($search['page_size'])) return [false,'请选择导出数据的条数'];
  37. if($search['page_size'] > 5000) return [false,'请选择导出数据的条数每次最多5000条'];
  38. $data['order_search']['menu_id'] = $data['menu_id'];
  39. $search = $data['order_search'];
  40. }
  41. list($status, $return) = $this->$function($search,$user);
  42. if(! $status) return [false, $return];
  43. return [true, $return];
  44. }
  45. public function fillE($type, &$user){
  46. $header = config("excel." . $type) ?? [];
  47. $funcName = $header['name'] ?? "";
  48. // $header_f = "extra_" . $menu_id;
  49. // $service = new TableHeadService();
  50. // if(method_exists($service,$header_f)) $service->$header_f($header_default);
  51. $user['e_header_default'] = $header['array'] ?? [];
  52. return $funcName;
  53. }
  54. private function fillData($data, $column, &$return)
  55. {
  56. // 预先创建包含默认值的键数组
  57. $default = array_fill_keys($column, '');
  58. foreach ($data as $value) {
  59. // 提取交集,并用默认值补充缺失的键
  60. $return[] = array_merge($default, array_intersect_key($value, $default));
  61. }
  62. }
  63. private function fillTotalData($data, $column, &$return){
  64. $tmp = [];
  65. foreach ($column as $value){
  66. $key = $value['key'];
  67. if(! empty($value['sum']) && isset($data[$value['key']])){
  68. $decimals = $col['decimals'] ?? 2;
  69. // $tmp[$value['key']] = $data[$value['key']];
  70. // 用 number_format 格式化输出(保持字符串形式,避免科学计数)
  71. $tmp[$key] = number_format((float)$data[$key], $decimals, '.', '');
  72. }else{
  73. $tmp[$value['key']] = "";
  74. }
  75. }
  76. $return[] = $tmp;
  77. }
  78. public function employee($ergs,$user){
  79. // 导出数据
  80. $return = [];
  81. $header_default = $user['e_header_default'];
  82. $column = array_column($header_default,'export');
  83. $header = array_column($header_default,'value');
  84. $service = new EmployeeService();
  85. $model = $service->employeeCommon($ergs, $user);
  86. $model->chunk(500,function ($data) use(&$return, $service, $column, $user){
  87. $service->fillDataForExport($data, $column, $user, $return);
  88. });
  89. return [true, $this->saveExportData($return,$header)];
  90. }
  91. public function depart($ergs,$user){
  92. // 导出数据
  93. $return = [];
  94. $header_default = $user['e_header_default'];
  95. $column = array_column($header_default,'export');
  96. $header = array_column($header_default,'value');
  97. $service = new EmployeeService();
  98. $model = $service->departCommon($ergs, $user);
  99. $model->chunk(500,function ($data) use(&$return, $service, $column, $user){
  100. $data = $data->toArray();
  101. $list['data'] = $data;
  102. //订单数据
  103. $list = $service->fillDepartList($list, $user, true);
  104. //返回数据
  105. $this->fillData($list['data'], $column, $return);
  106. });
  107. return [true, $this->saveExportData($return,$header)];
  108. }
  109. public function device($ergs,$user){
  110. // 导出数据
  111. $return = [];
  112. $header_default = $user['e_header_default'];
  113. $column = array_column($header_default,'export');
  114. $header = array_column($header_default,'value');
  115. $service = new DeviceService();
  116. $model = $service->deviceCommon($ergs, $user);
  117. $model->chunk(500,function ($data) use(&$return, $service, $column,$ergs, $user){
  118. $data = $data->toArray();
  119. $list['data'] = $data;
  120. //订单数据
  121. $list = $service->fillData($list, $ergs, $user);
  122. //返回数据
  123. $this->fillData($list['data'], $column, $return);
  124. });
  125. return [true, $this->saveExportData($return,$header)];
  126. }
  127. public function item($ergs,$user){
  128. // 导出数据
  129. $return = [];
  130. $header_default = $user['e_header_default'];
  131. $column = array_column($header_default,'export');
  132. $header = array_column($header_default,'value');
  133. $service = new ItemService();
  134. $model = $service->itemCommon($ergs, $user);
  135. $model->chunk(500,function ($data) use(&$return,$column,$service, $user){
  136. // 调用 Service 层的填充方法
  137. $service->fillDataForExport($data, $column, $user, $return);
  138. });
  139. return [true, $this->saveExportData($return,$header)];
  140. }
  141. public function fee($ergs,$user){
  142. // 导出数据
  143. $return = [];
  144. $header_default = $user['e_header_default'];
  145. $column = array_column($header_default,'export');
  146. $header = array_column($header_default,'value');
  147. $service = new FeeService();
  148. $model = $service->feeCommon($ergs, $user);
  149. $model->chunk(500,function ($data) use(&$return, $service, $column, $user){
  150. $data = $data->toArray();
  151. $list['data'] = $data;
  152. //订单数据
  153. $list = $service->fillFeeList($list, $user, true);
  154. //返回数据
  155. $this->fillData($list['data'], $column, $return);
  156. });
  157. return [true, $this->saveExportData($return,$header)];
  158. }
  159. public function monthPwOrder($ergs,$user){
  160. // 导出数据
  161. $return = [];
  162. $header_default = $user['e_header_default'];
  163. $column = array_column($header_default,'export');
  164. $header = array_column($header_default,'value');
  165. $service = new PersonWorkService();
  166. $model = $service->monthlyPwOrderCommon($ergs, $user);
  167. $model->chunk(500,function ($data) use(&$return, $service, $column){
  168. // 直接处理这一批主表数据,将其与详情合并平铺
  169. $service->fillDataForExport($data->toArray(), $column, $return);
  170. });
  171. return [true, $this->saveExportData($return,$header)];
  172. }
  173. public function monthDwOrder($ergs,$user){
  174. // 导出数据
  175. $return = [];
  176. $header_default = $user['e_header_default'];
  177. $column = array_column($header_default,'export');
  178. $header = array_column($header_default,'value');
  179. $service = new DeviceWorkService();
  180. $model = $service->monthlyDwOrderCommon($ergs, $user);
  181. $model->chunk(500,function ($data) use(&$return, $service, $column){
  182. // 直接处理这一批主表数据,将其与详情合并平铺
  183. $service->fillDataForExport($data->toArray(), $column, $return);
  184. });
  185. return [true, $this->saveExportData($return,$header)];
  186. }
  187. public function monthPsOrder($ergs,$user){
  188. // 导出数据
  189. $return = [];
  190. $header_default = $user['e_header_default'];
  191. $column = array_column($header_default,'export');
  192. $header = array_column($header_default,'value');
  193. $service = new PersonSalaryService();
  194. $model = $service->monthlyPsOrderCommon($ergs, $user);
  195. $model->chunk(500,function ($data) use(&$return, $service, $column){
  196. // 直接处理这一批主表数据,将其与详情合并平铺
  197. $service->fillDataForExport($data->toArray(), $column, $return);
  198. });
  199. return [true, $this->saveExportData($return,$header)];
  200. }
  201. public function monthDdOrder($ergs,$user){
  202. // 导出数据
  203. $return = [];
  204. $header_default = $user['e_header_default'];
  205. $column = array_column($header_default,'export');
  206. $header = array_column($header_default,'value');
  207. $service = new DeviceDepreciationService();
  208. $model = $service->monthlyDdOrderCommon($ergs, $user);
  209. $model->chunk(500,function ($data) use(&$return, $service, $column){
  210. // 直接处理这一批主表数据,将其与详情合并平铺
  211. $service->fillDataForExport($data->toArray(), $column, $return);
  212. });
  213. return [true, $this->saveExportData($return,$header)];
  214. }
  215. public function ruleSet($ergs,$user){
  216. // 导出数据
  217. $return = [];
  218. $header_default = $user['e_header_default'];
  219. $column = array_column($header_default,'export');
  220. $header = array_column($header_default,'value');
  221. $service = new RuleSetService();
  222. $model = $service->ruleSetCommon($ergs, $user);
  223. $model->chunk(500,function ($data) use(&$return, $service, $column){
  224. // 直接处理这一批主表数据,将其与详情合并平铺
  225. $service->fillDataForExport($data->toArray(), $column, $return);
  226. });
  227. return [true, $this->saveExportData($return,$header)];
  228. }
  229. public function dailyPwOrder($ergs,$user){
  230. // 导出数据
  231. $return = [];
  232. $header_default = $user['e_header_default'];
  233. $column = array_column($header_default,'export');
  234. $header = array_column($header_default,'value');
  235. $service = new PersonWorkService();
  236. $model = $service->dailyPwOrderCommon($ergs, $user);
  237. $model->chunk(500,function ($data) use(&$return, $service, $column){
  238. // 直接处理这一批主表数据,将其与详情合并平铺
  239. $service->fillDataForExportDaily($data->toArray(), $column, $return);
  240. });
  241. return [true, $this->saveExportData($return,$header)];
  242. }
  243. public function dailyDwOrder($ergs,$user){
  244. // 导出数据
  245. $return = [];
  246. $header_default = $user['e_header_default'];
  247. $column = array_column($header_default,'export');
  248. $header = array_column($header_default,'value');
  249. $service = new DeviceWorkService();
  250. $model = $service->dailyDwOrderCommon($ergs, $user);
  251. $model->chunk(500,function ($data) use(&$return, $service, $column){
  252. // 直接处理这一批主表数据,将其与详情合并平铺
  253. $service->fillDataForExportDaily($data->toArray(), $column, $return);
  254. });
  255. return [true, $this->saveExportData($return,$header)];
  256. }
  257. public function leaveOrder($ergs,$user){
  258. // 导出数据
  259. $return = [];
  260. $header_default = $user['e_header_default'];
  261. $column = array_column($header_default,'export');
  262. $header = array_column($header_default,'value');
  263. $service = new PLeaveOverService();
  264. $ergs['type'] = PLeaveOverOrder::TYPE_ONE;
  265. $model = $service->pLeaveOverCommon($ergs, $user);
  266. $model->chunk(500,function ($data) use(&$return, $service, $column){
  267. // 直接处理这一批主表数据,将其与详情合并平铺
  268. $service->fillDataForExportDaily($data->toArray(), $column, $return);
  269. });
  270. return [true, $this->saveExportData($return,$header)];
  271. }
  272. public function overtimeOrder($ergs,$user){
  273. // 导出数据
  274. $return = [];
  275. $header_default = $user['e_header_default'];
  276. $column = array_column($header_default,'export');
  277. $header = array_column($header_default,'value');
  278. $service = new PLeaveOverService();
  279. $ergs['type'] = PLeaveOverOrder::TYPE_TWO;
  280. $model = $service->pLeaveOverCommon($ergs, $user);
  281. $model->chunk(500,function ($data) use(&$return, $service, $column){
  282. // 直接处理这一批主表数据,将其与详情合并平铺
  283. $service->fillDataForExportDaily($data->toArray(), $column, $return);
  284. });
  285. return [true, $this->saveExportData($return,$header)];
  286. }
  287. public function exportEmployeeSalary($data, $user)
  288. {
  289. $service = new StatisticService();
  290. // 1. 调用你现有的查询方法获取基础数据
  291. list($status, $itemMonthList) = $service->employeeMonthSalaryStatistic($data, $user);
  292. if (!$status) return $itemMonthList; // 返回错误信息
  293. // 2. 提取所有涉及到的唯一项目 (按 Code 排序,保证列顺序固定)
  294. $projects = collect($itemMonthList)->pluck('item_code')->unique()->sort()->values()->toArray();
  295. // 3. 按月份对数据进行分组
  296. $groupedByMonth = collect($itemMonthList)->groupBy('month')->sortKeys();
  297. $exportData = [];
  298. $columnTotals = array_fill(0, count($projects) * 2, 0); // 用于存储每列的合计
  299. $grandTotalSalary = 0; // 总计金额
  300. // 4. 循环每个月,构造行数据
  301. foreach ($groupedByMonth as $month => $items) {
  302. $row = [$month]; // A列:月份
  303. $monthTotalSalary = 0;
  304. // 创建该月项目的映射,方便快速查找
  305. $monthItemsMap = $items->keyBy('item_code');
  306. foreach ($projects as $index => $code) {
  307. $itemDetail = $monthItemsMap->get($code);
  308. $days = $itemDetail['days'] ?? 0;
  309. $salary = $itemDetail['allocated_salary'] ?? 0;
  310. $row[] = $days > 0 ? $days : ''; // 天数列
  311. $row[] = $salary > 0 ? $salary : ''; // 工资列
  312. // 累加合计行(列合计)
  313. $columnTotals[$index * 2] += $days;
  314. $columnTotals[$index * 2 + 1] += $salary;
  315. $monthTotalSalary += $salary;
  316. }
  317. $row[] = $monthTotalSalary; // 最后一列:该月合计工资
  318. $grandTotalSalary += $monthTotalSalary;
  319. $exportData[] = $row;
  320. }
  321. // 5. 构造最后的“合计”行
  322. $totalRow = ['合计'];
  323. foreach ($columnTotals as $val) {
  324. $totalRow[] = $val > 0 ? $val : 0;
  325. }
  326. $totalRow[] = $grandTotalSalary;
  327. $exportData[] = $totalRow;
  328. $file_name = "项目工资统计表_" . date("Y-m-d") . "_". rand(1000,9999);
  329. $filename = $file_name . '.' . 'xlsx';
  330. $bool = Excel::store(new ItemSalarySheetExport($projects, $exportData, Depart::where('id', $user['top_depart_id'])->value('title')),"/public/export/{$filename}", null, 'Xlsx', []);
  331. return [true, $filename];
  332. }
  333. public function exportManMonthlyWorkHour($data, $user)
  334. {
  335. // 1. 获取报表基础数据
  336. $service = new StatisticService();
  337. list($status, $result) = $service->employeeDayHourStatistic($data, $user);
  338. if (!$status) return $result;
  339. $sourceData = collect($result['data']);
  340. // 2. 按月份分组,准备多 Sheet 数据
  341. // 结构:[ '2024-04' => [ 'days' => 30, 'data' => [...] ], ... ]
  342. $monthsData = [];
  343. // 按月分组数据
  344. $groupedByMonth = $sourceData->groupBy(function ($item) {
  345. return date('Y年m月', strtotime($item['order_date']));
  346. });
  347. foreach ($groupedByMonth as $monthName => $monthItems) {
  348. // A. 计算该月总天数
  349. // 转换 '2024年04月' 为 '2024-04' 获取天数
  350. $formatMonth = str_replace(['年', '月'], ['-', ''], $monthName);
  351. $daysInMonth = date('t', strtotime($formatMonth . '-01'));
  352. // B. 进一步按 项目+人员 分组,因为一行显示一个项目一个人的全月工时
  353. $groupedByUserItem = $monthItems->groupBy(function ($item) {
  354. return $item['item_code'] . '_' . $item['employee_id'];
  355. });
  356. $sheetRows = [];
  357. foreach ($groupedByUserItem as $key => $records) {
  358. $first = $records->first();
  359. // 初始化行:前两列是 项目编号 和 姓名
  360. $row = [
  361. $first['item_code'],
  362. $first['employee_name']
  363. ];
  364. // C. 循环 1 号到该月最后一天,填充工时
  365. // 将该员工该项目在这个月的记录转为 日期 => 工时 的映射
  366. $dayMap = $records->keyBy(function($r){
  367. return (int)date('d', strtotime($r['order_date']));
  368. });
  369. for ($d = 1; $d <= $daysInMonth; $d++) {
  370. $workHour = $dayMap->get($d)['total_work_hours'] ?? '';
  371. // 如果工时为 0 或空,按你要求的格式传空字符串
  372. $row[] = ($workHour > 0) ?(float) $workHour : '';
  373. }
  374. $sheetRows[] = $row;
  375. }
  376. $monthsData[$monthName] = [
  377. 'days' => (int)$daysInMonth,
  378. 'data' => $sheetRows
  379. ];
  380. }
  381. $file_name = "人员月工时统计表_" . date("Y-m-d") . "_". rand(1000,9999);
  382. $filename = $file_name . '.' . 'xlsx';
  383. $bool = Excel::store(new ManMonthlyWorkHourMultipleSheetExport($monthsData), "/public/export/{$filename}", null, 'Xlsx', []);
  384. return [true, $filename];
  385. }
  386. public function exportDeviceZj(array $data, $user)
  387. {
  388. $service = new StatisticService();
  389. list($status, $result) = $service->itemDeviceMonthStatistic($data, $user);
  390. if (!$status) return $result;
  391. // 2. 将数据按 [项目编号][月份] 进行分组
  392. // 预期结构:$monthsData['RD01']['months']['2025-01'] = [设备1, 设备2...]
  393. $groupedData = collect($result)->groupBy('item_code');
  394. $finalExportData = [];
  395. foreach ($groupedData as $itemCode => $itemRecords) {
  396. $projectName = $itemRecords->first()['item_title'] ?? '';
  397. // 2. 获取年份(从 order_month 字段提取,如 "2026-01" 取前4位)
  398. $firstMonth = $firstRecord['month'] ?? date('Y-m');
  399. $year = substr($firstMonth, 0, 4);
  400. // 3. 构造新的 Key:年-项目 (例如: 2026-53code)
  401. $newSheetKey = $year . '年度项目' . $itemCode;
  402. // 按月份进一步分组
  403. $monthGroups = $itemRecords->groupBy('month');
  404. $monthsPayload = [];
  405. foreach ($monthGroups as $month => $devices) {
  406. $monthData = [];
  407. foreach ($devices as $dev) {
  408. $monthData[] = [
  409. 'device_name' => $dev['device_title'],
  410. 'original_value' => $dev['device_original'], // 设备原值
  411. 'total_depreciation' => $dev['total_depreciatio'], // 当月总折旧
  412. 'project_hours' => $dev['hours'], // 本项目工时
  413. 'total_hours' => $dev['total_hours'], // 当月总工时
  414. 'ratio' => bcmul($dev['ratio'], 100,2), // 研发工时占比
  415. 'allocated_depreciation' => $dev['allocated_depreciatio'], // 本项目分摊折旧
  416. ];
  417. }
  418. $monthsPayload[$month] = $monthData;
  419. }
  420. // 构造 Sheet 所需结构
  421. $finalExportData[$newSheetKey] = [
  422. 'project_name' => $projectName,
  423. 'months' => $monthsPayload
  424. ];
  425. }
  426. $file_name = "项目设备折旧费用统计表_" . date("Y-m-d") . "_". rand(1000,9999);
  427. $filename = $file_name . '.' . 'xlsx';
  428. $bool = Excel::store(new ProjectDepreciationMultipleSheetExport($finalExportData), "/public/export/{$filename}", null, 'Xlsx', []);
  429. return [true, $filename];
  430. }
  431. public function exportItemSalaryFT(array $data, $user)
  432. {
  433. $service = new StatisticService();
  434. list($status, $result) = $service->itemDaySalaryStatistic($data, $user);
  435. if (!$status) return $result;
  436. $sourceData = collect($result);
  437. $groupedByMonth = $sourceData->groupBy('month');
  438. $monthsData = [];
  439. foreach ($groupedByMonth as $month => $monthRecords) {
  440. // A. 获取本月参与的所有唯一项目编码
  441. $monthProjects = $monthRecords->pluck('item_code')->unique()->sort()->values()->all();
  442. // B. 按人员分组组织数据
  443. $groupedByEmployee = $monthRecords->groupBy('employee_id');
  444. $sheetRows = [];
  445. $index = 1;
  446. // 初始化列合计
  447. $colTotals = [
  448. 'total_salary' => 0,
  449. 'total_min_hours' => 0, // 月总工时合计
  450. 'project_days' => array_fill_keys($monthProjects, 0),
  451. 'project_salary' => array_fill_keys($monthProjects, 0),
  452. 'total_attendance_days' => 0, // 合计工时列的合计
  453. ];
  454. foreach ($groupedByEmployee as $employeeId => $records) {
  455. $first = $records->first();
  456. $empMonthSalary = (float)$first['total_salary'];
  457. $empTotalHours = round((float)$first['total_min'] / 60, 2); // 月总工时(小时)
  458. // 1-4列:序号、姓名、工资、月总工时
  459. $row = [$index++, $first['employee_title'], $empMonthSalary, $empTotalHours];
  460. // 5. 动态项目工时列
  461. $empMap = $records->keyBy('item_code');
  462. $rowProjectDaysSum = 0;
  463. foreach ($monthProjects as $code) {
  464. $days = $empMap->has($code) ? (float)$empMap->get($code)['days'] : 0;
  465. $row[] = $days > 0 ? $days : '';
  466. $rowProjectDaysSum += $days;
  467. $colTotals['project_days'][$code] += $days;
  468. }
  469. // 6. 合计工时列
  470. $row[] = $rowProjectDaysSum;
  471. $colTotals['total_attendance_days'] += $rowProjectDaysSum;
  472. // 7. 动态项目金额列
  473. foreach ($monthProjects as $code) {
  474. $salary = $empMap->has($code) ? (float)$empMap->get($code)['allocated_salary'] : 0;
  475. $row[] = $salary > 0 ? $salary : '';
  476. $colTotals['project_salary'][$code] += $salary;
  477. }
  478. // 8. 总计工资列
  479. $row[] = $empMonthSalary;
  480. // 累加合计
  481. $colTotals['total_salary'] += $empMonthSalary;
  482. $colTotals['total_min_hours'] += $empTotalHours;
  483. $sheetRows[] = $row;
  484. }
  485. // C. 构造合计行
  486. $totalRow = ['合计', '', $colTotals['total_salary'], $colTotals['total_min_hours']];
  487. foreach ($monthProjects as $code) { $totalRow[] = $colTotals['project_days'][$code]; }
  488. $totalRow[] = $colTotals['total_attendance_days'];
  489. foreach ($monthProjects as $code) { $totalRow[] = $colTotals['project_salary'][$code]; }
  490. $totalRow[] = $colTotals['total_salary'];
  491. $sheetRows[] = $totalRow;
  492. $monthsData[$month] = [
  493. 'projects' => $monthProjects,
  494. 'data' => $sheetRows
  495. ];
  496. }
  497. $file_name = "项目工资分摊统计表_" . date("Y-m-d") . "_". rand(1000,9999);
  498. $filename = $file_name . '.xlsx';
  499. Excel::store(
  500. new ItemSalaryFTMultipleSheetExport($monthsData, Depart::where('id', $user['top_depart_id'])->value('title')),
  501. "/public/export/{$filename}"
  502. );
  503. return [true, $filename];
  504. }
  505. public function saveExportData($data, $headers, $type = 'default',$file_name = ''){
  506. if(empty($file_name)) $file_name = self::$filename . "_". date("Y-m-d") . "_". rand(1000,9999);
  507. $filename = $file_name . '.' . 'xlsx';
  508. $bool = Excel::store(new ExportOrder($data,$type,$headers),"/public/export/{$filename}", null, 'Xlsx', []);
  509. return $filename;
  510. }
  511. public function saveExportData2($data,$type = 1,$column,$timeRow, $file_name = ''){
  512. if(empty($file_name)) $file_name = self::$filename . "_". date("Y-m-d") . "_". rand(1000,9999);
  513. $filename = $file_name . '.' . 'xlsx';
  514. \Maatwebsite\Excel\Facades\Excel::store(new MultiSheetExport($data, $type,$column,$timeRow),"/public/export/{$filename}", null, 'Xlsx', []);
  515. return $filename;
  516. }
  517. }