<?php

$status = array
(
    1 => '未对账',
    2 => '已对账',
);

$type = Dever::db('cash/shop')->config['config_type'];

$factory = function()
{
    $array = array();
    $info = Dever::db('factory/info')->state();
    if($info)
    {
        $array += $info;
    }
    return $array;
};

return array
(
    # 表名
    'name' => 'factory',
    # 显示给用户看的名称
    'lang' => '工厂对账单',
    'order' => 70,
    'config_status' => $status,
    'config_type' => $type,
    # 数据结构
    'struct' => array
    (
    
        'id'        => array
        (
            'type'      => 'int-11',
            'name'      => 'ID',
            'default'   => '',
            'desc'      => '',
            'match'     => 'is_numeric',
            'search'    => 'order',
            //'list'      => true,
        ),

        'type'        => array
        (
            'type'      => 'tinyint-1',
            'name'      => '对账单类型',
            'default'   => '1',
            'desc'      => '对账单类型',
            'match'     => 'is_numeric',
        ),

        'day'     => array
        (
            'type'      => 'int-11',
            'name'      => '对账单时间',
            'default'   => '',
            'match'     => 'is_numeric',
            'desc'      => '',
            'search'    => 'day',
            'order'     => 'desc',
            'list'      => 'Dever::load("cash/lib/set.statDate", "{type}", "{day}")',
        ),

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

        'start'     => array
        (
            'type'      => 'int-11',
            'name'      => '对账单开始时间',
            'default'   => '',
            'match'     => 'is_numeric',
            'desc'      => '',
        ),

        'end'     => array
        (
            'type'      => 'int-11',
            'name'      => '对账单结束时间',
            'default'   => '',
            'match'     => 'is_numeric',
            'desc'      => '',
            'list_name' => '对账周期',
            'list'      => 'Dever::load("cash/lib/set.statTime", "{start}", "{end}")',
        ),

        'cash'      => array
        (
            'type'      => 'varchar-100',
            'name'      => '对账金额',
            'default'   => '0',
            'desc'      => '对账金额',
            'match'     => 'option',
            'update'    => 'text',
            'list'      => 'Dever::load("cash/lib/set.getCash", "{cash}")',
        ),

        'num'      => array
        (
            'type'      => 'varchar-100',
            'name'      => '对账数量',
            'default'   => '0',
            'desc'      => '对账数量',
            'match'     => 'option',
            'update'    => 'text',
            //'list'        => true,
        ),

        'factory_status'        => array
        (
            'type'      => 'int-11',
            'name'      => '工厂对账状态',
            'default'   => '1',
            'desc'      => '工厂对账状态',
            'match'     => 'is_numeric',
            'update'    => 'radio',
            'search'    => 'select',
            'option'    => $status,
            'list'      => true,
        ),

        'status'        => array
        (
            'type'      => 'int-11',
            'name'      => '平台对账状态',
            'default'   => '1',
            'desc'      => '平台对账状态',
            'match'     => 'is_numeric',
            'update'    => 'radio',
            'search'    => 'select',
            'option'    => $status,
            'list'      => 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})',
            //'list'      => 'Dever::load("service/lib/manage.showOrderTime", "{id}")',
        ),
    ),

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

        'list_button' => array(

            'list' => array('查看详情', '"order&project=cash&id={id}&page_type=1&type=factory"'),

            'oper'  => array('确认对账金额', '"cash/lib/set.audit?id={id}&type=factory"', '{status} == 1', 'Dever::load("cash/lib/set.statYes", "{id}", "factory")', '请确认'),
        ),
    ),

    'request' => array
    (
        # 获取总金额
        'getAll' => array
        (
            # 匹配的正则或函数 选填项
            'option' => array
            (
                'start' => array('yes-day', '>='),
                'end' => array('yes-day', '<='),
                'factory_id' => 'yes',
                'factory_status' => 'yes',
                'status' => 'yes',
                'state' => 1,
            ),
            'type' => 'all',
            'page' => array(10, 'list'),
            'col' => '*',
        ),
    ),
);
