<?php

$type = Dever::db('setting/role_goods')->config['set']['type'];

if (Dever::load('manage/auth')->checkFunc('menu_268.menu_272', 'edit1', '导出数据')) {
    $excel = true;
}else{
    $excel = false;
}

return array
(
    # 表名
    'name' => 'goods_stat',
    # 显示给用户看的名称
    'lang' => '权益统计',
    'order' => 78,
    'menu' => 'agent',
    # 数据结构
    'struct' => array
    (
    
        'id'        => array
        (
            'type'      => 'int-11',
            'name'      => 'ID',
            'default'   => '',
            'desc'      => '',
            'match'     => 'is_numeric',
            'search'    => 'order',
            //'list'        => true,
        ),

        'day'     => array
        (
            'type'      => 'int-11',
            'name'      => '日期',
            'default'   => '',
            'match'     => 'is_numeric',
            'desc'      => '',
            'search'    => 'sday',
            'search_buttons' => array
            (
                'sum' => 'total_num,sell_num,cash,sell_nonum,price',
                'option' => array(
                    'day' => '按天',
                    'week' => '按周',
                    'month' => '按月',
                ),
                'group' => 'type,type_id,sku_id',
            ),
            'order'     => 'desc',
            // 'list'      => 'Dever::showDay("{month}")',
        ),

        'type'        => array
        (
            'type'      => 'tinyint-1',
            'name'      => '类型',
            'default'   => '1',
            'desc'      => '类型',
            'match'     => 'is_numeric',
            'update'    => 'radio',
            'option'    => $type,
            'search'    => 'select',
            'list'      => true,
            'list_order' => 4,
        ),

        'type_id'      => array
        (
            'type'      => 'int-11',
            'name'      => '类型id',
            'default'   => '-1',
            'desc'      => '类型id',
            'match'     => 'is_numeric',
            'list_name' => '权益名称',
            //'list'      => 'Dever::load("agent/lib/manage.getGoods#name", "{type}", "{type_id}", "{sku_id}")',
            //'list_order' => 5,
            'list_name' => '平均单件价值',
            'list'      => 'round({cash}/{total_num}, 2)',
            'list_order' => 9,
        ),

        'sku_id'      => array
        (
            'type'      => 'int-11',
            'name'      => 'sku_id',
            'default'   => '-1',
            'desc'      => 'sku_id',
            'match'     => 'is_numeric',
            'list'      => true,
            'list_name' => '未兑换数量',
            'list'      => '{total_num} - {sell_num}',
            'list_order' => 7,
        ),

        'name'      => array
        (
            'type'      => 'varchar-100',
            'name'      => '权益名称',
            'default'   => '',
            'desc'      => '权益名称',
            'match'     => 'is_string',
            'update'    => 'text',
            'search'    => 'fulltext',
            'list'      => '"{name}" ? "{name}" : Dever::load("agent/lib/manage.getGoods#name", "{type}", "{type_id}", "{sku_id}")',
            'list_order' => 5,
        ),

        'total_num'        => array
        (
            'type'      => 'int-11',
            'name'      => '总数量',
            'default'   => '0',
            'desc'      => '总数量',
            'match'     => 'is_numeric',
            //'list_name' => '剩余数量/总数量',
            //'list'      => '{total_num} - {sell_num} . " / " . {total_num}',
            'list'      => true,
            'list_order' => 6,
        ),

        'sell_num'      => array
        (
            'type'      => 'int-11',
            'name'      => '已兑换数量',
            'default'   => '0',
            'desc'      => '已兑换数量',
            'match'     => 'option',
            'list'      => true,
            'list_order' => 8,
        ),

        'sell_nonum'      => array
        (
            'type'      => 'int-11',
            'name'      => '已兑换未发货数量',
            'default'   => '0',
            'desc'      => '已兑换未发货数量',
            'match'     => 'option',
            'list'      => true,
            'list_order' => 8,
        ),

        'cash'      => array
        (
            'type'      => 'decimal-11,2',
            'name'      => '总价值',
            'default'   => '0',
            'desc'      => '总价值',
            'match'     => 'is_numeric',
            'update'    => 'text',
            'list'      => true,
            'list_order' => 10,
        ),

        'w_cash'      => array
        (
            'type'      => 'decimal-11,2',
            'name'      => '未兑换价值',
            'default'   => '0',
            'desc'      => '未兑换价值',
            'match'     => 'is_numeric',
            'update'    => 'text',
            'list'      => true,
            'list_order' => 11,
        ),

        'y_cash'      => array
        (
            'type'      => 'decimal-11,2',
            'name'      => '已兑换价值',
            'default'   => '0',
            'desc'      => '已兑换价值',
            'match'     => 'is_numeric',
            'update'    => 'text',
            'list'      => true,
            'list_order' => 12,
        ),

        'state'     => array
        (
            'type'      => 'tinyint-1',
            'name'      => '状态',
            'default'   => '1',
            'desc'      => '请选择状态',
            'match'     => 'is_numeric',
        ),
        
        'cdate'     => array
        (
            'type'      => 'int-11',
            'name'      => '统计时间',
            'match'     => array('is_numeric', time()),
            'desc'      => '',
        ),
    ),

    'manage' => array
    (
        'insert' => false,
        'delete' => false,
        'edit' => false,
        'excel' => $excel,
    ),

    'request' => array
    (
        'list' => array
        (
            # 匹配的正则或函数 选填项
            'option' => array
            (
                'type' => 'yes',
                'type_id' => 'yes',
                'sku_id' => 'yes',
                'start_day' => array('yes-day', '>='),
                'end_day' => array('yes-day', '<='),
                'state' => 1,
            ),
            'type' => 'all',
            'order' => array('day' => 'desc', 'cdate' => 'desc'),
            'page' => array(20, 'list'),
            'group' => '(case when type = 2 then concat_ws("_", type, type_id) else concat_ws("_", type, type_id, sku_id) end)',
            'col' => '*,sum(total_num) as total_num, sum(sell_num) as sell_num, sum(cash) as cash,sum(sell_nonum) as sell_nonum,sum(w_cash) as w_cash,sum(y_cash) as y_cash',
        ),

        'all' => array
        (
            # 匹配的正则或函数 选填项
            'option' => array
            (
                'type' => 'yes',
                'type_id' => 'yes',
                'sku_id' => 'yes',
                'start_day' => array('yes-day', '>='),
                'end_day' => array('yes-day', '<='),
                'state' => 1,
            ),
            'type' => 'all',
            'order' => array('day' => 'desc', 'cdate' => 'desc'),
            'group' => '(case when type = 2 then concat_ws("_", type, type_id) else concat_ws("_", type, type_id, sku_id) end)',
            'col' => '*,sum(total_num) as total_num, sum(sell_num) as sell_num, sum(cash) as cash,sum(sell_nonum) as sell_nonum,sum(w_cash) as w_cash,sum(y_cash) as y_cash',
        ),
    ),
);