Style.php 1.4 KB
<?php

namespace app\common\model;

use think\Model;

class Style extends Model
{
    /**
     * 获取风格列表
     */
    public static function styleList($style_template_id){
        // 一级风格
        $list = self::getStyleList(['style_template_id'=>$style_template_id,'pid'=>0,'display_mode'=>'1']);
        return $list;
    }

    /**
     * 获取风格列表
     */
    public static function getStyleList($where){
        $list = self::where($where)
            ->order('weigh asc')
            ->select();
        foreach($list as $v){
            $v['style_value_list'] = self::getStyleValueList($v['id']);
            $v['two_style_list'] = self::getStyleList(['pid'=>$v['id']]);
            $v->visible(['id','style_name','style_type','display_mode'])->append(['style_value_list','two_style_list']);
        }
        $list = collection($list)->toArray();
        return $list;
    }

    /**
     * 获取选项列表
     */
    public static function getStyleValueList($style_id){
        $list = StyleValue::where('style_id',$style_id)
            ->order('weigh asc')
            ->select();
        foreach($list as $v){
            $v['style_list'] = self::getStyleList(['id'=>['in',$v['style_ids']]]);
            $v->visible(['id','style_id','style_value_name','style_value_image','style_value_desc','style_ids'])->append(['style_list']);
        }
        $list = collection($list)->toArray();
        return $list;
    }
}