审查视图

application/admin/controller/Dashboard.php 8.2 KB
王智 authored
1 2 3 4
<?php

namespace app\admin\controller;
王智 authored
5
use think\Db;
王智 authored
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
use app\common\controller\Backend;
use think\Config;

/**
 * 控制台
 *
 * @icon fa fa-dashboard
 * @remark 用于展示当前系统中的统计数据、统计报表及重要实时数据
 */
class Dashboard extends Backend
{

    /**
     * 查看
     */
    public function index()
    {
        $seventtime = \fast\Date::unixtime('day', -7);
王智 authored
24
        $paylist = $createlist = [];
王智 authored
25
        for ($i = 0; $i < 7; $i++) {
王智 authored
26
            $day = date("Y-m-d", $seventtime + ($i * 86400));
王智 authored
27
            $createlist[$day] = mt_rand(20, 200);
王智 authored
28 29 30 31 32 33 34 35
            $paylist[$day] = mt_rand(1, mt_rand(1, $createlist[$day]));
        }
        $hooks = config('addons.hooks');
        $uploadmode = isset($hooks['upload_config_init']) && $hooks['upload_config_init'] ? implode(',', $hooks['upload_config_init']) : 'local';
        $addonComposerCfg = ROOT_PATH . '/vendor/karsonzhang/fastadmin-addons/composer.json';
        Config::parse($addonComposerCfg, "json", "composer");
        $config = Config::get("composer");
        $addonVersion = isset($config['version']) ? $config['version'] : __('Unknown');
王智 authored
36 37 38 39
        //月 起止时间戳
        $start_time = mktime(0, 0, 0, date('m'), 1, date('Y'));
        $end_time = mktime(23, 59, 59, date('m'), date('t'), date('Y'));
        $map['createtime'] = ['between', [$start_time, $end_time]];
王智 authored
40
        //报修总量
王智 authored
41 42 43
        $BaoxiuArr = Db::name('baoxiudan')->where($map)->select();
        $BaoxiuWancheng = Db::name('baoxiudan')->where('type', 2)->where($map)->select();
        $BaoxiuWeiWancheng = Db::name('baoxiudan')->where('type', 1)->where($map)->select();
王智 authored
44
        $Round = round(count($BaoxiuWancheng) / count($BaoxiuArr) * 100, 2);
王智 authored
45
        $WRound = round(count($BaoxiuWeiWancheng) / count($BaoxiuArr) * 100, 2);
王智 authored
46
        //监控系统
王智 authored
47
        $jiankong = Db::name('baoxiudan')->where('system', 1)->where($map)->select();
王智 authored
48
        //通信系统
王智 authored
49
        $tongxin = Db::name('baoxiudan')->where('system', 2)->where($map)->select();
王智 authored
50
        //供配电系统
王智 authored
51
        $peidian = Db::name('baoxiudan')->where('system', 3)->where($map)->select();
王智 authored
52
        //计重设备
王智 authored
53
        $jizhong = Db::name('baoxiudan')->where('system', 4)->where($map)->select();
王智 authored
54
        //收费系统
王智 authored
55
        $shoufei = Db::name('baoxiudan')->where('system', 5)->where($map)->select();
王智 authored
56
        $this->view->assign([
王智 authored
57
            'baoxiunum' => count($BaoxiuArr),
王智 authored
58
            'baoxiu' => $Round . '%',
王智 authored
59
            'wbaoxiu' => $WRound . '%',
王智 authored
60 61 62 63 64
            'jiankong' => count($jiankong),
            'tongxin' => count($tongxin),
            'peidian' => count($peidian),
            'jizhong' => count($jizhong),
            'shoufei' => count($shoufei),
王智 authored
65 66 67
            'totaluser' => 35200,
            'totalviews' => 219390,
            'totalorder' => 32143,
王智 authored
68
            'totalorderamount' => 174800,
王智 authored
69 70 71 72 73 74 75 76 77
            'todayuserlogin' => 321,
            'todayusersignup' => 430,
            'todayorder' => 2324,
            'unsettleorder' => 132,
            'sevendnu' => '80%',
            'sevendau' => '32%',
            'paylist' => $paylist,
            'createlist' => $createlist,
            'addonversion' => $addonVersion,
王智 authored
78
            'uploadmode' => $uploadmode,
王智 authored
79
        ]);
王智 authored
80 81
        $ZhanDianArr = Db::name('zhandian')->select();
        foreach ($ZhanDianArr as $k => $v) {
王智 authored
82
            $data[$k]['id'] = $v['id'];
王智 authored
83 84
            $data[$k]['zhandian_name'] = $v['zhandian'];
            $BaoXiuZhandian = Db::name('baoxiudan')->where('zhandian_id', $v['id'])->where($map)->select();
王智 authored
85 86
            $BaoxiuWancheng = Db::name('baoxiudan')->where('zhandian_id', $v['id'])->where($map)->where('type', 2)->select();
            $BaoxiuWeiWancheng = Db::name('baoxiudan')->where('zhandian_id', $v['id'])->where($map)->where('type', 1)->select();
王智 authored
87 88
            if (empty($BaoXiuZhandian)) {
                $data[$k]['baoxiu_num'] = 0;
王智 authored
89
                $data[$k]['BaoXiuStr'] = '';
王智 authored
90 91 92
                $data[$k]['Round'] = '无记录';
                $data[$k]['WRound'] = '无记录';
王智 authored
93 94
            } else {
                $data[$k]['baoxiu_num'] = count($BaoXiuZhandian);
王智 authored
95 96 97
                foreach ($BaoXiuZhandian as $k1 => $v1) {
                    $StrArr[$k1] = $v1['colum'];
                }
王智 authored
98 99
                $Round = round(count($BaoxiuWancheng) / count($BaoXiuZhandian) * 100, 2);
                $WRound = round(count($BaoxiuWeiWancheng) / count($BaoXiuZhandian) * 100, 2);
王智 authored
100
                $data[$k]['BaoXiuStr'] = implode($StrArr, ',');
王智 authored
101 102
                $data[$k]['Round'] = $Round . '%';
                $data[$k]['WRound'] = $WRound . '%';
王智 authored
103 104 105
            }
        }
        $this->view->assign("row", $data);
王智 authored
106 107 108
        return $this->view->fetch();
    }
王智 authored
109
王智 authored
110
    //自定义导出
王智 authored
111 112
    public function exportDayInner()
    {
王智 authored
113 114 115 116
        //月 起止时间戳
        $start_time = mktime(0, 0, 0, date('m'), 1, date('Y'));
        $end_time = mktime(23, 59, 59, date('m'), date('t'), date('Y'));
        $map['createtime'] = ['between', [$start_time, $end_time]];
王智 authored
117 118 119 120 121 122 123 124 125 126 127 128
        $ZhanDianArr = Db::name('zhandian')->select();
        foreach ($ZhanDianArr as $k => $v) {
            $data[$k]['id'] = $v['id'];
            $data[$k]['zhandian_name'] = $v['zhandian'];
            $BaoXiuZhandian = Db::name('baoxiudan')->where('zhandian_id', $v['id'])->where($map)->select();
            $BaoxiuWancheng = Db::name('baoxiudan')->where('zhandian_id', $v['id'])->where($map)->where('type', 2)->select();
            $BaoxiuWeiWancheng = Db::name('baoxiudan')->where('zhandian_id', $v['id'])->where($map)->where('type', 1)->select();
            if (empty($BaoXiuZhandian)) {
                $data[$k]['baoxiu_num'] = 0;
                $data[$k]['BaoXiuStr'] = '';
                $data[$k]['Round'] = '无记录';
                $data[$k]['WRound'] = '无记录';
王智 authored
129
王智 authored
130 131 132 133 134 135 136 137 138 139
            } else {
                $data[$k]['baoxiu_num'] = count($BaoXiuZhandian);
                foreach ($BaoXiuZhandian as $k1 => $v1) {
                    $StrArr[$k1] = $v1['colum'];
                }
                $Round = round(count($BaoxiuWancheng) / count($BaoXiuZhandian) * 100, 2);
                $WRound = round(count($BaoxiuWeiWancheng) / count($BaoXiuZhandian) * 100, 2);
                $data[$k]['BaoXiuStr'] = implode($StrArr, ',');
                $data[$k]['Round'] = $Round . '%';
                $data[$k]['WRound'] = $WRound . '%';
王智 authored
140 141
            }
        }
王智 authored
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
        $table = '';
        $table .= "<table>
                <thead>
                    <tr>
                        <th class='name'>站点</th>
                        <th class='name'>报修单数量</th>
                        <th class='name'>报修完成率</th>
                        <th class='name'>报修未完成率</th>
                        <th class='name'>故障设备名称</th>
                    </tr>
                </thead>
                <tbody>";
        foreach ($data as $v) {
            $table .= "<tr>
                        <td class='name'>{$v['zhandian_name']}</td>
                        <td class='name'>{$v['baoxiu_num']}</td>
                        <td class='name'>{$v['Round']}</td>
                        <td class='name'>{$v['WRound']}</td>
                        <td class='name'>{$v['BaoXiuStr']}</td>
                    </tr>";
        }
        $table .= "</tbody>
            </table>";
        //通过header头控制输出excel表格
王智 authored
166 167 168 169 170 171
        header("Pragma: public");
        header("Expires: 0");
        header("Cache-Control:must-revalidate, post-check=0, pre-check=0");
        header("Content-Type:application/force-download");
        header("Content-Type:application/vnd.ms-execl");
        header("Content-Type:application/octet-stream");
王智 authored
172 173
        header("Content-Type:application/download");;
        header('Content-Disposition:attachment;filename="入库明细表.xls"');
王智 authored
174
        header("Content-Transfer-Encoding:binary");
王智 authored
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
//        echo $table->downLoad();
        $this->downLoad($table);
    }

    private $head;
    private $body;

    public function downLoad($filename = '')
    {
        if (!$filename)
            $filename = date('YmdHis', time()) . '.xls';
        header("Content-type:application/vnd.ms-excel");
        header("Content-Disposition:filename=$filename");
        header("Content-Type:charset=gb2312");
        if ($this->head)
            echo $this->head;
        echo $this->body;
王智 authored
192
    }
王智 authored
193
}