Commit c95ebdc3 authored by hujun's avatar hujun

删除图片

parent 2e9500f1
...@@ -39,6 +39,7 @@ class OfficeService ...@@ -39,6 +39,7 @@ class OfficeService
public function edit(array $data, int $agent_id = 0) { public function edit(array $data, int $agent_id = 0) {
$result['status'] = 'fail'; $result['status'] = 'fail';
$result['msg'] = ''; $result['msg'] = '';
$result['data'] = [];
if (isset($data['id'])) { if (isset($data['id'])) {
$scene = 'edit'; $scene = 'edit';
...@@ -60,11 +61,18 @@ class OfficeService ...@@ -60,11 +61,18 @@ class OfficeService
if (!empty($data['add_building_stations'])) { if (!empty($data['add_building_stations'])) {
$add_building_stations = json_decode($data['add_building_stations'], true); $add_building_stations = json_decode($data['add_building_stations'], true);
foreach ($add_building_stations as $k=>$v) { foreach ($add_building_stations as $k=>$v) {
if (empty($data['stations_id'])) { if (empty($v['stations_id'])) {
continue; continue;
} }
if (empty($data['distance'])) { if (empty($v['distance'])) {
continue;
}
$where['building_id'] = $id;
$where['stations_id'] = $v['stations_id'];
$building_station_id = $this->m_building_stations->getFindData('id', $where);
if (isset($building_station_id['id'])) {
continue; continue;
} }
$save_stations[$k]['building_id'] = $id; $save_stations[$k]['building_id'] = $id;
...@@ -82,6 +90,11 @@ class OfficeService ...@@ -82,6 +90,11 @@ class OfficeService
$this->m_building_stations->updateData(['is_del'=>1], ['id'=>['in', $data['del_building_stations']]]); $this->m_building_stations->updateData(['is_del'=>1], ['id'=>['in', $data['del_building_stations']]]);
} }
//楼盘图片
if (!empty($data['slide_show'])) {
$this->m_office_img->edit($data['slide_show'], $id, 2);
}
$result['status'] = 'successful'; $result['status'] = 'successful';
} else { } else {
$result['msg'] = '新增或编辑失败!'; $result['msg'] = '新增或编辑失败!';
......
...@@ -66,7 +66,7 @@ class OfficeGBuildingImg extends BaseModel ...@@ -66,7 +66,7 @@ class OfficeGBuildingImg extends BaseModel
* @throws \think\exception\DbException * @throws \think\exception\DbException
*/ */
public function getFindData($field, $where) { public function getFindData($field, $where) {
$where['is_del'] = 0; $where['img_status'] = 0;
return $this->db_->field($field) return $this->db_->field($field)
->where($where) ->where($where)
->find(); ->find();
...@@ -82,7 +82,7 @@ class OfficeGBuildingImg extends BaseModel ...@@ -82,7 +82,7 @@ class OfficeGBuildingImg extends BaseModel
*/ */
public function getListAll($field, $where) public function getListAll($field, $where)
{ {
$where['is_del'] = 0; $where['img_status'] = 0;
return $this->db_->field($field) return $this->db_->field($field)
->where($where) ->where($where)
->select(); ->select();
...@@ -99,4 +99,53 @@ class OfficeGBuildingImg extends BaseModel ...@@ -99,4 +99,53 @@ class OfficeGBuildingImg extends BaseModel
{ {
return $this->db_->where($where)->update($data); return $this->db_->where($where)->update($data);
} }
/**
* 商铺图片编辑
*
* @param $image_arr
* @param $house_id
* @param $type
* @return mixed
*/
public function edit($image_arr, $house_id, $type) {
try {
$image_arr = array_unique($image_arr);
//编辑图片
$where['img_status'] = 0;
$where['building_id'] = $house_id;
$where['img_type'] = $type;
$house_img_data = $this->getListAll('id,img_name', $where);
$house_img_edit = [];
foreach ($house_img_data as $k=>$v) {
if (in_array($v['img_name'], $image_arr)) {
$key = array_search($v['img_name'], $image_arr);
if ($key !== false) {
unset($image_arr[$key]);
}
} else {
$house_img_edit['img_status'] = 1;
$this->db_->where('id', $v['id'])->update($house_img_edit);
}
}
foreach ($image_arr as $k2=>$v2) {
$house_img_add[$k2]['img_status'] = 0;
$house_img_add[$k2]['img_name'] = $v2;
$house_img_add[$k2]['img_type'] = $type;
$house_img_add[$k2]['building_id'] = $house_id;
}
if (isset($house_img_add)) {
$this->db_->insertAll($house_img_add);
}
$this->saveAll($house_img_edit);
$result['status'] = 'successful';
} catch (\Exception $e) {
$result['status'] = 'fail';
$result['msg'] = $e->getMessage();
}
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