123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909 |
- <?php
- /**
- * Created by PhpStorm.
- * User: xiaofeng
- * Date: 2018/3/4
- * Time: 下午2:20
- */
- //处理楼盘业务
- namespace backend\server;
- use backend\base\Help;
- use common\models\House;
- use common\models\HouseDetail;
- use common\models\UserHouse;
- use Yii;
- class Houses extends \yii\base\Component
- {
- const EVENT_COMPRESS = 'compress_img'; //压缩图片
- public function GroupList($input)
- {
- $model = new House();
- if(!empty($input['city']))
- {
- $city = new \common\models\CategoryCity();
- $pro = $city->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);
- }
- }
|