Explorar el Código

酒店详情修改

dev
nizongfeng hace 3 años
padre
commit
17887c6a34
Se han modificado 5 ficheros con 632 adiciones y 191 borrados
  1. +21
    -0
      application/admin/controller/Ajax.php
  2. +28
    -159
      application/admin/controller/CfHotelInfo.php
  3. +103
    -0
      application/admin/dao/CfHotelInfoDao.php
  4. +45
    -0
      application/admin/service/CfHotelInfoService.php
  5. +435
    -32
      application/admin/view/cf_hotel_info/index.html

+ 21
- 0
application/admin/controller/Ajax.php Ver fichero

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

namespace app\admin\controller;

use app\admin\command\Util;
use app\common\controller\Backend;
use app\common\exception\UploadException;
use app\common\library\Upload;
@@ -289,6 +290,26 @@ class Ajax extends Backend
$provincelist = Db::name('area')->where($where)->field('id as value,name')->select();
$this->success('', '', $provincelist);
}
/**
* 读取省市区数据,联动列表
*/
public function areaList()
{
$province = $this->request->post('province', '');
$city = $this->request->post('city', '');
$where = ['pid' => 0, 'level' => 1];
$provincelist = null;
if ($province !== '') {
$where['pid'] = $province;
$where['level'] = 2;
if ($city !== '') {
$where['pid'] = $city;
$where['level'] = 3;
}
}
$provincelist = Db::name('area')->where($where)->field('id as value,name')->select();
return json(Util::returnArrSu("",$provincelist->toArray()));
}

/**
* 生成后缀图标


+ 28
- 159
application/admin/controller/CfHotelInfo.php Ver fichero

@@ -3,6 +3,7 @@
namespace app\admin\controller;

use app\admin\model\Area;
use app\admin\service\CfHotelInfoService;
use app\common\controller\Backend;
use think\Db;
use think\exception\PDOException;
@@ -15,17 +16,17 @@ use think\exception\ValidateException;
*/
class CfHotelInfo extends Backend
{
/**
* CfHotelInfo模型对象
* @var \app\admin\model\CfHotelInfo
* PaymentOrder模型对象
* @var \app\admin\model\PaymentOrder
*/
protected $model = null;

public function _initialize()
{
parent::_initialize();
$this->model = new \app\admin\model\CfHotelInfo;
$this->model = new \app\admin\model\PaymentOrder;

}

@@ -40,170 +41,38 @@ class CfHotelInfo 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_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' => $result]);
/****=========================================**/
/**
* 获取列表
* @return \think\response\Json
*/
public function getList(){
$params=$this->request->post();
$service = new CfHotelInfoService();
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);
}
$area=new Area();
if ($params["area"]){
$params["area_name"]=$area->where("id","=",$params["area"])->value("name");
}
if ($params["province"]){
$params["province_name"]=$area->where("id","=",$params["province"])->value("name");
}
if ($params["city"]){
$params["city_name"]=$area->where("id","=",$params["city"])->value("name");
}
$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 save(){
$params=$this->request->post();
$params['create_id']=$this->auth->id;
$params['group_id']=$this->auth->getGroupId();
$service = new CfHotelInfoService();
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);
}
$area=new Area();
if ($params["area"]){
$params["area_name"]=$area->where("id","=",$params["area"])->value("name");
}
if ($params["province"]){
$params["province_name"]=$area->where("id","=",$params["province"])->value("name");
}
if ($params["city"]){
$params["city_name"]=$area->where("id","=",$params["city"])->value("name");
}
$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();
public function delAll(){
$params=$this->request->post();
$service = new CfHotelInfoService();
return json($service->del($params));
}
}

+ 103
- 0
application/admin/dao/CfHotelInfoDao.php Ver fichero

@@ -0,0 +1,103 @@
<?php
/**
* Created by PhpStorm.
* User: nizongfeng
* Date: 2021/11/23
* Time: 11:35
*/

namespace app\admin\dao;


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

