TimestampBehavior::class, 'value' => time() ] ]; } public static function tableName() { return '{{%attr_library}}'; } public function rules() { return [ [['store_id', 'name',], 'required'], [['store_id', 'parent_id', 'sort', 'created_at', 'updated_at', 'is_delete', 'type'], 'integer'], [['name'], 'string', 'max' => 255], ]; } public function attributeLabels() { return [ 'id' => 'ID', 'store_id' => '商城id', 'parent_id' => '上级分类id', 'name' => '分类名称', 'sort' => '排序,升序', 'created_at' => '创建时间', 'updated_at' => '更新时间', 'is_delete' => 'Is Delete', 'type' => '类型', ]; } /** * 获取所有的分类 * @param int $store_id * @param int $parent_id * @return array */ public static function getList($store_id = 1, $parent_id = 0) { $res = []; $query = self::find()->where([ 'parent_id' => $parent_id, 'is_delete' => 0, 'store_id' => $store_id ])->orderBy(['sort'=>SORT_DESC]); $list = $query->asArray()->all(); if (empty($list)) { return $res; } foreach ($list as &$val) { $val['children'] = self::getList($store_id, $val['id']); $res[] = $val; } return $res; } }