@@ -53,20 +53,39 @@ class CfHotelInfo extends Backend | |||
return $this->selectpage(); | |||
} | |||
list($where, $sort, $order, $offset, $limit) = $this->buildparams(); | |||
$group_id=$this->auth->getGroupId(); | |||
$list = $this->model | |||
->where($where) | |||
->order($sort, $order) | |||
->paginate($limit); | |||
->alias("a") | |||
->join('hbp_admin c','a.create_id = c.id','left') | |||
->field("a.*,c.nickname") | |||
->where($where); | |||
if ($group_id){ | |||
$list = $list | |||
->where("group_id","=",$group_id) | |||
->order($sort, $order) | |||
->paginate($limit); | |||
}else{ | |||
$list = $list | |||
->order($sort, $order) | |||
->paginate($limit); | |||
} | |||
$result = array("total" => $list->total(), "rows" => $list->items()); | |||
return json($result); | |||
} | |||
return $this->view->fetch(); | |||
} | |||
public function getHotelList(){ | |||
$name=$this->request->post('name'); | |||
$keyValue=$this->request->post('keyValue'); | |||
$result= $this->model->getList($name,$keyValue); | |||
if($keyValue){ | |||
return json(['list' => $result]); | |||
} | |||
return json(['list' => array_merge([['id'=>0,'name'=>'暂无']],$result)]); | |||
} | |||
/** | |||
* 添加 | |||
*/ | |||
@@ -2,7 +2,11 @@ | |||
namespace app\admin\controller; | |||
use app\admin\model\Area; | |||
use app\common\controller\Backend; | |||
use think\Db; | |||
use think\exception\PDOException; | |||
use think\exception\ValidateException; | |||
/** | |||
* 配置-酒店房型 | |||
@@ -35,6 +39,142 @@ class CfRoomInfo extends Backend | |||
* 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑 | |||
* 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改 | |||
*/ | |||
/** | |||
* 查看 | |||
*/ | |||
public function index() | |||
{ | |||
//设置过滤方法 | |||
$this->request->filter(['strip_tags', 'trim']); | |||
if ($this->request->isAjax()) { | |||
//如果发送的来源是Selectpage,则转发到Selectpage | |||
if ($this->request->request('keyField')) { | |||
return $this->selectpage(); | |||
} | |||
list($where, $sort, $order, $offset, $limit) = $this->buildparams(); | |||
$group_id=$this->auth->getGroupId(); | |||
$list = $this->model | |||
->alias('a') | |||
->join('hbp_cf_hotel_info b','a.hotel_id = b.id','left') | |||
->join('hbp_admin c','a.create_id = c.id','left') | |||
->field("a.id,a.room_name,a.room_memo,b.hotel_name,a.create_time,a.update_time,c.nickname") | |||
->where($where); | |||
if ($group_id){ | |||
$list = $list | |||
->where("group_id","=",$group_id) | |||
->order($sort, $order) | |||
->paginate($limit); | |||
}else{ | |||
$list= $list->order($sort, $order) | |||
->paginate($limit); | |||
} | |||
$result = array("total" => $list->total(), "rows" => $list->items()); | |||
return json($result); | |||
} | |||
return $this->view->fetch(); | |||
} | |||
/** | |||
* 添加 | |||
*/ | |||
public function add() | |||
{ | |||
if ($this->request->isPost()) { | |||
$params = $this->request->post("row/a"); | |||
if ($params) { | |||
$params = $this->preExcludeFields($params); | |||
if ($this->dataLimit && $this->dataLimitFieldAutoFill) { | |||
$params[$this->dataLimitField] = $this->auth->id; | |||
} | |||
$result = false; | |||
Db::startTrans(); | |||
try { | |||
//是否采用模型验证 | |||
if ($this->modelValidate) { | |||
$name = str_replace("\\model\\", "\\validate\\", get_class($this->model)); | |||
$validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate; | |||
$this->model->validateFailException(true)->validate($validate); | |||
} | |||
$params['create_id']=$this->auth->id; | |||
$params['group_id']=$this->auth->getGroupId(); | |||
$result = $this->model->allowField(true)->save($params); | |||
Db::commit(); | |||
} catch (ValidateException $e) { | |||
Db::rollback(); | |||
$this->error($e->getMessage()); | |||
} catch (PDOException $e) { | |||
Db::rollback(); | |||
$this->error($e->getMessage()); | |||
} catch (Exception $e) { | |||
Db::rollback(); | |||
$this->error($e->getMessage()); | |||
} | |||
if ($result !== false) { | |||
$this->success(); | |||
} else { | |||
$this->error(__('No rows were inserted')); | |||
} | |||
} | |||
$this->error(__('Parameter %s can not be empty', '')); | |||
} | |||
return $this->view->fetch(); | |||
} | |||
/** | |||
* 编辑 | |||
*/ | |||
public function edit($ids = null) | |||
{ | |||
$row = $this->model->get($ids); | |||
if (!$row) { | |||
$this->error(__('No Results were found')); | |||
} | |||
$adminIds = $this->getDataLimitAdminIds(); | |||
if (is_array($adminIds)) { | |||
if (!in_array($row[$this->dataLimitField], $adminIds)) { | |||
$this->error(__('You have no permission')); | |||
} | |||
} | |||
if ($this->request->isPost()) { | |||
$params = $this->request->post("row/a"); | |||
if ($params) { | |||
$params = $this->preExcludeFields($params); | |||
$result = false; | |||
Db::startTrans(); | |||
try { | |||
//是否采用模型验证 | |||
if ($this->modelValidate) { | |||
$name = str_replace("\\model\\", "\\validate\\", get_class($this->model)); | |||
$validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate; | |||
$row->validateFailException(true)->validate($validate); | |||
} | |||
$result = $row->allowField(true)->save($params); | |||
Db::commit(); | |||
} catch (ValidateException $e) { | |||
Db::rollback(); | |||
$this->error($e->getMessage()); | |||
} catch (PDOException $e) { | |||
Db::rollback(); | |||
$this->error($e->getMessage()); | |||
} catch (Exception $e) { | |||
Db::rollback(); | |||
$this->error($e->getMessage()); | |||
} | |||
if ($result !== false) { | |||
$this->success(); | |||
} else { | |||
$this->error(__('No rows were updated')); | |||
} | |||
} | |||
$this->error(__('Parameter %s can not be empty', '')); | |||
} | |||
$this->view->assign("row", $row); | |||
return $this->view->fetch(); | |||
} | |||
} |
@@ -27,10 +27,17 @@ class CfHotelInfo extends Model | |||
protected $append = [ | |||
]; | |||
public function getList($name='',$keyValue=''){ | |||
$this->field('id,hotel_name as name'); | |||
if($keyValue){ | |||
$this->where(['id'=>$keyValue]); | |||
}elseif($name){ | |||
$this->where(['hotel_name'=>['like','%'.$name.'%']]); | |||
} | |||
return $this->select(); | |||
} | |||
@@ -12,40 +12,12 @@ | |||
<input id="c-hotel_phone" data-rule="required" class="form-control" name="row[hotel_phone]" type="text" value="{$row.hotel_phone|htmlentities}"> | |||
</div> | |||
</div> | |||
<div class="form-group"> | |||
<label class="control-label col-xs-12 col-sm-2">{:__('Country_id')}:</label> | |||
<div class="col-xs-12 col-sm-8"> | |||
<input id="c-country_id" data-rule="required" data-source="country/index" class="form-control selectpage" name="row[country_id]" type="text" value="{$row.country_id|htmlentities}"> | |||
</div> | |||
</div> | |||
<div class="form-group"> | |||
<label class="control-label col-xs-12 col-sm-2">{:__('Country_name')}:</label> | |||
<div class="col-xs-12 col-sm-8"> | |||
<input id="c-country_name" data-rule="required" class="form-control" name="row[country_name]" type="text" value="{$row.country_name|htmlentities}"> | |||
</div> | |||
</div> | |||
<div class="form-group"> | |||
<label class="control-label col-xs-12 col-sm-2">{:__('Province_id')}:</label> | |||
<div class="col-xs-12 col-sm-8"> | |||
<input id="c-province_id" data-rule="required" data-source="province/index" class="form-control selectpage" name="row[province_id]" type="text" value="{$row.province_id|htmlentities}"> | |||
</div> | |||
</div> | |||
<div class="form-group"> | |||
<label class="control-label col-xs-12 col-sm-2">{:__('Province_name')}:</label> | |||
<div class="col-xs-12 col-sm-8"> | |||
<input id="c-province_name" data-rule="required" class="form-control" name="row[province_name]" type="text" value="{$row.province_name|htmlentities}"> | |||
</div> | |||
</div> | |||
<div class="form-group"> | |||
<label class="control-label col-xs-12 col-sm-2">{:__('City_id')}:</label> | |||
<div class="form-group" data-toggle="cxselect" data-selects="province,city,area"> | |||
<label class="control-label col-xs-12 col-sm-2">{:__('酒店所在区域')}:</label> | |||
<div class="col-xs-12 col-sm-8"> | |||
<input id="c-city_id" data-rule="required" data-source="city/index" class="form-control selectpage" name="row[city_id]" type="text" value="{$row.city_id|htmlentities}"> | |||
</div> | |||
</div> | |||
<div class="form-group"> | |||
<label class="control-label col-xs-12 col-sm-2">{:__('City_name')}:</label> | |||
<div class="col-xs-12 col-sm-8"> | |||
<input id="c-city_name" data-rule="required" class="form-control" name="row[city_name]" type="text" value="{$row.city_name|htmlentities}"> | |||
<select class="province" name="row[province]" data-value="{$row.province|htmlentities}" data-url="ajax/area"></select> | |||
<select class="city" name="row[city]" data-value="{$row.city|htmlentities}" data-url="ajax/area"></select> | |||
<select class="area" name="row[area]" data-value="{$row.area|htmlentities}" data-url="ajax/area"></select> | |||
</div> | |||
</div> | |||
<div class="form-group"> | |||
@@ -54,24 +26,6 @@ | |||
<input id="c-detail_address" data-rule="required" class="form-control" name="row[detail_address]" type="text" value="{$row.detail_address|htmlentities}"> | |||
</div> | |||
</div> | |||
<div class="form-group"> | |||
<label class="control-label col-xs-12 col-sm-2">{:__('Del_flag')}:</label> | |||
<div class="col-xs-12 col-sm-8"> | |||
<input id="c-del_flag" data-rule="required" class="form-control" name="row[del_flag]" type="number" value="{$row.del_flag|htmlentities}"> | |||
</div> | |||
</div> | |||
<div class="form-group"> | |||
<label class="control-label col-xs-12 col-sm-2">{:__('Create_time')}:</label> | |||
<div class="col-xs-12 col-sm-8"> | |||
<input id="c-create_time" data-rule="required" class="form-control datetimepicker" data-date-format="YYYY-MM-DD HH:mm:ss" data-use-current="true" name="row[create_time]" type="text" value="{:$row.create_time?datetime($row.create_time):''}"> | |||
</div> | |||
</div> | |||
<div class="form-group"> | |||
<label class="control-label col-xs-12 col-sm-2">{:__('Update_time')}:</label> | |||
<div class="col-xs-12 col-sm-8"> | |||
<input id="c-update_time" data-rule="required" class="form-control datetimepicker" data-date-format="YYYY-MM-DD HH:mm:ss" data-use-current="true" name="row[update_time]" type="text" value="{:$row.update_time?datetime($row.update_time):''}"> | |||
</div> | |||
</div> | |||
<div class="form-group layer-footer"> | |||
<label class="control-label col-xs-12 col-sm-2"></label> | |||
<div class="col-xs-12 col-sm-8"> | |||
@@ -1,9 +1,10 @@ | |||
<form id="add-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action=""> | |||
<div class="form-group"> | |||
<label class="control-label col-xs-12 col-sm-2">{:__('Hotel_id')}:</label> | |||
<label class="control-label col-xs-12 col-sm-2">{:__('所属酒店')}:</label> | |||
<div class="col-xs-12 col-sm-8"> | |||
<input id="c-hotel_id" data-rule="required" data-source="hotel/index" class="form-control selectpage" name="row[hotel_id]" type="text" value=""> | |||
<input id="c-hotel_id" data-rule="required" data-source="cf_hotel_info/getHotelList" class="form-control selectpage" name="row[hotel_id]" type="text" value=""> | |||
</div> | |||
</div> | |||
<div class="form-group"> | |||
@@ -18,30 +19,6 @@ | |||
<input id="c-room_memo" data-rule="required" class="form-control" name="row[room_memo]" type="text" value=""> | |||
</div> | |||
</div> | |||
<div class="form-group"> | |||
<label class="control-label col-xs-12 col-sm-2">{:__('Room_log')}:</label> | |||
<div class="col-xs-12 col-sm-8"> | |||
<input id="c-room_log" data-rule="required" class="form-control" name="row[room_log]" type="text" value=""> | |||
</div> | |||
</div> | |||
<div class="form-group"> | |||
<label class="control-label col-xs-12 col-sm-2">{:__('Del_flag')}:</label> | |||
<div class="col-xs-12 col-sm-8"> | |||
<input id="c-del_flag" data-rule="required" class="form-control" name="row[del_flag]" type="number" value="0"> | |||
</div> | |||
</div> | |||
<div class="form-group"> | |||
<label class="control-label col-xs-12 col-sm-2">{:__('Create_time')}:</label> | |||
<div class="col-xs-12 col-sm-8"> | |||
<input id="c-create_time" data-rule="required" class="form-control datetimepicker" data-date-format="YYYY-MM-DD HH:mm:ss" data-use-current="true" name="row[create_time]" type="text" value="{:date('Y-m-d H:i:s')}"> | |||
</div> | |||
</div> | |||
<div class="form-group"> | |||
<label class="control-label col-xs-12 col-sm-2">{:__('Update_time')}:</label> | |||
<div class="col-xs-12 col-sm-8"> | |||
<input id="c-update_time" data-rule="required" class="form-control datetimepicker" data-date-format="YYYY-MM-DD HH:mm:ss" data-use-current="true" name="row[update_time]" type="text" value="{:date('Y-m-d H:i:s')}"> | |||
</div> | |||
</div> | |||
<div class="form-group layer-footer"> | |||
<label class="control-label col-xs-12 col-sm-2"></label> | |||
<div class="col-xs-12 col-sm-8"> | |||
@@ -1,9 +1,10 @@ | |||
<form id="edit-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action=""> | |||
<div class="form-group"> | |||
<label class="control-label col-xs-12 col-sm-2">{:__('Hotel_id')}:</label> | |||
<label class="control-label col-xs-12 col-sm-2">{:__('所属酒店')}:</label> | |||
<div class="col-xs-12 col-sm-8"> | |||
<input id="c-hotel_id" data-rule="required" data-source="hotel/index" class="form-control selectpage" name="row[hotel_id]" type="text" value="{$row.hotel_id|htmlentities}"> | |||
<input id="c-hotel_id" data-rule="required" data-source="cf_hotel_info/getHotelList" class="form-control selectpage" name="row[hotel_id]" type="text" value="{$row.hotel_id|htmlentities}"> | |||
</div> | |||
</div> | |||
<div class="form-group"> | |||
@@ -18,30 +19,6 @@ | |||
<input id="c-room_memo" data-rule="required" class="form-control" name="row[room_memo]" type="text" value="{$row.room_memo|htmlentities}"> | |||
</div> | |||
</div> | |||
<div class="form-group"> | |||
<label class="control-label col-xs-12 col-sm-2">{:__('Room_log')}:</label> | |||
<div class="col-xs-12 col-sm-8"> | |||
<input id="c-room_log" data-rule="required" class="form-control" name="row[room_log]" type="text" value="{$row.room_log|htmlentities}"> | |||
</div> | |||
</div> | |||
<div class="form-group"> | |||
<label class="control-label col-xs-12 col-sm-2">{:__('Del_flag')}:</label> | |||
<div class="col-xs-12 col-sm-8"> | |||
<input id="c-del_flag" data-rule="required" class="form-control" name="row[del_flag]" type="number" value="{$row.del_flag|htmlentities}"> | |||
</div> | |||
</div> | |||
<div class="form-group"> | |||
<label class="control-label col-xs-12 col-sm-2">{:__('Create_time')}:</label> | |||
<div class="col-xs-12 col-sm-8"> | |||
<input id="c-create_time" data-rule="required" class="form-control datetimepicker" data-date-format="YYYY-MM-DD HH:mm:ss" data-use-current="true" name="row[create_time]" type="text" value="{:$row.create_time?datetime($row.create_time):''}"> | |||
</div> | |||
</div> | |||
<div class="form-group"> | |||
<label class="control-label col-xs-12 col-sm-2">{:__('Update_time')}:</label> | |||
<div class="col-xs-12 col-sm-8"> | |||
<input id="c-update_time" data-rule="required" class="form-control datetimepicker" data-date-format="YYYY-MM-DD HH:mm:ss" data-use-current="true" name="row[update_time]" type="text" value="{:$row.update_time?datetime($row.update_time):''}"> | |||
</div> | |||
</div> | |||
<div class="form-group layer-footer"> | |||
<label class="control-label col-xs-12 col-sm-2"></label> | |||
<div class="col-xs-12 col-sm-8"> | |||
@@ -25,9 +25,9 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin | |||
columns: [ | |||
[ | |||
{checkbox: true}, | |||
{field: 'id', title: __('Id')}, | |||
{field: 'hotel_name', title: __('Hotel_name'), operate: 'LIKE'}, | |||
{field: 'hotel_phone', title: __('Hotel_phone'), operate: 'LIKE'}, | |||
{field: 'nickname', title: __('创建人')}, | |||
{field: 'area_name', title: __('区县名称'), operate: 'LIKE'}, | |||
{field: 'province_name', title: __('Province_name'), operate: 'LIKE'}, | |||
{field: 'city_name', title: __('City_name'), operate: 'LIKE'}, | |||
@@ -25,12 +25,10 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin | |||
columns: [ | |||
[ | |||
{checkbox: true}, | |||
{field: 'id', title: __('Id')}, | |||
{field: 'hotel_id', title: __('Hotel_id')}, | |||
{field: 'hotel_name', title: __('酒店名称')}, | |||
{field: 'nickname', title: __('创建人')}, | |||
{field: 'room_name', title: __('Room_name'), operate: 'LIKE'}, | |||
{field: 'room_memo', title: __('Room_memo'), operate: 'LIKE'}, | |||
{field: 'room_log', title: __('Room_log'), operate: 'LIKE'}, | |||
{field: 'del_flag', title: __('Del_flag'), formatter: Table.api.formatter.flag}, | |||
{field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime}, | |||
{field: 'update_time', title: __('Update_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime}, | |||
{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate} | |||