SiteController.php 13 KB

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