SiteController.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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\snowflake\PageSnowFake;
  11. use common\helpers\Tool;
  12. use common\models\CurrencyConversions;
  13. use common\models\DealType;
  14. use common\models\Period;
  15. use common\models\RegType;
  16. use common\models\DecRole;
  17. use common\models\OpenBank;
  18. use common\models\UserSystem;
  19. use Yii;
  20. use backendApi\modules\v1\models\User;
  21. use common\helpers\Cache;
  22. class SiteController extends BaseController
  23. {
  24. public $modelClass = User::class;
  25. public function behaviors() {
  26. return parent::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. // Elite级别
  66. $eliteLevels = Cache::getEliteLevelConfig();
  67. // 注册类型
  68. $regTypes = Cache::getRegType();
  69. // 交易类型
  70. $dealTypes = Cache::getDealType();
  71. // 体系
  72. $systems = [];
  73. // 菜单
  74. $menu = require Yii::getAlias('@backendApi/config/menu.php');
  75. $menu = $this->_childMenu($menu);
  76. // 管理员角色
  77. $adminRoles = Cache::getAdminRole();
  78. // 超级管理员角色ID
  79. $superAdminRoleId = Yii::$app->params['superAdminRoleId'];
  80. // 时间差
  81. $daysDiff = Yii::$app->params['daysDiff'];
  82. // 钱包
  83. $shopWalletType = Tool::paramConvert(Yii::$app->params['shopWalletType']);
  84. // 报单中心角色
  85. $decRoles = Cache::getDecRoleConfig();
  86. // 子公司
  87. $subCompanies = [];
  88. // 会员状态
  89. $allStatus = Tool::paramConvert(Yii::$app->params['userStatus']);
  90. // 全部银行
  91. $allOpenBank = OpenBank::find()->where('1=1 AND STATUS=1')->select('BANK_NAME,BANK_CODE')->indexBy('BANK_CODE')->asArray()->all();
  92. // 民族
  93. $allNation = Yii::$app->params['nation'];
  94. // 期数
  95. $period = Period::instance();
  96. $periodNum = $period->getNowPeriodNum();
  97. // 汇率
  98. $exchangeRate = floatval(Cache::getSystemConfig()['exchangeRate']['VALUE'] ?? 0);
  99. return [
  100. 'decLevels' => $decLevels,
  101. 'empLevels' => $empLevels,
  102. 'eliteLevels' => $eliteLevels,
  103. 'regTypes' => $regTypes,
  104. 'dealTypes' => $dealTypes,
  105. 'systems' => $systems,
  106. 'menu' => $menu,
  107. 'adminRoles' => $adminRoles,
  108. 'superAdminRoleId' => $superAdminRoleId,
  109. 'daysDiff' => $daysDiff,
  110. 'shopWalletType' => $shopWalletType,
  111. 'decRoles' => $decRoles,
  112. 'subCompanies' => $subCompanies,
  113. 'allStatus' => $allStatus,
  114. 'allOpenBank' => $allOpenBank,
  115. 'allNation' => $allNation,
  116. 'nowPeriodNum' => $periodNum,
  117. 'exchangeRate' => $exchangeRate,
  118. ];
  119. }
  120. private function _childMenu($parentArray){
  121. $menuResult = [];
  122. foreach($parentArray as $key => $parentMenu){
  123. // 菜单是否显示
  124. if(isset($parentMenu['show']) && !$parentMenu['show']){
  125. continue;
  126. }
  127. // 查看是否有该控制器的权限
  128. if(isset($parentMenu['controller']) && $parentMenu['controller']){
  129. if(!Yii::$app->user->validateAdminController($parentMenu['controller'])) continue;
  130. }
  131. // 查看是否有权限
  132. if(isset($parentMenu['action']) && $parentMenu['action']){
  133. if(!Yii::$app->user->validateAdminAction($parentMenu['controller'], $parentMenu['action'])) continue;
  134. }
  135. // 子菜单同样设置
  136. if(isset($parentMenu['child']) && !empty($parentMenu['child'])){
  137. $parentMenu['child'] = $this->_childMenu($parentMenu['child']);
  138. }
  139. // 如果在白名单的不显示菜单
  140. if(isset($parentMenu['controller']) && $parentMenu['controller']){
  141. if(Yii::$app->user->noCheckAdminController($parentMenu['controller'])) continue;
  142. }
  143. $menuResult[] = $parentMenu;
  144. }
  145. return $menuResult;
  146. }
  147. /**
  148. * 发送钉钉测试信息
  149. * @return mixed
  150. * @throws \yii\web\HttpException
  151. */
  152. public function actionSendNotice()
  153. {
  154. $data = [
  155. 'code' => 400,
  156. 'message' => 'autoSendDingTalk',
  157. ];
  158. return static::notice(['data' => $data['bug监控正常运行,没有发现异常.']]);
  159. }
  160. public function actionSendNotify()
  161. {
  162. $message = Yii::$app->request->get('message', '收到信息了');
  163. $data = ['message' => $message];
  164. return static::notice($data);
  165. }
  166. public function actionCountries()
  167. {
  168. // 国家
  169. $countries = Cache::getCountries();
  170. if (\Yii::$app->request->hasProperty('filter')) {
  171. $filter = \Yii::$app->request->get('filter');
  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. foreach ($countries as $key => $country) {
  177. if (!in_array($country['ID'], $adminCountry)) {
  178. unset($countries[$key]);
  179. }
  180. }
  181. }
  182. }
  183. // 货币
  184. $currencies = Cache::getCurrencies();
  185. $currencies = array_column($currencies, NULL, 'ID');
  186. // 货币汇率
  187. $currenciesConversions = CurrencyConversions::getFromCache();
  188. $currenciesConversions = array_column($currenciesConversions, NULL, 'TO_CURRENCY_ID');
  189. foreach ($countries as &$country) {
  190. $country['LOCAL_CURRENCY_NAME'] = $currencies[$country['LOCAL_CURRENCY_ID']]['NAME'] ?? '';
  191. $country['CURRENCY_PRODUCT_RATE'] = $currenciesConversions[$country['LOCAL_CURRENCY_ID']]['PRODUCT_RATE'] ?? 0;
  192. }
  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. }