0], [['hbAmount'], 'required', 'message' => '请填写红包金额'], // 注意:不要对字段做 intval 过滤,避免 "abc" 被转成 0 导致校验绕过 [['hbAmount'], 'number', 'min' => 0.01, 'tooSmall' => '{attribute}必须大于等于0.01'], [['hbNum', 'miniCost'], 'integer', 'message' => '{attribute}必须为正整数', 'min' => 0, 'tooSmall' => '{attribute}不能小于0'], [['duration'], 'integer', 'min' => 0, 'max' => 3650, 'tooSmall' => '{attribute}不能小于0', 'tooBig' => '{attribute}过大'], [['effectiveType'], 'in', 'range' => [1, 2]], [['effectiveDate'], 'default', 'value' => null], [['effectiveDate'], 'filter', 'filter' => function($value) { return $value === '0000-00-00' ? null : $value; }], [['effectiveDate'], 'datetime', 'format' => 'php:Y-m-d'], [['effectiveDays'], 'integer', 'min' => 0, 'max' => 365, 'tooSmall' => '{attribute}不能小于0', 'tooBig' => '{attribute}过大'], ]; } /** * {@inheritdoc} */ public function attributeLabels() { return [ 'hbAmount' => '红包金额', 'hbNum' => '红包数量', 'miniCost' => '最低消费金额', 'duration' => '有效天数', 'effectiveType' => '生效类型', 'effectiveDate' => '生效日期', 'effectiveDays' => '生效天数', ]; } }