request->isAjax) { $query = FInputPolicy::find(); $data = []; $params = Yii::$app->request->get('FInputPolicy',[]); $query = mergeParams($query,$params); $countQuery = clone $query; //分页 if(isset($_GET['limit'])){ $query->limit(intval($_GET['limit']));} if(isset($_GET['offset'])){ $query->offset(intval($_GET['offset']));} //排序 if(isset($_GET['sort'])&&isset($_GET['sortOrder'])) { $sortWay = $_GET['sortOrder']=='asc'?SORT_ASC:SORT_DESC; $resultList = $query->orderBy([$_GET['sort']=>$sortWay])->all(); } else { $resultList = $query->all(); } foreach($resultList as $result) { $data[] = array('id'=>$result->id,'creator'=>$result->creator,'a_time'=>$result->a_time,'m_time'=>$result->m_time,'is_active'=>$result->is_active); } $result = ["total"=>$countQuery->count(),"totalNotFiltered"=>$countQuery->count(),"rows"=>$data]; echo_json($result); } $this->tableTitle = array( array('field'=>'id','title'=>'ID','align'=>'center','sortable'=>true,'class'=>'col-md-2'), array('field'=>'creator','title'=>'创建人','align'=>'center','class'=>'col-md-2'), array('field'=>'a_time','title'=>'创建时间','align'=>'center','class'=>'col-md-2'), array('field'=>'m_time','title'=>'修改时间','align'=>'center','class'=>'col-md-2'), array('field'=>'is_active','title'=>'状态','align'=>'center','formatter'=>'switchFormatter','class'=>'col-md-2'), array('field'=>'operate','title'=>'操作','align'=>'center','events'=>'window.operateEvents','formatter'=>'operateFormatter','class'=>'col-md-2'), ); $this->tableConfig = array('table'=>'f_input_policy','url'=>$this->createRealUrl(['car/baseinfo/celue']),'setFieldUrl'=>$this->createRealUrl(['car/baseinfo/setfield']),'idField'=>FInputPolicy::modelPrimaryKey(),'checkbox'=>0,'dropmenu'=>1,'pagination'=>true,'pagesize'=>20,'refresh'=>true); return $this->render('celue',array('model'=>new FInputPolicy())); } function actionCelueadd() { $model = new FInputPolicy(); if(Yii::$app->request->isAjax&&$model->load(Yii::$app->request->post())){ $post = Yii::$app->request->post(); $model->is_active = $post['FInputPolicy']['is_active']?$post['FInputPolicy']['is_active']:0; $model->a_time = $model->m_time = date('Y-m-d H:i:s'); $model->creator = $this->getIdentityInfo('real_name'); if(!$model->validate()) { $msgdata = ['error' => 1,'msg' => $model->returnFirstError()]; } else { if($model->save()) { $msgdata = ['error' => 0,'msg' => '操作成功']; } else { $msgdata = ['error' => 1,'msg' => '操作失败']; } } echo_json($msgdata); } return $this->renderAjax('celueadd',array('model'=>$model)); } function actionCelueedit() { $id = $this->getKeyId('id'); $model = FInputPolicy::findOne($id); check_record_exists($model); if(Yii::$app->request->isAjax&&$model->load(Yii::$app->request->post())){ $post = Yii::$app->request->post(); $model->is_active = $post['FInputPolicy']['is_active']?$post['FInputPolicy']['is_active']:0; $model->creator = $this->getIdentityInfo('real_name'); $model->m_time = date('Y-m-d H:i:s'); if(!$model->validate()) { $msgdata = ['error' => 1,'msg' => $model->returnFirstError()]; } else { if($model->save(false)) { $msgdata = ['error' => 0,'msg' => '操作成功']; } else { $msgdata = ['error' => 1,'msg' => '操作失败']; } } echo_json($msgdata); } return $this->renderAjax('celueedit',array('model'=>$model)); } function actionCeluedetail() { $id = $this->getKeyId('id'); $model = FInputPolicy::findOne($id); check_record_exists($model); return $this->renderAjax('celuedetail',array('model'=>$model)); } //删除 public function actionCeluedel() { $id = $this->getKeyId('id'); $model = FInputPolicy::findOne($id); check_record_exists($model); if($model->delete()) { $msgdata = ['error' => 0,'msg' => '操作成功!']; } else { $msgdata = ['error' => 1,'msg' => '操作失败!']; } echo_json($msgdata); } public function actionFuzeren() { $query = FCarInfo::find(); if (Yii::$app->request->isAjax) { $data = []; $params = Yii::$app->request->get(); $where = $this->getWhere($query, $params); if(!empty($where)){ $sql = join(" and ",$where); $query->where($sql); } $countQuery = clone $query; //分页 if(isset($_GET['limit'])){ $query->limit(intval($_GET['limit']));} if(isset($_GET['offset'])){ $query->offset(intval($_GET['offset']));} //排序 if(isset($_GET['sort'])&&isset($_GET['sortOrder'])) { $resultList = $query->select('*')->orderBy([$_GET['sort']=>($_GET['sortOrder']=='asc'?SORT_ASC:SORT_DESC)])->asArray()->all(); } else { $resultList = $query->select('*')->orderBy(['car_id'=>SORT_DESC])->asArray()->all(); } foreach($resultList as $result) { $data[] = array('car_id'=>$result['car_id'],'card_num'=>$result['card_num'],'city'=>$result['city'],'dpt_sec'=>$result['dpt_sec'],'grid'=>$result['grid'],'self_rent'=>$result['self_rent'],'car_type'=>$result['car_type'],'using_tag'=>$result['using_tag'],'rps_dpt'=>$result['rps_dpt'],'rps_man'=>$result['rps_man'],'cell_num'=>$result['cell_num'],'is_special_car'=>$result['is_special_car']); } $result = ["total" => $countQuery->count(), "totalNotFiltered" => $countQuery->count(), "rows" => $resultList]; echo_json($result); } $this->tableTitle = array( array('field'=>'card_num','title'=>'车牌号','align'=>'center'), array('field'=>'city','title'=>'单位','align'=>'center'), array('field'=>'dpt_sec','title'=>'二级单位','align'=>'center'), array('field'=>'grid','title'=>'三级单位','align'=>'center'), array('field'=>'own_dpt','title'=>'所属单位','align'=>'center'), array('field'=>'rps_man','title'=>'负责人姓名','align'=>'center','formatter'=>'editFormatter'), array('field'=>'cell_num','title'=>'电话','align'=>'center','formatter'=>'editFormatter'), ); //$this->tableConfig = array('table'=>'f_car_info','url'=>$this->createRealUrl(['car/baseinfo/fuzeren']),'setFieldUrl'=>$this->createRealUrl(['car/baseinfo/setfield']),'idField'=>'car_id','checkbox'=>0,'dropmenu'=>1,'pagination'=>true,'pagesize'=>20,'refresh'=>true,'height'=>500); $this->tableConfig = array('table' => 'f_car_info', 'url' => $this->createRealUrl(['car/baseinfo/fuzeren']), 'setFieldUrl' => $this->createRealUrl(['car/baseinfo/setfield']), 'idField' => 'car_id', 'checkbox' => 0, 'dropmenu' => 1, 'pagination' => true, 'pagesize' => 20, 'refresh' => true, 'height' => 500, 'tableClass' => 'table-nowrap'); return $this->render('fuzeren',array('model'=>new FCarInfo())); } //特殊车辆 public function actionSpecar() { if (Yii::$app->request->isAjax) { $query = FSpcCar::find(); $data = []; $params = Yii::$app->request->get('FSpcCar',[]); $query = mergeParams($query,$params); $countQuery = clone $query; //分页 if(isset($_GET['limit'])){ $query->limit(intval($_GET['limit']));} if(isset($_GET['offset'])){ $query->offset(intval($_GET['offset']));} //排序 if(isset($_GET['sort'])&&isset($_GET['sortOrder'])) { $sortWay = $_GET['sortOrder']=='asc'?SORT_ASC:SORT_DESC; $resultList = $query->orderBy([$_GET['sort']=>$sortWay])->all(); } else { $resultList = $query->all(); } foreach($resultList as $result) { $data[] = array('id'=>$result->id,'card_num'=>$result->card_num,'is_spec'=>$result->is_spec,'bak'=>$result->bak,'dept'=>$result->dept); } $result = ["total"=>$countQuery->count(),"totalNotFiltered"=>$countQuery->count(),"rows"=>$data]; echo_json($result); } $this->tableTitle = array( array('field'=>'id','title'=>FSpcCar::getAttributeName('id'),'align'=>'center','sortable'=>true,'class'=>'col-md-1'), array('field'=>'card_num','title'=>FSpcCar::getAttributeName('card_num'),'align'=>'center','class'=>'col-md-2'), array('field'=>'is_spec','title'=>FSpcCar::getAttributeName('is_spec'),'align'=>'center','formatter'=>'switchFormatter','class'=>'col-md-2'), array('field'=>'bak','title'=>FSpcCar::getAttributeName('bak'),'align'=>'center','class'=>'col-md-2'), array('field'=>'dept','title'=>FSpcCar::getAttributeName('dept'),'align'=>'center','class'=>'col-md-2'), array('field'=>'operate','title'=>FSpcCar::getAttributeName('operate'),'align'=>'center','events'=>'window.operateEvents','formatter'=>'operateFormatter','class'=>'col-md-2'), ); $this->tableConfig = array('table'=>'f_spc_car','url'=>$this->createRealUrl(['car/baseinfo/specar']),'setFieldUrl'=>$this->createRealUrl(['car/baseinfo/setfield']),'idField'=>FSpcCar::modelPrimaryKey(),'checkbox'=>0,'dropmenu'=>1,'pagination'=>true,'pagesize'=>20,'refresh'=>true); return $this->render('spelist',array('model'=>new FSpcCar())); } function actionAddspec() { $model = new FSpcCar(); if(Yii::$app->request->isAjax&&$model->load(Yii::$app->request->post())){ if(!$model->validate()) { $msgdata = ['error' => 1,'msg' => $model->returnFirstError()]; } else { if($model->save()) { $msgdata = ['error' => 0,'msg' => '操作成功']; } else { $msgdata = ['error' => 1,'msg' => '操作失败']; } } echo_json($msgdata); } return $this->renderAjax('addspec',array('model'=>$model)); } function actionEditspec() { $id = $this->getKeyId(); $model = FSpcCar::findOne($id); check_record_exists($model); if(Yii::$app->request->isAjax&&$model->load(Yii::$app->request->post())){ if(!$model->validate()) { $msgdata = ['error' => 1,'msg' => $model->returnFirstError()]; } else { if($model->save()) { $msgdata = ['error' => 0,'msg' => '操作成功']; } else { $msgdata = ['error' => 1,'msg' => '操作失败']; } } echo_json($msgdata); } return $this->renderAjax('addspec',array('model'=>$model)); } //删除 public function actionDelspec() { $id = $this->getKeyId(); $model = FSpcCar::findOne($id); check_record_exists($model); if($model->delete()) { $msgdata = ['error' => 0,'msg' => '操作成功!']; } else { $msgdata = ['error' => 1,'msg' => '操作失败!']; } echo_json($msgdata); } //数据导入查询 public function actionDataimport() { $statusOption = [ '-1' => '导入失败', '0' => '上传成功', '1' => '导入成功', ]; if (Yii::$app->request->isAjax) { $query = FDataImport::find(); $data = []; $params = Yii::$app->request->get(); $where = []; if(!empty($params['template'])){ $where['template'] = $params['template']; } if(!empty($params['statistical_month'])){ $where['statistical_month'] = str_replace('-','',$params['statistical_month']); } $query->where($where); $countQuery = clone $query; //分页 if(isset($_GET['limit'])){ $query->limit(intval($_GET['limit']));} if(isset($_GET['offset'])){ $query->offset(intval($_GET['offset']));} //排序 if(isset($_GET['sort'])&&isset($_GET['sortOrder'])) { $sortWay = $_GET['sortOrder']=='asc'?SORT_ASC:SORT_DESC; $resultList = $query->orderBy([$_GET['sort']=>$sortWay])->asArray()->all(); } else { $resultList = $query->orderBy(['a_id'=>SORT_DESC])->asArray()->all(); } foreach($resultList as $result) { $data[] = ['file_name'=>$result['file_name'],'file_path'=>UPLOAD_URL.$result['file_path'],'template'=>$result['template'],'statistical_month'=>$result['statistical_month'],'upload_time'=>$result['upload_time'],'status'=>$statusOption[$result['status']],'remark'=>$result['remark']]; } $result = ["total"=>$countQuery->count(),"totalNotFiltered"=>$countQuery->count(),"rows"=>$data]; echo_json($result); } $this->tableTitle = array( array('field'=>'template','title'=>'导入模板','align'=>'center','sortable'=>true), array('field'=>'statistical_month','title'=>'导入账期','align'=>'center','sortable'=>true), array('field'=>'upload_time','title'=>'上传时间','align'=>'center','sortable'=>true), array('field'=>'file_name','title'=>'文件名','align'=>'center','sortable'=>true), array('field'=>'status','title'=>'状态','align'=>'center','sortable'=>true), array('field'=>'remark','title'=>'失败原因','align'=>'center','sortable'=>true), ); $this->tableConfig = array('table'=>'f_data_import','url'=>$this->createRealUrl(['car/baseinfo/dataimport']),'setFieldUrl'=>$this->createRealUrl(['car/baseinfo/setfield']),'idField'=>'a_id','checkbox'=>0,'dropmenu'=>1,'pagination'=>true,'pagesize'=>20,'refresh'=>true); return $this->render('dataimport',array('model'=>new FSpcCar())); } //数据上传 public function actionUpload() { if (Yii::$app->request->isPost) { Yii::$app->response->format = Response::FORMAT_JSON; //try { //按名称获取实例 $file = UploadedFile::getInstanceByName('file'); if (empty($file)) { return ['code' => 1, 'msg' => '上传失败,没有文件!']; } //是否有错误 if ($file->getHasError()) { return ['code' => 1, 'msg' => '文件异常!']; } //1M $default = 1048576; //匹配文件后缀 $extension = $file->getExtension(); if (!in_array($extension, ['xls','xlsx','csv'])) { return ['code' => 1, 'msg' => '暂不支持上传' . $extension . '文件']; } if ($file->size > 50 * $default) { return ['code' => 1, 'msg' => '上传文件过大!']; } $params = Yii::$app->request->post(); if(empty($params['template'])){ return ['code' => 1, 'msg' => '请选择上传模板!']; } if(empty($params['statistical_month'])){ return ['code' => 1, 'msg' => '请选择导入账期!']; } $params['statistical_month'] = safe_replace(str_replace('-','',$params['statistical_month'])); if(strpos($file->name,$params['template'])===false){ return ['code' => 1, 'msg' => '导入文件名与导入模板名称不匹配,导入文件名需包含导入模板名称('.$params['template'].')!']; } if($res = FDataImport::find()->where(['template'=>$params['template'],'statistical_month'=>$params['statistical_month']])->one()){ return ['code' => 1, 'msg' => $params['template'].','.$params['statistical_month'].'账期已导入,请联系管理员处理!']; } $childPath = 'car-data'.DIRECTORY_SEPARATOR.date('Ymd',TIMESTAMP).DIRECTORY_SEPARATOR; $targetPath = UPLOAD_PATH.$childPath; $fileName = get_unique_file_name($targetPath,$file->extension);//文件重命名 if (!is_dir($targetPath)) { FileHelper::createDirectory($targetPath); } $targetFile = $targetPath . $fileName; $filePath = str_replace(DIRECTORY_SEPARATOR,'/',$childPath.$fileName); $fileUrl = UPLOAD_URL.$filePath; if ($file->saveAs($targetFile)) { if (!file_exists($targetFile)) { return ['code' => 1, 'msg' => '文件保存失败!']; } //写入附件表 $attachment = new FDataImport(); $attachment->file_name = $file->name; $attachment->file_path = $filePath; $attachment->file_size = $file->size; $attachment->file_ext = $file->extension; $attachment->hash = md5($filePath); $attachment->upload_time = date('Y-m-d H:i:s'); $attachment->upload_ip = self::getClientIp(); $attachment->template = $params['template']; $attachment->statistical_month = $params['statistical_month']; $attachment->status = 0; $attachment->save(); return [ 'code' => 0, 'url' =>$fileUrl, 'attachment' => $filePath, 'name'=>$file->name, 'size'=>$file->size ]; } return ['code' => 1, 'msg' => '文件保存异常!']; //} catch (Exception $e) { //return ['code' => 1, 'msg' => '调用失败']; //} } return ['code' => 1, 'msg' => '没有文件!']; } /**获取客户端ip * @return string */ protected function getClientIp () { if (getenv('HTTP_CLIENT_IP')) { $ip = getenv('HTTP_CLIENT_IP'); } else if (getenv('HTTP_X_FORWARDED_FOR')) { $ip = getenv('HTTP_X_FORWARDED_FOR'); } else if (getenv('REMOTE_ADDR')) { $ip = getenv('REMOTE_ADDR'); } else { $ip = $_SERVER['REMOTE_ADDR']; } return $ip; } }