Commit 15cd33ce authored by shajiaiming's avatar shajiaiming

置顶公告

parent 00d91e80
...@@ -44,7 +44,7 @@ class NoticeController extends BaseController ...@@ -44,7 +44,7 @@ class NoticeController extends BaseController
$size = \Yii::$app->request->get('size', 10); $size = \Yii::$app->request->get('size', 10);
$query = Notice::find() $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]) ->where(['status' => Notice::STATUS_ON])
->orderBy('create_time desc'); ->orderBy('create_time desc');
......
...@@ -32,14 +32,24 @@ class Notice extends BaseActiveRecord ...@@ -32,14 +32,24 @@ class Notice extends BaseActiveRecord
{ {
return [ return [
[['title', 'content', 'type', 'status', 'platform_id', 'author'], 'required'], [['title', 'content', 'type', 'status', 'platform_id', 'author'], 'required'],
[['status', 'type', 'platform_id'], 'integer'], [['status', 'type', 'platform_id', 'is_top'], 'integer'],
['type', 'verfiyType'], ['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) 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(); $count = self::find()->where(['platform_id' => $this->platform_id, 'type' => $this->type])->count();
if (Notice::TYPE_ROLL == $this->type) { if (Notice::TYPE_ROLL == $this->type) {
if ($count >= 3) { if ($count >= 3) {
......
...@@ -82,7 +82,7 @@ class NoticeController extends BaseController ...@@ -82,7 +82,7 @@ class NoticeController extends BaseController
if (Yii::$app->request->isGet) { if (Yii::$app->request->isGet) {
$id = Yii::$app->request->get('id'); $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; 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