[ 'class' => AccessControl::className(), 'rules' => [ [ 'actions' => [], 'allow' => true, 'roles' => ['@'], ], ], ], ]; } //用户等级 public static function userlevel(){ if(!empty(Yii::$app->user->id)){ $model = UserCompany::find()->where('uid=:uid',[':uid'=>Yii::$app->user->id])->one(); if(!empty($model)){ $member = $model->member; return $member; } return "数据不对"; } return "未登录"; } //我的首页 public function actionIndividual(){ $model = UserCompany::find()->where('uid=:uid',[':uid'=>Yii::$app->user->id])->one(); return $this->render('individual',['model'=>$model]); } //我的基础资料 public function actionBasics(){ if(Yii::$app->request->get()){ $id = Yii::$app->request->get('id'); $company = Yii::$app->request->get('company'); $tel = Yii::$app->request->get('tel'); $address = Yii::$app->request->get('address'); $submit_address = Yii::$app->request->get('submit_address'); if(!empty($submit_address)){ $arr_address = explode(',',$submit_address); $province = $arr_address[0];//省 $city = $arr_address[1];//城市 $district = $arr_address[2];//地区 } $model = UserCompany::find()->where('id=:id',[':id'=>$id])->one(); $model->province = !empty($province)?$province:$model->province; $model->company = !empty($company)?$company:$model->company; $model->tel = !empty($tel)?$tel:$model->tel; $model->city = !empty($city)?$city:$model->city; $model->district = !empty($district)?$district:$model->district; $model->address = !empty($address)?$address:$model->address; $model->updated_at = time(); if($model->validate()&&$model->save()){ $result=['sign'=>1,'msg'=>'修改成功']; }else{ $result=['sign'=>4000,'msg'=>'修改失败']; } return json_encode($result); }else{ $model = UserCompany::find()->where('uid=:uid',[':uid'=>Yii::$app->user->id])->one(); return $this->render('basics', [ 'model'=>$model ]); } } //logo public function actionImg(){ $serverid = Yii::$app->request->get('serverid'); $result=['sign'=>4000,'msg'=>'参数有误']; $id = Yii::$app->request->get('id'); $results = LMUploadFile::wechatUploaImage($serverid,'logo',false,200,200); if(!empty($id)){ $model = UserCompany::find()->where('id=:id',[':id'=>$id])->one(); if(!empty($results['remote'])){ $model->logo = !empty($results['remote'])?$results['remote']:""; $model->updated_at = time(); if($model->validate()&&$model->save()){ }else{ $result=['sign'=>4000,'msg'=>'保存失败','imgurl'=>$results['remote']]; } } } if(!empty($results)){ $result=['sign'=>1,'msg'=>'保存成功','imgurl'=>$results['remote']]; } return json_encode($result); } public function actionIndex(){ $model = UserCompany::find()->where('uid=:uid',[':uid'=>Yii::$app->user->id])->one(); $conduct = Yii::$app->request->post('conduct'); $id = Yii::$app->request->post('id'); $picture_form = new LMUploadFile(); switch($conduct){ case "add": return companyuser::add_company(); break; case "update": return companyuser::update_company($id); break; case "verify": return companyuser::verify_company(); break; default: return $this->render('index',['model'=>$model,'picture_form'=>$picture_form]); break; } } //人员管理列表 public function actionPersonnel(){ //设计师 $models_designer = Designer::find()->where('company=:company and status=:status',[':company'=>Yii::$app->user->id,':status'=>Designer::STATUS_YES])->orderBy('created_at DESC')->all(); //项目经理 $models_manager = Manager::find()->where('company=:company and status=:status',[':company'=>Yii::$app->user->id,':status'=>Designer::STATUS_YES])->orderBy('created_at DESC')->all(); return $this->render('personnel', [ 'models_designer'=>$models_designer, 'models_manager'=>$models_manager, ]); } //删除设计师 项目经理 public function actionDelete(){ $id = Yii::$app->request->get('id'); $type = Yii::$app->request->get('type'); if($type == "designer"){ return companyuser::delede_designer($id); }elseif($type == "manager"){ return companyuser::delede_manager($id); }else{ $result=['sign'=>4000,'msg'=>'数据有误'.$id.$type]; return json_encode($result); } } //更新设计师、项目经理 public function actionUpdate(){ $type = Yii::$app->request->get('type'); $id = Yii::$app->request->get('id'); $realname = Yii::$app->request->get('realname'); $introduction = Yii::$app->request->get('introduction'); $imageurl = Yii::$app->request->get('imageurl'); if(!empty($imageurl)){ $imageurl = $this->imgurl($imageurl); } if(!empty($realname)){; if($type == "designer"){ $model = Designer::find()->where('id=:id and status=:status',[':id'=>$id,':status'=>Designer::STATUS_YES])->one(); $image_model = ImageSource::find()->where('topid=:topid and status=:status and type=:type ',[':type'=>ImageSource::TYPE_DESIGNER,':topid'=>$model->id,':status'=>ImageSource::STATUS_YES])->one(); $model->realname = $realname; $model->introduction = $introduction; $model->update_at = time(); if(!empty($image_model)){ $image_model->pic = isset($imageurl)?$imageurl:""; $image_model->updated_at = time(); }else{ $image_model = new ImageSource(); $image_model->pic = isset($imageurl)?$imageurl:""; $image_model->updated_at = time(); $image_model->created_at = time(); $image_model->status = 10; $image_model->type = ImageSource::TYPE_DESIGNER; $image_model->topid = $model->id; } if($model->validate()&&$model->save()){ if(!empty($imageurl)){ if($image_model->validate()&&$image_model->save()){ $result=['sign'=>1,'msg'=>'更新成功']; }else{ $result=['sign'=>4000,'msg'=>'图片更新失败']; } }else{ $result=['sign'=>1,'msg'=>'更新成功']; } }else{ $result=['sign'=>4000,'msg'=>'数据有误']; } return json_encode($result); }elseif($type == "manager"){ $model = Manager::find()->where('id=:id and status=:status',[':id'=>$id,':status'=>Manager::STATUS_YES])->one(); $image_model = ImageSource::find()->where('topid=:topid and status=:status and type=:type ',[':type'=>ImageSource::TYPE_MANAGER,':topid'=>$model->id,':status'=>ImageSource::STATUS_YES])->one(); $model->realname = $realname; $model->introduction = $introduction; $model->updated_at = time(); if(!empty($image_model)){ $image_model->pic = isset($imageurl)?$imageurl:""; $image_model->updated_at = time(); }else{ $image_model = new ImageSource(); $image_model->pic = isset($imageurl)?$imageurl:""; $image_model->updated_at = time(); $image_model->created_at = time(); $image_model->status = 10; $image_model->type = ImageSource::TYPE_MANAGER; $image_model->topid = $model->id; } if($model->validate()&&$model->save()){ if(!empty($imageurl)) { if ($image_model->validate() && $image_model->save()) { $result = ['sign' => 1, 'msg' => '更新成功']; } else { $result = ['sign' => 4000, 'msg' => '图片更新失败']; } }else{ $result = ['sign' => 1, 'msg' => '更新成功']; } }else{ $result=['sign'=>4000,'msg'=>'数据有误']; } return json_encode($result); } }else{ if($type == "designer"){ $model = Designer::find()->where('id=:id and status=:status',[':id'=>$id,':status'=>Designer::STATUS_YES])->one(); }elseif($type == "manager"){ $model = Manager::find()->where('id=:id and status=:status',[':id'=>$id,':status'=>Manager::STATUS_YES])->one(); } return $this->render('update',['model'=>$model,'id'=>$id,'type'=>$type]); } } //添加设计师、项目经理 public function actionAdd(){ $type = Yii::$app->request->get('type'); if(!empty($type)){ $imageurl = Yii::$app->request->get('imageurl'); if(!empty($imageurl)){ $imageurl = $this->imgurl($imageurl); } $realname = Yii::$app->request->get('realname'); $introduction= Yii::$app->request->get('introduction'); if($type == "designer"){ $model = new Designer(); $image_model = new ImageSource(); $model->realname = $realname; $model->introduction = $introduction; $model->company = Yii::$app->user->id; $model->created_at = time(); $model->status = Designer::STATUS_YES; $model->update_at = time(); $image_model->type = ImageSource::TYPE_DESIGNER; $image_model->pic = $imageurl; $image_model->status = ImageSource::STATUS_YES; $image_model->created_at = time(); $image_model->updated_at = time(); if($model->validate()&&$model->save()){ $image_model->topid = $model->id; if($image_model->validate()&&$image_model->save()){ $result=['sign'=>1,'msg'=>'添加成功']; }else{ $result=['sign'=>4000,'msg'=>'图片添加失败']; } }else{ $result=['sign'=>4000,'msg'=>'数据添加失败']; } return json_encode($result); }elseif($type == "manager"){ $model = new Manager(); $image_model = new ImageSource(); $model->realname = $realname; $model->introduction = $introduction; $model->company = Yii::$app->user->id; $model->created_at = time(); $model->status = Manager::STATUS_YES; $model->updated_at = time(); $image_model->type = ImageSource::TYPE_MANAGER; $image_model->pic = $imageurl; $image_model->status = ImageSource::STATUS_YES; $image_model->created_at = time(); $image_model->updated_at = time(); if($model->validate()&&$model->save()){ $image_model->topid = $model->id; if($image_model->validate()&&$image_model->save()){ $result=['sign'=>1,'msg'=>'添加成功']; }else{ $result=['sign'=>4000,'msg'=>'图片添加失败']; } }else{ $result=['sign'=>4000,'msg'=>'数据添加失败']; } return json_encode($result); } $result=['sign'=>1,'msg'=>'更新成功']; return json_encode($result); }else{ return $this->render('add'); } } /** * 头像 * @return string */ public function imgurl($imageurl) { $results = LMUploadFile::wechatUploaImage($imageurl,'head',false,200,200); return $results['remote']; } //预约管理 public function actionSubscribe(){ $models = Appointment::find() ->joinWith('building')->where('bd_building.uid=:userid',[':userid'=>Yii::$app->user->id]); $pages = $models->count(); $pages = ceil($pages/self::PAGESIZE); $models = $models->orderBy('bd_appointment.created_at desc')->limit(self::PAGESIZE)->all(); return $this->render('subscribe',['models'=>$models,'pages'=>$pages]); } //预约管理分页 public function actionSubscribepage(){ $page = Yii::$app->request->post('page'); $models = Appointment::find() ->joinWith('building')->where('bd_building.uid=:userid',[':userid'=>Yii::$app->user->id]); $models = $models->orderBy('bd_appointment.created_at desc')->offset($page*self::PAGESIZE)->limit(self::PAGESIZE)->all(); return $this->renderPartial('subscribepage',['models'=>$models]); } //评价管理 public function actionEvaluate(){ $models = Comment::find()->joinWith('houseinfo')->where('bd_building.uid=:uid',[':uid'=>Yii::$app->user->id]); $pages = $models->count(); $pages = ceil($pages/self::PAGESIZE); $models = $models->orderBy('created_at desc')->limit(self::PAGESIZE)->all(); return $this->render('evaluate',['models'=>$models,'pages'=>$pages]); } //评价管理分页 public function actionEvaluatepage(){ $page = Yii::$app->request->post('page'); $models = Comment::find()->joinWith('houseinfo')->where('bd_building.uid=:uid',[':uid'=>Yii::$app->user->id]); $models = $models->orderBy('created_at desc')->offset($page*self::PAGESIZE)->limit(self::PAGESIZE)->all(); return $this->renderPartial('evaluatepage',['models'=>$models]); } //回复评价 public function actionReply(){ $comment_id = Yii::$app->request->get('comment_id'); $user_id = Yii::$app->request->get('user_id'); $content = Yii::$app->request->get('content'); $model = new Reply(); $model->cid = $comment_id; $model->from_userid = Yii::$app->user->id; $model->to_userid = $user_id; $model->content = $content; $model->created_at = time(); $model->status = Reply::STATUS_ACTIVE; if($model->validate()&&$model->save()){ $result=['sign'=>1,'msg'=>'回复成功']; }else{ $result=['sign'=>4000,'msg'=>'参数有误']; } return json_encode($result); } //我的设置 public function actionSetting(){ return $this->render('setting'); } //意见、建议反馈 public function actionFeedback(){ $content = Yii::$app->request->get('content');//内容 $contact = Yii::$app->request->get('contact');//联系方式 if(!empty($content)){ $model = new Feedback(); $model->uid = Yii::$app->user->id; $model->contact = $contact; $model->content = isset($content)?$content:""; $model->created_at = time(); $model->updated_at = time(); $model->status = Feedback::STATUS_ACTIVE; $model->state = Feedback::STATE_WAIT; $model->type = Feedback::TYPE_COMPANY; if($model->validate()&&$model->save()){ $result=['sign'=>1,'msg'=>'提交成功']; }else{ $result=['sign'=>4000,'msg'=>'提交失败']; } return json_encode($result); }else{ return $this->render('feedback'); } } //添加手机 public function actionMessage(){ $tel = Yii::$app->request->get('tel'); $models = Tel::find()->where('uid=:uid and status=:status',[':uid'=>Yii::$app->user->id,':status'=>Tel::STATUS_ACTIVE])->all(); if(!empty($tel)){ $model = new Tel(); $model->uid = Yii::$app->user->id; $model->tel = isset($tel)?$tel:""; $model->status = Tel::STATUS_ACTIVE; $model->type = Tel::TYPE_COMPANY;; $model->created_at = time(); if($model->validate()&&$model->save()){ $result=['sign'=>1,'msg'=>'添加成功']; }else{ $result=['sign'=>4000,'msg'=>'添加失败']; } return json_encode($result); }else{ return $this->render('message', [ 'models'=>$models ]); } } //删除手机 public function actionDeletetel(){ $id = Yii::$app->request->get('id'); $model = Tel::find()->where('id=:id and status=:status',[':id'=>$id,':status'=>Tel::STATUS_ACTIVE])->one(); $model->status = Tel::STATUS_DELETED; if($model->validate()&&$model->save()){ $result=['sign'=>1,'msg'=>'删除成功']; }else{ $result=['sign'=>4000,'msg'=>'删除失败']; } return json_encode($result); } //项目经理详情 public function actionManagerlist(){ $id = Yii::$app->request->get('id'); $model = Manager::find()->where('id=:id',[':id'=>$id])->one(); return $this->render('managerlist',['model'=>$model]); } //设计师详情 public function actionDesignerlist(){ $id = Yii::$app->request->get('id'); $model = Designer::find()->where('id=:id',[':id'=>$id])->one(); return $this->render('designerlist',['model'=>$model]); } //关于我们 public function actionProfile(){ $model = Information::find()->where('type=:type',[':type'=>Information::ABOUTWE])->orderBy('created_at desc')->one(); return $this->render('profile',['model'=>$model]); } //修改密码 public function actionAlterpassword(){ $result=['sign'=>1,'msg'=>'调用成功']; $user = \common\models\User::find()->where('id=:id',[':id'=>Yii::$app->user->id])->one(); if(Yii::$app->request->post()){ $password= Yii::$app->request->post('password'); $password1 = Yii::$app->request->post('password1'); if(!empty($password)){ if(!empty($user)){ if(Yii::$app->getSecurity()->validatePassword($password, $user->password_hash)){ $user->password_hash = Yii::$app->security->generatePasswordHash($password1); $user->updated_at = time(); if($user->save()&&$user->validate()){ $result=['sign'=>1,'msg'=>'修改成功']; }else{ $result=['sign'=>4000,'msg'=>'数据修改失败']; } }else{ $result=['sign'=>4000,'msg'=>'密码错误']; } }else{ $result=['sign'=>4000,'msg'=>'用户不存在']; } }else{ $result=['sign'=>4000,'msg'=>'密码不能为空']; } return json_encode($result); }else{ return $this->render('alterpassword'); } } }