SiteController.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445
  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. $menu = require Yii::getAlias('@frontendApi/config/menu.php');
  112. $menu = $this->_childMenu($menu);
  113. // 时间差
  114. $daysDiff = Yii::$app->params['daysDiff'];
  115. // 钱包
  116. $shopWalletType = Tool::paramConvert(Yii::$app->params['shopWalletType']);
  117. //期数显示
  118. $periodNum = Period::instance()->getNowPeriodNum();
  119. $curYM = Period::find()->select("CALC_YEAR,CALC_MONTH")->where('PERIOD_NUM=:PERIOD_NUM', [':PERIOD_NUM' => $periodNum])->asArray()->one();
  120. $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();
  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. 'menu' => $menu,
  150. 'daysDiff' => $daysDiff,
  151. 'periodNum' => $periodNum . ',' . $wkrd . ' PC of ' . $monthArray[$curYM['CALC_MONTH']],
  152. 'shopWalletType' => $shopWalletType,
  153. 'whetherBA' => false,
  154. ];
  155. }
  156. private function _childMenu($parentArray){
  157. $menuResult = [];
  158. foreach($parentArray as $key => $parentMenu){
  159. if($key !== 'article'){
  160. // 菜单是否显示
  161. if(isset($parentMenu['show']) && !$parentMenu['show']){
  162. continue;
  163. }
  164. if($this->_teamworkChkMenu($parentMenu)){
  165. continue;
  166. }
  167. if($this->_decChkMenu($parentMenu)){
  168. continue;
  169. }
  170. // 查看是否有该控制器的权限
  171. if(isset($parentMenu['controller']) && $parentMenu['controller']){
  172. if(!Yii::$app->user->validateUserController($parentMenu['controller'])) continue;
  173. }
  174. // 查看是否有权限
  175. if(isset($parentMenu['action']) && $parentMenu['action']){
  176. if(!Yii::$app->user->validateUserAction($parentMenu['controller'], $parentMenu['action'])) continue;
  177. }
  178. // 子菜单同样设置
  179. if(isset($parentMenu['child']) && !empty($parentMenu['child'])){
  180. $parentMenu['child'] = $this->_childMenu($parentMenu['child']);
  181. }
  182. }
  183. $menuResult[] = $parentMenu;
  184. }
  185. return $menuResult;
  186. }
  187. /**
  188. * 虚拟会员hz解决暂写死
  189. * @param $menu
  190. * @return bool
  191. */
  192. private function _teamworkChkMenu($menu){
  193. if (User::getEnCodeInfo(\Yii::$app->user->id)['IS_UNION']==1) {
  194. if(in_array($menu['routePath'],['dashboard/index','user','user/index','finance','finance/index','finance/period','finance/flow-bonus','finance/withdraw'])) return true;
  195. }
  196. return false;
  197. }
  198. /**
  199. * 报单中心显示菜单
  200. * @param $menu
  201. * @return bool
  202. */
  203. private function _decChkMenu($menu) {
  204. if(!isset($menu['allow'])){
  205. return false;
  206. }
  207. if($menu['allow']=='studio'){
  208. $isStudio = User::getEnCodeInfo(\Yii::$app->user->id)['IS_STUDIO'];
  209. if($isStudio==1){
  210. return false;
  211. }
  212. }
  213. if($menu['allow']=='declarer'){
  214. $isDecReg = Cache::getSystemConfig()['isDecReg']['VALUE'];
  215. if(!$isDecReg) return false;
  216. $isDec = User::getEnCodeInfo(\Yii::$app->user->id)['IS_DEC'];
  217. if($isDec==1){
  218. return false;
  219. }
  220. }
  221. if($menu['allow']=='transferRecordSwitch'){
  222. $transferRecordSwitch = isset(Cache::getSystemConfig()['transferRecordSwitch']) ? Cache::getSystemConfig()['transferRecordSwitch']['VALUE'] : '';
  223. if($transferRecordSwitch) return false;
  224. }
  225. if($menu['allow']=='transferSwitch'){
  226. $transferSwitch = isset(Cache::getSystemConfig()['transferSwitch']) ? Cache::getSystemConfig()['transferSwitch']['VALUE'] : '';
  227. if($transferSwitch) return false;
  228. }
  229. if($menu['allow']=='pastBonusSwitch'){
  230. $pastBonusSwitch = isset(Cache::getSystemConfig()['pastBonusSwitch'])
  231. ? Cache::getSystemConfig()['pastBonusSwitch']['VALUE']
  232. : '';
  233. if($pastBonusSwitch) return false;
  234. }
  235. if($menu['allow']=='newBonusSwitch'){
  236. // ???
  237. $newBonusSwitch = isset(Cache::getSystemConfig()['newBonusSwitch'])
  238. ? Cache::getSystemConfig()['newBonusSwitch']['VALUE']
  239. : '';
  240. if($newBonusSwitch) return false;
  241. }
  242. return true;
  243. }
  244. public function actionDoc(){
  245. $docCssPath = \Yii::$app->basePath.'/libs/doc/markdown.css';
  246. $treeCssPath = \Yii::$app->basePath.'/libs/doc/tree.css';
  247. $treeJsPath = \Yii::$app->basePath.'/libs/doc/tree.js';
  248. $docfilePath = \Yii::$app->basePath.'/libs/doc/shopApiReadMe.md';
  249. $docCssStyle = file_get_contents($docCssPath);
  250. $docContent = file_get_contents($docfilePath);
  251. $treeCssStyle= file_get_contents($treeCssPath);
  252. $treeJsPath= file_get_contents($treeJsPath);
  253. $parsedown = Parsedown::instance();
  254. $result = '<!DOCTYPE html><html lang="zh-CN"><head><meta charset="UTF-8">';
  255. $result .= '<script src="http://code.jquery.com/jquery-1.7.2.min.js"></script>';
  256. $result .= "<script>{$treeJsPath}</script>";
  257. $result .= "<style>{$treeCssStyle}</style>";
  258. $result .= "<style>{$docCssStyle}</style></head>";
  259. $result .= '<body><div class="markdown-body">';
  260. $result .= $parsedown->text($docContent);
  261. $result .= '</div></body></html>';
  262. print_r($result);
  263. exit();
  264. }
  265. /**
  266. * 站点设置
  267. * @return mixed
  268. * @throws \yii\web\HttpException
  269. */
  270. public function actionConfig() {
  271. $systemConfig = Cache::getSystemConfig();
  272. if ($systemConfig['siteClose']['VALUE']) {
  273. $siteCloseInfo = $systemConfig['siteCloseInfo']['VALUE'];
  274. return static::notice(['siteClose' => true, 'siteCloseInfo' => $siteCloseInfo]);
  275. }
  276. $siteTitle = $systemConfig['siteTitle']['VALUE'];
  277. return static::notice(['siteClose' => false, 'siteTitle' => $siteTitle]);
  278. }
  279. /**
  280. * 请求基础信息
  281. * @return array
  282. */
  283. public function actionBaBaseInfo(){
  284. // 菜单
  285. $menu = require Yii::getAlias('@frontendApi/config/menuBA.php');
  286. // 获取全部文章分类
  287. $allArticleCategory = ArticleCategory::getAllCategory();
  288. foreach($allArticleCategory as $category){
  289. $menu['article']['child'][] = ['name'=>$category['CATE_NAME'], 'class'=>'', 'icon'=>'', 'controller'=>'article', 'action'=>'list', 'routePath'=>'article/list/'.$category['ID'], 'show'=>1,];
  290. }
  291. $menu = $this->_childBaMenu($menu);
  292. // 时间差
  293. $daysDiff = Yii::$app->params['daysDiff'];
  294. // 钱包
  295. $shopWalletType = Tool::paramConvert(Yii::$app->params['shopWalletType']);
  296. return [
  297. 'decLevels' => '',
  298. 'empLevels' => '',
  299. 'menu' => $menu,
  300. 'daysDiff' => $daysDiff,
  301. 'shopWalletType' => $shopWalletType,
  302. 'whetherBA' => true,
  303. ];
  304. }
  305. private function _childBaMenu($parentArray) {
  306. $menuResult = [];
  307. foreach ($parentArray as $key => $parentMenu) {
  308. if ($key !== 'article'){
  309. // 菜单是否显示
  310. if (isset($parentMenu['show']) && !$parentMenu['show']) {
  311. continue;
  312. }
  313. // 查看是否有该控制器的权限
  314. if(isset($parentMenu['controller']) && $parentMenu['controller']){
  315. if(!Yii::$app->user->validateUserController($parentMenu['controller'])) continue;
  316. }
  317. // 查看是否有权限
  318. if(isset($parentMenu['action']) && $parentMenu['action']){
  319. if(!Yii::$app->user->validateUserAction($parentMenu['controller'], $parentMenu['action'])) continue;
  320. }
  321. // 子菜单同样设置
  322. if(isset($parentMenu['child']) && !empty($parentMenu['child'])){
  323. $parentMenu['child'] = $this->_childBaMenu($parentMenu['child']);
  324. }
  325. }
  326. $menuResult[] = $parentMenu;
  327. }
  328. return $menuResult;
  329. }
  330. /**
  331. * 发送钉钉测试信息
  332. * @return mixed
  333. * @throws \yii\web\HttpException
  334. */
  335. public function actionSendNotice()
  336. {
  337. $data = [
  338. 'code' => 400,
  339. 'message' => 'autoSendDingTalk',
  340. ];
  341. return static::notice(['data' => $data['bug监控正常运行,没有发现异常.']]);
  342. }
  343. public function actionSendNotify()
  344. {
  345. Alarm::reportAlarm([
  346. 'stance' => 1,
  347. 'brand' => 'OTA',
  348. 'message' => '预警信息测试',
  349. ]);
  350. return static::notice('成功', 0);
  351. }
  352. public function actionGetInstance()
  353. {
  354. // $sign = [];
  355. // for ($i = 0; $i < 8; $i++) {
  356. // $sign[] = PageSnowFake::instance()->generateId();
  357. // }
  358. //
  359. // return static::notice($sign);
  360. $result = [];
  361. $yearStart = 2024;
  362. $yearEnd = 2029;
  363. for ($y = $yearStart; $y <= $yearEnd; $y++) {
  364. for ($i = 1; $i <= 12; $i++) {
  365. // 月初
  366. // $date = "{$y}-{$i}-01 00:00:00";
  367. // $result[] = strtotime($date);
  368. // 月底
  369. $date = date('Y-m-t', strtotime("{$y}-{$i}")) . ' 23:59:59';
  370. $result[] = strtotime($date);
  371. }
  372. }
  373. return static::notice($result);
  374. }
  375. public function actionCountries()
  376. {
  377. // 国家列表
  378. $data = Cache::getCountries();
  379. return static::notice(['data' => $data]);
  380. }
  381. public function actionLanguages()
  382. {
  383. // 语言列表
  384. $data = Cache::getLanguages();
  385. return static::notice(['data' => $data]);
  386. }
  387. public function actionBanks()
  388. {
  389. // 默认国家
  390. $countryId = \Yii::$app->request->get('countryId');
  391. if (!$countryId) {
  392. return static::notice(Yii::t('app', 'countryDoesNotSelect'), 400);
  393. }
  394. $data = OpenBank::find()
  395. ->where('STATUS=:STATUS AND COUNTRY_ID=:COUNTRY_ID', [':STATUS' => 1, ':COUNTRY_ID' => $countryId])
  396. ->orderBy('BANK_NAME ASC')
  397. ->asArray()
  398. ->all();
  399. return static::notice(['data' => $data]);
  400. }
  401. }