employee->root_id]]; //小区名称获取 $communities = Community::where($condition)->where([['type', '=', 0]])->select()->toArray(); View::assign('communities', $communities); //设计师获取 $designers = $this->get_designer(); View::assign('designers', $designers); //风格获取 $decostyles = Decostyle::where($condition)->where([['type', '=', 0]])->select()->toArray(); View::assign('decostyles', $decostyles); //客户见证分类获取 $cates = EvidenceCate::where($condition)->select()->toArray(); View::assign('cates', $cates); //发圈分类获取 $Wechatlabel = DailyWechatLabel::where($condition)->select(); View::assign('Wechatlabel', $Wechatlabel); return View::fetch(); } //获取设计师列表 private function get_designer() { //设计师获取 $w[] = ['path', 'like', request()->employee->root_id . '-%']; $w[] = ['org_type', '=', 2]; $orgs = Org::where($w)->column('id'); $list = Employee::where([['org_id', 'in', $orgs], ['state', '=', '在职'], ['show', '=', 0]])->field('id,name,initials s')->order('s asc')->select()->toArray(); return $list; } /* * 案例添加视图页面 */ public function case_add() { $condition = [['root_id', '=', request()->employee->root_id]]; //小区名称获取 $communities = Community::where($condition)->where([['type', '=', 0]])->order('pinyin asc')->select()->toArray(); if (!empty($communities)) { $communities = hanziheadstr($communities); } View::assign('communities', $communities); //设计师获取 $root_id = request()->employee->root_id; $list = $this->get_designer(); if (!empty($list)) { // $list = hanziInitsort($list, 'name'); $sort = array_column($list, 's'); sort($sort); array_multisort($sort, SORT_ASC, $list); $sort = array_unique($sort); $list = ['sort' => $sort, 'arr' => $list]; } View::assign('designers', $list); //风格获取 $decostyles = Decostyle::where($condition)->where([['type', '=', 0]])->select()->toArray(); View::assign('decostyles', $decostyles); //户型获取 $housetype = Housetype::where($condition)->select()->toArray(); View::assign('housetype', $housetype); $adding = input('adding', 0); view::assign('adding', $adding); return View::fetch(); } public function evidence_add() { $condition = [['root_id', '=', request()->employee->root_id]]; //客户见证分类获取 $cates = EvidenceCate::where($condition)->select()->toArray(); View::assign('cates', $cates); $adding = input('adding', 0); view::assign('adding', $adding); return View::fetch(); } public function wxshow_add() { $condition = [['root_id', '=', request()->employee->root_id], ['from_type', '=', 0]]; //发圈分类获取 $Wechatlabel = DailyWechatLabel::where($condition)->select(); View::assign('Wechatlabel', $Wechatlabel); $adding = input('adding', 0); view::assign('adding', $adding); return View::fetch(); } /** * 添加/列表页面 */ public function __call($method, $arg) { if ($method == 'choiceadding') { $view = $arg['type'] . 'adding'; } elseif ($method == 'wxshowlisting') { $eid = DailyWechatArticle::where([['del', '=', 0], ['root_id', '=', request()->employee->root_id], ['employee_id', '>', 0]])->group('employee_id')->column('employee_id'); $where = [ ['id', 'in', $eid], ['grant_id', '>', 0], ['root_id', '=', request()->employee->root_id] ]; // 运营人员列表 $employee = Employee::where($where)->field(['id', 'opt_name as name'])->select()->toArray(); View::assign('employee', $employee); //分类列表 $label_list = DailyWechatLabel::where('root_id', request()->employee->root_id)->field('id,label_name')->select(); View::assign('label_list', $label_list); $view = $method; } elseif ($method == 'community') { $view = $method; // 查询上传人 $empIds = Community::where([['root_id', '=', request()->employee->root_id]])->column('employee_id'); $employee = Employee::where([['id', 'in', $empIds]])->select(); view::assign('employee', $employee); } else { $view = $method; } return View::fetch($view); } /** * 客户见证添加 */ public function apievidencesaving() { $data = input(); $data['media_url'] = $data['oss_url']; $data['root_id'] = request()->employee->root_id; $obj = new MaterialEvidenceMedia(); if ($obj->save($data)) return json(['code' => 0, 'msg' => '保存成功', 'data' => $obj]); } /** * 添加小区页面 */ public function communityadding() { $id = input('id', '', 'intval'); $info = []; if ($id) { $info = Community::where([['id', '=', $id], ['root_id', '=', request()->employee->root_id]])->findOrEmpty(); $info['province'] = $info['city'] = $info['area'] = ''; if (!$info->isEmpty()) { $location = !empty($info->location) ? explode('/', $info->location) : []; $info['province'] = !empty($location[0]) ? rtrim($location[0], '省') : ''; $info['city'] = !empty($location[1]) ? rtrim($location[1], '市') : ''; $info['area'] = !empty($location[2]) ? rtrim($location[2], '区') : ''; } } View::assign('data', $info); View::assign('id', $id); return View::fetch(); } /* * 案例小区添加 */ public function apicommunityadding() { $param = request()->only(['id', 'community', 'type', 'location' => '', 'duetime' => '']); if (!isset($param['community']) || !$param['community']) { return json(['code' => 1, 'msg' => '请输入小区名称']); } elseif (strlen($param['community']) > 60) { return json(['code' => 1, 'msg' => '小区名称过长']); } $condition = [ 'root_id' => request()->employee->root_id ]; if (isset($param['id']) && $param['id']) { $condition['id'] = $param['id']; } else { $condition['name'] = $param['community']; } $condition['type'] = isset($param['type']) ? $param['type'] : 0; $exitedobj = Community::where($condition)->findorEmpty(); if (empty($param['id']) && !$exitedobj->isEmpty()) return json(['code' => 1, 'msg' => '小区名称重复']); $pinyin = hanzi2pinyin($param['community']); $exitedobj->save([ 'root_id' => request()->employee->root_id, 'pinyin' => $pinyin, 'name' => $param['community'], 'type' => isset($param['type']) ? $param['type'] : 0, 'initials' => strtoupper(substr($pinyin, 0, 1)), 'location' => $param['location'], 'duetime' => $param['duetime'] ? $param['duetime'] : null, 'employee_id' => request()->employee->id ]); return json(['code' => 0, 'msg' => '保存成功', 'data' => ['id' => $exitedobj->id, 'name' => $exitedobj->name]]); } /* * 案例设计师添加 */ public function apidesigneradding() { $data = input(); if (!isset($data['designer-name']) || !$data['designer-name']) { return json(['code' => 1, 'msg' => '请输入设计师名称']); } elseif (strlen($data['designer-name']) > 45) { return json(['code' => 1, 'msg' => '设计师名称过长']); } $data['name'] = $data['designer-name']; $data['root_id'] = request()->employee->root_id; $exitedobj = Designer::where(['name' => $data['name'], 'root_id' => $data['root_id']])->find(); if ($exitedobj) return json(['code' => 1, 'msg' => '设计师已存在']); unset($data['designer-name']); $obj = new Designer(); if ($obj->save($data)) { return json(['code' => 0, 'msg' => '保存成功', 'data' => ['id' => $obj->id, 'name' => $obj->name]]); } } /* * 案例风格添加 */ public function apidecostyleadding() { $param = request()->only(['id', 'decostyle', 'type']); if (!isset($param['decostyle']) || !$param['decostyle']) { return json(['code' => 1, 'msg' => '请输入风格名称']); } elseif (strlen($param['decostyle']) > 45) { return json(['code' => 1, 'msg' => '风格名称过长']); } $condition = [ 'root_id' => request()->employee->root_id ]; if (isset($param['id']) && $param['id']) { $condition['id'] = $param['id']; } else { $condition['name'] = $param['decostyle']; } $condition['type'] = isset($param['type']) ? $param['type'] : 0; $exitedobj = Decostyle::where($condition)->findorEmpty(); if (empty($param['id']) && !$exitedobj->isEmpty()) return json(['code' => 1, 'msg' => '风格重复']); $exitedobj->save([ 'root_id' => request()->employee->root_id, 'name' => $param['decostyle'], 'type' => isset($param['type']) ? $param['type'] : 0, ]); return json(['code' => 0, 'msg' => '保存成功', 'data' => ['id' => $exitedobj->id, 'name' => $exitedobj->name]]); } /* * 案例户型添加 */ public function apihousetypeadding() { $housetype_name = input('housetype-name'); if (!$housetype_name) { return json(['code' => 1, 'msg' => '请输入户型名称']); } elseif (strlen($housetype_name) > 45) { return json(['code' => 1, 'msg' => '户型名称过长']); } $exitedobj = Housetype::where(['name' => $housetype_name, 'root_id' => request()->employee->root_id])->find(); if ($exitedobj) return json(['code' => 1, 'msg' => '户型已存在']); $obj = new Housetype(); $obj->save(['name' => $housetype_name, 'root_id' => request()->employee->root_id]); return json(['code' => 0, 'msg' => '保存成功', 'data' => ['id' => $obj->id, 'name' => $obj->name]]); } /* * 客户见证分类 */ public function apievidencecateadding() { $data = Request::only(['cate-name']); $data['name'] = $data['cate-name']; $data['root_id'] = request()->employee->root_id; $exitedobj = EvidenceCate::where(['name' => $data['name'], 'root_id' => $data['root_id']])->find(); if ($exitedobj) return json(['code' => 1, 'msg' => '分类已存在']); unset($data['cate-name']); $obj = new EvidenceCate(); if ($obj->save($data)) { return json(['code' => 0, 'msg' => '保存成功', 'data' => ['id' => $obj->id, 'name' => $obj->name]]); } } /* * 案例添加 */ public function apicaseadding() { $data = Request::only(['title', 'community_id', 'designer_id', 'style_id', 'housetype_id', 'square', 'room', 'hall', 'toilet', 'desc', 'cover_img', 'money', 'real_case', 'video_case', 'vr_case', 'video_type', 'recommend', 'cover_share_img', 'bh_type']); $data['root_id'] = request()->employee->root_id; $data['employee_id'] = request()->employee->id; $exitedobj = MaterialCase::where(['title' => $data['title'], 'root_id' => $data['root_id']])->find(); if ($exitedobj) return json(['code' => 1, 'msg' => '案例标题已存在']); if (!empty($data['vr_case'])) { $data['vr_case'] = $this->vrlink_set($data['vr_case']); } $data['recommend'] = (isset($data['recommend']) && $data['recommend'] == 'on') ? 1 : 0; $community = Community::where('id', $data['community_id'])->find(); if ($community == null) return json(['code' => 1, 'msg' => '小区不存在']); $data['housetype_type'] = $data['bh_type'] == 2 ? 'building_housetype' : 'housetype'; $m = MaterialCase::create($data); $community->case_num = $community->case_num + 1; $community->save(); // 楼盘 $b = Building::where(['community_id' => $data['community_id']])->find(); dataStatistics(request()->employee->root_id, 'case_count', 1, 'inc'); //manage应用首页统计数据 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 apicaseupdate() { $data = Request::only(['id', 'title', 'community_id', 'designer_id', 'style_id', 'housetype_id', 'square', 'room', 'hall', 'toilet', 'desc', 'cover_img', 'money', 'img_content', 'real_case', 'video_case', 'vr_case', 'video_type', 'recommend', 'cover_share_img', 'housetype_type']); $data['recommend'] = (isset($data['recommend']) && $data['recommend'] == 'on') ? 1 : 0; $exitedobj = MaterialCase::where(['id' => $data['id'], 'root_id' => request()->employee->root_id])->find(); if (!$exitedobj) return json(['code' => 1, 'msg' => '案例未创建']); $cover_img = $exitedobj->cover_img; if (!empty($data['img_content'])) { $img_content = array_filter(json_decode($data['img_content'], true)); foreach ($img_content as $k => $v) { $domain = config('app.ali_oss_bindurl'); $search = 'https://' . $domain . '/'; $img_content[$k]['img'] = str_replace($search, '', $v['img']); // 封面默认为第一张图 if ($k == 0) { $cover_img = str_replace($search, '', $v['img']); } } $data['img_content'] = json_encode($img_content); $data['cover_img'] = $cover_img; } if (!empty($data['cover_img'])) { $data['cover_img'] = str_replace('?x-oss-process=image/resize,l_125', '', $data['cover_img']); } if (!empty($data['cover_share_img'])) { $data['cover_share_img'] = str_replace('?x-oss-process=image/resize,l_125', '', $data['cover_share_img']); } if (!empty($data['vr_case'])) { $data['vr_case'] = $this->vrlink_set($data['vr_case']); } $param = $data; $data = array_filter($data, function ($v) { return ($v === '' || $v === null) ? false : true; }); //非必传可以为空字段 $fields = ['vr_case', 'money', 'desc', 'real_case', 'designer_id']; foreach ($fields as $v) { if (isset($param[$v])) $data[$v] = $param[$v]; } unset($param); if ($exitedobj->save($data)) { return json(['code' => 0, 'msg' => '保存成功']); } else { return json(['code' => 1, 'msg' => '数据未改动']); } } //vr链接设置修改 public function vrlink_set($vr_link) { //2023-05-04 app创建的vr作品 if (strpos($vr_link, '/vr/#')) return $vr_link; // 旧域名 替换成 新域名 $links = [ 'xiaohongwu' => 'hnweizhihui.xiaohongwu.nczyzs.com', 'kujiale' => 'pano337.p.kujiale.com', 'justeasy' => 'vr-17.justeasy.nczyzs.com', '3d66' => 'vr.3d66.nczyzs.com', ]; $url = parse_url($vr_link); if ($url === false || !isset($url['host'])) { echo json_encode(['code' => 1, 'msg' => '链接格式错误']); exit; } if (strpos($url['host'], 'xiaohongwu') !== false) { return str_replace($url['host'], $links['xiaohongwu'], $vr_link); } if (strpos($url['host'], 'kujiale') !== false) { return str_replace($url['host'], $links['kujiale'], $vr_link); } if (strpos($url['host'], 'justeasy') !== false) { return str_replace($url['host'], $links['justeasy'], $vr_link); } if (strpos($url['host'], '3d66') !== false) { return str_replace($url['host'], $links['3d66'], $vr_link); } echo json_encode(['code' => 1, 'msg' => '无效的VR链接']); exit; } /* * 案例删除 */ public function apicasedelete() { $data = input(); if (MaterialCase::where(['id' => $data['id'], 'root_id' => request()->employee->root_id])->update(['del' => 1])) { dataStatistics(request()->employee->root_id, 'case_count', 1, 'dec'); //manage应用首页统计数据 return json(['code' => 0, 'msg' => '删除成功']); } else { return json(['code' => 1, 'msg' => '删除失败']); } } /* * 客户见证添加 */ public function apieviadding() { $data = Request::only(['title', 'desc', 'cate', 'evidence_image', 'pics', 'difference', 'cover' => '', 'video_type', 'cover_share_img']); //视频 if ($data['difference'] == 1) { $data['pics'] = input('video_url', ''); //图片 } else { $data['pics'] = implode(',', $data['evidence_image']); unset($data['evidence_image']); } $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 (MaterialEvidence::create($data)) { return json(['code' => 0, 'msg' => '保存成功']); } else { return json(['code' => 1, 'msg' => '保存失败']); } } /* * 客户见证编辑保存 */ public function apieviupdate() { $data = Request::only(['id', 'title', 'cate', '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) { $video_url = input('video_url', ''); $end = explode(',', $video_url); $data['pics'] = end($end); } else { $data['pics'] = ''; if (isset($data['evidence_image_exist']) && is_array($data['evidence_image_exist'])) { $data['pics'] = implode(',', (array) $data['evidence_image_exist']); } if (isset($data['evidence_image']) && is_array($data['evidence_image'])) { $newpicsstr = implode(',', (array) $data['evidence_image']); if (!empty($data['pics'])) { $data['pics'] = $data['pics'] . ',' . $newpicsstr; } else { $data['pics'] = $newpicsstr; } } } unset($data['evidence_image_exist']); unset($data['evidence_image']); $data['desc'] = isset($data['desc']) && $data['desc'] ? str_replace("\r\n", '', $data['desc']) : ''; $evidence = MaterialEvidence::where(['id' => $data['id'], 'root_id' => request()->employee->root_id])->find(); $evidence->save($data); return json(['code' => 0, 'msg' => '保存成功']); } /* * 客户见证删除 */ public function apievidelete() { $data = input(); if (MaterialEvidence::where(['id' => $data['id'], 'root_id' => request()->employee->root_id])->update(['del' => 1])) { return json(['code' => 0, 'msg' => '删除成功']); } else { return json(['code' => 1, 'msg' => '删除失败']); } } public function apipublish() { $param = Request::param(); $condition = ['id' => $param['id'], 'root_id' => request()->employee->root_id]; switch ($param['cate']) { case 'case': $obj = MaterialCase::where($condition)->find(); break; case 'evidence': $obj = MaterialEvidence::where($condition)->find(); break; case 'wxshow': $obj = DailyWechatArticle::where($condition)->find(); break; } if (empty($obj)) return json(['code' => 1, 'msg' => '数据不存在']); $obj->publish = $obj->publish == 1 ? 0 : 1; $obj->save(); if ($param['cate'] == 'case') { if ($obj->publish) dataStatistics(request()->employee->root_id, 'case_count', 1, 'inc'); //manage应用首页统计数据 //判断是否赠送过积分跟贡献值 $you = Credits::where(['root_id' => request()->employee->root_id, 'employee_id' => $obj->employee_id, 'type' => 1, 'json' => 'upcaseid=' . $obj->id])->count(); if (empty($you)) { $this->add_emp_integral($obj->employee_id, $obj->id); } } return json(['code' => 0, 'msg' => '修改成功']); } //增加业务员的贡献值跟积分 public function add_emp_integral($empid, $id) { $request = request(); $where[] = ['code', '=', 'material_case_value']; $where[] = ['root_id', '=', $request->employee->root_id]; $data = CreditsSetting::where($where)->value('value'); $material_case_value = 1; if (!empty($data)) { $material_case_value = $data; } if ($material_case_value) { $allgx = Credits::where(['root_id' => $request->employee->root_id, 'employee_id' => $empid, 'type' => 1])->sum('credits'); Credits::create([ 'employee_id' => $empid, 'root_id' => $request->employee->root_id, 'credits' => $material_case_value, 'sum' => $allgx + $material_case_value, 'type' => 1, 'json' => 'upcaseid=' . $id, 'remark' => '上传案例审核通过' ]); } } public function caselisting() { $styleList = Decostyle::where(['root_id' => request()->employee->root_id, 'type' => 0])->select(); View::assign('decostyle', $styleList); $eid = MaterialCase::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); $communityList = Community::where(['root_id' => request()->employee->root_id, 'type' => 0])->order('pinyin asc')->select(); if (!empty($communityList)) { $communityList = hanziheadstr($communityList->toArray()); } View::assign('communityList', $communityList); return View::fetch(); } public function personal_case_list() { $communityList = Community::where(['root_id' => request()->employee->root_id, 'type' => 0])->order('pinyin asc')->select()->toArray(); if (!empty($communityList)) { $communityList = hanziheadstr($communityList); } View::assign('communityList', $communityList); $list = $this->get_designer(); if (!empty($list)) { $list = ['sort' => array_unique(array_column($list, 's')), 'arr' => $list]; } View::assign('designers', $list); $employee_ids = MaterialCase::where([['root_id', '=', request()->employee->root_id], ['from', '=', 1], ['del', '=', 0]])->group('employee_id')->column('employee_id'); $employee = Employee::where([['id', 'in', $employee_ids], ['state', '=', '在职']])->select(); View::assign('employee', $employee); return View::fetch(); } /* * 装修案例列表 */ public function caselist() { $param = Request::param(); if (isset($param['title']) && $param['title']) { $where[] = ['title', 'like', '%' . trim($param['title']) . '%']; } // 小区搜索 if (!empty($param['community'])) { $where[] = ['community_id', '=', $param['community']]; } // 风格搜索 if (!empty($param['decostyle'])) { $where[] = ['style_id', '=', $param['decostyle']]; } //上传时间筛选 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[] = ['addtime', 'between', [$start_time, $end_time]]; } if (isset($param['designer_name']) && $param['designer_name']) { $designer_ids = Employee::where([['root_id', '=', request()->employee->root_id], ['name', 'like', '%' . $param['designer_name'] . '%']])->column('id'); $where[] = ['designer_id', 'in', $designer_ids]; } $order = 'recommend desc,addtime 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']; } $where[] = ['del', '=', 0]; $where[] = ['root_id', '=', request()->employee->root_id]; // 员工上传 if (!empty($param['from'])) { $where[] = ['from', '=', 1]; } else { $where[] = ['from', '=', 0]; } if (!empty($param['employee_id'])) { $where[] = ['employee_id', '=', $param['employee_id']]; } if (!empty($param['designer_id'])) { $where[] = ['designer_id', '=', $param['designer_id']]; } $list = MaterialCase::with(['community', 'designer', 'decostyle', 'housetype', 'employee'])->where($where)->page($param['page'], $param['limit'])->order($order)->select(); $list = $list->append(['housetype.name'])->toArray(); $count = MaterialCase::where($where)->count(); $footVisitTime = Footprints::where([ ['pipe_type', '=', 'materialCase'], ['pipe_id', 'in', array_column($list, 'id')], ])->group('pipe_id')->column("sum(visit_due_time)", 'pipe_id'); foreach ($list as $k => $item) { $list[$k]['visit_due_time'] = isset($footVisitTime[$item['id']]) ? $footVisitTime[$item['id']] : 0; } return json(['code' => 0, 'data' => $list, 'count' => $count]); } public function evidencelisting() { $eid = MaterialEvidence::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); $cate_list = EvidenceCate::where('root_id', '=', request()->employee->root_id)->select(); View::assign('cate_list', $cate_list); return View::fetch(); } /* * 客户见证列表 */ public function evidencelist() { $param = Request::param(); if (isset($param['title']) && $param['title']) { $where[] = ['title', 'like', '%' . trim($param['title']) . '%']; } if (!empty($param['cate'])) { $where[] = ['cate', '=', $param['cate']]; } 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[] = ['addtime', 'between', [$start_time, $end_time]]; } $order = 'addtime 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']; } $where[] = ['del', '=', 0]; $where[] = ['root_id', '=', request()->employee->root_id]; $list = MaterialEvidence::with(['cate', 'employee'])->where($where)->page($param['page'], $param['limit'])->order($order)->select(); foreach ($list as &$item) { if (is_string($item->getData('pics'))) { $item['picsdata'] = explode(',', $item->getData('pics')); } if ($item['pics']) { $item['picnum'] = count($item['pics']); } else { $item['picnum'] = 0; } } //增加查询转发次数浏览时长 // if(!empty($list->toArray())){ // $statismod=new MaterialLogic; // $selorder=!empty($param['order'])?$param['order']:''; // $list=$statismod->sel_case_share($list->toArray(),'MaterialEvidence',$selorder); // } $count = MaterialEvidence::where($where)->count(); return json(['code' => 0, 'data' => $list, 'count' => $count]); } /* * 案例修改展示 */ public function casedetail() { $id = input('id'); $data = MaterialCase::where(['id' => $id, 'root_id' => request()->employee->root_id])->with(['community', 'designer', 'decostyle', 'housetype'])->find(); if (empty($data)) return '无效请求'; if (!empty($data['img_content'])) { $img_content = json_decode($data['img_content'], true); foreach ($img_content as $k => $v) { $ali_oss_bindurl = config('app.ali_oss_bindurl'); $img_content[$k]['img'] = 'https://' . $ali_oss_bindurl . '/' . $v['img']; } $data['img_content'] = $img_content; } View::assign('data', $data); $condition = [['root_id', '=', request()->employee->root_id]]; $communities = Community::where($condition)->where([['type', '=', 0]])->order('pinyin asc')->select()->toArray(); if (!empty($communities)) { $communities = hanziheadstr($communities); } View::assign('communities', $communities); $designers = $this->get_designer(); if (!empty($designers)) { $sort = array_column($designers, 's'); sort($sort); array_multisort($sort, SORT_ASC, $designers); $sort = array_unique($sort); $designers = ['sort' => $sort, 'arr' => $designers]; // $designers = hanziInitsort($designers, 'name'); } View::assign('designers', $designers); $decostyles = Decostyle::where($condition)->where([['type', '=', 0]])->select()->toArray(); View::assign('decostyles', $decostyles); $housetype = Housetype::where($condition)->select()->toArray(); View::assign('housetype', $housetype); if (isset($data['from']) && $data['from'] == 1) { return View::fetch('edit_personal_case'); } else { return View::fetch(); } } /* * 拓客案例预览api */ public function preview_casedetail() { $id = input('id'); $data = MaterialCase::where(['id' => $id, 'root_id' => request()->employee->root_id])->with(['community', 'designer', 'decostyle', 'housetype'])->find(); if (!empty($data['img_content'])) { $img_content = json_decode($data['img_content'], true); foreach ($img_content as $k => $v) { $ali_oss_bindurl = config('app.ali_oss_bindurl'); $img_content[$k]['img'] = 'https://' . $ali_oss_bindurl . '/' . $v['img']; } $data['img_content'] = $img_content; } //公司信息 $where[] = ['root_id', '=', request()->employee->root_id]; $data['company_info'] = Company::where($where)->field('company_name,logo,company_address')->find(); //设计师附属字段 if ($data->designer) { $designer = Designer::where([['employee_id', '=', $data->designer_id], ['root_id', '=', request()->employee->root_id]])->field('id,good_at,position')->findOrEmpty(); if ($designer->isEmpty()) { $data->designer->good_at = ''; $data->designer->position = ''; } else { $data->designer->good_at = !empty($designer->good_at) ? $designer->good_at : ''; $data->designer->position = $designer->position ? $designer->position : ''; } $data->designer->headimgurl = User::where('id', '=', $data->designer->uid)->value('headimgurl'); } // 为null处理,防止前端报错 $data['real_case'] = !empty($data['real_case']) ? $data['real_case'] : ''; $data['desc'] = !empty($data['desc']) ? $data['desc'] : ''; $data['vr_case'] = !empty($data['vr_case']) ? $data['vr_case'] : ''; return json(['code' => 0, 'data' => $data, 'msg' => '获取成功']); } /* * 客户见证编辑展示 */ public function evidencedetail() { $id = input('id'); $evidence = MaterialEvidence::with('cate')->where(['id' => $id, 'root_id' => request()->employee->root_id])->field('*,cate cate_id')->find()->toArray(); $evidence['pics'] = $evidence['difference'] == 1 ? $evidence['pics'][0] : $evidence['pics']; View::assign('evidence', $evidence); $ali_oss_bindurl = config('app.ali_oss_bindurl'); View::assign('ali_oss_bindurl', $ali_oss_bindurl); //客户见证分类获取 $cates = EvidenceCate::where([['root_id', '=', request()->employee->root_id]])->select()->toArray(); View::assign('cates', $cates); return View::fetch(); } /* * 客户见证预览 */ public function preview_read() { $id = input('id', 0); $evidence = MaterialEvidence::with('cate')->where(['id' => $id, 'root_id' => request()->employee->root_id])->field('*,cate cate_id')->find()->toArray(); $evidence['pics'] = $evidence['difference'] == 1 ? $evidence['pics'][0] : $evidence['pics']; //公司信息 $where[] = ['root_id', '=', request()->employee->root_id]; $evidence['company_info'] = Company::where($where)->field('company_name,logo,company_address')->find(); return json(['code' => 0, 'msg' => '获取成功', 'data' => $evidence]); } /* * 每日发圈列表 */ public function wxshowlist() { $param = Request::param(); if (isset($param['title']) && $param['title']) { $where[] = ['content', 'like', '%' . trim($param['title']) . '%']; } if (isset($param['employee_id']) && $param['employee_id']) { $where[] = ['employee_id', '=', $param['employee_id']]; } if (isset($param['festival_id']) && $param['festival_id']) { $where[] = ['festival_id', '=', $param['festival_id']]; } if (!empty($param['addtime'])) { list($start_date, $end_date) = explode(' - ', $param['addtime']); $where[] = ['addtime', '>=', $start_date]; $where[] = ['addtime', '<=', date('Y-m-d H:i:s', strtotime($end_date) + 86400)]; } $where[] = ['del', '=', 0]; $where[] = ['root_id', '=', request()->employee->root_id]; //$where[] = ['from_type', '=', 0]; // 获取数据 $list = DailyWechatArticle::where($where)->with(['dailyWechatLabel', 'employee'])->order('addtime desc,use_count desc')->page($param['page'], $param['limit'])->select(); $count = DailyWechatArticle::where($where)->count(); return json(['code' => 0, 'data' => $list, 'count' => $count]); } /* * 每日发圈修改展示 */ public function wxshowdetail() { $id = input('id'); $data = DailyWechatArticle::where(['id' => $id, 'root_id' => request()->employee->root_id])->find(); $data->video = ''; if ($data->type == 1) { $picture = $data->getData('picture'); $arr = $data->picture; $data->video = ($picture == 'undefined' || !$picture) ? '' : end($arr); } View::assign('data', $data); $ali_oss_bindurl = config('app.ali_oss_bindurl'); // $ali_oss_bindurl = 'http://o.nczyzs.com/'; View::assign('ali_oss_bindurl', $ali_oss_bindurl); $label = DailyWechatLabel::where([['root_id', '=', request()->employee->root_id], ['from_type', '=', 0]])->select(); View::assign('label', $label); return View::fetch(); } /** * 每日发圈修改保存 */ public function wxshowsave() { //Request中设置的有全局过滤规则trim,此处重新定义过滤规则(每次发圈开头不需要过滤) request()->filter([]); $data = Request::only(['content', 'article_image', 'article_image_exist', 'label', 'id', 'video_url', 'show_date']); $type = DailyWechatArticle::where('id', $data['id'])->value('type'); // echo $type; if (empty($data['content'])) { return json(['code' => 1, 'msg' => '请输入内容']); } $inset = [ 'festival_id' => !empty($data['label']) ? $data['label'] : 0, 'content' => $data['content'], // 'picture' => empty($data['article_image']) ? '' : implode(',', $data['article_image']), 'id' => $data['id'], 'show_date' => empty($data['show_date']) ? date('Y-m-d') : $data['show_date'] ]; if ($type == 1 && !empty($data['video_url'])) { $arr = explode(',', $data['video_url']); $inset['picture'] = end($arr); } elseif ($type == 2) { isset($data['article_image']) ?: $data['article_image'] = []; isset($data['article_image_exist']) ?: $data['article_image_exist'] = []; $data['article_image'] = array_merge($data['article_image'], $data['article_image_exist']); $inset['picture'] = empty($data['article_image']) ? '' : implode(',', $data['article_image']); } // var_dump($inset);die; // $inset['type'] = empty($inset['picture']) ? 3 : 2; DailyWechatArticle::where(['id' => $data['id'], 'root_id' => request()->employee->root_id])->find()->save($inset); return json(['code' => 0, 'msg' => '修改成功']); } /* * 每日发圈分类添加 */ public function add_wechat_label() { $value = Request::param('value'); $obj = DailyWechatLabel::create(['label_name' => $value, 'root_id' => request()->employee->root_id]); return json(['code' => 0, 'msg' => '添加成功', 'data' => ['id' => $obj->id, 'name' => $obj->label_name]]); } /* * 每日发圈添加 */ public function apiwxadding() { //Request中设置的有全局过滤规则trim,此处重新定义过滤规则(每次发圈开头不需要过滤) request()->filter([]); $data = Request::only(['type', 'content', 'video_url', 'article_image', 'label', 'show_date']); $inset = [ 'festival_id' => !empty($data['label']) ? $data['label'] : 0, 'content' => $data['content'], // 'picture' => $data['type'] == 1 ? $data['video_url'] : ($data['type'] == 3 ? '' : implode(',', $data['article_image'])), // 'picture' => empty($data['article_image']) ? '' : implode(',', $data['article_image']), 'root_id' => request()->employee->root_id, 'type' => $data['type'], 'employee_id' => request()->employee->id, 'show_date' => empty($data['show_date']) ? date('Y-m-d') : $data['show_date'] ]; if ($data['type'] == 1) { $inset['picture'] = isset($data['video_url']) && $data['video_url'] ? $data['video_url'] : ''; } elseif ($data['type'] == 2) { $inset['picture'] = empty($data['article_image']) ? '' : implode(',', $data['article_image']); if ($inset['picture']) { $img = explode(',', $inset['picture']); $imgs = []; foreach ($img as $v) { array_unshift($imgs, $v); } $inset['picture'] = implode(',', $imgs); } } else { $inset['picture'] = ''; } DailyWechatArticle::insert($inset); return json(['code' => 0, 'msg' => '添加成功']); } /* * 每日发圈删除 */ public function apiwxdelete() { $data = input(); Db::startTrans(); try { $ms = DailyWechatArticle::where(['id' => $data['id'], 'root_id' => request()->employee->root_id])->find(); //->update(['del' => 1]); //增加查询是否有指派 $zp = DailyWechatArticle::where([['from_content_id', '=', $data['id']], ['from_type', 'in', [1, 2]], ['from_root_id', '=', request()->employee->root_id]])->find(); if (!empty($zp)) { //删除所有本文章的指派 DailyWechatArticle::where([['from_content_id', '=', $data['id']], ['from_type', 'in', [1, 2]], ['from_root_id', '=', request()->employee->root_id]])->update(['del' => 1]); //查询当前删除文章分类下是否有其它指派的文章 $you = DailyWechatArticle::where([['festival_id', '=', $zp['festival_id']], ['from_type', 'in', [1, 2]], ['from_root_id', '=', request()->employee->root_id], ['del', '=', 0]])->count(); //如果没有就直接删除当前文章的指派分类 if (empty($you)) { $obj = DailyWechatLabel::where([['id', '=', $zp['festival_id']], ['from_content_id', '=', $ms['festival_id']], ['from_type', 'in', [1, 2]], ['from_root_id', '=', request()->employee->root_id]])->delete(); } } $dl = DailyWechatArticle::where(['id' => $data['id'], 'root_id' => request()->employee->root_id])->update(['del' => 1]); Db::commit(); } catch (\Exception $e) { Db::rollback(); //var_dump($e->getMessage()); return json(['code' => 1, 'msg' => '提交数据失败.']); } if ($dl) { return json(['code' => 0, 'msg' => '删除成功']); } else { return json(['code' => 1, 'msg' => '删除失败']); } } /* * VR */ public function vr() { return View::fetch(); } /* * Vision 智能屏 */ public function vision() { return View::fetch(); } /* * 分类管理 */ function cate_administration($type) { view::assign('type', $type); return View::fetch(); } /* * 素材案例分类管理列表 */ function cate_administration_list() { $param = Request::param(); $type = isset($param['type']) ? $param['type'] : 0; $condition = [['root_id', '=', request()->employee->root_id]]; if (!empty($param['keyword'])) $condition[] = ['name', 'like', '%' . $param['keyword'] . '%']; if (!empty($param['addtime'])) { list($start_date, $end_date) = explode(' - ', $param['addtime']); $condition[] = ['addtime', '>=', $start_date]; $condition[] = ['addtime', '<=', date('Y-m-d H:i:s', strtotime($end_date) + 86400)]; } if (!empty($param['employee_id'])) { $condition[] = ['employee_id', '=', $param['employee_id']]; } if ($type == 0) { //小区名称获取 $list = Community::with(['employee' => function ($query) { $query->field(['id', 'opt_name']); }])->where($condition)->where([['type', '=', 0]])->page($param['page'], $param['limit'])->order(['show' => 'asc', 'id' => 'desc'])->select(); $count = Community::where($condition)->where([['type', '=', 0]])->count(); } elseif ($type == 1) { //风格获取 $list = Decostyle::where($condition)->where([['type', '=', 0]])->page($param['page'], $param['limit'])->order(['show' => 'asc', 'id' => 'desc'])->select()->toArray(); $count = Decostyle::where($condition)->where([['type', '=', 0]])->count(); } elseif ($type == 2) { //户型获取 $list = Housetype::where($condition)->page($param['page'], $param['limit'])->order(['show' => 'asc', 'id' => 'desc'])->select()->toArray(); $count = Housetype::where($condition)->select()->count(); } return json(['code' => 0, 'data' => $list, 'count' => $count]); } /* * 分类管理编辑 */ function cate_administration_edit() { $param = Request::param(); // return $param; $type = isset($param['type']) ? $param['type'] : 0; $conditions[] = ['id', '=', $param['id']]; $conditions[] = ['root_id', '=', request()->employee->root_id]; $condition[] = ['name', '=', $param['name']]; $condition[] = ['root_id', '=', request()->employee->root_id]; $data['name'] = $param['name']; $province = !empty($param['province']) ? rtrim($param['province'], '省') . '省' : ''; $city = !empty($param['city']) ? rtrim($param['city'], '市') . '市' : ''; $area = !empty($param['area']) ? rtrim($param['area'], '区') . '区' : ''; if ($type == 0) { $model = Community::where($condition); $models = Community::where($conditions); $data['pinyin'] = hanzi2pinyin($data['name']); $data['initials'] = strtoupper(substr($data['pinyin'], 0, 1)); //$data['location'] = isset($param['location']) ? $param['location'] : ''; $data['location'] = $province . '/' . $city . '/' . $area; $data['duetime'] = !empty($param['duetime']) ? $param['duetime'] : null; $data['employee_id'] = request()->employee->id; $data['households'] = input('households', 0); $data['users'] = $param['users']; //小区名称 } elseif ($type == 1) { //风格 $model = Decostyle::where($condition); $models = Decostyle::where($conditions); } elseif ($type == 2) { //户型获取 $model = Housetype::where($condition); $models = Housetype::where($conditions); } $info = $model->find(); if ($info && $info['id'] != $param['id']) { return json(['code' => 1, 'msg' => '名称已存在']); } $models->save($data); return json(['code' => 0, 'msg' => '保存成功', 'data' => '']); } /* * 分类管理添加 */ function cate_administration_add() { $param = Request::param(); // return $param; $type = isset($param['type']) ? $param['type'] : 0; $condition[] = ['name', '=', $param['name']]; $condition[] = ['root_id', '=', request()->employee->root_id]; $province = !empty($param['province']) ? rtrim($param['province'], '省') . '省' : ''; $city = !empty($param['city']) ? rtrim($param['city'], '市') . '市' : ''; $area = !empty($param['area']) ? rtrim($param['area'], '区') . '区' : ''; $data['name'] = $param['name']; $data['root_id'] = request()->employee->root_id; if ($type == 0) { $model = Community::where($condition)->where([['type', '=', 0]]); $models = new Community; $data['pinyin'] = hanzi2pinyin($data['name']); $data['initials'] = strtoupper(substr($data['pinyin'], 0, 1)); //$data['location'] = isset($param['location']) ? $param['location'] : ''; $data['location'] = $province . '/' . $city . '/' . $area; $data['duetime'] = !empty($param['duetime']) ? $param['duetime'] : null; $data['employee_id'] = request()->employee->id; $data['households'] = input('households', 0); $data['users'] = $param['users']; //小区名称 } elseif ($type == 1) { //风格 $model = Decostyle::where($condition)->where([['type', '=', 0]]); $models = new Decostyle; } elseif ($type == 2) { //户型获取 $model = Housetype::where($condition); $models = new Housetype; } $info = $model->find(); if ($info) { return json(['code' => 1, 'msg' => '名称已存在']); } $models->save($data); return json(['code' => 0, 'msg' => '保存成功', 'data' => '']); } /* * 分类管理关联的数量 */ public function with_cate_administration_count() { $param = Request::param(); $type = isset($param['type']) ? $param['type'] : 0; $msg = '确定删除该分类吗?'; $joinMsg = ''; if ($type == 0) { //小区名称 $caseCount = MaterialCase::where([['del', '=', 0], ['root_id', '=', request()->employee->root_id], ['community_id', '=', $param['id']]])->count(); $caseCount > 0 ? $joinMsg .= $caseCount . '个拓客案例/' : ''; $buildingCount = Building::where([['root_id', '=', request()->employee->root_id], ['community_id', '=', $param['id']]])->count(); $buildingCount > 0 ? $joinMsg .= $buildingCount . '个热装楼盘/' : ''; $constructionCount = Construction::where([['root_id', '=', request()->employee->root_id], ['community_id', '=', $param['id']]])->count(); $constructionCount > 0 ? $joinMsg .= $constructionCount . '个在施工地/' : ''; if ($caseCount > 0 || $buildingCount > 0 || $constructionCount > 0) $msg = '该分类有' . $joinMsg . '删除后该内容将归为其它分类。'; } elseif ($type == 1) { //风格 $caseCount = MaterialCase::where([['del', '=', 0], ['root_id', '=', request()->employee->root_id], ['style_id', '=', $param['id']]])->count(); $caseCount > 0 ? $joinMsg .= $caseCount . '个拓客案例/' : ''; $constructionCount = Construction::where([['root_id', '=', request()->employee->root_id], ['style_id', '=', $param['id']]])->count(); $constructionCount > 0 ? $joinMsg .= $constructionCount . '个在施工地/' : ''; if ($caseCount > 0 || $constructionCount > 0) $msg = '该分类有' . $joinMsg . '删除后该内容将归为其它分类。'; } elseif ($type == 2) { //户型 $caseCount = MaterialCase::where([['del', '=', 0], ['root_id', '=', request()->employee->root_id], ['housetype_id', '=', $param['id']]])->count(); $caseCount > 0 ? $joinMsg .= $caseCount . '个拓客案例/' : ''; $constructionCount = Construction::where([['root_id', '=', request()->employee->root_id], ['housetype_id', '=', $param['id']]])->count(); $constructionCount > 0 ? $joinMsg .= $constructionCount . '个在施工地/' : ''; if ($caseCount > 0 || $constructionCount > 0) $msg = '该分类有' . $joinMsg . '删除后该内容将归为其它分类。'; } return $msg; } /* * 拓客案例分类删除 */ public function cate_administration_delete() { $param = Request::param(); $type = isset($param['type']) ? $param['type'] : 0; Db::startTrans(); try { if ($type == 0) { //小区删除关联(拓客案例、热装楼盘、在施工地) $community_id = Community::where(['root_id' => request()->employee->root_id, 'type' => 0, 'show' => 1])->value('id'); if (empty($community_id)) $community_id = Community::insertGetId(['name' => '其它', 'pinyin' => 'qita', 'root_id' => request()->employee->root_id, 'type' => 0, 'show' => 1]); //删除标签 Community::where(['root_id' => request()->employee->root_id, 'id' => $param['id']])->delete(); //关联的标签更换为其它 MaterialCase::where([['del', '=', 0], ['root_id', '=', request()->employee->root_id], ['community_id', '=', $param['id']]])->update(['community_id' => $community_id]); Construction::where([['root_id', '=', request()->employee->root_id], ['community_id', '=', $param['id']]])->update(['community_id' => $community_id]); Building::where([['root_id', '=', request()->employee->root_id], ['community_id', '=', $param['id']]])->update(['community_id' => $community_id]); } elseif ($type == 1) { //风格删除关联(拓客案例、在施工地) $Decostyle_id = Decostyle::where(['root_id' => request()->employee->root_id, 'show' => 1])->value('id'); if (empty($Decostyle_id)) $Decostyle_id = Decostyle::insertGetId(['name' => '其它', 'root_id' => request()->employee->root_id, 'type' => 0, 'show' => 1]); //删除标签 Decostyle::where(['root_id' => request()->employee->root_id, 'id' => $param['id']])->delete(); //关联的标签更换为其它 MaterialCase::where([['del', '=', 0], ['root_id', '=', request()->employee->root_id], ['style_id', '=', $param['id']]])->update(['style_id' => $Decostyle_id]); Construction::where([['root_id', '=', request()->employee->root_id], ['style_id', '=', $param['id']]])->update(['style_id' => $Decostyle_id]); } elseif ($type == 2) { //户型删除关联(拓客案例、在施工地) $housetype_id = Housetype::where(['root_id' => request()->employee->root_id, 'show' => 1])->value('id'); if (empty($housetype_id)) $housetype_id = Housetype::insertGetId(['name' => '其它', 'root_id' => request()->employee->root_id, 'show' => 1]); //删除标签 Housetype::where(['root_id' => request()->employee->root_id, 'id' => $param['id']])->delete(); //关联的标签更换为其它 MaterialCase::where([['del', '=', 0], ['root_id', '=', request()->employee->root_id], ['housetype_id', '=', $param['id']]])->update(['housetype_id' => $housetype_id]); Construction::where([['root_id', '=', request()->employee->root_id], ['housetype_id', '=', $param['id']]])->update(['housetype_id' => $housetype_id]); } Db::commit(); return json(['code' => 0, 'msg' => '操作成功']); } catch (\Exception $e) { Db::rollback(); return json(['code' => 1, 'msg' => '操作失败']); } } /* * 客户见证分类管理 */ function cate_customer() { return View::fetch(); } /* * 客户见证分类管理列表 */ function cate_customer_list() { $param = Request::param(); $condition = [['root_id', '=', request()->employee->root_id]]; $list = EvidenceCate::where($condition)->page($param['page'], $param['limit'])->order(['show' => 'asc', 'id' => 'desc'])->field('id,name,show')->select()->toarray(); $count = EvidenceCate::where($condition)->count(); return json(['code' => 0, 'data' => $list, 'count' => $count]); } /* * 客户见证分类管理添加 */ function cate_customer_add() { $param = Request::param(); $condition[] = ['name', '=', $param['name']]; $condition[] = ['root_id', '=', request()->employee->root_id]; $data['name'] = $param['name']; $model = EvidenceCate::where($condition); $models = new EvidenceCate; $info = $model->find(); if ($info) { return json(['code' => 1, 'msg' => '名称已存在']); } $models->name = $param['name']; $models->root_id = request()->employee->root_id; $models->save(); return json(['code' => 0, 'msg' => '保存成功', 'data' => '']); } /* * 分类管理编辑 */ function cate_customer_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]; $data['name'] = $param['name']; if (!$data['name']) { return json(['code' => 1, 'msg' => '名称不能为空!']); } $model = EvidenceCate::where($condition); $models = EvidenceCate::where($conditions); $info = $model->find(); if ($info) { return json(['code' => 1, 'msg' => '名称已存在']); } $models->update($data); return json(['code' => 0, 'msg' => '保存成功', 'data' => '']); } /* * 客户见证分类关联数量 */ public function with_evidence_cate_count() { $id = Request::param('id'); $where = [ ['root_id', '=', request()->employee->root_id], ['del', '=', 0], ['cate', '=', $id] ]; $count = MaterialEvidence::where($where)->count(); return $count > 0 ? '该分类有' . $count . '个客户好评,删除后该内容将归为其它分类。' : '确定删除该分类吗?'; } /* * 客户见证分类删除 */ public function delete_evidence_cate() { $id = Request::param('id'); $cate_id = EvidenceCate::where(['root_id' => request()->employee->root_id, 'show' => 1])->value('id'); if (empty($cate_id)) $cate_id = EvidenceCate::insertGetId(['name' => '其它', 'root_id' => request()->employee->root_id, 'show' => 1]); EvidenceCate::where(['root_id' => request()->employee->root_id, 'id' => $id])->delete(); $where = [ ['root_id', '=', request()->employee->root_id], ['del', '=', 0], ['cate', '=', $id] ]; MaterialEvidence::where($where)->update(['cate' => $cate_id]); return json(['code' => 0, 'msg' => '删除成功']); } /* * 朋友圈分类管理 */ function cate_wechat() { //来源判断是集团后台还是店面后台 $from = request()->param('from'); View::assign('from', $from); return View::fetch(); } /* * 朋友圈分类管理列表 */ function cate_wechat_list() { $param = Request::param(); $condition = [ ['root_id', '=', request()->employee->root_id] // ['from_type', '=', 0] ]; $list = DailyWechatLabel::where($condition)->page($param['page'], $param['limit'])->order(['show' => 'asc', 'id' => 'desc'])->field('id,label_name name,from_type,show')->select()->toArray(); //去掉集团指派的分类重复 foreach ($list as $key => $val) { $xin[$val['from_type']][] = $val; } foreach ($xin as $key => $val) { $p = $this->quchong($val); $new[] = $p; } foreach ($new as $key => $val) { foreach ($val as $k => $v) { $s[] = $v[0]; } } $count = DailyWechatLabel::where($condition)->count(); return json(['code' => 0, 'data' => $s, 'count' => $count]); } public function quchong($val) { foreach ($val as $key => $val) { $xin[$val['name']][] = $val; } return $xin; } /* * 朋友圈分类管理添加 */ function cate_wechat_add() { $param = Request::param(); $condition[] = ['label_name', '=', $param['name']]; $condition[] = ['root_id', '=', request()->employee->root_id]; $condition[] = ['from_type', '=', 0]; //增加查询自建的分类 $data['label_name'] = $param['name']; $model = DailyWechatLabel::where($condition); $models = new DailyWechatLabel; $info = $model->find(); if ($info) { return json(['code' => 1, 'msg' => '名称已存在']); } $models->label_name = $param['name']; $models->root_id = request()->employee->root_id; $models->save(); return json(['code' => 0, 'msg' => '保存成功', 'data' => '']); } /* * 朋友圈分类管理编辑 */ function cate_wechat_edit() { $param = Request::param(); $conditions[] = ['id', '=', $param['id']]; $conditions[] = ['root_id', '=', request()->employee->root_id]; $condition[] = ['label_name', '=', $param['name']]; $condition[] = ['root_id', '=', request()->employee->root_id]; $condition[] = ['from_type', '=', 0]; $data['label_name'] = $param['name']; $model = DailyWechatLabel::where($condition); $models = DailyWechatLabel::where($conditions); $info = $model->find(); if ($info) { return json(['code' => 1, 'msg' => '名称已存在']); } $models->update($data); return json(['code' => 0, 'msg' => '保存成功', 'data' => '']); } /* * 朋友圈分类删除时关联数量 */ public function cate_wechat_join_count() { $id = Request::param('id'); $where = [ ['root_id', '=', request()->employee->root_id], ['festival_id', '=', $id] ]; $count = DailyWechatArticle::where($where)->count(); return $count > 0 ? '该分类有' . $count . '个每日发圈,删除后该内容将归为其它分类。' : '确定删除该分类吗?'; } /* * 朋友圈分类删除 */ public function cate_wechat_delete() { $id = Request::param('id'); $cate_id = DailyWechatLabel::where(['root_id' => request()->employee->root_id, 'show' => 1])->value('id'); if (empty($cate_id)) $cate_id = DailyWechatLabel::insertGetId(['label_name' => '其它', 'root_id' => request()->employee->root_id, 'show' => 1]); DailyWechatLabel::where(['root_id' => request()->employee->root_id, 'id' => $id])->delete(); $where = [ ['root_id', '=', request()->employee->root_id], ['festival_id', '=', $id] ]; DailyWechatArticle::where($where)->update(['festival_id' => $cate_id]); return json(['code' => 0, 'msg' => '删除成功']); } /****************************集团后台板块开始*********************************/ /* * 集团后台每日发圈数据列表 */ public function group_wechat_list() { $param = Request::param(); if (!Request::isAjax()) { View::assign('root_id', isset($param['root_id']) ? $param['root_id'] : ''); return View::fetch(); } $where = [ ['del', '=', 0], ['from_type', '=', 0], ['root_id', '=', request()->employee->root_id] ]; if (isset($param['keyword'])) { $where[] = ['content', 'like', '%' . trim($param['keyword']) . '%']; } // 获取数据 $list = DailyWechatArticle::where($where)->with(['dailyWechatLabel', 'employee'])->order('addtime desc,use_count desc')->page($param['page'], $param['limit'])->select()->toArray(); $ids = array_column($list, 'id'); $shareCompany = DailyWechatArticle::where([['from_type', '=', 1], ['from_content_id', 'in', $ids]])->group('from_content_id')->column('count(id)', 'from_content_id'); foreach ($list as &$v) { $v['shareCompany'] = isset($shareCompany[$v['id']]) ? $shareCompany[$v['id']] : 0; } $count = DailyWechatArticle::where($where)->count(); return json(['code' => 0, 'data' => $list, 'count' => $count]); } /* * 共享的店面 */ public function groupShareCompany() { if (!Request::isAjax()) { $id = request()->param('id'); view::assign('id', $id); return View::fetch(); } $id = request()->param('id'); $page = input('page', 1); $limit = input('limit', 10); $data = DailyWechatArticle::with(['company'])->where(['from_content_id' => $id, 'from_root_id' => request()->employee->root_id])->page($page, $limit)->select(); $count = DailyWechatArticle::with(['company'])->where(['from_content_id' => $id, 'from_root_id' => request()->employee->root_id])->count(); return json(['code' => 0, 'data' => $data, 'count' => $count]); } /* * 指派 */ public function groupAssign() { $param = request()->param(); if (!Request::isAjax()) { View::assign('id', $param['id']); return View::fetch(); } $companyId = Company::where('root_id', request()->employee->root_id)->value('id'); $data = Company::where('company_group', $companyId)->field('root_id,company_name')->page($param['page'], $param['limit'])->select(); $count = Company::where('company_group', $companyId)->count(); return json(['code' => 0, 'data' => $data, 'count' => $count]); } /* * 每日发圈指派 */ public function group_wechat_assign() { $param = request()->param(); //共享时查询关联数据 $wechat = DailyWechatArticle::where(['id' => $param['id'], 'root_id' => request()->employee->root_id])->find(); if (!$wechat) return json(['code' => 1, 'msg' => '数据不存在']); $label = DailyWechatLabel::where('id', $wechat['festival_id'])->find(); Db::startTrans(); try { $ids = explode(',', $param['ids']); foreach ($ids as $v) { //标签共享 //查询标签重复 $where = []; $where[] = ['root_id', '=', $v]; $where[] = ['label_name', '=', $label['label_name']]; $check = DailyWechatLabel::where($where)->findOrEmpty(); if ($check->isEmpty()) { $newLabel = DailyWechatLabel::insertGetId([ 'from_type' => 1, 'from_root_id' => request()->employee->root_id, 'from_content_id' => $label['id'], 'label_name' => $label['label_name'], 'root_id' => $v ]); } else { $newLabel = $check->id; } unset($where); //课程数据 $NewData = [ 'content' => $wechat['content'], 'picture' => $wechat->getData('picture'), 'type' => $wechat['type'], 'festival_id' => $newLabel, 'use_count' => 0, 'publish' => 1, 'employee_id' => $wechat['employee_id'], 'root_id' => $v, 'from_type' => 1, 'from_root_id' => $wechat['root_id'], 'from_content_id' => $wechat['id'], ]; DailyWechatArticle::create($NewData); } Db::commit(); return json(['code' => 0, 'msg' => '操作成功']); } catch (\Exception $e) { Db::rollback(); return json(['code' => 1, 'msg' => '操作失败']); } } /***************************集团后台板块结束**********************************/ /** * 拓客案例数据统计页面 */ public function case_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 = MaterialCase::where($case_where)->column('view_times'); $data['case_count'] = count($case); //浏览人数 $data['views'] = array_sum(array_filter($case)); //浏览人数 //浏览时长 $foot_where = [['pipe_type', '=', 'MaterialCase'], ['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'); // var_dump($foot_where);exit; $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', '=', 'MaterialCase']]; 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', '=', 'materialCase']]; 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 case_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', '=', 'MaterialCase']])->where($share_date_where)->column('employee_id'); //浏览人数,浏览次数,浏览时长 $footprint = Footprints::where([['employee_id', 'in', $eids], ['pipe_type', '=', 'materialCase']])->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', '=', 'materialCase']])->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->case_data_statistics(1, $param['org_id'], $param['date']); return json(['code' => 0, 'data' => $res, 'count' => $count, 'top_data' => $top_date]); } /** * 拓客案例数据部门详情列表 */ public function case_datastatistics_org() { $org_id = input('org_id', 0); View::assign('org_id', $org_id); return View::fetch(); } /** * 拓客案例数据部门详情列表 */ public function case_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', '=', 'MaterialCase']])->where($share_date_where)->column('employee_id'); //浏览人数 // $footprints = Footprints::where([['employee_id', 'in', $eids], ['pipe_type', '=', 'materialCase']])->where($date_where)->group('employee_id')->column('count(id) count,sum(visit_due_time) visit_due_time', 'employee_id'); //浏览人数,浏览次数,浏览时长 $footprint = Footprints::where([['employee_id', 'in', $eids], ['pipe_type', '=', 'materialCase']])->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', '=', 'materialCase']])->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 case_datastatistics_org_read() { $eid = input('eid', 0); View::assign('eid', $eid); return View::fetch(); } /** * 拓客案例数据统计人员统计详情页面 */ public function case_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', '=', 'MaterialCase']; if ($param['keyword']) { $keyword_where[] = ['root_id', '=', $root_id]; $keyword_where[] = ['title', 'like', '%' . trim($param['keyword']) . '%']; $mids = MaterialCase::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 = MaterialCase::where($query)->page($param['page'], $param['limit'])->column('title,id'); $count = MaterialCase::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', '=', 'MaterialCase']])->where($share_where)->group('data_id')->column('count(id) count', 'data_id'); //获得线索 $clue = CustomerClue::where([['pipe_id', 'in', $ids], ['pipe_type', '=', 'materialCase']])->where($date_where)->group('pipe_id')->column('count(id) count', 'pipe_id'); //浏览时长,浏览次数 $foot_where[] = ['pipe_type', '=', 'materialCase']; $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]); } //客户好评数据统计列表 public function evidence_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 = 'materialEvidence'; $share_type = 'MaterialEvidence'; $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) { $evidence_cont = MaterialEvidence::where([['del', '=', 0], ['root_id', '=', request()->employee->root_id]])->count(); $all = ['evidence_cont' => $evidence_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 = 'materialEvidence'; $share_type = 'MaterialEvidence'; //转发人数 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]]; } $em_where[] = ['employee_id', 'in', $sub_employee_ids]; $where[] = ['type', '=', $share_type]; //$where[] = ['employee_id', 'in', $sub_employee_ids]; $shared_employee = ShareLog::where($where)->where($em_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)->where($em_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)->where($em_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 = 'materialEvidence'; $share_type = 'MaterialEvidence'; $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 = MaterialEvidence::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 = MaterialEvidence::where([['root_id', '=', request()->employee->root_id], ['id', 'in', $share_list]])->field('id,title')->page($param['page'], $param['limit'])->select()->toArray(); $clue_type = 'materialEvidence'; $share_type = 'MaterialEvidence'; 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 = MaterialEvidence::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 = 'materialEvidence'; $share_type = 'MaterialEvidence'; $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']; } } //$clue_id=$foot_id=[]; $vdid = array_values(array_unique(array_merge($shared_id, $clue_id, $foot_id))); return $vdid; } /** * 此方法用于从某个企业复制<拓客案例>至另一个企业 */ public function copy_materialcase($from_root_id = 0, $new_root_id = 0) { if (!$from_root_id || !$new_root_id) return '错误'; if ($from_root_id == $new_root_id) return '错误'; $company = Company::where([['root_id', 'in', [$from_root_id, $new_root_id]]])->count(); if ($company != 2) return '错误'; //小区 $communities_arr = []; $communities = Community::where('root_id', $from_root_id)->order('addtime')->column('*', 'id'); foreach ($communities as $comment) { $have = Community::where(['root_id' => $new_root_id, 'name' => $comment['name']])->value('id'); if (!empty($have)) { $cid = $have; } else { $cid = Community::insertGetId([ 'name' => $comment['name'], 'pinyin' => $comment['pinyin'], 'nick_name' => $comment['nick_name'], 'location' => $comment['location'], 'cover_img' => $comment['cover_img'], 'desc' => $comment['desc'], 'case_num' => $comment['case_num'], 'root_id' => $new_root_id, 'type' => $comment['type'], 'show' => $comment['show'], 'initials' => $comment['initials'], ]); } $communities_arr[$comment['id']] = $cid; } //风格 $style_arr = []; $decostyle = Decostyle::where('root_id', $from_root_id)->order('addtime')->select(); foreach ($decostyle as $style) { $have = Decostyle::where(['root_id' => $new_root_id, 'name' => $style['name']])->value('id'); if (!empty($have)) { $sid = $have; } else { $sid = Decostyle::insertGetId([ 'name' => $style['name'], 'desc' => $style['desc'], 'root_id' => $new_root_id, 'type' => $style['type'], 'show' => $style['show'], ]); } $style_arr[$style['id']] = $sid; } //户型 $housetype_arr = []; $housetype = Housetype::where('root_id', $from_root_id)->order('addtime')->select(); foreach ($housetype as $type) { $have = Housetype::where(['root_id' => $new_root_id, 'name' => $type['name']])->value('id'); if (!empty($have)) { $hid = $have; } else { $hid = Housetype::insertGetId([ 'name' => $type['name'], 'desc' => $type['desc'], 'root_id' => $new_root_id, 'show' => $type['show'], ]); } $housetype_arr[$type['id']] = $hid; } $material = MaterialCase::where(['root_id' => $from_root_id, 'del' => 0])->order('addtime')->column('*', 'id'); foreach ($material as $item) { MaterialCase::insertGetId([ 'root_id' => $new_root_id, 'title' => $item['title'], 'community_id' => isset($communities_arr[$item['community_id']]) ? $communities_arr[$item['community_id']] : 0, 'designer_id' => 0, 'style_id' => isset($style_arr[$item['style_id']]) ? $style_arr[$item['style_id']] : 0, 'square' => $item['square'], 'room' => $item['room'], 'hall' => $item['hall'], 'toilet' => $item['toilet'], 'cover_img' => $item['cover_img'], 'desc' => $item['desc'], 'publish' => $item['publish'], 'housetype_id' => isset($housetype_arr[$item['housetype_id']]) ? $housetype_arr[$item['housetype_id']] : 0, 'money' => $item['money'], 'img_content' => $item['img_content'], 'from' => $item['from'], 'qrcode' => $item['qrcode'], 'img_content_data' => $item['img_content_data'], 'img_download_status' => $item['img_download_status'], 'real_case' => $item['real_case'], 'video_case' => $item['video_case'], 'vr_case' => $item['vr_case'], ]); } return '复制成功'; } /** * 此方法用于从某个企业复制<拓客视频>至另一个企业 */ public function copy_video($from_root_id = 0, $new_root_id = 0) { if (!$from_root_id || !$new_root_id) return '错误'; if ($from_root_id == $new_root_id) return '错误'; $company = Company::where([['root_id', 'in', [$from_root_id, $new_root_id]]])->count(); if ($company != 2) return '错误'; $type_arr = []; $label_arr = []; $VideoType = VideoType::where(['root_id' => $from_root_id, 'type' => 'video', 'pid' => 0])->select(); foreach ($VideoType as $val) { $typeid = VideoType::insertGetId([ 'name' => $val['name'], 'sort' => $val['sort'], 'type' => 'video', 'root_id' => $new_root_id, 'show' => $val['show'], 'pid' => 0 ]); $type_arr[$val['id']] = $typeid; $label = VideoType::where(['root_id' => $from_root_id, 'type' => 'video', 'pid' => $val['id']])->select(); foreach ($label as $la) { $labelid = VideoType::insertGetId([ 'name' => $la['name'], 'sort' => $la['sort'], 'type' => 'video', 'root_id' => $new_root_id, 'show' => $la['show'], 'pid' => $typeid ]); $label_arr[$la['id']] = $labelid; } } $video = Video::where(['root_id' => $from_root_id, 'delete_time' => 0])->column('*', 'id'); foreach ($video as $item) { Video::insertGetId([ 'title' => $item['title'], 'description' => $item['description'], 'video_url' => $item['video_url'], 'type' => isset($type_arr[$item['type']]) ? $type_arr[$item['type']] : 0, 'cover' => $item['cover'], 'publish' => $item['publish'], 'label' => isset($label_arr[$item['label']]) ? $label_arr[$item['label']] : 0, 'root_id' => $new_root_id, ]); } return '复制成功'; } /** * 此方法用于从某个企业复制<拓客图文>至另一个企业 */ public function copy_article($from_root_id = 0, $new_root_id = 0) { if (!$from_root_id || !$new_root_id) return '错误'; if ($from_root_id == $new_root_id) return '错误'; $company = Company::where([['root_id', 'in', [$from_root_id, $new_root_id]]])->count(); if ($company != 2) return '错误'; $type_arr = []; $label_arr = []; $VideoType = VideoType::where(['root_id' => $from_root_id, 'type' => 'article', 'pid' => 0])->select(); foreach ($VideoType as $val) { $typeid = VideoType::insertGetId([ 'name' => $val['name'], 'sort' => $val['sort'], 'type' => 'article', 'root_id' => $new_root_id, 'show' => $val['show'], 'pid' => 0 ]); $type_arr[$val['id']] = $typeid; $label = VideoType::where(['root_id' => $from_root_id, 'type' => 'article', 'pid' => $val['id']])->select(); foreach ($label as $la) { $labelid = VideoType::insertGetId([ 'name' => $la['name'], 'sort' => $la['sort'], 'type' => 'article', 'root_id' => $new_root_id, 'show' => $la['show'], 'pid' => $typeid ]); $label_arr[$la['id']] = $labelid; } } $Article = Article::where(['root_id' => $from_root_id, 'delete_time' => 0])->column('*', 'id'); foreach ($Article as $item) { $new_label = []; $label_old = explode(',', $item['label']); if (!empty($label_old)) { foreach ($label_old as $v) { if (isset($label_arr[$v])) { $new_label[] = $label_arr[$v]; } } } $new_label = implode(',', $new_label); Article::insertGetId([ 'title' => $item['title'], 'cover_img' => $item['cover_img'], 'type' => isset($type_arr[$item['type']]) ? $type_arr[$item['type']] : 0, 'content' => $item['content'], 'publish' => $item['publish'], 'root_id' => $new_root_id, 'label' => $new_label ]); } return '复制成功'; } /** * 此方法用于从某个企业复制<公司实力>至另一个企业 */ public function copy_companystrength($from_root_id = 0, $new_root_id = 0) { if (!$from_root_id || !$new_root_id) return '错误'; if ($from_root_id == $new_root_id) return '错误'; $company = Company::where([['root_id', 'in', [$from_root_id, $new_root_id]]])->count(); if ($company != 2) return '错误'; $cate = CompanyStrengthCate::where(['root_id' => $from_root_id])->select(); foreach ($cate as $v) { CompanyStrengthCate::insertGetId([ 'root_id' => $new_root_id, 'name' => $v['name'], 'show' => $v['show'], 'pid' => $v['pid'], ]); } $data = CompanyStrength::where(['root_id' => $from_root_id, 'del' => 0])->column('*', 'id'); foreach ($data as $val) { CompanyStrength::insertGetId([ 'root_id' => $new_root_id, 'cate' => $val['cate'], 'title' => $val['title'], 'media_ids' => $val['media_ids'], 'pics' => $val['pics'], 'cover' => $val['cover'], 'desc' => $val['desc'], 'publish' => $val['publish'], 'difference' => $val['difference'], ]); } return '复制成功'; } /** * 此方法用于从某个企业复制<客户好评>至另一个企业 */ public function copy_materialevidence($from_root_id = 0, $new_root_id = 0) { if (!$from_root_id || !$new_root_id) return '错误'; if ($from_root_id == $new_root_id) return '错误'; $company = Company::where([['root_id', 'in', [$from_root_id, $new_root_id]]])->count(); if ($company != 2) return '错误'; $data = MaterialEvidence::where(['root_id' => $from_root_id, 'del' => 0])->column('*', 'id'); foreach ($data as $val) { MaterialEvidence::insertGetId([ 'root_id' => $new_root_id, 'cate' => $val['cate'], 'title' => $val['title'], 'media_ids' => $val['media_ids'], 'pics' => $val['pics'], 'cover' => $val['cover'], 'desc' => $val['desc'], 'publish' => $val['publish'], 'difference' => $val['difference'], ]); } return '复制成功'; } /** * 此方法用于从某个企业复制<热装楼盘>至另一个企业 * building_id传递只复制单个楼盘 */ public function copy_building($from_root_id = 0, $new_root_id = 0, $building_id = 0) { if (!$from_root_id || !$new_root_id) return '错误'; if ($from_root_id == $new_root_id) return '错误'; $company = Company::where([['root_id', 'in', [$from_root_id, $new_root_id]]])->count(); if ($company != 2) return '错误'; $where = [ 'root_id' => $from_root_id, 'del' => 0, ]; if (!empty($building_id)) $where['id'] = $building_id; Db::startTrans(); try { $data = Building::where($where)->column('*', 'id'); foreach ($data as $val) { //新增小区 $community = Community::where(['root_id' => $from_root_id, 'id' => $val['community_id']])->find(); $community_id = Community::where(['root_id' => $new_root_id, 'name' => $community['name']])->value('id'); if (empty($community_id)) { $comm = new Community; $comm->name = $community['name']; $comm->pinyin = $community['pinyin']; $comm->nick_name = $community['nick_name']; $comm->location = $community['location']; $comm->cover_img = $community['cover_img']; $comm->desc = $community['desc']; $comm->root_id = $new_root_id; $comm->show = $community['show']; $comm->initials = $community['initials']; $comm->save(); $community_id = $comm->id; } $buildingNewId = Building::insertGetId([ 'name' => $val['name'], 'pinyin' => $val['pinyin'], 'address' => $val['address'], 'duetime' => $val['duetime'], 'cover' => $val['cover'], 'vr_link' => $val['vr_link'], 'content' => $val['content'], 'root_id' => $new_root_id, 'sign_num' => $val['sign_num'], 'start_num' => $val['start_num'], 'finish_num' => $val['finish_num'], 'from' => $val['from'], 'down_status' => $val['down_status'], 'media_id' => $val['media_id'], 'community_id' => !empty($community_id) ? $community_id : 0, ]); //楼盘进展 $progress = BuildingProgress::where(['root_id' => $from_root_id, 'building_id' => $val['id']])->order('addtime')->column('*', 'id'); foreach ($progress as $p) { $pro['building_id'] = $buildingNewId; $pro['name'] = $p['name']; $pro['type'] = $p['type']; $pro['img'] = $p['img']; $pro['vr'] = $p['vr']; $pro['content'] = $p['content']; $pro['root_id'] = $new_root_id; $pro['video'] = $p['video']; $pro['from'] = $p['from']; $pro['down_status'] = $p['down_status']; $pro['media_id'] = $p['media_id']; BuildingProgress::insert($pro); } //楼盘户型 $housetype = BuildingHousetype::where(['root_id' => $from_root_id, 'building_id' => $val['id']])->order('addtime')->select(); foreach ($housetype as $t) { $house['building_id'] = $buildingNewId; $house['area'] = $t['area']; $house['room'] = $t['room']; $house['hall'] = $t['hall']; $house['bathroom'] = $t['bathroom']; $house['root_id'] = $new_root_id; $house['house_img'] = $t['house_img']; $house['vr_link'] = $t['vr_link']; $house['house_count'] = $t['house_count']; $house['orientation'] = $t['orientation']; $house['type'] = $t['type']; $house['from'] = $t['from']; $house['down_status'] = $t['down_status']; $house['media_id'] = $t['media_id']; $house['img_content'] = $t['img_content']; $house['house_img_media_id'] = $t['house_img_media_id']; $newHouTypeId = BuildingHousetype::insertGetId($house); //研发案例 $case = BuildingDevelopCase::where(['root_id' => $from_root_id, 'housetype_id' => $t['id']])->order('addtime')->select(); foreach ($case as $c) { $ca['name'] = $c['name']; $ca['type'] = $c['type']; $ca['vr_link'] = $c['vr_link']; $ca['content'] = $c['content']; $ca['building_id'] = $buildingNewId; $ca['housetype_id'] = $newHouTypeId; $ca['root_id'] = $new_root_id; $ca['cover'] = $c['cover']; $ca['from'] = $c['from']; $ca['img_content'] = $c['img_content']; $ca['down_status'] = $c['down_status']; $ca['media_id'] = $c['media_id']; $from_decostyle = Decostyle::where(['root_id' => $from_root_id, 'id' => $c['decostyles_id']])->find(); $new_decostyle = Decostyle::where(['root_id' => $new_root_id, 'name' => $from_decostyle['name']])->value('id'); if (empty($new_decostyle)) { $ca['decostyles_id'] = Decostyle::insertGetId([ 'name' => $from_decostyle['name'], 'desc' => $from_decostyle['desc'], 'root_id' => $new_root_id, 'type' => $from_decostyle['type'], 'show' => $from_decostyle['show'], ]); } else { $ca['decostyles_id'] = $new_decostyle; } BuildingDevelopCase::insertGetId($ca); } } } Db::commit(); return '复制成功'; } catch (\Exception $e) { // 回滚事务 Db::rollback(); return '复制失败'; } } /** * 小区导入 */ public function importingCommunity() { return View::fetch(); } /** * 导入前日志存储 */ public function importCommunityLog() { $request = request(); $param = $request->only(['file_name', 'count' => 0]); $logData = [ 'name' => $param['file_name'], 'employee_id' => $request->employee->id, 'root_id' => $request->employee->root_id, 'count' => $param['count'] ]; $data = CommunityImportLog::create($logData); return json(['code' => 0, 'msg' => '添加成功', 'data' => $data->id]); } /** * 小区excel添加 */ public function importCommunityAdd() { $logId = input('log_id', '', 'intval'); $log = CommunityImportLog::where('id', $logId)->find(); if (empty($log)) return json(['code' => 1, 'msg' => '请求错误,记录不存在']); $datas = input('content', '', 'trim'); if (count($datas) == 0) return json(['code' => 1, 'msg' => '请求错误,未传输数据']); $rs = ['ok' => 0, 'error' => 0, 'repeat' => 0]; $root_id = request()->employee->root_id; $community = []; foreach ($datas as $k => $data) { //判断小区是否已存在 $communityExist = Community::where([['name', '=', $data['name']], ['root_id', '=', $root_id]])->findOrEmpty(); if (!$communityExist->isEmpty()) { $rs['repeat']++; } else { $one['name'] = $data['name']; $one['households'] = $data['households']; $one['pinyin'] = hanzi2pinyin($data['name']); $one['initials'] = strtoupper(substr($one['pinyin'], 0, 1)); $one['root_id'] = $root_id; $one['employee_id'] = request()->employee->id; $one['location'] = $data['province'] . '/' . $data['city'] . '/' . $data['area']; $one['duetime'] = $data['duetime']; $one['users'] = $data['users']; $community[] = $one; } } Db::startTrans(); try { Community::insertAll($community); Db::commit(); } catch (\Exception $e) { trace($e->getMessage(), 'error'); // 回滚事务 Db::rollback(); return json(['code' => 1, 'msg' => $e->getMessage()]); } return json(['code' => 0, 'msg' => '保存成功', 'data' => $rs]); } /** * 导出小区 */ public function export_community() { $request = request(); $root_id = $request->employee->root_id; $list = Community::where([['root_id', '=', $root_id], ['type', '=', 0]])->order(['show' => 'asc', 'id' => 'desc'])->column('name,households,location,duetime,users'); foreach ($list as $key => $val) { $pty = []; if (!empty($val['location'])) $pty = explode('/', $val['location']); $new[] = ['name' => $val['name'], 'households' => $val['households'], 'province' => !empty($pty[0]) ? $pty[0] : '', 'city' => !empty($pty[1]) ? $pty[1] : '', 'area' => !empty($pty[2]) ? $pty[2] : '', 'duetime' => $val['duetime'], 'users'=> $val['users']]; } $header = ["A1" => "楼盘名称", "B1" => "户数", "C1" => "省", "D1" => "市", "E1" => "区", "F1" => '交房时间', "G1" => '活跃用户']; $fileName = date('Y-m-d H:i:s') . '小区导出'; $this->getExport($header, true, $new, $fileName); } // 导出 public function getExport($header = [], $type = false, $data = [], $fileName) { // 实例化类 $preadsheet = new Spreadsheet(); // 创建sheet $sheet = $preadsheet->getActiveSheet(); // 循环设置表头数据 foreach ($header as $k => $v) { $sheet->setCellValue($k, $v); } // 生成数据 $sheet->fromArray($data, null, "A2"); // 样式设置 $sheet->getDefaultColumnDimension()->setWidth(12); // 设置下载与后缀 if ($type) { header("Content-Type:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); $type = "Xlsx"; $suffix = "xlsx"; } else { header("Content-Type:application/vnd.ms-excel"); $type = "Xls"; $suffix = "xls"; } ob_end_clean(); //清楚缓存区 // 激活浏览器窗口 header("Content-Disposition:attachment;filename=$fileName.$suffix"); //缓存控制 header("Cache-Control:max-age=0"); // 调用方法执行下载 $writer = IOFactory::createWriter($preadsheet, $type); // 数据流 $writer->save("php://output"); } }