Commit c1229b4b authored by hujun's avatar hujun

商铺图片编辑优化

parent 3f576a4d
......@@ -174,18 +174,54 @@ class HouseService
}
}
if (empty($data['id'])) {
$house_img->add($data, $house_id); //只记录新增图片
} else {
$image_result = $house_img->edit($data, $house_id); //编辑图片
if (isset($data['cover'])) {
$image_result = $house_img->editV2($data['cover'], $house_id, 1);
if ($image_result['status'] == 'fail') {
$result['status'] = 'fail';
$result['msg'] = '新增或编辑主图图片失败,' . $image_result['msg'];
return $result;
}
}
if (isset($data['slide_show'])) {
$image_result = $house_img->editV2($data['slide_show'], $house_id, 2);
if ($image_result['status'] == 'fail') {
$result['status'] = 'fail';
$result['msg'] = '编辑图片失败,' . $validate->getError();
$result['msg'] = '新增或编辑轮播图片失败,' . $image_result['msg'];
return $result;
}
}
if (isset($data['plan'])) {
$image_result = $house_img->editV2($data['plan'], $house_id, 3);
if ($image_result['status'] == 'fail') {
$result['status'] = 'fail';
$result['msg'] = '新增或编辑楼盘图片失败,' . $image_result['msg'];
return $result;
}
}
if (isset($data['exclusive_img'])) {
$image_result = $house_img->editV2($data['exclusive_img'], $house_id, 4);
if ($image_result['status'] == 'fail') {
$result['status'] = 'fail';
$result['msg'] = '新增或编辑独家图片失败,' . $image_result['msg'];
return $result;
}
}
// if (empty($data['id'])) {
// $house_img->add($data, $house_id); //只记录新增图片
// } else {
// $image_result = $house_img->edit($data, $house_id); //编辑图片
//
// if ($image_result['status'] == 'fail') {
// $result['status'] = 'fail';
// $result['msg'] = '编辑图片失败,' . $validate->getError();
// return $result;
// }
// }
//案场权限人
if (isset($data['agent_data'])) {
$result_agent_data = $this->releaseRelationshipV2($data['agent_data'], $house_id, 1, $agent_id, $data['internal_title'], $site_id);
......
......@@ -187,6 +187,53 @@ class GHousesImgs extends BaseModel
return $result;
}
/**
* 商铺图片编辑
*
* @param $image_arr
* @param $house_id
* @param $type
* @return mixed
*/
public function editV2($image_arr, $house_id, $type) {
try {
$image_arr = array_unique($image_arr);
//编辑图片
$where['img_status'] = 0;
$where['house_id'] = $house_id;
$where['img_type'] = $type;
$house_img_data = $this->getListAll('id,img_name', $where);
$house_img_edit = [];
$count = 0;
foreach ($house_img_data as $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[$count]['id'] = $v['id'];
$house_img_edit[$count]['img_status'] = 1;
$count++;
}
}
foreach ($image_arr as $v2) {
$house_img_edit[$count]['img_status'] = 0;
$house_img_edit[$count]['img_name'] = $v2;
$house_img_edit[$count]['img_type'] = $type;
$house_img_edit[$count]['house_id'] = $house_id;
$count++;
}
$this->saveAll($house_img_edit);
$result['status'] = 'successful';
} catch (\Exception $e) {
$result['status'] = 'fail';
$result['msg'] = $e->getMessage();
}
return $result;
}
/****** zw start *******/
/**
* 查询图片
......
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