<?php

$type = array
(
    1 => '期权账户',
    2 => '原始期权账户',
);

return array
(
    # 表名
    'name' => 'cash',
    # 显示给用户看的名称
    'lang' => '期权账户数据',
    'order' => 100,
    'menu' => false,
    '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',
            'option'    => $type,
            'update'    => 'radio',
        ),

        'aid'      => array
        (
            'type'      => 'int-11',
            'name'      => '主账号手机号',
            'default'   => '-1',
            'desc'      => '期权登录账户',
            'match'     => 'is_string',
            'update'    => 'text',
            'search'    => array
            (
                'api' => 'option/member-getMain',
                'col' => 'mobile',
                'result' => 'aid',
                'search' => 'aid',//本表的字段,默认为当前的字段
            ),
            'list_name' => '主账户',
            'list'      => 'Dever::load("option/lib/account.getInfo", {aid})',
            'list_order' => 3,
        ),

        'mid'      => array
        (
            'type'      => 'int-11',
            'name'      => '子账号手机号',
            'default'   => '-1',
            'desc'      => '期权账户',
            'match'     => 'is_string',
            'update'    => 'text',
            'search'    => array
            (
                'api' => 'option/member-getChild',
                'col' => 'mobile',
                'result' => 'id',
                'search' => 'mid',//本表的字段,默认为当前的字段
            ),
            'list_name' => '子账户',
            'list'      => 'Dever::load("option/lib/member.getInfo", {mid})',
            'list_order' => 3,
        ),

        'daijiaofu_date'     => array
        (
            'type'      => 'int-11',
            'name'      => '最新的交付时间',
            'match'     => 'is_numeric',
            'desc'      => '最新的交付时间',
        ),

        'daijiaofu'      => array
        (
            'type'      => 'decimal-11,2',
            'name'      => '待交付额度',
            'default'   => '0.00',
            'desc'      => '待交付额度',
            'match'     => 'is_numeric',
            //'update'    => 'text',
            'list'      => true,
        ),

        'jiaofu'      => array
        (
            'type'      => 'decimal-11,2',
            'name'      => '已交付额度',
            'default'   => '0.00',
            'desc'      => '交付额度',
            'match'     => 'is_numeric',
            //'update'    => 'text',
            'list'      => true,
        ),

        'fafang'      => array
        (
            'type'      => 'decimal-11,2',
            'name'      => '发放额度',
            'default'   => '0.00',
            'desc'      => '发放额度',
            'match'     => 'is_numeric',
            //'update'    => 'text',
            'list'      => true,
        ),

        'duifu'      => array
        (
            'type'      => 'decimal-11,2',
            'name'      => '兑付额度',
            'default'   => '0.00',
            'desc'      => '兑付额度',
            'match'     => 'is_numeric',
            //'update'    => 'text',
            '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_order' => 2,
        ),
    ),

    'alter' => array
    (
        5 => array
        (
            array('update', 'daijiaofu', 'daijiaofu', 'decimal-11,2 0 待交付额度'),
            array('update', 'jiaofu', 'jiaofu', 'decimal-11,2 0 已交付额度'),
            array('update', 'fafang', 'fafang', 'decimal-11,2 0 发放额度'),
            array('update', 'duifu', 'duifu', 'decimal-11,2 0 兑付额度'),
        ),
        'version' => 5,
    ),

    'manage' => array
    (
        'insert' => false,
        'delete' => false,
        'edit' => false,
        'page_list' => 'cash',
    ),

    'request' => array
    (
        'getTotal' => array
        (
            'type' => 'all',
            'option' => array
            (
                'id' => 'yes',
                'aid' => 'yes',
                'mid' => 'yes',
                'state' => 1,
            ),
            'group' => 'type',
            'order' => array('daijiaofu_date' => 'desc', 'id' => 'desc'),
            'col' => '*,sum(daijiaofu) as daijiaofu, sum(jiaofu) as jiaofu, sum(fafang) as fafang, sum(duifu) as duifu',
        ),

        'upCash_daijiaofu' => array
        (
            'type' => 'update',
            'where' => array
            (
                'id' => 'yes',
            ),
            'set' => array
            (
                'cash' => array('yes-daijiaofu', '+='),
                'daijiaofu_date' => 'yes',
            ),
        ),

        'upCash_jiaofu' => array
        (
            'type' => 'update',
            'where' => array
            (
                'id' => 'yes',
            ),
            'set' => array
            (
                'cash' => array('yes-jiaofu', '+='),
            ),
        ),

        'upCash_fafang' => array
        (
            'type' => 'update',
            'where' => array
            (
                'id' => 'yes',
            ),
            'set' => array
            (
                'cash' => array('yes-fafang', '+='),
                'jiaofu' => array('yes', '-='),
            ),
        ),

        'upCash_duifu' => array
        (
            'type' => 'update',
            'where' => array
            (
                'id' => 'yes',
            ),
            'set' => array
            (
                'cash' => array('yes-duifu', '+='),
                'fafang' => array('yes', '-='),
            ),
        ),
    ),
);