On this page
用户反馈api
创建相关文件
php
// 创建反馈控制器
php think make:controller api/v1/Feedback
// 创建反馈模型
php think make:model Feedback
// 创建反馈验证器
php think make:validate FeedbackValidate
controller层:application\api\controller\v1\Feedback.php
php
<?php
namespace app\api\controller\v1;
use think\Controller;
use think\Request;
use app\common\controller\BaseController;
use app\common\validate\FeedbackValidate;
use app\common\model\Feedback as FeedbackModel;
class Feedback extends BaseController
{
// 反馈信息
public function feedback(){
(new FeedbackValidate())->goCheck('feedback');
(new FeedbackModel())->feedback();
return self::showResCodeWithOutData('反馈成功');
}
}
route层:route\route.php
php
// 用户操作(绑定手机)
Route::group('api/:v1/',function(){
// 用户反馈
Route::post('feedback','api/:v1.Feedback/feedback');
})->middleware(['ApiUserAuth','ApiUserBindPhone','ApiUserStatus']);
validate层:application\common\validate\FeedbackValidate.php
php
protected $rule = [
'data'=>'require|NotEmpty',
];
protected $scene = [
'feedback'=>['data'],
];
BaseValidate:application\common\validate\BaseValidate.php
php
// 不能为空
protected function NotEmpty($value, $rule='', $data='', $field='')
{
if (empty($value)) return $field."不能为空";
return true;
}
model层:application\common\model\Feedback.php
php
protected $autoWriteTimestamp = true;
// 用户反馈
public function feedback(){
$param = request()->param();
$data = [
'from_id' => request()->userId,
'to_id' => 0,
'data' => $param['data']
];
if (!$this -> create($data)) return TApiException();
return true;
}