| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\modules\admin\controllers;
- use app\models\Banner;
- use app\modules\admin\models\SlideForm;
- use yii\base\BaseObject;
- class SlideController extends BaseController
- {
- // 幻灯片列表
- public function actionList()
- {
- $type = !empty(get_params('type')) ?: Banner::TYPE_SAAS;
- $form = new SlideForm();
- $form->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],
- ]);
- }
- }
- }
- }
|