123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446 |
- <?php
- namespace backend\controllers;
- use backend\models\AdminUser;
- use common\library\LMUploadFile;
- use common\models\Aboutwe;
- use common\models\Advert;
- use common\models\HotSearch;
- use common\models\Information;
- use common\models\Notice;
- use yii\web\UploadedFile;
- //use common\models\Aboutwe;
- //use common\models\HelpTopic;
- use yii;
- use yii\data\Pagination;
- /**
- * 轮播图,公告,内容,热门管理
- * @package backend\controllers
- */
- class WebconfigController extends BaseController
- {
- public $layout = 'iframe';
- const PAGESIZE =20;
- // const HELP_SUBMIT = 0; //问题提交带审核
- // const HELP_AUDITING = 1; //问题已审核状态
- // const HELP_DEL = 2; //问题删除状态
- //
- //
- // const ISSHOW_SHOW = 1;//问题显示
- // const ISSHOW_NOT = 0;//问题不显示
- /**
- * 编辑框里图片上传
- * @return string
- */
- public function actionUploadsummernote(){
- $file= $_FILES;
- $picture_name=time().rand(0,10000000);
- $fileName = $file['file']['name'];
- $file_ext = strtolower(substr($fileName, strrpos($fileName, '.') + 1));
- $picture_name .= '.'.$file_ext;
- $type = Yii::$app->request->post('type');
- if($type=='information'){
- $folder = "/"."information"."/".date("Ym")."/".date("d")."/";
- }elseif($type=='aboutwe'){
- $folder = "/"."aboutwe"."/".date("Ym")."/".date("d")."/";
- }
- $file_path=\Yii::getAlias('@common/allupload').$folder;
- $file_path_rel = "/".date("Ym")."/".date("d")."/";
- $url =$file_path.$picture_name;
- if(!is_dir($file_path)){
- mkdir($file_path,0777,true);
- }
- if(move_uploaded_file($file['file']['tmp_name'],$file_path.$picture_name)){//上传到服务器
- return $folder.$picture_name;
- }
- }
- /**
- * 公告管理列表
- */
- public function actionNotice()
- {
- $datas = Notice::find()->where('status=:status',[':status'=>Notice::STATUS_ACTIVE])->orderBy('updated_at DESC');
- $pages=new Pagination(["totalCount"=>$datas->count(),"pageSize"=>self::PAGESIZE]);
- $datas=$datas->offset($pages->offset)->limit($pages->limit)->all();
- return $this->render('notice',['datas'=>$datas,'pages'=>$pages]);
- }
- /**
- * 添加公告界面
- */
- public function actionAddnotice()
- {
- $id=Yii::$app->request->get('id');
- $datas = Information::find()->select('title')->where(['status'=>Information::STATUS_ACTIVE])->all();
- if(!empty($id)){
- $model = Notice::find()->where('id = :id',[':id'=>$id])->one();
- return $this->render('add_notice',['model'=>$model,'datas'=>$datas]);
- }else{
- return $this->render('add_notice',['datas'=>$datas]);
- }
- }
- /**
- * 检查内容sid
- */
- public function actionChecksid()
- {
- $title = Yii::$app->request->post('title');
- $model = Information::find()->where('title=:title and status=:status',[':title'=>$title,'status'=>Information::STATUS_ACTIVE])->one();
- if(!empty($model)){
- $id = $model->id;
- $data = Notice::find()->where('sid=:sid and status=:status',[':sid'=>$id,'status'=>Notice::STATUS_ACTIVE])->one();
- if(!empty($data)){
- return json_encode('该内容标题已被安排');
- }
- return json_encode('该内容标题可用');
- }
- return json_encode('该内容标题不存在');
- }
- /**
- * 检查内容sid
- */
- public function actionChecktitle()
- {
- $title = Yii::$app->request->post('title');
- $model = Information::find()->where('title=:title and status=:status',[':title'=>$title,'status'=>Information::STATUS_ACTIVE])->one();
- if(empty($model)){
- return json_encode('该内容标题可用');
- }
- return json_encode('该内容标题已存在');
- }
- /**
- * 添加公告
- */
- public function actionAdd_notice()
- {
- $model =new Notice();
- $over_time = Yii::$app->request->post('end');
- $start = Yii::$app->request->post('start');
- $title = Yii::$app->request->post('title');
- $datas = Information::find()->select('title')->where(['status'=>Information::STATUS_ACTIVE])->all();
- if($title!='请选择标题'){
- $data = Information::find()->where('title=:title',[':title'=>$title])->one();
- if(!empty($data)){
- $model->sid = $data->id;
- if(empty($over_time)){
- $model->over_time = strtotime('2038-1-19');
- }else{
- $model->over_time = strtotime($over_time);
- }
- if(empty($start)){
- $model->release_time = time();
- }else{
- $model->release_time = strtotime($start);
- }
- $model->created_at = time();
- $model->updated_at = time();
- $model->status =Notice::STATUS_ACTIVE;
- if($model->validate() && $model->save()){
- Yii::$app->getSession()->setFlash('success', '添加成功!');
- return $this->redirect(['webconfig/notice']);
- }else{
- Yii::$app->getSession()->setFlash('error', '添加失败');
- return $this->render('add_notice',['datas'=>$datas]);
- }
- }else{
- Yii::$app->getSession()->setFlash('error', '添加失败,该标题不存在');
- return $this->render('add_notice',['datas'=>$datas]);
- }
- }else{
- Yii::$app->getSession()->setFlash('error', '请选择标题');
- return $this->render('add_notice',['datas'=>$datas]);
- }
- }
- /**
- * 修改公告
- * @return \yii\web\Response
- */
- public function actionEdit_notice(){
- $id = Yii::$app->request->post('id');
- $over_time = Yii::$app->request->post('end');
- $start = Yii::$app->request->post('start');
- $title = Yii::$app->request->post('title');
- $datas = Information::find()->select('title')->where(['status'=>Information::STATUS_ACTIVE])->all();
- if($title!='请选择标题') {
- $model = Notice::find()->where('id=:id',[':id'=>$id])->one();
- if (!empty($model)) {
- if (empty($over_time)) {
- $model->over_time = strtotime('2038-1-19');
- } else {
- $model->over_time = strtotime($over_time);
- }
- if (empty($start)) {
- $model->release_time = time();
- } else {
- $model->release_time = strtotime($start);
- }
- $model->updated_at = time();
- if ($model->validate() && $model->save()) {
- Yii::$app->getSession()->setFlash('success', '修改成功!');
- return $this->redirect(['webconfig/notice']);
- } else {
- Yii::$app->getSession()->setFlash('error', '修改失败');
- return $this->render('add_notice', ['model' => $model,'datas'=>$datas]);
- }
- } else {
- Yii::$app->getSession()->setFlash('error', '修改失败,该公告不存在');
- return $this->render('add_notice', ['model' => $model,'datas'=>$datas]);
- }
- }
- }
- /**
- * 删除公告
- * @return string
- */
- public function actionDel_notice(){
- $result=['sign'=>1,'msg'=>'ok'];
- $id = Yii::$app->request->post('id');
- $model = Notice::find()->where('id=:id',[':id'=>$id])->one();
- if(!empty($model)){
- $model->status = Notice::STATUS_DELETED;
- $model->updated_at = time();
- if($model->validate() && $model->save()){
- $result=['sign'=>1,'msg'=>'ok'];
- }else{
- // var_dump($model->getErrors());exit;
- $result=['sign'=>0,'msg'=>'error'];
- }
- }else{
- $result=['sign'=>0,'msg'=>'找不到该规格'];
- }
- return json_encode($result);
- }
- /**
- * 内容管理列表
- */
- public function actionInformation()
- {
- $datas = Information::find()->where('status=:status',[':status'=>Notice::STATUS_ACTIVE])->orderBy('updated_at DESC');
- $pages=new Pagination(["totalCount"=>$datas->count(),"pageSize"=>self::PAGESIZE]);
- $datas=$datas->offset($pages->offset)->limit($pages->limit)->all();
- return $this->render('information',['datas'=>$datas,'pages'=>$pages]);
- }
- /**
- * 添加内容界面
- */
- public function actionAddinformation()
- {
- $id=Yii::$app->request->get('id');
- if(!empty($id)){
- $model = Information::find()->where('id = :id',[':id'=>$id])->one();
- $picture_form = new LMUploadFile();
- return $this->render('add_information',['model'=>$model,'picture_form' => $picture_form]);
- }else{
- $picture_form = new LMUploadFile();
- return $this->render('add_information',["picture_form" => $picture_form]);
- }
- }
- /**
- * 添加内容
- */
- public function actionAdd_information()
- {
- $model =new Information();
- $picture_form = new LMUploadFile();
- if($model->load(Yii::$app->request->post())){
- $title = $_POST['Information']['title'];
- if(!empty($title)){
- $data = Information::find()->where('title=:title and status=:status',[':title'=>$title,':status'=>Information::STATUS_ACTIVE])->one();
- if(empty($data)){
- $model->created_at = time();
- $model->updated_at = time();
- $model->status =Information::STATUS_ACTIVE;
- if($model->validate() && $model->save()){
- Yii::$app->getSession()->setFlash('success', '添加成功!');
- return $this->redirect(['webconfig/information']);
- }else{
- return $this->render('add_information',["picture_form" => $picture_form]);
- }
- }else{
- Yii::$app->getSession()->setFlash('error', '标题已被使用,请使用别的标题');
- return $this->render('add_information',["picture_form" => $picture_form]);
- }
- }else{
- Yii::$app->getSession()->setFlash('error', '标题不能为空');
- return $this->render('add_information',["picture_form" => $picture_form]);
- }
- }else{
- Yii::$app->getSession()->setFlash('error', '修改失败');
- return $this->render('add_information',["picture_form" => $picture_form]);
- }
- }
- /**
- * 编辑内容
- * @return \yii\web\Response
- */
- public function actionEdit_information(){
- $id = Yii::$app->request->post('id');
- $model = Information::find()->where('id=:id',[':id'=>$id])->one();
- $picture_form = new LMUploadFile();
- if($model->load(Yii::$app->request->post())){
- $model->updated_at = time();
- if($model->validate() && $model->save()){
- Yii::$app->getSession()->setFlash('success', '修改成功!');
- return $this->redirect(['webconfig/information']);
- }else{
- Yii::$app->getSession()->setFlash('error', '修改失败');
- return $this->render('add_information',['model'=>$model,'picture_form' => $picture_form]);
- }
- }else{
- Yii::$app->getSession()->setFlash('error', '修改失败');
- return $this->render('add_information',['model'=>$model,'picture_form' => $picture_form]);
- }
- }
- /**
- * 删除内容
- * @return string
- */
- public function actionDel_information(){
- $result=['sign'=>1,'msg'=>'ok'];
- $id = Yii::$app->request->post('id');
- $model = Information::find()->where('id=:id',[':id'=>$id])->one();
- if(!empty($model)){
- $model->status = Information::STATUS_DELETED;
- $model->updated_at = time();
- if($model->validate() && $model->save()){
- $result=['sign'=>1,'msg'=>'ok'];
- }else{
- // var_dump($model->getErrors());exit;
- $result=['sign'=>0,'msg'=>'error'];
- }
- }else{
- $result=['sign'=>0,'msg'=>'找不到该规格'];
- }
- return json_encode($result);
- }
- /**
- * 热门搜索列表
- * @return string
- */
- public function actionHotsearch(){
- $datas = HotSearch::find()->where('status =:status',[':status'=>HotSearch::HOT_SEARCH_COMMON])->all();
- return $this->render('hot_search',['datas'=>$datas]);
- }
- /**
- * 添加热门搜索
- * @return string
- */
- public function actionAddhotsearch(){
- $result = '';
- $keyword = Yii::$app->request->post('keyword');
- if(!empty($keyword)){
- $model = HotSearch::find()->where('keyword=:keyword', [':keyword' => $keyword])->one();
- if(empty($model)){
- $dates = new HotSearch();
- $dates->keyword = $keyword;
- $dates->create_at = time();
- $dates->updated_at = time();
- $dates->status = HotSearch::HOT_SEARCH_COMMON;
- if($dates->validate() && $dates->save()){
- $result = ['sign'=>1,'msg'=>'添加成功','id'=>$dates->id];
- }else{
- $result=['sign'=>0,'msg'=>'添加失败'];
- }
- }else{
- $result=['sign'=>0,'msg'=>'该搜索词已存在'];
- }
- }else{
- $result=['sign'=>0,'msg'=>'搜索词不能为空'];
- }
- return json_encode($result);
- }
- /**
- *编辑热门搜索
- * @return string
- */
- public function actionEdithotsearch(){
- $id = Yii::$app->request->post('id');
- $keyword = Yii::$app->request->post('keyword');
- $model = HotSearch::find()->where('id=:id', [':id' => $id])->one();
- if(!empty($keyword)){
- if(!empty($model)){
- $model->keyword = $keyword;
- $model->updated_at = time();
- if($model->validate() && $model->save()){
- $result = ['sign'=>1,'msg'=>'修改成功'];
- }else{
- $result=['sign'=>0,'msg'=>'修改失败'];
- }
- }else{
- $result=['sign'=>0,'msg'=>'id不存在'];
- }
- }else{
- $result=['sign'=>0,'msg'=>'搜索词不能为空'];
- }
- return json_encode($result);
- }
- /**
- * 删除热门搜索
- * @return string
- */
- public function actionDelhotsearch(){
- $id = Yii::$app->request->post('id');
- $model = HotSearch::find()->where('id=:id', [':id' => $id])->one();
- if(!empty($model)){
- $model->status = HotSearch::HOT_SEARCH_DEL;
- $model->updated_at = time();
- if($model->validate() && $model->save()){
- $result = ['sign'=>1,'msg'=>'删除成功'];
- }else{
- $result=['sign'=>0,'msg'=>'删除失败'];
- }
- }else{
- $result=['sign'=>0,'msg'=>'删除失败'];
- }
- return json_encode($result);
- }
- /**
- * 内容管理上传封面
- * @return string
- */
- public function actionAdvertimgurl()
- {
- $type = Yii::$app->request->post('type');
- if (Yii::$app->request->isPost) {
- $picture_form = new LMUploadFile();
- $picture_form->imageFile = UploadedFile::getInstance($picture_form, 'imageFile');
- if($type=='advert'){
- if ($picture_form->upload('advert_picture',false,160,160)) {
- return "<script language='JavaScript'>window.parent.callback('上传成功!',1,'" . $picture_form->filepath . "');</script>";
- } else {
- if(isset($picture_form->getErrors()['imageFile'][0])){
- $error = $picture_form->getErrors()['imageFile'][0];
- }else{
- $error = '图片上传失败';
- }
- return "<script language='JavaScript'>window.parent.callback('上传失败!',0,'" . $error . "');</script>";
- }
- }else if($type=='covers'){
- if ($picture_form->upload('covers_picture',false,160,160)) {
- return "<script language='JavaScript'>window.parent.callback('上传成功!',1,'" . $picture_form->filepath . "');</script>";
- } else {
- if(isset($picture_form->getErrors()['imageFile'][0])){
- $error = $picture_form->getErrors()['imageFile'][0];
- }else{
- $error = '图片上传失败';
- }
- return "<script language='JavaScript'>window.parent.callback('上传失败!',0,'" . $error . "');</script>";
- }
- }
- }
- }
- }
|