nizongfeng 3 years ago
parent
commit
338f7f3d43
3 changed files with 540 additions and 162 deletions
  1. +28
    -130
      application/admin/controller/CfRoomPlan.php
  2. +107
    -0
      application/admin/dao/CfRoomPlanDao.php
  3. +405
    -32
      application/admin/view/cf_room_plan/index.html

+ 28
- 130
application/admin/controller/CfRoomPlan.php View File

@@ -2,6 +2,7 @@

namespace app\admin\controller;

use app\admin\dao\CfRoomPlanDao;
use app\admin\dao\GroupDao;
use app\admin\model\Area;
use app\common\controller\Backend;
@@ -16,7 +17,7 @@ use think\exception\ValidateException;
*/
class CfRoomPlan extends Backend
{
protected $noNeedRight = ['getList'];
protected $noNeedRight = ['getList',"list","save","delAll"];
/**
* CfRoomPlan模型对象
* @var \app\admin\model\CfRoomPlan
@@ -73,143 +74,40 @@ class CfRoomPlan extends Backend
}

/**
* 查看
* 获取列表
* @return \think\response\Json
*/
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();
$groupDao = new GroupDao();
$group_id = $groupDao->getTopGroup($this->auth->getGroupId());
$list = $this->model
->alias("a")
->join('hbp_admin','a.purchase_user_id = hbp_admin.id','left')
->join('hbp_cf_room_info e','a.room_id = e.id','left')
->join('hbp_cf_hotel_info f','a.hotel_id = f.id','left')
->field("a.*,hbp_admin.nickname,e.room_name,f.hotel_name")
->where($where);
$list = $list
->where("a.group_id","=",$group_id)
->order($sort, $order)
->paginate($limit);
$result = $list->items();
foreach ($result as $k=>$item){
$result[$k]["continuity_type"]=$this->continuity_type[$item["continuity_type"]];
$result[$k]["hbp_admin.nickname"] = $item["nickname"];
}
$result = array("total" => $list->total(), "rows" => $result);
return json($result);
}
return $this->view->fetch();
public function list(){
$params=$this->request->post();
$params['create_id']=$this->auth->id;
$groupDao = new GroupDao();
$params['group_id'] = $groupDao->getTopGroup($this->auth->getGroupId());
$service = new CfRoomPlanDao();
return json($service->getList($params));
}

/**
* 添加
* 保存记录
* @return \think\response\Json
*/
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);
}
$groupDao = new GroupDao();
$params['create_id']=$this->auth->id;
$params['group_id']=$groupDao->getTopGroup($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', ''));
}
$this->view->assign("continuity_type", $this->continuity_type);
return $this->view->fetch();
public function save(){
$params=$this->request->post();
$params['create_id']=$this->auth->id;
$groupDao = new GroupDao();
$params['group_id'] = $groupDao->getTopGroup($this->auth->getGroupId());
$service = new CfRoomPlanDao();
return json($service->save($params));
}


/**
* 编辑
* 删除
* @return \think\response\Json
*/
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("continuity_type", $this->continuity_type);
$this->view->assign("row", $row);
return $this->view->fetch();
public function delAll(){
$params=$this->request->post();
$service = new CfRoomPlanDao();
return json($service->del($params));
}


}

+ 107
- 0
application/admin/dao/CfRoomPlanDao.php View File

@@ -0,0 +1,107 @@
<?php
/**
* Created by PhpStorm.
* User: nizongfeng
* Date: 2021/11/30
* Time: 19:01
*/

namespace app\admin\dao;


use app\admin\command\Util;
use app\admin\model\CfRoomPlan;

