123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- <?php
- namespace api\modules\v1\controllers;
- use common\models\Comment;
- use common\models\Designer;
- use common\models\Feedback;
- use common\models\ImageSource;
- use common\models\Manager;
- use common\models\MaterType;
- use common\models\Reply;
- use yii\data\Pagination;
- use yii\rest\ActiveController;
- use common\library\Apireturn;
- use yii\helpers\ArrayHelper;
- use yii\filters\auth\QueryParamAuth;
- use yii;
- class ReplyController extends ActiveController
- {
- const DISPLAY = 15;//显示条数
- public $modelClass = 'common\models';
- public function behaviors()
- {
- return ArrayHelper::merge(parent::behaviors(), [
- 'authenticator' => [
- 'class' => QueryParamAuth::className(),
- 'tokenParam' => "token",//access-token修改为token
- 'optional' => [//不需要认证方法名 array
- ],
- ]
- ]);
- }
- /**
- * 商家回复留言
- * @return array
- */
- public function actionReply(){
- $id = Yii::$app->request->post('id');//评论id
- $content = Yii::$app->request->post('content');
- if(empty($content))
- return Apireturn::sent(0,'评论内容不能为空',200);
- $comment = Comment::find()->where(['id'=>$id,'reply_uid'=>Yii::$app->user->id])->one();
- if(empty($comment))
- return Apireturn::sent(0,'找不到该评论',200);
- $model =new Reply();
- $model->cid = $id;
- $model->from_userid=Yii::$app->user->id;
- $model->to_userid=$comment->uid;
- $model->created_at=time();
- $model->content=$content;
- $model->status=Reply::STATUS_ACTIVE;
- if($model->save()){
- return Apireturn::sent(1,'评论成功',200);
- }
- return Apireturn::sent(0,"评论失败",200);
- }
- /**
- * 用户回复留言
- * @return array
- */
- public function actionUserReply(){
- $id = Yii::$app->request->post('id');//评论id
- $content = Yii::$app->request->post('content');
- if(empty($content))
- return Apireturn::sent(0,'评论内容不能为空',200);
- $comment = Comment::find()->where(['id'=>$id,'uid'=>Yii::$app->user->id])->one();
- if(empty($comment))
- return Apireturn::sent(0,'找不到该评论',200);
- $model =new Reply();
- $model->cid = $id;
- $model->from_userid=Yii::$app->user->id;
- $model->to_userid=$comment->reply_uid;
- $model->created_at=time();
- $model->content=$content;
- $model->status=Reply::STATUS_ACTIVE;
- if($model->save()){
- return Apireturn::sent(1,'评论成功',200);
- }
- return Apireturn::sent(0,"评论失败",200);
- }
- }
|