<?php
$excel = false;
$excel[] = array('数据导出','数据导出','active/lib/excel.out_active_order');
$list_button = array();
if (Dever::load('manage/auth')->checkFunc('active.order', 'editRefund', '全额退款')) {
    $list_button['oper'] = array('全额退款', '"active/lib/manage.refund?id={id}"', '{status} == 2');
}
$pay_type = array
(
    1 => '在线支付',
);

$status = array
(
    1 => '待支付',
    2 => '已支付',
    3 => '已关闭',#超时未支付
    4 => '已完成',
    5 => '已完成（有退款）',
    6 => '已退款',#(全部退款)
);
$active = function()
{
    $array = array();
    $info = Dever::load('active/info-state');
    if($info)
    {
        $array += $info;
    }
    return $array;
};

return array
(
    # 表名
    'name' => 'order',
    # 显示给用户看的名称
    'lang' => '活动订单',
    'order' => 100,
    'config_status' => $status,
    'config_pay_type' => $pay_type,
    # 数据结构
    'struct' => array
    (
    
        'id'        => array
        (
            'type'      => 'int-11',
            'name'      => 'ID',
            'default'   => '',
            'desc'      => '',
            'match'     => 'is_numeric',
            'search'    => 'order',
            // 'list'      => true,
        ), 

        'order_num'      => array
        (
            'type'      => 'varchar-100',
            'name'      => '订单单号',
            'default'   => '',
            'desc'      => '订单单号',
            'match'     => 'is_string',
            'update'    => 'text',
            'search'    => 'fulltext',
            '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)',
        ),

        'active_id'      => array
        (
            'type'      => 'int-11',
            'name'      => '活动名称',
            'default'   => '-1',
            'desc'      => '活动名称',
            'match'     => 'is_string',
            'option'    => $active,
            'update'    => 'text',
            // 'search'    => 'text',
            'list'      => true,
        ),

        'num'        => array
        (
            'type'      => 'varchar-100',
            'name'      => '数量',
            'default'   => '',
            'desc'      => '数量',
            'match'     => 'option',
            'list'      => true,
        ),

        'price'        => array
        (
            'type'      => 'varchar-50',
            'name'      => '金额',
            'default'   => '0',
            'desc'      => '金额',
            'match'     => 'option',
            'update'    => 'text',
            'list'      => true,
        ),

        'status'        => array
        (
            'type'      => 'tinyint-1',
            'name'      => '支付状态',
            'default'   => '1',
            'desc'      => '支付状态',
            'match'     => 'is_numeric',
            'option'    => $status,
            'search'    => 'select',
            'list'      => true,
        ),

        'pay_type'        => array
        (
            'type'      => 'tinyint-1',
            'name'      => '支付类型',
            'default'   => '1',
            'desc'      => '支付类型',
            'match'     => 'is_numeric',
            'option'    => $pay_type,
            'search'    => 'select',
            'list'      => true,
        ),

        'remark'      => array
	    (
	        'type'      => 'varchar-300',
	        'name'      => '订单备注',
	        'default'   => '',
	        'desc'      => '订单备注',
	        'match'     => 'option',
	        'update'    => 'textarea',
	    ),

	    'url'      => array
        (
            'type'      => 'varchar-3000',
            'name'      => '支付链接',
            'default'   => '',
            'desc'      => '支付链接',
            'match'     => 'is_string',
            // 'update'    => 'fulltext',
            //'search'    => 'fulltext',
            //'list'      => true,
        ),

        'refund_admin' => array
        (
            'type'      => 'int-11',
            'name'      => '退款操作人',
            'default'   => '',
            'desc'      => '',
            'match'     => 'is_numeric',
           // 'search'    => 'order',
            'list_name' => '退款操作人<br>退款时间',
            'list'        => 'Dever::load("active/lib/manage.show",{id})',
        ),

        'rdate'     => array
        (
            'type'      => 'int-11',
            'name'      => '退款时间',
            'default'   => '',
            'match'     => 'is_numeric',
            'search'    => 'date',
            // 'desc'      => '',
            // 'list'      => 'date("Y-m-d H:i:s", {zdate})',
        ),

        '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'	=> $excel,
        'list_button' => $list_button,
    ),

    'request' => array
    (
        // # 获取数量
        'getNum' => array
        (
            # 匹配的正则或函数 选填项
            'option' => array
            (
                'mid' => 'yes',
                'active_id' => 'yes',
                'status' =>2,
                'state' => 1,
            ),
            'type' => 'one',
            'col' => 'sum(num) as total',
        ),
        'getAll' => array
        (
            # 匹配的正则或函数 选填项
            'option' => array
            (
                'mid' => 'yes',
                'status' => array('yes','!='),
                'state' => 1,
            ),
            'type' => 'all',
            'order' => array('cdate'=>'desc'),
            'page' => array(20,'list'),
            'col' => '*',
        ),
    ),
);
