<?php
$config = array
(
    'list' => array
    (
        'field'      => array
        (
            'ids' => array
            (
                'name' => '编号',
                'show' => '"G" . Dever\Helper\Str::uid("{id}")'
            ),
            'sort' => array
            (
                'type' => 'input',
            ),
            'name' => array
            (
                //'tip' => false,
            ),
            'source' => array
            (
                'show' => 'Dever::call("place/manage.getSource", array({id}, 3, "goods"))',
            ),
            'cate' => array
            (
                'show' => 'Dever::call("place/manage.getCateInfo", array("goods", "{cate}"))',
            ),
            'status' => array
            (
                'type' => 'switch',
                'show'  => '{status}',
                'active_value' => 1,
                'inactive_value' => 2,
            ),
            'cdate',
        ),
        'button' => array
        (
            '新增' => array('add'),
        ),
        'data_button' => array
        (
            '编辑' => 'edit',
        ),
        'search'    => array
        (
            'name' => 'like',
            'cate' => array
            (
                'type' => 'cascader',
                'option'    => 'Dever::call("place/manage.getCateList", array("goods"))',
            ),
            'cdate' => array
            (
                'name' => '创建时间',
                'type' => 'date',
                'date_type' => 'datetimerange',
                'value_format' => 'YYYY-MM-DD HH:mm:ss',
                'start_placeholder' => '开始日期',
                'end_placeholder' => '结束日期',
                'range_separator' => '至',
            ),
            'status',
        ),
    ),
    'update' => array
    (
        'end' => 'place/manage.updateCate',
        'control' => array
        (
            'goods/sku' => array
            (
                'spec_type' => 2,
            ),

            'goods/sku#' => array
            (
                'spec_type' => 3,
            ),
        ),
        'tab' => array
        (
            '基本信息' => 'name,cate,pic,info,content',
            '规格设置' => 'spec_type,goods/sku,goods/sku#',
            '特殊价格设置' => 'goods/vip_price,goods/agent_price',
        ),
        //'desc' => '原创声明：',
        'field'    => array
        (
            'name' => array
            (
                'rules' => true,
            ),
            'cate' => array
            (
                'rules' => true,
                'type' => 'cascader',
                'option'    => 'Dever::call("place/manage.getCateList", array("goods"))',
            ),
            'pic' => array
            (
                'type' => 'upload',
                'upload' => '1',
                'multiple' => true,
                'style' => 'pic',
            ),
            'info' => array
            (
                'type' => 'textarea',
                //'rows' => 4,
                'autosize' => array('minRows' => 4),
            ),
            'content' => array
            (
                'type' => 'editor',
                'editorMenu' => array
                (
                    'uploadImage' => 1,
                    'uploadVideo' => 3,
                ),
            ),
            'spec_type' => array
            (
                'type' => 'radio',
                'control' => true,
            ),
            'goods/sku' => array
            (
                'name' => '单规格设置',
                'where'  => array('info_id' => 'id', 'key' => '-1'),
                # 默认值，如果有默认值则无法添加和删除
                'default' => array
                (
                    # 默认值
                    array
                    (
                        'key' => '-1',
                        'code' => '',
                        'm_price' => '',
                        'price' => '',
                    ),
                ),
                'desc' => '如需设置商品库存，请到“商品库存”中设置，不设置库存则商品无库存',
            ),

            'goods/sku#' => array
            (
                'name' => '多规格设置',
                'where' => array('info_id' => 'id', 'key' => array('!=', '-1')),
                'type' => 'sku',
                # 设置规格表名
                'spec' => 'goods/spec',
                # 设置规格表关联字段
                'spec_field' => 'info_id',
                # 获取规格数据的接口
                'spec_data' => 'api/spec.manage',
                'desc' => '如需设置商品库存，请到“商品库存”中设置，不设置库存则商品无库存',
                'disable' => false,
            ),

            'goods/vip_price' => array
            (
                'name' => '会员价格',
                'where'  => array('info_id' => 'id'),
                'desc' => '可以按照会员等级设置不同的价格',
            ),
            'goods/agent_price' => array
            (
                'name' => '代理价格',
                'where'  => array('info_id' => 'id'),
                'desc' => '可以按照代理等级设置不同的价格',
            ),

            'goods/client_price' => array
            (
                'name' => '源主销量折扣',
                'where'  => array('info_id' => 'id'),
            ),
        ),
    ),
);
$extend = Dever::load('common', 'manage')->extend();
$place = Dever::db('info', 'place')->find(array('id' => $extend['data_id']));
if ($place && $place['channel'] == 1) {
    $config['update']['tab']['特殊价格设置'] .= ',goods/client_price';
}
$id = Dever::input('id');
if ($id) {
    $info = Dever::db('info', 'goods')->find($id);
    if ($info && isset($info['source']) && $info['source'] == 2) {
        $relation = Dever::db('resource_relation', 'place')->find(array('type' => 3, 'type_id' => $id));
        if ($relation && $relation['status'] = 1) {
            $place = Dever::db('info', 'place')->find($relation['channel_place_id']);
            $config['update']['field']['spec_type']['disable'] = true;
            $config['update']['field']['goods/sku#']['disable'] = true;
        }
    }
}

return $config;