<?php
$button = array();
if (Dever::load('manage/auth')->checkFunc('shop.record', 'chongzhi', '充值')) {
	$button['充值'] = array('fast',1,'record&type=1');
}
if (Dever::load('manage/auth')->checkFunc('shop.record', 'tixian', '提现')) {
	$button['提现'] = array('fast',1,'record&type=2');
}

$excel = false;
if (Dever::load('manage/auth')->checkFunc('shop.record', 'editrecord', '导出数据')) {
    $excel[] = array('数据导出','资金记录明细','shop/lib/record.out_record');
}
$shop = function()
{
    $array = array();
    $data = Dever::db('shop/info-state');
    if($data)
    {
        $array += $data;
    }
    return $array;
};
$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'),
);
$type = array
(
	1 => '对公打款充值',
	2 => '账户提现',
	3 => '订单退货返还',
	4 => '采购商品',
	// 5 => '门店罚款',
	// 6 => '平台发放',
	// 7 => '保证金',
	8 => '平台结算',
);
$manage_status = array
(
    //1 => '待审核',
    2 => '已审核',
    3 => '已作废',
);
// $fafang_status = array
// (
//     //1 => '待审核',
//     2 => '已发放',
//     3 => '已作废',
// );
$col = Dever::input('col');
$list_button = array();
$list_button['list'] = array('查看明细', '"record&project=shop&id={id}&page_type=1"');
$list_button['fast'] = array('提现审核', '"record&where_id={id}&audit=3&col=audit,audit_desc&oper_save_jump=record&oper_table=record&oper_parent=record"', '{status} == 1');
$shop_id = Dever::input('search_option_shop_id');
$info = '';
if($shop_id){
	// print_R($shop_id);die;
	$info = Dever::load('shop/lib/record')->getString($shop_id);
}
$config = array
(
    # 表名
    'name' => 'record',
    # 显示给用户看的名称
    'lang' => '资金记录明细',
    'order' => -10,
    'config_type' => $type,
    'config_status' => $status,
    'info' => $info,
    'start' => array
    (
        'insert' => 'shop/lib/record.insertRecord',
    ),
    'end' => array
    (
    	'insert' => 'shop/lib/record.updateRecord', 
    	'update' => 'shop/lib/record.RecordAuditUpdate',
    ),
    # 数据结构 不同的字段放这里
    'struct' => array
    (
        'id'        => array
        (
            'type'      => 'int-11',
            'name'      => 'ID',
            'default'   => '',
            'desc'      => '',
            'match'     => 'is_numeric',
            //'list'        => true,
        ),

        'shop_id'      => array
        (
            'type'      => 'int-11',
            'name'      => '店铺名称/店铺编号',
            'default'   => '',
            'desc'      => '店铺名称',
            'match'     => 'is_numeric',
            'option'    => $shop,
            'search'    => array
            (
                'api' => 'shop/info-like',
                'col' => '*',
                'result' => 'id',
            ) ,
            'list_name' => '门店信息',
            'list'      => 'Dever::load("shop/lib/record.order_num#name", {id})',
            'list_order' => 2,
        ),

        'sid'      => array
        (
            'type'      => 'varchar-30',
            'name'      => '店铺编号-一般为5位数字，不能重复',
            'default'   => '',
            'desc'      => '店铺编号',
            'match'     => 'is_string',
            'update'    => 'text',
            # 绑定js脚本，更新时使用，第一个参数是执行的方式，第二个参数执行的方法，第三个参数是传值。
            'bind'        => array('onblur', 'loading', array('url' => Dever::url("shop/lib/record.search"))),
        ),
      
        'order_num'      => array
        (
            'type'      => 'varchar-100',
            'name'      => '流水号',
            'default'   => '',
            'desc'      => '流水号',
            'match'     => 'is_string',
            // 'update'    => 'text',
            // 'search'    => 'fulltext',
            //'list'      => true,
            'list_name' => '流水号<br />交易时间',
            'list'      =>'Dever::load("shop/lib/record.order_num#num", {id})',
            'list_order'  => 1,
        ),

        'price'      => array
        (
            'type'      => 'decimal-11,2',
            'name'      => '金额',
            'default'   => '0',
            'desc'      => '金额',
            'match'     => 'is_numeric',
            'update'    => 'text',
            'list_name' => '交易金额<br />账户余额',
            'list'      => 'Dever::load("shop/lib/record.order_num#price", {id})',
            'list_order' => 5,
        ),

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

        'explan'      => array
        (
            'type'      => 'varchar-600',
            'name'      => '资金说明',
            'default'   => '',
            'desc'      => '资金说明',
            'match'     => 'option',
            'update'    => 'textarea',
            // 'list'      => '"{audit_desc}" ? "{audit_desc}" : "-"',
            // 'list_order'  => 9,
        ),

        'type'        => array
        (
            'type'      => 'tinyint-1',
            'name'      => '资金记录类型',
            'default'   => '1',
            'desc'      => '资金记录类型',
            'match'     => 'is_numeric',
            'option'    => $type,
            'search'    => 'select',
            'update'    => Dever::input('type') ? 'hidden' : 'select',
            'value'     => Dever::input('type'),
            //'search_after' => '<br />',
            'list'      => true,
            'list_order' => 3,
        ),

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

        'status'        => array
        (
            'type'      => 'tinyint-1',
            'name'      => '资金记录状态',
            'default'   => '1',
            'desc'      => '资金记录状态',
            'match'     => 'is_numeric',
            'option'    => $status,
            'search'    => 'select',
            //'search_after' => '<br />',
            'list'      => true,
            'list_order' => 14,
        ),

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

        'audit_desc'      => array
        (
            'type'      => 'varchar-600',
            'name'      => '备注',
            'default'   => '',
            'desc'      => '审核说明',
            'match'     => 'is_string',
            'update'    => $col ? 'textarea' : false,
            'list'      => '"{audit_desc}" ? "{audit_desc}" : "-"',
            'list_order'  => 20,
            'show'      => 'audit=3',
        ),
        // 'fafang'        => array
        // (
        //     'type'      => 'int-11',
        //     'name'      => '审核状态',
        //     'default'   => '2',
        //     'desc'      => '审核状态',
        //     'match'     => 'is_numeric',
        //     'update'    => $col ? 'radio' : false,
        //     'option'    => $fafang_status,
        //     'mul'       => true,
        //     'control'   => 'fafang',
        // ),

        // 'fafang_desc'      => array
        // (
        //     'type'      => 'varchar-600',
        //     'name'      => '备注',
        //     'default'   => '',
        //     'desc'      => '审核说明',
        //     'match'     => 'is_string',
        //     'update'    => $col ? 'textarea' : false,
        //     // 'list'      => '"{audit_desc}" ? "{audit_desc}" : "-"',
        //     // 'list_order'  => 20,
        //     'show'      => 'fafang=3',
        // ),
        'operdate'     => array
        (
            'type'      => 'int-11',
            'name'      => '审核确认时间',
            'default'   => '',
            'match'     => 'is_numeric',
            'desc'      => '',
            //'list'      => '"{operdate}" > 0 ? date("Y-m-d H:i", {operdate}) : "-"',
            //'list_order'  => 9,
        ),

        'pic'       => array
        (
            'type'      => 'text-255',
            'name'      => '打款凭证',
            'default'   => '',
            'desc'      => '多张图片',
            'match'     => 'is_string',
            'update'    => 'images',
            'key'       => '1',
            // 'place'     => '759*562',
        ),

        // 'fpic'       => array
        // (
        //     'type'      => 'text-255',
        //     'name'      => '发放凭证',
        //     'default'   => '',
        //     'desc'      => '多张图片',
        //     'match'     => 'is_string',
        //     'update'    => $col ? 'images' : false,
        //     'key'       => '1',
        //     // 'place'     => '759*562',
        //     'show'      => 'fafang=2',
        // ),

        '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})',
        ),
    ),

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

    # request 请求接口定义
    'request' => array
    (
        'getAll' => array
        (
            # 匹配的正则或函数 选填项
            'option' => array
            (
            	'start' => array('yes-cdate','>='),
            	'end' => array('yes-cdate','<='),
                'shop_id' => 'yes',
                'state' => 1,
            ),
            'type' => 'all',
            'order' => array('id'=>'desc'),
            'page' => array(10,'list'),
            'col' => 'id,shop_id,price,yue,type,status,cdate',
        ),
        'getSearch' => array
        (
            # 匹配的正则或函数 选填项
            'option' => array
            (
                'shop_id' => 'yes',
                'state' => 1,
            ),
            'type' => 'one',
            'order' => array('cdate'=>'desc'),
            'col' => 'yue',
        ),
    ),
);

return $config;