Commit b15e5f1e authored by shajiaiming's avatar shajiaiming

fix

parent f8efab9a
...@@ -16,6 +16,9 @@ class Notice extends BaseActiveRecord ...@@ -16,6 +16,9 @@ class Notice extends BaseActiveRecord
const STATUS_ON = 1; //激活 const STATUS_ON = 1; //激活
const STATUS_OFF = 0; //未激活 const STATUS_OFF = 0; //未激活
const TYPE_ROLL = 1; //滚动
const TYPE_POP = 0; //弹窗
//定义场景 //定义场景
const SCENARIOS_CREATE = 'create'; const SCENARIOS_CREATE = 'create';
const SCENARIOS_UPDATE = 'update'; const SCENARIOS_UPDATE = 'update';
...@@ -28,12 +31,32 @@ class Notice extends BaseActiveRecord ...@@ -28,12 +31,32 @@ class Notice extends BaseActiveRecord
public function rules() public function rules()
{ {
return [ return [
[['title', 'content', 'type', 'platform_id'], 'required'], [['title', 'content', 'type', 'status', 'platform_id', 'author'], 'required'],
[['author'], 'safe'], [['status', 'type', 'platform_id'], 'integer'],
[['status', 'status', 'platform_id'], 'integer'], ['type', 'verfiyType'],
]; ];
} }
public function verfiyType($attribute, $params)
{
if ('create' == self::getScenario()){
$count = self::find()->where(['platform_id' => $this->platform_id, 'type' => $this->type])->count();
if (Notice::TYPE_ROLL == $this->type) {
if ($count >= 3) {
$this->addError($attribute, '滚动公告最多只能3条');
return false;
}
}
if (Notice::TYPE_POP == $this->type) {
if ($count >= 1) {
$this->addError($attribute, '弹窗公告最多只能3条');
return false;
}
}
}
}
public function scenarios() public function scenarios()
{ {
$scenarios = [ $scenarios = [
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment