| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- <?php
- /**
- * Created by PhpStorm.
- * User: leo
- * Date: 2018/2/24
- * Time: 下午12:48
- */
- namespace backendApi\modules\v1\controllers;
- use common\helpers\snowflake\PageSnowFake;
- use common\models\DealType;
- use common\models\Period;
- use common\models\RegType;
- use common\models\DecRole;
- use common\models\OpenBank;
- use common\models\UserSystem;
- use Yii;
- use backendApi\modules\v1\models\User;
- use common\helpers\Cache;
- class SiteController extends BaseController
- {
- public $modelClass = User::class;
- public function behaviors() {
- $behaviors = parent::behaviors();
- //$behaviors['contentNegotiator']['formats']['text/html'] = Response::FORMAT_JSON;
- return $behaviors;
- }
- public function actions()
- {
- $actions = parent::actions();
- $actions['captcha'] = [
- 'class' => 'common\helpers\CaptchaAction',
- 'width' => 120,
- 'height' => 40,
- 'padding' => 0,
- 'minLength' => 4,
- 'maxLength' => 4,
- 'offset'=>8, //设置字符偏移量 有效果
- 'testLimit'=>1,
- ];
- return $actions;
- }
- /**
- * 请求服务器时间差
- * @return mixed
- * @throws \yii\web\HttpException
- */
- public function actionDaysDiff(){
- return static::notice(['daysDiff'=>Yii::$app->params['daysDiff']]);
- }
- /**
- * 请求页面数据
- * @return mixed
- * @throws \yii\web\HttpException
- */
- public function actionPageData() {
- $pageId = PageSnowFake::instance()->generateId();
- return static::notice(['pageId'=>$pageId]);
- }
- public function actionBaseInfo(){
- // 会员级别
- $decLevels = Cache::getDecLevelConfig();
- // 聘级
- $empLevels = Cache::getEmpLevelConfig();
- // 注册类型
- $regTypes = RegType::getTypes();
- // 类型
- $dealTypes = DealType::getAllTypes();
- // 体系
- $systems = UserSystem::getAllSystems();
- // 菜单
- $menu = require Yii::getAlias('@backendApi/config/menu.php');
- $menu = $this->_childMenu($menu);
- // 管理员角色
- $adminRoles = Cache::getAdminRole();
- // 超级管理员角色ID
- $superAdminRoleId = Yii::$app->params['superAdminRoleId'];
- // 时间差
- $daysDiff = Yii::$app->params['daysDiff'];
- // 钱包
- $shopWalletType = Yii::$app->params['shopWalletType'];
- // 全部报单中心角色
- $decRoles = DecRole::find()->where('1=1')->select('ID,ROLE_NAME')->indexBy('ID')->asArray()->all();
- // 全部子公司
- $subCompanies = [];
- // 全部会员状态
- $allStatus = Yii::$app->params['userStatus'];
- // 全部银行
- $allOpenBank = OpenBank::find()->where('1=1 AND STATUS=1')->select('BANK_NAME,BANK_CODE')->indexBy('BANK_CODE')->asArray()->all();
- // 钱包
- $allNation = Yii::$app->params['nation'];
- // 期数
- $period = Period::instance();
- $periodNum = $period->getNowPeriodNum();
- // 汇率
- $exchangeRate = floatval(Cache::getSystemConfig()['exchangeRate']['VALUE'] ?? 0);
- return [
- 'decLevels' => $decLevels,
- 'empLevels' => $empLevels,
- 'regTypes' => $regTypes,
- 'dealTypes' => $dealTypes,
- 'systems' => $systems,
- 'menu' => $menu,
- 'adminRoles' => $adminRoles,
- 'superAdminRoleId' => $superAdminRoleId,
- 'daysDiff' => $daysDiff,
- 'shopWalletType' => $shopWalletType,
- 'decRoles' => $decRoles,
- 'subCompanies' => $subCompanies,
- 'allStatus' => $allStatus,
- 'allOpenBank' => $allOpenBank,
- 'allNation' => $allNation,
- 'nowPeriodNum' => $periodNum,
- 'exchangeRate' => $exchangeRate,
- ];
- }
- private function _childMenu($parentArray){
- $menuResult = [];
- foreach($parentArray as $key => $parentMenu){
- // 菜单是否显示
- if(isset($parentMenu['show']) && !$parentMenu['show']){
- continue;
- }
- // 查看是否有该控制器的权限
- if(isset($parentMenu['controller']) && $parentMenu['controller']){
- if(!Yii::$app->user->validateAdminController($parentMenu['controller'])) continue;
- }
- // 查看是否有权限
- if(isset($parentMenu['action']) && $parentMenu['action']){
- if(!Yii::$app->user->validateAdminAction($parentMenu['controller'], $parentMenu['action'])) continue;
- }
- // 子菜单同样设置
- if(isset($parentMenu['child']) && !empty($parentMenu['child'])){
- $parentMenu['child'] = $this->_childMenu($parentMenu['child']);
- }
- // 如果在白名单的不显示菜单
- if(isset($parentMenu['controller']) && $parentMenu['controller']){
- if(Yii::$app->user->noCheckAdminController($parentMenu['controller'])) continue;
- }
- $menuResult[] = $parentMenu;
- }
- return $menuResult;
- }
- }
|