<?php namespace Goods\Api;
use Dever;
use Manage\Lib\Auth;
class Manage extends Auth
{
    public function getInfo()
    {
        return Dever::load('common', 'manage')->cascader(2, function($level, $parent) {
            if ($level == 1) {
                $data = Dever::db('info', 'goods')->select([]);
            } elseif ($level == 2) {
                $data = Dever::db('sku', 'goods')->select(array('info_id' => $parent));
                if ($data) {
                    foreach ($data as &$v) {
                        $v['name'] = Dever::load('sku', 'api')->getName($v['key'], 'goods');
                        if (!$v['name']) {
                            $v['name'] = '无规格';
                        }
                    }
                }
            }
            return $data;
        });
    }
}