<?php

$status = array
(
    1 => array('name' => '待审核', 'style' => 'font-weight:bold;color:#436EEE'),
    2 => array('name' => '已审核', 'style' => 'font-weight:bold;color:green'),
    3 => array('name' => '已作废', 'style' => 'font-weight:bold;color:#CD3700'),
);

$manage_status = array
(
    //1 => '待审核',
    2 => '已审核',
    3 => '已作废',
);

$type = array
(
    1 => '直推佣金',
    2 => '市场培训费',
    3 => '区域管理收益',#'代理区域分润',
    4 => '活动分佣',
    10 => '手动发放',
    11 => '提现',
    12 => '消费',
    13 => '区域招商补贴',
    14 => '创V归店补贴',
);

$role = function()
{
	$array = array();
	$data = Dever::load('setting/role-state');
	if($data)
	{
		$array += $data;
	}
	return $array;
};

$mid = Dever::input('search_option_mid');
$button = array();
if ($mid) {
    $button['返回上一页'] = array('location', 'l=project/database/list&project=agent&table=member_area&page_type=1&mid=' . $mid . '&[refer]');
    if (Dever::load('manage/auth')->checkFunc('agent.member', 'edit1', '发放资金')) {
        $button['发放资金'] = array('fast', '', 'push_cash&search_option_mid=' . $mid);
    }
    // $button = array
    // (
    //     '返回上一页' => array('location', 'l=project/database/list&project=agent&table=member_area&page_type=1&mid=' . $mid),
    //     '发放资金' => array('fast', '', 'push_cash&search_option_mid=' . $mid),
    // );
}
$excel = false;
if(Dever::load('manage/auth')->checkFunc('menu_244.menu_245', 'editCout', '数据导出')){
    $excel[] = array('数据导出','代理商分润', 'bill/lib/cash.out_cash');
}

$list_button = array();
$list_button['list'] = array('查看详情', '"push_cash&project=bill&id={id}&page_type=1&[refer]"');
if (Dever::load('manage/auth')->checkFunc('bill.tixian', 'edit', '审核')) {
    $list_button['fast'] = array('审核', '"cash&where_id={id}&col=audit,audit_desc&oper_save_jump=cash&oper_table=cash&oper_parent=cash"', '{status} == 1');
}
$mul = false;
if (Dever::load('manage/auth')->checkFunc('bill.tixian', 'tixianedit', '批量审核')) {
    $mul = '{status} == 1';
}

