<?php

$status = array
(
    1 => '正常',
    2 => '已申报',
    3 => '已退款',
);

return array
(
    # 表名
    'name' => 'buy_order_goods',
    # 显示给用户看的名称
    'lang' => '订单商品表',
    'menu' => false,
    'status' => $status,
    # 数据结构
    'struct' => array
    (
    
        'id'        => array
        (
            'type'      => 'int-11',
            'name'      => 'ID',
            'default'   => '',
            'desc'      => '',
            'match'     => 'is_numeric',
            'search'    => 'order',
            'update'    => 'hidden',
            //'list'        => true,
        ),

        'order_id'      => array
        (
            'type'      => 'int-11',
            'name'      => '订单表id',
            'default'   => '',
            'desc'      => '订单表id',
            'match'     => 'is_numeric',
        ),

        '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',
        ),

        'extend'       => array
        (
            'type'      => 'text-255',
            'name'      => '扩展信息',
            'default'   => '',
            'desc'      => '扩展信息',
            'match'     => 'option',
        ),

        'price'      => array
        (
            'type'      => 'varchar-50',
            'name'      => '单价',
            'default'   => '0',
            'desc'      => '单价',
            'match'     => 'option',
            'update'    => 'text',
            'list'        => true,
        ),

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

        'num'        => array
        (
            'type'      => 'int-11',
            'name'      => '购买数量',
            'default'   => '',
            'desc'      => '购买数量',
            'match'     => 'is_numeric',
            'search'    => 'select',
            'list'        => true,
        ),

        'status'        => array
        (
            'type'      => 'int-11',
            'name'      => '状态',
            'default'   => '1',
            '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,
        'delete' => false,
        'page_list' => 'buy_order_goods',
    ),

    'request' => array
    (
        # 获取单条数据
        'getIds' => array
        (
            # 匹配的正则或函数 选填项
            'option' => array
            (
                'uid' => 'yes',
                'shop_id' => 'yes',
                'order_id' => 'yes',
                'status' => 1,
                'state' => 1,
            ),
            'type' => 'all',
            'col' => '*|id',
        ),

        # 获取多条数据
        'getDataByIds' => array
        (
            # 匹配的正则或函数 选填项
            'option' => array
            (
                'ids' => array('yes-id', 'in'),
                'uid' => 'yes',
                'shop_id' => 'yes',
                'order_id' => 'yes',
                'state' => 1,
            ),
            'type' => 'all',
            'col' => '*',
        ),

        # 获取多条数据
        'getTotal' => array
        (
            # 匹配的正则或函数 选填项
            'option' => array
            (
                'order_id' => 'yes',
                'status' => array('yes', 'in'),
                'state' => 1,
            ),
            'type' => 'count',
            'col' => '*',
        ),

        # 获取商品数量
        'getGoodsNum' => array
        (
            # 匹配的正则或函数 选填项
            'option' => array
            (
                'order_id' => 'yes',
                'status' => 'yes',
                'state' => 1,
            ),
            'type' => 'one',
            'col' => 'sum(num) as total',
        ),

        # 获取商品数量
        'getGoodsTotal' => array
        (
            # 匹配的正则或函数 选填项
            'option' => array
            (
                'type' => array('yes-t_2.type'),
                'type_id' => array('yes-t_2.type_id'),
                'status' => array('yes-t_2.status', 'in'),
                'goods_id' => array('yes-t_1.goods_id'),
                'sku_id' => array('yes-t_1.sku_id'),
                'state' => array('yes-t_2.state', 1),
                'state_1' => array('yes-t_1.state', 1),
            ),
            # 联表
            'join' => array
            (
                array
                (
                    'table' => 'shop/buy_order',
                    'type' => 'left join',
                    'on' => array('order_id','id'),
                ),
            ),
            'type' => 'one',
            'col' => 'id,sum(t_2.num) as total',
        ),
    ),
);
