<?php

$pay_status = Dever::config('base', 'pay')->pay['status'];

$audit = array
(
    //1 => '待审核',
    2 => '审核通过',
    3 => '审核未通过',
);

$type = Dever::db('setting/role_goods')->config['set']['type'];

$dh_type = array
(
	1 => '兑换',
	2 => '自动发放',
);

$mid = Dever::input('search_option_mid');
$button = array();
if ($mid) {
    $button = array
    (
        '返回上一页' => array('location', 'l=project/database/list&project=agent&table=member_area&page_type=1&mid=' . $mid),
    );
}

$status = array
(
    1 => '待支付',
    2 => '待审核',
    3 => '已审核（未发货）',
    4 => '已审核（已发货）',
    5 => '已完成',
    6 => '已完成（有退款）',
    7 => '作废',
    8 => '已退款',
    11 => '已过期',
);

$refund_status = array
(
    1 => '未申请',
    2 => '申请中',
    3 => '有退款',
    4 => '已退款',
);
$mid = Dever::input('search_option_mid');
return array
(
    # 表名
    'name' => 'dh_order',
    # 显示给用户看的名称
    'lang' => '权益订单',
    'order' => 80,
    'status' => $status,
    'end' => array
    (
        //'insert' => 'agent/lib/manage.sellOrderUpdate',
        'update' => 'agent/lib/manage.sellOrderUpdate',
    ),
    # 数据结构
    'struct' => array
    (
    
        'id'        => array
        (
            'type'      => 'int-11',
            'name'      => 'ID',
            'default'   => '',
            'desc'      => '',
            'match'     => 'is_numeric',
            'search'    => 'order',
            //'list'      => true,
        ), 

        'shop_id'      => array
        (
            'type'      => 'int-11',
            'name'      => '门店名称',
            'default'   => '',
            'desc'      => '门店名称',
            'match'     => 'is_numeric',
            'search'    => 'select',
            'update'    => 'hidden',
        ),

        'mid'      => array
        (
            'type'      => 'int-11',
            'name'      => '行权人',
            'default'   => '-1',
            'desc'      => '代理商',
            'match'     => 'is_string',
            'update'    => 'text',
            'searchs'    => array
            (
                'api' => 'agent/member-find',
                'col' => 'mobile',
                'result' => 'id',
            ),
            'search'    => 'hidden',
            'list'      => 'Dever::load("agent/lib/member.getOne", {mid})',
            'list_order' => 3,
        ),

        'mobile'        => array
        (
            'type'      => 'varchar-300',
            'name'      => '手机号',
            'default'   => '',
            'desc'      => '手机号',
            'match'     => 'option',
            'search'    => $mid ? 'hidden' : 'fulltext',
            'list'      => true,
            'list_order' => 4,
        ),

        'address_id'      => array
        (
            'type'      => 'int-11',
            'name'      => '送货地址',
            'default'   => '',
            'desc'      => '送货地址',
            'match'     => 'is_numeric',
        ),

        'type'        => array
        (
            'type'      => 'tinyint-1',
            'name'      => '类型',
            'default'   => '1',
            'desc'      => '类型',
            'match'     => 'is_numeric',
            'update'  	=> 'radio',
            'option'    => $type,
        ),

        'type_id'      => array
        (
            'type'      => 'int-11',
            'name'      => '类型id',
            'default'   => '-1',
            'desc'      => '类型id',
            'match'     => 'is_numeric',
            'list_name' => '权益名称',
            //'list'      => 'Dever::load("agent/lib/manage.getGoods#name", "{type}", "{type_id}", "-2")',
        ),

        'dh_type'        => array
        (
            'type'      => 'tinyint-1',
            'name'      => '行权方式',
            'default'   => '1',
            'desc'      => '行权方式',
            'match'     => 'is_numeric',
            'update'  	=> 'radio',
            'option'    => $dh_type,
            'list'		=> true,
            'list_order' => 5,
        ),

        'name'      => array
        (
            'type'      => 'varchar-800',
            'name'      => '详情',
            'default'   => '',
            'desc'      => '订单名称',
            'match'     => 'is_string',
            'update'    => 'text',
            'list'		=> true,
            'list_order' => 6,
        ),

        'order_num'      => array
        (
            'type'      => 'varchar-100',
            'name'      => '订单号',
            'default'   => '',
            'desc'      => '订单号',
            'match'     => 'is_string',
            'update'    => 'text',
            'search'    => 'fulltext',
            'list'      => true,
            'list_order' => 1,
        ),

        'price'      => array
        (
            'type'      => 'varchar-50',
            'name'      => '订单总金额',
            'default'   => '0',
            'desc'      => '实付金额',
            'match'     => 'option',
            'update'    => 'text',
            'list'      => false,
            'list_order' => 11,
        ),

        'num'        => array
        (
            'type'      => 'int-11',
            'name'      => '购买总数量',
            'default'   => '',
            'desc'      => '购买总数量',
            'match'     => 'is_numeric',
            'search'    => 'select',
            'list'        => false,
            'list_order'    => 10,
        ),

        'refund_num'        => array
        (
            'type'      => 'int-11',
            'name'      => '退款数量',
            'default'   => '0',
            'desc'      => '退款数量',
            'match'     => 'is_numeric',
        ),

        'refund_cash'      => array
        (
            'type'      => 'float-11,2',
            'name'      => '退款金额',
            'default'   => '0',
            'desc'      => '已退订单金额',
            'match'     => 'option',
            'update'    => 'text',
        ),

        'refund_status'        => array
        (
            'type'      => 'tinyint-1',
            'name'      => '退款状态',
            'default'   => '1',
            'desc'      => '申请退款状态',
            'match'     => 'is_numeric',
            'option'    => $refund_status,
        ),

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

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

        'audit'        => array
        (
            'type'      => 'tinyint-1',
            'name'      => '审核状态',
            'default'   => '2',
            'desc'      => '审核状态',
            'match'     => 'is_numeric',
            'option'    => $audit,
            //'search'    => 'select',
            'update'    => 'radio',
        ),

        'audit_desc'        => array
        (
            'type'      => 'varchar-500',
            'name'      => '审核备注',
            'default'   => '',
            'desc'      => '审核备注',
            'match'     => 'option',
            'update'    => 'textarea',
        ),

        'fdate'     => array
        (
            'type'      => 'int-11',
            'name'      => '完成时间',
            'default'   => '',
            'match'     => 'is_numeric',
            'desc'      => '',
        ),

        'operdate'     => array
        (
            'type'      => 'int-11',
            'name'      => '操作时间',
            'default'   => '',
            'match'     => 'is_numeric',
            'desc'      => '',
            //'list'      => '"{operdate}" > 0 ? date("Y-m-d H:i:s", {operdate}) : "-"',
            //'list_name' => '发货时间',
            //'list_order' => 8,
        ),

        '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", {cdate})',
            //'list'      => 'Dever::load("service/lib/manage.showOrderTime", "{id}")',
            'list_order' => 2,
        ),
    ),

    'manage' => array
    (
        'delete' => false,
        'edit' => false,
        'insert' => false,

        'button' => $button,

        'list_button' => array
        (
            //fast_list
            'list' => array('查看详情', '"dh_order_goods&project=agent&order_id={id}&page_type=1"', '{type} == 1'),

            'list1' => array('查看采购单', '"buy_order&project=shop&search_option_type=1&search_option_parent_type=3&search_option_parent_order_id={id}&oper_table=dh_order&oper_project=agent"', '{type} == 1 && {status} >= 3 && {audit} == 2'),

            'fast' => array('审核', '"dh_order&where_id={id}&col=audit,audit_desc&oper_save_jump=dh_order&oper_table=dh_order&oper_parent=dh_order"', '{type} == 1 && {status} == 2'),

            'oper'  => array('确认收货', '"agent/lib/manage.setDhOrderStatus?mid={mid}&order_id={id}"', '{type} == 1 && {status} == 4'),
        ),
    ),

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

        'getAll' => array
        (
            # 匹配的正则或函数 选填项
            'option' => array
            (
                'name' => array('yes', 'like'),
                'mid' => 'yes',
                'mobile' => 'yes',
                'start' => array('yes-cdate', '>='),
                'end' => array('yes-cdate', '<='),
                'status' => array('yes', 'in'),
                'state' => 1,
            ),
            'type' => 'all',
            'order' => array('cdate' => 'desc'),
            'page' => array(10, 'list'),
            'col' => '*',
        ),

        'getYes' => array
        (
            # 匹配的正则或函数 选填项
            'option' => array
            (
                'mid' => 'yes',
                'state' => 1,
            ),
            'type' => 'all',
            'order' => array('cdate' => 'desc'),
            'col' => '*',
        ),

        # 获取提交订单超过12个小时
        'getDataByTime' => array
        (
            # 匹配的正则或函数 选填项
            'option' => array
            (
                'cdate' => array('yes', '<='),
                'status' => array('yes', 'in'),
                'state' => 1,
            ),
            'type' => 'all',
            'order' => array('cdate' => 'desc'),
            'col' => '*',
        ),

        # 获取1,2
        'getBuy' => array
        (
            # 匹配的正则或函数 选填项
            'option' => array
            (
                'status' => 'yes',
                'mid' => 'yes',
                'order_num' => 'yes',
                'uid' => 'yes',
                'state' => 1,
            ),
            'type' => 'all',
            'order' => array('id' => 'desc'),
            'col' => '*',
        ),

        'getMyAll' => array
        (
            # 匹配的正则或函数 选填项
            'option' => array
            (
                'uid' => 'yes',
                'status' => 'yes',
                'cate_id' => 'yes',
                'state' => 1,
            ),
            'type' => 'all',
            'order' => array('id' => 'desc'),
            'page' => array(10, 'list'),
            'col' => 'id,order_num,name,buy_num,cdate,cash,mid,buy_id',
        ),

        # 删除未支付订单
        'drop' => array
        (
            # 匹配的正则或函数 选填项
            'where' => array
            (
                'time' => array('yes-cdate', '<='),
                'status' => 1,
                'state' => 1,
            ),
            'type' => 'delete',
            'col' => 'id,order_num',
        ),

        # 获取数据
        'getAllByDate' => array
        (
            # 匹配的正则或函数 选填项
            'where' => array
            (
                'start' => array('yes-cdate', '>='),
                'end' => array('yes-cdate', '<='),
                'status' => array('yes', 'in'),
                'state' => 1,
            ),
            'type' => 'all',
            'col' => 'id,order_num,mobile,mid,cdate,price-refund_cash as total,num-refund_num as num',
        ),

        # 获取订单数量
        'getOrderNum' => array
        (
            # 匹配的正则或函数 选填项
            'option' => array
            (
                'start' => array('yes-cdate', '>='),
                'end' => array('yes-cdate', '<='),
                'mid' => 'yes',
                'status' => array('yes', 'in'),
                'state' => 1,
            ),
            'type' => 'count',
            'col' => '*',
        ),

        # 获取总金额
        'getCashNum' => array
        (
            # 匹配的正则或函数 选填项
            'option' => array
            (
                'start' => array('yes-cdate', '>='),
                'end' => array('yes-cdate', '<='),
                'mid' => 'yes',
                'status' => array('yes', 'in'),
                'state' => 1,
            ),
            'type' => 'one',
            'col' => 'sum(price-refund_cash) as total',
        ),

        # 获取商品数量
        'getGoodsNum' => array
        (
            # 匹配的正则或函数 选填项
            'option' => array
            (
                'start' => array('yes-cdate', '>='),
                'end' => array('yes-cdate', '<='),
                'mid' => 'yes',
                'status' => array('yes', 'in'),
                'state' => 1,
            ),
            'type' => 'one',
            'col' => 'sum(num-refund_num) as total',
        ),

        # 获取订单数量
        'getUser' => array
        (
            # 匹配的正则或函数 选填项
            'option' => array
            (
                'start' => array('yes-cdate', '>='),
                'end' => array('yes-cdate', '<='),
                'mid' => 'yes',
                'status' => array('yes', 'in'),
                'state' => 1,
            ),
            'type' => 'all',
            'group' => 'mobile',
            'col' => 'count(mobile) as total',
        ),

        'getUserNum' => array
        (
            # 匹配的正则或函数 选填项
            'option' => array
            (
                'start' => array('yes-cdate', '>='),
                'end' => array('yes-cdate', '<='),
                'mid' => 'yes',
                'status' => array('yes', 'in'),
                'state' => 1,
            ),
            'type' => 'count',
            'col' => '*',
        ),
    ),
);
