<?php
$status = Dever::config('base')->status;
return array
(
    # 表名
    'name' => 'goods',
    # 显示给用户看的名称
    'lang' => '商品列表',
    'order' => 10,
    'menu'  => false,
    'ends' => array
    (
        'insert' => 'factory/lib/manage.goodsUpdate',
        'update' => 'factory/lib/manage.goodsUpdate',
    ),
    'fill' => array
    (
        # 从哪个表填充
        'goods/info' => array
        (
            # 条件,另外一个表的字段 => 本表的字段
            'where' => array('id' => 'goods_id'),
            # 要填充的数据,另外一个表的字段 => 本表的字段,如果不填写就是所有的
            'update' => array('price_type' => 'price_type', 'status' => 'status'),
            # 不需要填充的字段 与update互斥
            //'no' => array('id', 'seller_id', 'service_id', 'chose', 'state', 'cdate')
        )
    ),
    # 数据结构
    'struct' => array
    (
    
        'id'        => array
        (
            'type'      => 'int-11',
            'name'      => 'ID',
            'default'   => '',
            'desc'      => '',
            'match'     => 'is_numeric',
            'search'    => 'order',
            'update'    => 'hidden',
            //'list'        => true,
        ),

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

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

        'category_id'      => array
        (
            'type'      => 'int-11',
            'name'      => '分类id',
            'default'   => '',
            'desc'      => '分类id',
            'match'     => 'is_numeric',
        ),

        'price_type'        => array
        (
            'type'      => 'int-11',
            'name'      => '价格类型',
            'default'   => '0',
            'desc'      => '价格类型',
            'match'     => 'is_numeric',
            'table'     => 'goods/info',
        ),

        'p_price'     => array
        (
            'type'      => 'varchar-100',
            'name'      => '出厂价',
            'default'   => '0',
            'desc'      => '出厂价',
            'match'     => 'option',
            'update'    => Dever::input('col') ? 'text' : 'hidden',
            'list'      => 'Dever::load("goods/lib/sku.table", "{goods_id}", "factory", "{factory_id}", false, false)',
        ),

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

        'status'        => array
        (
            'type'      => 'tinyint-1',
            'name'      => '状态',
            'default'   => '2',
            'desc'      => '状态',
            'match'     => 'is_numeric',
            //'update'  => 'select',
            'option'    => $status,
            'search'    => 'select',
            'list'      => true,
            //'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
    (
        2 => array
        (
            array('update', 'p_price', 'p_price', 'varchar-100 0 出厂价'),
        ),
        'version' => 2,
    ),

    'manage' => array
    (
        'insert' => false,
        'edit' => false,
        'delete' => false,

        # 列表里的按钮
        'list_button' => array
        (
            //'edit' => array('设置出厂价', 'p_price', '{price_type} == 1'),
            //'fast_list' => array('设置出厂价', '"goods_sku&project=factory&search_option_goods_id={goods_id}&search_option_factory_id={factory_id}&oper_parent=goods&oper_project=factory&top_table=info&oper_save_jump=goods&page_type=1"'),

            'fast_list' => array('设置出厂价', '"info_sku&project=goods&goods_id={goods_id}&other=factory&other_id={factory_id}&page_type=1"'),
        ),
    ),

    'request' => array
    (
        'getIds' => array
        (
            # 匹配的正则或函数 选填项
            'option' => array
            (
                'factory_id' => 'yes',
                'state' => 1,
            ),
            'type' => 'all',
            'order' => array('id' => 'desc'),
            'col' => '*|goods_id',
        ),

        # 更新售出量
        'incSell' => array
        (
            'type' => 'update',
            'where' => array
            (
                'factory_id' => 'yes',
                'goods_id' => 'yes',
            ),
            'set' => array
            (
                'sell_num' => array('yes', '+='),
            ),
        ),
    ),
);