| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- <?php
- namespace addons\QiJuhe\common\models;
- /**
- * This is the model class for table "{{%addons_qijuhe_goods_new}}".
- *
- * @property int $id
- * @property int|null $mall_id
- * @property int|null $supply_id
- * @property int|null $mall_goods_id
- * @property int|null $goods_id
- * @property string|null $title 商品名称
- * @property string|null $image_url 商品主图
- * @property int|null $source 来源 0中台 1云仓(聚合供应链) 2京东 6阿里 7天猫
- * @property float|null $agreement_price 协议价
- * @property float|null $guide_price 指导价
- * @property float|null $activity_price 营销价
- * @property float|null $market_price 市场价
- * @property float|null $sale_price 销售价
- * @property float|null $cost_price 成本价
- * @property int $stock 库存
- * @property int $sales 销量
- * @property int $min_buy_qty 销量
- * @property string|null $sn 商品编号
- * @property int|null $is_display 上下架 0下1上
- * @property string|null $desc 商品描述
- * @property string|null $unit 商品单位
- * @property string|null $barcode 商品条码
- * @property string|null $gallery 商品组图json
- * @property string|null $detail_images 商品详情
- * @property string|null $attrs 商品属性json
- * @property string|null $skus 商品规格json
- * @property string|null $brand 商品品牌json
- * @property string|null $category_1
- * @property string|null $category_2
- * @property string|null $category_3
- * @property string|null $source_name
- */
- class GoodsModel extends \yii\db\ActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_qijuhe_goods}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'supply_id', 'goods_id', 'mall_goods_id', 'source', 'stock', 'sales', 'is_display', 'min_buy_qty'], 'integer'],
- [['agreement_price', 'guide_price', 'activity_price', 'market_price', 'sale_price', 'cost_price'], 'number'],
- [['desc', 'detail_images', 'attrs', 'skus', 'brand'], 'string'],
- [['title', 'image_url', 'sn', 'barcode', 'category_1', 'category_2', 'category_3', 'source_name'], 'string', 'max' => 255],
- [['unit'], 'string', 'max' => 32],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => 'Mall ID',
- 'supply_id' => 'Supply ID',
- 'mall_goods_id' => '商城对应的商品id',
- 'goods_id' => '中台商品id',
- 'title' => '商品名称',
- 'image_url' => '商品主图',
- 'source' => '来源 0中台 1云仓(聚合供应链) 2京东 6阿里 7天猫',
- 'agreement_price' => '协议价',
- 'guide_price' => '指导价',
- 'activity_price' => '营销价',
- 'market_price' => '市场价',
- 'sale_price' => '销售价',
- 'cost_price' => '成本价',
- 'stock' => '库存',
- 'sales' => '销量',
- 'sn' => '商品编号',
- 'is_display' => '上下架 0下1上',
- 'desc' => '商品描述',
- 'unit' => '商品单位',
- 'barcode' => '商品条码',
- 'gallery' => '商品组图json',
- 'detail_images' => '商品详情',
- 'attrs' => '商品属性json',
- 'skus' => '商品规格json',
- 'brand' => '商品品牌json',
- 'category_1' => 'Category 1',
- 'category_2' => 'Category 2',
- 'category_3' => 'Category 3',
- ];
- }
- // 过滤字段
- public static function filterField(array $data): array
- {
- $safe_attr = self::getTableSchema()->getColumnNames();
- $not_safe_attr = array_diff(array_keys($data), $safe_attr);
- foreach ($not_safe_attr as $key) {
- unset($data[$key]);
- }
- return $data;
- }
- /**
- * 通过ids下架商品
- *
- * @param array $ids
- * @return int
- */
- public static function GoodsPullByMiddleIds(array $ids)
- {
- return static::updateAll([
- 'is_display' => 0
- ], [
- 'goods_id' => $ids
- ]);
- }
- /**
- * @param int $goods_id
- * @param int $sku_id
- * @return int
- */
- public static function getMinBuyQty(int $goods_id, int $sku_id)
- {
- $sku = GoodsSkuModel::getSku($goods_id, $sku_id);
- if (empty($sku)) return 0;
- return (int) self::find()->where(['goods_id' => $sku->supply_goods_id, 'mall_id' => $sku->mall_id])->select('min_buy_qty')->scalar();
- }
- }
|