<?php
# 获取分类权限
$status = array
(
    1 => '合作中',
    2 => '已终止合作',
    //3 => '申请合作中',
);

$type = array
(
    1 => '体验店',
    2 => '零售店',
    10 => '平台店',
);

$invoice = array
(
    1 => '可以开发票',
    2 => '不可以开发票',
);

$col = 'id,name,`desc`,ps_cash,free_ps_cash,truename,mobile,lng,lat,address,open,worktime,method,gotime,city,area,province,county,town,coupon_city,pdesc,license,food_license,jy_license,license_number,company_name,coord_address,invoice,type,mid';

$act = function()
{
    $info = Dever::db('act/info')->select();
    
    $id = Dever::input('where_id');
    $coupon = Dever::db('shop/coupon')->select(array('shop_id' => $id));
    if ($coupon) {
        foreach ($coupon as $k => $v) {
            $coupon_info = Dever::db('goods/coupon')->find($v['coupon_id']);
            if (isset($coupon_info['method'])) {
                $prefix = '（'.Dever::db('goods/coupon')->config['method'][$coupon_info['method']].'）';
                $coupon[$k]['name'] = $prefix . $coupon_info['name'];
            }
        }
    }
    foreach ($info as $k => $v) {
        if ($v['id'] == 1) {
            $info[$k]['child'] = $coupon;
        }
    }
    $info['state'] = 2;//1是无需记录上级id，字符串逗号隔开。2是需要记录上级id，json格式
    return $info;
};

$yes = array
(
    1 => '可用',
    2 => '不可用',
);

$open = array
(
    1 => '开启',
    2 => '关闭',
);

$method = array
(
    1 => '自提',
    2 => '外送',
    3 => '以上全支持',
);

$stat_type = Dever::db('cash/shop')->config['config_type'];

