<?php
$status = Dever::config('base')->status;
return array
(
    # 表名
    'name' => 'goods',
    # 显示给用户看的名称
    'lang' => '商品列表',
    'order' => 10,
    'menu'  => false,
    'ends' => array
    (
        'insert' => 'shop/lib/manage.goodsUpdate',
        'update' => 'shop/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,
        ),

        'shop_id'      => array
        (
            'type'      => 'int-11',
            'name'      => '所属门店',
            'default'   => '',
            'desc'      => '所属门店',
            'match'     => 'is_numeric',
            'update'    => 'hidden',
            'search'    => 'hidden',
            'value'     => Dever::input('search_option_shop_id'),
            'list'      => 'Dever::load("shop/info-one#name", {shop_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-one#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'   => '1',
            'desc'      => '价格类型',
            'match'     => 'is_numeric',
        ),

        'add_num'        => array
        (
            'type'      => 'int-11',
            'name'      => '新增库存-输入小于0的数字，则为减少库存',
            'default'   => '0',
            'desc'      => '新增库存',
            'match'     => 'is_numeric',
            'update'    => Dever::input('col') ? 'text' : 'hidden',
            'list_name' => '当前库存',
            'list'      => 'Dever::load("goods/lib/sku.table", "{goods_id}", "shop", "{shop_id}", false, false)',
        ),

        'total_num'        => array
        (
            'type'      => 'int-11',
            'name'      => '总库存',
            'default'   => '0',
            'desc'      => '总库存',
            'match'     => 'is_numeric',
        ),

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

        'min'       => array
        (
            'type'      => 'int-11',
            'name'      => '起购数',
            'default'   => '1',
            'desc'      => '起购数',
            'match'     => 'is_string',
            'update'    => 'text',
            //'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})',
        ),
    ),

    'manage' => array
    (
        'insert' => false,
        'edit' => false,
        'delete' => false,
        # 列表里的按钮
        'list_button' => array
        (
            'fast_list' => array('库存设置', '"info_sku&project=goods&goods_id={goods_id}&other=shop&other_id={shop_id}&page_type=1"', '{price_type} <= 3'),
        ),
    ),

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

        # 减少售出量
        'decSell' => array
        (
            'type' => 'update',
            'where' => array
            (
                'shop_id' => 'yes',
                'goods_id' => 'yes',
            ),
            'set' => array
            (
                'sell_num' => array('yes', '-='),
            ),
        ),

        # 更新总库存
        'updateTotal' => array
        (
            'type' => 'update',
            'where' => array
            (
                'id' => 'yes',
            ),
            'set' => array
            (
                'total_num' => array('yes', '+='),
            ),
        ),

        # 增加总库存
        'incTotal' => array
        (
            'type' => 'update',
            'where' => array
            (
                'shop_id' => 'yes',
                'goods_id' => 'yes',
            ),
            'set' => array
            (
                'total_num' => array('yes', '+='),
            ),
        ),

        # 减少总库存
        'decTotal' => array
        (
            'type' => 'update',
            'where' => array
            (
                'shop_id' => 'yes',
                'goods_id' => 'yes',
            ),
            'set' => array
            (
                'total_num' => array('yes', '-='),
            ),
        ),

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

        # 获取后台列表
        'list' => array
        (
            # 匹配的正则或函数 选填项
            'option' => array
            (
                'status' => 'yes',
                'shop_id' => 'yes',
                'state' => 1,
            ),
            'type' => 'all',
            'page' => array(15, 'list'),
            'col' => '*',
        ),

        # 推荐列表
        'getTop' => array
        (
            # 匹配的正则或函数 选填项
            'option' => array
            (
                'shop_id' => array('yes-t_1.shop_id'),
                'hot' => array('yes-t_2.hot'),
                'top' => array('yes-t_2.top'),
                'status' => array('yes-t_2.status', 1),
                'state' => array('yes-t_2.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'),
            'limit' => '0,6',
            'col' => '*,t_2.*,t_1.total_num-t_1.sell_num as num,t_1.sell_num',
        ),

        'getData' => array
        (
            # 匹配的正则或函数 选填项
            'option' => array
            (
                'shop_id' => array('yes-t_1.shop_id'),
                'hot' => array('yes-t_2.hot'),
                'top' => array('yes-t_2.top'),
                //'youhui' => array('yes-t_2.youhui'),
                'price_type' => array('yes-t_2.price_type', 'in'),
                'sell_type' => array('yes-t_2.sell_type'),
                'name' => array('yes-t_2.name', 'like'),
                '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'),
            'col' => '*,t_2.*,t_1.total_num-t_1.sell_num as num,t_1.sell_num',
        ),

        'getDataPage' => array
        (
            # 匹配的正则或函数 选填项
            'option' => array
            (
                'shop_id' => array('yes-t_1.shop_id'),
                'hot' => array('yes-t_2.hot'),
                'top' => array('yes-t_2.top'),
                //'youhui' => array('yes-t_2.youhui'),
                'price_type' => array('yes-t_2.price_type', 'in'),
                'sell_type' => array('yes-t_2.sell_type'),
                'name' => array('yes-t_2.name', 'like'),
                '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'),
            'page' => array(10, 'list'),
            'col' => '*,t_2.*,t_1.total_num-t_1.sell_num as num,t_1.sell_num',
        ),
    ),
);
