<?php

$status = array
(
    1 => '已确认',
    2 => '未确认',
);

$cash_status = array
(
    1 => '已发放',
    2 => '未发放',
);

$type = array
(
    1 => '城市',
    2 => '区县',
    3 => '街道',
);

$button = array();
$table = Dever::input('table');
if ($table == 'area_stat') {
    $month = Dever::input('search_option_month', date('Y-m'));
    if ($month) {
        Dever::setInput('search_option_month', $month);
    }

    
    $button['一键生成区域分润'] = array('oper', 'mail/?l=lib/manage.area&day=' . $month, '确认生成区域分润信息吗？');

    $button['重新生成区域分润'] = array('oper', 'mail/?l=lib/manage.area&day=' . $month, '确认生成区域分润信息吗？');

    $button['对账确认'] = array('oper', 'mail/?l=lib/manage.areaYes_commit&month=' . $month, '确定已完成对账？');

    $button['确认发放'] = array('oper', 'mail/?l=lib/manage.areaCash_commit&month=' . $month, '确认发放资金到代理商账户吗？确认后无法手动恢复');

}
$desc = '';



return array
(
    # 表名
    'name' => 'area_stat',
    # 显示给用户看的名称
    'lang' => '区域分润处理',
    'order' => 79,
    'menu' => 'agent',
    'info' => '',
    'desc' => '满足以下条件才可显示：1.区域下必须有门店；2.区域内代理商分润金额不为0；3.零售店、体验店全部处于合作中状态',
    'end' => array
    (
        'list' => 'mail/lib/manage.getAreaInfo',
    ),
    # 数据结构
    'struct' => array
    (
    
        'id'        => array
        (
            'type'      => 'int-11',
            'name'      => 'ID',
            'default'   => '',
            'desc'      => '',
            'match'     => 'is_numeric',
            'search'    => 'order',
            //'list'        => true,
        ),

        'month'     => array
        (
            'type'      => 'int-11',
            'name'      => '选择月份',
            'default'   => '',
            'match'     => 'is_numeric',
            'desc'      => '',
            'update'    => 'month',
            'search'    => 'month_eq',
            'search_default' => '',
            'list_name' => '月份',
            'list'      => 'is_numeric("{month}") ? date("Y-m", "{month}") : "{month}"',
        ),

        'name'       => array
	    (
	        'type'      => 'varchar-500',
	        'name'      => '区域',
	        'default'   => '',
	        'desc'      => '区域',
	        'match'     => 'option',
	        'update'    => 'linkage',
            //'search'    => 'linkage',
	        'list'      => 'Dever::load("mail/lib/manage.getArea", "{name}")',
            'option'    => Dever::url('api.get?level_total=4', 'area'),
	    ),

        'type'        => array
        (
            'type'      => 'int-11',
            'name'      => '区域类型',
            'default'   => '1',
            'desc'      => '区域类型',
            'match'     => 'is_numeric',
            'option'    => $type,
        ),

        'parent_id'       => array
        (
            'type'      => 'int-11',
            'name'      => '上级id',
            'default'   => -1,
            'desc'      => '请选择上级id',
            'match'     => 'is_numeric',
        ),

        't_cash'      => array
        (
            'type'      => 'decimal-11,2',
            'name'      => '体验店分润金额',
            'default'   => '0',
            'desc'      => '体验店分润金额',
            'match'     => 'is_numeric',
            // 'update'    => 'text',
            'list'      => true,
        ),

        'l_cash'      => array
        (
            'type'      => 'decimal-11,2',
            'name'      => '零售店分润金额',
            'default'   => '0',
            'desc'      => '零售店分润金额',
            'match'     => 'is_numeric',
            // 'update'    => 'text',
            'list'      => true,
        ),

        't_num'      => array
        (
            'type'      => 'int-11',
            'name'      => '体验店数量',
            'default'   => '0',
            'desc'      => '体验店数量',
            'match'     => 'is_numeric',
            // 'update'    => 'text',
            'list'      => true,
        ),

        'l_num'      => array
        (
            'type'      => 'int-11',
            'name'      => '零售店数量',
            'default'   => '0',
            'desc'      => '零售店数量',
            'match'     => 'is_numeric',
            // 'update'    => 'text',
            'list'      => true,
        ),

        't_buy'      => array
        (
            'type'      => 'decimal-11,2',
            'name'      => '体验店采购毛利',
            'default'   => '0',
            'desc'      => '体验店采购毛利',
            'match'     => 'is_numeric',
            // 'update'    => 'text',
            'list'      => true,
        ),

        'l_buy'      => array
        (
            'type'      => 'decimal-11,2',
            'name'      => '零售店采购毛利',
            'default'   => '0',
            'desc'      => '零售店采购毛利',
            'match'     => 'is_numeric',
            // 'update'    => 'text',
            'list'      => true,
        ),

        'mid'      => array
        (
            'type'      => 'int-11',
            'name'      => '收益代理商姓名/电话',
            'default'   => '-1',
            'desc'      => '代理商',
            'match'     => 'is_string',
            // 'update'    => 'text',
            'searchs'    => array
            (
                'api' => 'agent/member-getSearch',
                'col' => 'col',
                'result' => 'id',
                'search' => 'mid',
            ),
            'list_name' => '收益代理商',
            'list'      => 'Dever::load("mail/lib/manage.area_member", {id})',
        ),

        'status'        => array
        (
            'type'      => 'int-11',
            'name'      => '确认状态',
            'default'   => '2',
            'desc'      => '确认状态',
            'match'     => 'is_numeric',
            'option'    => $status,
            'list'      => true,
        ),

        'cash_status'        => array
        (
            'type'      => 'int-11',
            'name'      => '发放状态',
            'default'   => '2',
            'desc'      => '发放状态',
            'match'     => 'is_numeric',
            'option'    => $cash_status,
            'list'      => true,
        ),

        'data'       => array
        (
            'type'      => 'text-255',
            'name'      => '明细数据',
            'default'   => '',
            'desc'      => '明细数据',
            'match'     => 'is_string',
            'list_name' => '查看详情',
            'modal'     => '查看详情',
            'list'      => 'Dever::load("mail/lib/manage.area_stat_view", {id})',
        ),

        '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' => true,
        'list_type' => 'tree',
        'button' => $button,
    ),

    'request' => array
    (
        'getData' => array
        (
            # 匹配的正则或函数 选填项
            'option' => array
            (
                'mid' => 'yes',
                'cash_status' => 1,
                'month' => 'yes',
                'state' => 1,
            ),
            'order' => array('id' => 'desc'),
            'page' => array(10, 'list'),
            'type' => 'all',
            'col' => '*',
        ),

        'prev' => array
        (
            # 匹配的正则或函数 选填项
            'option' => array
            (
                'month' => array('yes-month', '<'),
                'mid' => 'yes',
                'state' => 1,
            ),
            'order' => array('time' => 'desc', 'id' => 'desc'),
            'type' => 'one',
            'col' => '*,min(month) as time, sum(num) as num',
            # 允许自定义以上配置
            'config' => true,
        ),
        'getOne' => array
        (
            # 匹配的正则或函数 选填项
            'option' => array
            (
                'mid' => 'yes',
                'state' => 1,
            ),
            'type' => 'count',
            'col' => '*',
        ),

        'getData' => array
        (
            # 匹配的正则或函数 选填项
            'option' => array
            (
                'mid' => 'yes',
                'cash_status' => 1,
                'state' => 1,
            ),
            'type' => 'all',
            'order' => array('month' => 'desc', 'id' => 'desc'),
            'page' => array(20, 'list'),
            'col' => '*',
        ),
    ),
);
