SiteController.php 13 KB

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