<?php

$config = array
(
    # 表名
    'name' => 'goods_sku',
    # 显示给用户看的名称
    'lang' => '商品价格设置',
    'order' => 200,
    'menu' => false,

    # 数据结构 不同的字段放这里
    'struct' => array
    (
        'id'        => array
        (
            'type'      => 'int-11',
            'name'      => 'ID',
            'default'   => '',
            'desc'      => '',
            'match'     => 'is_numeric',
            //'list'        => true,
        ),

        'factory_id'      => array
        (
            'type'      => 'int-11',
            'name'      => '所属工厂',
            'default'   => '',
            'desc'      => '所属工厂',
            'match'     => 'is_numeric',
            'list'      => 'Dever::load("factory/info-find#name", {factory_id})',
        ),

        'goods_id'      => array
        (
            'type'      => 'int-11',
            'name'      => '商品名称',
            'default'   => '',
            'desc'      => '商品名称',
            'match'     => 'is_numeric',
            'list'      => 'Dever::load("goods/info-find#name", {goods_id})',
        ),

        'sku_id'      => array
        (
            'type'      => 'int-11',
            'name'      => 'sku_id',
            'default'   => '-1',
            'desc'      => 'sku_id',
            'match'     => 'is_numeric',
        ),

        'p_price'     => array
        (
            'type'      => 'varchar-100',
            'name'      => '出厂价',
            'default'   => '0',
            'desc'      => '出厂价',
            'match'     => 'option',
            'update'    => 'text',
        ),

        'sell_num'      => array
        (
            'type'      => 'float-11,2',
            'name'      => '销量',
            'default'   => '0',
            'desc'      => '请填写销量',
            'match'     => 'option',
            'search'    => 'order',
            //'list'      => true,
        ),

        'reorder'       => array
        (
            'type'      => 'int-11',
            'name'      => '排序-数值越大越靠前,相当于置顶',
            'default'   => '1',
            'desc'      => '请输入排序',
            'match'     => 'option',
            //'update'  => 'text',
            'search'    => 'order',
            'list'      => true,
            'order'     => 'desc',
            'edit'      => true,
        ),

        'state'     => array
        (
            'type'      => 'tinyint-1',
            'name'      => '数据状态',
            'default'   => '1',
            'desc'      => '请选择状态',
            'match'     => 'is_numeric',
        ),

        'cdate'     => array
        (
            'type'      => 'int-11',
            'name'      => '发布时间',
            'match'     => array('is_numeric', time()),
            'desc'      => '',
            # 只有insert时才生效
            'insert'    => true,
            //'search'  => 'date',
            //'list'        => 'date("Y-m-d H:i:s", {cdate})',
        ),
    ),

    'alter' => array
    (
        3 => array
        (
            array('update', 'p_price', 'p_price', 'varchar-100 0 出厂价'),
            array('update', 'sell_num', 'sell_num', 'float-11,2 0 销量'),
        ),
        'version' => 3,
    ),

    'manage' => array
    (
        'insert' => false,
        'edit' => false,
        'delete' => false,
        'num' => false,
        'page_list_table' => 'sku',

        # 自定义快捷新增和编辑
        'button' => array
        (
            //'自定义属性' => array('fast', 1, 'config&where_id=1'),
        ),
    ),

    # request 请求接口定义
    'request' => array
    (
        'getDataPage' => array
        (
            # 匹配的正则或函数 选填项
            'option' => array
            (
                'factory_id' => array('yes-t_1.factory_id'),
                'name' => array('yes-t_2.name', 'like'),
                'sell_num' => array('yes', '<'),
                'column' => array('yes-t_2.column_id', 'like'),
                'category' => array('yes-t_2.category', 'like'),
                'top_category_id' => array('yes-t_2.top_category_id'),
                'second_category_id' => array('yes-t_2.second_category_id'),
                'category_id' => array('yes-t_2.category_id'),
                'status' => array('yes-t_2.status', 1),
                'state' => array('yes-t_2.state', 1),
                'state_1' => array('yes-t_1.state', 1),
            ),
            # 联表
            'join' => array
            (
                array
                (
                    'table' => 'goods/info',
                    'type' => 'left join',
                    'on' => array('goods_id','id'),
                    'col' => 'goods_id',
                ),
            ),
            'type' => 'all',
            'order' => array('t_2.reorder' => 'desc', 't_2.id' => 'desc', 't_1.p_price' => 'asc'),
            //'page' => array(30, 'list'),
            'col' => '*,t_2.name,t_2.cover,t_2.id as id,t_1.sell_num',
        ),

        # 更新售出量
        'incSell' => array
        (
            'type' => 'update',
            'where' => array
            (
                'factory_id' => 'yes',
                'goods_id' => 'yes',
                'sku_id' => 'yes',
            ),
            'set' => array
            (
                'sell_num' => array('yes', '+='),
            ),
        ),
        # 列表
        'getData' => array
        (
            # 匹配的正则或函数 选填项
            'option' => array
            (
                'factory_id' => 'yes',
                'sku_id' => 'yes',
                'goods_id' => 'yes',
                'state' => 1,
            ),
            'type' => 'all',
            'order' => array('id' => 'desc'),
            'col' => '*|sku_id',
        ),

        # 获取单条数据
        'getOne' => array
        (
            # 匹配的正则或函数 选填项
            'option' => array
            (
                'factory_id' => 'yes',
                'sku_id' => 'yes',
                'goods_id' => 'yes',
                'state' => 1,
            ),
            'type' => 'one',
            'col' => '*',
        ),

        'getMinOne' => array
        (
            # 匹配的正则或函数 选填项
            'option' => array
            (
                'factory_id' => 'yes',
                'sku_id' => 'yes',
                'goods_id' => 'yes',
                'state' => 1,
            ),
            'type' => 'one',
            'order' => array('price' => 'asc', 'id' => 'desc'),
            'col' => '*',
        ),

        'getMaxOne' => array
        (
            # 匹配的正则或函数 选填项
            'option' => array
            (
                'factory_id' => 'yes',
                'sku_id' => 'yes',
                'goods_id' => 'yes',
                'state' => 1,
            ),
            'type' => 'one',
            'order' => array('price' => 'desc', 'id' => 'desc'),
            'col' => '*',
        ),
    ),
);

return $config;