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('商品封面图') ?> + + = $form->field($model, 'detailImageId')->textInput()->label('') ?> + = $form->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('商品详情图') ?>