SiteController.php 5.8 KB

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