SiteController.php 13 KB

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