Commit c9e666c8 authored by hujun's avatar hujun Committed by hujun

商铺新增图片和删除图片

parent 26096ed9
...@@ -302,7 +302,10 @@ class Shop extends Basic ...@@ -302,7 +302,10 @@ class Shop extends Basic
$info = $file->validate(['size'=>1024000,'ext'=>'jpg,png'])->move($path); $info = $file->validate(['size'=>1024000,'ext'=>'jpg,png'])->move($path);
if($info){ if($info){
$img_path = $info->getSaveName(); //生成的图片路径 $img_path = $info->getSaveName(); //生成的图片路径
$data['img_type'] = $this->params['img_type'];
$data['img_name'] = $img_path;
$img = new GHousesImgs();
$img->addHouseImg($data,$this->params['house_id']);
$data['status'] = 200; $data['status'] = 200;
$data['msg'] = '上传成功'; $data['msg'] = '上传成功';
$data['data'] = [ $data['data'] = [
...@@ -333,23 +336,23 @@ class Shop extends Basic ...@@ -333,23 +336,23 @@ class Shop extends Basic
$data['msg'] = ''; $data['msg'] = '';
$data['data'] = ''; $data['data'] = '';
if (isset($this->params['house_id'])) { if(empty($this->params['save_path']) || empty($this->params['house_id'])){
$img = new GHousesImgs(); return $this->response($data['status'], 'Save_path or id house_id null', $data['data']);
$id = $img->getHouseImagesInfo('id',[ }
'house_id' => $this->params['house_id'],
'img_name' => $this->params['save_path']
]);
if (empty($id['id'])) { $img = new GHousesImgs();
$data['status'] = 200; $id = $img->getHouseImagesInfo('id',[
$img->editData(['img_status'=>1],$this->params['house_id'], 'id'); 'house_id' => $this->params['house_id'],
} 'img_name' => $this->params['save_path']
]);
if (isset($this->params['save_path'])) { if (empty($id['id'])) {
$path = ROOT_PATH . 'public' . DS . 'resource'. DS . 'lib'. DS .'Attachments'. DS .'Images/'; $data['msg'] = '没有该文件';
@unlink($path.$this->params['save_path']); } else {
$data['status'] = 200; $path = ROOT_PATH . 'public' . DS . 'resource'. DS . 'lib'. DS .'Attachments'. DS .'Images/';
} @unlink($path.$this->params['save_path']);
$img->editData(['img_status'=>1],$this->params['house_id'], 'id');
$data['status'] = 200;
} }
return $this->response($data['status'], $data['msg'], $data['data']); return $this->response($data['status'], $data['msg'], $data['data']);
......
...@@ -205,4 +205,19 @@ class GHousesImgs extends BaseModel ...@@ -205,4 +205,19 @@ class GHousesImgs extends BaseModel
public function getHouseImagesInfo($field, $where) { public function getHouseImagesInfo($field, $where) {
return $this->field($field)->where($where)->find(); return $this->field($field)->where($where)->find();
} }
/**
* 添加楼盘图片
*
* @param array $data
* @param $house_id
* @return false|int
*/
public function addHouseImg($data = [], $house_id) {
return $this->save([
'house_id' => $house_id,
'img_type' => $data['img_type'],
'img_name' => $data['img_name']
]);
}
} }
\ 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