MdCategory.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. namespace app\models;
  3. use yii\behaviors\TimestampBehavior;
  4. use yii\db\ActiveRecord;/**
  5. * This is the model class for table "{{%md_category}}".
  6. *
  7. * @property integer $id
  8. * @property integer $store_id
  9. * @property string $name
  10. * @property integer $sort
  11. * @property integer $is_show
  12. * @property integer $is_delete
  13. * @property integer $created_at
  14. * @property integer $updated_at
  15. */
  16. class MdCategory extends \yii\db\ActiveRecord
  17. {
  18. /**
  19. * 启用
  20. */
  21. const STATUS_ENABLE = 1;
  22. /**
  23. * 禁用
  24. */
  25. const STATUS_DISABLE = 0;
  26. /**
  27. * @inheritdoc
  28. */
  29. public static function tableName()
  30. {
  31. return '{{%md_category}}';
  32. }
  33. public function behaviors()
  34. {
  35. return [
  36. [
  37. 'class' => TimestampBehavior::class
  38. ]
  39. ];
  40. }
  41. /**
  42. * @inheritdoc
  43. */
  44. public function rules()
  45. {
  46. return [
  47. [['id', 'store_id', 'sort', 'is_show', 'is_delete', 'created_at', 'updated_at'], 'integer'],
  48. [['name'], 'string'],
  49. ];
  50. }
  51. public function attributeLabels()
  52. {
  53. return [
  54. 'id' => '',
  55. 'store_id' => '商城ID',
  56. 'name' => '分类名称',
  57. 'sort' => '排序',
  58. 'is_show' => '状态:1:开启,0:禁用',
  59. 'is_delete' => '',
  60. 'created_at' => '创建时间',
  61. 'updated_at' => '更新时间'
  62. ];
  63. }
  64. public static function getList($store_id, $id = 0, $is_enable = 1) {
  65. $where = [
  66. 'is_delete' => 0,
  67. 'is_show' => $is_enable,
  68. 'store_id' => $store_id
  69. ];
  70. if ($id) {
  71. $where['id'] = $id;
  72. }
  73. $list = self::find()->where($where)->orderBy('sort')->select('id, name')->asArray()->all();
  74. foreach ($list as &$item) {
  75. $item['id'] = intval($item['id']);
  76. }
  77. return $list;
  78. }
  79. }