userInfo = Identify::getUserInfo(); } //处理文档下载请求 public function actionDowndoc() { $docConfigResult = Yii::$app->db->createCommand("select * from {{%config}} where name='doc'")->queryOne(); $docConfig = string2array($docConfigResult['value']); $mimes = getMimes(); $direct = Yii::$app->request->get('direct'); $downcode = Yii::$app->request->get('downcode'); $downcodeModel = \app\modules\doc\models\DocDowncode::find()->where("downcode='".$downcode."'")->one(); if($downcodeModel&&$downcodeModel->doc_id) { $doc = DocReal::findOne($downcodeModel->doc_id); $docData = DocRealData::findOne($downcodeModel->doc_id); if($doc&&$docData) { $downFlag = false; //普通下载场景需要校验用户 if((!empty($this->userInfo['user_id'])&&$downcodeModel->user_id == $this->userInfo['user_id'])||$direct==1) { $downFlag = true; } if($downFlag) { //生成下载日志 $downlog = DocDownlog::find()->where("user_id=".intval($this->userInfo['user_id'])." and doc_id=".$doc->id)->one(); if($downlog) { $downlog->updateCounters(['count'=>1]); } else { $downlog = new DocDownlog(); $downlog->user_id = intval($this->userInfo['user_id'])?intval($this->userInfo['user_id']):intval($downcodeModel->user_id); $downlog->doc_id = $doc->id; $downlog->cat_id = $doc->cat_id; $downlog->doc_type = $doc->doc_type; $downlog->count = 1; $downlog->create_time = TIMESTAMP; $downlog->save(); } //更新文档被下载次数 $doc->updateCounters(['downs'=>1]); //输出文件下载请求 $file = sys_auth($docData->file,'DECODE',$docData->hash); //对于大文件,生成种子文件 if($doc->filesize>=$docConfig['bigfilesize']*1024*1024) { $tempFile = locateFile(getFileUrl($file),'download'); $file = initBigfileTorent($tempFile,$doc,$docConfig); $bigFileTip = '【下载说明】'; } else if($doc->doc_type==3)//网盘资源 { $file = initPanfile($doc,$docConfig); $bigFileTip = '【提取说明】'; } else if($doc->doc_type==2)//合辑文档 { $allsize = 0; $docIds = Yii::$app->db->createCommand("SELECT doc_id FROM {{%doc_col}} where col_id=".$doc->id)->queryColumn(); $resultList = DocReal::findAll($docIds); foreach($resultList as $result) { $allsize += $result->filesize; $contentList[] = array('title'=>$result->title,'ext'=>$result->ext,'file'=>sys_auth($result->data->file,'DECODE',$result->data->hash)); } $tempFile = locateColFile($doc,$contentList); $file = initBigfileTorent($tempFile,$doc,$docConfig); $bigFileTip = '【下载说明】'; } $ext = fileext($file); $mime = $mimes[$ext]; if(is_array($mime))$mime = $mime[0]; $fileContents = file_get_contents(getFileUrl($file)); $downcodeModel->used = 1; $downcodeModel->save(); ob_clean(); header("Content-Type: $mime; charset=UTF-8"); if(preg_match("/Safari/", $_SERVER["HTTP_USER_AGENT"])) { $filename = rawurlencode($doc->title.$bigFileTip); $filename = iconv('utf-8', 'gbk', $filename); header( 'Content-Disposition: attachment; filename*=UTF-8\'\''. $filename.'.'.$ext); } else { header("Content-Disposition:attachment;filename=".rawurlencode(rtrim($doc->title.$bigFileTip,".")).'.'.$ext); } echo $fileContents; exit; } } } } //判断下载请求处理状态 public function actionCheckdown() { $downcode = Yii::$app->request->get('downcode'); $downcodeModel = \app\modules\doc\models\DocDowncode::find()->where("downcode='".$downcode."'")->one(); if($downcodeModel->used==1) { $result = [ 'error' => 0, 'msg' => '处理完毕', 'data' => [], 'code'=>200 ]; echo_json($result); } } //联动菜单下级数据获取 public function actionNextlinkmenu() { $parent_id = isset($_GET['parent_id'])?intval($_GET['parent_id']):0; if(empty($parent_id)) { $result = array('error'=>1,'msg'=>'获取失败'); } else { $parentMenu = Linkmenu::findOne($parent_id); if(empty($parentMenu)) { $result = array('error'=>1,'msg'=>'获取失败'); } else { $query = Linkmenu::find(); if($parentMenu->key_id==0){ $params =['key_id'=>$parent_id,'parent_id'=>0,'disabled'=>0]; } else { $params =['parent_id'=>$parent_id,'disabled'=>0]; } $query = mergeParams($query,$params); $menuList = $query->orderBy(['list_order'=>SORT_ASC])->all(); if(is_array($menuList))foreach($menuList as $menu) { $data[] = array('menu_id'=>$menu->menu_id,'name'=>$menu->name); } $result = array('error'=>0,'msg'=>'获取成功','data'=>$data); echo_json($result); } } } //获取下级栏目 public function actionNextlinkcat() { $parent_id = isset($_GET['parent_id'])?intval($_GET['parent_id']):0; $content_model_id = isset($_GET['content_model_id'])?intval($_GET['content_model_id']):0; if(empty($parent_id)&&empty($content_model_id)) { $result = array('error'=>1,'msg'=>'获取失败'); } else { $catList = json_decode(Yii::$app->cache->get(CacheId::categoryItemsCacheId($content_model_id)),true); $data = []; if($content_model_id&&empty($parent_id)) { if(is_array($catList))foreach($catList as $cat) { if($cat['parent_id']==0) { $data[] = array('cat_id'=>$cat['cat_id'],'cat_name'=>$cat['cat_name']); } } } else if($content_model_id&&$parent_id) { if(is_array($catList))foreach($catList as $cat) { if($cat['parent_id']==$parent_id) { $data[] = array('cat_id'=>$cat['cat_id'],'cat_name'=>$cat['cat_name']); } } } $result = array('error'=>0,'msg'=>'获取成功','data'=>$data); } echo_json($result); } //获取栏目扩展配置 public function actionGetextconfig() { $cat_id = isset($_GET['cat_id'])?intval($_GET['cat_id']):0; $id = isset($_GET['id'])?intval($_GET['id']):0; $realStr = !empty($_GET['real'])?'_real':''; if(empty($cat_id)) { $result = array('error'=>1,'msg'=>'获取失败'); } else { $category = Category::findOne($cat_id); //栏目面包屑 $catTitTree = []; $catBreadInfos = Category::getParentCatRs($cat_id); if(is_array($catBreadInfos))foreach($catBreadInfos as $catBread) { $catTitTree[] = $catBread['cat_name']; } $catTitTree = join(" > ",$catTitTree); $model_list = json_decode(Yii::$app->cache->get(\app\common\components\CacheId::modelListCacheId()),true); $model = $model_list[$category->content_model_id]; $table_1_name = $model['table_name'].$realStr; $table_2_name = $model['table_name'].$realStr.'_data'; $model_name = getModelName($table_1_name); if($category->arr_parent_ids) { $extTypeList = CategoryConfig::find()->where("cat_id=".$cat_id." or cat_id in(".trim($category->arr_parent_ids,',').")")->orderBy(['cat_id'=>SORT_ASC,'list_order'=>SORT_ASC])->limit(5)->asArray()->all(); } else { $extTypeList = CategoryConfig::find()->where("cat_id=".$cat_id)->orderBy(['cat_id'=>SORT_ASC,'list_order'=>SORT_ASC])->limit(5)->asArray()->all(); } if($id) { $connection = Yii::$app->db; $sql = "select * from {{%".$table_1_name."}} a left join {{%".$table_2_name."}} b on a.id=b.id where a.id = ".$id.""; $command=$connection->createCommand($sql); $row=$command->queryOne(); } else { $row = []; } if(is_array($extTypeList))foreach($extTypeList as $k=>$ext_type) { $simpleField = 'ext_type_'.($k+1); $ext_type['var_name'] = $simpleField; $optionList = []; $field = $model_name?$model_name.'['.$ext_type['var_name'].']':$ext_type['var_name']; $fieldId = str_replace(array('[',']'),array('-',''),strtolower($field)); $value = $row[$simpleField]; if($ext_type['type']==1) { $optionList = string2array($ext_type['value']); $formlist[] = array( 'label'=>$ext_type['bak'], 'html'=> FormElements::select($optionList,$value,"请选择","name='$field' id='$fieldId' lay-ignore class='form-select ' "), 'optionList'=>$optionList, 'type'=>$ext_type['type'], ); } else if($ext_type['type']==2) { $options = string2array($ext_type['value']); foreach($options as $v) { $optionList[$v] = $v; } $formlist[] = array( 'label'=>$ext_type['bak'], 'html'=> FormElements::select($optionList,$value,"请选择","name='$field' id='$fieldId' lay-ignore class='form-select '"), 'optionList'=>$optionList, 'type'=>$ext_type['type'], ); } else if($ext_type['type']==3) { $sysconfig = Sysconfig::find()->where("name='".$ext_type['value']."'")->one(); if($sysconfig->type==1) $optionList = json_decode($sysconfig->value,true); if($sysconfig->type==2) { $options = json_decode($sysconfig->value,true); foreach($options as $v) { $optionList[$v] = $v; } } $formlist[] = array( 'label'=>$ext_type['bak'], 'html'=> FormElements::select($optionList,$value,"请选择","name='$field' id='$fieldId' lay-ignore class='form-select '"), 'optionList'=>$optionList, 'type'=>$ext_type['type'], ); } else if($ext_type['type']==4) { $array = array(); $array['key_id']= $ext_type['value']; $array['id']= $fieldId; $array['name']= $field; $array['level']= $ext_type['level']?$ext_type['level']:2; $array['emptyTxts']= ['请选择','请选择','请选择']; if(isset($value))$array['value']= $value; $array['selectClass']= 'form-select '; $array['blockClass']= 'mb-3 row'; $array['unitClass']= 'col-md-'.(12/$ext_type['level']); $array['unitStyle'] = 'padding-right:10px;'; $html = LinkmenuWidget::widget($array); $formlist[] = array( 'label'=>$ext_type['bak'], 'html'=> $html, 'optionList'=>[], 'type'=>$ext_type['type'], ); } } $result = array('error'=>0,'msg'=>'','data'=>['formlist'=>$formlist,'catTitTree'=>$catTitTree]); } echo_json($result); } //生成二维码 public function actionQrcode() { ob_clean(); $url = $_GET['url']; $qrcode = new \app\components\qrcode\qrcode($url); $qrcode->create(); } //生成含入口脚本的URL地址 public function createRealUrl($params) { return urldecode(Yii::$app->urlManager->createAbsoluteUrl($params)) ; } //记录显示模式 public function actionSetshowmode() { $showmode = $_GET['showmode']; $pageflag = $_GET['pageflag']; if(!empty($showmode)&&!empty($pageflag)) { Cookie::setCookie($pageflag,$showmode); } } //处理前台加载文档页面 public function actionLoaddocpage() { ini_set('pcre.backtrack_limit', 999999999); $page = Yii::$app->request->get('page'); $type = Yii::$app->request->get('type'); $id = Yii::$app->request->get('id'); if(!empty($page)&&!empty($type)&&!empty($id)) { $docData = DocRealData::findOne($id); //文档内容 $imgcode = string2array($docData->imgcode); $h5code = string2array($docData->h5code); if($type=='h5') { $result = https_request(getFileUrl($h5code[$page])); //过滤时段 $badwordConfigResult = Yii::$app->db->createCommand("select * from {{%config}} where name='badword'")->queryOne(); $badwordConfig = string2array($badwordConfigResult['value']); $filter = true; $hournow = get_date(TIMESTAMP,'H'); if($badwordConfig['hours']) { $hours = explode(",",$badwordConfig['hours']); if(!in_array($hournow,$hours)) { $filter = false; } } //爬虫过滤 if(isSpider()&&!$badwordConfig['open_spider']) { $filter = false; } if($filter) { $sesResult = sensitive($result); if(!empty($sesResult['after'])) { $result = $sesResult['after']; } } } else { $result = ""; } echo_json(array('error'=>'0','msg'=>'获取成功','data'=>$result)); } } //处理前台加载文档页面 public function actionLoaddocpagedirect() { ini_set('pcre.backtrack_limit', 999999999); $page = Yii::$app->request->get('page'); $type = Yii::$app->request->get('type'); $id = Yii::$app->request->get('id'); if(!empty($page)&&!empty($type)&&!empty($id)) { $docData = DocRealData::findOne($id); //文档内容 $imgcode = string2array($docData->imgcode); $h5code = string2array($docData->h5code); if($type=='h5') { $result = https_request(getFileUrl($h5code[$page])); //过滤时段设置 $badwordConfigResult = Yii::$app->db->createCommand("select * from {{%config}} where name='badword'")->queryOne(); $badwordConfig = string2array($badwordConfigResult['value']); $filter = true; $hournow = get_date(TIMESTAMP,'H'); if($badwordConfig['hours']) { $hours = explode(",",$badwordConfig['hours']); if(!in_array($hournow,$hours)) { $filter = false; } } //爬虫过滤 if(isSpider()&&!$badwordConfig['open_spider']) { $filter = false; } if($filter) { $sesResult = sensitive($result); if(!empty($sesResult['after'])) { $result = $sesResult['after']; } } } else { $result = ""; } echo $result; exit; } } //处理前台加载多媒体文档数据 public function actionLoaddocblob() { $id = Yii::$app->request->get('id'); if(!empty($id)) { $docData = DocRealData::findOne($id); //文档内容 $h5code = string2array($docData->h5code); $media_file = getFileUrl($h5code[0]); ob_clean(); echo https_request($media_file); } } //访问记录 public function actionVisitrecord() { $table_name = Yii::$app->request->get('table_name'); $data_id = Yii::$app->request->get('data_id'); $cat_id = Yii::$app->request->get('cat_id'); if(!empty($table_name)&&!empty($data_id)) { $tableLogDate = Yii::$app->db->tablePrefix."visit_record_".date('Ymd'); $preLogTable = Yii::$app->db->tablePrefix."visit_record_".date('Ymd',TIMESTAMP-24*3600); $sqlbuf = "show tables like '".$tableLogDate."';"; $result = Yii::$app->db->createCommand($sqlbuf)->queryOne(); if(!$result) { $sqlbuf = "create table if not exists $tableLogDate like {{%visit_record_t}};"; Yii::$app->db->createCommand($sqlbuf)->execute(); $sqlbuf = "show tables like '".$preLogTable."';"; $exist = Yii::$app->db->createCommand($sqlbuf)->queryAll(); if($exist) { $sqlbuf = "drop table $preLogTable;"; Yii::$app->db->createCommand($sqlbuf)->execute(); } } $visit_ip = MYIP; $visit_time = TIMESTAMP; $request_from = REQUEST_FROM; $sqlbuf="insert into $tableLogDate(table_name,data_id,cat_id,request_from,visit_ip,visit_time)values('".$table_name."',$data_id,$cat_id,$request_from,$visit_ip,$visit_time)"; Yii::$app->db->createCommand($sqlbuf)->execute(); $date = str_to_time(get_date(TIMESTAMP,'Y-m-d')); $stModel = VisitStatisticsByDay::find()->where("table_name='".$table_name."' and data_id = $data_id and date='".$date."'")->one(); if(empty($stModel)) { $stModel = new VisitStatisticsByDay(); $stModel->table_name = $table_name; $stModel->data_id = $data_id; $stModel->cat_id = $cat_id; $stModel->date = $date; $stModel->pv=1; $stModel->uv=1; $stModel->save(); } else { $sqlbuf = "select count(distinct(visit_ip)) as uv from $tableLogDate where table_name='".$table_name."' and data_id = $data_id"; $result = Yii::$app->db->createCommand($sqlbuf)->queryOne(); $uv = $result['uv']; $stModel->uv = $uv; $stModel->pv = $stModel->pv+1; $stModel->save(); } //查询数据表主键 $primaryKey = getPrikeyByTableName($table_name); if($primaryKey) { $sqlbuf = "update {{%$table_name}} set views=views+1 where $primaryKey = $data_id"; Yii::$app->db->createCommand($sqlbuf)->execute(); } //写历史记录 if($table_name&&Identify::hasLogined()) { $history = new UserHistory(); $history->table_name = $table_name; $history->data_id = $data_id; $history->user_id = Identify::getUserInfo(NULL,'user_id'); $history->create_time = TIMESTAMP; $history->save(); } } } //根据车牌搜索车辆 public function actionSearchcar() { $kw = Yii::$app->request->get('kw'); $city1 = Yii::$app->request->get('city1'); $city2 = Yii::$app->request->get('city2'); $city3 = Yii::$app->request->get('city3'); $params = []; $sql = "select card_num from wz_f_car_info "; if(!empty($kw)) $params[] = "card_num like '%".$kw."%'"; if(!empty($city1) && $city1!='全省') $params[] = "city = '".$city1."'"; if(!empty($city2) && $city2!='地市') $params[] = "dpt_sec = '".$city2."'"; if(!empty($city3) && $city3!='网格') $params[] = "grid = '".$city3."'"; if($params) $sql .= " where ".implode(' and ',$params); $sql .= "group by card_num limit 20"; //if(!empty($kw)) //{ $resultList = Yii::$app->db->createCommand($sql)->queryAll(); foreach($resultList as $result) { $carList[] = $result['card_num']; } $result = [ 'error' => 0, 'msg' => '搜索成功', 'data' => ['carList'=>$carList], 'code'=>200 ]; echo_json($result); //} } //下拉车牌搜索 public function actionSelectcar() { $kw = Yii::$app->request->post('card_num'); $city1 = Yii::$app->request->post('city1'); $city2 = Yii::$app->request->post('city2'); $city3 = Yii::$app->request->post('city3'); $page = Yii::$app->request->post('pageNumber')?:1; $pagesize = Yii::$app->request->post('pageSize')?:10; $params = []; if(empty($kw)) $kw = Yii::$app->request->post('searchValue'); //$sql = "select card_num from wz_f_car_info "; if(!empty($kw)) $params[] = "card_num like '%".strtoupper($kw)."%'"; $ci = ['全省','地市','网格','单位','一级单位','二级单位','三级单位']; if(!empty($city1) && !in_array($city1,$ci)) $params[] = "city = '".$city1."'"; if(!empty($city2) && !in_array($city2,$ci)) $params[] = "dpt_sec = '".$city2."'"; if(!empty($city3) && !in_array($city3,$ci)) $params[] = "grid = '".$city3."'"; //if($params) $sql .= " where ".implode(' and ',$params); $query = FCarInfo::find()->select('card_num')->where(join(' and ',$params))->groupBy('card_num'); $countQuery = clone $query; $resultList = $query->limit(intval($pagesize))->offset(intval(($page-1)*$pagesize))->orderBy(['card_num' => SORT_DESC])->asArray()->all(); $result = [ 'error' => 0, 'msg' => '搜索成功', 'totalRow' => $countQuery->count(), 'list' => $resultList, 'code'=>200 ]; echo_json($result); //} } }