Browse Source

增加导出功能

linwu 3 years ago
parent
commit
0b280e68cf

+ 6 - 1
app/Admin/Controllers/Content/BuyHouseJcController.php

@@ -2,6 +2,7 @@
 
 namespace App\Admin\Controllers\Content;
 
+use App\Admin\Exports\Content\HouseApplyJcExport;
 use App\Http\Controllers\Controller;
 use App\Models\TalentHouse;
 use App\Models\TalentHouseApply;
@@ -43,7 +44,7 @@ class BuyHouseJcController extends Controller
     {
         $grid = new Grid(new TalentHouseApply());
 
-        $grid->model()->with('house')->where('type', 2)->where('is_back', 2)->where('is_draft', 2)->orderBy('rs_check_status', 'ASC');
+        $grid->model()->with(['house','idcard'])->where('type', 2)->where('is_back', 2)->where('is_draft', 2)->orderBy('rs_check_status', 'ASC');
 
         $status_text = $this->status;
         $grid->id('ID');
@@ -75,6 +76,10 @@ class BuyHouseJcController extends Controller
                 }
             }, '状态', 'status')->radio($status_option);
         });
+
+        $grid->disableExport(false); //显示导出按钮
+        $grid->exporter(new HouseApplyJcExport()); //传入自己在第1步创建的导出类
+
         return $grid;
     }
 

+ 6 - 1
app/Admin/Controllers/Content/BuyHouseRsController.php

@@ -2,6 +2,7 @@
 
 namespace App\Admin\Controllers\Content;
 
+use App\Admin\Exports\Content\HouseApplyRsExport;
 use App\Http\Controllers\Controller;
 use App\Models\TalentHouse;
 use App\Models\TalentHouseApply;
@@ -43,7 +44,7 @@ class BuyHouseRsController extends Controller
     {
         $grid = new Grid(new TalentHouseApply());
 
-        $grid->model()->with('house')->where('type', 1)->where('is_back', 2)->where('is_draft', 2)->orderBy('rs_check_status', 'ASC');
+        $grid->model()->with(['house','idcard'])->where('type', 1)->where('is_back', 2)->where('is_draft', 2)->orderBy('rs_check_status', 'ASC');
 
         $status_text = $this->status;
         $grid->id('ID');
@@ -75,6 +76,10 @@ class BuyHouseRsController extends Controller
                 }
             }, '状态', 'status')->radio($status_option);
         });
+
+        $grid->disableExport(false); //显示导出按钮
+        $grid->exporter(new HouseApplyRsExport()); //传入自己在第1步创建的导出类
+
         return $grid;
     }
 

+ 6 - 1
app/Admin/Controllers/Content/BuyHouseZjController.php

@@ -2,6 +2,7 @@
 
 namespace App\Admin\Controllers\Content;
 
+use App\Admin\Exports\Content\HouseApplyZjExport;
 use App\Http\Controllers\Controller;
 use App\Models\TalentHouse;
 use App\Models\TalentHouseApply;
@@ -43,7 +44,7 @@ class BuyHouseZjController extends Controller
     {
         $grid = new Grid(new TalentHouseApply());
 
-        $grid->model()->with('house')->where('is_back',2)->where('rs_check_status',2)->orderBy('zj_check_status', 'ASC');
+        $grid->model()->with(['house','idcard'])->where('is_back',2)->where('rs_check_status',2)->orderBy('zj_check_status', 'ASC');
 
         $status_text = $this->status;
         $grid->id('ID');
@@ -75,6 +76,10 @@ class BuyHouseZjController extends Controller
                 }
             }, '状态', 'status')->radio($status_option);
         });
+
+        $grid->disableExport(false); //显示导出按钮
+        $grid->exporter(new HouseApplyZjExport()); //传入自己在第1步创建的导出类
+
         return $grid;
     }
 

+ 6 - 1
app/Admin/Controllers/Content/BuyHouseZrController.php

