TimestampBehavior::class, 'value' => time() ] ]; } public static function tableName() { return '{{%adopt_cat}}'; } public function rules() { return [ [['store_id', 'name',], 'required'], [['store_id', 'sort', 'created_at', 'updated_at', 'is_delete', 'is_show'], 'integer'], [['pic_url'], 'string'], [['name'], 'string', 'max' => 255], ]; } public function attributeLabels() { return [ 'id' => 'ID', 'store_id' => '商城id', 'name' => '分类名称', 'pic_url' => '分类图片url', 'sort' => '排序,升序', 'created_at' => '创建时间', 'updated_at' => '更新时间', 'is_delete' => 'Is Delete', 'is_show' => '是否显示', ]; } public static function getCatId($parent_id, &$cat_list = []) { $cat_list[] = $parent_id; $query = self::find()->where([ 'id' => $parent_id, 'is_delete' => 0, 'store_id' => get_store_id() ])->orderBy(['sort'=>SORT_DESC]); $query->andWhere([ 'is_show' => 1 ]); $cat = $query->asArray()->all(); if (empty($cat)) { return $cat_list; } foreach ($cat as &$val) { self::getCatId($val['id'], $cat_list); } return $cat_list; } }