Browse Source

修改后台商品字段

wechat_public_accounts
linyaostalker 5 years ago
parent
commit
36c55e2323
  1. 1
      vendor/antgoods/goods/src/controllers/GoodsController.php
  2. 30
      vendor/antgoods/goods/src/models/ars/Goods.php
  3. 84
      vendor/antgoods/goods/src/models/searchs/GoodsSearch.php

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

@ -84,6 +84,7 @@ class GoodsController extends Controller
public function actionCreate() public function actionCreate()
{ {
$model = new Goods(); $model = new Goods();
$model->is_sale = Goods::IS_SALE_YES;
if ($model->load(Yii::$app->request->post()) && $model->validate()) { if ($model->load(Yii::$app->request->post()) && $model->validate()) {
//商品封面图和商品详情图上传保存处理 //商品封面图和商品详情图上传保存处理
$res = GoodsManager::updateGoods(Yii::$app->request->post(), $model); $res = GoodsManager::updateGoods(Yii::$app->request->post(), $model);

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

@ -4,6 +4,9 @@ namespace antgoods\goods\models\ars;
use Yii; use Yii;
use yii\behaviors\TimestampBehavior; 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". * 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_ATTR = 1;//SKU类型属性
const SKU_MODE_MANUAL = 2;//SKU类型手写 const SKU_MODE_MANUAL = 2;//SKU类型手写
public static $isSale = [ public static $isSale = [
self::IS_SALE_NO => '',
self::IS_SALE_YES => ''
self::IS_SALE_NO => '不在售',
self::IS_SALE_YES => '在售'
]; ];
public $ruleVerify = 0;//规则验证是否通过 public $ruleVerify = 0;//规则验证是否通过
/** /**
@ -118,9 +121,9 @@ class Goods extends \yii\db\ActiveRecord
return [ return [
'id' => 'id', 'id' => 'id',
'pid' => '父级id', 'pid' => '父级id',
'cat_id' => '后台商品类别id',
'cat_id' => '后台商品类别',
'brand_id' => '品牌id', 'brand_id' => '品牌id',
'shop_cat_id' => '前端商品类别id',
'shop_cat_id' => '前端商品类别',
'name' => '商品名称', 'name' => '商品名称',
'sn' => '商品唯一货号', 'sn' => '商品唯一货号',
'code' => '商品货码', 'code' => '商品货码',
@ -139,9 +142,9 @@ class Goods extends \yii\db\ActiveRecord
'price' => '销售价', 'price' => '销售价',
'brief' => '简介', 'brief' => '简介',
'description' => '详细介绍', 'description' => '详细介绍',
'image' => '图片id',
'image' => '首页图片',
'model_id' => '模型id', 'model_id' => '模型id',
'is_sale' => '该商品是否开放销售',
'is_sale' => '销售状态',
'sort_order' => '排序', 'sort_order' => '排序',
'bouns_points' => '奖励积分', 'bouns_points' => '奖励积分',
'experience_points' => '经验值', 'experience_points' => '经验值',
@ -186,4 +189,19 @@ class Goods extends \yii\db\ActiveRecord
} }
return parent::beforeSave($insert); // TODO: Change the autogenerated stub 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']);
}
} }

84
vendor/antgoods/goods/src/models/searchs/GoodsSearch.php

@ -6,6 +6,9 @@ use yii\base\Model;
use yii\data\ActiveDataProvider; use yii\data\ActiveDataProvider;
use yii\helpers\ArrayHelper; use yii\helpers\ArrayHelper;
use antgoods\goods\models\ars\Goods; 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`. * GoodsSearch represents the model behind the search form of `antgoods\goods\models\ars\Goods`.
@ -53,38 +56,55 @@ class GoodsSearch extends Goods
'align' => 'center' 'align' => 'center'
], ],
'id', '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',
['attribute' => 'image',
'contentOptions' => [
'align' => 'center',
],
'width'=>'10%',
'format' => 'raw',
'value' => function ($model) {
return $model->image ?
Html::img(['/'.$model->imageFile->path], ['style' => 'width:80px'])
: '<div class="table_not_setting">未设置</div>';
}
],
'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', 'class' => 'iron\grid\ActionColumn',
'align' => 'center', 'align' => 'center',

Loading…
Cancel
Save