SiteController.php 13 KB

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