empcrm; View::assign('empdata', $empdata); $root_id = $request->empcrm->root_id; if ($empdata['empcrm_module'] == 1) $allmenu = $this->get_pcmenu($empdata); if ($empdata['empcrm_module'] == 2) $allmenu = $this->get_sqmenu($empdata); View::assign('menu', $allmenu['menu']); View::assign('leftnav', $allmenu['leftnav']); $switch_type = 0; if ($empdata['empcrm_module'] == 1 && $empdata['community_disable'] == 0) $switch_type = 2; if ($empdata['empcrm_module'] == 2 && $empdata['empcrm_disable'] == 0) $switch_type = 1; View::assign('switch_type', $switch_type); //查询加入的公司 $login_type = session('empcrm_login_type'); $where = [ ['root_id', '<>', $request->empcrm->root_id], ['state', '=', '在职'], ['uid', '>', 0], ]; if ($login_type == 'phone_login') { $where[] = ['phone', '=', cypherphone($request->empcrm->phone)]; } if ($login_type == 'wx_login') { $field = 'unionid'; $empcrm = session('empcrm'); // $user_id = User::where($field, '=', $empcrm[$field])->column('id'); // $where[] = ['uid', 'in', $user_id]; $where[] = [$field, '=', $empcrm->$field]; } $root_ids = Employee::where($where)->column('id', 'root_id'); $ydate = date('Y-m-d', strtotime('-1 day')); $condition = [ ['root_id', 'in', array_keys($root_ids)], ['end_date', '>', $ydate . ' 23:59:59'], ['status', '=', 0] ]; $shop = Company::with(['brand'])->where($condition)->field('company_name,root_id,logo,company_brand')->select()->toArray(); foreach ($shop as $key => $value) { $shop[$key]['employee_id'] = $root_ids[$value['root_id']]; if ($value['brand'] && $value['brand']['logo'] && !$value['logo']) { $shop[$key]['logo'] = $value['brand']['logo']; } } View::assign('shop', $shop); return View::fetch(); } /** * 获取PC端的菜单 */ public function get_pcmenu($empdata) { $channel_setting = Company::where(['root_id' => $empdata['root_id']])->value('channel_setting'); if ($empdata->is_manager == 1) { $menu = [ ['name' => '首页', 'url' => 'empcrm/index'], ['name' => '客户池', 'url' => 'empcrm/list'], ['name' => '指派客户', 'url' => 'manager_emp/shareList'], ['name' => '分配资源', 'url' => 'empcrm/resources_list'], ['name' => '资源库管理', 'url' => 'manager_emp/resource'], ['name' => '转移客户', 'url' => 'empcrm/assignment_list'], ['name' => '待回访', 'url' => 'empcrm/repay_list'], //['name'=>'待确认','url'=>'empcrm/stay_confirm_list'], ['name' => '见面', 'url' => 'empcrm/confirm_visit_list'], ['name' => $empdata['xinjushang'] == 1 ? '交定' : '签单', 'url' => 'empcrm/jiaoding_list'], ['name' => '有效申请', 'url' => 'valid_check/list'], ['name' => '公共库', 'url' => 'empcrm/pool_list'], ['name' => '账户明细', 'url' => 'manager_emp/extension_report'], ['name' => '账户渠道', 'url' => 'manager_emp/account_report'], ['name' => '日报', 'url' => 'empcrm/daily'], ['name' => '校对', 'url' => 'manager_emp/proofread'], ['name' => '员工统计', 'url' => 'empcrm/generalStatistics'], ['name' => '客户统计', 'url' => 'manager_emp/customer_statistics_list'], ]; if (isset($channel_setting)) { $tmp_data = json_decode($channel_setting, true); if (isset($tmp_data['fish_access_token']) && $empdata['clue_disable'] == 0) $menu[] = ['name' => '渠道统计', 'url' => 'empcrm/fish_total']; if (isset($tmp_data['fish_access_token']) && $empdata['clue_disable'] == 0) $menu[] = ['name' => '飞鱼线索', 'url' => 'empcrm/fish_list']; if (isset($tmp_data['tx_access_token']) && !empty($tmp_data['tx_adv']) && $empdata['clue_disable'] == 0) $menu[] = ['name' => '腾讯线索', 'url' => 'empcrm/tencent_list']; } $leftnav = [ ['name' => '首页', 'ishref' => 1, 'url' => 'empcrm/index', 'child' => []], ['name' => '客户数据', 'ishref' => 0, 'url' => '', 'child' => [ ['name' => '客户池', 'ishref' => 1, 'url' => 'empcrm/list'], ['name' => '分配资源', 'url' => 'empcrm/resources_list'], ['name' => '资源库管理', 'url' => 'manager_emp/resource'], ['name' => '见面', 'ishref' => 1, 'url' => 'empcrm/confirm_visit_list'], ['name' => '待确认', 'ishref' => 1, 'url' => 'empcrm/stay_confirm_list'], ['name' => '待回访', 'ishref' => 1, 'url' => 'empcrm/repay_list'], ['name' => $empdata['xinjushang'] == 1 ? '交定' : '签单', 'ishref' => 1, 'url' => 'empcrm/jiaoding_list'], ['name' => $empdata['xinjushang'] == 1 ? '签单' : '转单', 'ishref' => 1, 'url' => 'empcrm/achment_list'], ]], ['name' => '相关报表', 'ishref' => 0, 'url' => '', 'child' => [ ['name' => '年报明细', 'url' => 'manager_emp/year_report'], ['name' => '推广明细', 'url' => 'manager_emp/extension_report'], ['name' => '日报', 'ishref' => 1, 'url' => 'empcrm/daily'], ['name' => '账户渠道', 'ishref' => 1, 'url' => 'manager_emp/account_report'], ['name' => '员工报表', 'ishref' => 1, 'url' => 'empcrm/emp_daily'], ['name' => '设计师报表', 'ishref' => 1, 'url' => 'manager_emp/designer_report'], ['name' => '无效报表', 'ishref' => 1, 'url' => 'empcrm/invalid_report'] ]], ['name' => '新报表', 'ishref' => 0, 'url' => '', 'child' => [ ['name' => '销售报表', 'url' => 'statistics2/sale'], ['name' => '设计师部门报表', 'ishref' => 1, 'url' => 'statistics2/designerDepartment'], ['name' => '渠道报表', 'url' => 'statistics2/source'] ]], ['name' => '公共库', 'ishref' => 1, 'url' => 'empcrm/pool_list', 'child' => []], ['name' => '搜索', 'ishref' => 1, 'url' => 'empcrm/search_list', 'child' => []], ['name' => '校对', 'ishref' => 1, 'url' => 'manager_emp/proofread', 'child' => []], ]; } else { $menu = [ ['name' => '首页', 'url' => 'empcrm/index'], ['name' => '搜索', 'url' => 'empcrm/search_list'], ['name' => '日报', 'url' => 'empcrm/daily'], ['name' => '客户池', 'url' => 'empcrm/list'], ['name' => '指派客户', 'url' => 'manager_emp/shareList'], ['name' => '分配资源', 'url' => 'empcrm/resources_list'], ['name' => '待回访', 'url' => 'empcrm/repay_list'], ['name' => '待确认', 'url' => 'empcrm/stay_confirm_list'], ['name' => '见面', 'url' => 'empcrm/confirm_visit_list'], ['name' => $empdata['xinjushang'] == 1 ? '交定' : '签单', 'url' => 'empcrm/jiaoding_list'], ['name' => '有效申请', 'url' => 'valid_check/apply_list'], ['name' => '转移客户', 'url' => 'empcrm/assignment_list'], ['name' => '公共库', 'url' => 'empcrm/pool_list'], ['name' => '校对', 'url' => 'manager_emp/proofread'], ]; if (isset($channel_setting)) { // dump($empdata['clue_disable']); $tmp_data = json_decode($channel_setting, true); if (isset($tmp_data['fish_access_token']) && $empdata['clue_disable'] == 0) $menu[] = ['name' => '飞鱼线索', 'url' => 'empcrm/fish_list']; if (isset($tmp_data['tx_access_token']) && !empty($tmp_data['tx_adv']) && $empdata['clue_disable'] == 0) $menu[] = ['name' => '腾讯线索', 'url' => 'empcrm/tencent_list']; } $leftnav = [ ['name' => '首页', 'ishref' => 1, 'url' => 'empcrm/index', 'child' => []], ['name' => '客户数据', 'ishref' => 0, 'url' => '', 'child' => [ ['name' => '客户池', 'ishref' => 1, 'url' => 'empcrm/list'], ['name' => '分配资源', 'url' => 'empcrm/resources_list'], ['name' => '见面', 'ishref' => 1, 'url' => 'empcrm/confirm_visit_list'], ['name' => '待确认', 'ishref' => 1, 'url' => 'empcrm/stay_confirm_list'], ['name' => '待回访', 'ishref' => 1, 'url' => 'empcrm/repay_list'], ['name' => $empdata['xinjushang'] == 1 ? '交定' : '签单', 'ishref' => 1, 'url' => 'empcrm/jiaoding_list'], ['name' => $empdata['xinjushang'] == 1 ? '签单' : '转单', 'ishref' => 1, 'url' => 'empcrm/achment_list'], ]], ['name' => '统计学习', 'ishref' => 0, 'url' => '', 'child' => [ ['name' => '日报', 'url' => 'empcrm/daily'], ['name' => '员工报表', 'url' => 'empcrm/emp_daily'], ['name' => '无效报表', 'ishref' => 1, 'url' => 'empcrm/invalid_report'], ['name' => '公共库', 'ishref' => 1, 'url' => 'empcrm/pool_list'], ]], ['name' => '搜索', 'ishref' => 1, 'url' => 'empcrm/search_list', 'child' => []], ]; } return ['menu' => $menu, 'leftnav' => $leftnav]; } /** * 获取社群端的菜单 */ public function get_sqmenu($empdata) { if ($empdata->is_manager == 1) { $menu = [ ['name' => '首页', 'url' => 'community/index'], ['name' => '客户池', 'url' => 'community/list'], ['name' => '待回访', 'url' => 'community/repay_list'], ['name' => '见面', 'url' => 'community/confirm_visit_list'], ['name' => $empdata['xinjushang'] == 1 ? '交定' : '签单', 'url' => 'community/jiaoding_list'], ['name' => $empdata['xinjushang'] == 1 ? '签单' : '转单', 'ishref' => 1, 'url' => 'community/achment_list'], ['name' => '公共库', 'url' => 'community/pool_list'], ['name' => '搜索', 'url' => 'community/search_list'], ['name' => '日报', 'url' => 'community/daily'], ['name' => '楼盘报表', 'url' => 'community/community_report'], ['name' => '业务报表', 'url' => 'community/employee_report'], ['name' => '汇总报表', 'url' => 'community/summary_report'], ['name' => '运营报表', 'url' => 'community/operate_report'], ['name' => '运营', 'url' => 'community/operate_list'] ]; $leftnav = [ ['name' => '首页', 'ishref' => 1, 'url' => 'community/index', 'child' => []], ['name' => '数据统计', 'ishref' => 0, 'url' => '', 'child' => [ ['name' => '日报', 'ishref' => 1, 'url' => 'community/daily'], ['name' => '楼盘报表', 'ishref' => 1, 'url' => 'community/community_report'], ['name' => '员工报表', 'ishref' => 1, 'url' => 'community/employee_report'], ['name' => '设计师报表', 'ishref' => 1, 'url' => 'community/designer_report'], ['name' => '年报汇总', 'url' => 'community/summary_report'] ]], ['name' => '客户数据', 'ishref' => 0, 'url' => '', 'child' => [ ['name' => '客户池', 'ishref' => 1, 'url' => 'community/list'], ['name' => '分派', 'url' => 'community/assignment_list'], ['name' => '见面', 'url' => 'community/confirm_visit_list'], ['name' => '待回访', 'ishref' => 1, 'url' => 'community/repay_list'], ['name' => $empdata['xinjushang'] == 1 ? '交定' : '签单', 'ishref' => 1, 'url' => 'community/jiaoding_list'], ['name' => $empdata['xinjushang'] == 1 ? '签单' : '转单', 'ishref' => 1, 'url' => 'community/achment_list'], //['name'=>'故事力','ishref'=>1,'url'=>''], ]], ['name' => '其它统计', 'ishref' => 1, 'url' => '', 'child' => [ ['name' => '登陆详情', 'ishref' => 1, 'url' => 'community/login_record'], ]] ]; } else { $menu = [ ['name' => '首页', 'url' => 'community/index'], ['name' => '客户池', 'url' => 'community/list'], ['name' => '待回访', 'url' => 'community/repay_list'], ['name' => '见面', 'url' => 'community/confirm_visit_list'], ['name' => $empdata['xinjushang'] == 1 ? '交定' : '签单', 'url' => 'community/jiaoding_list'], ['name' => $empdata['xinjushang'] == 1 ? '签单' : '转单', 'ishref' => 1, 'url' => 'community/achment_list'], ['name' => '公共库', 'url' => 'community/pool_list'], ['name' => '搜索', 'url' => 'community/search_list'], ['name' => '日报', 'url' => 'community/daily'] ]; $leftnav = [ ['name' => '首页', 'ishref' => 1, 'url' => 'community/index', 'child' => []], ['name' => '客户数据', 'ishref' => 0, 'url' => '', 'child' => [ ['name' => '客户池', 'ishref' => 1, 'url' => 'community/list'], ['name' => '分派', 'url' => 'community/assignment_list'], ['name' => '见面', 'url' => 'community/confirm_visit_list'], ['name' => '待回访', 'ishref' => 1, 'url' => 'community/repay_list'], ['name' => $empdata['xinjushang'] == 1 ? '交定' : '签单', 'ishref' => 1, 'url' => 'community/jiaoding_list'], ['name' => $empdata['xinjushang'] == 1 ? '签单' : '转单', 'ishref' => 1, 'url' => 'community/achment_list'], //['name'=>'故事力','ishref'=>1,'url'=>''], ]], ['name' => '数据统计', 'ishref' => 0, 'url' => '', 'child' => [ ['name' => '日报', 'url' => 'community/daily'], ['name' => '员工报表', 'url' => 'community/employee_report'] ]] ]; } return ['menu' => $menu, 'leftnav' => $leftnav]; } /** * 多企业选择页面 */ public function company() { $request = request(); $rootId = $request->param('rootid'); $uid = $request->param('uid'); $phone = session('empcrm'); $login_type = session('empcrm_login_type'); if (is_object($phone)) return redirect(url('index/index')); if ($rootId && $uid) { $domain = request()->domain(); $field = 'phone|unionid'; if ($login_type == 'phone_login') $employee = Employee::where([[$field, '=', $phone], ['root_id', '=', $rootId], ['uid', '<>', 0], ['state', 'in', ['在职']]])->find(); if ($login_type == 'wx_login') $employee = Employee::where([['uid', '=', $uid], ['root_id', '=', $rootId], ['state', 'in', ['在职']]])->find(); if (!empty($employee)) { $company = Company::where('root_id', $employee['root_id'])->find(); if ($company['status'] == 1) { return json(['code' => 1, 'msg' => '账号被禁用,请联系管理员']); } elseif ($company['end_date'] . ' 23:59:59' < date('Y-m-d H:i:s', time())) { return json(['code' => 1, 'msg' => '账号已过期,请联系管理员']); } $orgType = Org::where('id', $employee['org_id'])->value('org_type'); $employee['org_type'] = $orgType; session('empcrm', $employee); event('SysOperate', [$employee, '登录']); cache('empcrm_' . $employee['phone'], Session::getId()); return redirect(url('index/index')); } } if ($login_type == 'phone_login') $companys = Employee::with(['company', 'companys'])->where([['phone|openid', '=', $phone], ['uid', '<>', 0], ['state', 'in', ['在职']]])->select()->toArray(); if ($login_type == 'wx_login') { $domain = request()->domain(); $field = 'unionid'; $companys = Employee::with(['company', 'companys'])->where('uid', 'in', explode(',', $phone))->where([['state', 'in', ['在职']], [$field, '<>', '']])->select()->toArray(); } foreach ($companys as $k => $v) { if ($v['account_status'] == 1) { $companys[$k]['off'] = 1; $companys[$k]['off_remark'] = '账号被禁用'; } elseif ($v['account_end_date'] . ' 23:59:59' < date('Y-m-d H:i:s', time())) { $companys[$k]['off'] = 1; $companys[$k]['off_remark'] = '账号已过期'; } else { $companys[$k]['off'] = 0; $companys[$k]['off_remark'] = '账号正常'; } } View::assign('companys', $companys); return View::fetch(); } /* * 首页数据中心 */ public function welcome() { $request = request(); $root_id = $request->empcrm->root_id; $empcrm = $request->empcrm; $today = date('Y-m-d H:i:s', time()); $firstday = $today; $lastday = date('Y-m-d 00:00:00', strtotime("$firstday -2 day")); if ($empcrm['empcrm_module'] == 2) { $org_employee = Employee::where([['root_id', '=', $root_id], ['org_id', '=', $request->empcrm->org_id], ['community_disable', '=', 0]])->column('id'); $where[] = ['customer_employee_id', 'in', $org_employee]; } $where[] = ['org_id', '=', $request->empcrm->org_id]; $where[] = ['addtime', 'between', [$lastday, $firstday]]; $where[] = ['state', 'in', array_merge(CustomerVisitLog::changeState('已交定', 'chaos'), CustomerVisitLog::changeState('已签单', 'chaos'))]; $list = CustomerVisitLog::with(['employee' => function ($query) { $query->field('id,name'); }])->where($where)->order('addtime desc')->select()->toArray(); $empmod = new Empcrm($this->app); foreach ($list as $key => $val) { $list[$key]['package_name'] = !empty($val['package_id']) ? CustomerPackage::where('id', $val['package_id'])->value('name') : ''; $cusdata = Customer::with(['designer'])->where('id', $val['customer_id'])->field('name,community_name,deposit_money,signed_money,addtime,designer_id')->find(); //如果客户不存在直接销毁跳过本次循环 if (empty($cusdata)) { unset($list[$key]); continue; } $cusdata['deposit_moneys'] = !empty($cusdata->getData('deposit_money')) ? number_format($cusdata->getData('deposit_money'), 2, '.', ',') : 0; $cusdata['signed_moneys'] = !empty($cusdata->getData('signed_money')) ? number_format($cusdata->getData('signed_money'), 2, '.', ',') : 0; $list[$key]['cusdata'] = $cusdata; } $company_name = Company::where('root_id', $root_id)->value('company_name'); View::assign('company_name', $company_name); View::assign('list', $list); return View::fetch(); return View::fetch(); } /** * 退出登陆 */ public function logout() { Session::delete('empcrm'); Session::delete('empcrm_login_type'); Session::delete('empcrm_module'); $domain = request()->domain(); $url = strpos($domain, "zqxg.cc") !== false ? url('manage/login/index') : url('login/index'); $url = Session('login_source') == 1 ? $domain : $url; Session::delete('login_source'); return redirect($url); } /** * 切换店面 */ public function switch_shop() { $request = request(); $rootId = $request->param('rootid'); $employee_id = $request->param('employee_id'); if ($rootId) { $employee = Employee::where([['id', '=', $employee_id], ['root_id', '=', $rootId], ['state', '=', '在职'], ['uid', '>', 0]])->find(); if (!empty($employee)) { $company = Company::where('root_id', $employee['root_id'])->find(); if ($company['status'] == 1) { return json(['code' => 1, 'msg' => '所在企业被禁用,请联系管理员']); } elseif ($company['end_date'] . ' 23:59:59' < date('Y-m-d H:i:s', time())) { return json(['code' => 1, 'msg' => '企业账号已过期,请联系管理员']); } $orgType = Org::where('id', $employee['org_id'])->value('org_type'); $employee['org_type'] = $orgType; Session::delete('empcrm_module'); session('empcrm', $employee); event('SysOperate', [$employee, '登录']); cache('empcrm_' . $employee['phone'], Session::getId()); return json(['code' => 0, 'msg' => '切换店面成功']); } } return json(['code' => 1, 'msg' => '切换失败']); } /** * 切换社群或PC端 */ public function switch_model() { $request = request(); $root_id = $request->empcrm->root_id; $type = $request->param('type'); $employee_id = $request->param('employee_id'); $empdata = Employee::where([['id', '=', $employee_id], ['root_id', '=', $root_id]])->find(); if ($type == 1 && $empdata['empcrm_disable'] == 0) { session('empcrm_module', 1); // 1、网销 2、社群 } if ($type == 2 && $empdata['community_disable'] == 0) { session('empcrm_module', 2); // 1、网销 2、社群 } return json(['code' => 0, 'msg' => '切换后台成功']); } }