SiteController.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: leo
  5. * Date: 2018/2/24
  6. * Time: 下午12:48
  7. */
  8. namespace frontendApi\modules\v1\controllers;
  9. use common\helpers\Cache;
  10. use common\helpers\LoggerTool;
  11. use common\helpers\snowflake\PageSnowFake;
  12. use common\models\Ad;
  13. use common\models\AdLocation;
  14. use common\models\ArticleCategory;
  15. use common\models\BaUser;
  16. use common\models\DecOrder;
  17. use common\models\DecRole;
  18. use Yii;
  19. use frontendApi\modules\v1\models\User;
  20. use common\helpers\parsedown\Parsedown;
  21. class SiteController extends BaseController
  22. {
  23. public $modelClass = User::class;
  24. /**
  25. * 请求服务器时间差
  26. * @return mixed
  27. * @throws \yii\web\HttpException
  28. */
  29. public function actionDaysDiff(){
  30. return static::notice(['daysDiff'=>Yii::$app->params['daysDiff']]);
  31. }
  32. /**
  33. * 获取广告
  34. * @return mixed
  35. * @throws \yii\web\HttpException
  36. */
  37. public function actionAd(){
  38. $lid = Yii::$app->request->get('lid');
  39. $adLocation = AdLocation::findUseSlaves()->where('ID=:ID', [':ID'=>$lid])->asArray()->one();
  40. $query = Ad::findUseSlaves()->select('ID,IMAGE,LID,TITLE,CONTENT,TYPE')->where('LID=:LID AND STATUS=1', [':LID'=>$lid])->orderBy('SORT ASC')->asArray();
  41. $data = [];
  42. if($adLocation['TYPE'] == AdLocation::TYPE_SLIDE){
  43. $data = $query->all();
  44. } elseif($adLocation['TYPE'] == AdLocation::TYPE_IMAGE) {
  45. $data = $query->one();
  46. }
  47. return static::notice($data);
  48. }
  49. /**
  50. * 请求手机基础信息
  51. * @return array
  52. */
  53. public function actionMobileBaseInfo(){
  54. // 会员级别
  55. $decLevels = Cache::getDecLevelConfig();
  56. // 聘级
  57. $empLevels = Cache::getEmpLevelConfig();
  58. // 时间差
  59. $daysDiff = Yii::$app->params['daysDiff'];
  60. // 钱包
  61. $shopWalletType = Yii::$app->params['shopWalletType'];
  62. return [
  63. 'decLevels' => $decLevels,
  64. 'empLevels' => $empLevels,
  65. 'daysDiff' => $daysDiff,
  66. 'shopWalletType' => $shopWalletType,
  67. ];
  68. }
  69. public function actions()
  70. {
  71. $actions = parent::actions();
  72. $actions['captcha'] = [
  73. 'class' => 'common\helpers\CaptchaAction',
  74. 'width' => 120,
  75. 'height' => 40,
  76. 'padding' => 0,
  77. 'minLength' => 4,
  78. 'maxLength' => 4,
  79. 'offset'=>8, //设置字符偏移量 有效果
  80. 'testLimit'=>1,
  81. ];
  82. return $actions;
  83. }
  84. /**
  85. * 请求页面数据
  86. * @return mixed
  87. * @throws \yii\web\HttpException
  88. */
  89. public function actionPageData() {
  90. $pageId = PageSnowFake::instance()->generateId();
  91. return static::notice(['pageId'=>$pageId]);
  92. }
  93. /**
  94. * 请求基础信息
  95. * @return array
  96. */
  97. public function actionBaseInfo(){
  98. // 会员级别
  99. $decLevels = Cache::getDecLevelConfig();
  100. // 聘级
  101. $empLevels = Cache::getEmpLevelConfig();
  102. // 菜单
  103. $menu = require Yii::getAlias('@frontendApi/config/menu.php');
  104. // 获取全部文章分类
  105. $allArticleCategory = ArticleCategory::getAllCategory();
  106. foreach($allArticleCategory as $category){
  107. $menu['article']['child'][] = ['name'=>$category['CATE_NAME'], 'class'=>'', 'icon'=>'', 'controller'=>'article', 'action'=>'list', 'routePath'=>'article/list/'.$category['ID'], 'show'=>1,];
  108. }
  109. $menu = $this->_childMenu($menu);
  110. // 时间差
  111. $daysDiff = Yii::$app->params['daysDiff'];
  112. // 钱包
  113. $shopWalletType = Yii::$app->params['shopWalletType'];
  114. return [
  115. 'decLevels' => $decLevels,
  116. 'empLevels' => $empLevels,
  117. 'menu' => $menu,
  118. 'daysDiff' => $daysDiff,
  119. 'shopWalletType' => $shopWalletType,
  120. 'whetherBA' => false,
  121. ];
  122. }
  123. private function _childMenu($parentArray){
  124. $menuResult = [];
  125. foreach($parentArray as $key => $parentMenu){
  126. if($key !== 'article'){
  127. // 菜单是否显示
  128. if(isset($parentMenu['show']) && !$parentMenu['show']){
  129. continue;
  130. }
  131. if($this->_teamworkChkMenu($parentMenu)){
  132. continue;
  133. }
  134. if($this->_decChkMenu($parentMenu)){
  135. continue;
  136. }
  137. // 查看是否有该控制器的权限
  138. if(isset($parentMenu['controller']) && $parentMenu['controller']){
  139. if(!Yii::$app->user->validateUserController($parentMenu['controller'])) continue;
  140. }
  141. // 查看是否有权限
  142. if(isset($parentMenu['action']) && $parentMenu['action']){
  143. if(!Yii::$app->user->validateUserAction($parentMenu['controller'], $parentMenu['action'])) continue;
  144. }
  145. // 子菜单同样设置
  146. if(isset($parentMenu['child']) && !empty($parentMenu['child'])){
  147. $parentMenu['child'] = $this->_childMenu($parentMenu['child']);
  148. }
  149. }
  150. $menuResult[] = $parentMenu;
  151. }
  152. return $menuResult;
  153. }
  154. /**
  155. * 虚拟会员hz解决暂写死
  156. * @param $menu
  157. * @return bool
  158. */
  159. private function _teamworkChkMenu($menu){
  160. if (User::getEnCodeInfo(\Yii::$app->user->id)['IS_UNION']==1) {
  161. if(in_array($menu['routePath'],['dashboard/index','user','user/index','finance','finance/index','finance/period','finance/flow-bonus','finance/withdraw'])) return true;
  162. }
  163. return false;
  164. }
  165. /**
  166. * 报单中心显示菜单
  167. * @param $menu
  168. * @return bool
  169. */
  170. private function _decChkMenu($menu) {
  171. if(!isset($menu['allow'])){
  172. return false;
  173. }
  174. if($menu['allow']=='studio'){
  175. $isStudio = User::getEnCodeInfo(\Yii::$app->user->id)['IS_STUDIO'];
  176. if($isStudio==1){
  177. return false;
  178. }
  179. }
  180. if($menu['allow']=='declarer'){
  181. $isDecReg = Cache::getSystemConfig()['isDecReg']['VALUE'];
  182. if(!$isDecReg) return false;
  183. $isDec = User::getEnCodeInfo(\Yii::$app->user->id)['IS_DEC'];
  184. if($isDec==1){
  185. return false;
  186. }
  187. }
  188. if($menu['allow']=='transferRecordSwitch'){
  189. $transferRecordSwitch = isset(Cache::getSystemConfig()['transferRecordSwitch']) ? Cache::getSystemConfig()['transferRecordSwitch']['VALUE'] : '';
  190. if($transferRecordSwitch) return false;
  191. }
  192. if($menu['allow']=='transferSwitch'){
  193. $transferSwitch = isset(Cache::getSystemConfig()['transferSwitch']) ? Cache::getSystemConfig()['transferSwitch']['VALUE'] : '';
  194. if($transferSwitch) return false;
  195. }
  196. if($menu['allow']=='pastBonusSwitch'){
  197. $pastBonusSwitch = isset(Cache::getSystemConfig()['pastBonusSwitch'])
  198. ? Cache::getSystemConfig()['pastBonusSwitch']['VALUE']
  199. : '';
  200. if($pastBonusSwitch) return false;
  201. }
  202. if($menu['allow']=='newBonusSwitch'){
  203. // ???
  204. $newBonusSwitch = isset(Cache::getSystemConfig()['newBonusSwitch'])
  205. ? Cache::getSystemConfig()['newBonusSwitch']['VALUE']
  206. : '';
  207. if($newBonusSwitch) return false;
  208. }
  209. return true;
  210. }
  211. public function actionDoc(){
  212. $docCssPath = \Yii::$app->basePath.'/libs/doc/markdown.css';
  213. $treeCssPath = \Yii::$app->basePath.'/libs/doc/tree.css';
  214. $treeJsPath = \Yii::$app->basePath.'/libs/doc/tree.js';
  215. $docfilePath = \Yii::$app->basePath.'/libs/doc/shopApiReadMe.md';
  216. $docCssStyle = file_get_contents($docCssPath);
  217. $docContent = file_get_contents($docfilePath);
  218. $treeCssStyle= file_get_contents($treeCssPath);
  219. $treeJsPath= file_get_contents($treeJsPath);
  220. $parsedown = Parsedown::instance();
  221. $result = '<!DOCTYPE html><html lang="zh-CN"><head><meta charset="UTF-8">';
  222. $result .= '<script src="http://code.jquery.com/jquery-1.7.2.min.js"></script>';
  223. $result .= "<script>{$treeJsPath}</script>";
  224. $result .= "<style>{$treeCssStyle}</style>";
  225. $result .= "<style>{$docCssStyle}</style></head>";
  226. $result .= '<body><div class="markdown-body">';
  227. $result .= $parsedown->text($docContent);
  228. $result .= '</div></body></html>';
  229. print_r($result);
  230. exit();
  231. }
  232. /**
  233. * 站点设置
  234. * @return mixed
  235. * @throws \yii\web\HttpException
  236. */
  237. public function actionConfig() {
  238. $systemConfig = Cache::getSystemConfig();
  239. if ($systemConfig['siteClose']['VALUE']) {
  240. $siteCloseInfo = $systemConfig['siteCloseInfo']['VALUE'];
  241. return static::notice(['siteClose' => true, 'siteCloseInfo' => $siteCloseInfo]);
  242. }
  243. $siteTitle = $systemConfig['siteTitle']['VALUE'];
  244. return static::notice(['siteClose' => false, 'siteTitle' => $siteTitle]);
  245. }
  246. /**
  247. * 请求基础信息
  248. * @return array
  249. */
  250. public function actionBaBaseInfo(){
  251. // 菜单
  252. $menu = require Yii::getAlias('@frontendApi/config/menuBA.php');
  253. // 获取全部文章分类
  254. $allArticleCategory = ArticleCategory::getAllCategory();
  255. foreach($allArticleCategory as $category){
  256. $menu['article']['child'][] = ['name'=>$category['CATE_NAME'], 'class'=>'', 'icon'=>'', 'controller'=>'article', 'action'=>'list', 'routePath'=>'article/list/'.$category['ID'], 'show'=>1,];
  257. }
  258. $menu = $this->_childBaMenu($menu);
  259. // 时间差
  260. $daysDiff = Yii::$app->params['daysDiff'];
  261. // 钱包
  262. $shopWalletType = Yii::$app->params['shopWalletType'];
  263. return [
  264. 'decLevels' => '',
  265. 'empLevels' => '',
  266. 'menu' => $menu,
  267. 'daysDiff' => $daysDiff,
  268. 'shopWalletType' => $shopWalletType,
  269. 'whetherBA' => true,
  270. ];
  271. }
  272. private function _childBaMenu($parentArray) {
  273. $menuResult = [];
  274. foreach ($parentArray as $key => $parentMenu) {
  275. if ($key !== 'article'){
  276. // 菜单是否显示
  277. if (isset($parentMenu['show']) && !$parentMenu['show']) {
  278. continue;
  279. }
  280. // 查看是否有该控制器的权限
  281. if(isset($parentMenu['controller']) && $parentMenu['controller']){
  282. if(!Yii::$app->user->validateUserController($parentMenu['controller'])) continue;
  283. }
  284. // 查看是否有权限
  285. if(isset($parentMenu['action']) && $parentMenu['action']){
  286. if(!Yii::$app->user->validateUserAction($parentMenu['controller'], $parentMenu['action'])) continue;
  287. }
  288. // 子菜单同样设置
  289. if(isset($parentMenu['child']) && !empty($parentMenu['child'])){
  290. $parentMenu['child'] = $this->_childBaMenu($parentMenu['child']);
  291. }
  292. }
  293. $menuResult[] = $parentMenu;
  294. }
  295. return $menuResult;
  296. }
  297. /**
  298. * 发送钉钉测试信息
  299. * @return mixed
  300. * @throws \yii\web\HttpException
  301. */
  302. public function actionSendNotice()
  303. {
  304. $data = [
  305. 'code' => 400,
  306. 'message' => 'autoSendDingTalk',
  307. ];
  308. return static::notice(['data' => $data['bug监控正常运行,没有发现异常.']]);
  309. }
  310. }