Feedback.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Db;
  5. use think\Exception;
  6. class Feedback extends Api
  7. {
  8. protected $noNeedLogin = [];
  9. protected $noNeedRight = '*';
  10. protected $model;
  11. public function _initialize()
  12. {
  13. parent::_initialize();
  14. $this->model = new \app\common\model\Feedback();
  15. }
  16. /**
  17. * 意见反馈添加
  18. * @return void
  19. */
  20. public function add()
  21. {
  22. try {
  23. $content = $this->request->param('content','');
  24. $images = $this->request->param('images','');
  25. //验证参数
  26. $validate = validate('Feedback');
  27. if(!$validate->check($this->request->param(),[],'add')){
  28. throw new Exception($validate->getError());
  29. }
  30. $userId = $this->auth->id;
  31. $content = $content;
  32. $images = $images;
  33. $limitNum = 100;//限制每月反馈数量
  34. $feedbackNum = $this->model->getMonthNum($userId);
  35. if ($feedbackNum >= $limitNum) {
  36. throw new Exception('您反馈的意见过多,请在次月再反馈');
  37. }
  38. $data = [
  39. 'user_id' => $userId,
  40. 'content' => $content,
  41. 'images' => $images,
  42. 'createtime' => time(),
  43. ];
  44. $addRes = $this->model->insertGetId($data);
  45. if (!$addRes) {
  46. throw new Exception('操作失败');
  47. }
  48. $this->success('操作成功');
  49. } catch (Exception $e) {
  50. $this->error($e->getMessage());
  51. }
  52. }
  53. }