SiteController.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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\LoggerTool;
  10. use common\helpers\snowflake\PageSnowFake;
  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. $regTypes = RegType::getTypes();
  67. // 类型
  68. $dealTypes = DealType::getAllTypes();
  69. // 体系
  70. $systems = UserSystem::getAllSystems();
  71. // 菜单
  72. $menu = require Yii::getAlias('@backendApi/config/menu.php');
  73. $menu = $this->_childMenu($menu);
  74. // 管理员角色
  75. $adminRoles = Cache::getAdminRole();
  76. // 超级管理员角色ID
  77. $superAdminRoleId = Yii::$app->params['superAdminRoleId'];
  78. // 时间差
  79. $daysDiff = Yii::$app->params['daysDiff'];
  80. // 钱包
  81. $shopWalletType = Yii::$app->params['shopWalletType'];
  82. // 全部报单中心角色
  83. $decRoles = DecRole::find()->where('1=1')->select('ID,ROLE_NAME')->indexBy('ID')->asArray()->all();
  84. // 全部子公司
  85. $subCompanies = [];
  86. // 全部会员状态
  87. $allStatus = Yii::$app->params['userStatus'];
  88. // 全部银行
  89. $allOpenBank = OpenBank::find()->where('1=1 AND STATUS=1')->select('BANK_NAME,BANK_CODE')->indexBy('BANK_CODE')->asArray()->all();
  90. // 钱包
  91. $allNation = Yii::$app->params['nation'];
  92. // 期数
  93. $period = Period::instance();
  94. $periodNum = $period->getNowPeriodNum();
  95. return [
  96. 'decLevels' => $decLevels,
  97. 'empLevels' => $empLevels,
  98. 'regTypes' => $regTypes,
  99. 'dealTypes' => $dealTypes,
  100. 'systems' => $systems,
  101. 'menu' => $menu,
  102. 'adminRoles' => $adminRoles,
  103. 'superAdminRoleId' => $superAdminRoleId,
  104. 'daysDiff' => $daysDiff,
  105. 'shopWalletType' => $shopWalletType,
  106. 'decRoles' => $decRoles,
  107. 'subCompanies' => $subCompanies,
  108. 'allStatus' => $allStatus,
  109. 'allOpenBank' => $allOpenBank,
  110. 'allNation' => $allNation,
  111. 'nowPeriodNum' => $periodNum,
  112. ];
  113. }
  114. private function _childMenu($parentArray){
  115. $menuResult = [];
  116. foreach($parentArray as $key => $parentMenu){
  117. // 菜单是否显示
  118. if(isset($parentMenu['show']) && !$parentMenu['show']){
  119. continue;
  120. }
  121. // 查看是否有该控制器的权限
  122. if(isset($parentMenu['controller']) && $parentMenu['controller']){
  123. if(!Yii::$app->user->validateAdminController($parentMenu['controller'])) continue;
  124. }
  125. // 查看是否有权限
  126. if(isset($parentMenu['action']) && $parentMenu['action']){
  127. if(!Yii::$app->user->validateAdminAction($parentMenu['controller'], $parentMenu['action'])) continue;
  128. }
  129. // 子菜单同样设置
  130. if(isset($parentMenu['child']) && !empty($parentMenu['child'])){
  131. $parentMenu['child'] = $this->_childMenu($parentMenu['child']);
  132. }
  133. // 如果在白名单的不显示菜单
  134. if(isset($parentMenu['controller']) && $parentMenu['controller']){
  135. if(Yii::$app->user->noCheckAdminController($parentMenu['controller'])) continue;
  136. }
  137. $menuResult[] = $parentMenu;
  138. }
  139. return $menuResult;
  140. }
  141. /**
  142. * 发送钉钉测试信息
  143. * @return mixed
  144. * @throws \yii\web\HttpException
  145. */
  146. public function actionSendNotice()
  147. {
  148. $data = [
  149. 'code' => 400,
  150. 'message' => 'autoSendDingTalk',
  151. ];
  152. return static::notice(['data' => $data['bug监控正常运行,没有发现异常.']]);
  153. }
  154. public function actionClearLoginFailedNum()
  155. {
  156. $adminName = \Yii::$app->request->get('adminName');
  157. $loginFailNums = Yii::$app->redis->get('FAIL_NUMS:' . $adminName) ?? 0;
  158. \Yii::$app->redis->del('FAIL_NUMS:' . $adminName);
  159. LoggerTool::error(sprintf('tmp_log_fail_nums_del, adminName: %s', $adminName));
  160. $loginFailNumsNie = Yii::$app->redis->get('FAIL_NUMS:' . $adminName) ?? 0;
  161. return static::notice(['data' => sprintf('登陆失败次数清空. 失败次数:%d -> %d', $loginFailNums, $loginFailNumsNie)]);
  162. }
  163. public function actionOpenBackendIpFilter()
  164. {
  165. \Yii::$app->redis->set('backend_ip_filter', 1);
  166. return static::notice(['data' => '开启后台IP过滤']);
  167. }
  168. public function actionCloseBackendIpFilter()
  169. {
  170. \Yii::$app->redis->del('backend_ip_filter');
  171. return static::notice(['data' => '关闭后台IP过滤']);
  172. }
  173. public function actionOpenMemberIpFilter()
  174. {
  175. \Yii::$app->redis->set('member_ip_filter', 1);
  176. return static::notice(['data' => '开启会员IP过滤']);
  177. }
  178. public function actionCloseMemberIpFilter()
  179. {
  180. \Yii::$app->redis->del('member_ip_filter');
  181. return static::notice(['data' => '关闭会员IP过滤']);
  182. }
  183. }