SiteController.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  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. // 会员类型
  113. $whetherBA = $this->_whetherBA();
  114. return [
  115. 'decLevels' => $decLevels,
  116. 'empLevels' => $empLevels,
  117. 'menu' => $menu,
  118. 'daysDiff' => $daysDiff,
  119. 'shopWalletType' => $shopWalletType,
  120. 'whetherBA' => $whetherBA,
  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. // 是否BA会员
  132. if ($this->_whetherBA()) {
  133. // BA会员展示BA菜单
  134. if (!isset($parentMenu['brandAmbassador']) || ($parentMenu['brandAmbassador'] !== 1)) {
  135. continue;
  136. }
  137. } else {
  138. // 正式会员不显示BA会员菜单
  139. if (!isset($parentMenu['isTop']) && (isset($parentMenu['brandAmbassador']) && ($parentMenu['brandAmbassador'] === 1))) {
  140. continue;
  141. }
  142. }
  143. if($this->_teamworkChkMenu($parentMenu)){
  144. continue;
  145. }
  146. if($this->_decChkMenu($parentMenu)){
  147. continue;
  148. }
  149. // 查看是否有该控制器的权限
  150. if(isset($parentMenu['controller']) && $parentMenu['controller']){
  151. if(!Yii::$app->user->validateUserController($parentMenu['controller'])) continue;
  152. }
  153. // 查看是否有权限
  154. if(isset($parentMenu['action']) && $parentMenu['action']){
  155. if(!Yii::$app->user->validateUserAction($parentMenu['controller'], $parentMenu['action'])) continue;
  156. }
  157. // 子菜单同样设置
  158. if(isset($parentMenu['child']) && !empty($parentMenu['child'])){
  159. $parentMenu['child'] = $this->_childMenu($parentMenu['child']);
  160. }
  161. }
  162. $menuResult[] = $parentMenu;
  163. }
  164. return $menuResult;
  165. }
  166. /**
  167. * 虚拟会员hz解决暂写死
  168. * @param $menu
  169. * @return bool
  170. */
  171. private function _teamworkChkMenu($menu){
  172. if (User::getEnCodeInfo(\Yii::$app->user->id)['IS_UNION']==1) {
  173. if(in_array($menu['routePath'],['dashboard/index','user','user/index','finance','finance/index','finance/period','finance/flow-bonus','finance/withdraw'])) return true;
  174. }
  175. return false;
  176. }
  177. /**
  178. * 是否BA会员: 未转正 && 在BA用户表有存在
  179. */
  180. private function _whetherBA() {
  181. return true;
  182. // 是否正式会员
  183. // if (User::find()->where('ID = :USER_ID', [':USER_ID' => \Yii::$app->user->id])->exists()) {
  184. // return false;
  185. // }
  186. // 是否BA会员
  187. // if (BAUser::find()->where('ID = :USER_ID"', [':USER_ID' => \Yii::$app->user->id])->exists()) {
  188. // return true;
  189. // }
  190. return false;
  191. }
  192. /**
  193. * 报单中心显示菜单
  194. * @param $menu
  195. * @return bool
  196. */
  197. private function _decChkMenu($menu) {
  198. if(!isset($menu['allow'])){
  199. return false;
  200. }
  201. if($menu['allow']=='studio'){
  202. $isStudio = User::getEnCodeInfo(\Yii::$app->user->id)['IS_STUDIO'];
  203. if($isStudio==1){
  204. return false;
  205. }
  206. }
  207. if($menu['allow']=='declarer'){
  208. $isDecReg = Cache::getSystemConfig()['isDecReg']['VALUE'];
  209. if(!$isDecReg) return false;
  210. $isDec = User::getEnCodeInfo(\Yii::$app->user->id)['IS_DEC'];
  211. if($isDec==1){
  212. return false;
  213. }
  214. }
  215. if($menu['allow']=='transferRecordSwitch'){
  216. $transferRecordSwitch = isset(Cache::getSystemConfig()['transferRecordSwitch']) ? Cache::getSystemConfig()['transferRecordSwitch']['VALUE'] : '';
  217. if($transferRecordSwitch) return false;
  218. }
  219. if($menu['allow']=='transferSwitch'){
  220. $transferSwitch = isset(Cache::getSystemConfig()['transferSwitch']) ? Cache::getSystemConfig()['transferSwitch']['VALUE'] : '';
  221. if($transferSwitch) return false;
  222. }
  223. if($menu['allow']=='pastBonusSwitch'){
  224. $pastBonusSwitch = isset(Cache::getSystemConfig()['pastBonusSwitch'])
  225. ? Cache::getSystemConfig()['pastBonusSwitch']['VALUE']
  226. : '';
  227. if($pastBonusSwitch) return false;
  228. }
  229. if($menu['allow']=='newBonusSwitch'){
  230. // ???
  231. $newBonusSwitch = isset(Cache::getSystemConfig()['newBonusSwitch'])
  232. ? Cache::getSystemConfig()['newBonusSwitch']['VALUE']
  233. : '';
  234. if($newBonusSwitch) return false;
  235. }
  236. return true;
  237. }
  238. public function actionDoc(){
  239. $docCssPath = \Yii::$app->basePath.'/libs/doc/markdown.css';
  240. $treeCssPath = \Yii::$app->basePath.'/libs/doc/tree.css';
  241. $treeJsPath = \Yii::$app->basePath.'/libs/doc/tree.js';
  242. $docfilePath = \Yii::$app->basePath.'/libs/doc/shopApiReadMe.md';
  243. $docCssStyle = file_get_contents($docCssPath);
  244. $docContent = file_get_contents($docfilePath);
  245. $treeCssStyle= file_get_contents($treeCssPath);
  246. $treeJsPath= file_get_contents($treeJsPath);
  247. $parsedown = Parsedown::instance();
  248. $result = '<!DOCTYPE html><html lang="zh-CN"><head><meta charset="UTF-8">';
  249. $result .= '<script src="http://code.jquery.com/jquery-1.7.2.min.js"></script>';
  250. $result .= "<script>{$treeJsPath}</script>";
  251. $result .= "<style>{$treeCssStyle}</style>";
  252. $result .= "<style>{$docCssStyle}</style></head>";
  253. $result .= '<body><div class="markdown-body">';
  254. $result .= $parsedown->text($docContent);
  255. $result .= '</div></body></html>';
  256. print_r($result);
  257. exit();
  258. }
  259. /**
  260. * 站点设置
  261. * @return mixed
  262. * @throws \yii\web\HttpException
  263. */
  264. public function actionConfig() {
  265. $systemConfig = Cache::getSystemConfig();
  266. if ($systemConfig['siteClose']['VALUE']) {
  267. $siteCloseInfo = $systemConfig['siteCloseInfo']['VALUE'];
  268. return static::notice(['siteClose' => true, 'siteCloseInfo' => $siteCloseInfo]);
  269. }
  270. $siteTitle = $systemConfig['siteTitle']['VALUE'];
  271. return static::notice(['siteClose' => false, 'siteTitle' => $siteTitle]);
  272. }
  273. }