Commit a3f785f8 authored by zhuwei's avatar zhuwei

绑定解绑门店

parent 9c782cb2
...@@ -239,4 +239,43 @@ class StoreFee extends Basic ...@@ -239,4 +239,43 @@ class StoreFee extends Basic
} }
/**
* 绑定解绑门店
* @return \think\Response
*/
public function bindStore()
{
$params = $this->params;
// $params = array(
// "id" => '1',//id
// );[ 'office_id', 'store_id' ]
$checkResult = $this->validate($params, "StoreFeeValidate.bindStore");
if (true !== $checkResult) {
return $this->response("101", $checkResult);
}
$m_store = new AStore();
if ($params['office_id'] == 0) {
//解绑
$conditions['office_id'] = 0;
$conditions['id'] = $params['store_id'];
$return = $m_store->updateStore($conditions);
} else {
$store_params['id'] = $params['store_id'];
$store_params['office_id'] = array('gt',0);
$store_result = $m_store->getStore($store_params, 'id');
if($store_result)
return $this->response("101", "该门店已绑定或已绑定其他办公室");
//绑定
$conditions['id'] = $params['store_id'];
$conditions['office_id'] = $params['office_id'];
$return = $m_store->updateStore($conditions);
}
return $this->response("200", "成功", $return);
}
} }
\ No newline at end of file
...@@ -12,7 +12,9 @@ class StoreFeeValidate extends Validate { ...@@ -12,7 +12,9 @@ class StoreFeeValidate extends Validate {
'office_address' => 'require', 'office_address' => 'require',
'rent' => 'require|number|gt:0', 'rent' => 'require|number|gt:0',
'id' => 'require|number|gt:0', 'id' => 'require|number|gt:0',
'office_id' => 'require|number',
'store_id' => 'require|number|gt:0',
]; ];
protected $message = [ protected $message = [
...@@ -26,12 +28,20 @@ class StoreFeeValidate extends Validate { ...@@ -26,12 +28,20 @@ class StoreFeeValidate extends Validate {
'id.require' => 'id为必填字段', 'id.require' => 'id为必填字段',
'id.number' => 'id只能为数字', 'id.number' => 'id只能为数字',
'id.gt' => 'id必须大于0', 'id.gt' => 'id必须大于0',
'office_id.require' => 'office_id为必填字段',
'office_id.number' => 'office_id只能为数字',
'store_id.require' => 'store_id为必填字段',
'store_id.number' => 'store_id只能为数字',
'store_id.gt' => 'store_id必须大于0',
]; ];
protected $scene = [ protected $scene = [
'addOffice' => [ 'site_id', 'office_name', 'office_address', 'rent' ], 'addOffice' => [ 'site_id', 'office_name', 'office_address', 'rent' ],
'getOfficeInfo' => [ 'id' ], 'getOfficeInfo' => [ 'id' ],
'editOffice' => [ 'id', 'site_id', 'office_name', 'office_address', 'rent' ], 'editOffice' => [ 'id', 'site_id', 'office_name', 'office_address', 'rent' ],
'bindStore' => [ 'office_id', 'store_id' ],
]; ];
} }
\ No newline at end of file
...@@ -337,4 +337,14 @@ class AStore extends BaseModel ...@@ -337,4 +337,14 @@ class AStore extends BaseModel
->count(); ->count();
return $store_num; return $store_num;
} }
/**
* 更新数据
* @param $params
* @return mixed
*/
public function updateStore($params)
{
return Db::table($this->table)->update($params);
}
} }
\ No newline at end of file
...@@ -84,57 +84,6 @@ class FOffice extends BaseModel ...@@ -84,57 +84,6 @@ class FOffice extends BaseModel
{ {
return $this->db_->update($params); return $this->db_->update($params);
} }
//
// /**
// * 根据id获取单个字段值
// *
// * @param $id
// * @param $where
// * @param $fields
// * @return mixed
// */
// public function getOfficeById($fields, $id, $where = [])
// {
// $where['is_del'] = 0;
// if ($id) {
// $where['id'] = $id;
// }
// $return = $this->db_->where($where)->value($fields);
// return $return;
// }
//
// /**
// * @param $id
// * @param $fields
// * @return false|\PDOStatement|string|\think\Collection
// * @throws \think\db\exception\DataNotFoundException
// * @throws \think\db\exception\ModelNotFoundException
// * @throws \think\exception\DbException
// */
// public function getOfficeByIdList($id, $fields)
// {
// $return = $this->db_->field($fields)->where('id', 'in',$id)->select();
// return $return;
// }
//
// /**
// * @param string $fields
// * @param array $where
// * @return bool|false|\PDOStatement|string|\think\Collection
// * User HuJun
// * Date 19-5-9 上午10:00
// */
// public function getOfficeList($fields = 'id,name,city', $where = [])
// {
// if (!isset($where['is_del'])) {
// $where['is_del'] = 0;
// }
// try {
// $result = $this->db_->field($fields)->where($where)->select();
// } catch (\Exception $e) {
// $result = false;
// }
// return $result;
// }
} }
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