Commit ba95e997 authored by rlgy's avatar rlgy

api公告新闻

parent 112e259f
...@@ -15,11 +15,6 @@ class BaseResponse extends Response ...@@ -15,11 +15,6 @@ class BaseResponse extends Response
public function send() public function send()
{ {
//TODO 错误处理 //TODO 错误处理
$this->data = [
'code' => 0,
'msg' => '',
'data' => $this->data,
];
parent::send(); parent::send();
} }
} }
\ No newline at end of file
...@@ -25,8 +25,11 @@ return [ ...@@ -25,8 +25,11 @@ return [
'baseUrl' => '/interface', 'baseUrl' => '/interface',
'cookieValidationKey' => '123456', 'cookieValidationKey' => '123456',
'enableCsrfValidation' => false, 'enableCsrfValidation' => false,
'parsers' => [ 'parsers' => [
'application/json' => 'yii\web\JsonParser', 'application/json' => [
'class' => 'yii\web\JsonParser',
'throwException' => false,//json格式错误不报错
],
], ],
], ],
'response' => [ 'response' => [
......
...@@ -31,14 +31,38 @@ class NoticeController extends BaseController ...@@ -31,14 +31,38 @@ class NoticeController extends BaseController
$request = Yii::$app->request; $request = Yii::$app->request;
$page = $request->post('page', 1); $page = $request->post('page', 1);
$limit = $request->post('limit', 10); $limit = $request->post('limit', 10);
$condition = $request->post(); $post = $request->post();
if (isset($condition['page'])) { $condition = [];
unset($condition['page']);
$post = array_filter($post, function ($value, $key) {
if ($key == 'status' && is_numeric($value)) {
return true;
}
if ($key == 'id' && is_numeric($value)) {
return true;
}
return $value;
}, ARRAY_FILTER_USE_BOTH);
if (isset($post['id'])) {
$condition[] = ['id' => $post['id']];
}
if (isset($post['title'])) {
$condition[] = ['like', 'title', $post['title']];
}
if (isset($post['author'])) {
$condition[] = ['author' => $post['author']];
} }
if (isset($condition['limit'])) { if (isset($post['status'])) {
unset($condition['limit']); $condition[] = ['status' => $post['status']];
} }
$data = Notice::getList($page, $limit, $condition); if (isset($post['create_at'])) {
$condition[] = ['>=', 'create_at', $post['create_at']];
}
if (isset($post['update_at'])) {
$condition[] = ['>=', 'update_at', $post['update_at']];
}
$data = Notice::getList($page, $limit, $condition);
Yii::$app->response->data = $data; Yii::$app->response->data = $data;
} }
} }
\ No newline at end of file
...@@ -35,7 +35,7 @@ class Article extends BaseActiveRecord ...@@ -35,7 +35,7 @@ class Article extends BaseActiveRecord
{ {
$query = self::find(); $query = self::find();
foreach ($condition as $item) { foreach ($condition as $item) {
$query = $query->andFilterWhere($item); $query = $query->andWhere($item);
} }
$count = $query->count(); $count = $query->count();
if ($count) { if ($count) {
......
...@@ -22,7 +22,7 @@ class Notice extends BaseActiveRecord ...@@ -22,7 +22,7 @@ class Notice extends BaseActiveRecord
{ {
$query = self::find(); $query = self::find();
foreach ($condition as $item) { foreach ($condition as $item) {
$query = $query->andFilterWhere($item); $query = $query->andWhere($item);
} }
$count = $query->count(); $count = $query->count();
if ($count) { if ($count) {
......
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