DownloadTemplateController.class.php 1.78 KB
<?php
/**
 * 【后台】下载人员导入,激励导入模板
 * DownloadTemplateController.class.php
 * @author:daijun
 * @date:2017-08-31
 */

namespace Frontend\Controller\Export;

class DownloadTemplateController extends AbstractController
{
    // 激励导入
    const INCENTIVES_IMPORT = 1;
    // 员工导入
    const USER_IMPORT = 2;

    public function Index()
    {
        $type = I('get.type', 0, 'intval');

        if (self::INCENTIVES_IMPORT == $type) {
            // 下载激励导入模板
            $data_path = APP_PATH . 'Data' . D_S . 'Incentives_import.xls';
            header('Content-Description: File Transfer');
            header('Content-Type: application/octet-stream');
            header('Content-Disposition: attachment; filename=激励导入模板.xls');
            header('Content-Transfer-Encoding: binary');
            header('Expires: 0');
            header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
            header('Pragma: public');
            header('Content-Length: ' . filesize($data_path));
            readfile($data_path);

        } elseif (self::USER_IMPORT == $type) {
            // 下载员工导入模板
            $data_path = APP_PATH . 'Data' . D_S . 'User_import.xls';
            header('Content-Description: File Transfer');
            header('Content-Type: application/octet-stream');
            header('Content-Disposition: attachment; filename=员工导入模板.xls');
            header('Content-Transfer-Encoding: binary');
            header('Expires: 0');
            header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
            header('Pragma: public');
            header('Content-Length: ' . filesize($data_path));
            readfile($data_path);
        }

        exit;
    }
}