SiteController.php 15 KB

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