Browse Source

处理上传商品封面图片字段问题

wechat_public_accounts
linyaostalker 5 years ago
parent
commit
e71848e311
  1. 6
      vendor/antgoods/goods/src/controllers/GoodsController.php
  2. 6
      vendor/antgoods/goods/src/models/ars/Goods.php
  3. 8
      vendor/antgoods/goods/src/views/goods/_form.php

6
vendor/antgoods/goods/src/controllers/GoodsController.php

@ -82,7 +82,7 @@ class GoodsController extends Controller
$model = new Goods(); $model = new Goods();
if ($model->load(Yii::$app->request->post())) { if ($model->load(Yii::$app->request->post())) {
$file_id_str = $model->imageId;
$file_id_str = $model->coverImageId;
$model->save(); $model->save();
$goods_manager = new GoodsManager(); $goods_manager = new GoodsManager();
$save_file_res = $goods_manager->saveFile(explode(',', $file_id_str), $model); $save_file_res = $goods_manager->saveFile(explode(',', $file_id_str), $model);
@ -108,11 +108,11 @@ class GoodsController extends Controller
public function actionUpdate($id) public function actionUpdate($id)
{ {
$model = $this->findModel($id); $model = $this->findModel($id);
$model->imageId = $model->image;
$model->coverImageId = $model->image;
$old_id_arr = $model->image; $old_id_arr = $model->image;
if ($model->load(Yii::$app->request->post())) { if ($model->load(Yii::$app->request->post())) {
$file_id_str = $model->imageId;
$file_id_str = $model->coverImageId;
$model->save(); $model->save();
$goods_manager = new GoodsManager(); $goods_manager = new GoodsManager();
$save_file_res = $goods_manager->saveFile(explode(',', $file_id_str), $model, explode(',', $old_id_arr)); $save_file_res = $goods_manager->saveFile(explode(',', $file_id_str), $model, explode(',', $old_id_arr));

6
vendor/antgoods/goods/src/models/ars/Goods.php

@ -44,8 +44,8 @@ use yii\behaviors\TimestampBehavior;
*/ */
class Goods extends \yii\db\ActiveRecord class Goods extends \yii\db\ActiveRecord
{ {
public $imagePath;
public $imageId;
public $coverImagePath;
public $coverImageId;
//是否删除is_delete //是否删除is_delete
const IS_DELETE_NO = 0;//未删除 const IS_DELETE_NO = 0;//未删除
const IS_DELETE_YES = 1;//已删除 const IS_DELETE_YES = 1;//已删除
@ -73,7 +73,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'], [['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'], [['cat_id', 'brand_id', 'shop_cat_id', 'name'], 'required'],
[['sn'], 'checkExist'], [['sn'], 'checkExist'],
[['description', 'imageId'], 'string'],
[['description', 'coverImageId'], 'string'],
[['name'], 'string', 'max' => 120], [['name'], 'string', 'max' => 120],
[['sn'], 'string', 'max' => 60], [['sn'], 'string', 'max' => 60],
[['code'], 'string', 'max' => 50], [['code'], 'string', 'max' => 50],

8
vendor/antgoods/goods/src/views/goods/_form.php

@ -69,17 +69,17 @@ use yii\helpers\Url;
<?= $form->field($model, 'express_template')->textInput() ?> <?= $form->field($model, 'express_template')->textInput() ?>
<?= $form->field($model, 'imageId')->textInput()->label('') ?>
<?= $form->field($model, 'imagePath')->widget(\iron\widgets\Upload::className(), [
<?= $form->field($model, 'coverImageId')->textInput()->label('') ?>
<?= $form->field($model, 'coverImagePath')->widget(\iron\widgets\Upload::className(), [
'url' => 'upload', 'url' => 'upload',
'deleteUrl' => 'img-id-del', 'deleteUrl' => 'img-id-del',
'dragdropWidth'=> 800, 'dragdropWidth'=> 800,
'afterSave' => 'save-file', 'afterSave' => 'save-file',
'maxCount' => 1, 'maxCount' => 1,
'fillInAttribute' => 'imageId',
'fillInAttribute' => 'coverImageId',
'model' => $model, 'model' => $model,
'previewConfig' => [ 'previewConfig' => [
'url' => Url::to(['image-file', 'fileidstr' => $model->imageId]),
'url' => Url::to(['image-file', 'fileidstr' => $model->coverImageId]),
], ],
])->label('图片') ?> ])->label('图片') ?>

Loading…
Cancel
Save