class CfHotelInfoDao
{
/**
* 添加记录
* @param $param
* @return array
*/
public function save($param)
{
try {
$data = [
'hotel_name' => $param['hotel_name'],
'hotel_phone' => $param['hotel_phone'],
'area' => $param['area'],
'area_name' => $param['area_name'],
'province' => $param['province'],
'province_name' => $param['province_name'],
'city' => $param['city'],
'city_name' => $param['city_name'],
'detail_address' => $param['detail_address']
];
$receiptOrder = new CfHotelInfo();
if (empty($param['id'])) {
$data['create_id'] = $param['create_id'];
$data['group_id'] = $param['group_id'];
$id = $receiptOrder->insertGetId($data);
return Util::returnArrSu("", $id);
} else {
$receiptOrder->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_name'])) {
$where['hotel_name'] = ["like","%".$param['hotel_name']."%"];
}
if (!empty($param['hotel_phone'])) {
$where["hotel_phone"] = $param['hotel_phone'];
}
if (!empty($param['area'])) {
$where["area"] = $param['area'];
}
if (!empty($param['province'])) {
$where["province"] = $param['province'];
}
if (!empty($param['city'])) {
$where["city"] = $param['city'];
}
$offset = ($param['pageNum'] - 1) * $param['pageSize'];
$model = new CfHotelInfo();
$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($id){
try {
//设置收购单状态
$receiptOrder = new CfHotelInfo();
$receiptOrder->save(['del_flag' => 1], ['id' => $id]);
return Util::returnArrSu();
} catch (\Exception $e) {
return Util::returnArrEr("修改状态失败" . $e->getMessage());
}
}
}

+ 45
- 0
application/admin/service/CfHotelInfoService.php Ver fichero

@@ -0,0 +1,45 @@
<?php
/**
* Created by PhpStorm.
* User: nizongfeng
* Date: 2021/11/23
* Time: 11:34
*/

namespace app\admin\service;


use app\admin\dao\CfHotelInfoDao;

class CfHotelInfoService
{
/**
* 获取列表
* @param $param
* @return array
*/
public function getList($param){
$dao = new CfHotelInfoDao();
return $dao->getList($param);
}

/**
* 保存记录
* @param $param
* @return array
*/
public function save($param){
$dao = new CfHotelInfoDao();
return $dao->save($param);
}

/**
* 删除记录
* @param $param
* @return array
*/
public function del($param){
$dao = new CfHotelInfoDao();
return $dao->del($param['id']);
}
}

+ 435
- 32
application/admin/view/cf_hotel_info/index.html Ver fichero

@@ -1,35 +1,438 @@
<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_hotel_info/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_hotel_info/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_hotel_info/del')?'':'hide'}" title="{:__('Delete')}" ><i class="fa fa-trash"></i> {:__('Delete')}</a>
<a href="javascript:;" class="btn btn-danger btn-import {:$auth->check('cf_hotel_info/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_hotel_info/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_hotel_info/edit')}"
data-operate-del="{:$auth->check('cf_hotel_info/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>名称:</span>
<el-input v-model="search.hotel_name" style="width: 120px;" placeholder="请输入内容"></el-input>
<span>名称:</span>
<el-input v-model="search.hotel_phone" style="width: 120px;" placeholder="请输入内容"></el-input>
<span>省份</span>
<el-select v-model="search.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>
<span>市</span>
<el-select v-model="search.city" placeholder="请选择" style="width: 120px;" clearable>
<el-option
v-for="item in city"
:key="item.value"
:label="item.name"
:value="item.value">
</el-option>
</el-select>
<span>区</span>
<el-select v-model="search.area" placeholder="请选择" style="width: 120px;" clearable>
<el-option
v-for="item in area"
:key="item.value"
:label="item.name"
:value="item.value">
</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="hotel_name" label="名称" min-width="180"></el-table-column>
<el-table-column prop="hotel_phone" label="手机号" min-width="100"></el-table-column>
<el-table-column prop="province_name" label="省" min-width="90"></el-table-column>
<el-table-column prop="city_name" label="市" min-width="90"></el-table-column>
<el-table-column prop="area_name" label="区" min-width="90"></el-table-column>
<el-table-column prop="detail_address" label="详细地址" min-width="250"></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="150">
<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>
<el-form-item label="手机号:" style="width: 80%">
<el-input v-model="editData.hotel_phone" style="width: 120px;" 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>
<el-form-item label="区:" >
<el-select v-model="editData.area" placeholder="请选择" style="width: 120px;" clearable>
<el-option v-for="item in edit_area" :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: {
hotel_name: "",
hotel_phone: "",
province:"",
city:"",
area: "",
pageSize:10,
pageNum: 1
},
total: 0,
tableData: [],
editShow: false,
editType: false,
editData: {
},
province: [],
city: [],
area:[],
edit_city_set:3,
edit_city: [],
edit_area:[],

}
},
created() {
this.getProvince();
this.getData(1)
},
watch: {
"search.province" : function (newVal,oldVal){
this.city = []
this.area = []
this.search.city=""
this.search.area=""
if (newVal==''){
return false;
}
let row = {
"province":newVal
}
axios.post("/hotel.php/ajax/areaList", row).then((response) => {
let data = response.data;
if (data.flag) {
this.city = data.data;

} else {
this.$message.error(data.msg);
}
}).catch(function (error) {
console.log(error);
});
},
"search.city" : function (newVal,oldVal){
this.area = []
this.search.area=""
if (newVal == "") {
return false;
}
let row = {
province:this.search.province,
city:newVal
}
axios.post("/hotel.php/ajax/areaList", row).then((response) => {
let data = response.data;
if (data.flag) {
this.area = data.data;
} else {
this.$message.error(data.msg);
}
}).catch(function (error) {
console.log(error);
});

},
"editData.province" : function (newVal,oldVal){
if (this.edit_city_set==3) {
this.edit_city = []
this.edit_area = []
this.editData.city=""
this.editData.area=""
}
if (newVal==''){
return false;
}
let row = {
"province":newVal
}
axios.post("/hotel.php/ajax/areaList", row).then((response) => {
let data = response.data;
if (data.flag) {
this.edit_city = data.data;
this.edit_city_set++;
} else {
this.$message.error(data.msg);
}
}).catch(function (error) {
console.log(error);
});
},
"editData.city" : function (newVal,oldVal){
if (this.edit_city_set==3) {
this.edit_area = []
this.editData.area=""
}
if (newVal == "") {
return false;
}
let row = {
province:this.editData.province,
city:newVal
}
axios.post("/hotel.php/ajax/areaList", row).then((response) => {
let data = response.data;
if (data.flag) {
this.edit_area = data.data;
this.edit_city_set++;
} else {
this.$message.error(data.msg);
}
}).catch(function (error) {
console.log(error);
});

}
},
methods: {
getProvince(){
axios.post("/hotel.php/ajax/areaList", {}).then((response) => {
let data = response.data;
if (data.flag) {
this.province = data.data;
} else {
this.$message.error(data.msg);
}
}).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_hotel_info/getList", 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) {
if (info == null) {
this.editType = false;
this.editData = {
hotel_name: "",
hotel_phone: "",
province:"",
city:"",
area: "",
detail_address:""
}
} else {
this.edit_city_set = 1;
this.editType = true;
this.editData = {
id:info.id,
hotel_name: info.hotel_name,
hotel_phone: info.hotel_phone,
province:info.province,
province_name:info.province_name,
city:info.city,
city_name:info.city_name,
area: info.area,
area_name:info.area_name,
detail_address:info.detail_address
}
}
this.editShow = true;
},
setAreaName(){
for (let i = 0; i < this.province.length; i++) {
if (this.province[i].value == this.editData.province) {
this.editData.province_name = this.province[i].name;
break
}
}
for (let i = 0; i < this.edit_city.length; i++) {
if (this.edit_city[i].value == this.editData.city) {
this.editData.city_name = this.edit_city[i].name;
break
}
}
for (let i = 0; i < this.edit_area.length; i++) {
if (this.edit_area[i].value == this.editData.area) {
this.editData.area_name = this.edit_area[i].name;
break;
}
}
},
editDoing(){
if (this.editData.hotel_name==''){
this.$message.error("名称不能为空");return false;
}
if (this.editData.hotel_phone==''){
this.$message.error("手机号不能为空");return false;
}
if (this.editData.province==''){
this.$message.error("省不能为空");return false;
}
if (this.editData.city==''){
this.$message.error("市不能为空");return false;
}
if (this.editData.area==''){
this.$message.error("区不能为空");return false;
}
this.setAreaName();
axios.post("/hotel.php/cf_hotel_info/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_hotel_info/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>

Cargando…
Cancelar
Guardar