Index.php 948 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use app\common\model\Feedback;
  5. use app\api\validate\Feedback as FeedbackValidate;
  6. /**
  7. * 首页接口
  8. */
  9. class Index extends Api
  10. {
  11. protected $noNeedLogin = ['index'];
  12. protected $noNeedRight = ['*'];
  13. /**
  14. * 首页
  15. *
  16. */
  17. public function index()
  18. {
  19. $this->success(__('User Center'));
  20. }
  21. public function feedback()
  22. {
  23. $user = $this->auth->getUser();
  24. $params = $this->request->only(['type', 'content', 'images', 'phone']);
  25. // 使用验证器
  26. $validate = new FeedbackValidate();
  27. if (!$validate->check($params)) {
  28. $this->error($validate->getError());
  29. }
  30. if ($user) {
  31. $params['user_id'] = $user->id;
  32. }
  33. $result = Feedback::create($params);
  34. if ($result) {
  35. $this->success('感谢您的反馈');
  36. }
  37. }
  38. }