初始化代码
This commit is contained in:
235
longbingcore/permissions/AdminMenu.php
Normal file
235
longbingcore/permissions/AdminMenu.php
Normal file
@@ -0,0 +1,235 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | Longbing [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright Chengdu longbing Technology Co., Ltd.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Website http://longbing.org/
|
||||
// +----------------------------------------------------------------------
|
||||
// | Sales manager: +86-13558882532 / +86-13330887474
|
||||
// | Technical support: +86-15680635005
|
||||
// | After-sale service: +86-17361005938
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace longbingcore\permissions;
|
||||
|
||||
|
||||
|
||||
use app\admin\info\PermissionAdmin;
|
||||
|
||||
/**
|
||||
* c端后台菜单
|
||||
* @author ArtizanZhang
|
||||
* @DataTime: 2019/12/6 18:56
|
||||
* Class AdminMenu
|
||||
* @package longbingcore\permissions
|
||||
*/
|
||||
class AdminMenu {
|
||||
|
||||
/**
|
||||
* 根据权限来返回有权限的菜单
|
||||
*
|
||||
* @param int $uniacid
|
||||
* @return array
|
||||
* @author ArtizanZhang
|
||||
* @DataTime: 2019/12/6 19:01
|
||||
*/
|
||||
static public function all (int $uniacid) : array {
|
||||
|
||||
$menu_data = longbing_init_info_data('AdminMenu' , 'model');
|
||||
|
||||
|
||||
// dump($menu_data);exit;
|
||||
$denyAdminMenuKeys = self::getAuthList($uniacid);
|
||||
|
||||
|
||||
|
||||
|
||||
//获取权限接口 2019年12月20日09:51:18 By.jingshuixian
|
||||
/*
|
||||
foreach ($saas_auth_admin_model_list as $key=>$item){
|
||||
|
||||
|
||||
if($item['auth_is_saas_check'] || $item['auth_platform'] ){
|
||||
$permissionPath = APP_PATH . $key . '/info/Permission.php' ;
|
||||
if(file_exists($permissionPath) && require_once($permissionPath)){
|
||||
|
||||
$permissionClassName = 'app\\' . $key .'\\info\\Permission' ;
|
||||
$permissionClass = new $permissionClassName($uniacid);
|
||||
|
||||
if($item['auth_is_saas_check'] && $permissionClass->sAuth() && $item['auth_platform'] && $permissionClass->pAuth() ){
|
||||
$denyAdminMenuKeys[] = $key;
|
||||
}else if ( !$item['auth_is_saas_check'] && $item['auth_platform'] && $permissionClass->pAuth() ) {
|
||||
$denyAdminMenuKeys[] = $key;
|
||||
}
|
||||
}
|
||||
|
||||
}else{
|
||||
$denyAdminMenuKeys[] = $key;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
//从查找没有权限的adminMenuKey
|
||||
/*$denyAdminMenuKeys = [];
|
||||
$permissions = config('permissions');
|
||||
foreach ($permissions as $permissionClass) {
|
||||
|
||||
//判断一个对象是否为一个类的子类
|
||||
if (!is_subclass_of($permissionClass, PermissionAbstract::class)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
$permission = new $permissionClass($uniacid, 0);
|
||||
if (!$permission->pAuth() && !empty($permission->adminMenuKey)) {
|
||||
$denyAdminMenuKeys[] = $permission->adminMenuKey;
|
||||
}
|
||||
}*/
|
||||
|
||||
//返回有权限的菜单
|
||||
$rst = [];
|
||||
|
||||
|
||||
foreach ($menu_data as $k => $menu) {
|
||||
|
||||
|
||||
if (array_key_exists($k, $denyAdminMenuKeys) ) {
|
||||
//装载插件权限 By.jingshuixian
|
||||
if($k == 'appstore'){
|
||||
//后去插件所有菜单 需要过滤权限
|
||||
$appMenudataList = longbing_init_info_data('AdminMenu','app');
|
||||
$app = json_decode($menu, true);
|
||||
$children = $app['children'] ;
|
||||
|
||||
foreach ($appMenudataList as $appKey => $appMenu) {
|
||||
|
||||
//过滤插件全选,需要验证是否正确
|
||||
if (array_key_exists($appKey, $denyAdminMenuKeys)){
|
||||
|
||||
|
||||
$m = json_decode($appMenu, true);
|
||||
|
||||
if(!empty($m)){
|
||||
foreach ($m as $item ){
|
||||
$children[] = $item;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//应用中心主菜单
|
||||
|
||||
$app['children'] = $children ;
|
||||
|
||||
$rst[] = $app ;
|
||||
}else if($k == 'admin'){
|
||||
|
||||
$adminMenu = json_decode($menu, true) ;
|
||||
$permission = new PermissionAdmin($uniacid);
|
||||
$pAuthConfig = $permission->getPAuthConfig();
|
||||
if($pAuthConfig && $pAuthConfig['copyright_id'] != 0 ){
|
||||
$children = $adminMenu['children'];
|
||||
foreach ($children as $k => $child) {
|
||||
if ($child['path'] == 'copyright') {
|
||||
unset($children[$k]);
|
||||
}
|
||||
}
|
||||
$adminMenu['children'] = array_values($children);
|
||||
|
||||
$url = $adminMenu['meta']['subNavName'][1]['url'];
|
||||
unset($url[0]);
|
||||
$adminMenu['meta']['subNavName'][1]['url'] = array_values($url);
|
||||
}
|
||||
|
||||
$rst[] = $adminMenu ;
|
||||
|
||||
}else{
|
||||
$rst[] = json_decode($menu, true);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
return $rst;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取所有应用列表权限
|
||||
*
|
||||
* @param int $uniacid
|
||||
* @return array
|
||||
* @author shuixian
|
||||
* @DataTime: 2019/12/20 13:51
|
||||
*/
|
||||
static public function getAppstoreInfoList (int $uniacid) : array {
|
||||
|
||||
$dataList = longbing_init_info_data('Info','app');
|
||||
|
||||
$denyAdminMenuKeys = self::getAuthList($uniacid);
|
||||
|
||||
$returnList = [] ;
|
||||
|
||||
foreach ($dataList as $key => $item ){
|
||||
|
||||
if(array_key_exists($item['name'], $denyAdminMenuKeys) ){
|
||||
$returnList[] = $item ;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
return $returnList ;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获得拥有模块/app权限列表
|
||||
*
|
||||
* @param $uniacid
|
||||
* @return array
|
||||
* @author shuixian
|
||||
* @DataTime: 2019/12/20 13:39
|
||||
*/
|
||||
static public function getAuthList($uniacid){
|
||||
$denyAdminMenuKeys = [] ;
|
||||
|
||||
|
||||
if(empty($uniacid)){
|
||||
return $denyAdminMenuKeys ;
|
||||
}
|
||||
|
||||
$adminModelListInfo = config('app.AdminModelList') ;
|
||||
$saas_auth_admin_model_list = $adminModelListInfo['saas_auth_admin_model_list'];
|
||||
|
||||
|
||||
foreach ($saas_auth_admin_model_list as $key=>$item) {
|
||||
|
||||
$className = 'Permission' . ucfirst($key);
|
||||
$permissionPath = APP_PATH . $key . '/info/' . $className . '.php';
|
||||
if (file_exists($permissionPath) && require_once($permissionPath)) {
|
||||
|
||||
$permissionClassName = 'app\\' . $key . '\\info\\'. $className;
|
||||
$permission = new $permissionClassName($uniacid , $item);
|
||||
if ( $permission->pAuth() && !empty($permission->adminMenuKey)) {
|
||||
|
||||
$denyAdminMenuKeys[$key] = $item;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $denyAdminMenuKeys ;
|
||||
}
|
||||
|
||||
}
|
||||
274
longbingcore/permissions/PermissionAbstract.php
Normal file
274
longbingcore/permissions/PermissionAbstract.php
Normal file
@@ -0,0 +1,274 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | Longbing [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright Chengdu longbing Technology Co., Ltd.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Website http://longbing.org/
|
||||
// +----------------------------------------------------------------------
|
||||
// | Sales manager: +86-13558882532 / +86-13330887474
|
||||
// | Technical support: +86-15680635005
|
||||
// | After-sale service: +86-17361005938
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace longbingcore\permissions;
|
||||
|
||||
|
||||
use app\Common\Rsa2Sign;
|
||||
use think\db\exception\DataNotFoundException;
|
||||
use think\db\exception\DbException;
|
||||
use think\db\exception\ModelNotFoundException;
|
||||
use think\facade\Db;
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* 权限的抽象类
|
||||
* @author ArtizanZhang
|
||||
* @DataTime: 2019/12/6 18:56
|
||||
* Class PermissionAbstract
|
||||
* @package longbingcore\permissions
|
||||
*/
|
||||
abstract class PermissionAbstract
|
||||
{
|
||||
/**
|
||||
* @var int|null 小程序底部菜单的key
|
||||
*/
|
||||
public $tabbarKey;
|
||||
|
||||
/**
|
||||
* @var string|null 后台菜单的key
|
||||
*/
|
||||
public $adminMenuKey;
|
||||
|
||||
/**
|
||||
* @var array 权限关联的apiPaths
|
||||
*/
|
||||
public $apiPaths;
|
||||
|
||||
/**
|
||||
* @var string|null saas端授权的key
|
||||
*/
|
||||
public $saasKey;
|
||||
|
||||
|
||||
/**
|
||||
* @var int|null sass端授权的值
|
||||
*/
|
||||
protected $sassValue;
|
||||
|
||||
/**
|
||||
* @var int 小程序id
|
||||
*/
|
||||
protected $uniacid;
|
||||
|
||||
/**
|
||||
* @var array info控制配置信息
|
||||
*/
|
||||
public $infoConfig = [
|
||||
'auth_platform' => true ,
|
||||
'auth_is_platform_check' =>true ,
|
||||
'auth_is_saas_check' => true ,
|
||||
];
|
||||
|
||||
public $info = [];
|
||||
|
||||
static public $pAuthConfig;
|
||||
|
||||
|
||||
public function __construct(int $uniacid, ?int $tabbarKey, ?string $adminMenuKey, ?string $saasKey, ?array $apiPaths , $infoConfigOptions = [])
|
||||
{
|
||||
$this->tabbarKey = $tabbarKey;
|
||||
$this->adminMenuKey = $adminMenuKey;
|
||||
$this->saasKey = $saasKey;
|
||||
$this->apiPaths = $apiPaths;
|
||||
$this->uniacid = $uniacid;
|
||||
|
||||
if(!empty($infoConfigOptions)){
|
||||
$this->infoConfig = array_merge($this->infoConfig , $infoConfigOptions);
|
||||
}else{
|
||||
//自动从全局Info里获取
|
||||
$adminModelListInfo = config('app.AdminModelList') ;
|
||||
$saas_auth_admin_model_list = $adminModelListInfo['saas_auth_admin_model_list'];
|
||||
if(array_key_exists($this->adminMenuKey , $saas_auth_admin_model_list)){
|
||||
$this->infoConfig = array_merge($this->infoConfig , $saas_auth_admin_model_list[$this->adminMenuKey]);
|
||||
}
|
||||
}
|
||||
|
||||
$this->info = $this->getModelInfo($this->adminMenuKey);
|
||||
|
||||
$this->sassValue = $this->getAuthVaule($this->saasKey );
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前模块/app配置的info信息
|
||||
*
|
||||
* @param $model_name
|
||||
* @return array|mixed
|
||||
* @author shuixian
|
||||
* @DataTime: 2019/12/27 17:47
|
||||
*/
|
||||
public function getModelInfo($model_name){
|
||||
|
||||
//导入info信息查看
|
||||
$infoDataPath = APP_PATH . $model_name . '/info/Info.php' ;
|
||||
$infoData = [] ;
|
||||
if(file_exists($infoDataPath)){
|
||||
$infoData = include $infoDataPath ;
|
||||
}
|
||||
return $infoData ;
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回saas端授权结果
|
||||
*
|
||||
* @return bool
|
||||
* @author ArtizanZhang
|
||||
* @DataTime: 2019/12/6 18:57
|
||||
*/
|
||||
abstract public function sAuth(): bool;
|
||||
|
||||
/**
|
||||
* 返回p端授权结果
|
||||
*
|
||||
* @return bool
|
||||
* @author ArtizanZhang
|
||||
* @DataTime: 2019/12/6 18:57
|
||||
*/
|
||||
abstract public function pAuth(): bool;
|
||||
|
||||
/**
|
||||
* 返回c端授权结果
|
||||
*
|
||||
* @param int $user_id
|
||||
* @return bool
|
||||
* @author ArtizanZhang
|
||||
* @DataTime: 2019/12/9 17:13
|
||||
*/
|
||||
abstract public function cAuth(int $user_id): bool;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 返回saasValue
|
||||
*
|
||||
* @return int
|
||||
* @author ArtizanZhang
|
||||
* @DataTime: 2019/12/6 18:58
|
||||
*/
|
||||
public function getSaasValue(): int
|
||||
{
|
||||
return $this->sassValue;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 返回当前实例
|
||||
*
|
||||
* @param int $uniacid
|
||||
* @return PermissionAbstract
|
||||
* @author ArtizanZhang
|
||||
* @DataTime: 2019/12/9 10:59
|
||||
*/
|
||||
static function this (int $uniacid) : self {
|
||||
return new static($uniacid);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取p端的权限配置
|
||||
*
|
||||
* @return array|null
|
||||
* @author ArtizanZhang
|
||||
* @DataTime: 2019/12/9 14:22
|
||||
*/
|
||||
public function getPAuthConfig(): ?array
|
||||
{
|
||||
if (isset(self::$pAuthConfig[$this->uniacid])) {
|
||||
return self::$pAuthConfig[$this->uniacid];
|
||||
}
|
||||
|
||||
try {
|
||||
$cardauth2_config_exist = Db::query('show tables like "%longbing_cardauth2_config%"');
|
||||
if (empty($cardauth2_config_exist)) {
|
||||
return null;
|
||||
}
|
||||
$pAuthConfig = Db::name('longbing_cardauth2_config')->where([['modular_id', '=', $this->uniacid]])->find();
|
||||
} catch (DataNotFoundException $notFoundException) {
|
||||
return null;
|
||||
} catch (ModelNotFoundException $modelNotFoundException) {
|
||||
return null;
|
||||
} catch (DbException $exception) {
|
||||
return null;
|
||||
}
|
||||
|
||||
self::$pAuthConfig[$this->uniacid] = $pAuthConfig;
|
||||
return $pAuthConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据saasAuthKey获得值
|
||||
*
|
||||
* @param $saasAuthKey
|
||||
* @return int|null
|
||||
* @author shuixian
|
||||
* @DataTime: 2019/12/19 19:07
|
||||
*/
|
||||
public function getAuthVaule($saasAuthKey , $defaultAuthNumber = -1){
|
||||
$returnNumber = 0 ;
|
||||
$auth = SaasAuthConfig::getSAuthConfig($this->uniacid);
|
||||
if($auth){
|
||||
$authkey = array_column($auth,1 , 0) ;
|
||||
}else{
|
||||
$authkey = [];
|
||||
}
|
||||
|
||||
|
||||
if(array_key_exists($saasAuthKey , $authkey)){
|
||||
|
||||
$returnNumber = intval( $authkey[$saasAuthKey] ) ;
|
||||
//0 代表无限制数量, 默认给 99999999
|
||||
$returnNumber = $returnNumber == 0 ? 0 : $returnNumber ;
|
||||
|
||||
}else{
|
||||
$returnNumber = $defaultAuthNumber ;
|
||||
}
|
||||
|
||||
/* if($saasAuthKey == 'LONGBING_BAIDU'){
|
||||
|
||||
longbing_dd($auth);
|
||||
|
||||
longbing_dd($saasAuthKey . '=========='.$defaultAuthNumber .'===========' . $this->uniacid);
|
||||
}*/
|
||||
|
||||
|
||||
return $returnNumber ;
|
||||
}
|
||||
|
||||
|
||||
public function getAuthPlatform(){
|
||||
return $this->infoConfig['auth_platform'] ;
|
||||
}
|
||||
|
||||
public function getAuthIsPlatformCheck(){
|
||||
return $this->infoConfig['auth_is_platform_check'] ;
|
||||
}
|
||||
|
||||
public function getAuthIsSaasCheck(){
|
||||
return $this->infoConfig['auth_is_saas_check'] ;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取授权数量
|
||||
*
|
||||
* @author shuixian
|
||||
* @DataTime: 2019/12/19 19:02
|
||||
*/
|
||||
public function getAuthNumber(){
|
||||
|
||||
return $this->getAuthVaule( $this->saasKey);
|
||||
}
|
||||
|
||||
}
|
||||
143
longbingcore/permissions/SaasAuthConfig.php
Normal file
143
longbingcore/permissions/SaasAuthConfig.php
Normal file
@@ -0,0 +1,143 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | Longbing [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright Chengdu longbing Technology Co., Ltd.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Website http://longbing.org/
|
||||
// +----------------------------------------------------------------------
|
||||
// | Sales manager: +86-13558882532 / +86-13330887474
|
||||
// | Technical support: +86-15680635005
|
||||
// | After-sale service: +86-17361005938
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
namespace longbingcore\permissions;
|
||||
|
||||
include_once LONGBING_EXTEND_PATH . 'LongbingUpgrade.php';
|
||||
|
||||
use app\Common\Rsa2Sign;
|
||||
use think\db\exception\DataNotFoundException;
|
||||
use think\db\exception\DbException;
|
||||
use think\db\exception\ModelNotFoundException;
|
||||
use think\facade\Db;
|
||||
use think\facade\Env;
|
||||
use LongbingUpgrade;
|
||||
|
||||
/**
|
||||
* saas端请求到的权限数据(k-v格式)
|
||||
*
|
||||
* @author ArtizanZhang
|
||||
* @DataTime: 2019/12/9 14:23
|
||||
* Class SaasAuthConfig
|
||||
* @package longbingcore\permissions
|
||||
*/
|
||||
Class SaasAuthConfig {
|
||||
|
||||
|
||||
static public $sAuthConfig = [];
|
||||
|
||||
|
||||
/**
|
||||
* 获取s端的权限配置
|
||||
*
|
||||
* @return array|null
|
||||
* @author ArtizanZhang
|
||||
* @DataTime: 2019/12/9 11:26
|
||||
*/
|
||||
public static function getSAuthConfig (int $uniacid): ?array
|
||||
{
|
||||
if (isset(self::$sAuthConfig[$uniacid])) {
|
||||
return self::$sAuthConfig[$uniacid];
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
$sAuthConfig = self::_getsAuthConfig($uniacid);
|
||||
if(empty($sAuthConfig)) {
|
||||
$sAuthConfig = [] ;
|
||||
}
|
||||
|
||||
self::$sAuthConfig[$uniacid] = $sAuthConfig;
|
||||
|
||||
return $sAuthConfig;
|
||||
} catch (\Exception $exception) {
|
||||
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取saas端的值
|
||||
* @param string $server_url
|
||||
* @return array|bool|mixed
|
||||
* @throws DataNotFoundException
|
||||
* @throws DbException
|
||||
* @throws ModelNotFoundException
|
||||
* @author ArtizanZhang
|
||||
* @DataTime: 2019/12/6 19:01
|
||||
*
|
||||
*/
|
||||
private static function _getsAuthConfig($uniacid, $server_url = 'http://api.longbing.org')
|
||||
{
|
||||
|
||||
$app_model_name = config('app.AdminModelList')['app_model_name'];
|
||||
//By.jingshuixian 2019年12月20日16:48:41 优化代码逻辑
|
||||
//代理管理端是固定小程
|
||||
$uniacid = $uniacid ? $uniacid : 8888 ;
|
||||
|
||||
$domain_name = $_SERVER['HTTP_HOST'];
|
||||
|
||||
$auth_data = getCache('single_checked_auth_'. $app_model_name . $domain_name, $uniacid );
|
||||
//dump($auth_data);exit;
|
||||
if (!empty($auth_data)&&!empty($auth_data[0][0])) {
|
||||
|
||||
return $auth_data;
|
||||
|
||||
}
|
||||
//By.jingshuixian 2019年12月20日16:48:41 优化代码逻辑 end
|
||||
|
||||
$goods_name = config('app.AdminModelList')['app_model_name'];
|
||||
|
||||
$auth_uniacid = config('app.AdminModelList')['auth_uniacid'];
|
||||
|
||||
$upgrade = new LongbingUpgrade($auth_uniacid , $goods_name , Env::get('j2hACuPrlohF9BvFsgatvaNFQxCBCc' , false));
|
||||
|
||||
$param_list = $upgrade->getsAuthConfig();
|
||||
|
||||
if (!empty($param_list)) {
|
||||
|
||||
$data = $param_list;
|
||||
|
||||
$auth_data = [];
|
||||
//解密
|
||||
foreach ($data as $k => $item) {
|
||||
|
||||
$a = explode(':', $item);
|
||||
//存入缓存 一天的有效期
|
||||
if ($a[0] == 'LONGBING_AUTH_GOODS_SINGLE') {
|
||||
|
||||
$a[0] = 'LONGBING_AUTH_GOODS';
|
||||
|
||||
}
|
||||
$auth_data[] = $a;
|
||||
}
|
||||
setCache('single_checked_auth_' . $app_model_name . $domain_name, $auth_data, 3600, $uniacid);
|
||||
|
||||
return $auth_data;
|
||||
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
226
longbingcore/permissions/Tabbar.php
Normal file
226
longbingcore/permissions/Tabbar.php
Normal file
@@ -0,0 +1,226 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | Longbing [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright Chengdu longbing Technology Co., Ltd.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Website http://longbing.org/
|
||||
// +----------------------------------------------------------------------
|
||||
// | Sales manager: +86-13558882532 / +86-13330887474
|
||||
// | Technical support: +86-15680635005
|
||||
// | After-sale service: +86-17361005938
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace longbingcore\permissions;
|
||||
|
||||
use app\diy\model\DiyModel;
|
||||
use think\facade\Db;
|
||||
|
||||
/**
|
||||
* 小程序底部菜单
|
||||
* @author ArtizanZhang
|
||||
* @DataTime: 2019/12/6 18:56
|
||||
* Class Tabbar
|
||||
* @package longbingcore\permissions
|
||||
*/
|
||||
class Tabbar {
|
||||
|
||||
/**
|
||||
* 根据权限来返回有权限的小程序底部菜单
|
||||
*
|
||||
* @param int $uniacid
|
||||
* @param int $user_id
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author ArtizanZhang
|
||||
* @DataTime: 2019/12/10 15:56
|
||||
*/
|
||||
static public function all (int $uniacid, int $user_id) : array {
|
||||
$diy = DiyModel::where([['uniacid', '=', $uniacid], ['status', '=', 1]])->find();
|
||||
if (empty($diy)) {
|
||||
return [];
|
||||
}
|
||||
$diy_tabbar = json_decode($diy['tabbar'], true);
|
||||
|
||||
|
||||
//从查找没有权限的tabbarKey
|
||||
$denyTabbarKeys = [];
|
||||
$permissions = config('permissions');
|
||||
foreach ($permissions as $permissionClass) {
|
||||
if (!is_subclass_of($permissionClass, PermissionAbstract::class)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @var PermissionAbstract $permission
|
||||
*/
|
||||
$permission = new $permissionClass($uniacid, $user_id);
|
||||
if (!$permission->cAuth($user_id) && !empty($permission->tabbarKey)) {
|
||||
$denyTabbarKeys[] = $permission->tabbarKey;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//返回有权限的菜单
|
||||
foreach ($diy_tabbar['list'] as $k => $tabbar) {
|
||||
if (in_array($tabbar['key'], $denyTabbarKeys)) {
|
||||
unset($diy_tabbar['list'][$k]);
|
||||
}
|
||||
}
|
||||
|
||||
return $diy_tabbar;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* diy时,返回有diy权限的小程序菜单
|
||||
*
|
||||
* @param int $uniacid
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author ArtizanZhang
|
||||
* @DataTime: 2019/12/10 15:56
|
||||
*/
|
||||
static public function allForDiySelect (int $uniacid) : array {
|
||||
$diy_tabbar = [] ;
|
||||
|
||||
|
||||
$adminModelListInfo = config('app.AdminModelList') ;
|
||||
$saas_auth_admin_model_list = $adminModelListInfo['saas_auth_admin_model_list'];
|
||||
|
||||
|
||||
foreach ($saas_auth_admin_model_list as $key=>$item) {
|
||||
|
||||
$className = 'Permission' . ucfirst($key);
|
||||
$permissionPath = APP_PATH . $key . '/info/' . $className . '.php';
|
||||
if (file_exists($permissionPath) && require_once($permissionPath)) {
|
||||
|
||||
$permissionClassName = 'app\\' . $key . '\\info\\'. $className;
|
||||
$permission = new $permissionClassName($uniacid , $item);
|
||||
|
||||
if ( $permission->pAuth() && !empty($permission->adminMenuKey)) {
|
||||
|
||||
$diyTabbarPath = APP_PATH . $key . '/info/DiyTabbar.php';
|
||||
if (file_exists($diyTabbarPath)) {
|
||||
|
||||
$tabbar = include_once ($diyTabbarPath) ;
|
||||
|
||||
$diy_tabbar = array_merge($diy_tabbar , $tabbar) ;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$data['list'] = $diy_tabbar;
|
||||
//默认设置
|
||||
$data['color'] = '#5d6268';
|
||||
$data['selectedColor'] = '#19c865';
|
||||
$data['backgroundColor'] = '#fff';
|
||||
$data['borderStyle'] = 'white';
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $uniacid
|
||||
* @功能说明:获取有权限的默认数据
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-05-15 17:28
|
||||
*/
|
||||
static public function getAuthDefultTabbar($data){
|
||||
|
||||
$url = config('app.AdminModelList')['diy_default_data']['tabbar'];
|
||||
//默认配置
|
||||
//$url = '{"id":1,"uniacid":4,"status":1,"create_time":1578106749,"update_time":1578106749,"list":[{"is_show":1,"key":1,"iconPath":"icon-mingpian","selectedIconPath":"icon-mingpian1","pageComponents":"cardHome","name":"\u540d\u7247","url":"\/pages\/user\/home","url_out":"","jump_way":0},{"key":2,"is_show":1,"iconPath":"icon-shangcheng1","selectedIconPath":"icon-shangcheng","pageComponents":"shopHome","name":"\u5546\u57ce","url":"","url_jump_way":"0","url_out":"","is_delete":false,"bind_compoents":[],"bind_links":[],"page":[]},{"key":3,"is_show":1,"iconPath":"icon-dongtai1","selectedIconPath":"icon-dongtai","pageComponents":"infoHome","name":"\u52a8\u6001","url":"","url_jump_way":"0","url_out":"","is_delete":false,"bind_compoents":[],"bind_links":[],"page":[]},{"key":4,"is_show":1,"iconPath":"icon-guanwang","selectedIconPath":"icon-guanwang1","pageComponents":"websiteHome","name":"\u5b98\u7f51","url":"","url_jump_way":"0","url_out":"","is_delete":false,"bind_compoents":[],"bind_links":[],"page":[]},{"key":20001,"is_show":1,"iconPath":"iconyonghuduangerenzhongxin","selectedIconPath":"iconyonghuduangerenzhongxin1","pageComponents":"","name":"\u4e2a\u4eba\u4e2d\u5fc3","url":"","url_jump_way":"0","url_out":"","is_delete":false,"bind_compoents":["ucenterCompoent"],"bind_links":["case"],"page":[]}],"color":"#5d6268","selectedColor":"#19c865","backgroundColor":"#fff","borderStyle":"white"}';
|
||||
|
||||
$url = json_decode($url,true);
|
||||
|
||||
foreach ($url['list'] as $k=>$v){
|
||||
|
||||
if(!in_array($v['key'],$data)){
|
||||
|
||||
unset($url['list'][$k]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$url['list'] = array_values($url['list']);
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $uniacid
|
||||
* @功能说明:获取有权限的
|
||||
* @author chenniang
|
||||
* @DataTime: 2020-05-15 17:50
|
||||
*/
|
||||
static public function getAuthDefultPage($data){
|
||||
|
||||
$url = config('app.AdminModelList')['diy_default_data']['page'];
|
||||
//默认配置
|
||||
//$url = '{"1":{"list":[]},"2":{"list":[]},"3":{"list":[]},"4":{"list":[]},"20001":{"list":[{"title":"\u7528\u6237\u4fe1\u606f","type":"userInfo","icon":"iconyonghuxinxi","isDelete":false,"addNumber":1,"attr":[{"title":"\u5b57\u4f53\u989c\u8272","type":"ColorPicker","name":"fontColor"},{"title":"\u80cc\u666f\u56fe\u7247","type":"UploadImage","desc":"750*440","name":"bgImage"}],"data":{"nickName":"\u7528\u6237\u6635\u79f0","avatarUrl":"https:\/\/retail.xiaochengxucms.com\/defaultAvatar.png","nickText":"\u66f4\u65b0\u6211\u7684\u4e2a\u4eba\u8d44\u6599","fontColor":"#F9DEAF","bgImage":[{"url":"http:\/\/longbingcdn.xiaochengxucms.com\/admin\/diy\/user_bg.jpg"}]},"id":1578137234868,"compontents":"ucenterCompoent"},{"title":"\u521b\u5efa\u540d\u7247","type":"createCard","icon":"iconchuangjianmingpian","isDelete":false,"addNumber":1,"data":{"createText":"\u521b\u5efa\u6211\u7684\u540d\u7247","createBtn":"\u521b\u5efa\u540d\u7247"},"id":1578137237049,"compontents":"ucenterCompoent"},{"title":"\u8ba2\u5355\u7ba1\u7406","type":"moduleMenuShopOrder","icon":"iconshoporder","isDelete":true,"addNumber":1,"attr":[{"title":"\u6a21\u677f\u540d\u79f0","type":"Switch","name":"isShowTitle"},{"title":"\u9009\u62e9\u6a21\u677f","type":"ChooseModule","name":"module","data":[{"title":"\u4e00\u884c\u591a\u5217","name":"module-menu-row","img":"http:\/\/longbingcdn.xiaochengxucms.com\/admin\/diy\/module-menu-col.jpg"},{"title":"\u4e00\u884c\u4e00\u5217","name":"module-menu-col","img":"http:\/\/longbingcdn.xiaochengxucms.com\/admin\/diy\/module-menu-row.jpg"}]},{"title":"\u4e00\u884c\u591a\u5c11\u5217","type":"InputNumber","name":"row"}],"data":{"isShowTitle":false,"module":"module-menu-row","row":{"number":4,"min":2,"max":5,"label":"\u8bf7\u8f93\u5165"},"list":[{"title":"\u5168\u90e8","icon":"iconwodedingdan","link":{"type":2,"url":"\/shop\/pages\/order\/list?index=0"}},{"title":"\u5f85\u4ed8\u6b3e","icon":"icondingdandaifukuan","link":{"type":2,"url":"\/shop\/pages\/order\/list?index=1"}},{"title":"\u5f85\u53d1\u8d27","icon":"icondingdandaifahuo","link":{"type":2,"url":"\/shop\/pages\/order\/list?index=2"}},{"title":"\u5f85\u6536\u8d27","icon":"icondingdandaishouhuo","link":{"type":2,"url":"\/shop\/pages\/order\/list?index=3"}},{"title":"\u5df2\u5b8c\u6210","icon":"icondingdanyiwancheng","link":{"type":2,"url":"\/shop\/pages\/order\/list?index=4"}}]},"id":1578137248488,"compontents":"ucenterCompoent"},{"title":"\u5fc5\u5907\u5de5\u5177","type":"moduleMenuShop","icon":"iconshop","isDelete":true,"addNumber":1,"attr":[{"title":"\u6a21\u677f\u540d\u79f0","type":"Switch","name":"isShowTitle"},{"title":"\u9009\u62e9\u6a21\u677f","type":"ChooseModule","name":"module","data":[{"title":"\u4e00\u884c\u591a\u5217","name":"module-menu-row","img":"http:\/\/longbingcdn.xiaochengxucms.com\/admin\/diy\/module-menu-col.jpg"},{"title":"\u4e00\u884c\u4e00\u5217","name":"module-menu-col","img":"http:\/\/longbingcdn.xiaochengxucms.com\/admin\/diy\/module-menu-row.jpg"}]},{"title":"\u4e00\u884c\u591a\u5c11\u5217","type":"InputNumber","name":"row"}],"data":{"isShowTitle":false,"module":"module-menu-row","row":{"number":4,"min":2,"max":5,"label":"\u8bf7\u8f93\u5165"},"list":[{"title":"\u6211\u7684\u552e\u540e","icon":"iconwodeshouhou","link":{"type":2,"url":"\/shop\/pages\/refund\/list"}},{"title":"\u6211\u7684\u6536\u5165","icon":"icontixianguanli","link":{"type":2,"url":"\/shop\/pages\/partner\/income"}},{"title":"\u6211\u7684\u4f18\u60e0\u5238","icon":"iconwodekaquan","link":{"type":2,"url":"\/shop\/pages\/coupon\/list"}},{"title":"\u5206\u9500\u5546\u54c1","icon":"iconquanmianfenxiao","link":{"type":2,"needStaffId":true,"url":"\/shop\/pages\/partner\/distribution?staff_id="}},{"title":"\u6211\u7684\u5730\u5740","icon":"icondizhi2","link":{"type":2,"url":"\/shop\/pages\/address\/list"}}]},"id":1578137252032,"compontents":"ucenterCompoent"},{"title":"\u5207\u6362\u9500\u552e","type":"changeStaff","icon":"iconqiehuanmingpian-copy","isDelete":false,"addNumber":1,"attr":[{"title":"\u6a21\u677f\u540d\u79f0","type":"Input","name":"title"},{"title":"\u662f\u5426\u663e\u793a\u66f4\u591a","type":"Switch","name":"isShowMore"}],"data":{"title":"\u5207\u6362\u9500\u552e","isShowMore":true},"dataList":[],"id":1578137250013,"compontents":"ucenterCompoent"}]}}';
|
||||
|
||||
$url = json_decode($url,true);
|
||||
|
||||
foreach ($url as $k=>$v){
|
||||
|
||||
if(!in_array($k,$data)){
|
||||
|
||||
unset($url[$k]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $url;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获得拥有模块/app权限列表
|
||||
*
|
||||
* @param $uniacid
|
||||
* @return array
|
||||
* @author shuixian
|
||||
* @DataTime: 2019/12/20 13:39
|
||||
*/
|
||||
public function getAuthList($uniacid){
|
||||
$denyAdminMenuKeys = [] ;
|
||||
|
||||
|
||||
if(empty($uniacid)){
|
||||
return $denyAdminMenuKeys ;
|
||||
}
|
||||
|
||||
$adminModelListInfo = config('app.AdminModelList') ;
|
||||
$saas_auth_admin_model_list = $adminModelListInfo['saas_auth_admin_model_list'];
|
||||
|
||||
foreach ($saas_auth_admin_model_list as $key=>$item) {
|
||||
|
||||
$className = 'Permission' . ucfirst($key);
|
||||
$permissionPath = APP_PATH . $key . '/info/' . $className . '.php';
|
||||
if (file_exists($permissionPath) && require_once($permissionPath)) {
|
||||
|
||||
$permissionClassName = 'app\\' . $key . '\\info\\'. $className;
|
||||
$permission = new $permissionClassName($uniacid , $item);
|
||||
|
||||
if ( $permission->pAuth() && !empty($permission->adminMenuKey)) {
|
||||
$denyAdminMenuKeys[$key] = $item;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $denyAdminMenuKeys ;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user