diff --git a/vendor/antgoods/goods/src/controllers/GoodsController.php b/vendor/antgoods/goods/src/controllers/GoodsController.php index 6ce0aa2..0731e6a 100644 --- a/vendor/antgoods/goods/src/controllers/GoodsController.php +++ b/vendor/antgoods/goods/src/controllers/GoodsController.php @@ -84,6 +84,7 @@ class GoodsController extends Controller public function actionCreate() { $model = new Goods(); + $model->is_sale = Goods::IS_SALE_YES; 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 f01302b..6fe2306 100644 --- a/vendor/antgoods/goods/src/models/ars/Goods.php +++ b/vendor/antgoods/goods/src/models/ars/Goods.php @@ -4,6 +4,9 @@ namespace antgoods\goods\models\ars; use Yii; use yii\behaviors\TimestampBehavior; +use antgoods\goods\models\ars\Category; +use antgoods\goods\models\ars\ShopCategory; +use common\models\ars\File; /** * This is the model class for table "antgoods_goods". @@ -61,8 +64,8 @@ class Goods extends \yii\db\ActiveRecord const SKU_MODE_ATTR = 1;//SKU类型属性 const SKU_MODE_MANUAL = 2;//SKU类型手写 public static $isSale = [ - self::IS_SALE_NO => '否', - self::IS_SALE_YES => '是' + self::IS_SALE_NO => '不在售', + self::IS_SALE_YES => '在售' ]; public $ruleVerify = 0;//规则验证是否通过 /** @@ -118,9 +121,9 @@ class Goods extends \yii\db\ActiveRecord return [ 'id' => 'id', 'pid' => '父级id', - 'cat_id' => '后台商品类别id', + 'cat_id' => '后台商品类别', 'brand_id' => '品牌id', - 'shop_cat_id' => '前端商品类别id', + 'shop_cat_id' => '前端商品类别', 'name' => '商品名称', 'sn' => '商品唯一货号', 'code' => '商品货码', @@ -139,9 +142,9 @@ class Goods extends \yii\db\ActiveRecord 'price' => '销售价', 'brief' => '简介', 'description' => '详细介绍', - 'image' => '图片id', + 'image' => '首页图片', 'model_id' => '模型id', - 'is_sale' => '该商品是否开放销售', + 'is_sale' => '销售状态', 'sort_order' => '排序', 'bouns_points' => '奖励积分', 'experience_points' => '经验值', @@ -186,4 +189,19 @@ class Goods extends \yii\db\ActiveRecord } return parent::beforeSave($insert); // TODO: Change the autogenerated stub } + + public function getCategory() + { + return $this->hasOne(Category::className(), ['id' => 'cat_id']); + } + + public function getShopCategory() + { + return $this->hasOne(ShopCategory::className(), ['id' => 'shop_cat_id']); + } + + public function getImageFile() + { + return $this->hasOne(File::className(), ['id' => 'image']); + } } diff --git a/vendor/antgoods/goods/src/models/searchs/GoodsSearch.php b/vendor/antgoods/goods/src/models/searchs/GoodsSearch.php index 41c5c29..3fbd782 100644 --- a/vendor/antgoods/goods/src/models/searchs/GoodsSearch.php +++ b/vendor/antgoods/goods/src/models/searchs/GoodsSearch.php @@ -6,6 +6,9 @@ use yii\base\Model; use yii\data\ActiveDataProvider; use yii\helpers\ArrayHelper; use antgoods\goods\models\ars\Goods; +use yii\bootstrap4\Html; +use antgoods\goods\models\ars\Category; +use antgoods\goods\models\ars\ShopCategory; /** * GoodsSearch represents the model behind the search form of `antgoods\goods\models\ars\Goods`. @@ -52,39 +55,56 @@ class GoodsSearch extends Goods 'width' => '2%', 'align' => 'center' ], - 'id', - 'pid', - 'cat_id', - 'brand_id', - 'shop_cat_id', - //'name', - //'sn', - //'code', - //'supplier_id', - //'weight', - //'length', - //'width', - //'height', - //'diameter', - //'unit', - //'sold_count', - //'limit_count', - //'stock', - //'stock_warn', - //'market_price', - //'price', - //'brief', - //'description', - //'image', - //'model_id', - //'is_sale', - //'sort_order', - //'bouns_points', - //'experience_points', - //'is_delete', - //'express_template', - //'created_at', - //'updated_at', + 'id', + ['attribute' => 'image', + 'contentOptions' => [ + 'align' => 'center', + ], + 'width'=>'10%', + 'format' => 'raw', + 'value' => function ($model) { + return $model->image ? + Html::img(['/'.$model->imageFile->path], ['style' => 'width:80px']) + : '
未设置
'; + + } + ], + 'name', + [ + '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' => 'stock', + 'width' => '5%', + 'value' => function ($model) { + if ($model->stock == -1) { + return '未开启'; + } else { + return $model->stock; + } + }, + ], + 'price', + ['attribute' => 'is_sale', + 'width' => '5%', + 'value' => + function ($model) { + return $model->is_sale ? Goods::$isSale[$model->is_sale] : '未设置'; + + }, + ], + 'updated_at:datetime', [ 'class' => 'iron\grid\ActionColumn', 'align' => 'center',