InstallController.class.php 4.13 KB
<?php
/**
 * Created by PhpStorm.
 * User: liyifei2012it
 * Date: 17/6/13
 * Time: 18:13
 */

namespace Rpc\Controller\Common;

use Common\Common\Constant;
use Common\Service\FileService;
use Common\Service\RightService;

class InstallController extends AbstractController
{
    /**
     * 是否必须登录
     */
    protected $_require_login = false;

    private $folderId;

    /**
     * 应用默认数据安装接口
     * @author tangxingguo
     */
    public function Index()
    {
        // 默认文件夹
        $this->_addFolder();
        // 默认文件
        $this->_addFile();
    }


    // 添加文件夹
    private function _addFolder()
    {
        // 兼容多次操作
        $fileServ = new FileService();
        $fileInfo = $fileServ->get_by_conds([]);
        if (!empty($fileInfo)) {
            return;
        }

        // 添加文件夹
        $folderInfo = [
            'parent_id' => 0,
            'file_name' => '【系统预设】资料库使用指南',
            'is_download' => 1,
            'file_type' => Constant::FILE_TYPE_IS_FOLDER,
            'update_time' => MILLI_TIME,
            'file_status' => Constant::FILE_STATUS_NORMAL,
            'file_py' => '',
            'at_id' => '',
            'at_size' => 0,
            'at_url' => '',
            'at_convert_url' => '',
            'is_show' => 2,
            'order' => 0,
        ];
        $this->folderId = $fileServ->insert($folderInfo);

        // 保存权限
        $right = [
            'is_all' => 2,
        ];
        // 阅读权限
        $rightServ = new RightService();
        $readConds = [
            'file_id' => $this->folderId,
            'right_type' => Constant::RIGHT_TYPE_IS_READ,
        ];
        $rightServ->saveData($readConds, $right);
        // 下载权限
        $downloadConds = [
            'file_id' => $this->folderId,
            'right_type' => Constant::RIGHT_TYPE_IS_DOWNLOAD,
        ];
        $rightServ->saveData($downloadConds, $right);
    }

    // 添加默认文件
    private function _addFile()
    {
        // 兼容多次操作
        $fileServ = new FileService();
        $fileInfo = $fileServ->get_by_conds(['parent_id > ?' => 0]);
        if (!empty($fileInfo)) {
            return;
        }

        // 默认文件
        $folderInfo = [
            [
                'parent_id' => $this->folderId,
                'file_name' => '如何使用资料库(员工).pdf',
                'is_download' => 1,
                'file_type' => Constant::FILE_TYPE_IS_DOC,
                'update_time' => MILLI_TIME,
                'file_status' => Constant::FILE_STATUS_NORMAL,
                'file_py' => '',
                'at_id' => '9BF929EE0A6924904D785B1154706A2D',
                'at_size' => 644525,
                'at_url' => 'https://resources.vchangyi.com/public/%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8%e8%b5%84%e6%96%99%e5%ba%93%ef%bc%88%e5%91%98%e5%b7%a5%ef%bc%89.pdf',
                'at_convert_url' => 'https://resources.vchangyi.com/public/4E2811830A69249026DB87FAFFE1D070/1fe1b9b9-977f-4d92-b196-bad83f0fde53.html',
                'is_show' => 2,
                'order' => 0,
            ],
            [
                'parent_id' => $this->folderId,
                'file_name' => '如何上传并管理海量文件资料(管理员).pdf',
                'is_download' => 1,
                'file_type' => Constant::FILE_TYPE_IS_DOC,
                'update_time' => MILLI_TIME,
                'file_status' => Constant::FILE_STATUS_NORMAL,
                'file_py' => '',
                'at_id' => '9BF941DD0A6924904D785B11DBD0251D',
                'at_size' => 535823,
                'at_url' => 'https://resources.vchangyi.com/public/%e5%a6%82%e4%bd%95%e4%b8%8a%e4%bc%a0%e5%b9%b6%e7%ae%a1%e7%90%86%e6%b5%b7%e9%87%8f%e6%96%87%e4%bb%b6%e8%b5%84%e6%96%99%ef%bc%88%e7%ae%a1%e7%90%86%e5%91%98%ef%bc%89.pdf',
                'at_convert_url' => 'https://resources.vchangyi.com/public/4E280EF80A69249026DB87FA322DFCD2/cf57c8be-8e20-4471-9be4-13665aa3ddb5.html',
                'is_show' => 2,
                'order' => 0,
            ]
        ];

        $fileServ->insert_all($folderInfo);
    }

}