<?php
$people = function()
{
    $array = array();
    $data = Dever::db('clue/user_set')->state();
    if($data)
    {
    	
        $array += $data;
    }
    return $array;
};

$source = function()
{
    $array = array();
    $data = Dever::db('clue/source')->state(array('type'=>1));
    if($data)
    {
        $array += $data;
    }
    return $array;
};
$status = function()
{
    $array = array();
    $data = Dever::db('clue/sale_status')->state();
    if($data)
    {
        $array += $data;
    }
    return $array;
};
// $selepeople = function()
// {
//     $array = array();
//     $data = Dever::db('clue/salepeople')->state();
//     if($data)
//     {
//     	foreach ($data as $k => $v) {
//     		$data[$k]['name'] = $v['group'];
//     	}
//         $array += $data;
//     }
//     return $array;
// };
$sex = array
(
    1 => '未知',
    2 => '男',
    3 => '女',
);
$type = array
(
    1 => '待分派',
    2 => '待跟进',
    3 => '已跟进',
    4 => '已完成',
    5 => '已关闭',
    6 => '未跟进',
);
$out_type = array
(
    1 => '否',
    2 => '是',
);
$admin = Dever::load("manage/auth.info");
$admin_id = '';
if ($admin) {
    $admin_id = $admin['id'];
}
$search_auth = Dever::input('search_option_dever_auth', 2);
if ($search_auth ==2) {
	$company = Dever::load('manage/company.get');
	$admin = Dever::db('manage/admin')->find($admin_id);
	if ($admin) {
		$admin['group'] = explode(',',$admin['group']);
		foreach ($admin['group'] as $k =>$v) {
			$group = Dever::db('manage/group')->find(array('company_id'=>$company,'id'=>$v));
		}
		if ($group) {
			$work = Dever::db('work/branch')->find(array('group_id'=>$group['id']));
			if ($work) {
				$work['group'] = explode(',',$work['group']);
				if (isset($work['group'][1]) && $work['group'][1] && $work['group'][1] == $admin_id) {
					$audit_group = Dever::setInput('search_option_follow_group_id', $group['id']);
				} else {
					$audit_admin = Dever::setInput('search_option_follow_admin_id', $admin_id);
				}
			}
		}
	}
}
$list_button = array();
$list_button['location'] = array('查看详情',Dever::url('lib/info.show','clue'));
$list_button ['fast_add'] = array('转派','info&where_id={id}&col=follow', '{type}<4 || {type}>5');
$excel[] = array('数据导出','线索列表数据导出', 'clue/lib/manage.out_info');
$button = array();
$button['线索导入'] = array('fast','','import&project=clue&call=clue/lib/manage.import');
$col = Dever::input('col');
$mul = false;
// if (Dever::load('manage/auth')->checkFunc('menu_61.menu_85', 'piliangfafang', '批量收货')) {
    // $mul = '({type} < 4 || {type} > 5)';
