InstallController.class.php 1.52 KB
<?php
/**
 * Created by PhpStorm.
 */

namespace Frontend\Controller\Callback;

use Common\Service\CategoryService;

class InstallController extends AbstractController
{
    /** @var CategoryService */
    protected $category_service;


    public function __construct()
    {
        parent::__construct();

        // 实例化分类表
        $this->category_service = new CategoryService();
    }

    /**
     * 应用默认数据安装接口
     */
    public function Index()
    {
        $this->Install();
        exit('SUCCESS');
    }

    /**
     * 安装应用
     *
     * @author caijianhua
     *
     * @return bool
     */
    public function Install()
    {
        // 安装默认分类
        $this->AddCategory();
        return true;
    }

    /**
     * 添加默认分类数据
     * @return bool
     */
    public function AddCategory()
    {

        // 初始化默认数据
        $data = [
            [
                'ca_name' => '入职培训',
                'ca_status' => CategoryService::CATEGORY_OPEN,
                'ca_order' => 0
            ],
            [
                'ca_name' => '技能培训',
                'ca_status' => CategoryService::CATEGORY_OPEN,
                'ca_order' => 0
            ],
            [
                'ca_name' => '晋升培训',
                'ca_status' => CategoryService::CATEGORY_OPEN,
                'ca_order' => 0
            ]
        ];

        // 批量写入数据
        $this->category_service->insert_all($data);
        return true;
    }
}