12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064 |
- <?php
- namespace api\modules\v1\controllers;
- use common\library\ZM_Geohash;
- use common\models\Appointment;
- use common\models\Area;
- use common\models\Building;
- use common\models\Comment;
- use common\models\Designer;
- use common\models\ImageSource;
- use common\models\Manager;
- use common\models\Reply;
- use common\models\UserCompany;
- use common\models\UserInfo;
- use yii\rest\ActiveController;
- use common\library\Apireturn;
- use yii\helpers\ArrayHelper;
- use yii\filters\auth\QueryParamAuth;
- use yii;
- class CompanyBuildingController extends ActiveController
- {
- public static $stage_arr = array('开工大吉','拆改','水电','泥水','木工','油漆','验收');
- public static $layout_arr = array('一房','二房','三房','四房','五房','复式','楼中楼','别墅','办公室','店面','单身公寓','自建房','跃层式');
- public static $style_arr =array('北欧','欧式','现代简约','中式','新中式','美式乡村','田园','地中海','东南亚','时尚混搭','简欧','新古典','雅致主义','日韩式','工业风','港式');
- public static $pattern_arr = array('清包','半包','全包');
- public $modelClass = 'common\models';
- const DISPLAY = 10;//显示条数
- public function behaviors()
- {
- return ArrayHelper::merge(parent::behaviors(), [
- 'authenticator' => [
- 'class' => QueryParamAuth::className(),
- 'tokenParam' => "token",//access-token修改为token
- 'optional' => [//不需要认证方法名 array
- ],
- ]
- ]);
- }
- /**
- * 添加样板房
- */
- public function actionAddRoom()
- {
- $post = Yii::$app->request->post();
- if(empty($post['name']) || empty($post['acreage']) || empty($post['budget']) || empty($post['opening_begin']) || empty($post['opening_end']) || empty($post['layout']) || empty($post['style']))
- return Apireturn::sent(0,'请填写完整信息',200);
- $str_opening_begin = strtotime($post['opening_begin']);
- $str_opening_end = strtotime($post['opening_end']);
- if($str_opening_begin > $str_opening_end)
- return Apireturn::sent(0,'可约时间不能大于结束时间',200);
- if(empty($post['designer_id']) || empty($post['manager_id']))
- return Apireturn::sent(0,'请选择设计师和项目经理',200);
- if(empty($post['province']) || empty($post['city']) || empty($post['district']) )
- return Apireturn::sent(0,'请选择地区',200);
- if(empty($post['address']))
- return Apireturn::sent(0,'请输入详细地址',200);
- if(empty($post['longitude']) || empty($post['latitude']))
- return Apireturn::sent(0,'缺少经纬度',200);
- $model = new Building();
- $model->uid = Yii::$app->user->id;
- $model->name = $post['name'];
- $model->type = Building::TYPE_HOUSE;
- $model->latitude = $post['latitude'];
- $model->longitude = $post['longitude'];
- if(!empty($model->longitude)&&!empty($model->latitude)) {
- $geohash = new ZM_Geohash();
- $geohash->init_codingMap();
- $model->hashcode = $geohash->encode($model->latitude, $model->longitude);
- }
- $model->province = $post['province'];
- $model->city = $post['city'];
- $model->district = $post['district'];
- $model->address = $post['address'];
- $model->created_at = time();
- $model->updated_at = time();
- $model->status = Building::STATUS_SUCCESS;
- $model->acreage = $post['acreage'];
- $model->budget = $post['budget'];
- $model->layout = $post['layout'];
- $model->style = $post['style'];
- $model->opening_begin =$str_opening_begin;
- $model->opening_end = $str_opening_end;
- $model->manager_id = $post['manager_id'];
- $model->designer_id = $post['designer_id'];
- $model->posted = Building::POSTED_YES;
- if($model->save())
- {
- $this->uploadBuildingImg($model->id,$post);
- return Apireturn::sent(1,'添加样板房成功',200);
- }else{
- return Apireturn::sent(0,'添加样板房失败',200);
- }
- }
- /**
- * 查看样板房
- */
- public function actionCheckRoom()
- {
- $id = Yii::$app->request->post('id');
- if(empty($id))
- return Apireturn::sent(0,'非法操作',200);
- $info = Building::find()->where(['id'=>$id,'uid'=>Yii::$app->user->id])->select("id,name,latitude,longitude,province,city,district,address,layout,acreage,opening_begin,opening_end,budget,style,manager_id,designer_id")->one();
- if(empty($info))
- return Apireturn::sent(0,'找不到该样板房',200);
- $arr = array();
- foreach ($info->getOldAttributes() as $key =>$value)
- {
- $arr[$key] = $value;
- }
- //设计师详情
- $data['designer'] = array();
- if(!empty($info->designer))
- {
- $arr['designer']['id'] = $info->designer->id;
- $arr['designer']['realname'] = $info->designer->realname;
- }
- //项目经理详情
- $data['manager'] = array();
- if(!empty($info->manager))
- {
- $arr['manager']['id'] = $info->manager->id;
- $arr['manager']['realname'] = $info->manager->realname;
- }
- $arr['living_room'] = $info->living ? $info->living->pic : "" ;
- $arr['master_bedroom'] = $info->master ? $info->master->pic : "" ;
- $arr['portion'] = $info->portion ? $info->portion->pic : "" ;
- $arr['portion2'] = $info->portion2 ? $info->portion2->pic : "" ;
- $arr['portion3'] = $info->portion3 ? $info->portion3->pic : "" ;
- $arr['portion4'] = $info->portion4 ? $info->portion4->pic : "" ;
- $arr['portion5'] = $info->portion5 ? $info->portion5->pic : "" ;
- $arr['flat'] = $info->flat ? $info->flat->pic : "" ;
- $arr['province_name'] = !empty($info->province) ? Area::queryCity($info->province) : "";
- $arr['city_name'] = !empty($info->city) ? Area::queryCity($info->city) : "";
- $arr['district_name'] = !empty($info->district) ? Area::queryCity($info->district) : "";
- return Apireturn::sent(1,'success',200,$arr);
- }
- /**
- * 编辑样板房
- */
- public function actionEditRoom()
- {
- $post = Yii::$app->request->post();
- if(empty($post['id']))
- return Apireturn::sent(0,'缺少id',200);
- $model = Building::find()->where(['id'=>$post['id'],'uid'=>Yii::$app->user->id])->one();
- if(empty($model))
- return Apireturn::sent(0,'找不到该样板房',200);
- if(empty($post['name']) || empty($post['acreage']) || empty($post['budget']) || empty($post['opening_begin']) || empty($post['opening_end']) || empty($post['layout']) || empty($post['style']))
- return Apireturn::sent(0,'请填写完整信息',200);
- $str_opening_begin = strtotime($post['opening_begin']);
- $str_opening_end = strtotime($post['opening_end']);
- if($str_opening_begin > $str_opening_end)
- return Apireturn::sent(0,'可约时间不能大于结束时间',200);
- if(empty($post['designer_id']) || empty($post['manager_id']))
- return Apireturn::sent(0,'请选择设计师和项目经理',200);
- if(empty($post['province']) || empty($post['city']) || empty($post['district']) )
- return Apireturn::sent(0,'请选择地区',200);
- if(empty($post['address']))
- return Apireturn::sent(0,'请输入详细地址',200);
- if(empty($post['longitude']) || empty($post['latitude']))
- return Apireturn::sent(0,'缺少经纬度',200);
- if(!empty($model->longitude)&&!empty($model->latitude)) {
- $geohash = new ZM_Geohash();
- $geohash->init_codingMap();
- $model->hashcode = $geohash->encode($model->latitude, $model->longitude);
- }
- $model->name = $post['name'];
- $model->latitude = $post['latitude'];
- $model->longitude = $post['longitude'];
- $model->province = $post['province'];
- $model->city = $post['city'];
- $model->district = $post['district'];
- $model->address = $post['address'];
- $model->updated_at = time();
- $model->acreage = $post['acreage'];
- $model->budget = $post['budget'];
- $model->layout = $post['layout'];
- $model->style = $post['style'];
- $model->opening_begin =$str_opening_begin;
- $model->opening_end = $str_opening_end;
- $model->manager_id = $post['manager_id'];
- $model->designer_id = $post['designer_id'];
- if($model->save())
- {
- $this->uploadBuildingImg($model->id,$post,'edit');
- return Apireturn::sent(1,'修改样板房成功',200);
- }else{
- return Apireturn::sent(0,'修改样板房失败',200);
- }
- }
- /**
- * 添加工地
- */
- public function actionAddWork()
- {
- $post = Yii::$app->request->post();
- if(empty($post['name']) || empty($post['acreage']) || empty($post['budget']) || empty($post['opening_begin']) || empty($post['opening_end']) || empty($post['layout']) || empty($post['style']) || empty($post['stage']) || empty($post['pattern']) )
- return Apireturn::sent(0,'请填写完整信息',200);
- $str_opening_begin = strtotime($post['opening_begin']);
- $str_opening_end = strtotime($post['opening_end']);
- if($str_opening_begin > $str_opening_end)
- return Apireturn::sent(0,'可约时间不能大于结束时间',200);
- if(empty($post['designer_id']) || empty($post['manager_id']))
- return Apireturn::sent(0,'请选择设计师和项目经理',200);
- if(empty($post['province']) || empty($post['city']) || empty($post['district']) )
- return Apireturn::sent(0,'请选择地区',200);
- if(empty($post['address']))
- return Apireturn::sent(0,'请输入详细地址',200);
- if(empty($post['longitude']) || empty($post['latitude']))
- return Apireturn::sent(0,'缺少经纬度',200);
- $model = new Building();
- $model->uid = Yii::$app->user->id;
- $model->name = $post['name'];
- $model->type = Building::TYPE_SITE;
- $model->latitude = $post['latitude'];
- $model->longitude = $post['longitude'];
- if(!empty($model->longitude)&&!empty($model->latitude)) {
- $geohash = new ZM_Geohash();
- $geohash->init_codingMap();
- $model->hashcode = $geohash->encode($model->latitude, $model->longitude);
- }
- $model->stage = $post['stage'];
- $model->pattern = $post['pattern'];
- $model->province = $post['province'];
- $model->city = $post['city'];
- $model->district = $post['district'];
- $model->address = $post['address'];
- $model->created_at = time();
- $model->updated_at = time();
- $model->status = Building::STATUS_SUCCESS;
- $model->acreage = $post['acreage'];
- $model->budget = $post['budget'];
- $model->layout = $post['layout'];
- $model->style = $post['style'];
- $model->opening_begin =$str_opening_begin;
- $model->opening_end = $str_opening_end;
- $model->manager_id = $post['manager_id'];
- $model->designer_id = $post['designer_id'];
- $model->posted = Building::POSTED_YES;
- if($model->save())
- {
- $this->uploadBuildingImg($model->id,$post);
- return Apireturn::sent(1,'添加样板房成功',200);
- }else{
- return Apireturn::sent(0,'添加样板房失败',200);
- }
- }
- /**
- * 查看工地
- */
- public function actionCheckWork()
- {
- $id = Yii::$app->request->post('id');
- if(empty($id))
- return Apireturn::sent(0,'非法操作',200);
- $info = Building::find()->where(['id'=>$id,'uid'=>Yii::$app->user->id])->select("id,name,latitude,longitude,province,city,district,address,layout,stage,pattern,acreage,opening_begin,opening_end,budget,style,manager_id,designer_id")->one();
- if(empty($info))
- return Apireturn::sent(0,'找不到该工地',200);
- $arr = array();
- foreach ($info->getOldAttributes() as $key =>$value)
- {
- $arr[$key] = $value;
- }
- //设计师详情
- $data['designer'] = array();
- if(!empty($info->designer))
- {
- $arr['designer']['id'] = $info->designer->id;
- $arr['designer']['realname'] = $info->designer->realname;
- }
- //项目经理详情
- $data['manager'] = array();
- if(!empty($info->manager))
- {
- $arr['manager']['id'] = $info->manager->id;
- $arr['manager']['realname'] = $info->manager->realname;
- }
- $arr['living_room'] = $info->living ? $info->living->pic : "" ;
- $arr['master_bedroom'] = $info->master ? $info->master->pic : "" ;
- $arr['portion'] = $info->portion ? $info->portion->pic : "" ;
- $arr['build'] = $info->build ? $info->build->pic : "" ;
- $arr['build2'] = $info->build2 ? $info->build2->pic : "" ;
- $arr['flat'] = $info->flat ? $info->flat->pic : "" ;
- $arr['province_name'] = !empty($info->province) ? Area::queryCity($info->province) : "";
- $arr['city_name'] = !empty($info->city) ? Area::queryCity($info->city) : "";
- $arr['district_name'] = !empty($info->district) ? Area::queryCity($info->district) : "";
- return Apireturn::sent(1,'success',200,$arr);
- }
- /**
- * 工地详情
- */
- public function actionWorkInfo()
- {
- $id = Yii::$app->request->post('id');
- $model = Building::find()->where(['id'=>$id,'uid'=>Yii::$app->user->id,'type'=>Building::TYPE_SITE])->select('id,name,latitude,longitude,layout,budget,stage,style,acreage,pattern,address,opening_begin,opening_end,manager_id,designer_id,view')->one();
- if(empty($model))
- return Apireturn::sent(0,'找不到该工地',200);
- $data = array();
- foreach ($model->getOldAttributes() as $key => $value)
- {
- $data[$key] = $value;
- }
- /*公司名称
- $data['companyName'] = "";
- $userCompany = UserCompany::find()->select('company')->where(['uid'=>Yii::$app->user->id])->one();
- if(!empty($userCompany))
- $data['companyName'] = $userCompany->company;*/
- //户型图
- $data['flat']="";
- if(!empty($model->flat->pic))
- $data['flat'] = $model->flat->pic;
- //设计师详情
- $data['designer'] = array();
- if(!empty($model->designer))
- {
- $data['designer']['id'] = $model->designer->id;
- $data['designer']['pic'] = !empty($model->designer->image->pic) ? $model->designer->image->pic : "";
- $data['designer']['realname'] = $model->designer->realname;
- }
- //项目经理详情
- $data['manager'] = array();
- if(!empty($model->manager))
- {
- $data['manager']['id'] = $model->manager->id;
- $data['manager']['pic'] = !empty($model->manager->image->pic) ? $model->manager->image->pic : "";
- $data['manager']['realname'] = $model->manager->realname;
- }
- //轮播图列表
- $data['imgs'] = array();
- if(!empty($model->allimg))
- {
- foreach ($model->allimg as $img_val)
- {
- $data['imgs'][] = $img_val->pic;
- }
- }
- //预约人列表
- $data['appoints'] = array();
- if(!empty($model->appointment))
- {
- foreach ($model->appointment as $user)
- {
- $data['appoints'][] = !empty($user->user->userinfo->portrait) ? UserInfo::imagesUrl($user->user->userinfo->portrait):"";
- }
- }
- //所有评论
- $comment = Comment::find()->select("id,star,uid,content,created_at")->where('pid=:id and status = :status',[':id'=>$id,':status'=>Comment::STATUS_ACTIVE])->orderBy("created_at DESC")->all();
- $data['comments'] = array();
- if(!empty($comment))
- {
- foreach ($comment as $com_key => $com_val)
- {
- $data['comments'][$com_key]['id'] = $com_val->id;
- $data['comments'][$com_key]['star'] = $com_val->star;
- $data['comments'][$com_key]['content'] = $com_val->content;
- $data['comments'][$com_key]['created_at'] = Comment::time_tran($com_val->created_at);
- $data['comments'][$com_key]['imgs'] = ImageSource::find()->select('pic')->where(['topid'=>$com_val->id,'type'=>ImageSource::TYPE_COMMENT,'status'=>ImageSource::STATUS_YES])->asArray()->all();
- if(!empty($com_val->userinfo))
- {
- $data['comments'][$com_key]['portrait'] = !empty($com_val->userinfo->portrait) ? UserInfo::imagesUrl($com_val->userinfo->portrait):"";;
- $data['comments'][$com_key]['nickname'] = $com_val->userinfo->nickname;
- }
- $data['comments'][$com_key]['replys'] = array();
- $replys = Reply::find()->where(['cid'=>$com_val->id,'status'=>Reply::STATUS_ACTIVE])->select('id,from_userid,to_userid,content')->orderBy('created_at ASC')->all();
- if(!empty($replys))
- {
- foreach ($replys as $rep_key => $rep_val)
- {
- $data['comments'][$com_key]['replys'][$rep_key]['own'] = $rep_val->from_userid == Yii::$app->user->id ? 1 : 0 ;
- $data['comments'][$com_key]['replys'][$rep_key]['content'] = $rep_val->content;
- }
- }
- }
- }
- return Apireturn::sent(1,'success',200,$data);
- }
- /**
- * 编辑工地
- */
- public function actionEditWork()
- {
- $post = Yii::$app->request->post();
- if(empty($post['id']))
- return Apireturn::sent(0,'缺少id',200);
- $model = Building::find()->where(['id'=>$post['id'],'uid'=>Yii::$app->user->id])->one();
- if(empty($model))
- return Apireturn::sent(0,'找不到该样板房',200);
- if(empty($post['name']) || empty($post['acreage']) || empty($post['budget']) || empty($post['opening_begin']) || empty($post['opening_end']) || empty($post['layout']) || empty($post['style']) || empty($post['stage']) || empty($post['pattern']) )
- return Apireturn::sent(0,'请填写完整信息',200);
- $str_opening_begin = strtotime($post['opening_begin']);
- $str_opening_end = strtotime($post['opening_end']);
- if($str_opening_begin > $str_opening_end)
- return Apireturn::sent(0,'可约时间不能大于结束时间',200);
- if(empty($post['designer_id']) || empty($post['manager_id']))
- return Apireturn::sent(0,'请选择设计师和项目经理',200);
- if(empty($post['province']) || empty($post['city']) || empty($post['district']) )
- return Apireturn::sent(0,'请选择地区',200);
- if(empty($post['address']))
- return Apireturn::sent(0,'请输入详细地址',200);
- if(empty($post['longitude']) || empty($post['latitude']))
- return Apireturn::sent(0,'缺少经纬度',200);
- $model->name = $post['name'];
- $model->latitude = $post['latitude'];
- $model->longitude = $post['longitude'];
- if(!empty($model->longitude)&&!empty($model->latitude)) {
- $geohash = new ZM_Geohash();
- $geohash->init_codingMap();
- $model->hashcode = $geohash->encode($model->latitude, $model->longitude);
- }
- $model->stage = $post['stage'];
- $model->pattern = $post['pattern'];
- $model->province = $post['province'];
- $model->city = $post['city'];
- $model->district = $post['district'];
- $model->address = $post['address'];
- $model->updated_at = time();
- $model->acreage = $post['acreage'];
- $model->budget = $post['budget'];
- $model->layout = $post['layout'];
- $model->style = $post['style'];
- $model->opening_begin =$str_opening_begin;
- $model->opening_end = $str_opening_end;
- $model->manager_id = $post['manager_id'];
- $model->designer_id = $post['designer_id'];
- if($model->save())
- {
- $this->uploadBuildingImg($model->id,$post,'edit');
- return Apireturn::sent(1,'修改成功',200);
- }else{
- return Apireturn::sent(0,'修改失败',200);
- }
- }
- /**
- * 更改样板房/工地发布状态
- */
- public function actionUpdatePosted()
- {
- $post = Yii::$app->request->post();
- if(empty($post['id']))
- return Apireturn::sent(0,'非法操作');
- $model = Building::find()->where(['id'=>$post['id'],'uid'=>Yii::$app->user->id])->one();
- if(empty($model))
- return Apireturn::sent(0,'找不到记录');
- if(!in_array($post['posted'],array(Building::POSTED_YES,Building::POSTED_NO)))
- return Apireturn::sent(0,'参数错误');
- $posted = $post['posted'];
- $model->posted = $posted;
- if($model->save())
- return Apireturn::sent(1,'操作成功');
- else
- return Apireturn::sent(0,'操作失败');
- }
- /**
- * 获取设计师
- */
- public function actionDesigner()
- {
- $list = Designer::find()->where(['company'=>Yii::$app->user->id,'status'=>Designer::STATUS_YES])->select('id,realname,introduction')->orderBy('id DESC')->all();
- $arr =array();
- if(!empty($list)){
- foreach ($list as $value)
- {
- $arr[] = array('id'=>$value->id,'realname'=>$value->realname,'introduction'=>$value->introduction,'pic'=>$value->image?$value->image->pic:"");
- }
- }
- return Apireturn::sent(1,'success',200,$arr);
- }
- /**
- * 获取项目经理
- */
- public function actionManager()
- {
- $list = Manager::find()->where(['company'=>Yii::$app->user->id,'status'=>Manager::STATUS_YES])->select('id,realname,introduction')->orderBy('id DESC')->all();
- $arr =array();
- if(!empty($list)){
- foreach ($list as $value)
- {
- $arr[] = array('id'=>$value->id,'realname'=>$value->realname,'introduction'=>$value->introduction,'pic'=>$value->image?$value->image->pic:"");
- }
- }
- return Apireturn::sent(1,'success',200,$arr);
- }
- /**
- * 我的工地列表
- */
- public function actionWorkList()
- {
- $page = Yii::$app->request->POST('page', 1);//分页页数
- $display = Yii::$app->request->POST('display', self::DISPLAY);//分页页数
- $list = Building::findBySql("SELECT id,name,layout,acreage,style,designer_id,posted FROM {{%building}} WHERE uid = :uid AND type = :type AND (posted = :posted OR posted = :posted2) ORDER BY id DESC limit " . ($page - 1) * $display . "," . $display,[':uid'=>Yii::$app->user->id,':posted'=>Building::POSTED_YES,':posted2'=>Building::POSTED_NO,':type'=>Building::TYPE_SITE])->all();
- $count = Building::find()->where('uid = :uid AND type = :type AND (posted = :posted OR posted = :posted2)',[':uid'=>Yii::$app->user->id,':posted'=>Building::POSTED_YES,':posted2'=>Building::POSTED_NO,':type'=>Building::TYPE_SITE])->count();
- $arr = array();
- if(!empty($list)){
- foreach ($list as $key => $value)
- {
- foreach ($value->getOldAttributes() as $key2 =>$value2)
- {
- $arr[$key][$key2] = $value2;
- }
- $arr[$key]['design_name'] = $value->designer?$value->designer->realname:"";
- $arr[$key]['pic'] = $value->all?$value->all->pic:"";
- }
- }
- return Apireturn::sent(1,'success',200,array('count'=>$count,'list'=>$arr));
- }
- /**
- * 我的样板房列表
- */
- public function actionRoomList()
- {
- $page = Yii::$app->request->POST('page', 1);//分页页数
- $display = Yii::$app->request->POST('display', self::DISPLAY);//分页页数
- $list = Building::findBySql("SELECT id,name,layout,acreage,style,designer_id,posted FROM {{%building}} WHERE uid = :uid AND type = :type AND (posted = :posted OR posted = :posted2) ORDER BY id DESC limit " . ($page - 1) * $display . "," . $display,[':uid'=>Yii::$app->user->id,':posted'=>Building::POSTED_YES,':posted2'=>Building::POSTED_NO,':type'=>Building::TYPE_HOUSE])->all();
- $count = Building::find()->where('uid = :uid AND type = :type AND (posted = :posted OR posted = :posted2)',[':uid'=>Yii::$app->user->id,':posted'=>Building::POSTED_YES,':posted2'=>Building::POSTED_NO,':type'=>Building::TYPE_HOUSE])->count();
- $arr = array();
- if(!empty($list)){
- foreach ($list as $key => $value)
- {
- foreach ($value->getOldAttributes() as $key2 =>$value2)
- {
- $arr[$key][$key2] = $value2;
- }
- $arr[$key]['design_name'] = $value->designer?$value->designer->realname:"";
- $arr[$key]['pic'] = $value->all?$value->all->pic:"";
- }
- }
- return Apireturn::sent(1,'success',200,array('count'=>$count,'list'=>$arr));
- }
- /**
- * 样板房详情
- */
- public function actionRoomInfo()
- {
- $id = Yii::$app->request->post('id');
- $model = Building::find()->where(['id'=>$id,'uid'=>Yii::$app->user->id,'type'=>Building::TYPE_HOUSE])->select('id,name,latitude,longitude,layout,budget,style,acreage,address,opening_begin,opening_end,manager_id,designer_id,view')->one();
- if(empty($model))
- return Apireturn::sent(0,'找不到该工地',200);
- $data = array();
- foreach ($model->getOldAttributes() as $key => $value)
- {
- $data[$key] = $value;
- }
- /*公司名称
- $data['companyName'] = "";
- $userCompany = UserCompany::find()->select('company')->where(['uid'=>Yii::$app->user->id])->one();
- if(!empty($userCompany))
- $data['companyName'] = $userCompany->company;*/
- //户型图
- $data['flat']="";
- if(!empty($model->flat->pic))
- $data['flat'] = $model->flat->pic;
- //设计师详情
- $data['designer'] = array();
- if(!empty($model->designer))
- {
- $data['designer']['id'] = $model->designer->id;
- $data['designer']['pic'] = !empty($model->designer->image->pic) ? $model->designer->image->pic : "";
- $data['designer']['realname'] = $model->designer->realname;
- }
- //项目经理详情
- $data['manager'] = array();
- if(!empty($model->manager))
- {
- $data['manager']['id'] = $model->manager->id;
- $data['manager']['pic'] = !empty($model->manager->image->pic) ? $model->manager->image->pic : "";
- $data['manager']['realname'] = $model->manager->realname;
- }
- //轮播图列表
- $data['imgs'] = array();
- if(!empty($model->allimg))
- {
- foreach ($model->allimg as $img_val)
- {
- $data['imgs'][] = $img_val->pic;
- }
- }
- //预约人列表
- $data['appoints'] = array();
- if(!empty($model->appointment))
- {
- foreach ($model->appointment as $user)
- {
- $data['appoints'][] = !empty($user->user->userinfo->portrait) ? UserInfo::imagesUrl($user->user->userinfo->portrait):"";
- }
- }
- //所有评论
- $comment = Comment::find()->select("id,star,uid,content,created_at")->where('pid=:id and status = :status',[':id'=>$id,':status'=>Comment::STATUS_ACTIVE])->orderBy("created_at DESC")->all();
- $data['comments'] = array();
- if(!empty($comment))
- {
- foreach ($comment as $com_key => $com_val)
- {
- $data['comments'][$com_key]['id'] = $com_val->id;
- $data['comments'][$com_key]['star'] = $com_val->star;
- $data['comments'][$com_key]['content'] = $com_val->content;
- $data['comments'][$com_key]['created_at'] = Comment::time_tran($com_val->created_at);
- $data['comments'][$com_key]['imgs'] = ImageSource::find()->select('pic')->where(['topid'=>$com_val->id,'type'=>ImageSource::TYPE_COMMENT,'status'=>ImageSource::STATUS_YES])->asArray()->all();
- if(!empty($com_val->userinfo))
- {
- $data['comments'][$com_key]['portrait'] =!empty($com_val->userinfo->portrait) ? UserInfo::imagesUrl($com_val->userinfo->portrait):"";;
- $data['comments'][$com_key]['nickname'] = $com_val->userinfo->nickname;
- }
- $data['comments'][$com_key]['replys'] = array();
- $replys = Reply::find()->where(['cid'=>$com_val->id,'status'=>Reply::STATUS_ACTIVE])->select('id,from_userid,to_userid,content')->orderBy('created_at ASC')->all();
- if(!empty($replys))
- {
- foreach ($replys as $rep_key => $rep_val)
- {
- $data['comments'][$com_key]['replys'][$rep_key]['own'] = $rep_val->from_userid == Yii::$app->user->id ? 1 : 0 ;
- $data['comments'][$com_key]['replys'][$rep_key]['content'] = $rep_val->content;
- }
- }
- }
- }
- return Apireturn::sent(1,'success',200,$data);
- }
- /**
- * 添加更新工地图片
- */
- public function uploadBuildingImg($id,$post,$type = 'add')
- {
- //客厅照片,开工大吉
- if(!empty($post['living_room']))
- {
- if($type != 'add'){//编辑
- $model = ImageSource::find()->where(['topid'=>$id,'status'=>ImageSource::STATUS_YES,'type'=>ImageSource::TYPE_LIVING_ROOM])->one();
- if(empty($model))
- {
- $model = new ImageSource();
- $model->topid = $id;
- $model->created_at = time();
- $model->status = ImageSource::STATUS_YES;
- $model->type = ImageSource::TYPE_LIVING_ROOM;
- }
- }else{//添加
- $model = new ImageSource();
- $model->topid = $id;
- $model->created_at = time();
- $model->status = ImageSource::STATUS_YES;
- $model->type = ImageSource::TYPE_LIVING_ROOM;
- }
- $model->pic = $post['living_room'];
- $model->updated_at = time();
- $model->save();
- unset($model);
- }elseif (empty($post['living_room']) && $type == 'edit')
- {
- $model = ImageSource::find()->where(['topid'=>$id,'status'=>ImageSource::STATUS_YES,'type'=>ImageSource::TYPE_LIVING_ROOM])->one();
- if(!empty($model))
- {
- $model->status = ImageSource::STATUS_NO;
- $model->updated_at = time();
- $model->save();
- }
- }
- //主卧照片,现场施工
- if(!empty($post['master_bedroom']))
- {
- if($type != 'add'){//编辑
- $model = ImageSource::find()->where(['topid'=>$id,'status'=>ImageSource::STATUS_YES,'type'=>ImageSource::TYPE_MASTER_BEDROOM])->one();
- if(empty($model))
- {
- $model = new ImageSource();
- $model->topid = $id;
- $model->created_at = time();
- $model->status = ImageSource::STATUS_YES;
- $model->type = ImageSource::TYPE_MASTER_BEDROOM;
- }
- }else{//添加
- $model = new ImageSource();
- $model->topid = $id;
- $model->created_at = time();
- $model->status = ImageSource::STATUS_YES;
- $model->type = ImageSource::TYPE_MASTER_BEDROOM;
- }
- $model->pic = $post['master_bedroom'];
- $model->updated_at = time();
- $model->save();
- unset($model);
- }elseif (empty($post['master_bedroom']) && $type == 'edit')
- {
- $model = ImageSource::find()->where(['topid'=>$id,'status'=>ImageSource::STATUS_YES,'type'=>ImageSource::TYPE_MASTER_BEDROOM])->one();
- if(!empty($model))
- {
- $model->status = ImageSource::STATUS_NO;
- $model->updated_at = time();
- $model->save();
- }
- }
- //局部美照,现场施工
- if(!empty($post['portion']))
- {
- if($type != 'add'){//编辑
- $model = ImageSource::find()->where(['topid'=>$id,'status'=>ImageSource::STATUS_YES,'type'=>ImageSource::TYPE_PORTION])->one();
- if(empty($model))
- {
- $model = new ImageSource();
- $model->topid = $id;
- $model->created_at = time();
- $model->status = ImageSource::STATUS_YES;
- $model->type = ImageSource::TYPE_PORTION;
- }
- }else{//添加
- $model = new ImageSource();
- $model->topid = $id;
- $model->created_at = time();
- $model->status = ImageSource::STATUS_YES;
- $model->type = ImageSource::TYPE_PORTION;
- }
- $model->pic = $post['portion'];
- $model->updated_at = time();
- $model->save();
- unset($model);
- }elseif (empty($post['portion']) && $type == 'edit')
- {
- $model = ImageSource::find()->where(['topid'=>$id,'status'=>ImageSource::STATUS_YES,'type'=>ImageSource::TYPE_PORTION])->one();
- if(!empty($model))
- {
- $model->status = ImageSource::STATUS_NO;
- $model->updated_at = time();
- $model->save();
- }
- }
- //现场施工照片2
- if(!empty($post['build']))
- {
- if($type != 'add'){//编辑
- $model = ImageSource::find()->where(['topid'=>$id,'status'=>ImageSource::STATUS_YES,'type'=>ImageSource::TYPE_BUILD])->one();
- if(empty($model))
- {
- $model = new ImageSource();
- $model->topid = $id;
- $model->created_at = time();
- $model->status = ImageSource::STATUS_YES;
- $model->type = ImageSource::TYPE_BUILD;
- }
- }else{//添加
- $model = new ImageSource();
- $model->topid = $id;
- $model->created_at = time();
- $model->status = ImageSource::STATUS_YES;
- $model->type = ImageSource::TYPE_BUILD;
- }
- $model->pic = $post['build'];
- $model->updated_at = time();
- $model->save();
- unset($model);
- }elseif (empty($post['build']) && $type == 'edit')
- {
- $model = ImageSource::find()->where(['topid'=>$id,'status'=>ImageSource::STATUS_YES,'type'=>ImageSource::TYPE_BUILD])->one();
- if(!empty($model))
- {
- $model->status = ImageSource::STATUS_NO;
- $model->updated_at = time();
- $model->save();
- }
- }
- //现场施工照片3
- if(!empty($post['build2']))
- {
- if($type != 'add'){//编辑
- $model = ImageSource::find()->where(['topid'=>$id,'status'=>ImageSource::STATUS_YES,'type'=>ImageSource::TYPE_BUILD2])->one();
- if(empty($model))
- {
- $model = new ImageSource();
- $model->topid = $id;
- $model->created_at = time();
- $model->status = ImageSource::STATUS_YES;
- $model->type = ImageSource::TYPE_BUILD2;
- }
- }else{//添加
- $model = new ImageSource();
- $model->topid = $id;
- $model->created_at = time();
- $model->status = ImageSource::STATUS_YES;
- $model->type = ImageSource::TYPE_BUILD2;
- }
- $model->pic = $post['build2'];
- $model->updated_at = time();
- $model->save();
- unset($model);
- }elseif (empty($post['build2']) && $type == 'edit')
- {
- $model = ImageSource::find()->where(['topid'=>$id,'status'=>ImageSource::STATUS_YES,'type'=>ImageSource::TYPE_BUILD2])->one();
- if(!empty($model))
- {
- $model->status = ImageSource::STATUS_NO;
- $model->updated_at = time();
- $model->save();
- }
- }
- //局部美照2
- if(!empty($post['portion2']))
- {
- if($type != 'add'){//编辑
- $model = ImageSource::find()->where(['topid'=>$id,'status'=>ImageSource::STATUS_YES,'type'=>ImageSource::TYPE_PORTION2])->one();
- if(empty($model))
- {
- $model = new ImageSource();
- $model->topid = $id;
- $model->created_at = time();
- $model->status = ImageSource::STATUS_YES;
- $model->type = ImageSource::TYPE_PORTION2;
- }
- }else{//添加
- $model = new ImageSource();
- $model->topid = $id;
- $model->created_at = time();
- $model->status = ImageSource::STATUS_YES;
- $model->type = ImageSource::TYPE_PORTION2;
- }
- $model->pic = $post['portion2'];
- $model->updated_at = time();
- $model->save();
- unset($model);
- }elseif (empty($post['portion2']) && $type == 'edit')
- {
- $model = ImageSource::find()->where(['topid'=>$id,'status'=>ImageSource::STATUS_YES,'type'=>ImageSource::TYPE_PORTION2])->one();
- if(!empty($model))
- {
- $model->status = ImageSource::STATUS_NO;
- $model->updated_at = time();
- $model->save();
- }
- }
- //局部美照3
- if(!empty($post['portion3']))
- {
- if($type != 'add'){//编辑
- $model = ImageSource::find()->where(['topid'=>$id,'status'=>ImageSource::STATUS_YES,'type'=>ImageSource::TYPE_PORTION3])->one();
- if(empty($model))
- {
- $model = new ImageSource();
- $model->topid = $id;
- $model->created_at = time();
- $model->status = ImageSource::STATUS_YES;
- $model->type = ImageSource::TYPE_PORTION3;
- }
- }else{//添加
- $model = new ImageSource();
- $model->topid = $id;
- $model->created_at = time();
- $model->status = ImageSource::STATUS_YES;
- $model->type = ImageSource::TYPE_PORTION3;
- }
- $model->pic = $post['portion3'];
- $model->updated_at = time();
- $model->save();
- unset($model);
- }elseif (empty($post['portion3']) && $type == 'edit')
- {
- $model = ImageSource::find()->where(['topid'=>$id,'status'=>ImageSource::STATUS_YES,'type'=>ImageSource::TYPE_PORTION3])->one();
- if(!empty($model))
- {
- $model->status = ImageSource::STATUS_NO;
- $model->updated_at = time();
- $model->save();
- }
- }
- //局部美照4
- if(!empty($post['portion4']))
- {
- if($type != 'add'){//编辑
- $model = ImageSource::find()->where(['topid'=>$id,'status'=>ImageSource::STATUS_YES,'type'=>ImageSource::TYPE_PORTION4])->one();
- if(empty($model))
- {
- $model = new ImageSource();
- $model->topid = $id;
- $model->created_at = time();
- $model->status = ImageSource::STATUS_YES;
- $model->type = ImageSource::TYPE_PORTION4;
- }
- }else{//添加
- $model = new ImageSource();
- $model->topid = $id;
- $model->created_at = time();
- $model->status = ImageSource::STATUS_YES;
- $model->type = ImageSource::TYPE_PORTION4;
- }
- $model->pic = $post['portion4'];
- $model->updated_at = time();
- $model->save();
- unset($model);
- }elseif (empty($post['portion4']) && $type == 'edit')
- {
- $model = ImageSource::find()->where(['topid'=>$id,'status'=>ImageSource::STATUS_YES,'type'=>ImageSource::TYPE_PORTION4])->one();
- if(!empty($model))
- {
- $model->status = ImageSource::STATUS_NO;
- $model->updated_at = time();
- $model->save();
- }
- }
- //局部美照5
- if(!empty($post['portion5']))
- {
- if($type != 'add'){//编辑
- $model = ImageSource::find()->where(['topid'=>$id,'status'=>ImageSource::STATUS_YES,'type'=>ImageSource::TYPE_PORTION5])->one();
- if(empty($model))
- {
- $model = new ImageSource();
- $model->topid = $id;
- $model->created_at = time();
- $model->status = ImageSource::STATUS_YES;
- $model->type = ImageSource::TYPE_PORTION5;
- }
- }else{//添加
- $model = new ImageSource();
- $model->topid = $id;
- $model->created_at = time();
- $model->status = ImageSource::STATUS_YES;
- $model->type = ImageSource::TYPE_PORTION5;
- }
- $model->pic = $post['portion5'];
- $model->updated_at = time();
- $model->save();
- unset($model);
- }elseif (empty($post['portion5']) && $type == 'edit')
- {
- $model = ImageSource::find()->where(['topid'=>$id,'status'=>ImageSource::STATUS_YES,'type'=>ImageSource::TYPE_PORTION5])->one();
- if(!empty($model))
- {
- $model->status = ImageSource::STATUS_NO;
- $model->updated_at = time();
- $model->save();
- }
- }
- //户型平面图
- if(!empty($post['flat']))
- {
- if($type != 'add'){//编辑
- $model = ImageSource::find()->where(['topid'=>$id,'status'=>ImageSource::STATUS_YES,'type'=>ImageSource::TYPE_FLAT])->one();
- if(empty($model))
- {
- $model = new ImageSource();
- $model->topid = $id;
- $model->created_at = time();
- $model->status = ImageSource::STATUS_YES;
- $model->type = ImageSource::TYPE_FLAT;
- }
- }else{//添加
- $model = new ImageSource();
- $model->topid = $id;
- $model->created_at = time();
- $model->status = ImageSource::STATUS_YES;
- $model->type = ImageSource::TYPE_FLAT;
- }
- $model->pic = $post['flat'];
- $model->updated_at = time();
- $model->save();
- unset($model);
- }elseif (empty($post['flat']) && $type == 'edit')
- {
- $model = ImageSource::find()->where(['topid'=>$id,'status'=>ImageSource::STATUS_YES,'type'=>ImageSource::TYPE_FLAT])->one();
- if(!empty($model))
- {
- $model->status = ImageSource::STATUS_NO;
- $model->updated_at = time();
- $model->save();
- }
- }
- }
- /**
- * 工地/样板房预约列表
- */
- public function actionAppointments()
- {
- $page = Yii::$app->request->post('page', 1);//分页页数
- $display = Yii::$app->request->post('display', self::DISPLAY);//分页页数
- $id = Yii::$app->request->post('id');//工地,样板房id
- $list = Appointment::findBySql("SELECT a.applicant_name,a.applicant_tel,a.state,a.booking_time,b.portrait FROM {{%appointment}} a LEFT JOIN {{%user_info}} b ON a.uid = b.uid WHERE a.pid = :id AND a.status = :status ORDER BY a.id DESC LIMIT ".($page-1) * $display.",".$display,[':id'=>$id,':status'=>Appointment::STATE_YES])->asArray()->all();
- if(!empty($list))
- {
- foreach ($list as $key => $value)
- {
- $list[$key]['portrait'] = empty($value['portrait']) ? "":UserInfo::imagesUrl($value['portrait']);
- //$list[$key]['applicant_tel'] = empty($value['applicant_tel']) ? "":Appointment::telPreg($value['applicant_tel']);
- $building = Building::find()->where(['id'=>$id])->select('name')->one();
- if(!empty($building))
- $list[$key]['name'] = $building->name;
- else
- $list[$key]['name'] = "";
- }
- }
- $userCompany = UserCompany::find()->where(['uid'=>Yii::$app->user->id])->select('member')->one();
- $member = 0;
- if(!empty($userCompany))
- $member = $userCompany->member;
- return Apireturn::sent(1,'success',200,array('member'=>$member,'list'=>$list));
- }
- /**
- * 装修进度,户型,装修方式,装修风格
- * @return array
- */
- public function actionData()
- {
- $array = array('stage'=>self::$stage_arr,'layout'=>self::$layout_arr,'style'=>self::$style_arr,'pattern'=>self::$pattern_arr);
- return Apireturn::sent(1,'success',200,$array);
- }
- }
|