class CfRoomPlanDao
{
/**
* 添加记录
* @param $param
* @return array
*/
public function save($param)
{
try {
$data = [
'hotel_id' => $param['hotel_id'],
'room_id' => $param['room_id'],
'plan_name' => $param['plan_name'],
'breakfast_num' => $param['breakfast_num'],
'book_end_day' => $param['book_end_day'],
'book_end_hour' => $param['book_end_hour'],
'continuity_type' => $param['continuity_type'],
"coutinuity_day"=>$param['coutinuity_day'],
'plan_memo' => $param['plan_memo'],
'purchase_user_id' => $param['purchase_user_id']
];
$model = new CfRoomPlan();
if (empty($param['id'])) {
$data['create_id'] = $param['create_id'];
$data['group_id'] = $param['group_id'];
$id = $model->insertGetId($data);
return Util::returnArrSu("", $id);
} else {
$model->save($data, ['id' => $param['id']]);
return Util::returnArrSu("", $param['id']);
}
} catch (\Exception $e) {
return Util::returnArrEr("更新记录失败:" . $e->getMessage());
}
}

/**
* 获取列表
* @param $param
* @return array
*/
public function getList($param)
{
try {
$where = ["del_flag"=>0];
if (!empty($param['hotel_id'])) {
$where["hotel_id"] = $param['hotel_id'];
}
if (!empty($param['room_id'])) {
$where["room_id"] = $param['room_id'];
}
if (!empty($param['plan_name'])) {
$where["plan_name"] = ["like","%".$param['plan_name']."%"];
}
if (!empty($param['purchase_user_id'])) {
$where["purchase_user_id"] = $param['purchase_user_id'];
}
if (!empty($param['id'])) {
$where['id'] = $param['id'];
}
if (!empty($param['group_id'])) {
$where['group_id'] = $param['group_id'];
}
$offset = ($param['pageNum'] - 1) * $param['pageSize'];
$model = new CfRoomPlan();
$total = $model->where($where)->count();
$list = $model->where($where)
->limit($offset, $param['pageSize'])
->order("id","DESC")->select();
$data = ["total" => $total, "list" => $list->toArray()];
return Util::returnArrSu("", $data);
} catch (\Exception $e) {
return Util::returnArrSu("", ["total" => 0, "list" => []]);
}
}

/**
* 删除
* @param $id
* @return array
*/
public function del($param){
try {
//设置收购单状态
$model = new CfRoomPlan();
$model->save(['del_flag' =>1], ['id' => $param['id']]);
return Util::returnArrSu();
} catch (\Exception $e) {
return Util::returnArrEr("修改状态失败" . $e->getMessage());
}
}
}

+ 405
- 32
application/admin/view/cf_room_plan/index.html View File

@@ -1,35 +1,408 @@
<div class="panel panel-default panel-intro">
{:build_heading()}

<div class="panel-body">
<div id="myTabContent" class="tab-content">
<div class="tab-pane fade active in" id="one">
<div class="widget-body no-padding">
<div id="toolbar" class="toolbar">
<a href="javascript:;" class="btn btn-primary btn-refresh" title="{:__('Refresh')}" ><i class="fa fa-refresh"></i> </a>
<a href="javascript:;" class="btn btn-success btn-add {:$auth->check('cf_room_plan/add')?'':'hide'}" title="{:__('Add')}" ><i class="fa fa-plus"></i> {:__('Add')}</a>
<a href="javascript:;" class="btn btn-success btn-edit btn-disabled disabled {:$auth->check('cf_room_plan/edit')?'':'hide'}" title="{:__('Edit')}" ><i class="fa fa-pencil"></i> {:__('Edit')}</a>
<a href="javascript:;" class="btn btn-danger btn-del btn-disabled disabled {:$auth->check('cf_room_plan/del')?'':'hide'}" title="{:__('Delete')}" ><i class="fa fa-trash"></i> {:__('Delete')}</a>
<a href="javascript:;" class="btn btn-danger btn-import {:$auth->check('cf_room_plan/import')?'':'hide'}" title="{:__('Import')}" id="btn-import-file" data-url="ajax/upload" data-mimetype="csv,xls,xlsx" data-multiple="false"><i class="fa fa-upload"></i> {:__('Import')}</a>