return array
(
    # 表名
    'name' => 'info',
    # 显示给用户看的名称
    'lang' => '门店列表',
    # 后台菜单排序
    'order' => 99,
    'act' => $act,
    'config_col' => $col,
    'check' => 'sid',
    'config_type' => $type,

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

        'hr1'       => array
        (
            'name'      => '门店基本信息',
            'class'     => '',//本项必须填写
            'attr'      => '',
        ),

        'uid'       => array
        (
            'type'      => 'int-11',
            'name'      => '用户名',
            'default'   => '0',
            'desc'      => '请选择用户',
            'match'     => 'is_numeric',
            //'update'    => 'text',
            //'search'  => 'select',
            'searchs'    => array
            (
                'api' => 'passport/user-select',
                'col' => 'username',
                'result' => 'id',
            ),
            //'list'      => '{uid} > 0 ? Dever::load("passport/user-find#username", {uid}) : "匿名用户"',
        ),

        'sid'      => array
        (
            'type'      => 'varchar-30',
            'name'      => '店铺编号-一般为5位数字，不能重复',
            'default'   => '',
            'desc'      => '店铺编号',
            'match'     => 'is_string',
            'update'    => 'text',
            'search'    => 'fulltext',
            'list'      => true,
        ),
        
        'name'      => array
        (
            'type'      => 'varchar-32',
            'name'      => '门店名称',
            'default'   => '',
            'desc'      => '请输入门店名称',
            'match'     => 'is_string',
            'update'    => 'text',
            'search'    => 'fulltext',
            'list'      => true,
        ),

        'desc'      => array
        (
            'type'      => 'varchar-800',
            'name'      => '门店介绍',
            'default'   => '',
            'desc'      => '门店介绍',
            'match'     => 'is_string',
            'update'    => 'textarea',
        ),

        'truename'      => array
        (
            'type'      => 'varchar-100',
            'name'      => '联系人姓名',
            'default'   => '',
            'desc'      => '请输入联系人姓名',
            'match'     => 'is_string',
            'update'    => 'text',
            'search'    => 'fulltext',
            'list'      => true,
        ),

        'mobile'      => array
        (
            'type'      => 'bigint-11',
            'name'      => '联系人电话',
            'default'   => '',
            'desc'      => '请输入联系人电话',
            'match'     => Dever::rule('mobile'),
            'update'    => 'text',
            'search'    => 'fulltext',
            'list'      => true,
        ),

        'area'       => array
        (
            'type'      => 'varchar-500',
            'name'      => '所在街道',
            'default'   => '',
            'desc'      => '所在街道',
            'match'     => 'option',
            'search'    => 'linkage',
            'update'    => 'linkage',
            'option'    => Dever::url('api.get?level_total=4', 'area'),
            //'list'      => 'Dever::load("area/api.string", "{area}")',
        ),

        'province'      => array
        (
            'type'      => 'int-11',
            'name'      => '省份',
            'default'   => '',
            'desc'      => '省份',
            'match'     => 'option',
            //'update'  => 'text',
        ),

        'city'      => array
        (
            'type'      => 'int-11',
            'name'      => '城市',
            'default'   => '',
            'desc'      => '城市',
            'match'     => 'option',
            //'update'  => 'text',
        ),

        'county'      => array
        (
            'type'      => 'int-11',
            'name'      => '县区',
            'default'   => '',
            'desc'      => '县区',
            'match'     => 'option',
            //'update'  => 'text',
        ),

        'town'      => array
        (
            'type'      => 'int-11',
            'name'      => '街道',
            'default'   => '',
            'desc'      => '街道',
            'match'     => 'option',
            //'update'  => 'text',
        ),

        'map'       => array
        (
            'type'      => 'varchar-300',
            'name'      => '地理位置',
            'default'   => '',
            'desc'      => '地理位置',
            'match'     => 'is_string',
            # 如果是map，必须在config的base.php中设置map信息
            //'update'  => 'map',
        ),

        'lng'       => array
        (
            'type'      => 'varchar-100',
            'name'      => '经度',
            'default'   => '',
            'desc'      => '经度',
            'match'     => 'option',
            //'update'    => 'text',
            //'list'        => true,
        ),

        'lat'       => array
        (
            'type'      => 'varchar-100',
            'name'      => '纬度',
            'default'   => '',
            'desc'      => '纬度',
            'match'     => 'option',
            //'update'    => 'text',
            //'list'        => true,
        ),

        'coord_address'       => array
        (
            'type'      => 'varchar-1000',
            'name'      => '门店坐标地址',
            'default'   => '',
            'desc'      => '门店坐标地址',
            'match'     => 'option',
            //'update'    => 'text',
            //'list'        => true,
        ),

        'address'       => array
        (
            'type'      => 'varchar-1000',
            'name'      => '门店地址',
            'default'   => '',
            'desc'      => '门店地址',
            'match'     => 'option',
            'update'    => 'text',
            //'list'        => true,
        ),

        'goods'       => array
        (
            'type'      => 'text-255',
            'name'      => '请先选择分类-选择分类，之后选择分类下的商品，点击商品名称可以设置库存',
            'default'   => '',
            'desc'      => '生产能力',
            'match'     => 'option',
            // 多级联动+多选
            'update'    => Dever::input('col') ? 'linkage' : false,
            'option'    => array(Dever::url('api.get', 'category'), 'cate_id', Dever::url('lib/info.getGoods', 'goods'), '快速设置', Dever::url('project/database/list?project=goods&table=info_sku&page_type=1&other=shop&other_id={where_id}&goods_id={id}', 'manage')),
        ),

        'factory'       => array
        (
            'type'      => 'text-255',
            'name'      => '分配工厂-请先选择地区，再选择工厂',
            'default'   => '',
            'desc'      => '分配工厂',
            'match'     => 'option',
            // 多级联动+多选
            'update'    => Dever::input('col') ? 'linkage' : false,
            'option'    => array(Dever::url('api.get?level_total=3', 'area'), 'city', Dever::url('lib/manage.getInfo', 'factory'), '分配工厂'),
        ),

        'store'       => array
        (
            'type'      => 'text-255',
            'name'      => '分配仓库-请先选择地区，再选择仓库',
            'default'   => '',
            'desc'      => '分配仓库',
            'match'     => 'option',
            // 多级联动+多选
            'update'    => Dever::input('col') ? 'linkage' : false,
            'option'    => array(Dever::url('api.get?level_total=3', 'area'), 'city', Dever::url('lib/manage.getInfo', 'store'), '分配仓库'),
        ),

        'hr2'       => array
        (
            'name'      => '门店营业设置',
            'class'     => '',//本项必须填写
            'attr'      => '',
        ),

        'open'        => array
        (
            'type'      => 'int-11',
            'name'      => '营业状态',
            'default'   => '1',
            'desc'      => '营业状态',
            'match'     => 'is_numeric',
            'update'    => 'radio',
            'option'    => $open,
            'search'    => 'select',
            'list'      => true,
        ),

        'method'        => array
        (
            'type'      => 'int-11',
            'name'      => '门店能力',
            'default'   => '3',
            'desc'      => '门店能力',
            'match'     => 'is_numeric',
            'update'    => 'radio',
            'option'    => $method,
            'control'   => 'method',
        ),

        'worktime'      => array
        (
            'type'      => 'varchar-100',
            'name'      => '营业时间-如10:00~22:00，24小时制',
            'default'   => '',
            'desc'      => '营业时间',
            'match'     => 'is_string',
            'update'    => 'text',
            //'show'      => 'method=1,3',
        ),

        'gotime'      => array
        (
            'type'      => 'varchar-100',
            'name'      => '外送时间-如10:00~22:00，24小时制',
            'default'   => '',
            'desc'      => '外送时间',
            'match'     => 'is_string',
            //'update'    => 'text',
            //'show'      => 'method=2,3',
        ),

        'hr3'       => array
        (
            'name'      => '门店认证信息',
            'class'     => '',//本项必须填写
            'attr'      => '',
        ),

        'license'     => array
        (
            'type'      => 'varchar-150',
            'name'      => '营业执照',
            'default'   => '',
            'desc'      => '营业执照',
            'match'     => 'option',
            'update'    => 'image',
            'key'       => '8',
            'place'     => '660*660',
        ),

        'license_number'      => array
        (
            'type'      => 'varchar-200',
            'name'      => '营业执照号码',
            'default'   => '',
            'desc'      => '营业执照号码',
            'match'     => 'option',
            'update'    => 'text',
        ),

        'company_name'      => array
        (
            'type'      => 'varchar-200',
            'name'      => '公司名称',
            'default'   => '',
            'desc'      => '公司名称',
            'match'     => 'option',
            'update'    => 'text',
        ),

        'idcard_front'     => array
        (
            'type'      => 'varchar-150',
            'name'      => '身份证正面',
            'default'   => '',
            'desc'      => '身份证正面',
            'match'     => 'option',
            'update'    => 'image',
            'key'       => '8',
            'place'     => '660*660',
        ),

        'idcard_back'     => array
        (
            'type'      => 'varchar-150',
            'name'      => '身份证背面',
            'default'   => '',
            'desc'      => '身份证背面',
            'match'     => 'option',
            'update'    => 'image',
            'key'       => '8',
            'place'     => '660*660',
        ),

        'jy_license'     => array
        (
            'type'      => 'varchar-150',
            'name'      => '经营许可证',
            'default'   => '',
            'desc'      => '经营许可证',
            'match'     => 'option',
            'update'    => 'image',
            'key'       => '8',
            'place'     => '660*660',
        ),

        'food_license'     => array
        (
            'type'      => 'varchar-150',
            'name'      => '食品许可证',
            'default'   => '',
            'desc'      => '食品许可证',
            'match'     => 'option',
            'update'    => 'image',
            'key'       => '8',
            'place'     => '660*660',
        ),

        'hr4'       => array
        (
            'name'      => '其他设置',
            'class'     => '',//本项必须填写
            'attr'      => '',
        ),

        'type'        => array
        (
            'type'      => 'int-11',
            'name'      => '门店类型-自营为平台店，当没有找到加盟店时，将自动获取平台店',
            'default'   => '1',
            'desc'      => '门店类型',
            'match'     => 'is_numeric',
            'update'    => 'radio',
            'option'    => $type,
            'search'    => 'select',
            'list'      => true,
        ),

        'invoice'        => array
        (
            'type'      => 'int-11',
            'name'      => '是否可以开发票',
            'default'   => '1',
            'desc'      => '是否可以开发票',
            'match'     => 'is_numeric',
            'update'    => 'radio',
            'option'    => $invoice,
        ),

        'coupon_city'        => array
        (
            'type'      => 'int-11',
            'name'      => '优惠券是否同城可用-废弃',
            'default'   => '2',
            'desc'      => '优惠券是否同城可用',
            'match'     => 'is_numeric',
            //'update'    => 'radio',
            //'update'    => Dever::input('col') ? 'radio' : false,
            'option'    => $yes,
        ),

        'act'       => array
        (
            'type'      => 'text-255',
            'name'      => '参与活动',
            'default'   => '',
            'desc'      => '参与活动',
            'match'     => 'option',
            'update'    => 'checkbox',
            'update'    => Dever::input('col') ? 'checkbox' : false,
            'data'      => 'parent',
            'option'    => $act,
        ),

        'mid'      => array
        (
            'type'      => 'varchar-50',
            'name'      => '分账商户号',
            'default'   => '',
            'desc'      => '分账商户号',
            'match'     => 'option',
            'update'    => 'text',
        ),

        'ps_cash'      => array
        (
            'type'      => 'varchar-50',
            'name'      => '运费-单位为元',
            'default'   => '0',
            'desc'      => '运费',
            'match'     => 'option',
            'update'    => 'text',
        ),

        'free_ps_cash'      => array
        (
            'type'      => 'varchar-50',
            'name'      => '免运费额度-满多少免运费，这里直接填写一个订单满多少金额就免费配送的金额，单位为元',
            'default'   => '0',
            'desc'      => '免运费额度',
            'match'     => 'option',
            'update'    => 'text',
        ),

        'pdesc'      => array
        (
            'type'      => 'text-255',
            'name'      => '配送与自提说明',
            'default'   => '',
            'desc'      => '配送与自提说明',
            'match'     => 'is_string',
            'update'    => 'textarea',
        ),

        'stat_type'        => array
        (
            'type'      => 'int-11',
            'name'      => '对账周期-可以选择周期生成对账单，选择按天生成对账单，则每天会生成前一天的对账单',
            'default'   => '1',
            'desc'      => '对账周期',
            'match'     => 'is_numeric',
            'update'    => 'radio',
            'option'    => $stat_type,
            'control'   => 'stat_type',
        ),

        'stat_day'      => array
        (
            'type'      => 'int-11',
            'name'      => '对账单生成日期-这里直接填写对账周期内的第几天即可，如按月对账，这里填写10，就是本月10号生成上一个月的对账单，如按周对账，这里填写2，就是本周二生成上一周的对账单',
            'default'   => '10',
            'desc'      => '对账单生成日期',
            'match'     => 'option',
            'update'    => 'text',
            'show'      => 'stat_type=1,2',
        ),

        'status'        => array
        (
            'type'      => 'int-11',
            'name'      => '合作状态',
            'default'   => '1',
            'desc'      => '合作状态',
            'match'     => 'is_numeric',
            //'update'  => 'select',
            'option'    => $status,
            'search'    => 'select',
            'list'      => true,
            'edit'      => true,
        ),

        'reorder'       => array
        (
            'type'      => 'int-11',
            'name'      => '排序(数值越大越靠前)',
            'default'   => '1',
            'desc'      => '请输入排序',
            'match'     => 'option',
            'update'    => 'text',
            'search'    => 'order',
            //'list'      => true,
            'order'     => 'desc',
            //'edit'      => true,
        ),

        '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,
            //'list'      => 'date("Y-m-d H:i:s", {cdate})',
        ),
    ),

    'alter' => array
    (
        2 => array
        (
            array('update', 'sid', 'sid', 'varchar-30  店铺编号'),
        ),
        'version' => 2,
    ),

    'manage' => array
    (
        //'mul' => true,
        //'insert' => false,
        'list_button' => array
        (
            'delete' => '删除',

            'br11' => array('<br /><br />'),

            'location1' => array('分配工厂', Dever::url('lib/set.factory', 'shop')),

            'location2' => array('分配仓库', Dever::url('lib/set.store', 'shop')),
            /*
            'add12' => array('分配工厂', '"info&where_id={id}&col=factory&oper_save_jump=info&oper_table=info&oper_parent=info"'),

            'add13' => array('分配仓库', '"info&where_id={id}&col=store&oper_save_jump=info&oper_table=info&oper_parent=info"'),
            */
            'fast' => array('设置活动', '"info&where_id={id}&col=act&oper_save_jump=info&oper_table=info&oper_parent=info"'),

            'br1' => array('<br /><br />'),

            'location' => array('商品设置', Dever::url('lib/set.home', 'shop')),
            //'add1' => array('批量设置商品', '"info&where_id={id}&col=goods&oper_save_jump=info&oper_table=info&oper_parent=info"'),
            'list22' => array('商品列表', '"goods&search_option_shop_id={id}&oper_table=info"'),


            'br2' => array('<br /><br />'),

            'list' => array('优惠券管理', '"coupon&search_option_shop_id={id}&oper_table=info"'),
            'list1' => array('账号管理', '"member&search_option_shop_id={id}&oper_table=info"'),
            'list2' => array('打印机管理', '"print&search_option_shop_id={id}&oper_table=info"'),

            //'br3' => array('<br /><br />'),

            //'list3' => array('销售订单', '"sell_order&search_option_shop_id={id}&oper_table=info"'),
            //'list4' => array('采购订单', '"buy_order&search_option_shop_id={id}&oper_table=info"'),
        ),
    ),

    'request' => array
    (
        # 获取单条数据
        'getOne' => array
        (
            # 匹配的正则或函数 选填项
            'option' => array
            (
                'city' => 'yes',
                'coupon_city' => 'yes',
                'id' => 'yes',
                'status' => 1,
                'state' => 1,
            ),
            'type' => 'one',
            'col' => $col,
        ),

        # 获取城市
        'getCity' => array
        (
            # 匹配的正则或函数 选填项
            'option' => array
            (
                'city' => 'yes',
                'id' => 'yes',
                'status' => 1,
                'state' => 1,
            ),
            'type' => 'all',
            'group' => 'city',
            'col' => $col,
        ),

        # 获取城市
        'getDataByType' => array
        (
            # 匹配的正则或函数 选填项
            'option' => array
            (
                'type' => 'yes',
                'id' => 'yes',
                'status' => 1,
                'state' => 1,
            ),
            'type' => 'one',
            'order' => array('reorder' => 'desc', 'id' => 'desc'),
            'col' => $col,
        ),

        'like' => array
        (
            # 匹配的正则或函数 选填项
            'option' => array
            (
                'name' => array('yes', 'like'),
                'sid' => array('yes', 'like'),
                'type' => array('yes', 'like'),
                'id' => 'yes',
                'status' => 1,
                'state' => 1,
            ),
            'type' => 'all',
            'order' => array('reorder' => 'desc', 'id' => 'desc'),
            'col' => $col . '|id',
        ),

        'getAll' => array
        (
            # 匹配的正则或函数 选填项
            'option' => array
            (
                'type' => array('yes', '!='),
                'town' => 'yes',
                'area' => array('yes', 'like'),
                'state' => 1,
            ),
            'type' => 'all',
            'order' => array('reorder' => 'desc', 'id' => 'desc'),
            'col' => 'id,id as value, name',
        ),

        'getInfo' => array
        (
            # 匹配的正则或函数 选填项
            'option' => array
            (
                'type' => 'yes',
                'state' => 1,
            ),
            'type' => 'one',
            'order' => array('reorder' => 'desc', 'id' => 'desc'),
            'col' => 'id,id as value, name',
        ),
    ),
);
