linwu 2 weken geleden
bovenliggende
commit
c87b58b6c0

+ 120 - 0
app/admin/controller/Officer.php

@@ -0,0 +1,120 @@
+<?php
+
+namespace app\admin\controller;
+
+use app\admin\AdminBaseController;
+use app\common\model\OfficerAnswerModel;
+use app\common\model\OfficerReviewModel;
+
+class Officer extends AdminBaseController
+{
+    public function index()
+    {
+        return view();
+    }
+
+    public function listOfficer()
+    {
+        $list  = OfficerReviewModel::limit(input('limit'))
+            ->page(input('page'))
+            ->select();
+        $count = OfficerReviewModel::count();
+        if ($count == 0) {
+            ajax_return(1, '未查询到数据');
+        }
+        list_return($list, $count);
+    }
+
+    /**
+     * 列表
+     */
+    public function detail()
+    {
+        $id = input('id');
+        if (empty($id)) {
+            return '该测评不存在';
+        }
+
+        return view('', ['id' => $id]);
+    }
+
+    public function listDetail()
+    {
+        $id    = input('id', 0);
+        $list  = OfficerAnswerModel::where('rid', $id)
+            ->order('id', 'desc')
+            ->limit(input('limit'))
+            ->page(input('page'))
+            ->append(['status_text'])
+            ->select();
+        $count = OfficerAnswerModel::count();
+        if ($count == 0) {
+            ajax_return(1, '未查询到数据');
+        }
+        list_return($list, $count);
+    }
+
+    public function export()
+    {
+        $id   = input('id', 0);
+        $list = OfficerAnswerModel::with(['detail'])
+            ->where('rid', $id)
+            ->order('id', 'desc')
+            ->append(['status_text'])
+            ->select();
+
+        if ($list->isEmpty()) {
+            return '暂无人答题';
+        }
+
+        $xlsCell = [
+            ['name', '姓名'],
+            ['mobile', '手机号'],
+            ['sex', '性别'],
+            ['age', '年龄'],
+            ['marry', '婚姻状况'],
+            ['education', '学历'],
+            ['major', '专业'],
+            ['seniority', '工龄'],
+            ['leader', '担任领导的累计年限'],
+            ['industry', '所在行业'],
+            ['company', '所在单位'],
+            ['job', '职位'],
+        ];
+
+        $res = [];
+        foreach ($list as $ak => $answer) {
+            $item              = [];
+            $item['name']      = $answer['name'];
+            $item['mobile']    = $answer['mobile'];
+            $item['sex']       = $answer['sex'];
+            $item['age']       = $answer['age'];
+            $item['marry']     = $answer['marry'];
+            $item['education'] = $answer['education'];
+            $item['major']     = $answer['major'];
+            $item['seniority'] = $answer['seniority'];
+            $item['leader']    = $answer['leader'];
+            $item['industry']  = $answer['industry'];
+            if (empty($answer['company_text'])) {
+                $item['company'] = $answer['company'];
+            } else {
+                $item['company'] = $answer['company'] . "({$answer['company_text']})";
+            }
+            if (empty($answer['job_text'])) {
+                $item['job'] = $answer['job'];
+            } else {
+                $item['job'] = $answer['job'] . "({$answer['job_text']})";
+            }
+            foreach ($answer['detail'] as $k => $v) {
+                $index = 'part_' . $v['no'];
+                if ($ak == 0) {
+                    $xlsCell[] = [$index, $index];
+                }
+                $item[$index] = $v['score'];
+            }
+            $res[] = $item;
+        }
+
+        export_exl("考试明细", $xlsCell, $res);
+    }
+}

+ 59 - 0
app/admin/view/officer/detail.html

@@ -0,0 +1,59 @@
+<style>
+
+</style>
+<div class="layui-fluid">
+    <div class="layui-card">
+        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
+            <button class="layui-btn layuiadmin-btn" data-type="export">导出</button>
+        </div>
+
+        <div class="layui-card-body">
+            <table id="{$lay_table}" lay-filter="{$lay_table}"></table>
+        </div>
+    </div>
+</div>
+
+<script>
+    layui.use(['index', 'admin', 'form', 'table'], function () {
+        const $ = layui.$;
+        const admin = layui.admin;
+        const form = layui.form;
+        const table = layui.table;
+        form.render();
+
+        table.render({
+            elem: '#{$lay_table}',
+            url: "{:url('officer/listDetail')}?id={$id}",
+            cols: [
+                [
+                    {field: 'name', title: '姓名' ,width: 150},
+                    {field: 'mobile', title: '手机号', width: 200},
+                    {field: 'sex', title: '性别', width: 150},
+                    {field: 'age', title: '年龄', width: 150},
+                    {field: 'marry', title: '婚姻状况', width: 150},
+                    {field: 'education', title: '学历', width: 150},
+                    {field: 'major', title: '专业', width: 150},
+                    {field: 'score', title: '总分', width: 150},
+                    {field: 'create_time', title: '提交时间', align: 'center'},
+                ]
+            ],
+            page: true,
+            limit: 50,
+            cellMinWidth: 150,
+            text: '对不起,加载出现异常!'
+        });
+
+        //事件
+        const active = {
+            export: function() {
+                const url = "{:url('officer/export')}?id={$id}";
+                window.open(url);
+            },
+        };
+
+        $('.layui-btn.layuiadmin-btn').on('click', function () {
+            const type = $(this).data('type');
+            active[type] ? active[type].call(this) : '';
+        });
+    });
+</script>