<div class="dropdown btn-group {:$auth->check('cf_room_plan/multi')?'':'hide'}">
<a class="btn btn-primary btn-more dropdown-toggle btn-disabled disabled" data-toggle="dropdown"><i class="fa fa-cog"></i> {:__('More')}</a>
<ul class="dropdown-menu text-left" role="menu">
<li><a class="btn btn-link btn-multi btn-disabled disabled" href="javascript:;" data-params="status=normal"><i class="fa fa-eye"></i> {:__('Set to normal')}</a></li>
<li><a class="btn btn-link btn-multi btn-disabled disabled" href="javascript:;" data-params="status=hidden"><i class="fa fa-eye-slash"></i> {:__('Set to hidden')}</a></li>
</ul>
</div>

</div>
<table id="table" class="table table-striped table-bordered table-hover table-nowrap"
data-operate-edit="{:$auth->check('cf_room_plan/edit')}"
data-operate-del="{:$auth->check('cf_room_plan/del')}"
width="100%">
</table>
</div>
</div>

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<!-- import CSS -->
<link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
</head>
<body>
<div id="app" class="table">
<div>
<div class="header-search">
<span>ID:</span>
<el-input v-model="search.id" style="width: 120px;" placeholder="请输入内容"></el-input>
<span>名称:</span>
<el-input v-model="search.plan_name" style="width: 120px;" placeholder="请输入内容"></el-input>
<span>酒店</span>
<el-select v-model="search.hotel_id" placeholder="请选择" style="width: 120px;" clearable>
<el-option
v-for="item in hotelList"
:key="item.id"
:label="item.name"
:value="item.id">
</el-option>
</el-select>
<span>房型</span>
<el-select v-model="search.room_id" placeholder="请选择" style="width: 120px;" clearable>
<el-option
v-for="item in roomList"
:key="item.id"
:label="item.name"
:value="item.id">
</el-option>
</el-select>
<span>采购负责人</span>
<el-select v-model="search.purchase_user_id" placeholder="请选择" style="width: 120px;" clearable>
<el-option
v-for="item in userList"
:key="item.id"
:label="item.name"
:value="item.id">
</el-option>
</el-select>
<el-button type="primary" icon="el-icon-search" @click="getData(1)">搜索</el-button>
<el-button type="primary" icon="el-icon-plus" @click="edit(null)">新增</el-button>
</div>

<el-table ref="multipleTable" :data="tableData" border tooltip-effect="dark"
style="font-size:12px;width: 100%;margin-top: 12px">
<el-table-column prop="id" label="ID" min-width="50"></el-table-column>
<el-table-column prop="plan_name" label="名称" min-width="120"></el-table-column>
<el-table-column label="酒店" :formatter="getHotelName" min-width="180"></el-table-column>
<el-table-column label="房型" :formatter="getRoomName" min-width="180"></el-table-column>
<el-table-column prop="breakfast_num" label="早餐数量" min-width="60"></el-table-column>
<el-table-column prop="book_end_day" label="提前几天预定" min-width="60"></el-table-column>
<el-table-column prop="book_end_hour" label="几点前预定" min-width="60"></el-table-column>
<el-table-column prop="continuity_type" label="入住类型" :formatter="getTypeName" min-width="60"></el-table-column>
<el-table-column prop="coutinuity_day" label="连续入住天数" min-width="60"></el-table-column>
<el-table-column prop="plan_memo" label="方案说明" min-width="60">
<template slot-scope="scope">
<el-popover
placement="top-start"
title=""
width="200"
trigger="hover"
:content="scope.row.plan_memo">
<div slot="reference" v-html="scope.row.plan_memo" style="overflow:hidden;white-space: nowrap;"></div>
</el-popover>
</template>
</el-table-column>
<el-table-column prop="purchase_user_id" label="采购负责人" :formatter="getPurchaseName" min-width="90"></el-table-column>
<el-table-column prop="create_time" label="创建时间" min-width="80"></el-table-column>
<el-table-column prop="update_time" label="更新时间" min-width="80"></el-table-column>
<el-table-column label="操作" min-width="180">
<template slot-scope="scope">
<el-button-group>
<el-button type="primary" size="mini" @click="edit(scope.row)" icon="el-icon-edit">编辑</el-button>
<el-button type="danger" size="mini" icon="el-icon-delete" @click="delAll(scope.row.id)">删除</el-button>
</el-button-group>
</template>
</el-table-column>
</el-table>
<el-pagination
:page-size="search.pageSize"
:pager-count="11"
layout="total, sizes, prev, pager, next, jumper"
:total="total"
:current-page="search.pageNum"
:page-sizes="[10, 20, 30, 40, 50]"
@size-change="sizeChange"
@current-change="getData"
@prev-click="getData"
@next-click="getData"
></el-pagination>
</div>