@@ -2,6 +2,7 @@
 
 namespace App\Admin\Controllers\Content;
 
+use App\Admin\Exports\Content\HouseApplyZrExport;
 use App\Http\Controllers\Controller;
 use App\Models\TalentHouse;
 use App\Models\TalentHouseApply;
@@ -43,7 +44,7 @@ class BuyHouseZrController extends Controller
     {
         $grid = new Grid(new TalentHouseApply());
 
-        $grid->model()->with('house')->where('is_back',2)->where('zj_check_status',2)->orderBy('zr_check_status', 'ASC');
+        $grid->model()->with(['house','idcard'])->where('is_back',2)->where('zj_check_status',2)->orderBy('zr_check_status', 'ASC');
 
         $status_text = $this->status;
         $grid->id('ID');
@@ -75,6 +76,10 @@ class BuyHouseZrController extends Controller
                 }
             }, '状态', 'status')->radio($status_option);
         });
+
+        $grid->disableExport(false); //显示导出按钮
+        $grid->exporter(new HouseApplyZrExport()); //传入自己在第1步创建的导出类
+
         return $grid;
     }
 

+ 53 - 0
app/Admin/Exports/Content/HouseApplyJcExport.php

@@ -0,0 +1,53 @@
+<?php
+
+namespace App\Admin\Exports\Content;
+
+use App\Admin\Exports\ViewExport;
+use Illuminate\Contracts\View\View;
+use Illuminate\Support\Collection;
+
+class HouseApplyJcExport extends ViewExport
+{
+    /**
+     * 设置文件名
+     * @return string
+     */
+    public function getFilename(): string
+    {
+        return "house_apply.xlsx";
+    }
+
+    /**
+     * 渲染对应的视图
+     * @param Collection $data 导出的数据
+     * @return View
+     */
+    public function getView(Collection $data): View
+    {
+        $status = ['未知', '待审核', '审核通过', '审核驳回'];
+        $marry  = ['未知', '未婚', '已婚', '离异', '丧偶'];
+        foreach ($data as $row) {
+            $family = empty($row->family) ? '' : json_decode($row->family, true);
+            if (!empty($family)) {
+                $relation = [];
+                $child    = [];
+                $id_card  = [];
+                foreach ($family as $v) {
+                    $relation[] = $v['relation'];
+                    $child[]    = $v['realname'];
+                    $id_card[]  = $v['idcard'];
+                }
+                $row['relation']         = implode('/', $relation);
+                $row['relation_name']    = implode('/', $child);
+                $row['relation_id_card'] = implode('/', $id_card);
+            }
+
+            $row['status_text']   = $status[$row['rs_check_status']];
+            $row['check_time']    = $row['rs_check_time'];
+            $row['check_comment'] = $row['rs_check_comment'];
+            $row['marry_text']    = $marry[$row['marry']];
+        }
+
+        return view('admin.content.export_house_apply', ['data' => $data]);
+    }
+}

+ 53 - 0
app/Admin/Exports/Content/HouseApplyRsExport.php

