123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373 |
- <?php
- namespace api\controllers;
- use app\common\controllers\AController;
- use app\common\controllers\CController;
- use app\models\Nav;
- use app\modules\admin\models\Config;
- use app\modules\ad\models\AdData;
- use app\modules\doc\models\DocReal;
- use app\modules\ucenter\models\UserNum;
- use app\assets\WapAsset;
- use app\modules\cms\models\Category;
- use app\common\components\MultiSearchUrl;
- use app\modules\cms\models\Page;
- use Yii;
- class MappController extends AController
- {
- public $assetsUrl;
- public $optional1 = [
- 'config',
- 'index',
- 'catlist',
- 'catconfig',
- 'doclist',
- 'search',
- ];
- public function init()
- {
- $this->optional = array_merge($this->optional,$this->optional1);
- $view = $this->getView();
- $assets = WapAsset::register($view);
- $this->assetsUrl = API_URL.ltrim($assets->baseUrl,'/').'/';
- parent::init();
- }
- //读取小程序配置
- public function actionConfig()
- {
- $request_from = $this->get['request_from'];
- //百度小程序
- if($request_from==3)
- {
- $configResult = Config::find()->where("name = 'bdapp'")->limit(1)->one();
- }
- //微信小程序
- if($request_from==4)
- {
- $configResult = Config::find()->where("name = 'wxapp'")->limit(1)->one();
- }
- $config = string2array($configResult->value);
- $config['logo'] = getFileUrl($config['logo']);
- $config['shortlogo'] = getFileUrl($config['shortlogo']);
- //附加配置
- $hotWords = \app\models\SearchRecord::find()->where("recommend=1")->orderBy(['times'=>SORT_DESC])->limit(5)->all();
- $config['hotWords'] = $hotWords;
- $config['docname'] = $this->docconfig['docname']?$this->docconfig['docname']:'文档';
- $config['colname'] = $this->docconfig['colname']?$this->docconfig['colname']:'合辑';
- $config['coin_name'] = $this->coinconfig['coin_name'];
- $config['doc_model_id'] = $this->docconfig['content_model_id'];
- $config['assetsUrl'] = $this->assetsUrl;
- $config['fastAccountType'] = $this->openauthconfig['fastAccountType'];
- $config['commonAccountType'] = $this->openauthconfig['commonAccountType'];
- if($config['fastAccountType']=='mobile')
- {
- $config['fastAccountTip'] = '手机号';
- }
- else if($config['fastAccountType']=='email')
- {
- $config['fastAccountTip'] = '邮箱';
- }
- else if($config['fastAccountType']=='all')
- {
- $config['fastAccountTip'] = '手机号/邮箱';
- }
- if($config['commonAccountType']=='mobile')
- {
- $config['commonAccountTip'] = '手机号';
- }
- else if($config['commonAccountType']=='email')
- {
- $config['commonAccountTip'] = '邮箱';
- }
- else if($config['commonAccountType']=='all')
- {
- $config['commonAccountTip'] = '手机号/邮箱';
- }
- $config['certTimeOut'] = $this->smsconfig['certTimeOut'];
- $config['certValidTime'] = $this->smsconfig['certValidTime'].'分钟';
- $config['user_model_id'] = getSysconfigValue('default_user_model');
- $config['share_arg_name'] = Yii::$app->params['shareArgName'];
- $config['refer_page_name'] = Yii::$app->params['referPageName'];
- $agreements = Page::findOne(getSysconfigValue('user_agreements_cat_id'));
- $privacy = Page::findOne(getSysconfigValue('privacy_agreements_cat_id'));
- $config['agreements'] = $agreements;
- $config['privacy'] = $privacy;
- return [
- 'error' => 0,
- 'msg' => '操作成功',
- 'data' => ['config'=>$config],
- 'code'=>200
- ];
- }
- //首页
- public function actionIndex()
- {
- $request_from = $this->get['request_from'];
- //首页BANNER
- $bannerList = $this->_getAdData(12);
- if(is_array($bannerList))foreach($bannerList as $k=>$banner)
- {
- $bannerList[$k]['thumb'] = getFileUrl($banner['thumb']);
- }
- //文档数量
- $totalNum = DocReal::find()->where('is_delete=0 and status=1')->count();
- $totalNum = $totalNum + $this->docconfig['virtualnum'];
- $preDate = get_date(strtotime("-1 day"),"Y-m-d");
- $predayNum = UserNum::find()->where("date='".$preDate."'")->sum('doc_uploadnum');
- $predayNum = $predayNum+$this->docconfig['virtualaddnum'];
- //首页菜单
- if($request_from==3)//百度小程序
- {
- $menuList = Nav::find()->where("type=81 and disabled=0")->orderBy(['list_order'=>SORT_ASC])->asArray()->all();
- }
- if($request_from==4)//微信小程序
- {
- $menuList = Nav::find()->where("type=91 and disabled=0")->orderBy(['list_order'=>SORT_ASC])->asArray()->all();
- }
- //首页横幅广告
- $adList = $this->_getAdData(13);
- if(is_array($adList))foreach($adList as $k=>$ad)
- {
- $adList[$k]['thumb'] = getFileUrl($ad['thumb']);
- }
- //最新文档
- $newDocList = DocReal::find()->where("is_new=1 and status=1 and is_delete=0 and doc_type!=2")->orderBy(['create_time'=>SORT_DESC])->limit(10)->asArray()->all();
- foreach($newDocList as $k=>$newDoc)
- {
- $newDocList[$k]['thumb'] = $this->makeThumb($newDoc['thumb'],320,340);
- $newDocList[$k]['icon'] = $this->assetsUrl.'images/icon/'.DocReal::getExtImgName($newDoc['ext']).'.png';
- $newDocList[$k]['views'] = $this->getDocView($newDoc['views']);
- $newDocList[$k]['downs'] = $this->getDocDowns($newDoc['downs']);
- }
- //最新合辑
- $newColList = DocReal::find()->where("is_new=1 and status=1 and is_delete=0 and doc_type=2")->orderBy(['create_time'=>SORT_DESC])->limit(10)->asArray()->all();
- foreach($newColList as $k=>$newCol)
- {
- $newColList[$k]['thumb'] = $this->makeThumb($newCol['thumb'],354,254);
- $newColList[$k]['icon'] = $this->assetsUrl.'images/icon/'.DocReal::getExtImgName($newCol['ext']).'.png';
- $newColList[$k]['views'] = $this->getDocView($newCol['views']);
- $newColList[$k]['downs'] = $this->getDocDowns($newCol['downs']);
- }
- $tabTitle[] = $this->docconfig['docname']?$this->docconfig['docname']:'文档';
- $tabTitle[] = $this->docconfig['colname']?$this->docconfig['colname']:'合辑';
- return [
- 'error' => 0,
- 'msg' => '操作成功',
- 'data' => ['bannerList'=>$bannerList,'adList'=>$adList,'menuList'=>$menuList,'totalNum'=>$totalNum,'predayNum'=>$predayNum,'tabTitle'=>$tabTitle,'newDocList'=>$newDocList,'newColList'=>$newColList,'assetsUrl'=>$this->assetsUrl],
- 'code'=>200
- ];
- }
- //获取栏目列表
- public function actionCatlist()
- {
- $level = $this->docconfig['catlevel'];
- $menuList = Category::getDocCatMenus($this->docconfig['content_model_id']);
- foreach($menuList as $i=>$menu)
- {
- if(empty($menu['childs']))
- {
- $menuList[$i]['childs'][] = ['title'=>$menu['title'],'cat_id'=>$menu['cat_id']];
- }
- else
- {
- foreach($menu['childs'] as $k=>$subMenu)
- {
- if(empty($subMenu['childs']))
- {
- $menuList[$i]['childs'][$k]['childs'][] = ['title'=>$subMenu['title'],'cat_id'=>$subMenu['cat_id']];
- }
- }
- }
- }
- return [
- 'error' => 0,
- 'msg' => '操作成功',
- 'data' => ['menuList'=>$menuList,'level'=>$level],
- 'code'=>200
- ];
- }
- //获取栏目配置
- public function actionCatconfig()
- {
- $cat_id = $this->get['cat_id'];
- $controller = new \app\common\controllers\FController('default','web');
- $controller->initFilterConfig();
- $docFilterConfig = $controller->filterConfig['doc'];
- if($cat_id>0)
- {
- $category = Category::findOne($cat_id);
- //栏目扩展配置(加入SEO)
- $extConfigList = $category->getExtconfig($docFilterConfig['xConfig']);
- }
- return [
- 'error' => 0,
- 'msg' => '操作成功',
- 'data' => ['extConfigList'=>$extConfigList,'spConfig'=>$docFilterConfig['spConfig'],'vpConfig'=>$docFilterConfig['vpConfig'],'sortConfig'=>$docFilterConfig['sortConfigWap']],
- 'code'=>200
- ];
- }
- //文档列表
- public function actionDoclist()
- {
- $doc_type = $this->get['doc_type'];
- $searchConditions = [];
- if(is_array($this->get))foreach($this->get as $k=>$v)
- {
- if($v==0)continue;
- $searchConditions[] = $k.$v;
- }
- //序列化筛选条件
- $controller = new \app\common\controllers\FController('default','web');
- $controller->initFilterConfig();
- $docFilterConfig = $controller->filterConfig['doc'];
- $multiSearch = MultiSearchUrl::getSelfInstance(array('fieldConfig'=> $docFilterConfig['fieldConfig'],'sortConfig'=>$docFilterConfig['sortConfig']));
- $multiSearch->existConditions = $searchConditions;
- $sqlInfo = $multiSearch->sqllizeConditions();
- $catId = $multiSearch->getConditionValueByType($searchConditions,'c');
- $st = $multiSearch->getConditionValueByType($searchConditions,'st');
- if($catId)
- {
- $category = Category::findOne($catId);
- //栏目扩展配置(加入SEO)
- $extConfigList = $category->getExtconfig($docFilterConfig['xConfig']);
- if(is_array($extConfigList))foreach($extConfigList as $extname=>$extConfig){
- if(is_array($extConfig['options']))foreach($extConfig['options'] as $k=>$v){
- if(in_array($extConfig['key'].$k,$searchConditions)){
- $$extname = $v;
- }
- }
- }
- //栏目SEO设置
- $seosettingsPre = 'wap_';
- $cat_name = $category->cat_name;
- $categorySeoSettings = Category::getCatSeoSettings($catId,$seosettingsPre);
- $_replaceconfig = array(
- 'targets'=>['{brand}','{cat_name}','{ext_type_1}','{ext_type_2}','{ext_type_3}','{ext_type_4}','{ext_type_5}'],
- 'values'=>[$this->baseconfig['brand'],$cat_name,$ext_type_1,$ext_type_2,$ext_type_3,$ext_type_4,$ext_type_5],
- 'pre'=>$seosettingsPre
- );
- $metaInfo = seoSettings($categorySeoSettings,$_replaceconfig);
- }
- else
- {
- $metaInfo = [$this->docconfig['meta_title'],$this->docconfig['meta_keywords'],$this->docconfig['meta_description']];
- }
- //初始化查询语句
- $query = DocReal::find()->asArray();
- $sql = " 1=1 ";
- if($sqlInfo['where']) $sql.= $sqlInfo['where'];
- if($doc_type==2)
- {
- $sql .= " and doc_type=2 and status=1 and is_delete=0";
- }
- else
- {
- $sql .= " and doc_type!=2 and status=1 and is_delete=0";
- }
- $currentPage = Yii::$app->request->get('page',1);
- $return = $controller->doList($query,$sql,$sqlInfo,'doc',10,$this->higherconfig);
- $pages = $return['pages'];
- $resultList = $return['resultList'];
- if(is_array($resultList))foreach($resultList as $k=>$result)
- {
- $tempDocType = $result['doc_type1']?$result['doc_type1']:$result['doc_type'];
- if($tempDocType==2)
- {
- $resultList[$k]['thumb'] = $this->makeThumb($result['thumb'],354,254);
- }
- else
- {
- $resultList[$k]['thumb'] = $this->makeThumb($result['thumb'],320,340);
- }
- $resultList[$k]['icon'] = $this->assetsUrl.'images/icon/'.DocReal::getExtImgName($result['ext']).'.png';
- $resultList[$k]['views'] = $this->getDocView($result['views']);
- $resultList[$k]['downs'] = $this->getDocDowns($result['downs']);
- $resultList[$k]['doc_type'] = $tempDocType;
- $resultList[$k]['doc_num'] = $result['doc_num'];
- $resultList[$k]['coin_price'] = number_format($result['coin_price'],1);
- }
- return [
- 'error' => 0,
- 'msg' => '请求成功',
- 'data' => ['resultList'=>$resultList,'count'=>$pages->totalCount,'pageCount'=>$pages->getPageCount(),'currentPage'=>$currentPage,'pageSize'=>$pages->pageSize,'metaInfo'=>$metaInfo],
- 'code'=>200
- ];
- }
- //搜索
- public function actionSearch()
- {
- $kw = safe_replace(urldecode($_GET['kw']));
- $model_id = intval($_GET['model_id']);
- if($kw&&$model_id)
- {
- $controller = new \app\common\controllers\FController('default','web');
- $controller->initFilterConfig();
- $searchReturn = $controller->doSearch($kw,$model_id,$this->higherconfig);
- extract($searchReturn);
- return [
- 'error' => 0,
- 'msg' => '请求成功',
- 'data' => ['resultList'=>$resultList,'count'=>$count,'pageCount'=>$pageCount,'currentPage'=>$currentPage,'pageSize'=>$pageSize],
- 'code'=>200
- ];
- }
- }
- //获取用户信息
- public function actionUserinfo()
- {
- $this->userInfo['avatar'] = getFileUrl($this->user['avatar']);
- return [
- 'error' => 0,
- 'msg' => '请求成功',
- 'data' => ['userInfo'=>$this->userInfo],
- 'code'=>200
- ];
- }
- //返回文档浏览数
- public function getDocView($views)
- {
- $virtualViews = $views+intval($this->docconfig['virtualviews']);
- return $virtualViews>=999?'999+':$virtualViews;
- }
- //返回文档下载数
- public function getDocDowns($downs)
- {
- $virtualDowns = $downs+intval($this->docconfig['virtualdowns']);
- return $virtualDowns>=99?'99+':$virtualDowns;
- }
- //获取广告数据
- private function _getAdData($space_id)
- {
- $dataList = AdData::find()->where("space_id='".$space_id."' and status=1 and end_time>".TIMESTAMP)->orderBy(['list_order'=>SORT_ASC])->asArray()->all();
- return $dataList;
- }
- }
|