SiteController.php 7.2 KB

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