453 lines
15 KiB
PHP
Executable File
453 lines
15 KiB
PHP
Executable File
<?php
|
|
|
|
/**
|
|
* @Author: fm453
|
|
* @Date: 2018-08-17 19:39:41
|
|
# @Last modified by: fm453
|
|
# @Last modified time: 2021-09-15T16:42:59+08:00
|
|
* @Email: fm453@lukegzs.com
|
|
*/
|
|
namespace backend\controllers;
|
|
|
|
use Yii;
|
|
use yii\data\Pagination;
|
|
use yii\helpers\Url;
|
|
use backend\models\FmHotel as Hotel;
|
|
use backend\models\FmRoom as Room;
|
|
use backend\models\FmRoomOwner as RoomOwner;
|
|
|
|
class RoomController extends \yii\web\Controller
|
|
{
|
|
//替代常规的_construct 析构函数;其他方法调用前执行
|
|
public function init()
|
|
{
|
|
parent::init();
|
|
$session = Yii::$app->session;
|
|
if(isset($_GET['pid']) && (int)$_GET['pid']>0){
|
|
$session->set('pid',(int)$_GET['pid']);
|
|
}
|
|
$pid = $session->get('pid');
|
|
if(!$pid){
|
|
$url = Url::toRoute('/index/index');
|
|
return $this->redirect($url);
|
|
}
|
|
}
|
|
//主界面
|
|
public function actionIndex()
|
|
{
|
|
return $this->render('../layouts/dev',[]);
|
|
}
|
|
|
|
public function actionList()
|
|
{
|
|
global $_HI,$_FM;
|
|
$pid = Yii::$app->session->get('pid');
|
|
$citys = Yii::$app->params['citys'];
|
|
$model = new Room();
|
|
$where = $where2 = [];
|
|
$where2[]='and';
|
|
$where['pid'] = $pid;
|
|
$post = Yii::$app->request->post();
|
|
$search = isset($post['search']) ? $post['search'] : [];
|
|
$page = isset($_GET['page']) ? (int)$_GET['page'] : 0;
|
|
$session = Yii::$app->session;
|
|
if($page==0){
|
|
$session->set('Room:List:'.$pid,$search);
|
|
}else{
|
|
$search = $search ? $search : $session->get('Room:List:'.$pid);
|
|
}
|
|
|
|
$hotel_id = Yii::$app->request->get('hotel_id');
|
|
$hotel_id = (int)$hotel_id;
|
|
if($hotel_id){
|
|
$search['hotel'] = $hotel_id;
|
|
}
|
|
|
|
$model = new Room();
|
|
$where = [];
|
|
$where['pid'] = Yii::$app->session->get('pid');
|
|
$search['title'] = isset($search['title']) ? trim(htmlspecialchars_decode($search['title'])) : '';
|
|
if(!empty($search['title'])){
|
|
$where2[] = ['LIKE','title',$search['title']];
|
|
}
|
|
|
|
$search['hotel'] = isset($search['hotel']) ? (int)$search['hotel'] : 0;
|
|
if(!empty($search['hotel'])){
|
|
$where2[] = ['=','hotel_id',$search['hotel']];
|
|
$hotel = Hotel::find()->where(['id'=>$search['hotel']])->one();
|
|
$search['hotel_title'] = $hotel['title'];
|
|
}
|
|
|
|
$search['f'] = isset($search['f']) ? (int)$search['f'] : 0;
|
|
if(!empty($search['f'])){
|
|
$where2[] = ['=','f',$search['f']];
|
|
}else{
|
|
unset($search['f']);
|
|
}
|
|
$search['t'] = isset($search['t']) ? (int)$search['t'] : 0;
|
|
if(!empty($search['t'])){
|
|
$where2[] = ['=','t',$search['t']];
|
|
}else{
|
|
unset($search['t']);
|
|
}
|
|
$search['c'] = isset($search['c']) ? (int)$search['c'] : 0;
|
|
if(!empty($search['c'])){
|
|
$where2[] = ['=','c',$search['c']];
|
|
}else{
|
|
unset($search['c']);
|
|
}
|
|
$search['w'] = isset($search['w']) ? (int)$search['w'] : 0;
|
|
if(!empty($search['w'])){
|
|
$where2[] = ['=','w',$search['w']];
|
|
}else{
|
|
unset($search['w']);
|
|
}
|
|
$search['b'] = isset($search['b']) ? (int)$search['b'] : 0;
|
|
if(!empty($search['b'])){
|
|
$where2[] = ['=','b',$search['b']];
|
|
}else{
|
|
unset($search['b']);
|
|
}
|
|
|
|
$search['measure'] = isset($search['measure']) ? (int)$search['measure'] : 0;
|
|
if(!empty($search['measure'])){
|
|
$where2[] = ['<=','measure',$search['measure']];
|
|
}else{
|
|
unset($search['measure']);
|
|
}
|
|
|
|
$where['deleted'] = 0;
|
|
$data = $model->find()->where($where)->andwhere(['AND',$where2]);
|
|
|
|
$pages = new Pagination(['totalCount' =>$data->count(), 'pageSize' => '20']);
|
|
$res = $data->orderBy('hotel_id DESC, id DESC')->offset($pages->offset)->limit($pages->limit)->all();
|
|
|
|
$status = ['0'=>'隐藏','1'=>'正常'];
|
|
|
|
$model = new Hotel();
|
|
$where = [];
|
|
$where['pid'] = Yii::$app->session->get('pid');
|
|
$_hotels = $model->find()->where($where)->all();
|
|
$hotels = [];
|
|
foreach($_hotels as $s){
|
|
$hotels[$s->id] = $s->toArray();
|
|
}
|
|
|
|
$rooms = [];
|
|
foreach($res as $s){
|
|
$s = $s->toArray();
|
|
$rooms[] = $s;
|
|
}
|
|
|
|
return $this->render('list',[
|
|
'rooms'=>$rooms,
|
|
'hotels'=>$hotels,
|
|
'pager' => $pages,
|
|
'citys'=>$citys,
|
|
'status'=>$status,
|
|
'pager' => $pages,
|
|
'search'=>$search,
|
|
'hotel_id'=>$hotel_id,
|
|
'total'=>$data->count(),
|
|
]);
|
|
}
|
|
|
|
public function actionSelect()
|
|
{
|
|
$model = new Hotel();
|
|
$where = [];
|
|
$where['pid'] = Yii::$app->session->get('pid');
|
|
$citys = Yii::$app->params['citys'];
|
|
|
|
$where['deleted'] = 0;
|
|
$where['status_code'] = 1;
|
|
$data = $model->find()->where($where);
|
|
$pages = new Pagination(['totalCount' =>$data->count(), 'pageSize' => '20']);
|
|
$res = $data->offset($pages->offset)->limit($pages->limit)->all();
|
|
$status = ['0'=>'隐藏','1'=>'正常'];
|
|
$callback = !empty(Yii::$app->session->get('callback')) ? Yii::$app->session->get('callback') : 'hotel';
|
|
return $this->render('select',[
|
|
'hotels'=>$res,
|
|
'pager' => $pages,
|
|
'citys'=>$citys,
|
|
'status'=>$status,
|
|
'callback'=>$callback
|
|
]);
|
|
}
|
|
|
|
public function actionNew()
|
|
{
|
|
return $this->render('modify',[]);
|
|
}
|
|
|
|
public function actionEdit()
|
|
{
|
|
$model = new Room();
|
|
$id = Yii::$app->request->get('id');
|
|
$res = $model->find()->where(['id' => $id])->one();
|
|
if($res){
|
|
$res = $res->toArray();
|
|
$cols = ['signtime','deadline'];
|
|
foreach($cols as $col){
|
|
$res[$col] = $res[$col] ? date('Y-m-d',$res[$col]) : '';
|
|
}
|
|
$cols = ['income','expense','surplus'];
|
|
foreach($cols as $col){
|
|
$res[$col] = round($res[$col]/100,2);
|
|
}
|
|
}
|
|
|
|
$hotel = Hotel::find()->where(['id' => $res['hotel_id']])->one();
|
|
if($hotel){
|
|
$res['hotel_title'] = $hotel->title;
|
|
}
|
|
$owner = RoomOwner::findOne($res['owner_id']);
|
|
if($owner){
|
|
$res['owner_title'] = $owner->name;
|
|
}
|
|
|
|
return $this->render('modify',[
|
|
'detail'=>$res,
|
|
'id'=>$id,
|
|
]);
|
|
}
|
|
|
|
public function actionSave()
|
|
{
|
|
$post = Yii::$app->request->post();
|
|
$data = [];
|
|
$data['pid'] = Yii::$app->session->get('pid');
|
|
$id = $post['id'];
|
|
$op = Yii::$app->request->get('op');
|
|
switch($op){
|
|
case 'basic':
|
|
//目标键=》POST键
|
|
$cols = ['title'=>'title','sn'=>'sn','thumb'=>'thumb','longt'=>'lng','lat'=>'lat','addr'=>'addr'];
|
|
foreach($cols as $col=>$key){
|
|
$data[$col] = isset($post[$key]) ? trim($post[$key]) : '';
|
|
}
|
|
$cols = ['hotel_id'=>'hotel_id','f'=>'f','t'=>'t','c'=>'c','w'=>'w','b'=>'b','measure'=>'measure','deleted'=>'deleted'];
|
|
foreach($cols as $col=>$key){
|
|
$data[$col] = isset($post[$key]) ? (int)$post[$key] : 0;
|
|
}
|
|
$data['detail'] = $post['editor'];
|
|
$data['status_code'] = 1;
|
|
|
|
break;
|
|
case 'params':
|
|
//目标键=》POST键
|
|
$cols = ['wifi'=>'wifi','cooking'=>'cooking','gas'=>'gas','parker'=>'parker','swimmingpool'=>'swimmingpool'];
|
|
foreach($cols as $col=>$key){
|
|
$data[$col] = isset($post[$key]) ? (int)$post[$key] : 0;
|
|
}
|
|
break;
|
|
case 'owner':
|
|
//目标键=》POST键
|
|
$cols = ['owner_id'=>'owner_id','signmonths'=>'signmonths'];
|
|
foreach($cols as $col=>$key){
|
|
$data[$col] = isset($post[$key]) ? (int)$post[$key] : 0;
|
|
}
|
|
$cols = ['income'=>'income','expense'=>'expense','surplus'=>'surplus'];
|
|
foreach($cols as $col=>$key){
|
|
$data[$col] = isset($post[$key]) ? (int)($post[$key]*100) : 0;
|
|
}
|
|
$cols = ['signtime'=>'signtime','deadline'=>'deadline'];
|
|
foreach($cols as $col=>$key){
|
|
$data[$col] = isset($post[$key]) ? strtotime($post[$key]) : 0;
|
|
}
|
|
break;
|
|
case 'other':
|
|
//目标键=》POST键
|
|
$cols = ['landscape'=>'landscape','feature'=>'feature','tag'=>'tag','traffic'=>'traffic'];
|
|
foreach($cols as $col=>$key){
|
|
$data[$col] = isset($post[$key]) ? trim($post[$key]) : '';
|
|
}
|
|
$data['remark'] = $post['remark-editor'];
|
|
break;
|
|
default:
|
|
\Yii::$app->getSession()->setFlash('success', '无效的数据保存操作!');
|
|
return $this->redirect(['edit','id'=>$id]);
|
|
break;
|
|
}
|
|
$data['update_at'] = time();
|
|
|
|
$model = new Room();
|
|
if($id){
|
|
$model = $model->findOne($id);
|
|
}
|
|
foreach($data as $key=>$val){
|
|
$model->$key = $val;
|
|
}
|
|
if($id){
|
|
$model->id = $id;
|
|
$res = $model->update();
|
|
}else{
|
|
$model->create_at = $data['update_at'];
|
|
$res = $model->save();
|
|
}
|
|
|
|
if($res){
|
|
$id = $id ? $id : $model->attributes['id']; //取插入后id
|
|
\Yii::$app->getSession()->setFlash('success', '房间资料保存成功!');
|
|
return $this->redirect(['edit','id'=>$id]);
|
|
}else{
|
|
\Yii::$app->getSession()->setFlash('warning', '房间资料保存失败!');
|
|
if($id){
|
|
return $this->redirect(['edit','id'=>$id]);
|
|
}else{
|
|
return $this->redirect(['new']);
|
|
}
|
|
}
|
|
}
|
|
|
|
public function actionDelete()
|
|
{
|
|
$get = Yii::$app->request->get();
|
|
$post = Yii::$app->request->post();
|
|
$id = (int)$get['id'];
|
|
$data = $where = [];
|
|
$where['pid'] = Yii::$app->session->get('pid');
|
|
$where['id'] = $id;
|
|
$data['update_at'] = time();
|
|
$data['deleted'] = 1;
|
|
|
|
$model = new Room();
|
|
foreach($data as $key=>$val){
|
|
$model->$key = $val;
|
|
}
|
|
|
|
$model->id = $id;
|
|
$res = $model->updateAll($data,$where);
|
|
|
|
$return = [];
|
|
$return['url'] = Url::toRoute('room/list');
|
|
$return['timeout'] = 3; //3秒后自动跳转
|
|
$return['status'] = 0;
|
|
if($res){
|
|
$return['msg'] = '房间删除成功';
|
|
$return['errorcode'] = 200;
|
|
$return['data'] = $id;
|
|
}else{
|
|
$return['msg'] = '房间删除失败';
|
|
$return['errorcode'] = 0;
|
|
}
|
|
exit(json_encode($return));
|
|
}
|
|
|
|
public function actionAjax()
|
|
{
|
|
$get = Yii::$app->request->get();
|
|
$post = Yii::$app->request->post();
|
|
$id = (int)$get['id'];
|
|
$data = $where = [];
|
|
$where['pid'] = Yii::$app->session->get('pid');
|
|
$where['id'] = $id;
|
|
$data['update_at'] = time();
|
|
|
|
$model = new Room();
|
|
$res = $model->findOne($id);
|
|
$return = [];
|
|
$return['timeout'] = 1; //3秒后自动跳转
|
|
$return['status'] = 0;
|
|
$return['ajax'] = 1;
|
|
if(!$res){
|
|
$return['msg'] = '房间数据不存在';
|
|
$return['errorcode'] = 404;
|
|
exit(json_encode($return));
|
|
}
|
|
$data = $res;
|
|
|
|
switch($get['do'])
|
|
{
|
|
case 'hide':
|
|
$data->status_code = 0;
|
|
$res = $data->update();
|
|
if($res !== false){
|
|
$return['msg'] = '房间隐藏成功';
|
|
$return['errorcode'] = 200;
|
|
$return['data'] = ['css'=>'info'];
|
|
}else{
|
|
$return['msg'] = '房间隐藏失败';
|
|
$return['errorcode'] = 0;
|
|
}
|
|
break;
|
|
case 'show':
|
|
$data->status_code = 1;
|
|
$res = $data->update();
|
|
if($res !== false){
|
|
$return['msg'] = '房间显示成功';
|
|
$return['errorcode'] = 200;
|
|
$return['data'] = ['css'=>'default'];
|
|
}else{
|
|
$return['msg'] = '房间显示失败';
|
|
$return['errorcode'] = 0;
|
|
}
|
|
break;
|
|
case 'cooking':
|
|
$data->cooking = ($data->cooking) ? 0 : 1;
|
|
$res = $data->update();
|
|
if($res !== false){
|
|
$return['msg'] = '参数标记成功';
|
|
$return['errorcode'] = 200;
|
|
$return['data'] = ['css'=>'default'];
|
|
}else{
|
|
$return['msg'] = '参数标记失败';
|
|
$return['errorcode'] = 0;
|
|
}
|
|
break;
|
|
case 'parker':
|
|
$data->parker = ($data->parker) ? 0 : 1;
|
|
$res = $data->update();
|
|
if($res !== false){
|
|
$return['msg'] = '参数标记成功';
|
|
$return['errorcode'] = 200;
|
|
$return['data'] = ['css'=>'default'];
|
|
}else{
|
|
$return['msg'] = '参数标记失败';
|
|
$return['errorcode'] = 0;
|
|
}
|
|
break;
|
|
case 'swimmingpool':
|
|
$data->swimmingpool = ($data->swimmingpool) ? 0 : 1;
|
|
$res = $data->update();
|
|
if($res !== false){
|
|
$return['msg'] = '参数标记成功';
|
|
$return['errorcode'] = 200;
|
|
$return['data'] = ['css'=>'default'];
|
|
}else{
|
|
$return['msg'] = '参数标记失败';
|
|
$return['errorcode'] = 0;
|
|
}
|
|
break;
|
|
case 'gas':
|
|
$data->gas = ($data->gas) ? 0 : 1;
|
|
$res = $data->update();
|
|
if($res !== false){
|
|
$return['msg'] = '参数标记成功';
|
|
$return['errorcode'] = 200;
|
|
$return['data'] = ['css'=>'default'];
|
|
}else{
|
|
$return['msg'] = '参数标记失败';
|
|
$return['errorcode'] = 0;
|
|
}
|
|
break;
|
|
case 'wifi':
|
|
$data->wifi = ($data->wifi) ? 0 : 1;
|
|
$res = $data->update();
|
|
if($res !== false){
|
|
$return['msg'] = '参数标记成功';
|
|
$return['errorcode'] = 200;
|
|
$return['data'] = ['css'=>'default'];
|
|
}else{
|
|
$return['msg'] = '参数标记失败';
|
|
$return['errorcode'] = 0;
|
|
}
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
exit(json_encode($return));
|
|
}
|
|
|
|
}
|