<?php

$shop_id = Dever::input('search_option_shop_id');

$method = Dever::db('goods/coupon')->config['method'];

$time = array
(
    3 => '3天',
    7 => '7天',
    15 => '15天',
    30 => '30天',
    90 => '90天',
    182 => '182天',
    365 => '365天',
);

return array
(
    # 表名
    'name' => 'coupon',
    # 显示给用户看的名称
    'lang' => '优惠券设置',
    'menu' => false,
    'time' => $time,
    'check' => 'shop_id,coupon',
    'end' => array
    (
        'insert' => 'shop/lib/manage.couponUpdate',
        'update' => 'shop/lib/manage.couponUpdate',
    ),
    # 数据结构
    'struct' => array
    (
    
        'id'        => array
        (
            'type'      => 'int-11',
            'name'      => 'ID',
            'default'   => '',
            'desc'      => '',
            'match'     => 'is_numeric',
            'search'    => 'order',
            'update'    => 'hidden',
            //'list'        => true,
        ),

        'shop_id'      => array
        (
            'type'      => 'int-11',
            'name'      => '所属门店',
            'default'   => '',
            'desc'      => '所属门店',
            'match'     => 'is_numeric',
            'update'    => 'hidden',
            'search'    => 'hidden',
            'value'     => Dever::input('search_option_shop_id'),
            'list'      => 'Dever::load("shop/info-find#name", {shop_id})',
        ),

        'coupon'       => array
        (
            'type'      => 'varchar-500',
            'name'      => '优惠券',
            'default'   => '',
            'desc'      => '优惠券',
            'match'     => 'option',
            //'search'    => 'linkage',
            'update'    => 'linkage',
            'option'    => Dever::url('lib/coupon.get', 'goods'),
        ),

        'method'      => array
        (
            'type'      => 'int-11',
            'name'      => '优惠券属性',
            'default'   => '',
            'desc'      => '优惠券属性',
            'match'     => 'option',
            'search'    => 'select',
            //'update'    => 'select',
            'option'    => $method,
            'list'      => true,
        ),

        'coupon_id'      => array
        (
            'type'      => 'int-11',
            'name'      => '优惠券',
            'default'   => '',
            'desc'      => '优惠券',
            'match'     => 'option',
            'list'      => 'Dever::load("goods/coupon-find#name", {coupon_id})',
        ),

        'city'      => array
        (
            'type'      => 'int-11',
            'name'      => '城市',
            'default'   => '',
            'desc'      => '城市',
            'match'     => 'option',
            //'update'    => 'hidden',
            //'value'     => Dever::input('search_option_city'),
        ),

        'day'        => array
        (
            'type'      => 'int-11',
            'name'      => '有效期-请选择天数',
            'default'   => '7',
            'desc'      => '有效期',
            'match'     => 'is_numeric',
            'update'    => 'select',
            'option'    => $time,
        ),

        'num'      => array
        (
            'type'      => 'int-11',
            'name'      => '发放数量-数量为0则不限量',
            'default'   => '10',
            'desc'      => '发放数量',
            'match'     => 'is_string',
            'update'    => 'text',
            'list'        => true,
        ),

        'act_num'      => array
        (
            'type'      => 'int-11',
            'name'      => '已用数量',
            'default'   => '0',
            'desc'      => '已用数量',
            'match'     => 'is_string',
            //'update'    => 'text',
            'list_name' => '剩余数量',
            'list'      => '{num}-{act_num}',
        ),

        '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
    (
        'button' => array
        (
            //'分享领取优惠券活动设置' => array('fast', 1, 'coupon_act_1&where_id='.$shop_id.'&search_option_shop_id='.$shop_id),
        ),
    ),

    'request' => array
    (
        # 列表
        'getAllPage' => array
        (
            # 匹配的正则或函数 选填项
            'option' => array
            (
                'shop_id' => 'yes',
                'method' => 'yes',
                'state' => 1,
            ),
            'type' => 'all',
            'page' => array(10, 'list'),
            'order' => array('id' => 'desc'),
            'col' => '*,num-act_num as num',
        ),

        # 列表
        'getAll' => array
        (
            # 匹配的正则或函数 选填项
            'option' => array
            (
                'shop_id' => 'yes',
                'method' => 'yes',
                'state' => 1,
            ),
            'type' => 'all',
            'order' => array('id' => 'desc'),
            'col' => '*,num-act_num as num',
        ),

        'getData' => array
        (
            # 匹配的正则或函数 选填项
            'option' => array
            (
                'id' => 'yes',
                'shop_id' => 'yes',
                'coupon_id' => 'yes',
                'method' => 'yes',
                'state' => 1,
            ),
            'type' => 'all',
            'order' => array('id' => 'desc'),
            'col' => '*,num-act_num as total',
        ),

        'getOne' => array
        (
            # 匹配的正则或函数 选填项
            'option' => array
            (
                'id' => 'yes',
                'shop_id' => 'yes',
                'coupon_id' => 'yes',
                'method' => 'yes',
                'state' => 1,
            ),
            'type' => 'one',
            'col' => '*,num-act_num as total',
        ),

        # 更新使用量
        'updateNum' => array
        (
            'type' => 'update',
            'where' => array
            (
                'id' => 'yes',
            ),
            'set' => array
            (
                'act_num' => array('yes', '+='),
            ),
        ),
    ),
);
