request->get(); $query = Region::find()->where(['level'=>1]); $this->field = [ Region::class => [ 'id', 'name', 'pid', 'level', 'express_fee' ] ]; return $this->create($query, $get); } /** * @doc-name 编辑快递费 * @doc-param int id id * @doc-param float express_fee 快递费 */ public function actionEditFee() { $post = \Yii::$app->request->post(); $this->requestValidate($post, [ [['id', 'express_fee'], 'required'], ]); $Region = Region::find()->where(['id' => $post['id']])->one(); if (!$Region) throw new Exception('地区不存在'); $Region->express_fee = $post['express_fee']; if (!$Region->saveOrFail()) { throw new Exception('修改失败'); }; return ['修改成功']; } /** * @doc-name 地区列表 */ public function actionAllRegionList() { $Region = Region::find()->asArray()->all(); return ArrayHelper::list_to_tree($Region, 'id', 'pid', 'children'); } }