SiteController.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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. return parent::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. // Elite级别
  65. $eliteLevels = Cache::getEliteLevelConfig();
  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. 'eliteLevels' => $eliteLevels,
  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. public function actionSendNotify()
  160. {
  161. $message = Yii::$app->request->get('message', '收到信息了');
  162. $data = ['message' => $message];
  163. return static::notice($data);
  164. }
  165. public function actionCountries()
  166. {
  167. // 国家
  168. $countries = Cache::getCountries();
  169. // 货币
  170. $currencies = Cache::getCurrencies();
  171. $currencies = array_column($currencies, NULL, 'ID');
  172. // 货币汇率
  173. $currenciesConversions = CurrencyConversions::getFromCache();
  174. $currenciesConversions = array_column($currenciesConversions, NULL, 'TO_CURRENCY_ID');
  175. foreach ($countries as &$country) {
  176. $country['LOCAL_CURRENCY_NAME'] = $currencies[$country['LOCAL_CURRENCY_ID']]['NAME'] ?? '';
  177. $country['CURRENCY_PRODUCT_RATE'] = $currenciesConversions[$country['LOCAL_CURRENCY_ID']]['PRODUCT_RATE'] ?? 0;
  178. }
  179. return static::notice(['data' => $countries]);
  180. }
  181. public function actionLanguages()
  182. {
  183. // 语言列表
  184. $data = Cache::getLanguages();
  185. return static::notice(['data' => $data]);
  186. }
  187. public function actionBanks()
  188. {
  189. // 默认国家
  190. $countryId = \Yii::$app->request->get('countryId');
  191. if (!$countryId) {
  192. return static::notice(Yii::t('app', 'countryDoesNotSelect'), 400);
  193. }
  194. $data = OpenBank::find()
  195. ->where('STATUS=:STATUS AND COUNTRY_ID=:COUNTRY_ID', [':STATUS' => 1, ':COUNTRY_ID' => $countryId])
  196. ->orderBy('BANK_NAME ASC')
  197. ->asArray()
  198. ->all();
  199. return static::notice(['data' => $data]);
  200. }
  201. }