| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- <?php
- namespace addons\StarChain\common\models;
- use Yii;
- /**
- * This is the model class for table "{{%addons_star_chain_goods_attr}}".
- *
- * @property int $id
- * @property int $mall_id
- * @property string $sku_id 商品线上SKU
- * @property int $mall_goods_id 商品表商品ID
- * @property string $chain_goods_id 供应链商品ID
- * @property int $attr_id 商品属性表ID
- * @property int $is_delete
- */
- class GoodsAttr extends BaseModel
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_star_chain_goods_attr}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'mall_goods_id', 'attr_id', 'is_delete'], 'integer'],
- [['sku_id', 'chain_goods_id'], 'string', 'max' => 64],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => 'Mall ID',
- 'sku_id' => 'Sku ID',
- 'mall_goods_id' => 'Mall Goods ID',
- 'chain_goods_id' => 'Chain Goods ID',
- 'attr_id' => 'Attr ID',
- 'is_delete' => 'Is Delete',
- ];
- }
- /**
- * 删除商品对应的Attr
- *
- * @param integer $goods_id
- * @return int
- */
- public static function removeGoodsAttr(int $goods_id)
- {
- return static::updateAll(['is_delete' => 1], ['mall_goods_id' => $goods_id]);
- }
- /**
- * 获取一个SKUID
- *
- * @param integer $goods_id
- * @param integer $attr_id
- * @return GoodsSkuModel
- */
- public static function getSku($goods_id, $attr_id, $field = null)
- {
- $model = self::find();
- $field && $model->select($field);
-
- return $model->where(['mall_goods_id' => $goods_id, 'attr_id' => $attr_id, 'is_delete' => 0])
- ->one();
- }
- /**
- * 通过SKUIDs获取SKU信息
- *
- * @param array $attr_id
- * @param string $field
- * @return array
- */
- public static function getSkuByAttrIDs(array $attr_id, string $field = '')
- {
- $model = self::find();
- $field && $model->select($field);
-
- return $model
- ->where(['attr_id' => $attr_id, 'is_delete' => 0])
- ->asArray()
- ->all();
- }
- }
|