SiteController.php 5.6 KB

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