SiteController.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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\models\AdminCountry;
  10. use common\helpers\LoggerTool;
  11. use common\helpers\snowflake\PageSnowFake;
  12. use common\helpers\Tool;
  13. use common\models\CurrencyConversions;
  14. use common\models\DealType;
  15. use common\models\Period;
  16. use common\models\RegType;
  17. use common\models\DecRole;
  18. use common\models\OpenBank;
  19. use common\models\UserSystem;
  20. use Yii;
  21. use backendApi\modules\v1\models\User;
  22. use common\helpers\Cache;
  23. class SiteController extends BaseController
  24. {
  25. public $modelClass = User::class;
  26. public function behaviors() {
  27. return parent::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. // Elite级别
  67. $eliteLevels = Cache::getEliteLevelConfig();
  68. // 注册类型
  69. $regTypes = Cache::getRegType();
  70. // 交易类型
  71. $dealTypes = Cache::getDealType();
  72. // 体系
  73. $systems = [];
  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. 'eliteLevels' => $eliteLevels,
  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. public function actionSendNotify()
  162. {
  163. $message = Yii::$app->request->get('message', '收到信息了');
  164. $data = ['message' => $message];
  165. return static::notice($data);
  166. }
  167. public function actionCountries()
  168. {
  169. // 国家
  170. $countries = Cache::getCountries();
  171. $filter = \Yii::$app->request->get('filter', 0);
  172. if ($filter) {
  173. $adminId = Yii::$app->getUser()->getUserInfo()['id'];
  174. $adminCountry = AdminCountry::getCountry($adminId);
  175. $countries = array_filter($countries, fn($country) => in_array($country['ID'], $adminCountry));
  176. $countries = array_values($countries);
  177. }
  178. // 货币
  179. $currencies = Cache::getCurrencies();
  180. $currencies = array_column($currencies, NULL, 'ID');
  181. // 货币汇率
  182. $currenciesConversions = CurrencyConversions::getFromCache();
  183. $currenciesConversions = array_column($currenciesConversions, NULL, 'TO_CURRENCY_ID');
  184. $countries = array_map(function ($country) use ($currencies, $currenciesConversions) {
  185. return array_merge(
  186. $country,
  187. [
  188. 'LOCAL_CURRENCY_NAME' => $currencies[$country['LOCAL_CURRENCY_ID']]['NAME'] ?? '',
  189. 'CURRENCY_PRODUCT_RATE' => $currenciesConversions[$country['LOCAL_CURRENCY_ID']]['PRODUCT_RATE'] ?? 0
  190. ]
  191. );
  192. }, $countries);
  193. return static::notice(['data' => $countries]);
  194. }
  195. public function actionLanguages()
  196. {
  197. // 语言列表
  198. $data = Cache::getLanguages();
  199. return static::notice(['data' => $data]);
  200. }
  201. public function actionBanks()
  202. {
  203. // 默认国家
  204. $countryId = \Yii::$app->request->get('countryId');
  205. if (!$countryId) {
  206. return static::notice(Yii::t('app', 'countryDoesNotSelect'), 400);
  207. }
  208. $data = OpenBank::find()
  209. ->where('STATUS=:STATUS AND COUNTRY_ID=:COUNTRY_ID', [':STATUS' => 1, ':COUNTRY_ID' => $countryId])
  210. ->orderBy('BANK_NAME ASC')
  211. ->asArray()
  212. ->all();
  213. return static::notice(['data' => $data]);
  214. }
  215. }