InstallController.class.php 1.33 KB
<?php

namespace Rpc\Controller\Common;

use Common\Service\PluginService;

class InstallController extends AbstractController
{
    // 应用表默认数据
    const PLUGIN_DEFAULT_DATA = [
        'integral_center' => [
            'name' => '积分中心',
            'url' => ''
        ],
    ];

    /**
     * 应用默认数据安装接口
     * @author tangxingguo
     */
    public function Index()
    {
        // 初始化 plugin 表数据
        $this->initPluginData();

        return true;
    }

    /**
     * 初始化 plugin 表数据
     */
    private function initPluginData()
    {
        // 查询 应用表数据
        $pluginServ = new PluginService();
        $pluginList = $pluginServ->list_by_conds([
            'ap_key' => [
                'integral_center'
            ]
        ]);
        $pluginList = array_combine_by_key($pluginList, 'ap_key');

        // 写入 应用表数据
        $pluginInsertList = [];
        foreach (self::PLUGIN_DEFAULT_DATA as $apKey => $item) {
            if (!isset($pluginList[$apKey])) {
                $pluginInsertList[] = [
                    'ap_key' => $apKey,
                    'name' => $item['name'],
                    'url' => $item['url']
                ];
            }
        }
        $pluginServ->insert_all($pluginInsertList);

        return true;
    }
}