Commit fbbd5525 authored by shajiaiming's avatar shajiaiming

Merge branch 'feature/optimize' into develop

parents 1bdabc9a 907b6142
...@@ -44,9 +44,9 @@ class NoticeController extends BaseController ...@@ -44,9 +44,9 @@ 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, author, type, create_at') ->select('id, title, author, type, create_time')
->where(['status' => Notice::STATUS_ON]) ->where(['status' => Notice::STATUS_ON])
->orderBy('create_at desc'); ->orderBy('create_time desc');
if (false != $type) { if (false != $type) {
$query->andWhere(['type' => (int)$type]); $query->andWhere(['type' => (int)$type]);
...@@ -90,7 +90,7 @@ class NoticeController extends BaseController ...@@ -90,7 +90,7 @@ class NoticeController extends BaseController
goto doEnd; goto doEnd;
} }
$data = Notice::find()->select('title,content,author,type,create_at')->where(['id' => $id, 'platform_id' => $platform_id])->asArray()->one(); $data = Notice::find()->select('title,content,author,type,create_time')->where(['id' => $id, 'platform_id' => $platform_id])->asArray()->one();
$msg = 'ok'; $msg = 'ok';
$code = 0; $code = 0;
......
...@@ -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