99 lines
3.1 KiB
PHP
99 lines
3.1 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @author Any
|
|
* @description KISS
|
|
* @date 2020-11-4
|
|
* @version 1.0.0
|
|
*
|
|
* _____LOG_____
|
|
*
|
|
*/
|
|
namespace app\modules\admin\controllers;
|
|
|
|
use app\modules\admin\models\AdminMenu;
|
|
use app\models\wechat\WechatApp;
|
|
use app\models\User;
|
|
use Wechat\Wechat;
|
|
|
|
|
|
class Controller extends \app\controllers\Controller
|
|
{
|
|
public $layout = 'main';
|
|
|
|
/**
|
|
* 微信小程序
|
|
* @var WechatApp
|
|
*/
|
|
public $wechat_app;
|
|
|
|
/**
|
|
* 微信小程序
|
|
* @var Wechat
|
|
*/
|
|
public $wechat_mp;
|
|
|
|
|
|
|
|
|
|
public function init()
|
|
{
|
|
parent::init();
|
|
//微信小程序
|
|
$this->wechat_app = WechatApp::findOne([
|
|
'cx_mch_id' => $this->cx_mch_id,
|
|
'is_delete' => 0
|
|
]);
|
|
if($this->wechat_app){
|
|
if (!is_dir(\Yii::$app->runtimePath . '/pem')) {
|
|
mkdir(\Yii::$app->runtimePath . '/pem');
|
|
file_put_contents(\Yii::$app->runtimePath . '/pem/index.html', '');
|
|
}
|
|
$cert_pem_file = null;
|
|
if ($this->wechat_app->cert_pem) {
|
|
$cert_pem_file = \Yii::$app->runtimePath . '/pem/' . md5($this->wechat_app->cert_pem);
|
|
if (!file_exists($cert_pem_file))
|
|
file_put_contents($cert_pem_file, $this->wechat_app->cert_pem);
|
|
}
|
|
$key_pem_file = null;
|
|
if ($this->wechat_app->key_pem) {
|
|
$key_pem_file = \Yii::$app->runtimePath . '/pem/' . md5($this->wechat_app->key_pem);
|
|
if (!file_exists($key_pem_file))
|
|
file_put_contents($key_pem_file, $this->wechat_app->key_pem);
|
|
}
|
|
$this->wechat_mp = new Wechat([
|
|
'appId' => $this->wechat_app->app_id,
|
|
'appSecret' => $this->wechat_app->app_secret,
|
|
'mchId' => $this->wechat_app->mch_id,
|
|
'apiKey' => $this->wechat_app->key,
|
|
'certPem' => $cert_pem_file,
|
|
'keyPem' => $key_pem_file,
|
|
]);
|
|
}
|
|
}
|
|
|
|
|
|
public function behaviors()
|
|
{
|
|
return array_merge(parent::behaviors(), []);
|
|
}
|
|
|
|
/**
|
|
* 获取菜单
|
|
*/
|
|
public function getMenuList()
|
|
{
|
|
$m = new AdminMenu();
|
|
$menus = $m->getList();
|
|
if(\Yii::$app->admin->identity->creator_user_id != 0 && \Yii::$app->admin->identity->creator){
|
|
$creator_permissions = \Yii::$app->admin->identity->creator->permissions;
|
|
$creator_is_super_admin = \Yii::$app->admin->identity->creator->type == User::TYPE_ADMIN ? true : false;
|
|
$menuList = $m->getUserMenu($menus, $creator_permissions, $creator_is_super_admin);
|
|
}
|
|
$is_super_admin = \Yii::$app->admin->identity->user->type == User::TYPE_ADMIN ? true : false;
|
|
$permissions = \Yii::$app->admin->identity->user->permissions;
|
|
$menuList = $m->getUserMenu($menus, $permissions, $is_super_admin);
|
|
return $menuList;
|
|
}
|
|
|
|
} |