From 0486802ad33a85a681cfbe7b6688f9e654b32aec Mon Sep 17 00:00:00 2001 From: linyaostalker <602604991@qq.com> Date: Mon, 25 Nov 2019 11:09:43 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=84=E7=90=86=E4=B8=A4=E4=B8=AA=E4=BB=A5?= =?UTF-8?q?=E4=B8=8A=E4=B8=8A=E4=BC=A0=E6=8F=92=E4=BB=B6=E5=9C=A8=E5=90=8C?= =?UTF-8?q?=E4=B8=80=E9=A1=B5=E9=9D=A2=E6=97=B6=E5=8F=82=E6=95=B0=E6=B7=B7?= =?UTF-8?q?=E4=B9=B1=E9=97=AE=E9=A2=98=EF=BC=8C=E5=AE=8C=E6=88=90=E5=95=86?= =?UTF-8?q?=E5=93=81=E5=B0=81=E9=9D=A2=E5=9B=BE=E5=92=8C=E5=95=86=E5=93=81?= =?UTF-8?q?=E8=AF=A6=E6=83=85=E5=9B=BE=E4=BF=9D=E5=AD=98=E4=B8=8A=E4=BC=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../goods/src/controllers/GoodsController.php | 26 ++++++++++++------- .../antgoods/goods/src/models/ars/Goods.php | 6 ++++- .../antgoods/goods/src/views/goods/_form.php | 16 +++++++++++- vendor/iron/widgets/Upload.php | 5 ++-- 4 files changed, 40 insertions(+), 13 deletions(-) diff --git a/vendor/antgoods/goods/src/controllers/GoodsController.php b/vendor/antgoods/goods/src/controllers/GoodsController.php index 9d7691d..bf65680 100644 --- a/vendor/antgoods/goods/src/controllers/GoodsController.php +++ b/vendor/antgoods/goods/src/controllers/GoodsController.php @@ -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); diff --git a/vendor/antgoods/goods/src/models/ars/Goods.php b/vendor/antgoods/goods/src/models/ars/Goods.php index 6dd092c..d446283 100644 --- a/vendor/antgoods/goods/src/models/ars/Goods.php +++ b/vendor/antgoods/goods/src/models/ars/Goods.php @@ -44,8 +44,12 @@ use yii\behaviors\TimestampBehavior; */ class Goods extends \yii\db\ActiveRecord { + //商品封面图 public $coverImagePath; public $coverImageId; + //商品详情图 + public $detailImagePath; + public $detailImageId; //是否删除is_delete const IS_DELETE_NO = 0;//未删除 const IS_DELETE_YES = 1;//已删除 @@ -73,7 +77,7 @@ class Goods extends \yii\db\ActiveRecord [['pid', 'cat_id', 'brand_id', 'shop_cat_id', 'supplier_id', 'weight', 'length', 'width', 'height', 'diameter', 'sold_count', 'limit_count', 'stock', 'stock_warn', 'market_price', 'price', 'image', 'model_id', 'is_sale', 'sort_order', 'bouns_points', 'experience_points', 'is_delete', 'express_template'], 'integer'], [['cat_id', 'brand_id', 'shop_cat_id', 'name'], 'required'], [['sn'], 'checkExist'], - [['description', 'coverImageId'], 'string'], + [['description', 'coverImageId', 'detailImageId'], 'string'], [['name'], 'string', 'max' => 120], [['sn'], 'string', 'max' => 60], [['code'], 'string', 'max' => 50], diff --git a/vendor/antgoods/goods/src/views/goods/_form.php b/vendor/antgoods/goods/src/views/goods/_form.php index d9db444..c758167 100644 --- a/vendor/antgoods/goods/src/views/goods/_form.php +++ b/vendor/antgoods/goods/src/views/goods/_form.php @@ -81,7 +81,21 @@ use yii\helpers\Url; 'previewConfig' => [ 'url' => Url::to(['image-file', 'fileidstr' => $model->coverImageId]), ], - ])->label('图片') ?> + ])->label('商品封面图') ?> + + field($model, 'detailImageId')->textInput()->label('') ?> + field($model, 'detailImagePath')->widget(\iron\widgets\Upload::className(), [ + 'url' => 'upload', + 'deleteUrl' => 'img-id-del', + 'dragdropWidth'=> 800, + 'afterSave' => 'save-file', + 'maxCount' => 5, + 'fillInAttribute' => 'detailImageId', + 'model' => $model, + 'previewConfig' => [ + 'url' => Url::to(['image-file', 'fileidstr' => $model->detailImageId]), + ], + ])->label('商品详情图') ?>
'btn btn-success']) ?> diff --git a/vendor/iron/widgets/Upload.php b/vendor/iron/widgets/Upload.php index 6f8b10e..0fbf994 100644 --- a/vendor/iron/widgets/Upload.php +++ b/vendor/iron/widgets/Upload.php @@ -171,7 +171,7 @@ class Upload extends InputWidget $view = $this->getView(); UploadAsset::register($view); $js = <<< SCRIPT - $("#upload-file").uploadFile({ + $("#upload-file-{$this->attribute}").uploadFile({ url:"upload", returnType: "json", multiple:true, @@ -214,6 +214,7 @@ class Upload extends InputWidget dataType: "json", success: function(data) { + console.log(data); for(var i=0;i -
+
Upload