SiteController.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447
  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. // Elite级别
  111. $eliteLevels = Cache::getEliteLevelConfig();
  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. $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. 'eliteLevels' => $eliteLevels,
  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. public function actionGetInstance()
  356. {
  357. // $sign = [];
  358. // for ($i = 0; $i < 8; $i++) {
  359. // $sign[] = PageSnowFake::instance()->generateId();
  360. // }
  361. //
  362. // return static::notice($sign);
  363. $result = [];
  364. $yearStart = 2024;
  365. $yearEnd = 2029;
  366. for ($y = $yearStart; $y <= $yearEnd; $y++) {
  367. for ($i = 1; $i <= 12; $i++) {
  368. // 月初
  369. // $date = "{$y}-{$i}-01 00:00:00";
  370. // $result[] = strtotime($date);
  371. // 月底
  372. $date = date('Y-m-t', strtotime("{$y}-{$i}")) . ' 23:59:59';
  373. $result[] = strtotime($date);
  374. }
  375. }
  376. return static::notice($result);
  377. }
  378. public function actionCountries()
  379. {
  380. $countryId = User::getEnCodeInfo(\Yii::$app->user->id)['COUNTRY_ID'];
  381. $countries = array_filter(Cache::getCountries(), fn($country) => $country['ID'] === $countryId);
  382. return static::notice(['data' => array_values($countries)]);
  383. }
  384. public function actionLanguages()
  385. {
  386. $data = Cache::getLanguages();
  387. return static::notice(['data' => $data]);
  388. }
  389. public function actionBanks()
  390. {
  391. // 默认国家
  392. $countryId = \Yii::$app->request->get('countryId');
  393. if (!$countryId) {
  394. return static::notice(Yii::t('app', 'countryDoesNotSelect'), 400);
  395. }
  396. $data = OpenBank::find()
  397. ->where('STATUS=:STATUS AND COUNTRY_ID=:COUNTRY_ID', [':STATUS' => 1, ':COUNTRY_ID' => $countryId])
  398. ->orderBy('BANK_NAME ASC')
  399. ->asArray()
  400. ->all();
  401. return static::notice(['data' => $data]);
  402. }
  403. }