Browse Source

refactor:重构后台分类控制器代码,将业务逻辑剥离

antshop
linyaostalker 5 years ago
parent
commit
ab2d67188d
  1. 27
      backend/modules/goods/controllers/CategoryController.php

27
backend/modules/goods/controllers/CategoryController.php

@ -10,6 +10,7 @@ use backend\modules\goods\models\searchs\CategorySearch;
use yii\web\Controller; use yii\web\Controller;
use yii\web\NotFoundHttpException; use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter; use yii\filters\VerbFilter;
use backend\modules\file\logic\file\FileManager;
/** /**
* CategoryController implements the CRUD actions for Category model. * CategoryController implements the CRUD actions for Category model.
@ -82,17 +83,12 @@ class CategoryController extends Controller
$model->sort_order = 0; $model->sort_order = 0;
if ($model->load(Yii::$app->request->post()) && $model->validate()) { if ($model->load(Yii::$app->request->post()) && $model->validate()) {
//类目图片上传保存处理 //类目图片上传保存处理
$icon_image_id_str = $model->iconImageId;
$model->save();
$save_icon_image_res = GoodsManager::saveFile(explode(',', $icon_image_id_str), $model, [], File::OWN_TYPE_CATEGORY_ICON);
if($save_icon_image_res['status']){
$model->icon = $save_icon_image_res['first_file_id'];
$model->save();
}
$res = FileManager::saveFileInModel($model, 'iconImageId', '', File::OWN_TYPE_CATEGORY_ICON, 'icon');
return $this->redirect('index');
if ($res) {
return $this->redirect('index');
}
} }
return $this->render('create', [ return $this->render('create', [
@ -115,17 +111,12 @@ class CategoryController extends Controller
$icon_image_old_id_arr = $model->icon; $icon_image_old_id_arr = $model->icon;
if ($model->load(Yii::$app->request->post()) && $model->validate()) { if ($model->load(Yii::$app->request->post()) && $model->validate()) {
//类目图片上传保存处理 //类目图片上传保存处理
$icon_image_id_str = $model->iconImageId;
$model->save();
$save_icon_image_res = GoodsManager::saveFile(explode(',', $icon_image_id_str), $model, explode(',', $icon_image_old_id_arr), File::OWN_TYPE_CATEGORY_ICON);
if($save_icon_image_res['status'] && $save_icon_image_res['first_file_id'] !== 0){
$model->icon = $save_icon_image_res['first_file_id'];
$model->save();
}
$res = FileManager::saveFileInModel($model, 'iconImageId', $icon_image_old_id_arr, File::OWN_TYPE_CATEGORY_ICON, 'icon');
return $this->redirect('index');
if ($res) {
return $this->redirect('index');
}
} }
return $this->render('update', [ return $this->render('update', [

Loading…
Cancel
Save