linwu 2 år sedan
förälder
incheckning
5b40b28af2

+ 39 - 2
app/common/Excel.php

@@ -1,10 +1,12 @@
 <?php
+
 namespace app\common;
 
-class Excel{
+class Excel
+{
     public function __construct()
     {
-        include_once (CMF_ROOT.'/extend/Excel/PHPExcel.php');
+        include_once(CMF_ROOT . '/extend/Excel/PHPExcel.php');
     }
 
     public function import($file = '', $cell = [], $crop = 0, $sheet = 0)
@@ -52,4 +54,39 @@ class Excel{
 
         return array_values($data);
     }
+
+    /**
+     * @param $expTitle
+     * @param $expCellName [['a','A']]
+     * @param $expTableData [['a'=>1]]
+     * @param $textValue ['a']
+     */
+    public function export($expTitle, $expCellName, $expTableData, $textValue=[])
+    {
+        $xlsTitle    = iconv('utf-8', 'gb2312', $expTitle); //文件名称
+        $fileName    = $expTitle . date('_YmdHis'); //or $xlsTitle 文件名称可根据自己情况设定
+        $cellNum     = count($expCellName);
+        $dataNum     = count($expTableData);
+        $objPHPExcel = new \PHPExcel();
+        $cellName    = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'AA', 'AB', 'AC', 'AD', 'AE', 'AF', 'AG', 'AH', 'AI', 'AJ', 'AK', 'AL', 'AM', 'AN', 'AO', 'AP', 'AQ', 'AR', 'AS', 'AT', 'AU', 'AV', 'AW', 'AX', 'AY', 'AZ'];
+        for ($i = 0; $i < $cellNum; $i++) {
+            $objPHPExcel->setActiveSheetIndex(0)->setCellValue($cellName[$i] . '1', $expCellName[$i][1]);
+        }
+        // Miscellaneous glyphs, UTF-8
+        for ($i = 0; $i < $dataNum; $i++) {
+            for ($j = 0; $j < $cellNum; $j++) {
+                if (in_array($expCellName[$j][0],$textValue)) {
+                    $objPHPExcel->getActiveSheet(0)->setCellValueExplicit($cellName[$j] . ($i + 2), $expTableData[$i][$expCellName[$j][0]],\PHPExcel_Cell_DataType::TYPE_STRING);
+                } else {
+                    $objPHPExcel->getActiveSheet(0)->setCellValue($cellName[$j] . ($i + 2), $expTableData[$i][$expCellName[$j][0]]);
+                }
+            }
+        }
+        header('pragma:public');
+        header('Content-type:application/vnd.ms-excel;charset=utf-8;name="' . $xlsTitle . '.xls"');
+        header("Content-Disposition:attachment;filename=$fileName.xls"); //attachment新窗口打印inline本窗口打印
+        $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
+        $objWriter->save('php://output');
+        exit;
+    }
 }

+ 55 - 1
app/love/controller/AdminActiveController.php

@@ -11,6 +11,7 @@
 
 namespace app\love\controller;
 
+use app\common\Excel;
 use app\common\Fun;
 use app\love\model\ActiveApplyModel;
 use app\love\model\ActiveModel;
@@ -138,7 +139,7 @@ class AdminActiveController extends AdminBaseController
         foreach ($list as $v) {
             $v['age'] = Fun::getAgeByBirth($v['user']['birthday']);
         }
-        \think\facade\Log::record('sql为:'.ActiveApplyModel::getLastSql());
+
         $page = $list->render();
         $this->assign('list', $list);
         $this->assign('page', $page);
@@ -156,4 +157,57 @@ class AdminActiveController extends AdminBaseController
 
         $this->success('操作成功');
     }
+
+    /**
+     * 报名列表导出
+     */
+    public function applyExport()
+    {
+        $param = $this->request->param();
+
+        $where = [
+            ['active_id', '=', $param['id']],
+        ];
+        if (!empty($param['check_status'])) {
+            $where[] = ['cmf_active_apply.check_status', '=', $param['check_status']];
+        }
+        $sexWhere = [];
+        if (!empty($param['sex'])) {
+            $sexWhere = ['sex'=>$param['sex']];
+        }
+
+        $list  = ActiveApplyModel::hasWhere('user',$sexWhere)->with('user')->where($where)->order('check_status asc')->paginate(10);
+        $data = [];
+        foreach ($list as $v) {
+            $data[] = [
+                'name' => $v['user']['realname'],
+                'sex' => $v['user']['sex_text'],
+                'age' => Fun::getAgeByBirth($v['user']['birthday']),
+                'mobile' => $v['user']['mobile'],
+                'company' => $v['user']['company'],
+                'id_type' => $v['user']['id_type'],
+                'native' => $v['user']['native'],
+                'marry' => $v['user']['marry'],
+                'check_status' => $v['status_text'],
+            ];
+        }
+
+        if (empty($data)) {
+            return '暂无数据';
+        }
+
+        $excel = new Excel();
+        $title = [
+            ['name','姓名'],
+            ['sex','性别'],
+            ['age','年龄'],
+            ['mobile','电话'],
+            ['company','单位'],
+            ['id_type','身份类型'],
+            ['native','籍贯'],
+            ['marry','婚姻状况'],
+            ['check_status','审核状态'],
+        ];
+        $excel->export('报名列表',$title,$data,['mobile']);
+    }
 }

+ 5 - 0
app/love/model/ActiveApplyModel.php

@@ -14,6 +14,11 @@ use think\Model;
 
 class ActiveApplyModel extends Model
 {
+    public function getStatusTextAttr($value, $data)
+    {
+        $status = ['', '待审核', '审核通过','审核不通过'];
+        return $status[$data['check_status']];
+    }
 
     public function user()
     {

+ 13 - 1
public/themes/admin_simpleboot3/love/admin_active/apply_list.html

@@ -5,7 +5,8 @@
     <ul class="nav nav-tabs">
         <li class="active"><a href="javascript:;">报名管理</a></li>
     </ul>
-    <form class="well form-inline margin-top-20" method="post" action="{:url('AdminActive/applyList')}?id={$id}">
+    <form class="well form-inline margin-top-20" method="post" action="{:url('AdminActive/applyList')}">
+        <input type="hidden" name="id" value="{$id}">
         审核状态:
         <select class="form-control" name="check_status" style="width: 140px;">
             <option value='0'>全部</option>
@@ -22,6 +23,9 @@
         <input type="submit" class="btn btn-primary" value="搜索"/>
         <a class="btn btn-danger" href="{:url('AdminActive/applyList')}?id={$id}">清空</a>
     </form>
+    <div class="table-actions">
+        <button class="btn btn-primary btn-sm export">导出</button>
+    </div>
     <form class="js-ajax-form" action="" method="post">
         <table class="table table-hover table-bordered table-list">
             <thead>
@@ -128,6 +132,14 @@
     function detail(id) {
         parent.openIframeLayer("/user/admin_index/show/id/"+id+".html",'详情',{});
     }
+
+    $('.export').click(function(){
+        window.open(
+            '{:url("applyExport")}?'+$(".well").serialize(),
+            '_blank'
+        );
+
+    });
 </script>
 </body>
 </html>