| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- <?php
- namespace App\Module\Farm\Validations;
- use UCore\Validation\BaseValidation;
- /**
- * 作物摘取验证类
- *
- * @property int $pickerId 摘取者ID
- * @property int $cropId 作物ID
- * @property int $pickAmount 摘取数量
- * @property string $pickSource 摘取来源
- * @property int|null $sourceId 来源ID(可选)
- */
- class CropPickValidation extends BaseValidation
- {
- public int $pickerId;
- public int $cropId;
- public int $pickAmount;
- public string $pickSource;
- public ?int $sourceId = null;
- /**
- * 获取验证规则
- *
- * @return array
- */
- public function rules(): array
- {
- return [
- 'pickerId' => 'required|integer|min:1',
- 'cropId' => 'required|integer|min:1',
- 'pickAmount' => 'required|integer|min:1',
- 'pickSource' => 'required|string|max:50',
- 'sourceId' => 'nullable|integer|min:1',
- ];
- }
- /**
- * 获取验证错误消息
- *
- * @return array
- */
- public function messages(): array
- {
- return [
- 'pickerId.required' => '摘取者ID不能为空',
- 'pickerId.integer' => '摘取者ID必须为整数',
- 'pickerId.min' => '摘取者ID必须大于0',
- 'cropId.required' => '作物ID不能为空',
- 'cropId.integer' => '作物ID必须为整数',
- 'cropId.min' => '作物ID必须大于0',
- 'pickAmount.required' => '摘取数量不能为空',
- 'pickAmount.integer' => '摘取数量必须为整数',
- 'pickAmount.min' => '摘取数量必须大于0',
- 'pickSource.required' => '摘取来源不能为空',
- 'pickSource.string' => '摘取来源必须为字符串',
- 'pickSource.max' => '摘取来源长度不能超过50个字符',
- 'sourceId.integer' => '来源ID必须为整数',
- 'sourceId.min' => '来源ID必须大于0',
- ];
- }
- }
|