// } elseif (Dever::load('manage/auth')->checkFunc('menu_61.menu_218', 'piliangfafang', '批量收货')) {
//     $mul = '({status} == 4 || {status} == 2) && {shop_type} == 2';
// }
return array
(
    # 表名
    'name' => 'info',
    # 显示给用户看的名称
    'lang' => '创建新线索',
    # 后台菜单排序
    'order' => 100,
    // 'menu' => false,
    // 'auto' => 100000,
    'start' => array
    (
    	'insert' => 'clue/lib/info.insertInfo',
    	// 'updatemul' => 'clue/lib/info.setInfoFollow',
    	// 'update' => 'clue/lib/info.insertInfo',
    ),
    'end' => array
    (
        'insert' => 'clue/lib/info.updateInfo',
        'update' => 'clue/lib/info.updateInfo',
        // 'updatemul' => 'clue/lib/info.setInfoFollow',
    ),
    'config_type' => $type,
    'config_sex'  => $sex,
    # 数据结构
    'struct' => array
    (
        'id'        => array
        (
            'type'      => 'int-11',
            'name'      => 'ID',
            'default'   => '',
            'desc'      => '',
            'match'     => 'is_numeric',
            'search'    => 'order',
            'list'      => true,
            'order'     => 'desc',
        ),

        'company_id'       => array
        (
            'type'      => 'int-11',
            'name'      => '所属公司',
            'default'   => '1',
            'desc'      => '所属公司',
            'match'     => 'is_numeric',
            'update'    => 'hidden',
            //'search'    => $company ? 'select' : false,
            //'list'      => true,
        ),

        'day'     => array
        (
            'type'      => 'int-11',
            'name'      => '计划下次跟进时间',
            'default'   => '',
            'match'     => 'is_numeric',
            'desc'      => '',
            'search'    => 'sdate',
            'search_buttons' => array
            (
                // 'sum' => 'buy_num,buy_cash,sell_num,sell_cash,sl_num',
                'option' => array(
                    'day' => '按天',
                    'week' => '按周',
                    'month' => '按月',
                ),
                // 'group' => 'id',
            ),
            // 'order'     => 'desc',
            'list'      =>  'Dever::load("clue/lib/info.getNum#xdate",{id})',
            // 'Dever::showDay("{day}")',
            'list_order' => 5,
        ),
        'name'      => array
        (
            'type'      => 'varchar-32',
            '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',
            // 'value'     => Dever::input('search_option_mobile'),
            'list_name' => '客户信息',
            'list'      => 'Dever::load("clue/lib/info.getNum#user",{id})',#true,
            'list_order' => 2,
        ),

        'wechat'      => array
        (
            'type'      => 'varchar-32',
            'name'      => '微信号',
            'default'   => '',
            'desc'      => '微信号',
            'match'     => 'option',
            'update'    => 'text',
            // 'search'    => 'fulltext',
            // 'list'      => true,
        ),

        'qq'      => array
        (
            'type'      => 'varchar-32',
            'name'      => 'QQ号',
            'default'   => '',
            'desc'      => 'QQ号',
            'match'     => 'option',
            'update'    => 'text',
            // 'search'    => 'fulltext',
            // 'list'      => true,
        ),

        'source'      => array
        (
            'type'      => 'int-11',
            'name'      => '来源',
            'default'   => '1',
            'desc'      => '来源',
            'match'     => 'is_string',
            'option'    => $source,
            'update'    => 'radio',
            'search'    => 'select',
            'list'      => true,
        ),

        'area'       => array
        (
            'type'      => 'varchar-32',
            'name'      => '所在城市',
            'default'   => '',
            'desc'      => '所在城市',
            'match'     => 'option',
            'search'    => 'linkage',
            'update'    => 'linkage',
            'option'    => Dever::url('api.get?level_total=2', 'area'),
            'list'      => 'Dever::load("clue/lib/info.getNum#area",{id})',
        ),

        'clue_num'      => array
        (
            'type'      => 'varchar-50',
            'name'      => '线索编号',
            'default'   => '',
            'desc'      => '线索编号',
            'match'     => 'is_string',
            'update'    => 'hidden',
            // 'search'    => 'fulltext',
            // 'list'      => true,
        ),

        'sex'      => array
        (
            'type'      => 'int-11',
            'name'      => '性别',
            'default'   => '1',
            'desc'      => '性别',
            'match'     => 'is_string',
            'option'    => $sex,
            'update'    => 'radio',
            // 'search'    => 'select',
            // 'list'      => true,
        ),

        'age'      => array
        (
            'type'      => 'varchar-32',
            'name'      => '年龄',
            'default'   => '',
            'desc'      => '年龄',
            'match'     => 'option',
            'update'    => 'text',
            // 'search'    => 'fulltext',
            // 'list'      => true,
        ),

        'trade'      => array
        (
            'type'      => 'varchar-50',
            'name'      => '行业',
            'default'   => '',
            'desc'      => '行业',
            'match'     => 'option',
            'update'    => 'text',
            // 'search'    => 'fulltext',
            // 'list_name' => '计划下次跟进时间',
            // 'list'      => 'Dever::load("clue/lib/info.getNum#xdate",{id})',
            // 'list_order' => 5,
        ),
        
        'desc'       => array
        (
            'type'      => 'text-100',
            'name'      => '竞品了解',
            'default'   => '',
            'desc'      => '竞品了解',
            'match'     => 'option',
            'update'    => 'textarea',
            // 'list_name' => '跟进次数',
            // 'list'      => 'Dever::load("clue/lib/info.getNum#num",{id})',
            // 'list_order' => 4,
        ),

        'num'        => array
        (
            'type'      => 'int-11',
            'name'      => '跟进次数',
            'default'   => '0',
            'desc'      => '数量',
            'match'     => 'option',
            'update'    => 'hidden',
            'list'      => 'Dever::load("clue/lib/info.getNum#num",{id})',
            'list_order' => 4,
        ),

        'userset_id'      => array
        (
            'type'      => 'int-11',
            'name'      => '客户等级',
            'default'   => '-1',
            'desc'      => '客户等级',
            'match'     => 'is_string',
            'search'    => 'select',
            'update'    => 'select',
            'option'    => $people,
            'list'      => true,
            'list_order' => 3,
        ),

        'status_id'      => array
        (
            'type'      => 'int-11',
            'name'      => '线索状态',
            'default'   => '1',
            'desc'      => '线索状态',
            'match'     => 'is_string',
            'option'    => $status,
            'update'    => 'select',
            // 'search'    => $search_auth == 1 ? 'select' : false,
            // 'list'      => true,
            'control'	=> 'status_id',
        ),

        'out_type'      => array
        (
            'type'      => 'int-11',
            'name'      => '是否导入',
            'default'   => '1',
            'desc'      => '是否导入',
            'match'     => 'is_string',
            'option'    => $out_type,
            // 'update'    => 'select',
            // 'search'    => $search_auth == 1 ? 'select' : false,
            // 'list'      => true,
            // 'control'	=> 'status_id',
        ),

        'status_desc'       => array
        (
            'type'      => 'text-255',
            'name'      => '结论备注',
            'default'   => '',
            'desc'      => '结论备注',
            'match'     => 'is_string',
            'update'    => 'textarea',
            'update'    => $col ? 'textarea' : false,
            'show'      => 'status_id=5,6',
            // 'list'      => true,
        ),

        'follow_id'      => array
        (
            'type'      => 'int-11',
            'name'      => '跟进人表id',
            'default'   => '-1',
            'desc'      => '跟进人',
            'match'     => 'is_string',
            // 'option'    => $priority,
            // 'update'    => 'select',
            // 'search'    => 'select',
            // 'list'      => true,
        ),

        'follow'       => array
        (
            'type'      => 'varchar-32',
            'name'      => $col ? '选择队友' : '分派销售员',
            'default'   => '',
            'desc'      => '分派销售员',
            'match'     => 'option',
            // 'search'    => 'linkage',
            'update'    => 'linkage',
            'option'    => Dever::url('lib/salepeople.get?level_total=2', 'clue'),
            // $salepeople,
            'list_name' => '跟进人',
            'list'      => 'Dever::load("clue/lib/info.getNum#people",{id})',
            // 'mul'   => true,
            // 'mul_option' => Dever::url('lib/salepeople.get?level_total=2', 'clue'),
        ),


        'follow_admin_id'      => array
        (
            'type'      => 'int-11',
            'name'      => '跟进人',
            'default'   => '-1',
            'desc'      => '跟进人',
            'match'     => 'is_string',
            // 'value'     => $audit_admin,
            // 'option'    => $priority,
            // 'update'    => 'select',
            // 'search'    => 'select',
            // 'list'      => true,
        ),

         'follow_group_id'       => array
        (
            'type'      => 'int-11',
            'name'      => '部门',
            'default'   => '',
            'desc'      => '部门',
            'match'     => 'option',
            // 'search'    => 'linkage',
            'update'    => 'hidden',
            // 'option'    => Dever::url('lib/appoint.get?level_total=2', 'work'),
        ),

         'create_group_id'       => array
        (
            'type'      => 'int-11',
            'name'      => '创建人部门',
            'default'   => '',
            'desc'      => '部门',
            'match'     => 'option',
            // 'search'    => 'linkage',
            'update'    => 'hidden',
            // 'option'    => Dever::url('lib/appoint.get?level_total=2', 'work'),
        ),
        'create_admin_id'       => array
        (
            'type'      => 'int-11',
            'name'      => '创建人',
            'default'   => '',
            'desc'      => '部门',
            'match'     => 'option',
            // 'search'    => 'linkage',
            'update'    => 'hidden',
            // 'option'    => Dever::url('lib/appoint.get?level_total=2', 'work'),
        ),

        'fdate'     => array
        (
            'type'      => 'int-11',
            'name'      => '完成时间',
            'default'   => '',
            'match'     => 'is_numeric',
            // 'search'    => 'date',
            'list_name' => '创建时间<br/>最近跟进时间',
            // 'desc'      => '',
            'list'      => 'Dever::load("clue/lib/info.getNum#time",{id})',
            'list_order' => 1,
        ),

        'gdate'     => array
        (
            'type'      => 'int-11',
            'name'      => '跟进时间',
            'default'   => '',
            'match'     => 'is_numeric',
            // 'search'    => 'date',
        ),

        'type'      => array
        (
            'type'      => 'int-11',
            'name'      => '跟进状态',
            'default'   => '1',
            'desc'      => '跟进状态',
            'match'     => 'is_string',
            'option'    => $type,
            // 'update'    => 'select',
            'search'    => 'select',
            'list'      => true,
            // 'list_order' => 22,
        ),

        'audit_admin'     => array
        (
            'type'      => 'int-11',
            'name'      => '创建人',
            'default'   => '',
            'match'     => 'is_numeric',
            'desc'      => '创建人',
            'update'    => 'hidden',
            'value'     => $admin_id,
            // 'list'      => 'Dever::load("active/lib/manage.active#admin_name",{id})',
        ),

         'dever_auth'      => array
        (
            'name'      => '搜索',
            'default'   => '',
            'desc'      => '类型',
            'match'     => 'is_string',
            'search'    => 'hidden',
        ),

        'remark'       => array
        (
            'type'      => 'text-255',
            'name'      => '备注',
            'default'   => '',
            'desc'      => '备注',
            'match'     => 'option',
            'update'    => 'textarea',
            // 'list'      => 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,
            'search'    => 'date',
            // 'order'     => 'desc',
            // 'list'      => 'date("Y-m-d H:i:s", {cdate})',
        ),
    ),

    'manage' => array
    (
    	// 'insert' => true,
        'delete' => false,
        'edit' => false,
        'list_button' => $list_button,
        // 'data' => $data,
        'button' => $button,
        'excel'  => $excel,
        'mul' =>$mul,
        # 设置公司权限
        'company' => 'company_id',
    ),

    'request' => array
    (
    	'list_option' => array
        (
         'col' => 'yes-follow_admin_id,follow_group_id',
         'type' => array('yes', 'in'),
         'state' =>1,
        ),
        'list' => array
        (
            # 匹配的正则或函数 选填项
            'option' => array
            (
                'id' => 'yes',
                'area' => array('yes','like'),
                'name' => array('yes','like'),
                'mobile' => 'yes',
                'source' => 'yes',
                'userset_id' => 'yes',
                'type' => 'yes',
                'out_type' =>'yes',
                'start_cdate'=>array('yes-cdate','>='),
                'end_cdate' => array('yes-cdate','<='),
                'follow_admin_id' => 'yes',
                'follow_group_id' => 'yes',
                // 'area' => array('yes', 'like'),
                'start_day' => array('yes-day', '>='),
                'end_day' => array('yes-day', '<='),
                'state' => 1,
            ),
            'type' => 'all',
            'order' => array('cdate' => 'desc'),
            'page' => array(20, 'list'),
            // 'group' => 'shop_id',
            'col' => '*',
        ),
       	'getAll' => array
        (
            # 匹配的正则或函数 选填项
            'option' => array
            (
            	'start' => array('yes-cdate','>='),
            	'end'=>array('yes-cdate','<='),
                'follow_group_id' =>'yes',
                'create_group_id' => 'yes',
                // 'type' =>array('yes','in'),
                'state' => 1,
            ),
            'type' => 'all',
            // 'order' => array('reorder' => 'desc', 'id' => 'desc'),
            // 'page' => array(5,'list'),
            'col' => '*|follow_admin_id',
        ),

        'getHAll' => array
        (
            # 匹配的正则或函数 选填项
            'option' => array
            (
            	'start' => array('yes-cdate','>='),
            	'end'=>array('yes-cdate','<='),
                'follow_group_id' =>'yes',
                'gstart' => array('yes-gdate','>='),
                'gend' => array('yes-gdate','<='),
                'fstart' => array('yes-fdate','>='),
                'fend' => array('yes-fdate','<='),
                'type' =>array('yes','in'),
                'state' => 1,
            ),
            'type' => 'count',
            // 'order' => array('reorder' => 'desc', 'id' => 'desc'),
            // 'page' => array(5,'list'),
            'col' => '*',
        ),
    ),
);
