SiteController.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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\CurrencyConversions;
  12. use common\models\DealType;
  13. use common\models\Period;
  14. use common\models\RegType;
  15. use common\models\DecRole;
  16. use common\models\OpenBank;
  17. use common\models\UserSystem;
  18. use Yii;
  19. use backendApi\modules\v1\models\User;
  20. use common\helpers\Cache;
  21. class SiteController extends BaseController
  22. {
  23. public $modelClass = User::class;
  24. public function behaviors() {
  25. $behaviors = parent::behaviors();
  26. //$behaviors['contentNegotiator']['formats']['text/html'] = Response::FORMAT_JSON;
  27. return $behaviors;
  28. }
  29. public function actions()
  30. {
  31. $actions = parent::actions();
  32. $actions['captcha'] = [
  33. 'class' => 'common\helpers\CaptchaAction',
  34. 'width' => 120,
  35. 'height' => 40,
  36. 'padding' => 0,
  37. 'minLength' => 4,
  38. 'maxLength' => 4,
  39. 'offset'=>8, //设置字符偏移量 有效果
  40. 'testLimit'=>1,
  41. ];
  42. return $actions;
  43. }
  44. /**
  45. * 请求服务器时间差
  46. * @return mixed
  47. * @throws \yii\web\HttpException
  48. */
  49. public function actionDaysDiff(){
  50. return static::notice(['daysDiff'=>Yii::$app->params['daysDiff']]);
  51. }
  52. /**
  53. * 请求页面数据
  54. * @return mixed
  55. * @throws \yii\web\HttpException
  56. */
  57. public function actionPageData() {
  58. $pageId = PageSnowFake::instance()->generateId();
  59. return static::notice(['pageId'=>$pageId]);
  60. }
  61. public function actionBaseInfo(){
  62. // 会员级别
  63. $decLevels = Cache::getDecLevelConfig();
  64. // 管理星级
  65. $empLevels = Cache::getEmpLevelConfig();
  66. // 注册类型
  67. $regTypes = Cache::getRegType();
  68. // 交易类型
  69. $dealTypes = Cache::getDealType();
  70. // 体系
  71. $systems = [];
  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 = Tool::paramConvert(Yii::$app->params['shopWalletType']);
  83. // 报单中心角色
  84. $decRoles = Cache::getDecRoleConfig();
  85. // 子公司
  86. $subCompanies = [];
  87. // 会员状态
  88. $allStatus = Tool::paramConvert(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. 'regTypes' => $regTypes,
  102. 'dealTypes' => $dealTypes,
  103. 'systems' => $systems,
  104. 'menu' => $menu,
  105. 'adminRoles' => $adminRoles,
  106. 'superAdminRoleId' => $superAdminRoleId,
  107. 'daysDiff' => $daysDiff,
  108. 'shopWalletType' => $shopWalletType,
  109. 'decRoles' => $decRoles,
  110. 'subCompanies' => $subCompanies,
  111. 'allStatus' => $allStatus,
  112. 'allOpenBank' => $allOpenBank,
  113. 'allNation' => $allNation,
  114. 'nowPeriodNum' => $periodNum,
  115. 'exchangeRate' => $exchangeRate,
  116. ];
  117. }
  118. private function _childMenu($parentArray){
  119. $menuResult = [];
  120. foreach($parentArray as $key => $parentMenu){
  121. // 菜单是否显示
  122. if(isset($parentMenu['show']) && !$parentMenu['show']){
  123. continue;
  124. }
  125. // 查看是否有该控制器的权限
  126. if(isset($parentMenu['controller']) && $parentMenu['controller']){
  127. if(!Yii::$app->user->validateAdminController($parentMenu['controller'])) continue;
  128. }
  129. // 查看是否有权限
  130. if(isset($parentMenu['action']) && $parentMenu['action']){
  131. if(!Yii::$app->user->validateAdminAction($parentMenu['controller'], $parentMenu['action'])) continue;
  132. }
  133. // 子菜单同样设置
  134. if(isset($parentMenu['child']) && !empty($parentMenu['child'])){
  135. $parentMenu['child'] = $this->_childMenu($parentMenu['child']);
  136. }
  137. // 如果在白名单的不显示菜单
  138. if(isset($parentMenu['controller']) && $parentMenu['controller']){
  139. if(Yii::$app->user->noCheckAdminController($parentMenu['controller'])) continue;
  140. }
  141. $menuResult[] = $parentMenu;
  142. }
  143. return $menuResult;
  144. }
  145. /**
  146. * 发送钉钉测试信息
  147. * @return mixed
  148. * @throws \yii\web\HttpException
  149. */
  150. public function actionSendNotice()
  151. {
  152. $data = [
  153. 'code' => 400,
  154. 'message' => 'autoSendDingTalk',
  155. ];
  156. return static::notice(['data' => $data['bug监控正常运行,没有发现异常.']]);
  157. }
  158. public function actionSendNotify()
  159. {
  160. $message = Yii::$app->request->get('message', '收到信息了');
  161. $data = ['message' => $message];
  162. return static::notice($data);
  163. }
  164. public function actionCountries()
  165. {
  166. // 国家
  167. $countries = Cache::getCountries();
  168. // 货币
  169. $currencies = Cache::getCurrencies();
  170. $currencies = array_column($currencies, NULL, 'ID');
  171. // 货币汇率
  172. $currenciesConversions = CurrencyConversions::getFromCache();
  173. $currenciesConversions = array_column($currenciesConversions, NULL, 'TO_CURRENCY_ID');
  174. foreach ($countries as &$country) {
  175. $country['LOCAL_CURRENCY_NAME'] = $currencies[$country['LOCAL_CURRENCY_ID']]['NAME'] ?? '';
  176. $country['CURRENCY_PRODUCT_RATE'] = $currenciesConversions[$country['LOCAL_CURRENCY_ID']]['PRODUCT_RATE'] ?? 0;
  177. }
  178. return static::notice(['data' => $countries]);
  179. }
  180. public function actionLanguages()
  181. {
  182. // 语言列表
  183. $data = Cache::getLanguages();
  184. return static::notice(['data' => $data]);
  185. }
  186. public function actionBanks()
  187. {
  188. // 默认国家
  189. $countryId = \Yii::$app->request->get('countryId');
  190. if (!$countryId) {
  191. return static::notice(Yii::t('app', 'countryDoesNotSelect'), 400);
  192. }
  193. $data = OpenBank::find()
  194. ->where('STATUS=:STATUS AND COUNTRY_ID=:COUNTRY_ID', [':STATUS' => 1, ':COUNTRY_ID' => $countryId])
  195. ->orderBy('BANK_NAME ASC')
  196. ->asArray()
  197. ->all();
  198. return static::notice(['data' => $data]);
  199. }
  200. }