FindById($input['city']); if($pro['pid'] == 0) { // $input['city'] =$pro['id']; //20190223 注释 $r = $city->GetAllSon($input['city'],['city_name','id']); if(!empty($r)) { $input['city'] = array_column($r,'id'); } } } $list = $model->getList($input); if($list != null) { $arr = []; //资讯 $id = array_column($list,'id'); $houseNews = new \common\models\HouseNews(); //相册 $houseAlbum = new \common\models\HouseAlbum(); $houseAlbum->hid = $id; $albumList = $houseAlbum->HidTotal(); if($albumList != null) { $Albumcolumn = array_column($albumList,'num','hid'); } //户型 $houseType = new \common\models\HouseType(); $houseType->hid = $id; $typeList = $houseType->HidTotal(); if($typeList != null) { $typeColumn = array_column($typeList,'num','hid'); } //周边配套 $peitao = new \common\models\HouseFacilities(); $peitao->hid = $id; $peitaoList = $peitao->HidTotal(); if($peitaoList != null) { $peitaoColumn = array_column($peitaoList,'num','hid'); } $yushou = new \common\models\HousePermit(); $yushow = $yushou->HidTotal(['hid'=>$id]); if($yushow != null) { $PermitColumn = array_column($yushow,'num','hid'); } $videoModel = new \common\models\Video(); $videoModel->hid = $id; $videoModel->HidList(); if(!empty($videoModel)) { $video = array_column($yushow,'video_url','hid'); } foreach ($list as &$val) { $_houseNews = clone $houseNews; $val['album_num'] = 0; $val['type_num'] = 0; $val['peitao_num'] = 0; $val['permit'] = 0; $val['video'] = 0; $val['news_num'] = $_houseNews::find()->andWhere(['hid'=>$val['id']])->andWhere(['del'=>1])->count(); if(!empty($Albumcolumn[$val['id']])) { $val['album_num'] = $Albumcolumn[$val['id']]; } if(!empty($typeColumn[$val['id']])) { $val['type_num'] = $typeColumn[$val['id']]; } if(!empty($peitaoColumn[$val['id']])){ $val['peitao_num'] = $peitaoColumn[$val['id']]; } if(!empty($PermitColumn[$val['id']])) { $val['permit'] = $PermitColumn[$val['id']]; } if(!empty($video[$val['id']])) { $val['video'] = 1; } $val['create_at'] = date('Y-m-d H:i',$val['create_at']); } $arr['data'] = $list; $arr['count'] = $model->getListTotal($input); return $arr; } } public function HouseRelation() { $arr = []; //价格区间 $price = new \common\models\HousesPrice(); $arr['priceList'] = $price->getList([]); //特色楼盘 $tese = new \common\models\Characteristic(); $arr['teseList'] = $tese->getList([]); //区域 $city = new \common\models\CategoryCity(); // $city->pid = 0; $arr['city'] = $city->SortgetList([]); //楼盘标签 $label = new \common\models\CategoryLabel(); $label->type=1; $arr['label'] = $label->getList([]); $label->type=2; $arr['Architecture'] = $label->getList([]); $label->type=3; $arr['housetag'] = $label->getList([]); //户型划分 // $type = new \common\models\HouseType(); // $arr['type'] = $type->getList([]); //开发商 $developers = new \common\models\Developers(); $arr['developers'] = $developers->getList([]); return $arr; } public function add($form) { $model = new House(); $model->scenario = 'add'; $modelDetails = new HouseDetail(); $imgUrl = Yii::$app->params['img_url']['house']; $model->thumb = UploadFile::InstanceImgName('img',$imgUrl); if($model->thumb != false) { //压缩图片 // $compressParams = []; // $compressParams['data']['imgname'] = $model->thumb;; // $compressParams['data']['url'] = $imgUrl; // $compressParams['data']['source'] = '楼盘缩略图@添加'; // $this->onCompress($compressParams); } else { $model->thumb = ''; //图片不存在时返回false字段验证 的时候会报错 } $houseModel = $model->Authenticator($form); if(is_array($houseModel)) { return $houseModel; } $Details = $modelDetails->Authenticator($form); if(is_array($Details)) { return $Details; } $transaction = Yii::$app->db->beginTransaction(); $UserHouseModel = new UserHouse(); if(!empty($form['characteristic'])) { $houseModel->characteristic = json_encode(array_values($form['characteristic'])); } if(!empty($form['type'])) { $houseModel->type = json_encode(array_values($form['type'])); } if(!empty($form['architecture_type'])) { $houseModel->architecture_type = json_encode(array_values($form['architecture_type'])); } if(!empty($form['property_tag'])) { $Details->property_tag = json_encode(array_values($form['property_tag'])); } if(!empty($form['evaluating'])) { $Details->evaluating = json_encode($form['evaluating']); } // if(!empty($form['fit'])) // { // $Details->fit = implode(',',$form['fit']); // } $houseModel->insert(false); // exit; $Details->hid = $houseModel->attributes['id']; $UserHouseModel->uid = Yii::$app->session['user_info']['uid']; $UserHouseModel->hid = $Details->hid; if($Details->insert(false) == true && is_numeric($houseModel->attributes['id']) && $UserHouseModel->insert() == true) { $transaction->commit(); //水印 //水印处理 if(!empty($form['watermark'])) { // if( $form['watermark'] == 1 && $model->thumb != false) // { // $ImgSet = new SetUploadImg(); // $ImgSet->SetImgWatermark($model->thumb,$imgUrl); // } } // if($form['watermark'] == 1 && $model->thumb != false) // { // \backend\server\SetUploadImg::Watermark($imgUrl.$model->thumb, // Yii::$app->params['watermark_img']['url']. Yii::$app->params['watermark_img']['module1'],5); // } return true; } $transaction->rollBack(); //数据库添加不成功删除上传的图片 if($model->thumb != false) { UploadFile::delImg($imgUrl,$model->thumb); } return false; } public function Edit($input) { $model = new House(); $imgUrl = Yii::$app->params['img_url']['house']; $house = $model->FindById($input['id']); $house->scenario = 'edit'; $modelHouse = $house->Authenticator($input); if(is_array($modelHouse)) { return $modelHouse; } $modelDetails = new HouseDetail(); $HouseDetails = $modelDetails->Authenticator($input); if(is_array($HouseDetails)) { return $HouseDetails; } // $house = $model->FindById($input['id']); $delImg = $house->thumb; $houseUpdate = \backend\base\Help::SetAttr($input,$modelHouse,$house); if(!empty($input['characteristic'])) { $houseUpdate->characteristic = json_encode(array_values($input['characteristic'])); } else { $houseUpdate->characteristic = ''; } if(!empty($input['type'])) { $houseUpdate->type = json_encode(array_values($input['type'])); } else { $houseUpdate->type = ''; } if(!empty($input['architecture_type'])) { $houseUpdate->architecture_type = json_encode(array_values($input['architecture_type'])); } else { $houseUpdate->architecture_type = ''; } if(!empty($input['property_tag'])) { $HouseDetails->property_tag = json_encode(array_values($input['property_tag'])); } else { $HouseDetails->property_tag = ''; } if(!empty($input['evaluating'])) { $HouseDetails->evaluating = json_encode($input['evaluating']); } else { $HouseDetails->evaluating = ''; } // if(!empty($input['fit'])) // { // $HouseDetails->fit = implode(',',$input['fit']); // } $img = UploadFile::InstanceImgName('img',$imgUrl); if($img != false) { $houseUpdate->thumb = $img; UploadFile::delImg($imgUrl,$delImg); //水印处理 if(!empty($input['watermark'])){ // if($input['watermark'] == 1 ) // { // $ImgSet = new SetUploadImg(); // $ImgSet->SetImgWatermark($houseUpdate->thumb,$imgUrl); // } } //压缩图片 // $compressParams = []; // $compressParams['data']['imgname'] = $img;; // $compressParams['data']['url'] = $imgUrl; // $compressParams['data']['source'] = '楼盘缩略图@修改'; // $this->onCompress($compressParams); } $detailsHouse = $modelDetails->FindById($input['id']); $Update = $houseUpdate->update(false); $detailsHouse = \backend\base\Help::SetAttr($input,$HouseDetails,$detailsHouse); $UpdateDetails = $detailsHouse->update(false); if($UpdateDetails == true || $Update == true) return true; } public function HouseAndNews() { $query = new \common\models\News(); $query->hid = Yii::$app->request->post('hid'); $rows['data'] = $query->HouseNewsList(Yii::$app->request->post()); $rows['count'] = $query->HouseNewsTotal(); if(!empty($rows['data'])) { return $rows; } return false; } //后期再修改一下 SQL语句这样写不行 public function RelationNewsRecord() { $model = new \common\models\HouseNews(); $nid = Yii::$app->request->post('nid'); $insert = false; foreach ($nid as $val) { $_model = clone $model; $row = $_model::find()->andWhere(['nid'=>$val])->andWhere(['hid'=>Yii::$app->request->post('hid')])->one(); if($row == null) { $_model->nid = $val; $_model->hid = Yii::$app->request->post('hid'); $_model->uid = Yii::$app->session['user_info']['uid']; $insert = $_model->insert(); } else { $row->del = 1; $row->uid = Yii::$app->session['user_info']['uid']; $insert = $row->update(); } } if($insert == true) return true; } public function FilterNews() { $model = new \common\models\HouseNews(); $model->hid = Yii::$app->request->post('hid'); $houseNewsInfo = $model->getHidList(); $nids = array_column($houseNewsInfo,'nid'); $nid_hid = array_column($houseNewsInfo,'hnid','nid'); $newsModel = new \common\models\News(); $newsModel->hid = Yii::$app->request->post('hid'); $arr['data'] = $newsModel->getNewsListHouse($nids); // $arr['data'] = $model->getNewsList(Yii::$app->request->post()); if($arr['data'] != null) { foreach ($arr['data'] as $key=>$val) { if(!empty($val['state'])) { // $arr['data'][$key]['is_view'] = Yii::$app->params['newsStatus'][$val['is_view']]; $arr['data'][$key]['create_at'] = date('Y-m-d',$val['create_at']); if(isset($nid_hid[$val['id']]) && !empty($nid_hid[$val['id']])){ $arr['data'][$key]['hnid'] = $nid_hid[$val['id']]; }else{ $arr['data'][$key]['hnid'] = 'news'; } } else { unset($arr['data'][$key]); //删除文章的时候 } } $arr['count'] = $model->Total(Yii::$app->request->post()); return $arr; } } /* * 点击加载资讯时,过滤已经关联的资讯 * */ public function FilterLoadNews() { $model = new \common\models\News(); $model->id = Yii::$app->request->post('id'); $model->subject = Yii::$app->request->post('name'); $model->category = Yii::$app->request->post('news'); $result = $model->getList(Yii::$app->request->post()); $HouseNewsModel = new \common\models\HouseNews(); $HouseNewsModel->hid = Yii::$app->request->post('hid'); $HidArr = $HouseNewsModel->getHidList(); if($HidArr != null) { $arr = []; foreach ($HidArr as $key=>$val) { if($val['del'] != 2) { $arr[$val['nid']] = $val; } } } $brr = []; if($result != null) { foreach ($result as $key=>$val) { if(empty($arr[$val['id']])){ $brr[$key]['id'] = $val['id']; $brr[$key]['subject'] = $val['subject']; $brr[$key]['clicks'] = $val['clicks']; $brr[$key]['city_name'] = $val['city_name']; $brr[$key]['create_at'] = date('Y-m-d H:i',$val['create_at']); $brr[$key]['state'] = Yii::$app->params['newsStatus'][$val['state']]; } } $rows['count'] = count($brr); $rows['data'] = $brr; return $rows; } return false; } //添加楼盘相册逻辑 public function HouseAibumCreate() { $model = new \common\models\HouseAlbum(); $row = $model->Authenticator(Yii::$app->request->post()); return true; if(is_array($row)) return $row; $url = Yii::$app->params['img_url']['housealbum']; $inputArr = UploadFile::InstancesImgName('img',$url); if(is_array($inputArr)) { //水印处理 // if(Yii::$app->request->post('thumb_watermark') == 1) // { // $ImgSet = new SetUploadImg(); // $ImgSet->SetImgWatermark($inputArr,$url); // } //压缩图片 // $compressParams = []; // $compressParams['data']['imgname'] = $inputArr;; // $compressParams['data']['url'] = $url; // $compressParams['data']['source'] = $row->album_id.'-楼盘相册@添加'; // $this->onCompress($compressParams); $arrData = []; foreach($inputArr as $key=>$val) { $arrData[$key]['hid'] = $row->hid; $arrData[$key]['album_id'] = $row->album_id; $arrData[$key]['img'] = $val; $arrData[$key]['title'] = Yii::$app->request->post('imginput')[$key]; $arrData[$key]['zhu'] = Yii::$app->request->post('editzhux')[$key]; $arrData[$key]['create_at'] = $_SERVER['REQUEST_TIME']; $arrData[$key]['update_at'] = $_SERVER['REQUEST_TIME']; } $result = Yii::$app->db->createCommand()->batchInsert($model::tableName(),['hid','album_id','img','title','zhu','create_at','update_at'],$arrData)->execute(); if($result > 0) { return true; } } else { if($row->insert() == true) return true; } } public function HouseAlbumSave() { $post = Yii::$app->request->post(); $model = new \common\models\HouseAlbum(); $row = $model->Authenticator($post); if(is_array($row)) return $row; $arreditDefault = 0; //处理删除的信息 if(!empty($post['delimg'])) { $arreditDefault = \common\models\HouseAlbum::updateAll(['del'=>2,'update_at'=>$_SERVER['REQUEST_TIME']],['id'=>$post['delimg']]); } //处理修改的信息 if(!empty($post['edittitle'])) { $editContent = []; foreach ($post['editid'] as $key=>$val) { if(is_numeric($val)) { $editContent[$val]['title'] = $post['edittitle'][$key]; $editContent[$val]['zhu'] = $post['editzhuj'][$key]; } } foreach($editContent as $key=>$val) { if(!empty($val)) { $_model = clone $model; $findone = $_model::findOne($key); if($findone != null) { $findone->title =$val['title']; $findone->zhu =$val['zhu']; $arreditDefault = $findone->update(); } } } } //处理添加的信息 if(!empty($_FILES['img'])) { $inputArr = UploadFile::InstancesImgName('img',Yii::$app->params['img_url']['housealbum']); if(is_array($inputArr)) { //水印处理 // if(Yii::$app->request->post('thumb_watermark') == 1) // { // $ImgSet = new SetUploadImg(); // $ImgSet->SetImgWatermark($inputArr,Yii::$app->params['img_url']['housealbum']); // } //压缩图片 // $compressParams = []; // $compressParams['data']['imgname'] = $inputArr;; // $compressParams['data']['url'] = Yii::$app->params['img_url']['housealbum']; // $compressParams['data']['source'] =$row->album_id.'-楼盘相册@修改'; // $this->onCompress($compressParams); $arrData = []; foreach($inputArr as $key=>$val) { $arrData[$key]['hid'] = $row->hid; $arrData[$key]['album_id'] = $row->album_id; $arrData[$key]['img'] = $val; $arrData[$key]['title'] = Yii::$app->request->post('imginput')[$key]; $arrData[$key]['zhu'] = Yii::$app->request->post('editzhux')[$key]; $arrData[$key]['create_at'] = $_SERVER['REQUEST_TIME']; $arrData[$key]['update_at'] = $_SERVER['REQUEST_TIME']; } $arreditDefault = Yii::$app->db->createCommand()->batchInsert($model::tableName(),['hid','album_id','img','title','zhu','create_at','update_at'],$arrData)->execute(); } } if($post['album_idxxxx'] != $post['album_id']) { $arreditDefault = \common\models\HouseAlbum::updateAll(['album_id'=>$post['album_idxxxx'],'update_at'=>$_SERVER['REQUEST_TIME']],['hid'=>$post['hid'],'album_id'=>$post['album_id']]); } if($arreditDefault > 0) return true; return true; } public function AlbumStateSave($type) { $input = Yii::$app->request->post(); switch ($type) { case '1': switch ($input['state']) { case 'Y': $arr = ['state'=>2,'update_at'=>$_SERVER['REQUEST_TIME']]; break; case 'N': $arr = ['state'=>1,'update_at'=>$_SERVER['REQUEST_TIME']]; break; default: return false; break; } break; case '2': $arr = ['del'=>2,'update_at'=>$_SERVER['REQUEST_TIME']]; break; } $result = \common\models\HouseAlbum::updateAll($arr,['album_id'=>$input['album_id'],'hid'=>$input['hid'],'del'=>1]); if($result > 0) return true; } //添加楼盘户型逻辑 public function HouseTypeCreate() { $model = new \common\models\HouseType(); $input = Yii::$app->request->post(); $row = $model->Authenticator($input); if (is_array($row)) return $row; $inputArr = UploadFile::InstancesImgName('img', Yii::$app->params['img_url']['housetype']); if (is_array($inputArr)) { //判断是否水印 // if(!empty($input['thumb_watermark']) && $input['thumb_watermark'] == 1) // { // $ImgSet = new SetUploadImg(); // $ImgSet->SetImgWatermark($inputArr, Yii::$app->params['img_url']['housetype']); // } //压缩图片 // $compressParams = []; // $compressParams['data']['imgname'] = $inputArr; // $compressParams['data']['url'] = Yii::$app->params['img_url']['housetype']; // $compressParams['data']['source'] = $row->type_id.'-楼盘户型@添加'; // $this->onCompress($compressParams); $arrData = []; foreach ($inputArr as $key => $val) { $arrData[$key]['hid'] = $row->hid; $arrData[$key]['type_id'] = $row->type_id; $arrData[$key]['img'] = $val; if(isset($input['title'][$key])) $arrData[$key]['title'] = $input['title'][$key]; if(isset($input['area'][$key])) $arrData[$key]['area'] = $input['area'][$key]; if(isset($input['indoor_info'][$key])) $arrData[$key]['indoor_info'] = $input['indoor_info'][$key]; $arrData[$key]['create_at'] = $_SERVER['REQUEST_TIME']; $arrData[$key]['update_at'] = $_SERVER['REQUEST_TIME']; // $arrData[$key]['hot'] = $row->hot; } $result = Yii::$app->db->createCommand()->batchInsert($model::tableName(), ['hid', 'type_id', 'img', 'title','area','indoor_info', 'create_at', 'update_at'], $arrData)->execute(); if ($result > 0) { return true; } } else { if($row->insert() == true) return true; } } public function HouseTypeSave() { $post = Yii::$app->request->post(); $model = new \common\models\HouseType(); $row = $model->Authenticator($post); if(is_array($row)) return $row; $arreditDefault = false; //处理删除的信息 if(!empty($post['delimg'])) { $result = \common\models\HouseType::updateAll(['del'=>2,'update_at'=>$_SERVER['REQUEST_TIME']],['id'=>$post['delimg']]); } //处理修改的信息 if(!empty($post['editid'])) { // p($post['editid']); $imgSaveArr = []; foreach ($post['editid'] as $key=>$val) { if($val == 'undefined') { $imgSaveArr['title'][] = $post['title'][$key]; $imgSaveArr['indoor_info'][] = $post['indoor_info'][$key]; $imgSaveArr['area'][] = $post['area'][$key]; }else{ $_model = clone $model; $findRow = $_model::findOne($val); if($findRow != null) { $findRow->title = $post['title'][$key]; $findRow->indoor_info = $post['indoor_info'][$key]; $findRow->area = $post['area'][$key]; $result = $findRow->update(false); } } } } //处理添加的信息 if(!empty($_FILES['img'])) { $imgUrl = Yii::$app->params['img_url']['housetype']; $inputArr = UploadFile::InstancesImgName('img',$imgUrl); if(is_array($inputArr)) { // if(!empty($post['thumb_watermark']) && $post['thumb_watermark'] == 1) // { // $ImgSet = new SetUploadImg(); // $ImgSet->SetImgWatermark($inputArr,$imgUrl); // } //压缩图片 // $compressParams = []; // $compressParams['data']['imgname'] = $inputArr; // $compressParams['data']['url'] = $imgUrl; // $compressParams['data']['source'] = $row->type_id.'-楼盘户型@修改'; // $this->onCompress($compressParams); $arrData = []; foreach($inputArr as $key=>$val) { $arrData[$key]['hid'] = $row->hid; $arrData[$key]['type_id'] = $row->type_id; $arrData[$key]['img'] = $val; $arrData[$key]['title'] = $imgSaveArr['title'][$key]; $arrData[$key]['area'] = $imgSaveArr['area'][$key]; $arrData[$key]['indoor_info'] = $imgSaveArr['indoor_info'][$key]; $arrData[$key]['create_at'] = $_SERVER['REQUEST_TIME']; $arrData[$key]['update_at'] = $_SERVER['REQUEST_TIME']; } $result = Yii::$app->db->createCommand()->batchInsert($model::tableName(), ['hid', 'type_id', 'img', 'title','area','indoor_info', 'create_at', 'update_at'], $arrData)->execute(); } } if($post['huxing_id'] != $post['type_id']) { $result = \common\models\HouseType::updateAll(['type_id'=>$post['huxing_id'],'update_at'=>$_SERVER['REQUEST_TIME']],['type_id'=> $post['type_id'],'hid'=>$post['hid']]); } if($result > 0) return true; return true; } //楼盘户型的上架下架 public function HouseTypeStateSave($type) { $input = Yii::$app->request->post(); switch ($type) { case '1': switch ($input['state']) { case 'Y': $arr = ['state'=>2,'update_at'=>$_SERVER['REQUEST_TIME']]; break; case 'N': $arr = ['state'=>1,'update_at'=>$_SERVER['REQUEST_TIME']]; break; default: return false; break; } break; case '2': $arr = ['del'=>2,'update_at'=>$_SERVER['REQUEST_TIME']]; break; default: return false; break; } $result = \common\models\HouseType::updateAll($arr,['type_id'=>$input['type_id'],'hid'=>$input['hid'],'del'=>1]); if($result > 0) return true; } public function HousePriceRecordadd($input) { $model = new \common\models\HousePriceRecord(); $priceModel = $model->Authenticator($input); if(is_array($priceModel)) return $priceModel; $housemodel = new \common\models\House(); $houserRow = $housemodel->FindById($priceModel->hid); $Transaction = Yii::$app->db->beginTransaction(); $houserRow->sale_price = $priceModel->price; $houserRow->update_at = $_SERVER['REQUEST_TIME']; $add = $priceModel->insert(); $save = $houserRow->update(false); if($add == true && $save == true) { $Transaction->commit(); return true; } $Transaction->rollBack(); } public function HousePriceRecordSave($input) { $model = new \common\models\HousePriceRecord(); $priceModel = $model->Authenticator($input); if(is_array($priceModel)) return $priceModel; $row = $model->FindById($input['id']); if($row != null) { $save = \backend\base\Help::SetAttr($input,$priceModel,$row); if($save->update() == true) return true; } } public function HousePriceDelete($input) { // $model = new \common\models\HousePriceRecord(); foreach ($input['id'] as $val) { if(!is_numeric($val)) return false; } $del = \common\models\HousePriceRecord::updateAll(['del'=>2,'update_at'=>$_SERVER['REQUEST_TIME']],['id'=>$input['id']]); if($del > 0) return true; } //压缩图片 private function onCompress($data) { $model = new \backend\event\TinifyEvent(); $model->CompressImg($data); } }