12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- <?php
- namespace app\api\controller;
- use app\common\controller\Api;
- use think\Db;
- use think\Exception;
- class Feedback extends Api
- {
- protected $noNeedLogin = [];
- protected $noNeedRight = '*';
- protected $model;
- public function _initialize()
- {
- parent::_initialize();
- $this->model = new \app\common\model\Feedback();
- }
- /**
- * 意见反馈添加
- * @return void
- */
- public function add()
- {
- try {
- $content = $this->request->param('content','');
- $images = $this->request->param('images','');
- //验证参数
- $validate = validate('Feedback');
- if(!$validate->check($this->request->param(),[],'add')){
- throw new Exception($validate->getError());
- }
- $userId = $this->auth->id;
- $content = $content;
- $images = $images;
- $limitNum = 100;//限制每月反馈数量
- $feedbackNum = $this->model->getMonthNum($userId);
- if ($feedbackNum >= $limitNum) {
- throw new Exception('您反馈的意见过多,请在次月再反馈');
- }
- $data = [
- 'user_id' => $userId,
- 'content' => $content,
- 'images' => $images,
- 'createtime' => time(),
- ];
- $addRes = $this->model->insertGetId($data);
- if (!$addRes) {
- throw new Exception('操作失败');
- }
- $this->success('操作成功');
- } catch (Exception $e) {
- $this->error($e->getMessage());
- }
- }
- }
|