0, 'type' => 'article', 'root_id' => request()->employee->root_id])->column('*', 'id'); $label = VideoType::where([['pid', '>', 0], ['type', '=', 'article'], ['root_id', '=', request()->employee->root_id]])->select()->toArray(); $joinlabel = []; foreach ($label as $val) { $joinlabel[$val['pid']][$val['id']] = $val['name']; } $eid = ArticleModel::where([['delete_time','=',0],['root_id','=',request()->employee->root_id],['employee_id','>',0]])->group('employee_id')->column('employee_id'); $w[] = ['id','in',$eid]; $w[] = ['grant_id', '>', 0]; $w[] = ['root_id', '=', request()->employee->root_id]; // 运营人员列表 $employee = Employee::where($w)->field(['id', 'opt_name as name'])->select()->toArray(); View::assign('employee', $employee); View::assign('type', $type); View::assign('label', json_encode($joinlabel)); return View::fetch(); } /** * 文章列表 */ public function list() { // 请求参数获取 $param = Request::param(); // 请求条件初始化 $where = [ ['delete_time', '=', 0], ['root_id', '=', request()->employee->root_id], ]; if (!empty($param['title'])) { $where[] = ['title', 'like', '%' . $param['title'] . '%']; } if (!empty($param['type'])) { $where[] = ['type', '=', $param['type']]; } if (!empty($param['employee_id'])) { $where[] = ['employee_id', '=', $param['employee_id']]; } //上传时间筛选 if (!empty($param['add_time'])) { $newtime=explode(' - ', $param['add_time']); $start_time=$newtime[0].' 00:00:00'; $end_time=$newtime[1].' 23:59:59'; $where[] = ['uploadtime', 'between', [$start_time, $end_time]]; } $order='id desc,hot desc,star_num desc,got_customers_num desc'; if (!empty($param['order']) && in_array($param['order'], ['visit_due_time desc','visit_due_time asc','view_times asc','view_times desc','shared_times asc','shared_times desc'])) { $order = $param['order']; } $data = $count = ArticleModel::field('id,cover_img,title,type,label,publish,uploadtime,employee_id,hot,visit_due_time,view_times,shared_times')->with(['employee'])->where($where); if (!empty($param['label'])) { $data = $count = $data->whereRaw("FIND_IN_SET(" . $param['label'] . " , label)"); } // 获取数据 $list = $data->page($param['page'], $param['limit'])->order($order)->select()->toArray(); $count = $count->count(); //增加查询转发次数浏览时长 // if(!empty($list)){ // $statismod=new MaterialLogic; // $selorder=!empty($param['order'])?$param['order']:''; // $list=$statismod->sel_case_share($list,'Article',$selorder); // } return json(['code' => 0, 'data' => $list, 'count' => $count, 'msg' => '获取成功']); } /** * 文章添加视图 */ public function add() { // 类型获取 $type = VideoType::where(['pid' => 0, 'type' => 'article', 'root_id' => request()->employee->root_id])->column('*', 'id'); $label = VideoType::where([['pid', '>', 0], ['type', '=', 'article'], ['root_id', '=', request()->employee->root_id]])->select()->toArray(); $joinlabel = []; foreach ($label as $val) { $joinlabel[$val['pid']][$val['id']] = $val['name']; } View::assign('type', $type); View::assign('label', json_encode($joinlabel)); $adding = input('adding',0); view::assign('adding',$adding); return View::fetch(); } /** * 文章修改视图 */ public function edit($id) { $data = ArticleModel::where([['id', '=', $id], ['root_id', '=', request()->employee->root_id]])->find(); if (empty($data)) throw new HttpException(404, '数据不存在'); $data = $data->getData(); $data['cover_img'] = empty($data['cover_img']) ?: 'https://' . config('app.ali_oss_bindurl') . '/' . $data['cover_img']; $data['cover_share_img'] = empty($data['cover_share_img']) ?'': 'https://' . config('app.ali_oss_bindurl') . '/' . $data['cover_share_img']; // 类型获取 $type = VideoType::where(['pid' => 0, 'type' => 'article', 'root_id' => request()->employee->root_id])->column('*', 'id'); $label = VideoType::where([['pid', '>', 0], ['type', '=', 'article'], ['root_id', '=', request()->employee->root_id]])->select()->toArray(); $joinlabel = []; foreach ($label as $val) { $joinlabel[$val['pid']][$val['id']] = $val['name']; } View::assign('data', $data); View::assign('type', $type); View::assign('checked', $joinlabel[$data['type']] ?? []); View::assign('label', json_encode($joinlabel)); return View::fetch(); } /** * 文章修改视图 */ public function preview_read() { $id = input('id',0); $data = ArticleModel::where([['id', '=', $id], ['root_id', '=', request()->employee->root_id]])->find(); $data = $data->getData(); $data['cover_img'] = empty($data['cover_img']) ?: 'https://' . config('app.ali_oss_bindurl') . '/' . $data['cover_img']; //公司信息 $where[] = ['root_id','=',request()->employee->root_id]; $data['company_info'] = Company::where($where)->field('company_name,logo,company_address')->find(); return json(['code' => 0, 'msg' => '获取成功', 'data' => $data]); } /** * 添加文章保存 */ public function save() { $data = Request::only(['id', 'cover_img', 'title', 'content', 'type', 'label'=>'', 'cover_share_img']); if (empty($data['id'])) { $data['root_id'] = request()->employee->root_id; $data['employee_id'] = request()->employee->id; ArticleModel::create($data); } else { // $data['employee_id'] = request()->employee->id; ArticleModel::where(['id' => $data['id'], 'root_id' => request()->employee->root_id])->save($data); } return json(['code' => 0, 'msg' => '操作成功']); } /** * 文章删除 */ public function del($id) { $rs = ArticleModel::update(['delete_time' => time()], ['id' => $id, 'root_id' => request()->employee->root_id]); if (!$rs) { return json(['code' => 1, 'msg' => '删除失败']); } return json(['code' => 0, 'msg' => '删除成功']); } /* * 添加分类 */ public function addtype($value, $id = null) { $array = ['name' => $value, 'type' => 'article']; if (isset($id)) { $array['pid'] = $id; } $array['root_id'] = request()->employee->root_id; $insertGetId = VideoType::insertGetId($array); $data = ['id' => $insertGetId, 'value' => $value]; return json(['code' => 0, 'msg' => '添加成功', 'data' => $data]); } /** * 是否展示 */ public function publish($id) { $obj = ArticleModel::where(['id' => $id, 'root_id' => request()->employee->root_id])->find(); if (empty($obj)) return json(['code' => 1, 'msg' => '文章不存在']); $obj->publish = $obj->publish == 1 ? 0 : 1; $obj->save(); return json(['code' => 0, 'msg' => '修改成功']); } public function fileupload() { $ali_oss_bindurl = config('app.ali_oss_bindurl'); $url = 'https://' . $ali_oss_bindurl . '/' . Request::param('file'); return json(['code' => 0, 'data' => ['src' => $url]]); } public function filedelete() { $param = request()->param(); foreach ($param as $path) { $path = str_replace('https://' . config('app.ali_oss_bindurl') . '/', '', $path); trace($path); filedelete($path); } return json(['code' => 0, 'msg' => '删除成功']); } /** * 网址内容抓取 */ public function catch($link) { $crawler = new Crawler(); $data = $crawler->crawByUrl($link); View::assign('data', $data); return json(['code' => 0, 'data' => $data]); } /* * 分类管理 */ function cate_article() { return View::fetch(); } /* * 分类管理列表 */ function cate_article_list() { $param = Request::param(); $condition[] = ['root_id', '=', request()->employee->root_id]; $condition[] = ['type', '=', 'article']; $condition[] = ['pid', '=', 0]; $list = VideoType::where($condition)->page($param['page'], $param['limit'])->order(['show'=>'asc','id'=>'desc'])->field('id,name,show')->select()->toarray(); $count = VideoType::where($condition)->count(); return json(['code' => 0, 'data' => $list, 'count' => $count]); } /* * 分类管理添加 */ function cate_article_add() { $param = Request::param(); $condition[] = ['name', '=', $param['name']]; $condition[] = ['root_id', '=', request()->employee->root_id]; $condition[] = ['type', '=', 'article']; $data['name'] = $param['name']; $model = VideoType::where($condition); $models = new VideoType; $info = $model->find(); if ($info) { return json(['code' => 1, 'msg' => '名称已存在']); } $models->name = $param['name']; $models->type = 'article'; $models->root_id = request()->employee->root_id; $models->save(); return json(['code' => 0, 'msg' => '保存成功', 'data' => '']); } /* * 分类管理编辑 */ function cate_article_edit() { $param = Request::param(); $conditions[] = ['id', '=', $param['id']]; $conditions[] = ['root_id', '=', request()->employee->root_id]; $condition[] = ['name', '=', $param['name']]; $condition[] = ['root_id', '=', request()->employee->root_id]; $condition[] = ['type', '=', 'article']; $data['name'] = $param['name']; $model = VideoType::where($condition); $models = VideoType::where($conditions); $info = $model->find(); if ($info) { return json(['code' => 1, 'msg' => '名称已存在']); } $models->update($data); return json(['code' => 0, 'msg' => '保存成功', 'data' => '']); } /* * 分类管理 */ function cate_article_label() { $id = input('id'); view::assign('id', $id); return View::fetch(); } /* * 分类管理列表 */ function cate_article_list_label() { $param = Request::param(); $condition[] = ['root_id', '=', request()->employee->root_id]; $condition[] = ['type', '=', 'article']; $condition[] = ['pid', '=', $param['id']]; $list = VideoType::where($condition)->page($param['page'], $param['limit'])->order('id desc')->field('id,name')->select()->toArray(); $count = VideoType::where($condition)->count(); return json(['code' => 0, 'data' => $list, 'count' => $count]); } /* * 分类管理添加 */ function cate_article_add_label() { $param = Request::param(); $condition[] = ['name', '=', $param['name']]; $condition[] = ['root_id', '=', request()->employee->root_id]; $condition[] = ['type', '=', 'article']; $condition[] = ['pid', '=', $param['pid']]; $condition[] = ['type', '=', 'article']; $data['name'] = $param['name']; $model = VideoType::where($condition); $models = new VideoType; $info = $model->find(); if ($info) { return json(['code' => 1, 'msg' => '名称已存在']); } $models->name = $param['name']; $models->type = 'article'; $models->pid = $param['pid']; $models->root_id = request()->employee->root_id; $models->save(); return json(['code' => 0, 'msg' => '保存成功', 'data' => '']); } /* * 分类管理编辑 */ function cate_article_edit_label() { $param = Request::param(); $conditions[] = ['id', '=', $param['id']]; $conditions[] = ['root_id', '=', request()->employee->root_id]; $condition[] = ['name', '=', $param['name']]; $condition[] = ['root_id', '=', request()->employee->root_id]; $condition[] = ['pid', '=', $param['pid']]; $condition[] = ['type', '=', 'article']; $data['name'] = $param['name']; $model = VideoType::where($condition); $models = VideoType::where($conditions); $info = $model->find(); if ($info) { return json(['code' => 1, 'msg' => '名称已存在']); } $models->update($data); return json(['code' => 0, 'msg' => '保存成功', 'data' => '']); } /* * 标签管理 */ function cate_article_labels() { return View::fetch(); } /* * 新标签管理列表 */ function cate_article_list_labels() { $param = Request::param(); $condition[] = ['root_id', '=', request()->employee->root_id]; $condition[] = ['type', '=', 'article']; $condition[] = ['pid', '>', 0]; $parents = VideoType::where([['pid', '=', 0]])->column('name', 'id'); $list = VideoType::where($condition)->page($param['page'], $param['limit'])->order(['show'=>'asc','id'=>'desc'])->field('id,name,pid,show')->select()->toarray(); foreach ($list as $k => $v) { $list[$k]['pname'] = isset($parents[$v['pid']]) ? $parents[$v['pid']] : ''; } $count = VideoType::where($condition)->count(); return json(['code' => 0, 'data' => $list, 'count' => $count]); } /* * 新分类标签管理编辑 */ function cate_article_edit_labels() { $param = Request::param(); $conditions[] = ['id', '=', $param['id']]; $conditions[] = ['root_id', '=', request()->employee->root_id]; $condition[] = ['name', '=', $param['name']]; $condition[] = ['root_id', '=', request()->employee->root_id]; $condition[] = ['pid', '=', $param['pid']]; $condition[] = ['type', '=', 'article']; $data['name'] = $param['name']; $model = VideoType::where($condition); $models = VideoType::where($conditions); $info = $model->find(); if ($info) { return json(['code' => 1, 'msg' => '名称已存在']); } $models->update($data); return json(['code' => 0, 'msg' => '保存成功', 'data' => '']); } /* * 新标签添加 */ function cate_article_labels_add() { if (request()->isAjax()) { $param = Request::param(); if (!$param['id'] || !$param['name']) { return json(['code' => 1, 'msg' => '缺少参数', 'data']); } isset($param['label_id']) ? $condition[] = ['id', '<>', $param['label_id']] : ''; $condition[] = ['name', '=', $param['name']]; $condition[] = ['root_id', '=', request()->employee->root_id]; $condition[] = ['pid', '=', $param['id']]; $condition[] = ['type', '=', 'article']; $info = VideoType::where($condition)->find(); if ($info) { return json(['code' => 1, 'msg' => '名称已存在']); } if(isset($param['label_id'])) { VideoType::where(['root_id'=>request()->employee->root_id,'type'=>'article','id'=>$param['label_id']])->update(['pid'=>$param['id'],'name'=>$param['name']]); ArticleModel::where(['root_id'=>request()->employee->root_id])->whereRaw("FIND_IN_SET(" . $param['label_id'] . " , label)")->update(['type'=>$param['id']]); //print_r(ArticleModel::where(['root_id'=>request()->employee->root_id])->whereRaw("FIND_IN_SET(" . $param['label_id'] . " , label)")->select()->toArray());exit; }else{ $model = new VideoType; $model->name = $param['name']; $model->pid = $param['id']; $model->type = 'article'; $model->root_id = request()->employee->root_id; $model->save(); } return json(['code' => 0, 'msg' => '保存成功', 'data' => '']); } //编辑 if(Request::param('id')){ $data = Request::param(); view::assign('data', $data); } $condition[] = ['root_id', '=', request()->employee->root_id]; $condition[] = ['type', '=', 'article']; $condition[] = ['pid', '=', 0]; $list = VideoType::where($condition)->order('id desc')->field('id,name')->select()->toArray(); view::assign('list', $list); return view::fetch(); } /* * 文章标签分类列表 */ public function label_list() { $id = request()->param('id'); $zid = request()->param('zid'); //文章id $lid = request()->param('lid'); //需要选中的标签id $data = []; if ($id) { $types = VideoType::where([['pid', '=', $id]])->select()->toArray(); $zids = []; if ($zid) { $zids = ArticleModel::where([['id', '=', $zid]])->value('label'); $zids = $zids ? explode(',', $zids) : []; } foreach ($types as $k => $v) { $data[] = [ 'name' => $v['name'], 'value' => $v['id'], 'selected' => (in_array($v['id'], $zids) || $v['id']==$lid) ? true : false ]; } } return json($data); } /* * 删除标签或分类前,查询关联的内容数量 */ public function with_type_count() { $param = Request::param(); if($param['type'] == 'type') { $field = 'type'; }else{ $field = 'label'; } $where = [ ['root_id','=',request()->employee->root_id], ['delete_time','=',0], [$field,'=',$param['id']] ]; $count = ArticleModel::where($where)->count(); if($count > 0) { $type = $field == 'type' ? '分类' : '标签' ; $msg = '该'.$type.'有'.$count.'个'.'拓客图文,删除后该内容将归为其它分类。'; }else{ $msg = '确定删除该分类吗?'; } return $msg; } /* * 分类、标签删除 */ public function delete_type_or_label() { $param = Request::param(); $articleType = VideoType::where(['root_id'=>request()->employee->root_id,'type'=>'article','id'=>$param['id']])->find(); if(empty($articleType)) return json(['code' => 1, 'msg' => '数据不存在']); Db::startTrans(); try { if($param['type'] == 'type') { //查询是否存在其它分类 $type_id = VideoType::where(['root_id'=>request()->employee->root_id,'pid'=>0,'type'=>'article','show'=>1])->value('id'); if(empty($type_id)) $type_id = VideoType::insertGetId(['pid'=>0,'name'=>'其它','type'=>'article','root_id'=>request()->employee->root_id,'show'=>1]); //更新关联内容 VideoType::where(['root_id'=>request()->employee->root_id,'pid'=>$param['id'],'type'=>'article'])->update(['pid'=>$type_id]); ArticleModel::where(['root_id'=>request()->employee->root_id,'type'=>$param['id']])->update(['type'=>$type_id]); $more_other_id = VideoType::where(['root_id'=>request()->employee->root_id,'pid'=>$type_id,'type'=>'article','show'=>1])->column('id'); if(count($more_other_id) >= 2) { $first_id = $more_other_id[0]; ArticleModel::where([['root_id','=',request()->employee->root_id],['type','=',$type_id],['label','in',$more_other_id]])->update(['label'=>$first_id]); unset($more_other_id[0]); VideoType::where([['root_id','=',request()->employee->root_id],['id','in',$more_other_id]])->delete(); } //删除分类 $articleType->delete(); }else{ $label_id = VideoType::where(['root_id'=>request()->employee->root_id,'pid'=>$param['pid'],'type'=>'article','show'=>1])->value('id'); if(empty($label_id)) $label_id = VideoType::insertGetId(['pid'=>$param['pid'],'name'=>'其它','type'=>'article','root_id'=>request()->employee->root_id,'show'=>1]); //更新关联内容 ArticleModel::where(['root_id'=>request()->employee->root_id,'label'=>$param['id']])->update(['label'=>$label_id]); //删除分类 $articleType->delete(); } Db::commit(); return json(['code' => 0, 'msg' => '删除成功']); } catch (\Exception $e) { Db::rollback(); return json(['code' => 1, 'msg' => '删除失败']); } } //数据统计 public function statistics_data_list() { $request = request(); $param=$request->only(['page'=>1,'limit'=>10,'org_id','time']); if (!request()->isAjax()) { $list=orgSubIds(request()->employee->root_id); $xins=[]; foreach($list as $key=>$val){ if(Org::where([['pid','=',$val],['status','=',1]])->value('id')){ $xins[]=$val; } } $orglist=Org::where([['id','in',$xins]])->field('id,name,pid')->select()->toArray(); view::assign('orglist', $orglist); return view::fetch(); } if(!empty($param['org_id'])){ $list=orgSubIds($param['org_id']); }else{ $list=orgSubIds(request()->employee->root_id); } $xin=[]; foreach($list as $key=>$val){ if(!Org::where([['pid','=',$val],['status','=',1]])->value('id')){ $xin[]=$val; } } $newlist = Org::with(['employee' => function ($sql) { $sql->where([['state', '=', '在职'], ['uid', '<>', 0]])->field('id,org_id'); }])->where([['id', 'in', $xin]])->field('id,name,pid')->page($param['page'], $param['limit'])->select()->toArray(); $clue_type = 'article'; $share_type = 'Article'; $orgid = array_column($newlist, 'id'); $empid = Employee::where([['org_id', 'in', $orgid], ['state', '=', '在职'], ['uid', '<>', 0]])->column('id'); //转发人数 if (!empty($param['time'])) { $newtime = explode(' - ', $param['time']); $start_time = $newtime[0] . ' 00:00:00'; $end_time = $newtime[1] . ' 23:59:59'; $where[] = ['share_time', 'between', [$start_time, $end_time]]; $clue_where[] = ['addtime', 'between', [$start_time, $end_time]]; $foot_where[] = ['addtime', 'between', [$start_time, $end_time]]; } $where[] = ['type', '=', $share_type]; $where[] = ['employee_id', 'in', $empid]; $clue_where[] = ['employee_id', 'in', $empid]; $clue_where[] = ['pipe_type', '=', $clue_type]; $foot_where[] = ['employee_id', 'in', $empid]; $foot_where[] = ['pipe_type', '=', $clue_type]; $shared_employee = ShareLog::where($where)->column('employee_id'); $clue_count = CustomerClue::where($clue_where)->column('employee_id'); $foot_data = Footprints::where($foot_where)->field('id,employee_id,uid,visit_due_time')->select()->toArray(); $new = []; foreach ($foot_data as $key => $val) { $new[$val['employee_id']][] = $val; } foreach ($newlist as $key => $val) { $empids = array_column($val['employee'], 'id'); $newlist[$key]['share_count'] = count(array_intersect($shared_employee, $empids)); $yes_share_count = count(array_unique(array_intersect($shared_employee, $empids))); $newlist[$key]['share_employee_count'] = $yes_share_count; $newlist[$key]['clue_count'] = count(array_intersect($clue_count, $empids)); $cont = $visit_due_time = $uid = 0; foreach ($new as $k => $v) { if (in_array($k, $empids)) { $cont += count($v); $visit_due_time += array_sum(array_column($v, 'visit_due_time')); $uid += count(array_unique(array_column($v, 'uid'))); } } $newlist[$key]['footprints_count'] = $cont; $newlist[$key]['visit_long'] = $visit_due_time; $newlist[$key]['footprints_user_count'] = $uid; $un_share_employee = count($empids) - $yes_share_count; $newlist[$key]['un_share_employee_count'] = $un_share_employee; } $count = Org::where([['id', 'in', $xin]])->count(); $all = $this->top_statistics_data($xin, !empty($param['time']) ? $param['time'] : 0); $data = ['list' => $newlist, 'all' => $all]; return json(['code' => 0, 'msg' => '获取成功', 'data' => $data, 'count' => $count]); } public function top_statistics_data($xin,$time=0) { $article_cont=ArticleModel::where([['delete_time', '=', 0],['root_id', '=', request()->employee->root_id]])->count(); $all=['article_cont'=>$article_cont,'share_employee_count'=>0,'share_count'=>0,'clue_count'=>0,'footprints_count'=>0,'visit_long'=>0,'footprints_user_count'=>0,'un_share_employee_count'=>0]; $sub_employee_ids = Employee::where([['org_id', 'in', $xin], ['state', '=', '在职'], ['uid', '<>', 0]])->column('id'); $clue_type = 'article'; $share_type = 'Article'; //转发人数 if(!empty($time)){ $newtime=explode(' - ', $time); $start_time=$newtime[0].' 00:00:00'; $end_time=$newtime[1].' 23:59:59'; $where[] = ['share_time', 'between', [$start_time, $end_time]]; $clue_where[] = ['addtime', 'between', [$start_time, $end_time]]; $foot_where[] = ['addtime', 'between', [$start_time, $end_time]]; } $where[] = ['type', '=', $share_type]; $where[] = ['employee_id', 'in', $sub_employee_ids]; $shared_employee = ShareLog::where($where)->column('employee_id'); // 转发次数 $all['share_count'] = count($shared_employee); $all['share_employee_count']=count(array_values(array_unique($shared_employee))); // 获得线索 $clue_where[] = ['employee_id', 'in', $sub_employee_ids]; $clue_where[] = ['pipe_type', '=', $clue_type]; $clue_count = CustomerClue::where($clue_where)->count(); $all['clue_count']=$clue_count; // 浏览次数 $foot_where[] = ['employee_id', 'in', $sub_employee_ids]; $foot_where[] = ['pipe_type', '=', $clue_type]; $foot_user_count = Footprints::where($foot_where)->field('id,uid,visit_due_time')->select()->toArray(); $all['footprints_user_count']=count(array_unique(array_column($foot_user_count,'uid'))); // 浏览时长 $all['visit_long'] = array_sum(array_column($foot_user_count,'visit_due_time')); return $all; } //统计员工列表 public function statistics_emplist() { $request = request(); $param=$request->only(['page'=>1,'limit'=>10,'keyword','org_id','time']); if (!request()->isAjax()) { view::assign('org_id', $param['org_id']); return view::fetch(); } $e_where[]=['org_id', '=', $param['org_id']]; $e_where[]=['state', '=', '在职']; $e_where[]=['uid', '<>', 0]; if(!empty($param['keyword'])){ $e_where[]=['name','like','%'.$param['keyword'].'%']; } $employee_list = Employee::where($e_where)->field('id,name')->page($param['page'],$param['limit'])->select()->toArray(); $clue_type = 'article'; $share_type = 'Article'; $empid=array_column($employee_list,'id'); if(!empty($param['time'])){ $newtime=explode(' - ', $param['time']); $start_time=$newtime[0].' 00:00:00'; $end_time=$newtime[1].' 23:59:59'; $where[] = ['share_time', 'between', [$start_time, $end_time]]; $clue_where[] = ['addtime', 'between', [$start_time, $end_time]]; $foot_where[] = ['addtime', 'between', [$start_time, $end_time]]; } $where[]=['type', '=', $share_type]; $where[]=['employee_id', 'in', $empid]; $clue_where[]=['employee_id', 'in', $empid]; $clue_where[]=['pipe_type', '=', $clue_type]; $foot_where[] = ['employee_id', 'in', $empid]; $foot_where[] = ['pipe_type', '=', $clue_type]; $shared_employee = ShareLog::where($where)->column('employee_id'); $clue_count = CustomerClue::where($clue_where)->column('employee_id'); $foot_data = Footprints::where($foot_where)->field('id,employee_id,uid,visit_due_time')->select()->toArray(); $new=[]; foreach($foot_data as $key=>$val){ $new[$val['employee_id']][]=$val; } foreach($employee_list as $key=>$val){ $empids=[$val['id']]; $employee_list[$key]['share_count']=count(array_intersect($shared_employee,$empids)); $yes_share_count=count(array_unique(array_intersect($shared_employee,$empids))); $employee_list[$key]['share_employee_count']=$yes_share_count; $employee_list[$key]['clue_count']=count(array_intersect($clue_count,$empids)); $cont=$visit_due_time=$uid=0; foreach($new as $k=>$v){ if(in_array($k,$empids)){ $cont+=count($v); $visit_due_time+=array_sum(array_column($v,'visit_due_time')); $uid+=count(array_unique(array_column($v,'uid'))); } } $employee_list[$key]['footprints_count']=$cont; $employee_list[$key]['visit_long']=$visit_due_time; $employee_list[$key]['footprints_user_count']=$uid; $un_share_employee = count($empids) - $yes_share_count; $employee_list[$key]['un_share_employee_count'] = $un_share_employee; } $count=Employee::where($e_where)->count(); return json(['code' => 0, 'msg' => '获取成功', 'data' => $employee_list,'count'=>$count]); } //统计员工转发记录详情列表 public function emp_logdetail_list() { $request = request(); $param=$request->only(['page'=>1,'limit'=>10,'keyword','emp_id','time']); if (!request()->isAjax()) { view::assign('emp_id', $param['emp_id']); return view::fetch(); } $empid=$param['emp_id']; $share_list=$this->sel_emp_videolist($empid); if(!empty($param['keyword'])){ $key_list=ArticleModel::where([['root_id','=',request()->employee->root_id],['title','like','%'.$param['keyword'].'%']])->column('id'); if(!empty($key_list)&&!empty($share_list)){ $tm= array_intersect($key_list,$share_list); if(!empty($tm)){ $share_list=$tm; }else{ return json(['code' => 0, 'msg' => '获取成功', 'data' => [],'count'=>0]); } }else{ return json(['code' => 0, 'msg' => '获取成功', 'data' => [],'count'=>0]); } } $list=ArticleModel::where([['root_id','=',request()->employee->root_id],['id','in',$share_list]])->field('id,title')->page($param['page'],$param['limit'])->select()->toArray(); $clue_type = 'article'; $share_type = 'Article'; foreach($list as $key=>$val){ //转发人数 if(!empty($param['time'])){ $newtime=explode(' - ', $param['time']); $start_time=$newtime[0].' 00:00:00'; $end_time=$newtime[1].' 23:59:59'; $where[] = ['share_time', 'between', [$start_time, $end_time]]; $clue_where[] = ['addtime', 'between', [$start_time, $end_time]]; $foot_where[] = ['addtime', 'between', [$start_time, $end_time]]; } $where[] = ['type', '=', $share_type]; $where[] = ['employee_id', '=', $empid]; $where[] = ['data_id','=',$val['id']]; $list[$key]['share_count'] = ShareLog::where($where)->count(); // 获得线索 $clue_where[] = ['employee_id', '=', $empid]; $clue_where[] = ['pipe_type', '=', $clue_type]; $clue_where[] = ['pipe_id','=',$val['id']]; $clue_count = CustomerClue::where($clue_where)->count(); $list[$key]['clue_count'] = $clue_count; // 浏览次数 $foot_where[] = ['employee_id', '=', $empid]; $foot_where[] = ['pipe_type', '=', $clue_type]; $foot_where[] = ['reg_info', 'like', '{"id":' . $val['id'] . ',%']; $foot_user_count = Footprints::where($foot_where)->field('id,uid')->group('uid')->select(); $list[$key]['footprints_user_count'] = count($foot_user_count); // 浏览时长 $visit_long = Footprints::where($foot_where)->sum('visit_due_time'); $list[$key]['visit_long'] = $visit_long; $where = []; $clue_where = []; $foot_where = []; } $count=ArticleModel::where([['root_id','=',request()->employee->root_id],['id','in',$share_list]])->count(); //$list = array_slice($list, ($param['page'] - 1) * $param['limit'],$param['limit']); return json(['code' => 0, 'msg' => '获取成功', 'data' => $list,'count'=>$count]); } //计算所有关联员工的id public function sel_emp_videolist($empid) { $clue_type = 'article'; $share_type = 'Article'; $where[] = ['type', '=', $share_type]; $where[] = ['employee_id', '=', $empid]; $shared_id = ShareLog::where($where)->group('data_id')->column('data_id'); $clue_where[] = ['employee_id', '=', $empid]; $clue_where[] = ['pipe_type', '=', $clue_type]; $clue_id = CustomerClue::where($clue_where)->group('pipe_id')->column('pipe_id'); $foot_where[] = ['employee_id', '=', $empid]; $foot_where[] = ['pipe_type', '=', $clue_type]; $foot_list = Footprints::where($foot_where)->field('id,pipe_type,reg_info')->select(); $foot_id=[]; foreach($foot_list as $key=>$val){ $m=$val->getData('reg_info'); if(!empty($m)){ $info=json_decode($m,true); $foot_id[]=$info['id']; } } $vdid=array_values(array_unique(array_merge($shared_id,$clue_id,$foot_id))); return $vdid; } }