employee->root_id; $w[] = ['root_id','=',$root_id]; $cate = CompanyStrengthCate::where($w)->where('pid','=',0)->order('id asc')->select(); View::assign('cate',$cate); $eid = CompanyStrengthModel::where([['del','=',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); return View::fetch(); } /** * 公司实力列表 */ public function list() { $root_id = request()->employee->root_id; $param = Request::only(['page'=>1,'limit'=>10,'cate'=>'','title'=>'','employee_id'=>'','add_time','order']); $w[] = ['root_id','=',$root_id]; $w[] = ['del','=',0]; if ($param['cate']) { $w[] = ['cate','=',$param['cate']]; } if ($param['title']) { $w[] = ['title','like','%'.$param['title'].'%']; } if (!empty($param['employee_id'])) { $w[] = ['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'; $w[] = ['addtime', 'between', [$start_time, $end_time]]; } $order='id 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']; } $list = CompanyStrengthModel::with(['employee'=>function($query){ $query->visible(['id','name','opt_name']); }])->where($w)->order($order)->page($param['page'],$param['limit'])->select()->toArray(); $count = CompanyStrengthModel::where($w)->count(); //增加浏览时长转发次数 // if(!empty($list)){ // $statismod=new MaterialLogic; // $selorder=!empty($param['order'])?$param['order']:''; // $list=$statismod->sel_case_share($list,'CompanyStrength',$selorder); // } return json(['code' => 0, 'data' => $list, 'count' => $count, 'msg' => '获取成功']); } /** * 上下架 */ public function apipublish() { $param = Request::Only(['id'=>0]); $condition = ['id' => $param['id'], 'root_id' => request()->employee->root_id]; $obj = CompanyStrengthModel::where($condition)->findOrEmpty(); if ($obj->isEmpty()) return json(['code' => 1, 'msg' => '数据不存在']); $obj->publish = $obj->publish == 1 ? 0 : 1; $obj->save(); $msg = $obj->publish ? '上架成功' : '下架成功'; return json(['code' => 0, 'msg' => $msg]); } /** * 添加页面 */ public function add() { $root_id = request()->employee->root_id; $cate = CompanyStrengthCate::where(['pid' => 0, 'root_id' => $root_id])->column('*', 'id'); $label = CompanyStrengthCate::where([['pid', '>', 0], ['root_id', '=', $root_id]])->select()->toArray(); $joinlabel = []; foreach ($label as $val) { $joinlabel[$val['pid']][$val['id']] = $val['name']; } View::assign('cate',$cate); View::assign('label', json_encode($joinlabel)); $adding = input('adding', 0); view::assign('adding', $adding); return View::fetch(); } /* * 客户见证添加 */ public function adding() { $data = Request::only(['title', 'desc','label', 'cate', 'pics','difference','cover'=>'','video_type', 'cover_share_img']); //视频 if ($data['difference']==1) { $data['pics'] = input('video_url',''); //图片 }else{ $data['cover'] = $data['pics'] = input('covers',''); } $cateType = CompanyStrengthCate::where(['root_id'=>request()->employee->root_id,'id'=>$data['cate']])->find(); if(empty($cateType)) return json(['code' => 1, 'msg' => '分类数据不存在']); $data['cate'] = $cateType['name']; $data['root_id'] = request()->employee->root_id; $data['employee_id'] = request()->employee->id; $data['desc'] = isset($data['desc']) && $data['desc'] ? str_replace("\r\n", '', $data['desc']) : ''; if (CompanyStrengthModel::create($data)) { return json(['code' => 0, 'msg' => '保存成功']); } else { return json(['code' => 1, 'msg' => '保存失败']); } } /** * 删除 */ public function del() { $param = Request::Only(['id'=>0]); $condition = ['id' => $param['id'], 'root_id' => request()->employee->root_id]; $obj = CompanyStrengthModel::where($condition)->findOrEmpty(); if ($obj->isEmpty()) return json(['code' => 1, 'msg' => '数据不存在']); $obj->del = 1; $obj->save(); return json(['code' => 0, 'msg' => '删除成功']); } /* * 富文本图片 */ public function imgUpload() { $bindUrl = config('app.ali_oss_bindurl'); $data = [ 'src' => 'https://' . $bindUrl . '/' . Request::param('file'), 'title' => '' ]; return json(['code' => 0, 'msg' => '', 'data' => $data]); } /* * 公司实力编辑 */ public function edit() { $id = input('id'); $root_id = request()->employee->root_id; $evidence = CompanyStrengthModel::where(['id' => $id, 'root_id' => request()->employee->root_id])->find()->toArray(); $cateType = CompanyStrengthCate::where(['root_id'=>request()->employee->root_id,'name'=>$evidence['cate']])->find(); $evidence['cate'] = $cateType['id']; View::assign('evidence', $evidence); $ali_oss_bindurl = config('app.ali_oss_bindurl'); View::assign('ali_oss_bindurl', $ali_oss_bindurl); //公司实力分类获取 // $cates = CompanyStrengthCate::where([['root_id', '=', request()->employee->root_id],['pid','=',0]])->order('id asc')->select()->toArray(); // View::assign('cates', $cates); $cate = CompanyStrengthCate::where(['pid' => 0, 'root_id' => $root_id])->column('*', 'id'); $label = CompanyStrengthCate::where([['pid', '>', 0], ['root_id', '=', $root_id]])->select()->toArray(); $joinlabel = []; foreach ($label as $val) { $joinlabel[$val['pid']][$val['id']] = $val['name']; } View::assign('cates',$cate); View::assign('checked', $joinlabel[$evidence['cate']] ?? []); View::assign('label', json_encode($joinlabel)); return View::fetch(); } /* * 编辑保存 */ public function editing() { $data = Request::only(['id','title','cate','label','evidence_image_exist','evidence_image','desc'=>'','difference','cover','video_type','cover_share_img']); $data['cover'] = !isset($data['cover']) ? input('covers','') : $data['cover']; //视频 if ($data['difference']==1) { $url = input('video_url',''); $arr = explode(',',$url); $data['pics'] = end($arr); $data['cover'] = input('ycover','') ?: input('cover',''); }else{ $data['cover'] = $data['pics'] = input('ycovers','') ?: input('covers',''); } $cateType = CompanyStrengthCate::where(['root_id'=>request()->employee->root_id,'id'=>$data['cate']])->find(); if(empty($cateType)) return json(['code' => 1, 'msg' => '分类数据不存在']); $data['cate'] = $cateType['name']; unset($data['evidence_image_exist']); unset($data['evidence_image']); $data['desc'] = isset($data['desc']) && $data['desc'] ? str_replace("\r\n", '', $data['desc']) : ''; $evidence = CompanyStrengthModel::where(['id' => $data['id'], 'root_id' => request()->employee->root_id])->find(); $evidence->save($data); return json(['code' => 0, 'msg' => '保存成功']); } /* * 公司实力分类管理 */ function cate() { return View::fetch(); } /* * 公司实力分类列表 */ function cate_list() { $param = Request::only(['page'=>1,'limit'=>10]); $root_id = request()->employee->root_id; $where[] = ['root_id','=',$root_id]; $where[] = ['pid','=',0]; $list = CompanyStrengthCate::where($where)->page($param['page'],$param['limit'])->order(['show'=>'asc','id'=>'desc'])->select(); $count = CompanyStrengthCate::where($where)->count(); return json(['code' => 0, 'data' =>$list,'count'=>$count]); } /* * 添加分类 */ function cate_add() { $param = Request::only(['name'=>'']); $condition[] = ['name', '=', $param['name']]; $condition[] = ['root_id', '=', request()->employee->root_id]; $condition[] = ['pid', '=', 0]; $info = CompanyStrengthCate::where($condition)->findOrEmpty(); if (!$info->isEmpty()) { return json(['code' => 1, 'msg' => '名称已存在']); } $save = [ 'root_id' => request()->employee->root_id, 'name' => trim($param['name']), 'pid' => 0 ]; CompanyStrengthCate::insertGetId($save); return json(['code' => 0, 'msg' => '保存成功', 'data' => '保存成功']); } /* * 编辑分类 */ function cate_edit() { $param = Request::only(['name'=>'','id'=>0]); $condition[] = ['id', '=', $param['id']]; $condition[] = ['root_id', '=', request()->employee->root_id]; $condition[] = ['pid', '=', 0]; $info = CompanyStrengthCate::where($condition)->findOrEmpty(); if ($info->isEmpty()) { return json(['code' => 1, 'msg' => '数据不存在']); } $w[] = [ ['id','<>',$param['id']], ['name','=',$param['name']], ['root_id', '=', request()->employee->root_id], ['pid','=', 0], ]; $find = CompanyStrengthCate::where($w)->findOrEmpty(); if (!$find->isEmpty()) { return json(['code' => 1, 'msg' => '分类已存在']); } CompanyStrengthCate::where($condition)->update(['name'=>$param['name']]); return json(['code' => 0, 'msg' => '保存成功', 'data' => '保存成功']); } /* * 分类删除前关联的内容数量 */ public function with_cate_count() { $cate = Request::param('cate'); $where = [ ['root_id','=',request()->employee->root_id], ['del','=',0], ['cate','=',$cate] ]; $count = CompanyStrengthModel::where($where)->count(); return $count > 0 ? '该分类有'.$count.'个公司实力,删除后该内容将归为其它分类。' : '确定删除该分类吗?'; } /* * 分类删除 */ public function delete_cate() { $cate = Request::param('cate'); $cateType = CompanyStrengthCate::where(['root_id'=>request()->employee->root_id,'name'=>$cate])->find(); if(empty($cateType)) return json(['code' => 1, 'msg' => '数据不存在']); $other_id = CompanyStrengthCate::where(['root_id'=>request()->employee->root_id , 'show'=>1])->find(); if(empty($other_id)) CompanyStrengthCate::insert(['name'=>'其它','root_id'=>request()->employee->root_id,'show'=>1]); CompanyStrengthCate::where(['root_id'=>request()->employee->root_id , 'name'=>$cate,'pid' => 0])->delete(); CompanyStrengthCate::where(['root_id'=>request()->employee->root_id , 'pid' => $cateType['id']])->delete(); $where = [ ['root_id','=',request()->employee->root_id], ['del','=',0], ['cate','=',$cate] ]; CompanyStrengthModel::where($where)->update(['cate'=>'其它','label'=>0]); return json(['code' => 0, 'msg' => '删除成功']); } /* * 标签管理 */ function cate_labels() { return View::fetch(); } /* * 新标签管理列表 */ function cate_list_labels() { $param = Request::param(); $condition[] = ['root_id', '=', request()->employee->root_id]; $condition[] = ['pid', '>', 0]; $parents = CompanyStrengthCate::where([['pid', '=', 0]])->column('name', 'id'); $list = CompanyStrengthCate::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 = CompanyStrengthCate::where($condition)->count(); return json(['code' => 0, 'data' => $list, 'count' => $count]); } /* * 新标签添加和编辑 */ function cate_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']]; $info = CompanyStrengthCate::where($condition)->find(); if ($info) { return json(['code' => 1, 'msg' => '名称已存在']); } if(isset($param['label_id'])){ CompanyStrengthCate::where(['root_id'=>request()->employee->root_id,'id'=>$param['label_id']])->update(['pid'=>$param['id'],'name'=>$param['name']]); }else{ $model = new CompanyStrengthCate; $model->name = $param['name']; $model->pid = $param['id']; $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[] = ['pid', '=', 0]; $list = CompanyStrengthCate::where($condition)->order('id desc')->field('id,name')->select()->toArray(); view::assign('list', $list); return view::fetch(); } /* * 删除标签更新文章label */ public function with_type_count() { return '确认删除吗?删除后公司实力标签将重置。'; } /* * 标签删除 */ public function delete_type_or_label() { $param = Request::param(); $cateType = CompanyStrengthCate::where(['root_id'=>request()->employee->root_id,'id'=>$param['id']])->find(); if(empty($cateType)) return json(['code' => 1, 'msg' => '数据不存在']); Db::startTrans(); try { //更新关联内容 CompanyStrengthModel::where(['root_id'=>request()->employee->root_id,'label'=>$param['id']])->update(['label'=>0]); //删除分类 $cateType->delete(); Db::commit(); return json(['code' => 0, 'msg' => '删除成功']); } catch (\Exception $e) { Db::rollback(); return json(['code' => 1, 'msg' => '删除失败']); } } /* * 添加标签 */ public function addtype($value, $id = null) { $array = ['name' => $value]; if (isset($id)) { $cateType = CompanyStrengthCate::where(['root_id'=>request()->employee->root_id,'name'=>$id])->find(); if(empty($cateType)) return json(['code' => 1, 'msg' => '数据不存在']); $array['pid'] = $cateType['id']; } $array['root_id'] = request()->employee->root_id; $insertGetId = CompanyStrengthCate::insertGetId($array); $data = ['id' => $insertGetId, 'value' => $value]; return json(['code' => 0, 'msg' => '添加成功', 'data' => $data]); } /* * 预览api */ public function preview_read() { $id = input('id',0); $data = CompanyStrengthModel::where(['id' => $id, 'root_id' => request()->employee->root_id])->find()->toArray(); //公司信息 $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 data_statistics($type = 0, $org_id = 0, $date = '') { $root_id = request()->employee->root_id; if ($type) { if ($org_id) { $path = Org::where('id', $org_id)->value('path'); $org_where[] = ['path', 'like', $path . '%']; $org_ids = Org::where($org_where)->column('id'); $eids = Employee::where([['org_id', 'in', $org_ids], ['uid', '>', 0], ['state', '=', '在职']])->column('id'); } else { $pid = Org::where([['path', 'like', $root_id . '-%']])->column('pid'); $org_ids = Org::where([['path', 'like', $root_id . '-%'],['id','not in',$pid]])->column('id'); $em_where[] = ['root_id', '=', $root_id]; $em_where[] = ['uid', '>', 0]; $em_where[] = ['state', 'in', ['在职', '离职']]; $em_where[] = ['org_id','in',$org_ids]; $eids = Employee::where($em_where)->column('id'); } if ($date) $date = explode(' - ', $date); //案例总数 $case_where[] = ['root_id', '=', $root_id]; $case_where[] = ['del', '=', 0]; if (isset($eids)) $case_where[] = ['employee_id', 'in', $eids]; if ($date) $case_where[] = ['addtime', 'between', [trim($date[0]) . ' 00:00:00', trim($date[1]) . ' 23:59:59']]; $case = CompanyStrengthModel::where($case_where)->column('view_times'); $data['case_count'] = count($case); //浏览次数 // $data['views'] = array_sum(array_filter($case)); //浏览人数 //浏览时长 $foot_where = [['pipe_type', '=', 'CompanyStrength'], ['employee_id', 'in', $eids]]; if ($date) $foot_where[] = ['addtime', 'between', [trim($date[0]) . ' 00:00:00', trim($date[1]) . ' 23:59:59']]; $footprint = Footprints::where($foot_where)->column('visit_due_time,uid'); $data['times'] = array_sum(array_column($footprint,'visit_due_time')); $data['views'] = count(array_unique(array_column($footprint,'uid'))); //转发次数 $share_where = [['employee_id', 'in', $eids], ['type', '=', 'CompanyStrength']]; if ($date) $share_where[] = ['share_time', 'between', [trim($date[0]) . ' 00:00:00', trim($date[1]) . ' 23:59:59']]; $shares = ShareLog::where($share_where)->column('employee_id'); $data['share_count'] = count($shares); //转发人数 $data['share_group_count'] = count(array_unique($shares)); //获得线索 $clue_where = [['employee_id', 'in', $eids], ['pipe_type', '=', 'CompanyStrength']]; if ($date) $clue_where[] = ['addtime', 'between', [trim($date[0]) . ' 00:00:00', trim($date[1]) . ' 23:59:59']]; $data['clue'] = CustomerClue::where($clue_where)->count(); return $data; } //父級部门 $pid = Org::where([['path', 'like', $root_id . '-%']])->column('pid'); $org = Org::where([['id', 'in', $pid]])->column('id,name'); View::assign('org', $org); return View::fetch(); } /** * 拓客案例数据统计列表 */ public function data_statistics_list() { $root_id = request()->employee->root_id; $param = Request()->only(['page' => 1, 'limit' => 10, 'date' => '', 'org_id' => 0]); //父級部门 $pid = Org::where([['path', 'like', $root_id . '-%']])->column('pid'); $where[] = ['id', 'not in', $pid]; $where[] = ['path', 'like', $root_id . '-%']; if ($param['org_id']) { $path = Org::where('id', $param['org_id'])->value('path'); $where[] = ['path', 'like', $path . '%']; } $date_where = $share_date_where = []; if ($param['date']) { $date = explode(' - ', $param['date']); $date_where[] = ['addtime', 'between', [trim($date[0]) . ' 00:00:00', trim($date[1]) . ' 23:59:59']]; $share_date_where[] = ['share_time', 'between', [trim($date[0]) . ' 00:00:00', trim($date[1]) . ' 23:59:59']]; } //基层部门 $data = Org::with(['employee' => function ($query) { $query->where('state', '在职')->field('id,org_id'); }])->where($where)->page($param['page'], $param['limit'])->order('id asc')->field('id,name')->select()->toArray(); //业务员 $em_where[] = ['root_id', '=', $root_id]; $em_where[] = ['uid', '>', 0]; $em_where[] = ['state', '=', '在职']; $em_where[] = ['org_id', 'in', array_column($data, 'id')]; $eids = Employee::where($em_where)->column('id'); //转发人数,转发次数 $shares = ShareLog::where([['employee_id', 'in', $eids], ['type', '=', 'CompanyStrength']])->where($share_date_where)->column('employee_id'); //浏览人数,浏览次数,浏览时长 $footprint = Footprints::where([['employee_id', 'in', $eids], ['pipe_type', '=', 'CompanyStrength']])->where($date_where)->column('employee_id,uid,visit_due_time'); $footprints = []; foreach ($footprint as $val) { //浏览人员 $footprints[$val['employee_id']]['employee'][]=$val['uid']; //浏览时长 $val['visit_due_time'] = $val['visit_due_time'] ? $val['visit_due_time'] : 0; isset($footprints[$val['employee_id']]['visit_due_time']) ? $footprints[$val['employee_id']]['visit_due_time']+=$val['visit_due_time'] : $footprints[$val['employee_id']]['visit_due_time']=$val['visit_due_time']; } //线索 $clue = CustomerClue::where([['employee_id', 'in', $eids], ['pipe_type', '=', 'CompanyStrength']])->where($date_where)->group('employee_id')->column('count(id) count', 'employee_id'); $res = []; foreach ($data as $k => $v) { $employee = array_intersect($shares, array_column($v['employee'], 'id')); $share_count = count($employee); $share_group_count = count(array_unique($employee)); $look_person = []; //浏览人员 $clue_count = 0; //线索数量 $visit_due_time = 0; //浏览时长 $employee_count = count($v['employee']); //部门人数 foreach ($v['employee'] as $k2 => $v2) { if (isset($footprints[$v2['id']])) { $look_person = array_merge($footprints[$v2['id']]['employee'],$look_person); $visit_due_time += $footprints[$v2['id']]['visit_due_time']; } if (isset($clue[$v2['id']])) $clue_count += $clue[$v2['id']]; } $res[] = [ 'id' => $v['id'], 'org_name' => $v['name'], 'share_count' => $share_count, 'views' => count(array_unique($look_person)), 'clue' => $clue_count, 'visit_due_time' => $visit_due_time, 'share_group_count' => $share_group_count, 'no_share_count' => $employee_count - $share_group_count, ]; } $count = Org::where($where)->count(); $top_date = $this->data_statistics(1, $param['org_id'], $param['date']); return json(['code' => 0, 'data' => $res, 'count' => $count, 'top_data' => $top_date]); } /** * 数据部门详情列表 */ public function datastatistics_org() { $org_id = input('org_id', 0); View::assign('org_id', $org_id); return View::fetch(); } /** * 数据部门详情列表 */ public function datastatistics_org_list() { $param = Request()->only(['org_id' => 0, 'page' => 1, 'limit' => 10, 'keyword' => '', 'date' => '']); $root_id = request()->employee->root_id; $em_where[] = ['root_id', '=', $root_id]; $em_where[] = ['uid', '>', 0]; $em_where[] = ['state', '=', '在职']; $em_where[] = ['org_id', '=', $param['org_id']]; if ($param['keyword']) $em_where[] = ['name', 'like', '%' . trim($param['keyword']) . '%']; $res = Employee::where($em_where)->page($param['page'], $param['limit'])->column('id,name'); $count = Employee::where($em_where)->count(); $eids = array_column($res, 'id'); $date_where = $share_date_where = []; if ($param['date']) { $date = explode(' - ', $param['date']); $date_where[] = ['addtime', 'between', [trim($date[0]) . ' 00:00:00', trim($date[1]) . ' 23:59:59']]; $share_date_where[] = ['share_time', 'between', [trim($date[0]) . ' 00:00:00', trim($date[1]) . ' 23:59:59']]; } //转发人数,转发次数 $shares = ShareLog::where([['employee_id', 'in', $eids], ['type', '=', 'CompanyStrength']])->where($share_date_where)->column('employee_id'); //浏览人数,浏览次数,浏览时长 $footprint = Footprints::where([['employee_id', 'in', $eids], ['pipe_type', '=', 'CompanyStrength']])->where($date_where)->column('employee_id,uid,visit_due_time'); $footprints = []; foreach ($footprint as $val) { //浏览人员 $footprints[$val['employee_id']]['employee'][]=$val['uid']; //浏览时长 $val['visit_due_time'] = $val['visit_due_time'] ? $val['visit_due_time'] : 0; isset($footprints[$val['employee_id']]['visit_due_time']) ? $footprints[$val['employee_id']]['visit_due_time']+=$val['visit_due_time'] : $footprints[$val['employee_id']]['visit_due_time']=$val['visit_due_time']; } //线索 $clue = CustomerClue::where([['employee_id', 'in', $eids], ['pipe_type', '=', 'CompanyStrength']])->where($date_where)->group('employee_id')->column('count(id) count', 'employee_id'); $data = []; foreach ($res as $k => $v) { $employee = array_intersect($shares, [$v['id']]); $data[] = [ 'id' => $v['id'], 'name' => $v['name'], 'share_count' => count($employee), 'views' => isset($footprints[$v['id']]) ? count(array_unique($footprints[$v['id']]['employee'])) : 0, 'clue' => isset($clue[$v['id']]) ? $clue[$v['id']] : 0, 'visit_due_time' => isset($footprints[$v['id']]) ? $footprints[$v['id']]['visit_due_time'] : 0 ]; } return json(['code' => 0, 'data' => $data, 'count' => $count, 'page' => $param]); } /** * 数据统计人员统计详情页面 */ public function datastatistics_org_read() { $eid = input('eid', 0); View::assign('eid', $eid); return View::fetch(); } /** * 数据统计人员统计详情页面 */ public function datastatistics_org_read_list() { $param = Request()->only(['eid' => 0, 'page' => 1, 'limit' => 10, 'keyword' => '', 'date' => '']); $root_id = request()->employee->root_id; $where[] = ['employee_id', '=', $param['eid']]; $where[] = ['type', '=', 'CompanyStrength']; if ($param['keyword']) { $keyword_where[] = ['root_id', '=', $root_id]; $keyword_where[] = ['title', 'like', '%' . trim($param['keyword']) . '%']; $mids = CompanyStrengthModel::where($keyword_where)->column('id'); $where[] = ['data_id', 'in', $mids]; } $ids = ShareLog::where($where)->group('data_id')->column('data_id'); if (empty($ids)) return json(['code' => 0, 'data' => [], 'count' => 0]); $query[] = ['id', 'in', $ids]; //标题 $data = CompanyStrengthModel::where($query)->page($param['page'], $param['limit'])->column('title,id'); $count = CompanyStrengthModel::where($query)->count(); $ids = array_column($data, 'id'); $share_where = $date_where = []; if ($param['date']) { $date = explode(' - ', $param['date']); $share_where[] = ['share_time', 'between', [trim($date[0]) . ' 00:00:00', trim($date[1]) . ' 23:59:59']]; $date_where[] = ['addtime', 'between', [trim($date[0]) . ' 00:00:00', trim($date[1]) . ' 23:59:59']]; } //分享次数 $shares = ShareLog::where([['data_id', 'in', $ids], ['type', '=', 'CompanyStrength']])->where($share_where)->group('data_id')->column('count(id) count', 'data_id'); //获得线索 $clue = CustomerClue::where([['pipe_id', 'in', $ids], ['pipe_type', '=', 'CompanyStrength']])->where($date_where)->group('pipe_id')->column('count(id) count', 'pipe_id'); //浏览时长,浏览次数 $foot_where[] = ['pipe_type', '=', 'CompanyStrength']; $foot_where[] = ['employee_id', '=', $param['eid']]; $where_ids = []; foreach ($ids as $v) { $where_ids[] = '{"id":' . $v . '%'; } $foot_where[] = ['reg_info', 'like', $where_ids, 'OR']; $footprints = Footprints::where($foot_where)->where($date_where)->column('reg_info,visit_due_time'); $views = []; $time = []; foreach ($footprints as $v2) { $json = json_decode($v2['reg_info'], true); $views[$json['id']][] = $json['id']; if ($v2['visit_due_time']) { isset($time[$json['id']]) ? $time[$json['id']] += $v2['visit_due_time'] : $time[$json['id']] = $v2['visit_due_time']; } } $res = []; foreach ($data as $k3 => $v3) { //浏览人数,浏览时长 $res[] = [ 'title' => $v3['title'], 'id' => $v3['id'], 'share_count' => isset($shares[$v3['id']]) ? $shares[$v3['id']] : 0, 'view_count' => isset($views[$v3['id']]) ? count($views[$v3['id']]) : 0, 'visit_due_time' => isset($time[$v3['id']]) ? $time[$v3['id']] : 0, 'clue' => isset($clue[$v3['id']]) ? $clue[$v3['id']] : 0 ]; } return json(['code' => 0, 'data' => $res, 'count' => $count]); } }