123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Administrator
- * Date: 2017/7/24
- * Time: 11:37
- */
- namespace company\controllers;
- use common\library\ZM_Geohash;
- use yii\base\Controller;
- use yii;
- use yii\filters\AccessControl;
- use common\models\Building;
- use yii\data\Pagination;
- use common\models\Manager;
- use common\models\Designer;
- use common\library\LMUploadFile;
- use yii\web\UploadedFile;
- use common\models\ImageSource;
- use common\models\Appointment;
- class BuildingController extends Controller{
- public function behaviors()
- {
- return [
- 'access' => [
- 'class' => AccessControl::className(),
- 'rules' => [
- [
- 'actions' => [],
- 'allow' => true,
- 'roles' => ['@'],
- ],
- ],
- ],
- ];
- }
- //新加板样房、 工地
- public static function add_building(){
- $model = new Building();
- if($model->load(Yii::$app->request->get())){
- $opening_begin = strtotime(Yii::$app->request->get('opening_begin'));
- $opening_end = strtotime(Yii::$app->request->get('opening_end'));
- if(!is_numeric($opening_begin)&&!is_numeric($opening_end)){
- $opening_begin = strtotime($opening_begin);
- $opening_end = strtotime($opening_end);
- }
- $pickup_address_coordinate = Yii::$app->request->get('pickup_address_coordinate');//地址坐标
- $url ="http://restapi.amap.com/v3/geocode/regeo?key=9176f3987ffff3aaadfe2af13a2fccdb&location={$pickup_address_coordinate}&poitype=&radius=&extensions=base&batch=false&roadlevel=";
- $ch = curl_init();
- $timeout = 5;
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
- $html = curl_exec($ch);
- curl_close($ch);
- $html = json_decode($html);
- if($html->info == "OK")
- {
- if($html->regeocode->addressComponent->adcode != Yii::$app->request->get("Building")['district'] && $html->regeocode->addressComponent->adcode !=Yii::$app->request->get("Building")['city']){
- $result=['sign'=>1,'msg'=>"您选择的地区和地图的坐标地点不符合"];
- return json_encode($result);
- }
- }
- $arr = explode(',',$pickup_address_coordinate);
- $living_room = Yii::$app->request->get('living_room');//客厅照片
- $master_bedroom = Yii::$app->request->get('master_bedroom');//主卧照片
- $portion = Yii::$app->request->get('portion');//局部美图
- $portion2 = Yii::$app->request->get('portion2');//局部美图2
- $portion3 = Yii::$app->request->get('portion3');//局部美图3
- $portion4 = Yii::$app->request->get('portion4');//局部美图4
- $portion5 = Yii::$app->request->get('portion5');//局部美图5
- $build = Yii::$app->request->get('build');//施工图
- $build2 = Yii::$app->request->get('build2');//施工图
- $flat = Yii::$app->request->get('flat');//平面图
- $model->longitude = isset($arr[0])?$arr[0]:"";
- $model->latitude = isset($arr[1])?$arr[1]:"";
- if(!empty($model->longitude)&&!empty($model->latitude))
- {
- $geohash = new ZM_Geohash();
- $geohash->init_codingMap();
- $model->hashcode =$geohash->encode($model->latitude,$model->longitude);
- }
- $model->uid = Yii::$app->user->id;
- $model->opening_begin = $opening_begin;
- $model->opening_end = $opening_end;
- $model->created_at = time();
- $model->updated_at = time();
- $model->status = Building::STATUS_REVIEW;
- //客厅照片
- if($model->validate()&&$model->save()){
- if(!empty($living_room)){
- $living_room_image = new ImageSource();
- $living_room_image->topid = $model->id;
- $living_room_image->type = ImageSource::TYPE_LIVING_ROOM;
- $living_room_image->pic = isset($living_room)?$living_room:"";
- $living_room_image->status = ImageSource::STATUS_YES;
- $living_room_image->created_at = time();
- $living_room_image->updated_at = time();
- if($living_room_image->validate()&&$living_room_image->save()){
- $result=['sign'=>0,'msg'=>'成功'];
- }else{
- $result=['sign'=>4000,'msg'=>'失败,客厅照片'];
- return json_encode($result);
- }
- }
- //主卧照片
- if(!empty($master_bedroom)){
- $master_bedroom_image = new ImageSource();
- $master_bedroom_image->topid = $model->id;;
- $master_bedroom_image->type = ImageSource::TYPE_MASTER_BEDROOM;
- $master_bedroom_image->pic = isset($master_bedroom)?$master_bedroom:"";
- $master_bedroom_image->status = ImageSource::STATUS_YES;
- $master_bedroom_image->created_at = time();
- $master_bedroom_image->updated_at = time();
- if($master_bedroom_image->validate()&&$master_bedroom_image->save()){
- $result=['sign'=>0,'msg'=>'成功'];
- }else{
- $result=['sign'=>4000,'msg'=>'失败,主卧照片'];
- return json_encode($result);
- }
- }
- //局部美图
- if(!empty($portion)){
- $portion_image = new ImageSource();
- $portion_image->topid = $model->id;;
- $portion_image->type = ImageSource::TYPE_PORTION;
- $portion_image->pic = isset($portion)?$portion:"";
- $portion_image->status = ImageSource::STATUS_YES;
- $portion_image->created_at = time();
- $portion_image->updated_at = time();
- if($portion_image->validate()&&$portion_image->save()){
- $result=['sign'=>0,'msg'=>'成功'];
- }else{
- $result=['sign'=>4000,'msg'=>'失败,局部美图'];
- return json_encode($result);
- }
- }
- //局部美图2
- if(!empty($portion2)){
- $portion2_image = new ImageSource();
- $portion2_image->topid = $model->id;;
- $portion2_image->type = ImageSource::TYPE_PORTION2;
- $portion2_image->pic = isset($portion2)?$portion2:"";
- $portion2_image->status = ImageSource::STATUS_YES;
- $portion2_image->created_at = time();
- $portion2_image->updated_at = time();
- if($portion2_image->validate()&&$portion2_image->save()){
- $result=['sign'=>0,'msg'=>'成功'];
- }else{
- $result=['sign'=>4000,'msg'=>'失败,局部美图'];
- return json_encode($result);
- }
- }
- //局部美图3
- if(!empty($portion3)){
- $portion3_image = new ImageSource();
- $portion3_image->topid = $model->id;;
- $portion3_image->type = ImageSource::TYPE_PORTION3;
- $portion3_image->pic = isset($portion3)?$portion3:"";
- $portion3_image->status = ImageSource::STATUS_YES;
- $portion3_image->created_at = time();
- $portion3_image->updated_at = time();
- if($portion3_image->validate()&&$portion3_image->save()){
- $result=['sign'=>0,'msg'=>'成功'];
- }else{
- $result=['sign'=>4000,'msg'=>'失败,局部美图'];
- return json_encode($result);
- }
- }
- //局部美图4
- if(!empty($portion4)){
- $portion4_image = new ImageSource();
- $portion4_image->topid = $model->id;;
- $portion4_image->type = ImageSource::TYPE_PORTION4;
- $portion4_image->pic = isset($portion4)?$portion4:"";
- $portion4_image->status = ImageSource::STATUS_YES;
- $portion4_image->created_at = time();
- $portion4_image->updated_at = time();
- if($portion4_image->validate()&&$portion4_image->save()){
- $result=['sign'=>0,'msg'=>'成功'];
- }else{
- $result=['sign'=>4000,'msg'=>'失败,局部美图'];
- return json_encode($result);
- }
- }
- //局部美图5
- if(!empty($portion5)){
- $portion5_image = new ImageSource();
- $portion5_image->topid = $model->id;;
- $portion5_image->type = ImageSource::TYPE_PORTION5;
- $portion5_image->pic = isset($portion5)?$portion5:"";
- $portion5_image->status = ImageSource::STATUS_YES;
- $portion5_image->created_at = time();
- $portion5_image->updated_at = time();
- if($portion5_image->validate()&&$portion5_image->save()){
- $result=['sign'=>0,'msg'=>'成功'];
- }else{
- $result=['sign'=>4000,'msg'=>'失败,局部美图'];
- return json_encode($result);
- }
- }
- //施工图1
- if(!empty($build)){
- $build_image = new ImageSource();
- $build_image->topid = $model->id;;
- $build_image->type = ImageSource::TYPE_BUILD;
- $build_image->pic = isset($build)?$build:"";
- $build_image->status = ImageSource::STATUS_YES;
- $build_image->created_at = time();
- $build_image->updated_at = time();
- if($build_image->validate()&&$build_image->save()){
- $result=['sign'=>0,'msg'=>'成功'];
- }else{
- $result=['sign'=>4000,'msg'=>'失败,施工图'];
- return json_encode($result);
- }
- }
- //施工图2
- if(!empty($build2)){
- $build2_image = new ImageSource();
- $build2_image->topid = $model->id;;
- $build2_image->type = ImageSource::TYPE_BUILD2;
- $build2_image->pic = isset($build2)?$build2:"";
- $build2_image->status = ImageSource::STATUS_YES;
- $build2_image->created_at = time();
- $build2_image->updated_at = time();
- if($build2_image->validate()&&$build2_image->save()){
- $result=['sign'=>0,'msg'=>'成功'];
- }else{
- $result=['sign'=>4000,'msg'=>'失败,施工图'];
- return json_encode($result);
- }
- }
- //平面图
- if(!empty($flat)){
- $flat_image = new ImageSource();
- $flat_image->topid = $model->id;;
- $flat_image->type = ImageSource::TYPE_FLAT;
- $flat_image->pic = isset($flat)?$flat:"";
- $flat_image->status = ImageSource::STATUS_YES;
- $flat_image->created_at = time();
- $flat_image->updated_at = time();
- if($flat_image->validate()&&$flat_image->save()){
- $result=['sign'=>0,'msg'=>'成功'];
- }else{
- $result=['sign'=>4000,'msg'=>'失败,平面图'];
- return json_encode($result);
- }
- }
- $result=['sign'=>0,'msg'=>'发布成功'];
- return json_encode($result);
- }else{
- $result=['sign'=>4000,'msg'=>'添加失败'];
- return json_encode($result);
- }
- }else{
- $result=['sign'=>4000,'msg'=>'数据有误'];
- return json_encode($result);
- }
- }
- //更新板样房、 工地
- public static function update_building($id){
- if(empty($id)){
- $id = Yii::$app->request->get('topid');
- }
- $model = Building::find()->where('id=:id',[':id'=>$id])->one();
- if($model->load(Yii::$app->request->get())){
- $opening_begin = strtotime(Yii::$app->request->get('opening_begin'));
- $opening_end = strtotime(Yii::$app->request->get('opening_end'));
- $pickup_address_coordinate = Yii::$app->request->get('pickup_address_coordinate');//地址坐标
- $url ="http://restapi.amap.com/v3/geocode/regeo?key=9176f3987ffff3aaadfe2af13a2fccdb&location={$pickup_address_coordinate}&poitype=&radius=&extensions=base&batch=false&roadlevel=";
- $ch = curl_init();
- $timeout = 5;
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
- $html = curl_exec($ch);
- curl_close($ch);
- $html = json_decode($html);
- if($html->info == "OK")
- {
- if($html->regeocode->addressComponent->adcode != Yii::$app->request->get("Building")['district'] && $html->regeocode->addressComponent->adcode !=Yii::$app->request->get("Building")['city']){
- $result=['sign'=>1,'msg'=>"您选择的地区和地图的坐标地点不符合"];
- return json_encode($result);
- }
- }
- $arr = explode(',',$pickup_address_coordinate);
- $model->latitude = isset($arr[1])?$arr[1]:"";
- $model->longitude = isset($arr[0])?$arr[0]:"";
- if(!empty($model->longitude)&&!empty($model->latitude))
- {
- $geohash = new ZM_Geohash();
- $geohash->init_codingMap();
- $model->hashcode =$geohash->encode($model->latitude,$model->longitude);
- }
- $living_room = Yii::$app->request->get('living_room');//客厅照片
- $master_bedroom = Yii::$app->request->get('master_bedroom');//主卧照片
- $portion = Yii::$app->request->get('portion');//局部美图
- $portion2 = Yii::$app->request->get('portion2');//局部美图2
- $portion3 = Yii::$app->request->get('portion3');//局部美图3
- $portion4 = Yii::$app->request->get('portion4');//局部美图4
- $portion5 = Yii::$app->request->get('portion5');//局部美图5
- $build = Yii::$app->request->get('build');//施工图
- $build2 = Yii::$app->request->get('build2');//施工图2
- $flat = Yii::$app->request->get('flat');//平面图
- $living_room_delete = Yii::$app->request->get('living_room_delete');
- $master_bedroom_delete = Yii::$app->request->get('master_bedroom_delete');
- $portion_delete = Yii::$app->request->get('portion_delete');
- $portion2_delete = Yii::$app->request->get('portion2_delete');
- $portion3_delete = Yii::$app->request->get('portion3_delete');
- $portion4_delete = Yii::$app->request->get('portion4_delete');
- $portion5_delete = Yii::$app->request->get('portion5_delete');
- $build_delete = Yii::$app->request->get('build_delete');
- $build2_delete = Yii::$app->request->get('build2_delete');
- $flat_delete = Yii::$app->request->get('flat_delete');
- $model->uid = Yii::$app->user->id;
- $model->opening_begin = $opening_begin;
- $model->opening_end = $opening_end;
- $model->created_at = time();
- $model->updated_at = time();
- $model->status = Building::STATUS_REVIEW;
- //客厅照片
- if($model->validate()&&$model->save()){
- if($living_room_delete == -1)
- {
- $living_room_image = ImageSource::find()->where('topid=:topid and type=:type and status=:status',[':topid'=>$id,':type'=>ImageSource::TYPE_LIVING_ROOM,':status'=>ImageSource::STATUS_YES])->one();
- $living_room_image->status = ImageSource::STATUS_NO;
- $living_room_image->updated_at = time();
- $living_room_image->save();
- }
- if(!empty($living_room)){
- $living_room_image = ImageSource::find()->where('topid=:topid and type=:type and status=:status',[':topid'=>$id,':type'=>ImageSource::TYPE_LIVING_ROOM,':status'=>ImageSource::STATUS_YES])->one();
- if(empty($living_room_image)){
- $living_room_image = new ImageSource();
- $living_room_image->created_at = time();
- }
- $living_room_image->topid = $model->id;
- $living_room_image->type = ImageSource::TYPE_LIVING_ROOM;
- $living_room_image->pic = isset($living_room)?$living_room:"";
- $living_room_image->status = ImageSource::STATUS_YES;
- $living_room_image->updated_at = time();
- if($living_room_image->validate()&&$living_room_image->save()){
- $result=['sign'=>0,'msg'=>'成功'];
- }else{
- $result=['sign'=>1,'msg'=>'失败,客厅照片'];
- return json_encode($result);
- }
- }
- if($master_bedroom_delete == -1)
- {
- $master_bedroom_image = ImageSource::find()->where('topid=:topid and type=:type and status=:status',[':topid'=>$id,':type'=>ImageSource::TYPE_MASTER_BEDROOM,':status'=>ImageSource::STATUS_YES])->one();
- $master_bedroom_image->status = ImageSource::STATUS_NO;
- $master_bedroom_image->updated_at = time();
- $master_bedroom_image->save();
- }
- //主卧照片
- if(!empty($master_bedroom)){
- $master_bedroom_image = ImageSource::find()->where('topid=:topid and type=:type and status=:status',[':topid'=>$id,':type'=>ImageSource::TYPE_MASTER_BEDROOM,':status'=>ImageSource::STATUS_YES])->one();
- if(empty($master_bedroom_image)){
- $master_bedroom_image = new ImageSource();
- $master_bedroom_image->created_at = time();
- }
- $master_bedroom_image->topid = $model->id;;
- $master_bedroom_image->type = ImageSource::TYPE_MASTER_BEDROOM;
- $master_bedroom_image->pic = isset($master_bedroom)?$master_bedroom:"";
- $master_bedroom_image->status = ImageSource::STATUS_YES;
- $master_bedroom_image->updated_at = time();
- if($master_bedroom_image->validate()&&$master_bedroom_image->save()){
- $result=['sign'=>0,'msg'=>'成功'];
- }else{
- $result=['sign'=>1,'msg'=>'失败,主卧照片'];
- return json_encode($result);
- }
- }
- if($portion_delete == -1)
- {
- $portion_image = ImageSource::find()->where('topid=:topid and type=:type and status=:status',[':topid'=>$id,':type'=>ImageSource::TYPE_PORTION,':status'=>ImageSource::STATUS_YES])->one();
- $portion_image->status = ImageSource::STATUS_NO;
- $portion_image->updated_at = time();
- $portion_image->save();
- }
- //局部美图
- if(!empty($portion)){
- $portion_image = ImageSource::find()->where('topid=:topid and type=:type and status=:status',[':topid'=>$id,':type'=>ImageSource::TYPE_PORTION,':status'=>ImageSource::STATUS_YES])->one();
- if(empty($portion_image)){
- $portion_image = new ImageSource();
- $portion_image->created_at = time();
- }
- $portion_image->topid = $model->id;;
- $portion_image->type = ImageSource::TYPE_PORTION;
- $portion_image->pic = isset($portion)?$portion:"";
- $portion_image->status = ImageSource::STATUS_YES;
- $portion_image->updated_at = time();
- if($portion_image->validate()&&$portion_image->save()){
- $result=['sign'=>0,'msg'=>'成功'];
- }else{
- $result=['sign'=>1,'msg'=>'失败,局部美图'];
- return json_encode($result);
- }
- }
- if($portion2_delete == -1)
- {
- $portion2_image = ImageSource::find()->where('topid=:topid and type=:type and status=:status',[':topid'=>$id,':type'=>ImageSource::TYPE_PORTION2,':status'=>ImageSource::STATUS_YES])->one();
- $portion2_image->status = ImageSource::STATUS_NO;
- $portion2_image->updated_at = time();
- $portion2_image->save();
- }
- //局部美图2
- if(!empty($portion2)){
- $portion2_image = ImageSource::find()->where('topid=:topid and type=:type and status=:status',[':topid'=>$id,':type'=>ImageSource::TYPE_PORTION2,':status'=>ImageSource::STATUS_YES])->one();
- if(empty($portion2_image)){
- $portion2_image = new ImageSource();
- $portion2_image->created_at = time();
- }
- $portion2_image->topid = $model->id;;
- $portion2_image->type = ImageSource::TYPE_PORTION2;
- $portion2_image->pic = isset($portion2)?$portion2:"";
- $portion2_image->status = ImageSource::STATUS_YES;
- $portion2_image->updated_at = time();
- if($portion2_image->validate()&&$portion2_image->save()){
- $result=['sign'=>0,'msg'=>'成功'];
- }else{
- $result=['sign'=>1,'msg'=>'失败,局部美图'];
- return json_encode($result);
- }
- }
- if($portion3_delete == -1)
- {
- $portion3_image = ImageSource::find()->where('topid=:topid and type=:type and status=:status',[':topid'=>$id,':type'=>ImageSource::TYPE_PORTION3,':status'=>ImageSource::STATUS_YES])->one();
- $portion3_image->status = ImageSource::STATUS_NO;
- $portion3_image->updated_at = time();
- $portion3_image->save();
- }
- //局部美图3
- if(!empty($portion3)){
- $portion3_image = ImageSource::find()->where('topid=:topid and type=:type and status=:status',[':topid'=>$id,':type'=>ImageSource::TYPE_PORTION3,':status'=>ImageSource::STATUS_YES])->one();
- if(empty($portion3_image)){
- $portion3_image = new ImageSource();
- $portion3_image->created_at = time();
- }
- $portion3_image->topid = $model->id;;
- $portion3_image->type = ImageSource::TYPE_PORTION3;
- $portion3_image->pic = isset($portion3)?$portion3:"";
- $portion3_image->status = ImageSource::STATUS_YES;
- $portion3_image->updated_at = time();
- if($portion3_image->validate()&&$portion3_image->save()){
- $result=['sign'=>0,'msg'=>'成功'];
- }else{
- $result=['sign'=>1,'msg'=>'失败,局部美图'];
- return json_encode($result);
- }
- }
- if($portion4_delete == -1)
- {
- $portion4_image = ImageSource::find()->where('topid=:topid and type=:type and status=:status',[':topid'=>$id,':type'=>ImageSource::TYPE_PORTION4,':status'=>ImageSource::STATUS_YES])->one();
- $portion4_image->status = ImageSource::STATUS_NO;
- $portion4_image->updated_at = time();
- $portion4_image->save();
- }
- //局部美图4
- if(!empty($portion4)){
- $portion4_image = ImageSource::find()->where('topid=:topid and type=:type and status=:status',[':topid'=>$id,':type'=>ImageSource::TYPE_PORTION4,':status'=>ImageSource::STATUS_YES])->one();
- if(empty($portion4_image)){
- $portion4_image = new ImageSource();
- $portion4_image->created_at = time();
- }
- $portion4_image->topid = $model->id;;
- $portion4_image->type = ImageSource::TYPE_PORTION4;
- $portion4_image->pic = isset($portion4)?$portion4:"";
- $portion4_image->status = ImageSource::STATUS_YES;
- $portion4_image->updated_at = time();
- if($portion4_image->validate()&&$portion4_image->save()){
- $result=['sign'=>0,'msg'=>'成功'];
- }else{
- $result=['sign'=>1,'msg'=>'失败,局部美图'];
- return json_encode($result);
- }
- }
- if($portion5_delete == -1)
- {
- $portion5_image = ImageSource::find()->where('topid=:topid and type=:type and status=:status',[':topid'=>$id,':type'=>ImageSource::TYPE_PORTION5,':status'=>ImageSource::STATUS_YES])->one();
- $portion5_image->status = ImageSource::STATUS_NO;
- $portion5_image->updated_at = time();
- $portion5_image->save();
- }
- //局部美图5
- if(!empty($portion5)){
- $portion5_image = ImageSource::find()->where('topid=:topid and type=:type and status=:status',[':topid'=>$id,':type'=>ImageSource::TYPE_PORTION5,':status'=>ImageSource::STATUS_YES])->one();
- if(empty($portion5_image)){
- $portion5_image = new ImageSource();
- $portion5_image->created_at = time();
- }
- $portion5_image->topid = $model->id;;
- $portion5_image->type = ImageSource::TYPE_PORTION5;
- $portion5_image->pic = isset($portion5)?$portion5:"";
- $portion5_image->status = ImageSource::STATUS_YES;
- $portion5_image->updated_at = time();
- if($portion5_image->validate()&&$portion5_image->save()){
- $result=['sign'=>0,'msg'=>'成功'];
- }else{
- $result=['sign'=>1,'msg'=>'失败,局部美图'];
- return json_encode($result);
- }
- }
- if($build_delete == -1)
- {
- $build_image = ImageSource::find()->where('topid=:topid and type=:type and status=:status',[':topid'=>$id,':type'=>ImageSource::TYPE_BUILD,':status'=>ImageSource::STATUS_YES])->one();
- $build_image->status = ImageSource::STATUS_NO;
- $build_image->updated_at = time();
- $build_image->save();
- }
- //施工图
- if(!empty($build)){
- $build_image = ImageSource::find()->where('topid=:topid and type=:type and status=:status',[':topid'=>$id,':type'=>ImageSource::TYPE_BUILD,':status'=>ImageSource::STATUS_YES])->one();
- if(empty($build_image)){
- $build_image = new ImageSource();
- $build_image->created_at = time();
- }
- $build_image->topid = $model->id;;
- $build_image->type = ImageSource::TYPE_BUILD;
- $build_image->pic = isset($build)?$build:"";
- $build_image->status = ImageSource::STATUS_YES;
- $build_image->updated_at = time();
- if($build_image->validate()&&$build_image->save()){
- $result=['sign'=>0,'msg'=>'成功'];
- }else{
- $result=['sign'=>1,'msg'=>'失败,施工图'];
- return json_encode($result);
- }
- }
- if($build2_delete == -1)
- {
- $build2_image = ImageSource::find()->where('topid=:topid and type=:type and status=:status',[':topid'=>$id,':type'=>ImageSource::TYPE_BUILD2,':status'=>ImageSource::STATUS_YES])->one();
- $build2_image->status = ImageSource::STATUS_NO;
- $build2_image->updated_at = time();
- $build2_image->save();
- }
- //施工图2
- if(!empty($build2)){
- $build2_image = ImageSource::find()->where('topid=:topid and type=:type and status=:status',[':topid'=>$id,':type'=>ImageSource::TYPE_BUILD2,':status'=>ImageSource::STATUS_YES])->one();
- if(empty($build2_image)){
- $build2_image = new ImageSource();
- $build2_image->created_at = time();
- }
- $build2_image->topid = $model->id;;
- $build2_image->type = ImageSource::TYPE_BUILD2;
- $build2_image->pic = isset($build2)?$build2:"";
- $build2_image->status = ImageSource::STATUS_YES;
- $build2_image->updated_at = time();
- if($build2_image->validate()&&$build2_image->save()){
- $result=['sign'=>0,'msg'=>'成功'];
- }else{
- $result=['sign'=>1,'msg'=>'失败,施工图2'];
- return json_encode($result);
- }
- }
- if($flat_delete == -1)
- {
- $flat_image = ImageSource::find()->where('topid=:topid and type=:type and status=:status',[':topid'=>$id,':type'=>ImageSource::TYPE_FLAT,':status'=>ImageSource::STATUS_YES])->one();
- $flat_image->status = ImageSource::STATUS_NO;
- $flat_image->updated_at = time();
- $flat_image->save();
- }
- //平面图
- if(!empty($flat)){
- $flat_image = ImageSource::find()->where('topid=:topid and type=:type and status=:status',[':topid'=>$id,':type'=>ImageSource::TYPE_FLAT,':status'=>ImageSource::STATUS_YES])->one();
- if(empty($flat_image)){
- $flat_image = new ImageSource();
- $flat_image->created_at = time();
- }
- $flat_image->topid = $model->id;;
- $flat_image->type = ImageSource::TYPE_FLAT;
- $flat_image->pic = isset($flat)?$flat:"";
- $flat_image->status = ImageSource::STATUS_YES;
- $flat_image->updated_at = time();
- if($flat_image->validate()&&$flat_image->save()){
- $result=['sign'=>0,'msg'=>'成功'];
- }else{
- $result=['sign'=>1,'msg'=>'失败,平面图'];
- return json_encode($result);
- }
- }
- $result=['sign'=>0,'msg'=>'成功'];
- return json_encode($result);
- }else{
- $result=['sign'=>4000,'msg'=>'有问题'];
- return json_encode($result);
- }
- }else{
- $result=['sign'=>4000,'msg'=>'数据有误'];
- return json_encode($result); }
- }
- //删除板样房、 工地
- public static function delede_building($id){
- $model = Building::find()->where('id=:id',[':id'=>$id])->one();
- // if(!empty($model)){
- // $image_model = ImageSource::find()
- // ->where('topid=:topid and (type=:type1 or type=:type2 or type=:type3 or type=:type4)',
- // [
- // ':topid'=>$model->id,
- // ':type1'=>ImageSource::TYPE_LIVING_ROOM,
- // ':type1'=>ImageSource::TYPE_MASTER_BEDROOM,
- // ':type1'=>ImageSource::TYPE_PORTION,
- // ':type1'=>ImageSource::TYPE_FLAT,
- // ])->all();
- // }
- $model->posted = Building::POSTED_DELETE;
- $model->updated_at = time();
- if($model->validate()&&$model->save()){
- $result=['sign'=>1,'msg'=>'删除成功'];
- }else{
- var_dump($model->getErrors());
- $result=['sign'=>4000,'msg'=>'数据有误'];
- }
- return json_encode($result);
- }
- //发布板样房、 工地
- public static function delede_posted($id){
- $model = Building::find()->where('id=:id and posted=:posted',[':id'=>$id,':posted'=>Building::POSTED_NO])->one();
- $model->posted = Building::POSTED_YES;
- $model->updated_at = time();
- if($model->validate()&&$model->save()){
- $result=['sign'=>1,'msg'=>'发布成功'];
- }else{
- var_dump($model->getErrors());
- $result=['sign'=>4000,'msg'=>'数据有误'];
- }
- return json_encode($result);
- }
- //停止板样房、 工地
- public static function stop_posted($id){
- $model = Building::find()->where('id=:id and posted=:posted',[':id'=>$id,':posted'=>Building::POSTED_YES])->one();
- $model->posted = Building::POSTED_NO;
- $model->updated_at = time();
- if($model->validate()&&$model->save()){
- $result=['sign'=>1,'msg'=>'停止成功'];
- }else{
- var_dump($model->getErrors());
- $result=['sign'=>4000,'msg'=>'数据有误'];
- }
- return json_encode($result);
- }
- }
|