SiteController.php 9.0 KB

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