123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173 |
- <?php
- namespace backend\controllers;
- use backend\base\CommonController;
- use backend\base\Help;
- use common\models\Frontend;
- use backend\server\UploadFile;
- use Yii;
- use yii\helpers\Html;
- class FrontendController extends CommonController
- {
- public $enableCsrfValidation = false;
- /*
- * 菜单数据显示
- * */
- public function actionIndex()
- {
- return $this->render('index');
- }
- /*
- * 获取菜单数据
- * */
- public function actionIndexfrom()
- {
- $input = Yii::$app->request->post();
- $model = new \common\models\Frontend();
- $rows = $model->getList($input,['id','name','icon','url','pid','status','function','sort']);
- if($rows)
- {
- $imgUrl = Yii::$app->params['httpImg']['host'].Yii::$app->params['httpImg']['city'];
- foreach ($rows as &$val)
- {
- $val['icon'] = $imgUrl.$val['icon'];
- }
- return Help::JsonData(0,'成功',$model->getListTotal(),$rows);
- }
- return Help::JsonCode(Help::ERROR,Yii::t('app','get_error'));
- }
- /*
- * 父类添加
- */
- public function actionParentadd()
- {
- return $this->render('parentadd');
- }
- /*
- * 添加子菜单页面
- * */
- public function actionCreate()
- {
- return $this->render('create',['model'=>Yii::$app->request->get()]);
- }
- /*
- *添加菜单
- * */
- public function actionCreatefrom()
- {
- $model = new \common\models\Frontend();
- $input = Yii::$app->request->post();
- $url = Yii::$app->params['img_url']['city'];
- $img = UploadFile::InstanceImgName('img',$url);
- if(is_string($img))
- {
- $input['icon'] = $img;
- }
- if($model->load($input,'') && $model->save())
- {
- return Help::JsonCode(Help::SUCCESS,'菜单添加成功');
- }
- return Help::JsonCode(Help::ERROR,'菜单添加失败',$model->errors);
- }
- /*
- * 修改菜单
- * */
- public function actionEditfrom()
- {
- $input = Yii::$app->request->post();
- $model = new \common\models\Frontend();
- $row = $model->FindById($input['id']);
- if($row)
- {
- $url = Yii::$app->params['img_url']['city'];
- $img = UploadFile::InstanceImgName('img',$url);
- if(is_string($img))
- {
- UploadFile::delImg($url,$row->icon);
- $input['icon'] = $img;
- }
- if($row->load($input,'') && $row->save())
- {
- return Help::JsonCode(Help::SUCCESS,Yii::t('app','edit_success'));
- }
- }
- return Help::JsonCode(Help::ERROR,Yii::t('app','edit_error'),$row->errors);
- }
- /*
- * 修改菜单页面
- * */
- public function actionEdit()
- {
- $model = new \common\models\Frontend();
- $result = $model->FindById(Yii::$app->request->get('id'));
- if($result)
- {
- if($result['pid'] == 0)
- {
- return $this->render('parentedit',['model'=>$result]);
- }
- $result['function'] = Html::encode($result['function']);
- return $this->render('edit',['model'=>$result]);
- }
- return $this->goBack();
- }
- /*
- * 修改排序
- * */
- public function actionFrontendmenusortedit()
- {
- $model = new Frontend();
- $input = Yii::$app->request->post();
- $row = $model->GetFindById($input['id']);
- if (!empty($row))
- {
- switch ($input['type'])
- {
- case 'status':
- if($row->status == 1)
- {
- $row->status = 2;
- }else if($row->status == 2)
- {
- $row->status = 1;
- }
- break;
- case 'del':
- $row->del = 2;
- break;
- case 'sort':
- $row->sort = $input['sort'];
- break;
- }
- if($row->save(false)) return Help::JsonCode(Help::SUCCESS,Yii::t('app','edit_success'));
- }
- return Help::JsonCode(Help::ERROR,'操作失败');
- }
- //生成代码 用于显示和隐藏或个HTML模块
- public function actionProduce()
- {
- $input = Yii::$app->request->get();
- if(!empty($input['id']))
- {
- $find = \common\models\Frontend::findOne($input['id']);
- if($find)
- {
- $str = '<?php modules_show('.$find['id'].') ?>';
- }
- }
- return $this->render('produce',['str'=>$str]);
- }
- }
|