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

商铺新增图片和删除图片

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