<transition name="bounce" v-if="editShow">
<el-dialog title="详情" :visible.sync="editShow" width="90%" top="15px">
<el-form ref="form" label-width="100px" style="width: 100%;padding-bottom: 20px">
<div style="display: flex;width: 100%">
<el-form-item v-if="editType" label="ID:" style="width: 80%">
<div v-html="editData.id"></div>
</el-form-item>
</div>
<div>
<el-form-item label="名称:" style="width: 80%">
<el-input v-model="editData.hotel_name" style="width: 280px;" placeholder="请输入内容"></el-input>
</el-form-item>
</div>
<div style="display: flex">
<el-form-item label="省:" >
<el-select v-model="editData.province" placeholder="请选择" style="width: 120px;" clearable>
<el-option v-for="item in province" :key="item.value" :label="item.name" :value="item.value"></el-option>
</el-select>
</el-form-item>
<el-form-item label="市:" >
<el-select v-model="editData.city" placeholder="请选择" style="width: 120px;" clearable>
<el-option v-for="item in edit_city" :key="item.value" :label="item.name" :value="item.value"></el-option>
</el-select>
</el-form-item>
</div>
<div>
<el-form-item label="详细地址:" style="width: 80%">
<el-input v-model="editData.detail_address" style="width: 580px;" placeholder="请输入内容"></el-input>
</el-form-item>
</div>
<div>
<el-button type="primary" @click="editDoing()" >保存</el-button>
</div>
</el-form>
</el-dialog>
</transition>
</div>
</body>
<!-- import Vue before Element -->
<script src="/assets/js/vue/vue.js"></script>
<!-- import JavaScript -->
<script src="/assets/js/vue/index.js"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script>
new Vue({
el: '#app',
data: function () {
return {
search: {
id:"",
hotel_id: "",
room_id: "",
purchase_user_id:"",
plan_name:"",
pageSize:10,
pageNum: 1
},
total: 0,
tableData: [],
editShow: false,
editType: false,
editData: {
},
hotelList:[],
roomList:[],
roomAllList:[],
userList: [],
//连续入住类型 0无限制 1连住几晚 2连住几晚及以上 3连住几晚及其倍数
typeList:[
{id:0,name:"无限制"},
{id:1,name:"连住几晚"},
{id:2,name:"连住几晚及以上"},
{id:3,name:"连住几晚及其倍数"}
]

}
},
created() {
this.getHotelList();
this.getRoomAllList();
this.getAdminUser();
this.getData(1)
},
watch: {
"search.hotel_id" : function (newVal,oldVal){
this.roomList = []
axios.post("/hotel.php/cf_room_info/getRoomList?hotelId="+newVal, {}).then((response) => {
let data = response.data;
this.roomList = data.list;
}).catch(function (error) {
console.log(error);
});
}
},
methods: {
getPurchaseName(info) {
for (let i = 0; i < this.userList.length; i++) {
if (this.userList[i].id == info.purchase_user_id) {
return this.userList[i].name
}
}
return "-"
},
getTypeName(info) {
for (let i = 0; i < this.typeList.length; i++) {
if (this.typeList[i].id == info.continuity_type) {
return this.typeList[i].name
}
}
return "-"
},
getHotelName(info) {
for (let i = 0; i < this.hotelList.length; i++) {
if (this.hotelList[i].id == info.hotel_id) {
return this.hotelList[i].name
}
}
return "-"
},
getRoomName(info) {
for (let i = 0; i < this.roomAllList.length; i++) {
if (this.roomAllList[i].id == info.room_id) {
return this.roomAllList[i].name
}
}
return "-"
},
getRoomAllList(){
axios.post("/hotel.php/cf_room_info/getList", this.search).then((response) => {
this.roomAllList = response.data.list;
}).catch(function (error) {
console.log(error);
});
},
getAdminUser() {
axios.post("/hotel.php/auth/admin/getList", this.search).then((response) => {
this.userList = response.data.list;
}).catch(function (error) {
console.log(error);
});
},
getHotelList(){
axios.post("/hotel.php/cf_hotel_info/getHotelList", {}).then((response) => {
let data = response.data;
this.hotelList = data.list;
}).catch(function (error) {
console.log(error);
});
},
sizeChange(pageSize) {
this.search.pageSize = pageSize;
this.getData(this.search.pageNum)
},
//獲取列表
getData(page) {
this.search.pageNum = page;
axios.post("/hotel.php/cf_room_plan/list", this.search).then((response) => {
let data = response.data;
if (data.flag) {
this.tableData = data.data.list;
this.total = data.data.total;
} else {
this.$message.error(response.msg);
}
}).catch(function (error) {
console.log(error);
});
},
edit(info) {
this.$message.error("功能待完善");
return false
if (info == null) {
this.editType = false;
this.editData = {
hotel_id:"",
room_id:"",
plan_name:"",
breakfast_num:"",
book_end_day:"",
book_end_hour:"",
continuity_type:0,
coutinuity_day:"",
plan_memo:"",
purchase_user_id:"",

}
} else {
this.edit_city_set = 1;
this.editType = true;
this.editData = {
hotel_id:info.hotel_id,
room_id:info.room_id,
plan_name:info.plan_name,
breakfast_num:info.breakfast_num,
book_end_day:info.book_end_day,
book_end_hour:info.book_end_hour,
continuity_type:info.continuity_type,
coutinuity_day:info.coutinuity_day,
plan_memo:info.plan_memo,
purchase_user_id:info.purchase_user_id,
}
}
this.editShow = true;
},
editDoing(){
if (this.editData.hotel_id==''){
this.$message.error("请选择酒店");return false;
}
if (this.editData.room_id==''){
this.$message.error("请选择房型");return false;
}
if (this.editData.plan_name==''){
this.$message.error("名称不能为空");return false;
}
if (this.editData.breakfast_num==''){
this.$message.error("早餐数量不能为空");return false;
}
if (this.editData.book_end_day==''){
this.$message.error("提前几天预定不能为空");return false;
}
if (this.editData.book_end_hour==''){
this.$message.error("几点前预定不能为空");return false;
}
if (this.editData.continuity_type==''){
this.$message.error("选择入住类型不能");return false;
}
if (this.editData.coutinuity_day==''){
this.$message.error("连续入住天数不能为空");return false;
}
if (this.editData.plan_memo==''){
this.$message.error("方案说明不能为空");return false;
}
if (this.editData.purchase_user_id==''){
this.$message.error("请选择采购负责人");return false;
}
this.setAreaName();
axios.post("/hotel.php/cf_room_plan/save", this.editData).then( (response)=> {
let data = response.data;
console.log(this.tableData);
if (data.flag) {
this.$message({
message: '保存成功!',
type: 'success'
});
this.editShow = false;
this.getData(1);
} else {
this.$message.error(data.msg);
}
}).catch(function (error) {
this.$message.error("保存失败");
console.log(error);
});
},
delAll(id){
this.$confirm('确定删除?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
let param = {
id: id
}
axios.post("/hotel.php/cf_room_plan/delAll", param).then((response) => {
let data = response.data;
if (data.flag) {
this.getData(this.search.pageNum)
this.$message.success("保存成功");
} else {
this.$message.error(response.msg);
}
}).catch(function (error) {
console.log(error);
});
}).catch(() => {

this.$message({
type: 'info',
message: '已取消'
});
this.getData(this.search.pageNum)
})
}

}
})
</script>
<style lang="scss" scoped>
.el-table thead {
background-color: #5a5e66 !important;
}

.header-search {
font-size: 14px;
font-weight: 900;
}

body {
background-color: white;
}

.table {
width: 100%;
font-size: 12px;
margin-top: 12px;
background-color: white;
}
.el-form-item{
margin-bottom: 5px !important;
}
</style>
</html>

Loading…
Cancel
Save