| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\plugins\wxlive\controllers;
- use app\models\Plugins;
- use yii\base\Module;
- use yii\web\Controller;
- class BaseController extends Controller
- {
- /**
- * 原路由
- * @var string
- */
- public $route = null;
- public function __construct(string $id, Module $module, array $config = [])
- {
- $this->route = $config['callback'];
- $route = isset($_GET['r']) ? $_GET['r'] : null;
- if ($route && strpos($route, 'plugin') !== false) {
- if ($from = explode('/', $route)[0]) {
- switch ($from) {
- case 'client':
- $this->clientEvent();
- break;
- case 'admin':
- $this->adminEvent();
- break;
- default:
- break;
- }
- }
- }
- }
- /**
- * 客户端接口事件绑定
- */
- public function clientEvent() {
- $plugin = explode('/', $this->route)[0];
- if (!$plugin) {
- return;
- }
- $plugins_data = cache()->get('plugins_data_cache');
- // 取缓存
- if (!$plugins_data) {
- $plugins_data = Plugins::find()->asArray()->all();
- if (!$plugins_data) {
- return;
- }
- \Yii::$app->cache->set('plugins_data_cache', $plugins_data, 3600);
- }
- $temp_key = array_column($plugins_data, 'key');
- $data = array_combine($temp_key, $plugins_data);
- if (isset($data[$plugin]) && $data[$plugin]['status'] == Plugins::STATUS_OPEN) {
- require __DIR__ .'/../PluginInit.php';
- $str = '\app\plugins\%s\PluginInit';
- $class = sprintf($str, $plugin);
- if (method_exists($class, 'init')) {
- call_user_func($class. '::init', ['route' => $this->route]);
- }
- }
- }
- /**
- * 后台接口事件绑定
- */
- public function adminEvent() {
- }
- }
|