diff --git a/backend/modules/goods/controllers/CategoryController.php b/backend/modules/goods/controllers/CategoryController.php index 6fc6aae..0233de9 100755 --- a/backend/modules/goods/controllers/CategoryController.php +++ b/backend/modules/goods/controllers/CategoryController.php @@ -10,6 +10,7 @@ use backend\modules\goods\models\searchs\CategorySearch; use yii\web\Controller; use yii\web\NotFoundHttpException; use yii\filters\VerbFilter; +use backend\modules\file\logic\file\FileManager; /** * CategoryController implements the CRUD actions for Category model. @@ -82,17 +83,12 @@ class CategoryController extends Controller $model->sort_order = 0; 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', [ @@ -115,17 +111,12 @@ class CategoryController extends Controller $icon_image_old_id_arr = $model->icon; 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', [