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
$size = \Yii::$app->request->get('size', 10);
$query = Notice::find()
->select('id, title, author, type, create_at')
->select('id, title, author, type, create_time')
->where(['status' => Notice::STATUS_ON])
->orderBy('create_at desc');
->orderBy('create_time desc');
if (false != $type) {
$query->andWhere(['type' => (int)$type]);
......@@ -90,7 +90,7 @@ class NoticeController extends BaseController
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';
$code = 0;
......
......@@ -16,6 +16,9 @@ class Notice extends BaseActiveRecord
const STATUS_ON = 1; //激活
const STATUS_OFF = 0; //未激活
const TYPE_ROLL = 1; //滚动
const TYPE_POP = 0; //弹窗
//定义场景
const SCENARIOS_CREATE = 'create';
const SCENARIOS_UPDATE = 'update';
......@@ -28,12 +31,32 @@ class Notice extends BaseActiveRecord
public function rules()
{
return [
[['title', 'content', 'type', 'platform_id'], 'required'],
[['author'], 'safe'],
[['status', 'status', 'platform_id'], 'integer'],
[['title', 'content', 'type', 'status', 'platform_id', 'author'], 'required'],
[['status', 'type', '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()
{
$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