SiteController.php 11 KB

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