From ffb468659b9896288beaf76c511ae94d2be25b46 Mon Sep 17 00:00:00 2001 From: linyaostalker <602604991@qq.com> Date: Fri, 29 Nov 2019 14:03:06 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E5=95=86=E5=93=81=E8=AF=A6?= =?UTF-8?q?=E6=83=85=E9=A1=B5=E9=9D=A2=E5=88=97=E8=A1=A8=E5=AD=97=E6=AE=B5?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../goods/src/controllers/GoodsController.php | 1 + .../antgoods/goods/src/models/ars/Goods.php | 16 +++- .../antgoods/goods/src/views/goods/view.php | 90 +++++++++++++++---- 3 files changed, 87 insertions(+), 20 deletions(-) diff --git a/vendor/antgoods/goods/src/controllers/GoodsController.php b/vendor/antgoods/goods/src/controllers/GoodsController.php index 0731e6a..b239827 100644 --- a/vendor/antgoods/goods/src/controllers/GoodsController.php +++ b/vendor/antgoods/goods/src/controllers/GoodsController.php @@ -85,6 +85,7 @@ class GoodsController extends Controller { $model = new Goods(); $model->is_sale = Goods::IS_SALE_YES; + $model->stock = -1; if ($model->load(Yii::$app->request->post()) && $model->validate()) { //商品封面图和商品详情图上传保存处理 $res = GoodsManager::updateGoods(Yii::$app->request->post(), $model); diff --git a/vendor/antgoods/goods/src/models/ars/Goods.php b/vendor/antgoods/goods/src/models/ars/Goods.php index 6fe2306..e94430c 100644 --- a/vendor/antgoods/goods/src/models/ars/Goods.php +++ b/vendor/antgoods/goods/src/models/ars/Goods.php @@ -7,6 +7,8 @@ use yii\behaviors\TimestampBehavior; use antgoods\goods\models\ars\Category; use antgoods\goods\models\ars\ShopCategory; use common\models\ars\File; +use antgoods\goods\models\ars\Brand; +use antgoods\goods\models\ars\Supplier; /** * This is the model class for table "antgoods_goods". @@ -122,12 +124,12 @@ class Goods extends \yii\db\ActiveRecord 'id' => 'id', 'pid' => '父级id', 'cat_id' => '后台商品类别', - 'brand_id' => '品牌id', + 'brand_id' => '品牌', 'shop_cat_id' => '前端商品类别', 'name' => '商品名称', 'sn' => '商品唯一货号', 'code' => '商品货码', - 'supplier_id' => '供应商id', + 'supplier_id' => '供应商', 'weight' => '重量', 'length' => '长度', 'width' => '宽度', @@ -204,4 +206,14 @@ class Goods extends \yii\db\ActiveRecord { return $this->hasOne(File::className(), ['id' => 'image']); } + + public function getBrand() + { + return $this->hasOne(Brand::className(), ['id' => 'brand_id']); + } + + public function getSupplier() + { + return $this->hasOne(Supplier::className(), ['id' => 'supplier_id']); + } } diff --git a/vendor/antgoods/goods/src/views/goods/view.php b/vendor/antgoods/goods/src/views/goods/view.php index 5f51770..4b74e44 100644 --- a/vendor/antgoods/goods/src/views/goods/view.php +++ b/vendor/antgoods/goods/src/views/goods/view.php @@ -1,7 +1,9 @@ params['breadcrumbs'][] = $this->title; 'model' => $model, 'attributes' => [ 'id', - 'pid', - 'cat_id', - 'brand_id', - 'shop_cat_id', 'name', 'sn', + [ + 'attribute' => 'cat_id', + 'width' => '10%', + 'value' => function ($model) { + return $model->category ? $model->category->name : ''; + }, + ], + [ + 'attribute' => 'shop_cat_id', + 'width' => '10%', + 'value' => function ($model) { + return $model->shopCategory ? $model->shopCategory->name : ''; + }, + ], + [ + 'attribute' => 'brand_id', + 'width' => '10%', + 'value' => function ($model) { + return $model->brand ? $model->brand->name : ''; + }, + ], 'code', - 'supplier_id', + [ + 'attribute' => 'supplier_id', + 'width' => '10%', + 'value' => function ($model) { + return $model->supplier ? $model->supplier->name : ''; + }, + ], 'weight', 'length', 'width', 'height', 'diameter', 'unit', - 'sold_count', - 'limit_count', - 'stock', - 'stock_warn', + [ + 'attribute' => 'stock', + 'width' => '5%', + 'value' => function ($model) { + if ($model->stock == -1) { + return '未开启'; + } else { + return $model->stock; + } + }, + ], 'market_price', 'price', 'brief', - 'description:ntext', - 'image', - 'model_id', - 'is_sale', + ['attribute' => 'image', + 'format' => 'raw', + 'value' => function ($model) { + return $model->image ? + Html::img(['/'.$model->imageFile->path], ['style' => 'width:80px']) + : '
未设置
'; + + } + ], + [ + 'label' => '详情图', + 'format' => 'raw', + 'value' => function ($model) { + $image = ''; + $imgs = File::findAll(['own_id' => $model->id, 'own_type' => File::OWN_TYPE_GOODS_DETAILS, 'is_delete' => File::IS_DELETE_NO]); + foreach ($imgs as $img) { + $image .= Html::img(['/'.$img->path], ['style' => 'width:150px']); + } + return $image; + + } + ], + ['attribute' => 'is_sale', + 'width' => '5%', + 'value' => + function ($model) { + return $model->is_sale ? Goods::$isSale[$model->is_sale] : '未设置'; + + }, + ], 'sort_order', - 'bouns_points', - 'experience_points', - 'is_delete', - 'express_template', 'created_at:datetime', 'updated_at:datetime', ],