Commit 4c07227a authored by zhuwei's avatar zhuwei

编辑办公室

parent f8a8eb06
......@@ -25,7 +25,7 @@ class StoreFee extends Basic
}
/**
* 新增数据
* 新增办公室
* @return \think\Response
*/
public function addOffice()
......@@ -44,6 +44,10 @@ class StoreFee extends Basic
return $this->response("101", $checkResult);
}
$office = $this->getOffice('',$params['office_name']);
if ($office) {
return $this->response("101", '已存在该办公室!');
}
$data["site_id"] = $params['site_id'];
$data["office_name"] = $params['office_name'];
......@@ -61,6 +65,37 @@ class StoreFee extends Basic
}
/**
* 编辑办公室
* @return \think\Response
*/
public function editOffice()
{
$params = $this->params;
$params = array(
"id" => '1',//id
"site_id" => '10001',//站点id
"office_name" => '鳖12222',//办公室名
"office_address" =>'上海市黄浦区龙华东路800号',//办公室地址
"rent" => 5000,//租金每月
);
$checkResult = $this->validate($params, "StoreFeeValidate.editOffice");
if (true !== $checkResult) {
return $this->response("101", $checkResult);
}
$office = $this->getOffice($params['id'],$name='');
if (!$office) {
return $this->response("101", '不存在该办公室!');
}
$this->f_office->updateOffice($params);
return $this->response("200", "成功");
}
/**
* 办公室列表
* @return \think\Response
......@@ -108,15 +143,15 @@ class StoreFee extends Basic
{
$params = $this->params;
// $params = array(
// "id" => '1',//id
// );
$params = array(
"id" => '1',//id
);
$checkResult = $this->validate($params, "StoreFeeValidate.getOfficeInfo");
if (true !== $checkResult) {
return $this->response("101", $checkResult);
}
$conditions = [];
$field = 'id,site_id,office_name,office_address';
$conditions['id'] = $params['id'];
$field = 'id,rent,site_id,office_name,office_address';
$result = $this->f_office->findByOne($field, $conditions);
if (!$result) {
return $this->response("101", '此办公室不存在');
......@@ -126,6 +161,27 @@ class StoreFee extends Basic
}
/**
* 根据ID或者办公室名字查询是否存在
* @param $id
* @param $name
* @return array|false|\PDOStatement|string|\think\Model
*/
public function getOffice($id='',$name='')
{
$conditions = [];
if ($id) {
$conditions['id'] = $id;
}
if ($name) {
$conditions['office_name'] = $name;
}
$field = 'id';
$result = $this->f_office->findByOne($field, $conditions);
return $result;
}
}
\ No newline at end of file
......@@ -13,8 +13,6 @@ class StoreFeeValidate extends Validate {
'rent' => 'require|number|gt:0',
'id' => 'require|number|gt:0',
];
protected $message = [
......@@ -31,8 +29,9 @@ class StoreFeeValidate extends Validate {
];
protected $scene = [
'addOffice' => [ 'site_id', 'office_name', 'office_address', 'rent' ],
'getOfficeInfo' => [ 'id'],
'addOffice' => [ 'site_id', 'office_name', 'office_address', 'rent' ],
'getOfficeInfo' => [ 'id' ],
'editOffice' => [ 'id', 'site_id', 'office_name', 'office_address', 'rent' ],
];
}
\ No newline at end of file
......@@ -74,18 +74,16 @@ class FOffice extends BaseModel
->count();
return $result;
}
//
// /**
// * 更新数据
// * 朱伟 2018-10-18 10:41:10
// */
// public function updateOffice($params)
// {
// $result = $this->db_->update($params);
// //dump($this->db_->getLastSql());
// return $result;
//
// }
/**
* 更新数据
* @param $params
* @return int|string
*/
public function updateOffice($params)
{
return $this->db_->update($params);
}
//
// /**
// * 根据id获取单个字段值
......
......@@ -520,6 +520,8 @@ Route::group('index', [
'addOffice' => [ 'index/StoreFee/addOffice', [ 'method' => 'POST|GET' ] ],
'getOfficeList' => [ 'index/StoreFee/getOfficeList', [ 'method' => 'POST|GET' ] ],
'getOfficeInfo' => [ 'index/StoreFee/getOfficeInfo', [ 'method' => 'POST|GET' ] ],
'editOffice' => [ 'index/StoreFee/editOffice', [ 'method' => 'POST|GET' ] ],
]);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment