type = $type; return $this->asJson($form->getList(get_store_id())); } // 幻灯片编辑 public function actionEdit() { $id = input_params('id'); $type = input_params('type') ?: Banner::TYPE_SAAS; $banner = Banner::findOne(['id' => $id, 'type' => $type]); if (!$banner) { $banner = new Banner(); } if (\Yii::$app->request->isPost) { $form = new SlideForm(); $form->attributes = post_params(); $form->store_id = get_store_id(); $form->banner = $banner; $form->type = $type; return $this->asJson($form->save()); } foreach ($banner as $index => $value) { $banner[$index] = str_replace("\"", """, $value); } return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => $banner ]); } // 幻灯片删除 public function actionDelete() { $id = input_params('id'); $type = !empty(input_params('type')) ?: Banner::TYPE_SAAS; $banner = Banner::findOne(['id' => $id, 'is_delete' => 0, 'type' => $type]); if (!$banner) { return $this->asJson([ 'code' => 1, 'msg' => '幻灯片不存在或已经删除', ]); } $banner->is_delete = 1; if ($banner->save()) { return $this->asJson([ 'code' => 0, 'msg' => '成功', ]); } else { foreach ($banner->errors as $errors) { return $this->asJson([ 'code' => 1, 'msg' => $errors[0], ]); } } } }