|
|
@ -11,6 +11,7 @@ use yii\web\Controller; |
|
|
|
use yii\web\NotFoundHttpException; |
|
|
|
use yii\filters\VerbFilter; |
|
|
|
use antgoods\goods\logic\goods\GoodsManager; |
|
|
|
use common\models\ars\File; |
|
|
|
|
|
|
|
/** |
|
|
|
* GoodsController implements the CRUD actions for Goods model. |
|
|
@ -82,12 +83,14 @@ class GoodsController extends Controller |
|
|
|
$model = new Goods(); |
|
|
|
|
|
|
|
if ($model->load(Yii::$app->request->post())) { |
|
|
|
$file_id_str = $model->coverImageId; |
|
|
|
$cover_image_id_str = $model->coverImageId; |
|
|
|
$detail_image_id_str = $model->detailImageId; |
|
|
|
$model->save(); |
|
|
|
$goods_manager = new GoodsManager(); |
|
|
|
$save_file_res = $goods_manager->saveFile(explode(',', $file_id_str), $model); |
|
|
|
if($save_file_res['status']){ |
|
|
|
$model->image = $save_file_res['first_file_id']; |
|
|
|
$save_cover_image_res = $goods_manager->saveFile(explode(',', $cover_image_id_str), $model); |
|
|
|
$save_detail_image_res = $goods_manager->saveFile(explode(',', $detail_image_id_str), $model, [], File::OWN_TYPE_GOODS_DETAILS); |
|
|
|
if($save_cover_image_res['status'] && $save_detail_image_res['status']){ |
|
|
|
$model->image = $save_cover_image_res['first_file_id']; |
|
|
|
$model->save(); |
|
|
|
} |
|
|
|
return $this->redirect('index'); |
|
|
@ -109,15 +112,19 @@ class GoodsController extends Controller |
|
|
|
{ |
|
|
|
$model = $this->findModel($id); |
|
|
|
$model->coverImageId = $model->image; |
|
|
|
$old_id_arr = $model->image; |
|
|
|
$model->detailImageId = implode(',', File::find()->select('id')->where(['is_delete' => File::IS_DELETE_NO, 'own_id' => $model->id, 'own_type' => File::OWN_TYPE_GOODS_DETAILS])->column()); |
|
|
|
$cover_image_old_id_arr = $model->image; |
|
|
|
$detail_image_old_id_arr = $model->detailImageId; |
|
|
|
|
|
|
|
if ($model->load(Yii::$app->request->post())) { |
|
|
|
$file_id_str = $model->coverImageId; |
|
|
|
$cover_image_id_str = $model->coverImageId; |
|
|
|
$detail_image_id_str = $model->detailImageId; |
|
|
|
$model->save(); |
|
|
|
$goods_manager = new GoodsManager(); |
|
|
|
$save_file_res = $goods_manager->saveFile(explode(',', $file_id_str), $model, explode(',', $old_id_arr)); |
|
|
|
if($save_file_res['status']){ |
|
|
|
$model->image = $save_file_res['first_file_id']; |
|
|
|
$save_cover_image_res = $goods_manager->saveFile(explode(',', $cover_image_id_str), $model, explode(',', $cover_image_old_id_arr)); |
|
|
|
$save_detail_image_res = $goods_manager->saveFile(explode(',', $detail_image_id_str), $model, explode(',', $detail_image_old_id_arr), File::OWN_TYPE_GOODS_DETAILS); |
|
|
|
if($save_cover_image_res['status'] && $save_detail_image_res['status']){ |
|
|
|
$model->image = $save_cover_image_res['first_file_id']; |
|
|
|
$model->save(); |
|
|
|
} |
|
|
|
return $this->redirect('index'); |
|
|
@ -255,6 +262,7 @@ class GoodsController extends Controller |
|
|
|
$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); |
|
|
|