SiteController.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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. $crownLevels = Cache::getStarCrownLevelConfig();
  66. // 注册类型
  67. $regTypes = RegType::getTypes();
  68. // 类型
  69. $dealTypes = DealType::getAllTypes();
  70. // 体系
  71. $systems = UserSystem::getAllSystems();
  72. // 菜单
  73. $menu = require Yii::getAlias('@backendApi/config/menu.php');
  74. $menu = $this->_childMenu($menu);
  75. // 管理员角色
  76. $adminRoles = Cache::getAdminRole();
  77. // 超级管理员角色ID
  78. $superAdminRoleId = Yii::$app->params['superAdminRoleId'];
  79. // 时间差
  80. $daysDiff = Yii::$app->params['daysDiff'];
  81. // 钱包
  82. $shopWalletType = Yii::$app->params['shopWalletType'];
  83. // 全部报单中心角色
  84. $decRoles = DecRole::find()->where('1=1')->select('ID,ROLE_NAME')->indexBy('ID')->asArray()->all();
  85. // 全部子公司
  86. $subCompanies = [];
  87. // 全部会员状态
  88. $allStatus = Yii::$app->params['userStatus'];
  89. // 全部银行
  90. $allOpenBank = OpenBank::find()->where('1=1 AND STATUS=1')->select('BANK_NAME,BANK_CODE')->indexBy('BANK_CODE')->asArray()->all();
  91. // 钱包
  92. $allNation = Yii::$app->params['nation'];
  93. // 期数
  94. $period = Period::instance();
  95. $periodNum = $period->getNowPeriodNum();
  96. // 汇率
  97. $exchangeRate = floatval(Cache::getSystemConfig()['exchangeRate']['VALUE'] ?? 0);
  98. return [
  99. 'decLevels' => $decLevels,
  100. 'empLevels' => $empLevels,
  101. 'crownLevels' => $crownLevels,
  102. 'regTypes' => $regTypes,
  103. 'dealTypes' => $dealTypes,
  104. 'systems' => $systems,
  105. 'menu' => $menu,
  106. 'adminRoles' => $adminRoles,
  107. 'superAdminRoleId' => $superAdminRoleId,
  108. 'daysDiff' => $daysDiff,
  109. 'shopWalletType' => $shopWalletType,
  110. 'decRoles' => $decRoles,
  111. 'subCompanies' => $subCompanies,
  112. 'allStatus' => $allStatus,
  113. 'allOpenBank' => $allOpenBank,
  114. 'allNation' => $allNation,
  115. 'nowPeriodNum' => $periodNum,
  116. 'exchangeRate' => $exchangeRate,
  117. ];
  118. }
  119. private function _childMenu($parentArray){
  120. $menuResult = [];
  121. foreach($parentArray as $key => $parentMenu){
  122. // 菜单是否显示
  123. if(isset($parentMenu['show']) && !$parentMenu['show']){
  124. continue;
  125. }
  126. // 查看是否有该控制器的权限
  127. if(isset($parentMenu['controller']) && $parentMenu['controller']){
  128. if(!Yii::$app->user->validateAdminController($parentMenu['controller'])) continue;
  129. }
  130. // 查看是否有权限
  131. if(isset($parentMenu['action']) && $parentMenu['action']){
  132. if(!Yii::$app->user->validateAdminAction($parentMenu['controller'], $parentMenu['action'])) continue;
  133. }
  134. // 子菜单同样设置
  135. if(isset($parentMenu['child']) && !empty($parentMenu['child'])){
  136. $parentMenu['child'] = $this->_childMenu($parentMenu['child']);
  137. }
  138. // 如果在白名单的不显示菜单
  139. if(isset($parentMenu['controller']) && $parentMenu['controller']){
  140. if(Yii::$app->user->noCheckAdminController($parentMenu['controller'])) continue;
  141. }
  142. $menuResult[] = $parentMenu;
  143. }
  144. return $menuResult;
  145. }
  146. /**
  147. * 发送钉钉测试信息
  148. * @return mixed
  149. * @throws \yii\web\HttpException
  150. */
  151. public function actionSendNotice()
  152. {
  153. $data = [
  154. 'code' => 400,
  155. 'message' => 'autoSendDingTalk',
  156. ];
  157. return static::notice(['data' => $data['bug监控正常运行,没有发现异常.']]);
  158. }
  159. }