[ 'class' => AccessControl::className(), 'rules' => [ [ 'actions' => [], 'allow' => true, 'roles' => ['@'], ], ], ], ]; } /** * 工地列表 */ public function actionIndex() { $type = Yii::$app->request->get('type'); $company = Yii::$app->request->get('company'); $name = Yii::$app->request->get('name'); //$mod = Building::find()->where(['posted'=>Building::POSTED_YES]); $mod = Building::find()->where(['a.posted'=>Building::POSTED_YES])->select('a.* ,b.company')->from('{{%building}} a')->leftJoin(['b'=>'{{%user_company}}'],'a.uid=b.uid'); if(!empty($type)){ $mod->andWhere('a.type=:type',[':type'=>$type]); } if(!empty($company)){ $mod->andWhere('b.company like :company',[':company'=>"%$company%"]); } if(!empty($name)){ $mod->andWhere('a.name like :name',[':name'=>"%$name%"]); } $citys = AuthArea::queryAuth(); if($citys=='all') $mod; elseif (!empty($citys)) $mod->andWhere("a.city in ({$citys})"); else $mod->andWhere("a.city = -1"); $pages = new yii\data\Pagination(["totalCount"=>$mod->count(),"pageSize"=>self::PAGESIZE]); $datas=$mod->offset($pages->offset)->limit($pages->limit)->addOrderBy(['a.id'=>SORT_DESC])->asArray()->all(); return $this->render('index',['datas'=>$datas,'pages'=>$pages,'type'=>$type,'company'=>$company,'name'=>$name]); } /** * 用户预约列表 */ public function actionAppointments() { $type = Yii::$app->request->get('type'); $company = Yii::$app->request->get('company'); $mod = Appointment::find()->where(['a.status'=>Appointment::STATUS_DEAL])->select('a.* ,b.name,b.city,b.address,c.company')->from('{{%appointment}} a')->leftJoin(['b'=>'{{%building}}'],'a.pid=b.id')->leftJoin(['c'=>'{{%user_company}}'],'b.uid=c.uid'); if(!empty($type)){ $mod->andWhere('a.type=:type',[':type'=>$type]); } if(!empty($company)){ $mod->andWhere('b.name like :company',[':company'=>"%$company%"]); } $citys = AuthArea::queryAuth(); if($citys=='all') $mod; elseif (!empty($citys)) $mod->andWhere("b.city in ({$citys})"); else $mod->andWhere("b.city = -1"); $pages = new yii\data\Pagination(["totalCount"=>$mod->count(),"pageSize"=>self::PAGESIZE]); $datas=$mod->offset($pages->offset)->limit($pages->limit)->addOrderBy(['a.id'=>SORT_DESC])->asArray()->all(); if(!empty($datas)) { foreach ($datas as $key => $val) { $datas[$key]['visit'] = AppointmentVisit::find()->where(['aid'=>$val['id']])->orderBy("id ASC")->asArray()->all(); } } return $this->render('appointments',['datas'=>$datas,'pages'=>$pages,'type'=>$type,'company'=>$company]); } /** * 确认回访 */ public function actionHandleApp() { $result=['sign'=>1,'msg'=>'操作成功']; $id = Yii::$app->request->post('id'); $content = Yii::$app->request->post('content'); if($content =='') { $result=['sign'=>0,'msg'=>'回访记录不能为空']; return json_encode($result); } $model = Appointment::find()->where(['id'=>$id])->one(); if(empty($model)){ $result=['sign'=>0,'msg'=>'找不到记录']; }else{ if($model->handle != Appointment::HANDLE_YES){ $model->handle = Appointment::HANDLE_YES; $model->updated_at = time(); if($model->save()){ $result=['sign'=>1,'msg'=>'操作成功']; } else{ $result=['sign'=>0,'msg'=>'操作失败']; return json_encode($result); } } $visit_model = new AppointmentVisit(); $visit_model->aid = $model->id; $visit_model->content = $content; $visit_model->admin_id = Yii::$app->user->id; $visit_model->operation = Yii::$app->user->identity->username; $visit_model->c_time = time(); if($visit_model->save()){ $result['data'] = array('content'=>$visit_model->content,'operation'=>$visit_model->operation,'c_time'=>date("Y-m-d H:i",$visit_model->c_time)); }else{ $result=['sign'=>0,'msg'=>'操作失败']; } } return json_encode($result); } /** * 工地预约记录 */ public function actionAppointment() { $id = \Yii::$app->request->get('id'); $mod = Appointment::find()->where(['pid'=>$id]); $pages = new yii\data\Pagination(["totalCount"=>$mod->count(),"pageSize"=>self::PAGESIZE]); $datas=$mod->offset($pages->offset)->limit($pages->limit)->orderBy('created_at desc')->all(); return $this->render('appointment',['datas'=>$datas,'pages'=>$pages]); } /** * 工地评论记录 */ public function actionComment() { $id = \Yii::$app->request->get('id'); $mod = Comment::find()->where('pid=:pid and status=:status',[':pid'=>$id,':status'=>Comment::STATUS_ACTIVE]); $pages = new yii\data\Pagination(["totalCount"=>$mod->count(),"pageSize"=>self::PAGESIZE]); $datas=$mod->offset($pages->offset)->limit($pages->limit)->all(); return $this->render('comment',['datas'=>$datas,'pages'=>$pages]); } /** * 工地详情 * @return string */ public function actionEdit() { $id = Yii::$app->request->get('id'); $data = Yii::$app->db->createCommand('SELECT * from {{%building}} WhERE id = :id ') ->bindValue(':id',$id) ->queryOne(); $data['company'] = Yii::$app->db->createCommand('SELECT * from {{%user_company}} WhERE uid = :uid') ->bindValue(':uid',$data['uid']) ->queryOne(); $data['manager'] = Yii::$app->db->createCommand('SELECT realname,introduction from {{%manager}} WHERE id =:id')->bindValue(':id',$data['manager_id'])->queryOne(); $data['designer'] = Yii::$app->db->createCommand('SELECT realname,introduction from {{%designer}} WHERE id =:id')->bindValue(':id',$data['designer_id'])->queryOne(); return $this->render('edit',['data'=>$data]); } /** * 删除工地 */ public function actionDeletebuilding(){ //post 批量删除 if(Yii::$app->request->isPost) { $checks = Yii::$app->request->post('check'); if(empty($checks) || !is_array($checks)){ Yii::$app->getSession()->setFlash('error','没有选中项'); return $this->redirect(Yii::$app->request->referrer); } $checks = implode(",",$checks); $result = Yii::$app->db->createCommand('UPDATE {{%building}} SET posted = '.Building::POSTED_DELETE.' WhERE id in ('.$checks.')')->execute(); if($result) { Yii::$app->getSession()->setFlash('success','删除成功'); return $this->redirect(Yii::$app->request->referrer); }else{ Yii::$app->getSession()->setFlash('error','删除失败'); return $this->redirect(Yii::$app->request->referrer); } } $id = \Yii::$app->request->get('id'); $model = Building::findOne($id);//删除样板房记录 $model->posted = Building::POSTED_DELETE; $model->updated_at =time(); if($model->validate()&&$model->save()) { \Yii::$app->getSession()->setFlash('success','删除成功'); return $this->redirect(['index']); }else{ var_dump($model->getErrors());exit; \Yii::$app->getSession()->setFlash('error','删除失败'); return $this->redirect(['index']); } } }