GoodsAttr.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. namespace addons\StarChain\common\models;
  3. use Yii;
  4. /**
  5. * This is the model class for table "{{%addons_star_chain_goods_attr}}".
  6. *
  7. * @property int $id
  8. * @property int $mall_id
  9. * @property string $sku_id 商品线上SKU
  10. * @property int $mall_goods_id 商品表商品ID
  11. * @property string $chain_goods_id 供应链商品ID
  12. * @property int $attr_id 商品属性表ID
  13. * @property int $is_delete
  14. */
  15. class GoodsAttr extends BaseModel
  16. {
  17. /**
  18. * {@inheritdoc}
  19. */
  20. public static function tableName()
  21. {
  22. return '{{%addons_star_chain_goods_attr}}';
  23. }
  24. /**
  25. * {@inheritdoc}
  26. */
  27. public function rules()
  28. {
  29. return [
  30. [['mall_id', 'mall_goods_id', 'attr_id', 'is_delete'], 'integer'],
  31. [['sku_id', 'chain_goods_id'], 'string', 'max' => 64],
  32. ];
  33. }
  34. /**
  35. * {@inheritdoc}
  36. */
  37. public function attributeLabels()
  38. {
  39. return [
  40. 'id' => 'ID',
  41. 'mall_id' => 'Mall ID',
  42. 'sku_id' => 'Sku ID',
  43. 'mall_goods_id' => 'Mall Goods ID',
  44. 'chain_goods_id' => 'Chain Goods ID',
  45. 'attr_id' => 'Attr ID',
  46. 'is_delete' => 'Is Delete',
  47. ];
  48. }
  49. /**
  50. * 删除商品对应的Attr
  51. *
  52. * @param integer $goods_id
  53. * @return int
  54. */
  55. public static function removeGoodsAttr(int $goods_id)
  56. {
  57. return static::updateAll(['is_delete' => 1], ['mall_goods_id' => $goods_id]);
  58. }
  59. /**
  60. * 获取一个SKUID
  61. *
  62. * @param integer $goods_id
  63. * @param integer $attr_id
  64. * @return GoodsSkuModel
  65. */
  66. public static function getSku($goods_id, $attr_id, $field = null)
  67. {
  68. $model = self::find();
  69. $field && $model->select($field);
  70. return $model->where(['mall_goods_id' => $goods_id, 'attr_id' => $attr_id, 'is_delete' => 0])
  71. ->one();
  72. }
  73. /**
  74. * 通过SKUIDs获取SKU信息
  75. *
  76. * @param array $attr_id
  77. * @param string $field
  78. * @return array
  79. */
  80. public static function getSkuByAttrIDs(array $attr_id, string $field = '')
  81. {
  82. $model = self::find();
  83. $field && $model->select($field);
  84. return $model
  85. ->where(['attr_id' => $attr_id, 'is_delete' => 0])
  86. ->asArray()
  87. ->all();
  88. }
  89. }