SiteController.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: leo
  5. * Date: 2018/2/24
  6. * Time: 下午12:48
  7. */
  8. namespace backendApi\modules\v1\controllers;
  9. use common\helpers\snowflake\PageSnowFake;
  10. use common\models\DealType;
  11. use common\models\Period;
  12. use common\models\RegType;
  13. use common\models\DecRole;
  14. use common\models\OpenBank;
  15. use common\models\UserSystem;
  16. use Yii;
  17. use backendApi\modules\v1\models\User;
  18. use common\helpers\Cache;
  19. class SiteController extends BaseController
  20. {
  21. public $modelClass = User::class;
  22. public function behaviors() {
  23. $behaviors = parent::behaviors();
  24. //$behaviors['contentNegotiator']['formats']['text/html'] = Response::FORMAT_JSON;
  25. return $behaviors;
  26. }
  27. public function actions()
  28. {
  29. $actions = parent::actions();
  30. $actions['captcha'] = [
  31. 'class' => 'common\helpers\CaptchaAction',
  32. 'width' => 120,
  33. 'height' => 40,
  34. 'padding' => 0,
  35. 'minLength' => 4,
  36. 'maxLength' => 4,
  37. 'offset'=>8, //设置字符偏移量 有效果
  38. 'testLimit'=>1,
  39. ];
  40. return $actions;
  41. }
  42. /**
  43. * 请求服务器时间差
  44. * @return mixed
  45. * @throws \yii\web\HttpException
  46. */
  47. public function actionDaysDiff(){
  48. return static::notice(['daysDiff'=>Yii::$app->params['daysDiff']]);
  49. }
  50. /**
  51. * 请求页面数据
  52. * @return mixed
  53. * @throws \yii\web\HttpException
  54. */
  55. public function actionPageData() {
  56. $pageId = PageSnowFake::instance()->generateId();
  57. return static::notice(['pageId'=>$pageId]);
  58. }
  59. public function actionBaseInfo(){
  60. // 会员级别
  61. $decLevels = Cache::getDecLevelConfig();
  62. // 聘级
  63. $empLevels = Cache::getEmpLevelConfig();
  64. // 注册类型
  65. $regTypes = RegType::getTypes();
  66. // 类型
  67. $dealTypes = DealType::getAllTypes();
  68. // 体系
  69. $systems = UserSystem::getAllSystems();
  70. // 菜单
  71. $menu = require Yii::getAlias('@backendApi/config/menu.php');
  72. $menu = $this->_childMenu($menu);
  73. // 管理员角色
  74. $adminRoles = Cache::getAdminRole();
  75. // 超级管理员角色ID
  76. $superAdminRoleId = Yii::$app->params['superAdminRoleId'];
  77. // 时间差
  78. $daysDiff = Yii::$app->params['daysDiff'];
  79. // 钱包
  80. $shopWalletType = Yii::$app->params['shopWalletType'];
  81. // 全部报单中心角色
  82. $decRoles = DecRole::find()->where('1=1')->select('ID,ROLE_NAME')->indexBy('ID')->asArray()->all();
  83. // 全部子公司
  84. $subCompanies = [];
  85. // 全部会员状态
  86. $allStatus = Yii::$app->params['userStatus'];
  87. // 全部银行
  88. $allOpenBank = OpenBank::find()->where('1=1 AND STATUS=1')->select('BANK_NAME,BANK_CODE')->indexBy('BANK_CODE')->asArray()->all();
  89. // 钱包
  90. $allNation = Yii::$app->params['nation'];
  91. // 期数
  92. $period = Period::instance();
  93. $periodNum = $period->getNowPeriodNum();
  94. // 汇率
  95. $exchangeRate = floatval(Cache::getSystemConfig()['exchangeRate']['VALUE'] ?? 0);
  96. return [
  97. 'decLevels' => $decLevels,
  98. 'empLevels' => $empLevels,
  99. 'regTypes' => $regTypes,
  100. 'dealTypes' => $dealTypes,
  101. 'systems' => $systems,
  102. 'menu' => $menu,
  103. 'adminRoles' => $adminRoles,
  104. 'superAdminRoleId' => $superAdminRoleId,
  105. 'daysDiff' => $daysDiff,
  106. 'shopWalletType' => $shopWalletType,
  107. 'decRoles' => $decRoles,
  108. 'subCompanies' => $subCompanies,
  109. 'allStatus' => $allStatus,
  110. 'allOpenBank' => $allOpenBank,
  111. 'allNation' => $allNation,
  112. 'nowPeriodNum' => $periodNum,
  113. 'exchangeRate' => $exchangeRate,
  114. ];
  115. }
  116. private function _childMenu($parentArray){
  117. $menuResult = [];
  118. foreach($parentArray as $key => $parentMenu){
  119. // 菜单是否显示
  120. if(isset($parentMenu['show']) && !$parentMenu['show']){
  121. continue;
  122. }
  123. // 查看是否有该控制器的权限
  124. if(isset($parentMenu['controller']) && $parentMenu['controller']){
  125. if(!Yii::$app->user->validateAdminController($parentMenu['controller'])) continue;
  126. }
  127. // 查看是否有权限
  128. if(isset($parentMenu['action']) && $parentMenu['action']){
  129. if(!Yii::$app->user->validateAdminAction($parentMenu['controller'], $parentMenu['action'])) continue;
  130. }
  131. // 子菜单同样设置
  132. if(isset($parentMenu['child']) && !empty($parentMenu['child'])){
  133. $parentMenu['child'] = $this->_childMenu($parentMenu['child']);
  134. }
  135. // 如果在白名单的不显示菜单
  136. if(isset($parentMenu['controller']) && $parentMenu['controller']){
  137. if(Yii::$app->user->noCheckAdminController($parentMenu['controller'])) continue;
  138. }
  139. $menuResult[] = $parentMenu;
  140. }
  141. return $menuResult;
  142. }
  143. }