ReplyController.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. namespace api\modules\v1\controllers;
  3. use common\models\Comment;
  4. use common\models\Designer;
  5. use common\models\Feedback;
  6. use common\models\ImageSource;
  7. use common\models\Manager;
  8. use common\models\MaterType;
  9. use common\models\Reply;
  10. use yii\data\Pagination;
  11. use yii\rest\ActiveController;
  12. use common\library\Apireturn;
  13. use yii\helpers\ArrayHelper;
  14. use yii\filters\auth\QueryParamAuth;
  15. use yii;
  16. class ReplyController extends ActiveController
  17. {
  18. const DISPLAY = 15;//显示条数
  19. public $modelClass = 'common\models';
  20. public function behaviors()
  21. {
  22. return ArrayHelper::merge(parent::behaviors(), [
  23. 'authenticator' => [
  24. 'class' => QueryParamAuth::className(),
  25. 'tokenParam' => "token",//access-token修改为token
  26. 'optional' => [//不需要认证方法名 array
  27. ],
  28. ]
  29. ]);
  30. }
  31. /**
  32. * 商家回复留言
  33. * @return array
  34. */
  35. public function actionReply(){
  36. $id = Yii::$app->request->post('id');//评论id
  37. $content = Yii::$app->request->post('content');
  38. if(empty($content))
  39. return Apireturn::sent(0,'评论内容不能为空',200);
  40. $comment = Comment::find()->where(['id'=>$id,'reply_uid'=>Yii::$app->user->id])->one();
  41. if(empty($comment))
  42. return Apireturn::sent(0,'找不到该评论',200);
  43. $model =new Reply();
  44. $model->cid = $id;
  45. $model->from_userid=Yii::$app->user->id;
  46. $model->to_userid=$comment->uid;
  47. $model->created_at=time();
  48. $model->content=$content;
  49. $model->status=Reply::STATUS_ACTIVE;
  50. if($model->save()){
  51. return Apireturn::sent(1,'评论成功',200);
  52. }
  53. return Apireturn::sent(0,"评论失败",200);
  54. }
  55. /**
  56. * 用户回复留言
  57. * @return array
  58. */
  59. public function actionUserReply(){
  60. $id = Yii::$app->request->post('id');//评论id
  61. $content = Yii::$app->request->post('content');
  62. if(empty($content))
  63. return Apireturn::sent(0,'评论内容不能为空',200);
  64. $comment = Comment::find()->where(['id'=>$id,'uid'=>Yii::$app->user->id])->one();
  65. if(empty($comment))
  66. return Apireturn::sent(0,'找不到该评论',200);
  67. $model =new Reply();
  68. $model->cid = $id;
  69. $model->from_userid=Yii::$app->user->id;
  70. $model->to_userid=$comment->reply_uid;
  71. $model->created_at=time();
  72. $model->content=$content;
  73. $model->status=Reply::STATUS_ACTIVE;
  74. if($model->save()){
  75. return Apireturn::sent(1,'评论成功',200);
  76. }
  77. return Apireturn::sent(0,"评论失败",200);
  78. }
  79. }