SelectHouseExport.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace App\Admin\Exports\Content;
  3. use App\Admin\Exports\ViewExport;
  4. use Illuminate\Contracts\View\View;
  5. use Illuminate\Support\Collection;
  6. class SelectHouseExport extends ViewExport
  7. {
  8. /**
  9. * 设置文件名
  10. * @return string
  11. */
  12. public function getFilename(): string
  13. {
  14. return "select_house.xlsx";
  15. }
  16. /**
  17. * 渲染对应的视图
  18. * @param Collection $data 导出的数据
  19. * @return View
  20. */
  21. public function getView(Collection $data): View
  22. {
  23. $res = [];
  24. foreach ($data as $row) {
  25. $result = [];
  26. $result['child'] = '';
  27. $result['id_card'] = '';
  28. $family = empty($row->family) ? '' : json_decode($row->family, true);
  29. if (!empty($family)) {
  30. $child = [];
  31. $id_card = [];
  32. foreach ($family as $v) {
  33. if (strpos($v['relation'], '未成年子女') !== false) {
  34. $child[] = $v['realname'];
  35. $id_card[] = $v['idcard'];
  36. }
  37. }
  38. $result['child'] = implode('/', $child);
  39. $result['id_card'] = implode('/', $id_card);
  40. }
  41. $result['register_no'] = '';
  42. $result['mobile'] = $row->mobile;
  43. $result['marry'] = $row->marry > 1 ? '是' : '否';
  44. $result['select_status'] = $row->select_house_no == 999999 ? '否' : '是';
  45. $res[] = $result;
  46. }
  47. return view('admin.content.export_select_house', ['data' => $res]);
  48. }
  49. }