|
|
@@ -9,17 +9,11 @@ use hd\models\BaseForm;
|
|
|
*/
|
|
|
class SendHbRuleItemForm extends BaseForm
|
|
|
{
|
|
|
- /** @var int|string 规则ID:新增传空字符串,更新传正整数 */
|
|
|
- public $id;
|
|
|
-
|
|
|
- /** @var int 充值金额 */
|
|
|
- public $amount;
|
|
|
-
|
|
|
/** @var int 红包金额 */
|
|
|
public $hbAmount;
|
|
|
|
|
|
/** @var int 红包张数 */
|
|
|
- public $num;
|
|
|
+ public $hbNum;
|
|
|
|
|
|
/** @var int 最低消费金额(0 表示不限制) */
|
|
|
public $miniCost;
|
|
|
@@ -27,73 +21,53 @@ class SendHbRuleItemForm extends BaseForm
|
|
|
/** @var int 有效天数(0 表示永不过期) */
|
|
|
public $duration;
|
|
|
|
|
|
+ /** @var int 生效类型
|
|
|
+ * 1: 日期 2: 天数
|
|
|
+ */
|
|
|
+ public $effectiveType;
|
|
|
+
|
|
|
+ /** @var string 生效日期 */
|
|
|
+ public $effectiveDate;
|
|
|
+
|
|
|
+ /** @var int 生效天数 */
|
|
|
+ public $effectiveDays;
|
|
|
+
|
|
|
/**
|
|
|
* {@inheritdoc}
|
|
|
*/
|
|
|
public function rules()
|
|
|
{
|
|
|
return [
|
|
|
- [['id'], 'default', 'value' => ''],
|
|
|
- [['num'], 'default', 'value' => 1],
|
|
|
[['miniCost', 'duration'], 'default', 'value' => 0],
|
|
|
-
|
|
|
- [['amount'], 'required', 'message' => '请填写充值金额'],
|
|
|
[['hbAmount'], 'required', 'message' => '请填写红包金额'],
|
|
|
|
|
|
// 注意:不要对字段做 intval 过滤,避免 "abc" 被转成 0 导致校验绕过
|
|
|
- [['amount', 'hbAmount'], 'number', 'min' => 0.01, 'tooSmall' => '{attribute}必须大于等于0.01'],
|
|
|
- [['num'], 'integer', 'message' => '{attribute}必须为正整数', 'min' => 1, 'tooSmall' => '{attribute}最小不能小于1'],
|
|
|
- [['miniCost'], 'integer', 'message' => '{attribute}必须为正整数', 'min' => 0, 'tooSmall' => '{attribute}不能小于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}过大'],
|
|
|
-
|
|
|
- [['id'], 'validateId'],
|
|
|
+ [['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}过大'],
|
|
|
];
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 新增时 id 允许为空字符串;更新时必须为正整数。
|
|
|
- *
|
|
|
- * @param string $attribute
|
|
|
- */
|
|
|
- public function validateId($attribute)
|
|
|
- {
|
|
|
- $value = $this->$attribute;
|
|
|
- if ($value === '' || $value === null) {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- if (is_int($value)) {
|
|
|
- if ($value < 1) {
|
|
|
- $this->addError($attribute, '规则ID参数错误');
|
|
|
- }
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- if (is_string($value) && ctype_digit($value)) {
|
|
|
- $intVal = (int)$value;
|
|
|
- if ($intVal < 1) {
|
|
|
- $this->addError($attribute, '规则ID参数错误');
|
|
|
- return;
|
|
|
- }
|
|
|
- $this->$attribute = $intVal;
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- $this->addError($attribute, '规则ID参数错误');
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* {@inheritdoc}
|
|
|
*/
|
|
|
public function attributeLabels()
|
|
|
{
|
|
|
return [
|
|
|
- 'id' => '规则ID',
|
|
|
- 'amount' => '充值金额',
|
|
|
'hbAmount' => '红包金额',
|
|
|
- 'num' => '红包张数',
|
|
|
+ 'hbNum' => '红包数量',
|
|
|
'miniCost' => '最低消费金额',
|
|
|
'duration' => '有效天数',
|
|
|
+ 'effectiveType' => '生效类型',
|
|
|
+ 'effectiveDate' => '生效日期',
|
|
|
+ 'effectiveDays' => '生效天数',
|
|
|
];
|
|
|
}
|
|
|
}
|