SiteController.php 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  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\Alarm;
  10. use common\helpers\Cache;
  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\DecOrder;
  16. use common\models\DecRole;
  17. use Yii;
  18. use frontendApi\modules\v1\models\User;
  19. use common\helpers\parsedown\Parsedown;
  20. use yii\web\HttpException;
  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. ];
  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']=='declarer-upgrade'){
  188. $isOpenUpgrade = Cache::getSystemConfig()['isOpenUpgrade']['VALUE'];
  189. $isDec = User::getEnCodeInfo(\Yii::$app->user->id)['IS_DEC'];
  190. if($isDec==1 && $isOpenUpgrade == 1){
  191. return false;
  192. }
  193. }
  194. if($menu['allow']=='transferRecordSwitch'){
  195. $transferRecordSwitch = isset(Cache::getSystemConfig()['transferRecordSwitch']) ? Cache::getSystemConfig()['transferRecordSwitch']['VALUE'] : '';
  196. if($transferRecordSwitch) return false;
  197. }
  198. if($menu['allow']=='transferSwitch'){
  199. $transferSwitch = isset(Cache::getSystemConfig()['transferSwitch']) ? Cache::getSystemConfig()['transferSwitch']['VALUE'] : '';
  200. if($transferSwitch) return false;
  201. }
  202. if($menu['allow']=='pastBonusSwitch'){
  203. $pastBonusSwitch = isset(Cache::getSystemConfig()['pastBonusSwitch'])
  204. ? Cache::getSystemConfig()['pastBonusSwitch']['VALUE']
  205. : '';
  206. if($pastBonusSwitch) return false;
  207. }
  208. if($menu['allow']=='newBonusSwitch'){
  209. // ???
  210. $newBonusSwitch = isset(Cache::getSystemConfig()['newBonusSwitch'])
  211. ? Cache::getSystemConfig()['newBonusSwitch']['VALUE']
  212. : '';
  213. if($newBonusSwitch) return false;
  214. }
  215. return true;
  216. }
  217. public function actionDoc(){
  218. $docCssPath = \Yii::$app->basePath.'/libs/doc/markdown.css';
  219. $treeCssPath = \Yii::$app->basePath.'/libs/doc/tree.css';
  220. $treeJsPath = \Yii::$app->basePath.'/libs/doc/tree.js';
  221. $docfilePath = \Yii::$app->basePath.'/libs/doc/shopApiReadMe.md';
  222. $docCssStyle = file_get_contents($docCssPath);
  223. $docContent = file_get_contents($docfilePath);
  224. $treeCssStyle= file_get_contents($treeCssPath);
  225. $treeJsPath= file_get_contents($treeJsPath);
  226. $parsedown = Parsedown::instance();
  227. $result = '<!DOCTYPE html><html lang="zh-CN"><head><meta charset="UTF-8">';
  228. $result .= '<script src="http://code.jquery.com/jquery-1.7.2.min.js"></script>';
  229. $result .= "<script>{$treeJsPath}</script>";
  230. $result .= "<style>{$treeCssStyle}</style>";
  231. $result .= "<style>{$docCssStyle}</style></head>";
  232. $result .= '<body><div class="markdown-body">';
  233. $result .= $parsedown->text($docContent);
  234. $result .= '</div></body></html>';
  235. print_r($result);
  236. exit();
  237. }
  238. /**
  239. * 站点设置
  240. * @return mixed
  241. * @throws \yii\web\HttpException
  242. */
  243. public function actionConfig() {
  244. $systemConfig = Cache::getSystemConfig();
  245. if ($systemConfig['siteClose']['VALUE']) {
  246. $siteCloseInfo = $systemConfig['siteCloseInfo']['VALUE'];
  247. return static::notice(['siteClose' => true, 'siteCloseInfo' => $siteCloseInfo]);
  248. }
  249. $siteTitle = $systemConfig['siteTitle']['VALUE'];
  250. return static::notice(['siteClose' => false, 'siteTitle' => $siteTitle]);
  251. }
  252. /**
  253. * 发送钉钉测试信息
  254. * @return mixed
  255. * @throws \yii\web\HttpException
  256. */
  257. public function actionSendNotice()
  258. {
  259. $data = [
  260. 'code' => 400,
  261. 'message' => 'autoSendDingTalk',
  262. ];
  263. return static::notice(['data' => $data['bug监控正常运行,没有发现异常,奥利给!']]);
  264. }
  265. /**
  266. * @throws HttpException
  267. * @throws \Exception
  268. */
  269. public function actionSendNotify()
  270. {
  271. Alarm::reportAlarm([
  272. 'stance' => 1,
  273. 'brand' => 'OTA',
  274. 'message' => '预警信息测试',
  275. ]);
  276. return static::notice('成功', 0);
  277. }
  278. }