|
@ -2,8 +2,8 @@ |
|
|
|
|
|
|
|
|
namespace backend\modules\goods\controllers; |
|
|
namespace backend\modules\goods\controllers; |
|
|
|
|
|
|
|
|
use backend\modules\goods\logic\goods\GoodsManager; |
|
|
|
|
|
use backend\modules\file\models\ars\File; |
|
|
use backend\modules\file\models\ars\File; |
|
|
|
|
|
use Exception; |
|
|
use Yii; |
|
|
use Yii; |
|
|
use backend\modules\goods\models\ars\Category; |
|
|
use backend\modules\goods\models\ars\Category; |
|
|
use backend\modules\goods\models\searchs\CategorySearch; |
|
|
use backend\modules\goods\models\searchs\CategorySearch; |
|
@ -11,6 +11,8 @@ 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; |
|
|
use backend\modules\file\logic\file\FileManager; |
|
|
|
|
|
use yii\web\Response; |
|
|
|
|
|
use iron\widget\Excel; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* CategoryController implements the CRUD actions for Category model. |
|
|
* CategoryController implements the CRUD actions for Category model. |
|
@ -73,7 +75,7 @@ class CategoryController extends Controller |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* @return string|yii\web\Response |
|
|
|
|
|
|
|
|
* @return string|Response |
|
|
* @throws Exception |
|
|
* @throws Exception |
|
|
*/ |
|
|
*/ |
|
|
public function actionCreate() |
|
|
public function actionCreate() |
|
@ -81,16 +83,13 @@ class CategoryController extends Controller |
|
|
$model = new Category(); |
|
|
$model = new Category(); |
|
|
$model->is_show = Category::IS_SHOW_DISPLAY; |
|
|
$model->is_show = Category::IS_SHOW_DISPLAY; |
|
|
$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()) { |
|
|
//类目图片上传保存处理
|
|
|
//类目图片上传保存处理
|
|
|
$res = FileManager::saveFileInModel($model, 'iconImageId', '', File::OWN_TYPE_CATEGORY_ICON, 'icon'); |
|
|
$res = FileManager::saveFileInModel($model, 'iconImageId', '', File::OWN_TYPE_CATEGORY_ICON, 'icon'); |
|
|
|
|
|
|
|
|
if ($res) { |
|
|
if ($res) { |
|
|
return $this->redirect('index'); |
|
|
return $this->redirect('index'); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return $this->render('create', [ |
|
|
return $this->render('create', [ |
|
|
'model' => $model, |
|
|
'model' => $model, |
|
|
]); |
|
|
]); |
|
@ -102,6 +101,7 @@ class CategoryController extends Controller |
|
|
* @param integer $id |
|
|
* @param integer $id |
|
|
* @return mixed |
|
|
* @return mixed |
|
|
* @throws NotFoundHttpException if the model cannot be found |
|
|
* @throws NotFoundHttpException if the model cannot be found |
|
|
|
|
|
* @throws Exception |
|
|
*/ |
|
|
*/ |
|
|
public function actionUpdate($id) |
|
|
public function actionUpdate($id) |
|
|
{ |
|
|
{ |
|
@ -109,16 +109,13 @@ class CategoryController extends Controller |
|
|
$model->iconImageId = $model->icon; |
|
|
$model->iconImageId = $model->icon; |
|
|
//记录已保存的类目图片id,用于修改
|
|
|
//记录已保存的类目图片id,用于修改
|
|
|
$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()) { |
|
|
//类目图片上传保存处理
|
|
|
//类目图片上传保存处理
|
|
|
$res = FileManager::saveFileInModel($model, 'iconImageId', $icon_image_old_id_arr, File::OWN_TYPE_CATEGORY_ICON, 'icon'); |
|
|
$res = FileManager::saveFileInModel($model, 'iconImageId', $icon_image_old_id_arr, File::OWN_TYPE_CATEGORY_ICON, 'icon'); |
|
|
|
|
|
|
|
|
if ($res) { |
|
|
if ($res) { |
|
|
return $this->redirect('index'); |
|
|
return $this->redirect('index'); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return $this->render('update', [ |
|
|
return $this->render('update', [ |
|
|
'model' => $model, |
|
|
'model' => $model, |
|
|
]); |
|
|
]); |
|
@ -169,7 +166,7 @@ class CategoryController extends Controller |
|
|
} else { |
|
|
} else { |
|
|
$dataProvider = $searchModel->search($params); |
|
|
$dataProvider = $searchModel->search($params); |
|
|
} |
|
|
} |
|
|
\iron\widget\Excel::export([ |
|
|
|
|
|
|
|
|
Excel::export([ |
|
|
'models' => $dataProvider->getModels(), |
|
|
'models' => $dataProvider->getModels(), |
|
|
'format' => 'Xlsx', |
|
|
'format' => 'Xlsx', |
|
|
'asAttachment' => true, |
|
|
'asAttachment' => true, |
|
@ -184,19 +181,12 @@ class CategoryController extends Controller |
|
|
public function actionSaveFile() |
|
|
public function actionSaveFile() |
|
|
{ |
|
|
{ |
|
|
$data = Yii::$app->request->get('data'); |
|
|
$data = Yii::$app->request->get('data'); |
|
|
$file_name = Yii::$app->request->get('fileName')[0]; |
|
|
|
|
|
|
|
|
$fileName = Yii::$app->request->get('fileName')[0]; |
|
|
|
|
|
|
|
|
if ($data['status'] == true) { |
|
|
if ($data['status'] == true) { |
|
|
$model = new \backend\modules\file\models\ars\TemFile(); |
|
|
|
|
|
$model->user_id = Yii::$app->user->identity->id; |
|
|
|
|
|
$model->name = $file_name; |
|
|
|
|
|
$file_manager = new \backend\modules\file\logic\file\FileManager(); |
|
|
|
|
|
$model->type = $file_manager->searchType(pathinfo($data['path'])['extension']); |
|
|
|
|
|
$model->alias = $data['alias']; |
|
|
|
|
|
$model->path = $data['path']; |
|
|
|
|
|
$model->save(); |
|
|
|
|
|
return $model->id; |
|
|
|
|
|
|
|
|
return FileManager::saveTemFile($fileName, $data); |
|
|
} |
|
|
} |
|
|
|
|
|
return false; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
@ -205,24 +195,8 @@ class CategoryController extends Controller |
|
|
*/ |
|
|
*/ |
|
|
public function actionImgIdDel() |
|
|
public function actionImgIdDel() |
|
|
{ |
|
|
{ |
|
|
$img_id = Yii::$app->request->get('imgid'); |
|
|
|
|
|
$img_id_arr = explode(',', $img_id); |
|
|
|
|
|
if(isset(Yii::$app->request->get('data')['alias'])) { |
|
|
|
|
|
$alias = Yii::$app->request->get('data')['alias']; |
|
|
|
|
|
$tem_file = \backend\modules\file\models\ars\TemFile::findOne(['alias' => $alias]); |
|
|
|
|
|
if ($tem_file) { |
|
|
|
|
|
$img_id_arr = array_diff($img_id_arr, [$tem_file->id]); |
|
|
|
|
|
} |
|
|
|
|
|
}else{ |
|
|
|
|
|
foreach (Yii::$app->request->get() as $key => $value) { |
|
|
|
|
|
$tem_file = \backend\modules\file\models\ars\File::findOne(['alias' => $value]); |
|
|
|
|
|
if ($tem_file) { |
|
|
|
|
|
$img_id_arr = array_diff($img_id_arr, [$tem_file->id]); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
$img_id_str = implode(',', $img_id_arr); |
|
|
|
|
|
return $img_id_str; |
|
|
|
|
|
|
|
|
$data = Yii::$app->request->get(); |
|
|
|
|
|
return FileManager::dealFileIdStrInDel($data); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
@ -231,19 +205,7 @@ class CategoryController extends Controller |
|
|
*/ |
|
|
*/ |
|
|
public function actionImageFile() |
|
|
public function actionImageFile() |
|
|
{ |
|
|
{ |
|
|
$file_id_str = Yii::$app->request->get('fileidstr'); |
|
|
|
|
|
$file_id_arr = explode(',', $file_id_str); |
|
|
|
|
|
$data = \backend\modules\file\models\ars\File::find()->where(['id' => $file_id_arr])->all(); |
|
|
|
|
|
$res = array(); |
|
|
|
|
|
if($data) { |
|
|
|
|
|
$i = 0; |
|
|
|
|
|
foreach ($data as $key => $value) { |
|
|
|
|
|
$res[$i]['name'] = $value->alias; |
|
|
|
|
|
$res[$i]['path'] = Yii::$app->request->hostInfo . '/' . $value->path; |
|
|
|
|
|
$res[$i]['size'] = filesize($value->path); |
|
|
|
|
|
$i++; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
return json_encode($res); |
|
|
|
|
|
|
|
|
$fileIdStr = Yii::$app->request->get('fileIdStr'); |
|
|
|
|
|
return FileManager::loadExitFile($fileIdStr); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |