You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

122 lines
3.1 KiB

  1. <?php
  2. namespace antgoods\models\ars;
  3. use Yii;
  4. use yii\behaviors\TimestampBehavior;
  5. use common\models\ars\File;
  6. /**
  7. * This is the model class for table "antgoods_shop_category".
  8. *
  9. * @property int $id
  10. * @property string $name 类别名称
  11. * @property int $pid 父级id
  12. * @property int $goods_count 商品数量
  13. * @property string $keywords 关键字
  14. * @property string $desc 描述
  15. * @property int $sort_order 排序
  16. * @property string $icon 图标
  17. * @property string $filter_attr 筛选属性
  18. * @property int $is_show 是否显示,1为不显示
  19. * @property int $is_delete 是否删除,1为已删除
  20. * @property int $created_at 创建时间
  21. * @property int $updated_at 更新时间
  22. */
  23. class ShopCategory extends \yii\db\ActiveRecord
  24. {
  25. public $iconImageId;
  26. public $iconImagePath;
  27. //是否显示is_show
  28. const IS_SHOW_DISPLAY = 0;//显示
  29. const IS_SHOW_HIDE = 1;//隐藏
  30. //是否删除is_delete
  31. const IS_DELETE_NO = 0;//未删除
  32. const IS_DELETE_YES = 1;//已删除
  33. public static $isShow = [
  34. self::IS_SHOW_DISPLAY => '显示',
  35. self::IS_SHOW_HIDE => '隐藏'
  36. ];
  37. /**
  38. * {@inheritdoc}
  39. */
  40. public static function tableName()
  41. {
  42. return 'antgoods_shop_category';
  43. }
  44. /**
  45. * {@inheritdoc}
  46. */
  47. public function rules()
  48. {
  49. return [
  50. [['name'], 'required'],
  51. [['pid', 'goods_count', 'sort_order', 'icon', 'is_show', 'is_delete', 'iconImageId'], 'integer'],
  52. [['filter_attr'], 'safe'],
  53. [['name'], 'string', 'max' => 60],
  54. [['keywords'], 'string', 'max' => 100],
  55. [['desc'], 'string', 'max' => 255],
  56. ];
  57. }
  58. /**
  59. * {@inheritdoc}
  60. */
  61. public function attributeLabels()
  62. {
  63. return [
  64. 'id' => 'id',
  65. 'name' => '类别名称',
  66. 'pid' => '父级',
  67. 'goods_count' => '商品数量',
  68. 'keywords' => '关键字',
  69. 'desc' => '描述',
  70. 'sort_order' => '排序',
  71. 'icon' => '图标',
  72. 'filter_attr' => '筛选属性',
  73. 'is_show' => '是否显示',
  74. 'is_delete' => '是否删除',
  75. 'created_at' => '创建时间',
  76. 'updated_at' => '更新时间',
  77. ];
  78. }
  79. /**
  80. * @author linyao
  81. * @email 602604991@qq.com
  82. * @created Nov 8, 2019
  83. *
  84. * 行为存储创建时间和更新时间
  85. */
  86. public function behaviors()
  87. {
  88. return [
  89. [
  90. 'class' => TimestampBehavior::className(),
  91. 'createdAtAttribute' => 'created_at',
  92. 'updatedAtAttribute' => 'updated_at',
  93. 'value' => function() {
  94. return time();
  95. },
  96. ],
  97. ];
  98. }
  99. /**
  100. * @return array
  101. * 数据键值对
  102. */
  103. public static function modelColumn()
  104. {
  105. return $column = self::find()->select(['name'])->where(['is_delete' => self::IS_DELETE_NO])->indexBy('id')->column();
  106. }
  107. public function getIconFile()
  108. {
  109. return $this->hasOne(File::className(), ['id' => 'icon']);
  110. }
  111. }