request->isAjax) { Yii::$app->response->format = 'json'; $request = Yii::$app->request; $page = $request->get('page', 1); $limit = $request->get('limit', 10); $name = $request->get('category_name', ''); $where = []; if($name){ $where[] = ['name' => $name]; } $data = CoinApplicationCategory::getList($page, $limit, $where); return $data; } return $this->render('index'); } /** * 添加一个application category */ public function actionAddAndEdit() { if (Yii::$app->request->isPost) { Yii::$app->response->format = 'json'; $fields = ['id','name','sort','icon','banner','banner_url']; $params = $this->initParams(Yii::$app->request->post(), $fields); $application_category = new CoinApplicationCategoryForm(); if($params['id']){ //edit $application_category->setScenario(CoinApplicationCategoryForm::SCENARIO_EDIT); $application_category->load($params,''); return $application_category->edit(); }else{ $application_category->setScenario(CoinApplicationCategoryForm::SCENARIO_ADD); $application_category->load($params,''); return $application_category->add(); } } } /** * @return array * @throws \Throwable * @throws \yii\db\StaleObjectException */ public function actionDelete() { Yii::$app->response->format = 'json'; $id = Yii::$app->request->get('id'); if ($id) { $application_category = new CoinApplicationCategoryForm(); return $application_category->del($id); } return ['code' => 1, 'msg' => 'failed']; } public function actionSetSort() { if (Yii::$app->request->isAjax) { Yii::$app->response->format = 'json'; $request = Yii::$app->request; $id = $request->get('id', ''); $sort = $request->get('sort',1); if($id){ $category = CoinApplicationCategory::getCategoryById($id); if(!$category){ return ['code' => 1,'msg' =>'分类不存在,不能设置排序']; } $category->sort=$sort; $category->save(); return ['code' => 0,'msg' => '分类排序设置成功']; }else{ return ['code' => 1 ,'msg' => '分类排序设置失败']; } } } }