Feedback.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. namespace app\api\validate;
  3. use think\Validate;
  4. use app\common\Enum\FeedbackEnum;
  5. class Feedback extends Validate
  6. {
  7. /**
  8. * 验证规则
  9. */
  10. protected $rule = [
  11. //'type' => 'require|in:产品功能反馈,产品bug反馈,其他反馈',
  12. 'content' => 'require|max:2000',
  13. 'images' => 'array|length:0,3',
  14. 'phone' => 'mobile',
  15. ];
  16. /**
  17. * 提示消息
  18. */
  19. protected $message = [
  20. 'type.require' => '请选择反馈类型',
  21. 'type.in' => '反馈类型不正确',
  22. 'content.require' => '请输入反馈内容',
  23. 'content.max' => '反馈内容不能超过2000字符',
  24. 'images.array' => '图片必须是数组格式',
  25. 'images.length' => '最多上传3张图片',
  26. 'phone.mobile' => '手机号格式不正确',
  27. ];
  28. /**
  29. * 验证场景
  30. */
  31. protected $scene = [
  32. 'add' => ['type', 'content', 'images', 'phone'],
  33. ];
  34. public function __construct(array $rules = [], $message = [], $field = [])
  35. {
  36. // 动态设置枚举值
  37. $this->rule['type'] = 'require|in:' . implode(',', FeedbackEnum::FEEDBACK_TYPE_LIST);
  38. parent::__construct($rules, $message, $field);
  39. }
  40. }