SiteController.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  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. $menu = require Yii::getAlias('@frontendApi/config/menu.php');
  108. $menu = $this->_childMenu($menu);
  109. // 时间差
  110. $daysDiff = Yii::$app->params['daysDiff'];
  111. // 钱包
  112. $shopWalletType = Tool::paramConvert(Yii::$app->params['shopWalletType']);
  113. //期数显示
  114. $periodNum = Period::instance()->getNowPeriodNum();
  115. $curYM = Period::find()->select("CALC_YEAR,CALC_MONTH")->where('PERIOD_NUM=:PERIOD_NUM', [':PERIOD_NUM' => $periodNum])->asArray()->one();
  116. $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();
  117. $weeks = count($plist);
  118. $wkrd = '';
  119. foreach ($plist as $k=>$v){
  120. if($v['PERIOD_NUM']==$periodNum){
  121. $wkrd =$k+1;break;
  122. }
  123. }
  124. if($wkrd==1){
  125. $wkrd.='st';
  126. }else{
  127. $wkrd.='nd';
  128. }
  129. $monthArray = [
  130. 1 => 'Jan',
  131. 2 => 'Feb',
  132. 3 => 'Mar',
  133. 4 => 'Apr',
  134. 5 => 'May',
  135. 6 => 'Jun',
  136. 7 => 'Jul',
  137. 8 => 'Aug',
  138. 9 => 'Sep',
  139. 10 => 'Oct',
  140. 11 => 'Nov',
  141. 12 => 'Dec',
  142. ];
  143. return [
  144. 'decLevels' => $decLevels,
  145. 'empLevels' => $empLevels,
  146. 'crownLevels' => $crownLevels,
  147. 'menu' => $menu,
  148. 'daysDiff' => $daysDiff,
  149. 'periodNum' => $periodNum . ',' . $wkrd . ' PC of ' . $monthArray[$curYM['CALC_MONTH']],
  150. 'shopWalletType' => $shopWalletType,
  151. 'whetherBA' => false,
  152. ];
  153. }
  154. private function _childMenu($parentArray){
  155. $menuResult = [];
  156. foreach($parentArray as $key => $parentMenu){
  157. if($key !== 'article'){
  158. // 菜单是否显示
  159. if(isset($parentMenu['show']) && !$parentMenu['show']){
  160. continue;
  161. }
  162. if($this->_teamworkChkMenu($parentMenu)){
  163. continue;
  164. }
  165. if($this->_decChkMenu($parentMenu)){
  166. continue;
  167. }
  168. // 查看是否有该控制器的权限
  169. if(isset($parentMenu['controller']) && $parentMenu['controller']){
  170. if(!Yii::$app->user->validateUserController($parentMenu['controller'])) continue;
  171. }
  172. // 查看是否有权限
  173. if(isset($parentMenu['action']) && $parentMenu['action']){
  174. if(!Yii::$app->user->validateUserAction($parentMenu['controller'], $parentMenu['action'])) continue;
  175. }
  176. // 子菜单同样设置
  177. if(isset($parentMenu['child']) && !empty($parentMenu['child'])){
  178. $parentMenu['child'] = $this->_childMenu($parentMenu['child']);
  179. }
  180. }
  181. $menuResult[] = $parentMenu;
  182. }
  183. return $menuResult;
  184. }
  185. /**
  186. * 虚拟会员hz解决暂写死
  187. * @param $menu
  188. * @return bool
  189. */
  190. private function _teamworkChkMenu($menu){
  191. if (User::getEnCodeInfo(\Yii::$app->user->id)['IS_UNION']==1) {
  192. if(in_array($menu['routePath'],['dashboard/index','user','user/index','finance','finance/index','finance/period','finance/flow-bonus','finance/withdraw'])) return true;
  193. }
  194. return false;
  195. }
  196. /**
  197. * 报单中心显示菜单
  198. * @param $menu
  199. * @return bool
  200. */
  201. private function _decChkMenu($menu) {
  202. if(!isset($menu['allow'])){
  203. return false;
  204. }
  205. if($menu['allow']=='studio'){
  206. $isStudio = User::getEnCodeInfo(\Yii::$app->user->id)['IS_STUDIO'];
  207. if($isStudio==1){
  208. return false;
  209. }
  210. }
  211. if($menu['allow']=='declarer'){
  212. $isDecReg = Cache::getSystemConfig()['isDecReg']['VALUE'];
  213. if(!$isDecReg) return false;
  214. $isDec = User::getEnCodeInfo(\Yii::$app->user->id)['IS_DEC'];
  215. if($isDec==1){
  216. return false;
  217. }
  218. }
  219. if($menu['allow']=='transferRecordSwitch'){
  220. $transferRecordSwitch = isset(Cache::getSystemConfig()['transferRecordSwitch']) ? Cache::getSystemConfig()['transferRecordSwitch']['VALUE'] : '';
  221. if($transferRecordSwitch) return false;
  222. }
  223. if($menu['allow']=='transferSwitch'){
  224. $transferSwitch = isset(Cache::getSystemConfig()['transferSwitch']) ? Cache::getSystemConfig()['transferSwitch']['VALUE'] : '';
  225. if($transferSwitch) return false;
  226. }
  227. if($menu['allow']=='pastBonusSwitch'){
  228. $pastBonusSwitch = isset(Cache::getSystemConfig()['pastBonusSwitch'])
  229. ? Cache::getSystemConfig()['pastBonusSwitch']['VALUE']
  230. : '';
  231. if($pastBonusSwitch) return false;
  232. }
  233. if($menu['allow']=='newBonusSwitch'){
  234. // ???
  235. $newBonusSwitch = isset(Cache::getSystemConfig()['newBonusSwitch'])
  236. ? Cache::getSystemConfig()['newBonusSwitch']['VALUE']
  237. : '';
  238. if($newBonusSwitch) return false;
  239. }
  240. return true;
  241. }
  242. public function actionDoc(){
  243. $docCssPath = \Yii::$app->basePath.'/libs/doc/markdown.css';
  244. $treeCssPath = \Yii::$app->basePath.'/libs/doc/tree.css';
  245. $treeJsPath = \Yii::$app->basePath.'/libs/doc/tree.js';
  246. $docfilePath = \Yii::$app->basePath.'/libs/doc/shopApiReadMe.md';
  247. $docCssStyle = file_get_contents($docCssPath);
  248. $docContent = file_get_contents($docfilePath);
  249. $treeCssStyle= file_get_contents($treeCssPath);
  250. $treeJsPath= file_get_contents($treeJsPath);
  251. $parsedown = Parsedown::instance();
  252. $result = '<!DOCTYPE html><html lang="zh-CN"><head><meta charset="UTF-8">';
  253. $result .= '<script src="http://code.jquery.com/jquery-1.7.2.min.js"></script>';
  254. $result .= "<script>{$treeJsPath}</script>";
  255. $result .= "<style>{$treeCssStyle}</style>";
  256. $result .= "<style>{$docCssStyle}</style></head>";
  257. $result .= '<body><div class="markdown-body">';
  258. $result .= $parsedown->text($docContent);
  259. $result .= '</div></body></html>';
  260. print_r($result);
  261. exit();
  262. }
  263. /**
  264. * 站点设置
  265. * @return mixed
  266. * @throws \yii\web\HttpException
  267. */
  268. public function actionConfig() {
  269. $systemConfig = Cache::getSystemConfig();
  270. if ($systemConfig['siteClose']['VALUE']) {
  271. $siteCloseInfo = $systemConfig['siteCloseInfo']['VALUE'];
  272. return static::notice(['siteClose' => true, 'siteCloseInfo' => $siteCloseInfo]);
  273. }
  274. $siteTitle = $systemConfig['siteTitle']['VALUE'];
  275. return static::notice(['siteClose' => false, 'siteTitle' => $siteTitle]);
  276. }
  277. /**
  278. * 请求基础信息
  279. * @return array
  280. */
  281. public function actionBaBaseInfo(){
  282. // 菜单
  283. $menu = require Yii::getAlias('@frontendApi/config/menuBA.php');
  284. // 获取全部文章分类
  285. $allArticleCategory = ArticleCategory::getAllCategory();
  286. foreach($allArticleCategory as $category){
  287. $menu['article']['child'][] = ['name'=>$category['CATE_NAME'], 'class'=>'', 'icon'=>'', 'controller'=>'article', 'action'=>'list', 'routePath'=>'article/list/'.$category['ID'], 'show'=>1,];
  288. }
  289. $menu = $this->_childBaMenu($menu);
  290. // 时间差
  291. $daysDiff = Yii::$app->params['daysDiff'];
  292. // 钱包
  293. $shopWalletType = Tool::paramConvert(Yii::$app->params['shopWalletType']);
  294. return [
  295. 'decLevels' => '',
  296. 'empLevels' => '',
  297. 'menu' => $menu,
  298. 'daysDiff' => $daysDiff,
  299. 'shopWalletType' => $shopWalletType,
  300. 'whetherBA' => true,
  301. ];
  302. }
  303. private function _childBaMenu($parentArray) {
  304. $menuResult = [];
  305. foreach ($parentArray as $key => $parentMenu) {
  306. if ($key !== 'article'){
  307. // 菜单是否显示
  308. if (isset($parentMenu['show']) && !$parentMenu['show']) {
  309. continue;
  310. }
  311. // 查看是否有该控制器的权限
  312. if(isset($parentMenu['controller']) && $parentMenu['controller']){
  313. if(!Yii::$app->user->validateUserController($parentMenu['controller'])) continue;
  314. }
  315. // 查看是否有权限
  316. if(isset($parentMenu['action']) && $parentMenu['action']){
  317. if(!Yii::$app->user->validateUserAction($parentMenu['controller'], $parentMenu['action'])) continue;
  318. }
  319. // 子菜单同样设置
  320. if(isset($parentMenu['child']) && !empty($parentMenu['child'])){
  321. $parentMenu['child'] = $this->_childBaMenu($parentMenu['child']);
  322. }
  323. }
  324. $menuResult[] = $parentMenu;
  325. }
  326. return $menuResult;
  327. }
  328. /**
  329. * 发送钉钉测试信息
  330. * @return mixed
  331. * @throws \yii\web\HttpException
  332. */
  333. public function actionSendNotice()
  334. {
  335. $data = [
  336. 'code' => 400,
  337. 'message' => 'autoSendDingTalk',
  338. ];
  339. return static::notice(['data' => $data['bug监控正常运行,没有发现异常.']]);
  340. }
  341. }