You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
144 lines
3.6 KiB
144 lines
3.6 KiB
<?php
|
|
|
|
namespace frontend\controllers;
|
|
|
|
use common\libs\MyLib;
|
|
use common\models\MeetT;
|
|
use Yii;
|
|
use yii\web\Response;
|
|
|
|
class MeetController extends \yii\web\Controller
|
|
{
|
|
public $my = null;
|
|
private $_STATE = 1;
|
|
|
|
public function init()
|
|
{
|
|
parent::init();
|
|
|
|
$cookie = Yii::$app->request->cookies;
|
|
$user_id = MyLib::encrypt($cookie->get('aid'),'DECODE');
|
|
|
|
if($user_id != 0)
|
|
{
|
|
$this->my = MeetT::findOne(['id'=>$user_id]);
|
|
} else {
|
|
Yii::$app->response->redirect('/common/login')->send();
|
|
exit;
|
|
}
|
|
}
|
|
|
|
//列表页
|
|
public function actionList()
|
|
{
|
|
|
|
$request = Yii::$app->request;
|
|
$name = $request->get('name');
|
|
$mtype = $request->get('mtype');
|
|
$meet = MeetT::find();
|
|
if($name != ''){
|
|
$meet = $meet->andWhere(['like','name',$name]);
|
|
}
|
|
if($mtype > 0){
|
|
$meet = $meet->andWhere('mtype ='.$mtype);
|
|
}
|
|
$meet = $meet->andWhere('state ='.$this->_STATE);
|
|
$data = $meet->orderBy('id ASC')->all();
|
|
|
|
return $this->render('list',[
|
|
'info' => $data,
|
|
'name' => $name,
|
|
'mtype' => $mtype,
|
|
]);
|
|
}
|
|
|
|
//修改,添加页面
|
|
public function actionEdit()
|
|
{
|
|
|
|
$request = Yii::$app->request;
|
|
$id = $request->get('id');
|
|
if($id > 0) {
|
|
$info = MeetT::findOne(['id'=>$id]);
|
|
} else {
|
|
$info = new MeetT();
|
|
}
|
|
return $this->render('edit',[
|
|
'info' => $info,
|
|
]);
|
|
}
|
|
|
|
//ajax修改,新增
|
|
public function actionSave()
|
|
{
|
|
Yii::$app->response->format = Response::FORMAT_JSON;
|
|
$request = Yii::$app->request;
|
|
|
|
$result = array();
|
|
$result['success'] = false;
|
|
$result['msg'] = '保存失败';
|
|
|
|
if($request->isPost){
|
|
|
|
$id = $request->post('id',0);
|
|
$name = $request->post('name');
|
|
$code = $request->post('code');
|
|
$mtype = $request->post('mtype');
|
|
|
|
if($code == '') {
|
|
$result['msg'] = '请输入状态码!';
|
|
return $result;
|
|
}
|
|
if($mtype == 0) {
|
|
$result['msg'] = '请选择类型!';
|
|
return $result;
|
|
}
|
|
if($name == '') {
|
|
$result['msg'] = '请输入名称!';
|
|
return $result;
|
|
}
|
|
|
|
if($id > 0) {
|
|
$row = MeetT::findOne(['id'=>$id]);
|
|
} else {
|
|
$row = new MeetT();
|
|
}
|
|
$row->code = $code;
|
|
$row->mtype = $mtype;
|
|
$row->name = $name;
|
|
$row->state = 1;
|
|
$row->save();
|
|
|
|
$result['success'] = true;
|
|
$result['msg'] = '保存成功';
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
|
|
//删除
|
|
public function actionDel()
|
|
{
|
|
Yii::$app->response->format = Response::FORMAT_JSON;
|
|
$request = Yii::$app->request;
|
|
$result = array();
|
|
$result['success'] = false;
|
|
$result['msg'] = '删除失败';
|
|
|
|
if($request->isPost) {
|
|
|
|
$id = $request->post('id');
|
|
if($id > 0){
|
|
$row = MeetT::findOne(['id'=>$id]);
|
|
$row->state = 0;
|
|
$row->save();
|
|
|
|
$result['success'] = true;
|
|
$result['msg'] = '保存成功';
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
}
|
|
|
|
}
|
|
|