Commit ba95e997 authored by rlgy's avatar rlgy

api公告新闻

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