Commit 2e9500f1 authored by hujun's avatar hujun

删除图片

parent d505db54
<?php
/**
* Created by PhpStorm.
* User: HuJun
* Date: 2019/5/30
* Time: 10:11
*/
namespace app\api_broker\controller;
use app\index\extend\Basic;
use app\index\service\OfficeService;
use think\Request;
class OfficeManage extends Basic
{
private $service;
public function __construct(?Request $request = null)
{
parent::__construct($request);
$this->service = new OfficeService();
}
/**
* 新增楼盘
*
* @return \think\Response|\think\response\View
*/
public function add()
{
if (!$this->request->isAjax()) {
return view('office/add');
}
$code = 200;
$result['status'] = $msg = '';
if ($this->request->isPost()) {
$msg = '新增成功';
$result = $this->service->edit($this->params, $this->userId);
}
if ($result['status'] == 'fail') {
$code = 101;
$msg = $result['msg'];
}
return $this->response($code, $msg);
}
/**
* 编辑楼盘
*
* @return \think\Response|\think\response\View
*/
public function edit() {
if (!$this->request->isAjax()) {
return view('office/add');
}
if (empty($this->params['id'])) {
return $this->response(101, '参数错误');
}
$code = 200;
$msg = '';
if ($this->request->isPost()) {
$result = $this->service->edit($this->params);
} else {
$result = $this->service->getOfficeDetail($this->params['id'], 0);
}
if ($result['status'] == 'fail') {
$code = 101;
$msg = $result['msg'];
}
return $this->response($code, $msg, $result['data']);
}
/**
* 删除图片
*
* @return \think\Response
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function delHouseFile()
{
$msg = '';
$code = 200;
$result = $this->service->delHouseFile($this->params['id'], $this->params['building_id'], 2);
if ($result['status'] == 'fail') {
$code = 101;
$msg = '删除失败';
}
return $this->response($code, $msg);
}
}
\ No newline at end of file
......@@ -78,4 +78,24 @@ class OfficeManage extends Basic
return $this->response($code, $msg, $result['data']);
}
/**
* 删除图片
*
* @return \think\Response
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function delHouseFile()
{
$msg = '';
$code = 200;
$result = $this->service->delHouseFile($this->params['id'], $this->params['building_id'], 2);
if ($result['status'] == 'fail') {
$code = 101;
$msg = '删除失败';
}
return $this->response($code, $msg);
}
}
\ No newline at end of file
......@@ -10,8 +10,6 @@ namespace app\index\service;
use app\index\validate\OfficeBuildingValidate;
use app\model\GBusinessDistrict;
use app\model\MetroStations;
use app\model\OfficeGBuilding;
use app\model\OfficeGBuildingImg;
use app\model\OfficeGBuildingStations;
......@@ -21,12 +19,14 @@ class OfficeService
private $validate;
private $m_office;
private $m_office_img;
private $m_building_stations;
public function __construct()
{
$this->validate = new OfficeBuildingValidate();
$this->m_office = new OfficeGBuilding();
$this->m_office_img = new OfficeGBuildingImg();
$this->m_building_stations = new OfficeGBuildingStations();
}
/**
......@@ -55,6 +55,33 @@ class OfficeService
$id = $this->m_office->addOffice($data, $agent_id);
if ($id > 0) {
//新增周边交通
if (!empty($data['add_building_stations'])) {
$add_building_stations = json_decode($data['add_building_stations'], true);
foreach ($add_building_stations as $k=>$v) {
if (empty($data['stations_id'])) {
continue;
}
if (empty($data['distance'])) {
continue;
}
$save_stations[$k]['building_id'] = $id;
$save_stations[$k]['stations_id'] = $v['stations_id'];
$save_stations[$k]['distance'] = $v['distance'];
}
if (isset($save_stations)) {
$this->m_building_stations->insertData($save_stations);
}
}
//删除周边交通
if (!empty($data['del_building_stations'])) {
$this->m_building_stations->updateData(['is_del'=>1], ['id'=>['in', $data['del_building_stations']]]);
}
$result['status'] = 'successful';
} else {
$result['msg'] = '新增或编辑失败!';
......@@ -111,9 +138,8 @@ class OfficeService
// $data['business_name'] = "";
// }
$m_building_stations = new OfficeGBuildingStations();
$field_stations = 'a.id,b.line_name,name,distance,b.id as stations_id';
$data['building_stations'] = $m_building_stations->getListAll($field_stations, ['a.building_id'=>$id]);
$data['building_stations'] = $this->m_building_stations->getListAll($field_stations, ['a.building_id'=>$id]);
}
$result['data'] = $data;
......@@ -126,4 +152,41 @@ class OfficeService
return $result;
}
/**
* 删除图片
*
* @param $id
* @param $building_id
* @param $img_status
* @return mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function delHouseFile($id, $building_id, $img_status)
{
$data['status'] = 'fail';
$data['msg'] = '';
if (empty($id) || empty($building_id)) {
$data['msg'] = '参数错误';
return $data;
}
$where['building_id'] = $id;
$where['id'] = $id;
$where['img_status'] = $img_status;
$id = $this->m_office_img->getFindData('id', $where);
if (empty($id['id'])) {
$data['msg'] = '没有该文件';
} else {
$this->m_office_img->editData(['img_status' => 1], $id['id'], 'id');
$data['status'] = 200;
$data['msg'] = '删除成功';
}
return $data;
}
}
\ No newline at end of file
......@@ -82,9 +82,21 @@ class OfficeGBuildingImg extends BaseModel
*/
public function getListAll($field, $where)
{
$where['img_status'] = 0;
$where['is_del'] = 0;
return $this->db_->field($field)
->where($where)
->select();
}
/**
* @param $data
* @param $where
* @return int|string
* @throws \think\Exception
* @throws \think\exception\PDOException
*/
public function updateData($data, $where)
{
return $this->db_->where($where)->update($data);
}
}
......@@ -49,4 +49,24 @@ class OfficeGBuildingStations extends BaseModel
->where($where)
->select();
}
/**
* @param $data
* @param $where
* @return int|string
* @throws \think\Exception
* @throws \think\exception\PDOException
*/
public function updateData($data, $where)
{
return $this->db_->where($where)->update($data);
}
/**
* @param $data
* @return int|string
*/
public function insertData($data){
return $this->db_->insertAll($data);
}
}
......@@ -923,9 +923,15 @@ Route::group('search', [
Route::group('office', [
'isBargainEnd' => ['api_broker/OrderLog/isBargainEnd', ['method' => 'get']],
'isBargainEnd' => ['api_broker/OrderLog/isBargainEnd', ['method' => 'GET']],
'houseAdd' => ['api_broker/OfficeManage/add', ['method' => 'GET|POST']],//楼盘字典新增
'houseEdit' => ['api_broker/OfficeManage/edit', ['method' => 'GET|POST']],//楼盘字典编辑
'delHouseFile' => ['api_broker/OfficeManage/delHouseFile', ['method' => 'POST']],//删除楼盘图片
]);
Route::group('office_index', [
'houseAdd' => ['index/OfficeManage/add', ['method' => 'GET|POST']],//楼盘字典新增
'houseEdit' => ['index/OfficeManage/edit', ['method' => 'GET|POST']],//楼盘字典编辑
'delHouseFile' => ['index/OfficeManage/delHouseFile', ['method' => 'POST']],//删除楼盘图片
]);
//Route::miss('api/index/miss');//处理错误的url
\ No newline at end of file
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