return array
(
    # 表名
    'name' => 'cash',
    # 显示给用户看的名称
    'lang' => '资金流水',
    'auto' => 100000,
    'set' => array
    (
    	'status' => $status,
    	'type' => $type,
    ),
    'start' => array
    (
        'updatemul' => 'bill/lib/manage.cashAuditUpdateStart',
    ),

    'end' => array
    (
        'update' => 'bill/lib/manage.cashAuditUpdate',
        'updatemul' => 'bill/lib/manage.cashAuditUpdate',
    ),
    'order' => 99,
    # 数据结构
    'struct' => array
    (
    
        'id'        => array
        (
            'type'      => 'int-11',
            'name'      => 'ID',
            'default'   => '',
            'desc'      => '',
            'match'     => 'is_numeric',
            'search'    => 'order',
            //'list'        => true,
        ),

        'mid'      => array
        (
            'type'      => 'int-11',
            'name'      => '代理商姓名/手机号',
            'default'   => '-1',
            'desc'      => '代理商',
            'match'     => 'is_string',
            'update'    => 'text',
            'search'    => array
            (
                'api' => 'agent/member-getSearch',
                'col' => 'col',
                'result' => 'id',
                'search' => 'mid',
            ),
            'list_name' => '代理商信息',
            'list'      => 'Dever::load("agent/lib/member.getOne", {mid}, "agent/member", true)',
            'list_order' => 1,
        ),

        'agent-member-name'=> array
        (
            'name'      => '姓名',
            'default'   => '',
            'desc'      => '姓名',
            'match'     => 'option',
            # 读取另外表的关联方式
            'sync'      => array('mid', 'id'),
            'searchs'    => array
            (
                'api' => 'agent/member-find',
                'col' => 'name',
                'result' => 'id',
            ),
        ),

        'agent-member-role'=> array
        (
            'name'      => '代理角色',
            'default'   => '',
            'desc'      => '代理角色',
            'match'     => 'option',
            # 读取另外表的关联方式
            'sync'      => array('mid', 'id'),
            // 'list'      => 'Dever::load("setting/role-find#name", "{agent-member-role}")',
            // 'list_order' => 5,
        ),

        'order_num'      => array
        (
            'type'      => 'varchar-100',
            'name'      => '流水号',
            'default'   => '',
            'desc'      => '流水号',
            'match'     => 'is_string',
            'update'    => 'text',
            'search'    => 'fulltext',
            //'list'      => true,
            //'list_name' => '流水号<br />交易时间',
            //'list'      =>'Dever::load("bill/lib/cash.order_num#num", {id})',
            //'list_order'  => 1,
        ),

        'role'      => array
        (
            'type'      => 'int-11',
            'name'      => '代理角色',
            'default'   => '',
            'desc'      => '代理角色',
            'match'     => 'is_numeric',
            //'search'	=> 'select',
            'update'    => 'checkbox',
            'option'    => $role,
            //'list'      => true,
        ),

        'type'      => array
        (
            'type'      => 'int-11',
            'name'      => '交易类型',
            'default'   => '1',
            'desc'      => '交易类型',
            'match'     => 'is_numeric',
            'search'    => 'select',
            'update'    => 'checkbox',
            'option'    => $type,
            'list'      => true,
            'list_order' => 2,
        ),

        'type_id'      => array
        (
            'type'      => 'int-11',
            'name'      => '交易来源id',
            'default'   => '',
            'desc'      => '交易来源id',
            'match'     => 'is_string',
            'update'    => 'text',
        ),

        'cash'      => array
        (
            'type'      => 'decimal-11,2',
            'name'      => '金额',
            'default'   => '0',
            'desc'      => '金额',
            'match'     => 'is_numeric',
            'update'    => 'text',
            'list_name' => '金额<br />操作后余额',
            'list'      =>'Dever::load("bill/lib/cash.order_num#cash", {id})',
             'list_order' => 4,
        ),

        'yue'      => array
        (
            'type'      => 'decimal-11,2',
            'name'      => '操作后余额',
            'default'   => '0',
            'desc'      => '操作后余额',
            'match'     => 'is_numeric',
            'update'    => 'text',
            // 'list'      => true,
            // 'list_order' => 7,
        ),

        'status'        => array
        (
            'type'      => 'int-11',
            'name'      => '交易状态',
            'default'   => '1',
            'desc'      => '交易状态',
            'match'     => 'is_numeric',
            'update'  	=> 'hidden',
            'option'    => $status,
            'search'    => 'select',
            'list'      => true,
            'list_name' => '交易状态',
            'list_order' => 3,
        ),

        'audit'        => array
        (
            'type'      => 'int-11',
            'name'      => '审核状态',
            'default'   => '2',
            'desc'      => '审核状态',
            'match'     => 'is_numeric',
            'update'    => 'radio',
            'option'    => $manage_status,
            'mul'       => true,
            'control'   => 'audit',
        ),

        'audit_desc'      => array
        (
            'type'      => 'varchar-600',
            'name'      => '备注',
            'default'   => '',
            'desc'      => '审核说明',
            'match'     => 'is_string',
            'update'    => 'textarea',
            'list'      => '"{audit_desc}" ? "{audit_desc}" : "-"',
            'list_order'  => 5,
            'show'      => 'audit=3',
        ),

        'desc'      => array
        (
            'type'      => 'varchar-600',
            'name'      => '资金说明',
            'default'   => '',
            'desc'      => '资金说明',
            'match'     => 'is_string',
            'update'    => 'text',
        ),

        'operdate'     => array
        (
            'type'      => 'int-11',
            'name'      => '审核确认时间',
            'default'   => '',
            'match'     => 'is_numeric',
            'desc'      => '',
            //'list'      => '"{operdate}" > 0 ? date("Y-m-d H:i", {operdate}) : "-"',
            //'list_order'  => 9,
        ),

        '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_name'      => '交易时间<br />审核时间',
            'list'      => 'Dever::load("bill/lib/cash.order_num#num", {id})',
            'list_order'  => 20,
        ),
    ),

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

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

        # 获取订单数量
        'getCash' => array
        (
            # 匹配的正则或函数 选填项
            'option' => array
            (
                'start' => array('yes-cdate', '>='),
                'end' => array('yes-cdate', '<='),
                'type' => array('yes', 'in'),
                'mid' => 'yes',
                'status' => 2,
                'state' => 1,
            ),
            'type' => 'one',
            'col' => 'sum(cash) as total',
        ),
        'getwsCash' => array
        (
            # 匹配的正则或函数 选填项
            'option' => array
            (
                'start' => array('yes-cdate', '>='),
                'end' => array('yes-cdate', '<='),
                'status' => array('yes', 'in'),
                'type' => array('yes', 'in'),
                'mid' => 'yes',
                'state' => 1,
            ),
            'type' => 'one',
            'col' => 'sum(cash) as total',
        ),
        'getExcelAll' => array
        (
            # 匹配的正则或函数 选填项
            'option' => array
            (
                'start' => array('yes-cdate', '>='),
                'end' => array('yes-cdate', '<='),
                
                'state' => 1,
            ),
            'type' => 'all',
            'col' => '*',
        ),
    ),
);