GoodsSkuModel.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. namespace addons\QiJuhe\common\models;
  3. use Yii;
  4. use yii\db\ActiveRecord;
  5. /**
  6. * This is the model class for table "{{%addons_qijuhe_goods_attr}}".
  7. *
  8. * @property int $id
  9. * @property int $mall_id
  10. * @property int $supply_id 中台ID
  11. * @property int $sku_id 商品线上SKU
  12. * @property int $goods_id 商品表商品ID
  13. * @property int $supply_goods_id 中台商品表ID
  14. * @property int $attr_id 商品属性表ID
  15. * @property int $is_delete
  16. */
  17. class GoodsSkuModel extends ActiveRecord
  18. {
  19. /**
  20. * {@inheritdoc}
  21. */
  22. public static function tableName()
  23. {
  24. return '{{%addons_qijuhe_goods_attr}}';
  25. }
  26. /**
  27. * {@inheritdoc}
  28. */
  29. public function rules()
  30. {
  31. return [
  32. [['mall_id', 'sku_id', 'goods_id', 'attr_id'], 'required'],
  33. [['mall_id', 'supply_id', 'sku_id', 'goods_id', 'supply_goods_id', 'attr_id', 'is_delete'], 'integer'],
  34. ];
  35. }
  36. /**
  37. * {@inheritdoc}
  38. */
  39. public function attributeLabels()
  40. {
  41. return [
  42. 'id' => 'ID',
  43. 'mall_id' => 'Mall ID',
  44. 'supply_id' => 'Supply ID',
  45. 'sku_id' => 'Sku ID',
  46. 'goods_id' => 'Goods ID',
  47. 'supply_goods_id' => 'Supply Goods ID',
  48. 'attr_id' => 'Attr ID',
  49. 'is_delete' => 'Is Delete',
  50. ];
  51. }
  52. /**
  53. * 获取一个SKUID
  54. *
  55. * @param integer $goods_id
  56. * @param integer $attr_id
  57. * @return integer
  58. */
  59. public static function getSkuId($goods_id, $attr_id)
  60. {
  61. return self::find()
  62. ->where(['goods_id' => $goods_id, 'attr_id' => $attr_id])
  63. ->select('sku_id')
  64. ->scalar();
  65. }
  66. /**
  67. * 获取一个SKUID
  68. *
  69. * @param integer $goods_id
  70. * @param integer $attr_id
  71. * @return GoodsSkuModel
  72. */
  73. public static function getSku($goods_id, $attr_id, $field = null)
  74. {
  75. $model = self::find();
  76. $field && $model->select($field);
  77. return $model->where(['goods_id' => $goods_id, 'attr_id' => $attr_id])
  78. ->one();
  79. }
  80. /**
  81. * 查询
  82. *
  83. * @param integer $mall_id
  84. * @return array
  85. */
  86. public static function getImportedGoodsIds(int $mall_id)
  87. {
  88. return StorageModel::find()
  89. ->where(['mall_id' => $mall_id, 'is_import' => 2])
  90. ->select(['id', 'middle_goods_id'])
  91. ->all();
  92. }
  93. }