User.php 1002 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: 中闽 < 1464674022@qq.com >
  5. * Date: 2019/12/5
  6. * Time: 17:44
  7. */
  8. namespace app\api\controller;
  9. use app\common\model\Feedback;
  10. use app\api\controller\base\Permissions;
  11. class User extends Permissions
  12. {
  13. //个人资料接口
  14. public function info()
  15. {
  16. $this->json_success('success', $this->user);
  17. }
  18. //提交反馈接口
  19. public function feedback()
  20. {
  21. $post = $this->request->param();
  22. //验证
  23. $validate = new \think\Validate([
  24. ['content|内容', 'require|max:500'],
  25. ]);
  26. if (!$validate->check($post)) {
  27. $this->error('提交失败:' . $validate->getError());
  28. }
  29. $model = new Feedback();
  30. $post['user_id'] = $this->user->id;
  31. $res = $model->allowField(true)->save($post);
  32. if ($res) {
  33. $this->json_success("创建成功", $model);
  34. } else {
  35. $this->json_error("创建失败");
  36. }
  37. }
  38. }