+ 57 - 0
app/admin/view/officer/index.html

@@ -0,0 +1,57 @@
+<style>
+
+</style>
+<div class="layui-fluid">
+    <div class="layui-card">
+
+        <div class="layui-card-body">
+            <table id="{$lay_table}" lay-filter="{$lay_table}"></table>
+            <script type="text/html" id="setTpl">
+                <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="detail">
+                    <i class="layui-icon layui-icon-edit"></i>明细
+                </a>
+            </script>
+        </div>
+    </div>
+</div>
+
+<script>
+    layui.use(['index', 'admin', 'form', 'table'], function () {
+        const $ = layui.$;
+        const admin = layui.admin;
+        const form = layui.form;
+        const table = layui.table;
+        form.render();
+
+        table.render({
+            elem: '#{$lay_table}',
+            url: "{:url('officer/listOfficer')}",
+            cols: [
+                [
+                    {field: 'id', title: 'ID' ,width: 150},
+                    {field: 'name', title: '试卷标题'},
+                    {title: '操作', width: 100, align: 'center', fixed: 'right', toolbar: '#setTpl'}
+                ]
+            ],
+            page: true,
+            limit: 50,
+            cellMinWidth: 150,
+            text: '对不起,加载出现异常!'
+        });
+
+        //监听工具条
+        table.on('tool({$lay_table})', function (obj) {
+            const data = obj.data;
+            if (obj.event === 'detail') {
+                const index = layer.open({
+                    type: 2,
+                    title: '考试明细',
+                    content: "{:url('officer/detail')}?id=" + data.id,
+                    maxmin: true,
+                    area: ['550px', '550px']
+                });
+                layer.full(index);
+            }
+        });
+    });
+</script>

+ 21 - 5
app/common.php

@@ -36,20 +36,21 @@ function array_get($array, $key, $default = null)
  * @param array $expTableData [['a'=>1]]
  * @param array $textValue ['a']
  */
-function export_exl($expTitle, $expCellName, $expTableData, $textValue=[]) {
+function export_exl($expTitle, $expCellName, $expTableData, $textValue = [])
+{
     $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'];
+    $cellName    = get_exl_column_letter(count($expCellName));
     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);
+            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]]);
             }
@@ -65,6 +66,21 @@ function export_exl($expTitle, $expCellName, $expTableData, $textValue=[]) {
 }
 
 
+function get_exl_column_letter($num = 1)
+{
+    $res = [];
+    for ($i = 0; $i < $num; $i++) {
+        $y = ($i / 26);
+        if ($y >= 1) {
+            $y     = intval($y);
+            $res[] = chr($y + 64) . chr($i - $y * 26 + 65);
+        } else {
+            $res[] = chr($i + 65);
+        }
+    }
+
+    return $res;
+}
 
 /**
  * @param string $file
@@ -76,7 +92,7 @@ function export_exl($expTitle, $expCellName, $expTableData, $textValue=[]) {
 function import_exl($file = '', $cell = [], $crop = 0, $sheet = 0)
 {
     $file = iconv("utf-8", "gb2312", $file);   //转码
-    if (empty($file) OR !file_exists($file)) {
+    if (empty($file) or !file_exists($file)) {
         die('file not exists!');
     }
 

+ 4 - 0
app/common/model/OfficerAnswerModel.php

@@ -10,4 +10,8 @@ class OfficerAnswerModel extends BaseModel
     //自动完成
     protected $autoWriteTimestamp = true;
 
+    public function detail()
+    {
+        return $this->hasMany(OfficerAnswerDetailModel::class,'aid','id');
+    }
 }

+ 3 - 0
app/mobile/controller/Officer.php

@@ -46,6 +46,7 @@ class Officer extends MobileBaseController
 
         $officer_answer = OfficerAnswerModel::create($answer);
         $review_title   = OfficerReviewTitleModel::where('rid', $id)->column('option,title', 'no');
+        $score_sum      = 0;
         foreach ($answer_detail as $k => $v) {
             $options = json_decode($review_title[$k]['option'], true);
             $option  = $options[$v];
@@ -56,7 +57,9 @@ class Officer extends MobileBaseController
                 'score'        => $option['score'],
                 'option_title' => $option['title'],
             ]);
+            $score_sum += $option['score'];
         }
+        OfficerAnswerModel::update(['score' => $score_sum], ['id' => $officer_answer['id']]);
 
         ajax_return();
     }

+ 10 - 0
app/mobile/view/officer/answer.html

@@ -69,6 +69,10 @@
         base.active = Vue.ref(0);
         base.onStep = (active) => {
             base.active.value = active;
+            window.scrollTo({
+                top: 0,
+                behavior: 'smooth', // 平滑滚动
+            });
         }
         base.onSubmit = () => {
             for (let i = 0; i < sum; i++) {
@@ -78,7 +82,13 @@
                 }
             }
             base.answer.value.rid = {$id};
+            vant.showLoadingToast({
+                message: '正在提交中...',
+                forbidClick: true,
+                duration: 0,
+            });
             postJson("{:url('officer/answerPost')}",{id:{$id},answer:base.answer.value,answer_detail:base.answer_detail.value}).then((data) => {
+                vant.closeToast();
                 vant.showToast('提交成功');
                 location.href = "{:url('officer/finish')}";
             })