request; $page = $request->post('page', 1); $limit = $request->post('limit', 10); $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($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); return $data; } public function actionIndex() { $id = Yii::$app->request->get('id', ''); $page = Yii::$app->request->get('page', 1); $size = Yii::$app->request->get('size', 10); $exchange = Yii::$app->request->get('exchange', 'zhaobi'); $exchange_arr = ['huobi', 'binance', 'okex', 'zhaobi']; if (!in_array($exchange, $exchange_arr)) { $msg = '不存在的交易平台'; $code = -1; $data = []; goto doEnd; } $params = [ 'id' => $id, 'page' => $page, 'size' => $size ]; $builder = ExchangeBuilderFactory::create($exchange); $result = $builder->getNotice($params); $code = $result['code']; $data = $result['notice']; $msg = isset($result['msg']) ? $result['msg'] : 'success'; doEnd : return ['code' => $code, 'msg' => $msg, 'data' => $data]; } }