| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- <?php
- namespace app\models;
- use yii\behaviors\TimestampBehavior;
- use yii\db\ActiveRecord;/**
- * This is the model class for table "{{%md_category}}".
- *
- * @property integer $id
- * @property integer $store_id
- * @property string $name
- * @property integer $sort
- * @property integer $is_show
- * @property integer $is_delete
- * @property integer $created_at
- * @property integer $updated_at
- */
- class MdCategory extends \yii\db\ActiveRecord
- {
- /**
- * 启用
- */
- const STATUS_ENABLE = 1;
- /**
- * 禁用
- */
- const STATUS_DISABLE = 0;
- /**
- * @inheritdoc
- */
- public static function tableName()
- {
- return '{{%md_category}}';
- }
- public function behaviors()
- {
- return [
- [
- 'class' => TimestampBehavior::class
- ]
- ];
- }
- /**
- * @inheritdoc
- */
- public function rules()
- {
- return [
- [['id', 'store_id', 'sort', 'is_show', 'is_delete', 'created_at', 'updated_at'], 'integer'],
- [['name'], 'string'],
- ];
- }
- public function attributeLabels()
- {
- return [
- 'id' => '',
- 'store_id' => '商城ID',
- 'name' => '分类名称',
- 'sort' => '排序',
- 'is_show' => '状态:1:开启,0:禁用',
- 'is_delete' => '',
- 'created_at' => '创建时间',
- 'updated_at' => '更新时间'
- ];
- }
- public static function getList($store_id, $id = 0, $is_enable = 1) {
- $where = [
- 'is_delete' => 0,
- 'is_show' => $is_enable,
- 'store_id' => $store_id
- ];
- if ($id) {
- $where['id'] = $id;
- }
- $list = self::find()->where($where)->orderBy('sort')->select('id, name')->asArray()->all();
- foreach ($list as &$item) {
- $item['id'] = intval($item['id']);
- }
- return $list;
- }
- }
|