ReportController.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. namespace api\modules\v1\controllers;
  3. use api\controllers\OnAuthController;
  4. use services\common\ReportService;
  5. use Yii;
  6. /**
  7. * 举报
  8. * Class ReportController
  9. * @package api\modules\v1\controllers
  10. */
  11. class ReportController extends OnAuthController
  12. {
  13. /**
  14. * @var string
  15. */
  16. public $modelClass = '';
  17. /**
  18. * @var ReportService
  19. */
  20. protected $service;
  21. public function beforeAction($action)
  22. {
  23. parent::beforeAction($action);
  24. $this->service = new ReportService(['mall_id' => $this->mall_id]);
  25. return $action;
  26. }
  27. /**
  28. * 提交举报
  29. *
  30. * @return string
  31. */
  32. public function actionSubmit(int $id, string $from)
  33. {
  34. $post = $this->request->post();
  35. $validate = Yii::$app->services->validate->validate($post, [
  36. [['type', 'content'], 'required'],
  37. ]);
  38. if (!$validate) return $this->error(Yii::$app->services->validate->getErrorMessage());
  39. return $this->service->addReport($id, $from, $post)
  40. ? $this->success('举报成功')
  41. : $this->error($this->service->getError());
  42. }
  43. }