SiteController.php 10 KB

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