[ 'class' => QueryParamAuth::className(), 'tokenParam' => "token",//access-token修改为token 'optional' => [//不需要认证方法名 array ], ] ]); } // public function actionCommentlist(){ // $page = Yii::$app->request->POST('page', 1); // $tempcomment = Comment::find() // ->joinWith('houseinfo')->with(['userinfo','reply.from','reply.to']) // ->where('bd_building.uid=:uid',[':uid'=>Yii::$app->user->id]) // ->orderBy('{{%comment}}.updated_at desc'); // $tempcomment=$tempcomment->offset(($page-1)*self::DISPLAY)->limit(self::DISPLAY)->asArray()->all(); // foreach ($tempcomment as $key =>$each){ // $tempcomment[$key]['created_at']=Comment::time_tran($each['created_at']); // if(count($each['reply'])>0){ // foreach ($each['reply'] as $eh_rl=> $eachrelay){ // $tempcomment[$key]['reply'][$eh_rl]['created_at']=Comment::time_tran($eachrelay['created_at']); // } // } // } // $data['commentlist']=$tempcomment; // $data['companyname']=UserCompany::findOne(['uid'=>Yii::$app->user->id])->getAttribute('company'); // return Apireturn::sent(1,'评论列表成功',200,$data); // } /** * 我的评价列表 --装修公司 * @return array */ public function actionCommentlist(){ $page = Yii::$app->request->POST('page', 1);//分页页数 $display = Yii::$app->request->POST('display', self::DISPLAY);//分页页数 $comment = Comment::find()->select("id,pid,star,uid,content,created_at")->where('status = :status AND reply_uid = :uid ',[':status'=>Comment::STATUS_ACTIVE,':uid'=>Yii::$app->user->id])->offset(($page - 1) * $display)->limit($display)->orderBy("created_at DESC")->all(); $data['list'] = array(); $company = UserCompany::find()->where(['uid'=>Yii::$app->user->id])->select('company')->one(); $data['company_name'] = !empty($company) ? $company->company : ""; if(!empty($comment)) { foreach ($comment as $com_key => $com_val) { $data['list'][$com_key]['id'] = $com_val->id; $data['list'][$com_key]['star'] = $com_val->star; $data['list'][$com_key]['content'] = $com_val->content; $data['list'][$com_key]['created_at'] = Comment::time_tran($com_val->created_at); $data['list'][$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['list'][$com_key]['portrait'] = !empty($com_val->userinfo->portrait) ? UserInfo::imagesUrl($com_val->userinfo->portrait):"";; $data['list'][$com_key]['nickname'] = $com_val->userinfo->nickname; } $data['list'][$com_key]['building'] =array(); $building = Building::find()->where(['id'=>$com_val->pid])->select("id,name,layout,acreage,style")->one(); if(!empty($building)) { foreach ( $building->getOldAttributes() as $key =>$value) { $data['list'][$com_key]['building'][$key] = $value; } $data['list'][$com_key]['building']['backimg'] = empty($building->all) ? "" : $building->all->pic; } $data['list'][$com_key]['replys'] = array(); $replys = Reply::find()->where(['cid'=>$com_val->id,'status'=>Reply::STATUS_ACTIVE])->select('id,from_userid,to_userid,content,created_at')->orderBy('created_at ASC')->all(); if(!empty($replys)) { foreach ($replys as $rep_key => $rep_val) { $data['list'][$com_key]['replys'][$rep_key]['own'] = $rep_val->from_userid == Yii::$app->user->id ? 1 : 0 ; $data['list'][$com_key]['replys'][$rep_key]['content'] = $rep_val->content; $data['list'][$com_key]['replys'][$rep_key]['created_at'] = Comment::time_tran($rep_val->created_at); } } } } return Apireturn::sent(1,'success',200,$data); } /** * 我的评价列表 --用户 * @return array */ public function actionUcommentlist(){ $page = Yii::$app->request->POST('page', 1); $tempcomment = Comment::find() ->joinWith('houseinfo')->with(['userinfo','houseinfo.all','reply.fro','reply.too']) ->where('{{%comment}}.uid=:uid',[':uid'=>Yii::$app->user->id]) ->orderBy('{{%comment}}.updated_at desc'); $tempcomment=$tempcomment->offset(($page-1)*self::DISPLAY)->limit(self::DISPLAY)->asArray()->all(); foreach ($tempcomment as $key =>$each){ if(!empty($each['userinfo'])) { $tempcomment[$key]['userinfo']['portrait'] = !empty($each['userinfo']['portrait']) ? UserInfo::imagesUrl($each['userinfo']['portrait']) : ""; } $tempcomment[$key]['created_at']=Comment::time_tran($each['created_at']); $tempcomment[$key]['imgs']=ImageSource::find()->select('pic')->where(['topid'=>$each['id'],'type'=>ImageSource::TYPE_COMMENT,'status'=>ImageSource::STATUS_YES])->asArray()->all(); if(count($each['reply'])>0){ foreach ($each['reply'] as $eh_rl=> $eachrelay){ $tempcomment[$key]['reply'][$eh_rl]['created_at']=Comment::time_tran($eachrelay['created_at']); } } } $data['commentlist']=$tempcomment; $data['name']=UserInfo::findOne(['uid'=>Yii::$app->user->id])->getAttribute('nickname'); return Apireturn::sent(1,'评论列表成功',200,$data); } /** * 发表评论 * @return array */ public function actionComment(){ $pic = Yii::$app->request->post('pic'); $building = Building::find()->select('id,uid')->where(['id'=>Yii::$app->request->post('pid')])->one(); if(empty($building)) return Apireturn::sent(0,"找不到该工地/样板房",200); $picinfo = json_decode($pic,true); $model =new Comment(); $model->load(Yii::$app->request->post(),''); $model->uid=Yii::$app->user->id; $model->reply_uid=$building->uid; $model->created_at=time(); $model->updated_at=time(); $model->status=Comment::STATUS_ACTIVE; if( $model->save()){ if(count($picinfo)>0) { foreach ($picinfo as $eachinfo) { //新上传的图片 if(empty($eachinfo['id'])) { $newpic=new ImageSource(); $newpic->pic=$eachinfo['imgurl']; $newpic->thumbnail=$eachinfo['imgurl']; $newpic->updated_at = time(); $newpic->created_at = time(); $newpic->topid = $model->id; $newpic->type = ImageSource::TYPE_COMMENT; $newpic->status=Comment::STATUS_ACTIVE; if(!($newpic->save())) { return Apireturn::sent(1, 'pic save fail', 200); } } } return Apireturn::sent(1, '图片保存成功', 200,$picinfo); } else { return Apireturn::sent(1, '图片保存成功', 200,$picinfo); } } return Apireturn::sent(0,$model->firstErrors,200); } }