<?php
# 获取分类权限
$status = array
(
    1 => '已认证',
    2 => '认证中',
    3 => '认证失败',
);

$out_template = array
(
    1 => '默认模板',
    2 => '九阳',
    3 => '纯米',
    4 => '安鲜达',
);

$cate = function()
{
    $array = array();
    $info = Dever::load('category/api')->getTop(1);
    if($info)
    {
        $array += $info;
    }
    return $array;
};

$stat_type = Dever::db('cash/shop')->config['config_type'];
return array
(
    # 表名
    'name' => 'info',
    # 显示给用户看的名称
    'lang' => '工厂列表',
    # 后台菜单排序
    'order' => 99,
    'out_template' => $out_template,
    'end' => array
    (
        'insert' => 'factory/lib/manage.infoUpdate',
        'update' => 'factory/lib/manage.infoUpdate',
    ),
    # 同步更新另外一个或多个表的多条关联数据，以逗号隔开，goods格式有变化，只能通过end处理
    /*
    'sync' => array
    (
        'factory/goods' => array
        (
            # 更新时的条件，另外一个表的字段 => 本表的字段
            'where' => array('factory_id', 'id'),
            # 要更新的数据
            'update' => array('goods_id' => 'goods'),
            # 同步更新的类型，delete为先删再插入，update为先查询是否存在，存在直接更新，不存在则插入, only为仅更新
            'type' => 'update',
        )
    ),
    */
    # 数据结构
    '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}) : "匿名用户"',
        ),
        
        'name'      => array
        (
            'type'      => 'varchar-32',
            'name'      => '工厂名称',
            'default'   => '',
            'desc'      => '请输入工厂名称',
            'match'     => 'is_string',
            'update'    => 'text',
            'search'    => 'fulltext',
            'list'      => true,
        ),

        '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'     => 'is_numeric',
            '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=3', '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',
        ),

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

        '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') ? 'text' : 'hidden',
            //'adding'  => 'tag/manage.getByCate?cate=',
            # 开启这个，需要将update更换为text类型，输入文字即可选择标签
            'autocomplete' => array('goods/lib/manage.getByName', 'id', 'goods/info-getAllByName'),
            //'search'    => 'fulltext',
            //'list'        => true,
            # 与上边的cate联动（ajax）
            //'show'  => 'cate=goods/lib/manage.getByCate?cate=',
            # 或者加入可选项
            //'option' => $cate,
        ),
        */

        '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=factory&other_id={where_id}&goods_id={id}', 'manage')),
        ),

        'hr2'       => 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',
        ),

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

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

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

        'out_template'        => array
        (
            'type'      => 'int-11',
            'name'      => '导出模板-供应链管理中导出的表格模板',
            'default'   => '1',
            'desc'      => '导出模板',
            'match'     => 'is_numeric',
            'update'    => 'select',
            'option'    => $out_template,
            '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})',
        ),
    ),

    'manage' => array
    (
        'list_table' => 'html',
        
        'list_button' => array
        (
            'new' => array('工厂管理', '"home?sign=".Dever::login({id})', 'factory'),
            //'add' => array('设置生产能力', '"info&where_id={id}&col=goods&oper_save_jump=info&oper_table=info&oper_parent=info"'),

            'location' => array('设置生产能力', Dever::url('lib/set.home', 'factory')),

            'list3' => array('商品列表', '"goods&search_option_factory_id={id}&oper_table=info"'),

            'list1' => array('账号管理', '"member&search_option_factory_id={id}&oper_table=info"'),
            
            //'list2' => array('订货单', '"order&search_option_factory_id={id}&oper_table=info"'),
        ),
    ),

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