SiteController.php 13 KB

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