<?php
$wid = Session::get('wid');
$is_yg = Session::get('is_yg', 0);
$userAgency = (new Model('user_agency'))->find(['isadmin'=>1]);
$indexList = array(
    '数据分析' => array(
    'name'  => '数据分析',
    'style' => '<i class="fa fa-bar-chart-o icon"></i>',
    'id'    => 'm14',
    'sub'   => array(

      array(
        'name' => '数据分析',
        'file' => 'Addons/QyWechat/Admin/Datas/statistics',
      ),
    ),
  ),
 
              '企微设置' => array(
    'name'  => '企微设置',
    'style' => '<i class="fa fa-comment-o icon"></i>',
    'id'    => 'm10',
    'sub'   => array(

      array(
        'name' => '企微设置',
        'file' => 'Addons/QyWechat/Admin/QyWechat/qy_set',
      ),
	  	  array(
        'name' => '企微助手',
        'file' => 'Addons/QyWechat/Admin/MessageSend/message_send_set',
      ),

    ),
  ),
        '引流获客' => array(
    'name'  => '引流获客',
    'style' => '<i class="font_family theicon icon-neirongshichang"></i>',
    'id'    => 'm14',
    'sub'   => array(

      array(
        'name' => '渠道活码',
        'file' => 'Addons/QyWechat/Admin/Externalcontact/contact_way',
      ),


       array(
        'name' => '进群宝',   
        'file' => 'Addons/Inqunbao/Admin/Inqunbao/mission_list',
      ),

    ),
  ),

          '客户管理' => array(
    'name'  => '客户管理',
    'style' => '<i class="fa fa-user icon"></i>',
    'id'    => 'm14',
    'sub'   => array(

      array(
        'name' => '客户管理',
        'file' => 'Addons/QyWechat/Admin/Externalcontact/customer_list',
      ),
      array(
        'name' => '客户标签',
        'file' => 'Addons/QyWechat/Admin/Externalcontact/tag_manage',
      ),
	    array(
        'name' => '流失客户',
        'file' => 'Addons/QyWechat/Admin/Externalcontact/del_follow_user_record',
      ),
      array(
        'name' => '欢迎语',
        'file' => 'Addons/QyWechat/Admin/Users/welcome_msg',
      ),
    ),
  ),
           '消息群发' => array(
    'name'  => '消息群发',
    'style' => '<i class="fa fa-user icon"></i>',
    'id'    => 'm14',
    'sub'   => array(

	        array(
        'name' => '群发个人',
        'file' => 'Addons/QyWechat/Admin/Externalcontact/msg_template',
      ),
      array(
        'name' => '群发到群',
        'file' => 'Addons/QyWechat/Admin/MarketingTools/group_send_manage',
      ),

    ),
  ),
            '客户群管理' => array(
    'name'  => '客户群管理',
    'style' => '<i class="fa fa-bars icon"></i>',
    'id'    => 'm14',
    'sub'   => array(

      array(
        'name' => '客户群列表',
        'file' => 'Addons/QyWechat/Admin/Externalcontact/groupchat_list',
      ),
      array(
        'name' => '成员群数据',
        'file' => 'Addons/QyWechat/Admin/Externalcontact/user_creat_groupchat_statistic',
      ),
	  	 array(
        'name' => '欢迎语',
        'file' => 'Addons/QyWechat/Admin/Externalcontact/group_welcome_template',
      ),
    ),
  ),
  '侧边栏' => array(
    'name'  => '侧边栏',
    'style' => '<i class="fa fa-window-restore icon"></i>',
    'id'    => 'm10',
    'sub'   => array(

      array(
        'name' => '应用配置',
        'file' => 'Addons/QyWechat/Admin/Reply/quick_reply_steps',
      ),
      array(
        'name' => '快捷回复',
        'file' => 'Addons/QyWechat/Admin/Reply/quick_reply',
      ),

    ),
  ),
            '通讯录管理' => array(
    'name'  => '通讯录管理',
    'style' => '<i class="fa fa-id-card-o icon"></i>',
    'id'    => 'm16',
    'sub'   => array(

      array(
        'name' => '通讯录管理',
        'file' => 'Addons/QyWechat/Admin/Users/user_list',
      ),

    ),
  ),


  '账户中心'  => array(
    'name'  => '账户中心',
    'style' => '<i class="fa  fa-home icon"></i>',
    'id'    => 'm2',
    'sub'   => array(

      array(
        'name' => '修改密码',
        'file' => 'userCenter/updatePwd',
      ),

    ),
  ),


);

$dir = DOXCX_FRAME_PATH.'controller/admin/caidan';
$fileList=getFileList($dir);
foreach($fileList as $value){
	include $dir.'/'.$value;
}

$fileList=getAddonsFileList('menu');
// 读取模块配置文件
foreach($fileList as $value){
    $arr=include($value);
    $indexList=array_replace_recursive($indexList,(array)$arr['menu']);

}
$agency=get_user_agency();
$userMenu = (new Model('user_menu'))->find(['pid'=>$agency->id]);
if(!$userMenu->id){
	$userMenu = (new Model('user_menu'))->find(['pid'=>$userAgency->id]);
}
$menusort=json_decode($userMenu->menusort,1);
$menuname=json_decode($userMenu->menuname,1);
if($userMenu->id){
	foreach($indexList as $k=>$m){
		$indexList[$k]['id']=$menusort[$k];
		if($menuname[$k]){
			$indexList[$k]['name']=$menuname[$k];
		}
	}
	if(count($menusort)){
		array_multisort(array_column($indexList,'id'),SORT_ASC,$indexList);
	}
}



if ($is_yg != 1) {
  // 非员工
  $index = $indexList;
} else {
  // 员工
  $yg_id = Session::get('yg_id', 0);
  $yg = (new Model('yg'))->find(['wid' => $wid, 'id' => $yg_id]);
  if (!$yg_id || !$yg->id) {
    Redirect::to('/logout');
  } else {
    $authority=json_decode($yg->authority,true);
    $index=[];
    foreach ($authority as $a) {
      if(array_key_exists($a, $indexList)){
        $index[]=$indexList[$a];
      }
    }
  }
}

return [
  $indexList,
  $index,
];