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.

114 lines
2.8 KiB

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