'trim'], [['days'], 'default', 'value' => 0], [['count'], 'default', 'value' => 1], [['remark', 'effectiveDate', 'name', 'scopeValue'], 'default', 'value' => ''], [['scopeType'], 'default', 'value' => 1], [['specialApplicable'], 'default', 'value' => 1], ]; } /** * 业务校验:新旧两种入参至少满足一种 */ public function validateForm() { if (!parent::validateForm()) { return false; } $hasNew = !empty($this->customs) || !empty($this->rules); if ($hasNew) { if (empty($this->customs) || !is_array($this->customs)) { $this->addError('customs', '请选择客户'); return $this->failFirstError(); } if (empty($this->rules) || !is_array($this->rules)) { $this->addError('rules', '请至少配置一个红包'); return $this->failFirstError(); } return true; } // 旧版必填 if (empty($this->userId)) { $this->addError('userId', '请选择用户'); return $this->failFirstError(); } if (empty($this->customId)) { $this->addError('customId', '请选择客户'); return $this->failFirstError(); } if ($this->amount === null || $this->amount === '' || floatval($this->amount) < 0.01) { $this->addError('amount', '请填写红包金额'); return $this->failFirstError(); } if ($this->minConsume === null || $this->minConsume === '') { $this->addError('minConsume', '请填写最低消费金额'); return $this->failFirstError(); } return true; } protected function failFirstError() { $errors = $this->getFirstErrors(); $msg = $errors ? reset($errors) : '参数错误'; \common\components\util::fail($msg); return false; } public function attributeLabels() { return [ 'userId' => '用户ID', 'customId' => '客户ID', 'customs' => '客户列表', 'rules' => '红包规则', 'amount' => '红包金额', 'minConsume' => '最低消费', 'days' => '有效时长', 'count' => '红包个数', 'effectiveDate' => '生效时间', 'remark' => '备注信息', 'name' => '红包名称', 'scopeType' => '适用范围', 'scopeValue' => '适用范围内容', 'specialApplicable' => '特价活动是否适用', ]; } }