@@ -0,0 +1,53 @@
+<?php
+
+namespace App\Admin\Exports\Content;
+
+use App\Admin\Exports\ViewExport;
+use Illuminate\Contracts\View\View;
+use Illuminate\Support\Collection;
+
+class HouseApplyRsExport extends ViewExport
+{
+    /**
+     * 设置文件名
+     * @return string
+     */
+    public function getFilename(): string
+    {
+        return "house_apply.xlsx";
+    }
+
+    /**
+     * 渲染对应的视图
+     * @param Collection $data 导出的数据
+     * @return View
+     */
+    public function getView(Collection $data): View
+    {
+        $status = ['未知', '待审核', '审核通过', '审核驳回'];
+        $marry  = ['未知', '未婚', '已婚', '离异', '丧偶'];
+        foreach ($data as $row) {
+            $family = empty($row->family) ? '' : json_decode($row->family, true);
+            if (!empty($family)) {
+                $relation = [];
+                $child    = [];
+                $id_card  = [];
+                foreach ($family as $v) {
+                    $relation[] = $v['relation'];
+                    $child[]    = $v['realname'];
+                    $id_card[]  = $v['idcard'];
+                }
+                $row['relation']         = implode('/', $relation);
+                $row['relation_name']    = implode('/', $child);
+                $row['relation_id_card'] = implode('/', $id_card);
+            }
+
+            $row['status_text']   = $status[$row['rs_check_status']];
+            $row['check_time']    = $row['rs_check_time'];
+            $row['check_comment'] = $row['rs_check_comment'];
+            $row['marry_text']    = $marry[$row['marry']];
+        }
+
+        return view('admin.content.export_house_apply', ['data' => $data]);
+    }
+}

+ 53 - 0
app/Admin/Exports/Content/HouseApplyZjExport.php

@@ -0,0 +1,53 @@
+<?php
+
+namespace App\Admin\Exports\Content;
+
+use App\Admin\Exports\ViewExport;
+use Illuminate\Contracts\View\View;
+use Illuminate\Support\Collection;
+
+class HouseApplyZjExport extends ViewExport
+{
+    /**
+     * 设置文件名
+     * @return string
+     */
+    public function getFilename(): string
+    {
+        return "house_apply.xlsx";
+    }
+
+    /**
+     * 渲染对应的视图
+     * @param Collection $data 导出的数据
+     * @return View
+     */
+    public function getView(Collection $data): View
+    {
+        $status = ['未知', '待审核', '审核通过', '审核驳回'];
+        $marry  = ['未知', '未婚', '已婚', '离异', '丧偶'];
+        foreach ($data as $row) {
+            $family = empty($row->family) ? '' : json_decode($row->family, true);
+            if (!empty($family)) {
+                $relation = [];
+                $child    = [];
+                $id_card  = [];
+                foreach ($family as $v) {
+                    $relation[] = $v['relation'];
+                    $child[]    = $v['realname'];
+                    $id_card[]  = $v['idcard'];
+                }
+                $row['relation']         = implode('/', $relation);
+                $row['relation_name']    = implode('/', $child);
+                $row['relation_id_card'] = implode('/', $id_card);
+            }
+
+            $row['status_text']   = $status[$row['zj_check_status']];
+            $row['check_time']    = $row['zj_check_time'];
+            $row['check_comment'] = $row['zj_check_comment'];
+            $row['marry_text']    = $marry[$row['marry']];
+        }
+
+        return view('admin.content.export_house_apply', ['data' => $data]);
+    }
+}

+ 53 - 0
app/Admin/Exports/Content/HouseApplyZrExport.php

@@ -0,0 +1,53 @@
+<?php
+
+namespace App\Admin\Exports\Content;
+
+use App\Admin\Exports\ViewExport;
+use Illuminate\Contracts\View\View;
+use Illuminate\Support\Collection;
+
+class HouseApplyZrExport extends ViewExport
+{
+    /**
+     * 设置文件名
+     * @return string
+     */
+    public function getFilename(): string
+    {
+        return "house_apply.xlsx";
+    }
+
+    /**
+     * 渲染对应的视图
+     * @param Collection $data 导出的数据
+     * @return View
+     */
+    public function getView(Collection $data): View
+    {
+        $status = ['未知', '待审核', '审核通过', '审核驳回'];
+        $marry  = ['未知', '未婚', '已婚', '离异', '丧偶'];
+        foreach ($data as $row) {
+            $family = empty($row->family) ? '' : json_decode($row->family, true);
+            if (!empty($family)) {
+                $relation = [];
+                $child    = [];
+                $id_card  = [];
+                foreach ($family as $v) {
+                    $relation[] = $v['relation'];
+                    $child[]    = $v['realname'];
+                    $id_card[]  = $v['idcard'];
+                }
+                $row['relation']         = implode('/', $relation);
+                $row['relation_name']    = implode('/', $child);
+                $row['relation_id_card'] = implode('/', $id_card);
+            }
+
+            $row['status_text']   = $status[$row['zr_check_status']];
+            $row['check_time']    = $row['zr_check_time'];
+            $row['check_comment'] = $row['zr_check_comment'];
+            $row['marry_text']    = $marry[$row['marry']];
+        }
+
+        return view('admin.content.export_house_apply', ['data' => $data]);
+    }
+}

