12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- <?php
- namespace app\api\validate;
- use think\Validate;
- use app\common\Enum\FeedbackEnum;
- class Feedback extends Validate
- {
- /**
- * 验证规则
- */
- protected $rule = [
- //'type' => 'require|in:产品功能反馈,产品bug反馈,其他反馈',
- 'content' => 'require|max:2000',
- 'images' => 'array|length:0,3',
- 'phone' => 'mobile',
- ];
- /**
- * 提示消息
- */
- protected $message = [
- 'type.require' => '请选择反馈类型',
- 'type.in' => '反馈类型不正确',
- 'content.require' => '请输入反馈内容',
- 'content.max' => '反馈内容不能超过2000字符',
- 'images.array' => '图片必须是数组格式',
- 'images.length' => '最多上传3张图片',
- 'phone.mobile' => '手机号格式不正确',
- ];
- /**
- * 验证场景
- */
- protected $scene = [
- 'add' => ['type', 'content', 'images', 'phone'],
- ];
- public function __construct(array $rules = [], $message = [], $field = [])
- {
- // 动态设置枚举值
- $this->rule['type'] = 'require|in:' . implode(',', FeedbackEnum::FEEDBACK_TYPE_LIST);
- parent::__construct($rules, $message, $field);
- }
- }
|