| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447 |
- <?php
- /**
- * Created by PhpStorm.
- * User: leo
- * Date: 2018/2/24
- * Time: 下午12:48
- */
- namespace frontendApi\modules\v1\controllers;
- use common\helpers\Alarm;
- use common\helpers\Cache;
- use common\helpers\LoggerTool;
- use common\helpers\snowflake\PageSnowFake;
- use common\helpers\Tool;
- use common\models\Ad;
- use common\models\AdLocation;
- use common\models\ArticleCategory;
- use common\models\BaUser;
- use common\models\DecOrder;
- use common\models\DecRole;
- use common\models\OpenBank;
- use common\models\Order;
- use common\models\OrderGoods;
- use common\models\PerfPeriod;
- use common\models\Period;
- use common\models\ShopGoods;
- use Yii;
- use frontendApi\modules\v1\models\User;
- use common\helpers\parsedown\Parsedown;
- class SiteController extends BaseController
- {
- public $modelClass = User::class;
- /**
- * 请求服务器时间差
- * @return mixed
- * @throws \yii\web\HttpException
- */
- public function actionDaysDiff(){
- return static::notice(['daysDiff'=>Yii::$app->params['daysDiff']]);
- }
- /**
- * 获取广告
- * @return mixed
- * @throws \yii\web\HttpException
- */
- public function actionAd(){
- $lid = Yii::$app->request->get('lid');
- $adLocation = AdLocation::findUseSlaves()->where('ID=:ID', [':ID'=>$lid])->asArray()->one();
- $query = Ad::findUseSlaves()->select('ID,IMAGE,LID,TITLE,CONTENT,TYPE')->where('LID=:LID AND STATUS=1', [':LID'=>$lid])->orderBy('SORT ASC')->asArray();
- $data = [];
- if($adLocation['TYPE'] == AdLocation::TYPE_SLIDE){
- $data = $query->all();
- } elseif($adLocation['TYPE'] == AdLocation::TYPE_IMAGE) {
- $data = $query->one();
- }
- return static::notice($data);
- }
- /**
- * 请求手机基础信息
- * @return array
- */
- public function actionMobileBaseInfo(){
- // 会员级别
- $decLevels = Cache::getDecLevelConfig();
- // 聘级
- $empLevels = Cache::getEmpLevelConfig();
- // 时间差
- $daysDiff = Yii::$app->params['daysDiff'];
- // 钱包
- $shopWalletType = Tool::paramConvert(Yii::$app->params['shopWalletType']);
- return [
- 'decLevels' => $decLevels,
- 'empLevels' => $empLevels,
- 'daysDiff' => $daysDiff,
- 'shopWalletType' => $shopWalletType,
- ];
- }
- public function actions()
- {
- $actions = parent::actions();
- $actions['captcha'] = [
- 'class' => 'common\helpers\CaptchaAction',
- 'width' => 120,
- 'height' => 40,
- 'padding' => 0,
- 'minLength' => 4,
- 'maxLength' => 4,
- 'offset'=>8, //设置字符偏移量 有效果
- 'testLimit'=>1,
- ];
- return $actions;
- }
- /**
- * 请求页面数据
- * @return mixed
- * @throws \yii\web\HttpException
- */
- public function actionPageData() {
- $pageId = PageSnowFake::instance()->generateId();
- return static::notice(['pageId'=>$pageId]);
- }
- /**
- * 请求基础信息
- * @return array
- */
- public function actionBaseInfo(){
- // 会员级别
- $decLevels = Cache::getDecLevelConfig();
- // 聘级
- $empLevels = Cache::getEmpLevelConfig();
- // Elite级别
- $eliteLevels = Cache::getEliteLevelConfig();
- // 菜单
- $menu = require Yii::getAlias('@frontendApi/config/menu.php');
- $menu = $this->_childMenu($menu);
- // 时间差
- $daysDiff = Yii::$app->params['daysDiff'];
- // 钱包
- $shopWalletType = Tool::paramConvert(Yii::$app->params['shopWalletType']);
- //期数显示
- $periodNum = Period::instance()->getNowPeriodNum();
- $curYM = Period::find()->select("CALC_YEAR,CALC_MONTH")->where('PERIOD_NUM=:PERIOD_NUM', [':PERIOD_NUM' => $periodNum])->asArray()->one();
- $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();
- $wkrd = '';
- foreach ($plist as $k=>$v){
- if($v['PERIOD_NUM']==$periodNum){
- $wkrd =$k+1;break;
- }
- }
- if($wkrd==1){
- $wkrd.='st';
- }else{
- $wkrd.='nd';
- }
- $monthArray = [
- 1 => 'Jan',
- 2 => 'Feb',
- 3 => 'Mar',
- 4 => 'Apr',
- 5 => 'May',
- 6 => 'Jun',
- 7 => 'Jul',
- 8 => 'Aug',
- 9 => 'Sep',
- 10 => 'Oct',
- 11 => 'Nov',
- 12 => 'Dec',
- ];
- return [
- 'decLevels' => $decLevels,
- 'empLevels' => $empLevels,
- 'eliteLevels' => $eliteLevels,
- 'menu' => $menu,
- 'daysDiff' => $daysDiff,
- 'periodNum' => $periodNum . ',' . $wkrd . ' PC of ' . $monthArray[$curYM['CALC_MONTH']],
- 'shopWalletType' => $shopWalletType,
- 'whetherBA' => false,
- ];
- }
- private function _childMenu($parentArray){
- $menuResult = [];
- foreach($parentArray as $key => $parentMenu){
- if($key !== 'article'){
- // 菜单是否显示
- if(isset($parentMenu['show']) && !$parentMenu['show']){
- continue;
- }
- if($this->_teamworkChkMenu($parentMenu)){
- continue;
- }
- if($this->_decChkMenu($parentMenu)){
- continue;
- }
- // 查看是否有该控制器的权限
- if(isset($parentMenu['controller']) && $parentMenu['controller']){
- if(!Yii::$app->user->validateUserController($parentMenu['controller'])) continue;
- }
- // 查看是否有权限
- if(isset($parentMenu['action']) && $parentMenu['action']){
- if(!Yii::$app->user->validateUserAction($parentMenu['controller'], $parentMenu['action'])) continue;
- }
- // 子菜单同样设置
- if(isset($parentMenu['child']) && !empty($parentMenu['child'])){
- $parentMenu['child'] = $this->_childMenu($parentMenu['child']);
- }
- }
- $menuResult[] = $parentMenu;
- }
- return $menuResult;
- }
- /**
- * 虚拟会员hz解决暂写死
- * @param $menu
- * @return bool
- */
- private function _teamworkChkMenu($menu){
- if (User::getEnCodeInfo(\Yii::$app->user->id)['IS_UNION']==1) {
- if(in_array($menu['routePath'],['dashboard/index','user','user/index','finance','finance/index','finance/period','finance/flow-bonus','finance/withdraw'])) return true;
- }
- return false;
- }
- /**
- * 报单中心显示菜单
- * @param $menu
- * @return bool
- */
- private function _decChkMenu($menu) {
- if(!isset($menu['allow'])){
- return false;
- }
- if($menu['allow']=='studio'){
- $isStudio = User::getEnCodeInfo(\Yii::$app->user->id)['IS_STUDIO'];
- if($isStudio==1){
- return false;
- }
- }
- if($menu['allow']=='declarer'){
- $isDecReg = Cache::getSystemConfig()['isDecReg']['VALUE'];
- if($isDecReg) return false;
- $isDec = User::getEnCodeInfo(\Yii::$app->user->id)['IS_DEC'];
- if($isDec==1){
- return false;
- }
- }
- if($menu['allow']=='transferRecordSwitch'){
- $transferRecordSwitch = isset(Cache::getSystemConfig()['transferRecordSwitch']) ? Cache::getSystemConfig()['transferRecordSwitch']['VALUE'] : '';
- if($transferRecordSwitch) return false;
- }
- if($menu['allow']=='transferSwitch'){
- $transferSwitch = isset(Cache::getSystemConfig()['transferSwitch']) ? Cache::getSystemConfig()['transferSwitch']['VALUE'] : '';
- if($transferSwitch) return false;
- }
- if($menu['allow']=='pastBonusSwitch'){
- $pastBonusSwitch = isset(Cache::getSystemConfig()['pastBonusSwitch'])
- ? Cache::getSystemConfig()['pastBonusSwitch']['VALUE']
- : '';
- if($pastBonusSwitch) return false;
- }
- if($menu['allow']=='newBonusSwitch'){
- // ???
- $newBonusSwitch = isset(Cache::getSystemConfig()['newBonusSwitch'])
- ? Cache::getSystemConfig()['newBonusSwitch']['VALUE']
- : '';
- if($newBonusSwitch) return false;
- }
- return true;
- }
- public function actionDoc(){
- $docCssPath = \Yii::$app->basePath.'/libs/doc/markdown.css';
- $treeCssPath = \Yii::$app->basePath.'/libs/doc/tree.css';
- $treeJsPath = \Yii::$app->basePath.'/libs/doc/tree.js';
- $docfilePath = \Yii::$app->basePath.'/libs/doc/shopApiReadMe.md';
- $docCssStyle = file_get_contents($docCssPath);
- $docContent = file_get_contents($docfilePath);
- $treeCssStyle= file_get_contents($treeCssPath);
- $treeJsPath= file_get_contents($treeJsPath);
- $parsedown = Parsedown::instance();
- $result = '<!DOCTYPE html><html lang="zh-CN"><head><meta charset="UTF-8">';
- $result .= '<script src="http://code.jquery.com/jquery-1.7.2.min.js"></script>';
- $result .= "<script>{$treeJsPath}</script>";
- $result .= "<style>{$treeCssStyle}</style>";
- $result .= "<style>{$docCssStyle}</style></head>";
- $result .= '<body><div class="markdown-body">';
- $result .= $parsedown->text($docContent);
- $result .= '</div></body></html>';
- print_r($result);
- exit();
- }
- /**
- * 站点设置
- * @return mixed
- * @throws \yii\web\HttpException
- */
- public function actionConfig() {
- $systemConfig = Cache::getSystemConfig();
- if ($systemConfig['siteClose']['VALUE']) {
- $siteCloseInfo = $systemConfig['siteCloseInfo']['VALUE'];
- return static::notice(['siteClose' => true, 'siteCloseInfo' => $siteCloseInfo]);
- }
- $siteTitle = $systemConfig['siteTitle']['VALUE'];
- return static::notice(['siteClose' => false, 'siteTitle' => $siteTitle]);
- }
- /**
- * 请求基础信息
- * @return array
- */
- public function actionBaBaseInfo(){
- // 菜单
- $menu = require Yii::getAlias('@frontendApi/config/menuBA.php');
- // 获取全部文章分类
- $allArticleCategory = ArticleCategory::getAllCategory();
- foreach($allArticleCategory as $category){
- $menu['article']['child'][] = ['name'=>$category['CATE_NAME'], 'class'=>'', 'icon'=>'', 'controller'=>'article', 'action'=>'list', 'routePath'=>'article/list/'.$category['ID'], 'show'=>1,];
- }
- $menu = $this->_childBaMenu($menu);
- // 时间差
- $daysDiff = Yii::$app->params['daysDiff'];
- // 钱包
- $shopWalletType = Tool::paramConvert(Yii::$app->params['shopWalletType']);
- return [
- 'decLevels' => '',
- 'empLevels' => '',
- 'menu' => $menu,
- 'daysDiff' => $daysDiff,
- 'shopWalletType' => $shopWalletType,
- 'whetherBA' => true,
- ];
- }
- private function _childBaMenu($parentArray) {
- $menuResult = [];
- foreach ($parentArray as $key => $parentMenu) {
- if ($key !== 'article'){
- // 菜单是否显示
- if (isset($parentMenu['show']) && !$parentMenu['show']) {
- continue;
- }
- // 查看是否有该控制器的权限
- if(isset($parentMenu['controller']) && $parentMenu['controller']){
- if(!Yii::$app->user->validateUserController($parentMenu['controller'])) continue;
- }
- // 查看是否有权限
- if(isset($parentMenu['action']) && $parentMenu['action']){
- if(!Yii::$app->user->validateUserAction($parentMenu['controller'], $parentMenu['action'])) continue;
- }
- // 子菜单同样设置
- if(isset($parentMenu['child']) && !empty($parentMenu['child'])){
- $parentMenu['child'] = $this->_childBaMenu($parentMenu['child']);
- }
- }
- $menuResult[] = $parentMenu;
- }
- return $menuResult;
- }
- /**
- * 发送钉钉测试信息
- * @return mixed
- * @throws \yii\web\HttpException
- */
- public function actionSendNotice()
- {
- $data = [
- 'code' => 400,
- 'message' => 'autoSendDingTalk',
- ];
- return static::notice(['data' => $data['bug监控正常运行,没有发现异常.']]);
- }
- public function actionSendNotify()
- {
- Alarm::reportAlarm([
- 'stance' => 1,
- 'brand' => 'OTA',
- 'message' => '预警信息测试',
- ]);
- return static::notice('成功', 0);
- }
- public function actionGetInstance()
- {
- // $sign = [];
- // for ($i = 0; $i < 8; $i++) {
- // $sign[] = PageSnowFake::instance()->generateId();
- // }
- //
- // return static::notice($sign);
- $result = [];
- $yearStart = 2024;
- $yearEnd = 2029;
- for ($y = $yearStart; $y <= $yearEnd; $y++) {
- for ($i = 1; $i <= 12; $i++) {
- // 月初
- // $date = "{$y}-{$i}-01 00:00:00";
- // $result[] = strtotime($date);
- // 月底
- $date = date('Y-m-t', strtotime("{$y}-{$i}")) . ' 23:59:59';
- $result[] = strtotime($date);
- }
- }
- return static::notice($result);
- }
- public function actionCountries()
- {
- $countryId = User::getEnCodeInfo(\Yii::$app->user->id)['COUNTRY_ID'];
- $countries = array_filter(Cache::getCountries(), fn($country) => $country['ID'] === $countryId);
- return static::notice(['data' => array_values($countries)]);
- }
- public function actionLanguages()
- {
- $data = Cache::getLanguages();
- return static::notice(['data' => $data]);
- }
- public function actionBanks()
- {
- // 默认国家
- $countryId = \Yii::$app->request->get('countryId');
- if (!$countryId) {
- return static::notice(Yii::t('app', 'countryDoesNotSelect'), 400);
- }
- $data = OpenBank::find()
- ->where('STATUS=:STATUS AND COUNTRY_ID=:COUNTRY_ID', [':STATUS' => 1, ':COUNTRY_ID' => $countryId])
- ->orderBy('BANK_NAME ASC')
- ->asArray()
- ->all();
- return static::notice(['data' => $data]);
- }
- }
|