+ 86 - 0
resources/views/admin/content/export_house_apply.blade.php

@@ -0,0 +1,86 @@
+<html xmlns:o="urn:schemas-microsoft-com:office:office"
+      xmlns:x="urn:schemas-microsoft-com:office:excel"
+      xmlns="http://www.w3.org/TR/REC-html40">
+
+<head>
+    <meta http-equiv=Content-Type content="text/html; charset=utf-8">
+    <meta name=ProgId content=Excel.Sheet>
+    <meta name=Generator content="Microsoft Excel 15">
+    <style>
+        table {
+            mso-displayed-decimal-separator: "\.";
+            mso-displayed-thousand-separator: "\,";
+        }
+        .title {
+            font-weight:700;
+            font-size:20px;
+            text-align: center;
+        }
+        th {
+            color:red;
+        }
+        td {
+            text-align: center;
+            vnd.ms-excel.numberformat:@;
+        }
+    </style>
+</head>
+
+<body>
+
+<div align=center x:publishsource="Excel">
+    <table border=1 cellpadding=0 cellspacing=0 style='border-collapse:collapse;table-layout:fixed;'>
+        <tr>
+            <th>房源名称</th>
+            <th>姓名</th>
+            <th>联系电话</th>
+            <th>证件号</th>
+            <th>籍贯</th>
+            <th>电子邮箱</th>
+            <th>人才层次</th>
+            <th>人才证有效期</th>
+            <th>人才标签</th>
+            <th>人才认定条件</th>
+            <th>婚姻状态</th>
+            <th>未年成子女数量</th>
+            <th>家庭成员(关系)</th>
+            <th>家庭成员(姓名)</th>
+            <th>家庭成员(证件号)</th>
+            <th>工作单位</th>
+            <th>所属街道</th>
+            <th>家庭住房情况</th>
+            <th>住房政策</th>
+            <th>审核状态</th>
+            <th>审核时间</th>
+            <th>审核备注</th>
+        </tr>
+        @foreach($data as $v)
+            <tr>
+                <td>{{$v['house']['name']}}</td>
+                <td>{{$v['name']}}</td>
+                <td>{{$v['mobile']}}</td>
+                <td>{{$v['idcard']['id_card']}}</td>
+                <td>{{$v['native']}}</td>
+                <td>{{$v['email']}}</td>
+                <td>{{$v['talent_level']}}</td>
+                <td>{{$v['talent_card_validity']}}</td>
+                <td>{{$v['talent_tags']}}</td>
+                <td>{{$v['talent_condition']}}</td>
+                <td>{{$v['marry_text']}}</td>
+                <td>{{$v['child_num']}}</td>
+                <td>{{$v['relation']}}</td>
+                <td>{{$v['relation_name']}}</td>
+                <td>{{$v['relation_id_card']}}</td>
+                <td>{{$v['company']}}</td>
+                <td>{{$v['street']}}</td>
+                <td>{{$v['house_condition']}}</td>
+                <td>{{$v['house_policy']}}</td>
+                <td>{{$v['status_text']}}</td>
+                <td>{{$v['check_time']}}</td>
+                <td>{{$v['check_comment']}}</td>
+            </tr>
+        @endforeach
+    </table>
+</div>
+</body>
+</html>