request->get('id'); if (Yii::$app->request->isAjax) { Yii::$app->response->format = 'json'; $request = Yii::$app->request; $page = $request->get('page', 1); $limit = $request->get('limit', 10); $id = $request->get('id', ''); $where = []; if ($id) { $where[] = ['platform_withhold_id' => $id]; } $data = CoinSupportedSymbol::getList($page, $limit, $where); $data['code'] = 0; Yii::$app->response->format = 'json'; return $data; } return $this->render('index', ['platform_withhold_id' => $platform_withhold_id]); } public function actionAdd() { $model = new CoinSupportedSymbolForm(); $model->scenario = 'add'; if (Yii::$app->request->isPost) { $data = Yii::$app->request->post(); if ($model->load($data, '') && $model->validate()) { $coinSupportedSymbol = new CoinSupportedSymbol(); $coinSupportedSymbol->platform_withhold_id = $data['platform_withhold_id']; $coinSupportedSymbol->symbol = $data['symbol']; $result = $coinSupportedSymbol->save(); if ($result === true) { $this->success('添加成功', '/admin/coin-supported-symbol/list?id=' . $data['platform_withhold_id']); } } //表单验证失败 $errors = $model->errors; if ($errors) { foreach ($errors as $key => $item) { $errors = $item[0]; break; } } elseif (isset($result) && $result['code'] != 0) { $errors = $result['message']; } $this->error($errors, Yii::$app->request->getReferrer()); } $platform_withhold_id = Yii::$app->request->get('platform_withhold_id'); return $this->render('add', ['model' => $model, 'platform_withhold_id' => $platform_withhold_id]); } public function actionDelete() { Yii::$app->response->format = 'json'; $id = Yii::$app->request->get('id', 0); if ($id) { $model = CoinSupportedSymbol::findOne(['id' => $id]); if ($model) { try { $model->delete(); return ['code' => 0, 'msg' => 'succeed']; } catch (\Throwable $t) { return ['code' => $t->getCode(), 'msg' => $t->getMessage()]; } } } return ['code' => -1, 'msg' => '删除失败']; } }