[ 'class' => QueryParamAuth::className(), 'tokenParam' => "token",//access-token修改为token 'optional' => [//不需要认证方法名 array ], ] ]); } /** * 预约列表 装修端 * @return array */ public function actionList() { $page = Yii::$app->request->POST('page', 1); $models = Appointment::find()->select(['{{%appointment}}.uid','pid','booking_time','state','{{%appointment}}.type']) ->joinWith(['building'=>function($query){ $query->select(['id','name']);}]) ->andwhere('{{%building}}.uid=:uid',[':uid'=>Yii::$app->user->id]) ->with(['userinfo'=>function($query){ $query->select('nickname,portrait,uid'); },]); $is_member =UserCompany::findOne(['uid'=>Yii::$app->user->id])->getAttribute('member'); if($is_member==UserCompany::ISMEMBER){ $models->with(['user'=>function($query){ $query->select('id,tel'); }]); } $models = $models->orderBy('bd_appointment.created_at desc'); $models=$models->offset(($page-1)*self::DISPLAY)->limit(self::DISPLAY)->asArray()->all(); foreach ($models as $key => $each){ $models[$key]['booking_time']=date('Y-m-d H:i',$models[$key]['booking_time']); if(!empty($models[$key]['userinfo']) && !empty($models[$key]['userinfo']['portrait'])) $models[$key]['userinfo']['portrait'] = UserInfo::imagesUrl($models[$key]['userinfo']['portrait']); } $data['list']=$models; $data['ismember']=$is_member; return Apireturn::sent(1,'订单列表获取成功',200,$data); } /** * 预约列表 用户端 * @return array */ public function actionAppointlist() { $page = Yii::$app->request->POST('page', 1); $latitude=Yii::$app->request->post('latitude',''); $longitude=Yii::$app->request->post('longitude',''); $models = Appointment::find()->select(['{{%appointment}}.uid','pid','booking_time'])->where(array('{{%appointment}}.uid'=>Yii::$app->user->id)) ->with(['userinfo'=>function($query){ $query->select('nickname,portrait,uid'); },'building',]); $geohash = new ZM_Geohash(); $models = $models->orderBy('bd_appointment.created_at desc'); $models=$models->offset(($page-1)*self::DISPLAY)->limit(self::DISPLAY)->asArray()->all(); foreach ($models as $key => $each){ $models[$key]['booking_time']=date('Y-m-d H:i',$each['booking_time']); $images = ImageSource::find()->select('pic')->where('topid=:id and status=:status', [':id' => $each['pid'], ':status' => ImageSource::STATUS_YES])->andWhere(['type' => [20,30,40,50]])->one(); $models[$key]['img']=$images; if(!empty($latitude)&&!empty($longitude)) { $distance = $geohash->getDistance($latitude,$longitude,$each['building']['latitude'],$each['building']['longitude']); $models[$key]['building']['distance'] = sprintf( "%.1f ",$distance/1000); } } return Apireturn::sent(1,'预约列表获取成功',200,$models); } /** * 预约单详情 * @return array */ public function actionAppointdetail() { $page = Yii::$app->request->POST('page', 1); $id = Yii::$app->request->post('id'); if(empty($id)){ return Apireturn::sent(0,'参数错误',200); } $model = Building::find()->where('id=:id',[':id'=>$id])->one(); $comment = Comment::find()->where('pid=:pid',[':pid'=>$id])->all(); $img =$model->allimg; $data['banner']=$img; $data['buiding']=$model; $data['comment']=$comment; return Apireturn::sent(1,'预约单详情',200,$data); } /** * 设计师删除 * @return array */ public function actionDeldesigner() { $id = Yii::$app->request->post('id'); $deginers = Designer::findOne(['id'=>$id,'status'=>Designer::STATUS_YES,'company'=>Yii::$app->user->id]); if(!isset($deginers)){ return Apireturn::sent(1,'找不到设计师',200); } $deginers->status=Designer::STATUS_NO; if($deginers->save()){ return Apireturn::sent(0,'删除成功',200); } return Apireturn::sent(1,'删除失败',200); } /** * 项目经理删除 * @return array */ public function actionDelmanager() { $id = Yii::$app->request->post('id'); $deginers = Manager::findOne(['id'=>$id,'status'=>Designer::STATUS_YES,'company'=>Yii::$app->user->id]); if(!isset($deginers)){ return Apireturn::sent(1,'找不到经理',200); } $deginers->status=Manager::STATUS_NO; if($deginers->save()){ return Apireturn::sent(0,'删除成功',200); } return Apireturn::sent(1,'删除失败',200); } /** * 设计师和管理人缘添加 * @return array */ public function actionAdddesign() { $type = Yii::$app->request->post('type'); $avatar = Yii::$app->request->post('avatar'); $realname = Yii::$app->request->post('realname'); $intro = Yii::$app->request->post('intro'); if(empty($type)||empty($avatar)||empty($realname)||empty($intro)){ return Apireturn::sent(1,'参数错误',200); } //10 设计师 11:经理 if($type==10){ $newperson = new Designer(); } else if($type==11){ $newperson = new Manager(); } else{ return Apireturn::sent(1,'参数错误',200); } $newperson->company=Yii::$app->user->id; $newperson->realname=$realname; $newperson->introduction=$intro; $transaction = Yii::$app->db->beginTransaction(); if($newperson->save()){ $ava = new ImageSource; $ava->type=$type; $ava->topid=$newperson->id; $ava->pic=$avatar; $ava->thumbnail=$avatar; $ava->created_at=time(); $ava->updated_at=time(); if($ava->save()){ $transaction->commit(); return Apireturn::sent(0,'添加人员成功',200); } else{ $transaction->rollBack(); return Apireturn::sent(1,'添加人员失败',200); } } return Apireturn::sent(1,'添加失败11',200,$newperson->getErrors()); } /** * 设计师和管理人员编辑 * @return array */ public function actionEdit() { $id = Yii::$app->request->post('id'); $type = Yii::$app->request->post('type'); $avatar = Yii::$app->request->post('avatar'); $realname = Yii::$app->request->post('realname'); $intro = Yii::$app->request->post('intro'); if(empty($id)||empty($type)||empty($avatar)||empty($realname)||empty($intro)){ return Apireturn::sent(1,'参数错误',200); } //10 设计师 11:经理 if($type==10){ $newperson = Designer::findOne(['id'=>$id,'status'=>Designer::STATUS_YES,'company'=>Yii::$app->user->id]); } else if($type==11){ $newperson = Designer::findOne(['id'=>$id,'status'=>Designer::STATUS_YES,'company'=>Yii::$app->user->id]); } else{ return Apireturn::sent(1,'参数错误',200); } if(empty($newperson)){ return Apireturn::sent(1,'找不到该名人缘',200); } $newperson->company=Yii::$app->user->id; $newperson->realname=$realname; $newperson->introduction=$intro; $transaction = Yii::$app->db->beginTransaction(); if($newperson->save()){ $ava = ImageSource::findOne(['topid'=>$id,'status'=>ImageSource::STATUS_YES,'type'=>$type]);; $ava->topid=$id; $ava->pic=$avatar; $ava->thumbnail=$avatar; $ava->updated_at=time(); if($ava->save()){ $transaction->commit(); return Apireturn::sent(0,'修改人员成功',200); } else{ $transaction->rollBack(); return Apireturn::sent(1,'修改人员失败',200); } } return Apireturn::sent(1,'修改失败',200); } }