Commit 15cd33ce authored by shajiaiming's avatar shajiaiming

置顶公告

parent 00d91e80
......@@ -44,7 +44,7 @@ class NoticeController extends BaseController
$size = \Yii::$app->request->get('size', 10);
$query = Notice::find()
->select('id, title, content, author, type, create_time')
->select('id, title, content, author, type, is_top, create_time')
->where(['status' => Notice::STATUS_ON])
->orderBy('create_time desc');
......
......@@ -32,14 +32,24 @@ class Notice extends BaseActiveRecord
{
return [
[['title', 'content', 'type', 'status', 'platform_id', 'author'], 'required'],
[['status', 'type', 'platform_id'], 'integer'],
['type', 'verfiyType'],
[['status', 'type', 'platform_id', 'is_top'], 'integer'],
['is_top', 'verfiyIsTop'],
['type', 'verfiyType']
];
}
public function verfiyIsTop($attribute, $params)
{
$count = self::find()->where(['platform_id' => $this->platform_id, 'is_top' => $this->is_top])->count();
if ($count >= 1) {
$this->addError($attribute, '置顶公告只能1条');
return false;
}
}
public function verfiyType($attribute, $params)
{
if ('create' == self::getScenario()){
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) {
......
......@@ -82,7 +82,7 @@ class NoticeController extends BaseController
if (Yii::$app->request->isGet) {
$id = Yii::$app->request->get('id');
$data = Notice::find()->select('id, title, content, author, status, type')->where(['platform_id' => $platform_id, 'id' => $id])->asArray()->one();
$data = Notice::find()->select('id, title, content, author, status, type, is_top')->where(['platform_id' => $platform_id, 'id' => $id])->asArray()->one();
goto doEnd;
}
......
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