1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720 |
- <?php
- namespace app\sys\controller;
- use app\logics\OrgLogic;
- use app\model\Building as BuildingModel;
- use app\model\BuildingConstruction;
- use app\model\BuildingHousetype;
- use app\model\BuildingImportLog;
- use app\model\BuildingMaterialCase;
- use app\model\BuildingProgress;
- use app\model\BuildingUrge;
- use app\model\Community;
- use app\model\Construction as ConstructionModel;
- use app\model\ConstructionRecord;
- use app\model\ConstructionStep;
- use app\model\Employee;
- use app\model\MaterialCase;
- use app\model\Org;
- use think\facade\Db;
- use think\facade\Request;
- use think\facade\View;
- use app\model\Decostyle;
- use app\model\BuildingDevelopCase;
- use app\model\BuildingSpecialEmp;
- use app\logics\MaterialLogic;
- use app\model\BuildingHousetypeFile;
- use app\model\BuildingLabel;
- use app\model\VrGroup;
- use app\model\Footprints as FootprintsModel;
- class Building
- {
- public function index()
- {
- if (!request()->isAjax()) {
- // 运营人员列表
- $eid = BuildingModel::where([['del', '=', 0], ['from', '=', 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);
- //增加手机端上传人员列表
- $employee_mb = $this->mobile_up_emp();
- View::assign('employee_mb', $employee_mb);
- // 部门
- $org = OrgLogic::struc(request()->employee->root_id);
- View::assign('org', $org);
- $orgids = orgSubIds(request()->employee->root_id);
- View::assign('orgids', json_encode($orgids));
- $communityList = Community::field('id,name,pinyin as s')->where(['root_id' => request()->employee->root_id, 'type' => 0])->order('pinyin asc')->select();
- if (!empty($communityList)) {
- $communityList = $communityList->toArray();
- foreach ($communityList as &$item) {
- if (empty($item['s']))
- $item['s'] = hanziInitials($item['name']);
- else
- $item['s'] = $item['s'][0];
- $item['upper_s'] = strtoupper($item['s'][0]);
- }
- $communityList = ['sort' => array_unique(array_column($communityList, 'upper_s')), 'arr' => $communityList];
- }
- View::assign('communityList', $communityList);
- return View::fetch();
- }
- $from = input('from');
- if (!empty($from)) {
- $where[] = ['from', '=', 1];
- } else {
- $where[] = ['from', '=', 0];
- }
- $where[] = ['del', '=', 0];
- $name = input('name', '', 'trim');
- if ($name) {
- $condition = [
- ['root_id', '=', request()->employee->root_id],
- ['type', '=', 0],
- ['name', 'like', '%' . $name . '%']
- ];
- $community_id = Community::where($condition)->column('id');
- $where[] = ['community_id', 'in', $community_id];
- }
- $employee_id = input('employee_id');
- if ($employee_id) {
- $where[] = ['employee_id', '=', $employee_id];
- }
- // 小区筛选
- $community_id_get = input('community_id', '', 'intval');
- if ($community_id_get) {
- $where[] = ['community_id', '=', $community_id_get];
- }
- // 时间段筛选
- $time = input('time', '', 'trim');
- if ($time) {
- $newtime = explode(' - ', $time);
- $where[] = ['addtime', 'between', [$newtime[0] . ' 00:00:00', $newtime[1] . ' 23:59:59']];
- }
- //手机上传部门上传
- $org_id = input('org_id','','trim');
- if($org_id){
- if($from==1){
- $where[] = ['org_id','=',$org_id];
- }
- }
- $root_id = request()->employee->root_id;
- $where[] = ['root_id', '=', $root_id];
- $page = input('page', 1, 'intval');
- $limit = input('limit', 10, 'intval');
- $list = BuildingModel::with(['employee' => function ($query) {
- $query->field('id,name,opt_name');
- }])->where($where)->withCount(['progress', 'materialCase', 'housetype'])->order('addtime desc')->page($page, $limit)->select()->each(function ($item) {
- $vr_count = 0;
- if (!empty($item['vr_link'])){
- $vr_count ++;
- }
- $housetype_list = BuildingHousetype::where('building_id', '=', $item['id'])->select()->toArray();
- if (!empty($housetype_list)){
- foreach ($housetype_list as $k => $h){
- if (!empty($h['vr_link'])){
- $vr_count ++;
- }
- }
- }
- $develop_list = BuildingDevelopCase::where('building_id', '=', $item['id'])->select()->toArray();
- if (!empty($develop_list)){
- foreach ($develop_list as $k => $d){
- if (!empty($d['vr_link'])){
- $vr_count ++;
- }
- }
- }
- $progress_list = BuildingProgress::where('building_id', '=', $item['id'])->order('addtime desc')->select()->toArray();
- $item->last_update_time = '';
- if (!empty($progress_list)) {
- foreach ($progress_list as $k => $p) {
- if (!empty($p['vr'])) {
- $vrs = explode(',', $p['vr']);
- $vr_count += count($vrs);
- }
- if (!empty($p['addtime']) && $k == 0) {
- $item->last_update_time = $p['addtime'];
- }
- }
- }
- $item->vr_count = $vr_count;
- })->toArray();
- /*if (!empty($list)) {
- $sort = array_column($list,'pinyin');
- array_multisort($sort, SORT_ASC, $list);
- }*/
- //增加转发次数浏览时长
- if(!empty($list)){
- $statismod=new MaterialLogic;
- $selorder=!empty($param['order'])?$param['order']:'';
- $list=$statismod->sel_case_share($list,'Building',$selorder);
- }
- $count = BuildingModel::where($where)->count();
- return json(['code'=> 0, 'data'=> $list, 'count'=> $count]);
- }
- //手机端上传人员列表
- public function mobile_up_emp()
- {
- $eid = BuildingModel::where([['del', '=', 0], ['from', '=', 1], ['root_id', '=', request()->employee->root_id], ['employee_id', '>', 0]])->group('employee_id')->column('employee_id');
- $where = [
- ['id', 'in', $eid],
- ['root_id', '=', request()->employee->root_id]
- ];
- $list = Employee::where($where)->field(['id', 'name'])->select()->toArray();
- return $list;
- }
- /**
- * 楼盘名称列表
- */
- public function name_list()
- {
- $from=input('from');
- $where[] = ['root_id', '=', request()->employee->root_id];
- $where[] = ['from', '=', $from];
- $list = BuildingModel::where($where)->column('community_id');
- //$list = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'];
- $condition[] = ['root_id', '=', request()->employee->root_id];
- $condition[] = ['id', 'in', $list];
- $communities = Community::where($condition)->where([['type', '=', 0]])->order('pinyin asc')->select()->toArray();
- $first = [];
- if (!empty($communities)) {
- $communities = hanziheadstr($communities);
- $first = $communities['sort'];
- }
- return json(['code' => 0, 'data' => array_values(array_filter($first, function ($arr) {
- if ($arr === '' || $arr === null) {
- return false;
- }
- return true;
- }))]);
- }
- /**
- * 添加楼盘
- */
- public function add()
- {
- if (!request()->isPost()) {
- $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);
- return View::fetch();
- }
- $param = request()->only(['name', 'community_id', 'address', 'duetime', 'cover', 'vr_link'=>'', 'content', 'sign_num', 'start_num', 'finish_num','vr_group_ids','cover_share_img']);
- /*$name = $param['name'];
- $first_name = mb_substr($name, 0, 1);
- // 开头不是字母也不是汉字,限制添加
- if (!ctype_alpha($first_name) && !preg_match("/[\x{4e00}-\x{9fff}]+/u", $first_name)){
- return json(['code'=> 1, 'msg'=> '小区名称首字限制为字母或汉字']);
- }
- $param['pinyin'] = getfirstchar($first_name);*/
- $param['employee_id'] = request()->employee->id;
- $param['root_id'] = request()->employee->root_id;
- if (!empty($param['vr_link'])) {
- $param['vr_link'] = $this->vrlink_set($param['vr_link']);
- }
- if (!empty($param['cover'])) {
- $param['cover'] = implode(',', $param['cover']);
- }
- $param['duetime'] = empty($param['duetime']) ? null : $param['duetime'];
- $result = BuildingModel::create($param);
- if ($result) {
- dataStatistics(request()->employee->root_id,'building_count',1,'inc');//manage应用首页统计数据
- return json(['code' => 0, 'msg' => '添加成功']);
- } else {
- return json(['code' => 1, 'msg' => '添加失败']);
- }
- }
- /**
- * 编辑楼盘
- */
- public function edit()
- {
- if (!request()->isPost()) {
- $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);
- $id = input('id', '', 'intval');
- $info = BuildingModel::find($id);
- $info->group_name = $info->vr_group_ids ? (VrGroup::where('id',$info->vr_group_ids)->value('title') ?: '未命名作品') : '';
- View::assign('data', $info);
- View::assign('id', $id);
- return View::fetch();
- }
- $param = request()->only(['id', 'community_id', 'name', 'address', 'duetime', 'cover', 'vr_link'=>'', 'content', 'sign_num', 'start_num', 'finish_num','vr_group_ids','cover_share_img']);
- /*$name = $param['name'];
- $first_name = mb_substr($name, 0, 1);
- // 开头不是字母也不是汉字,限制添加
- if (!ctype_alpha($first_name) && !preg_match("/[\x{4e00}-\x{9fff}]+/u", $first_name)){
- return json(['code'=> 1, 'msg'=> '小区名称首字限制为字母或汉字']);
- }
- $param['pinyin'] = getfirstchar($first_name);*/
- if (!empty($param['vr_link'])) {
- $param['vr_link'] = $this->vrlink_set($param['vr_link']);
- }
- if (!empty($param['cover'])) {
- $new_img = $param['cover'];
- }
- $img_exist = input('img_exist', [], 'trim');
- foreach ($img_exist as $key => $val) {
- $img_exist[$key] = str_replace('https://' . config('app.ali_oss_bindurl') . '/', '', $val);
- }
- $img = [];
- if (!empty($new_img) && !empty($img_exist)) {
- $img = array_merge($new_img, $img_exist);
- } elseif (!empty($new_img)) {
- $img = $new_img;
- } elseif (!empty($img_exist)) {
- $img = $img_exist;
- }
- $param['cover'] = implode(',', $img);
- // var_dump($param);
- // exit;
- $param['duetime'] = empty($param['duetime']) ? null : $param['duetime'];
- $result = BuildingModel::where('id', $param['id'])->save($param);
- if ($result !== false) {
- return json(['code' => 0, 'msg' => '保存成功']);
- } else {
- return json(['code' => 1, 'msg' => '保存失败']);
- }
- }
- /**
- * 删除楼盘
- */
- public function delete()
- {
- $id = input('id', '', 'intval');
- $find = BuildingModel::find($id);
- if (empty($find)) {
- return json(['code' => 0, 'msg' => '删除成功']);
- }
- if ($find['root_id'] != request()->employee->root_id) {
- return json(['code' => 1, 'msg' => '删除失败']);
- }
- $result = $find->delete();
- if ($result !== false) {
- dataStatistics(request()->employee->root_id,'building_count',1,'dec');//manage应用首页统计数据
- return json(['code' => 0, 'msg' => '删除成功']);
- } else {
- return json(['code' => 1, 'msg' => '删除失败']);
- }
- }
- /**
- * 户型
- * @return string
- */
- public function housetype()
- {
- $building_id = input('building_id', '', 'intval');
-
- if (!request()->isAjax()) {
- $data = BuildingModel::find($building_id);
- View::assign('data', $data);
- View::assign('building_id', $building_id);
- return View::fetch();
- }
- $community_id = input('community_id', '', 'intval');
- if ($community_id) {
- return $this->selectHouseType($community_id);
- }
- $page = input('page',0);
- $limit = input('limit',10);
- $list = BuildingHousetype::where('building_id', '=', $building_id)->withCount(['materialCase', 'devcase'])->order('id desc')->page($page,$limit)->select()->toArray();
- $count = BuildingHousetype::where('building_id', '=', $building_id)->count();
- foreach ($list as $k => $v) {
- $list[$k]['construction_count'] = $v['constructionid'] ? count(explode(',',$v['constructionid'])) : 0;
- }
- return json(['code' => 0, 'data' => $list,'count'=>$count]);
- }
- private function selectHouseType($community_id){
- $building_id = BuildingModel::where(['community_id'=>$community_id])->value('id');
- $h = BuildingHousetype::where('building_id', '=', $building_id)->select();
- $nh = [1 => '一', 2 => '二', 3 => '三', 4 => '四', 5 => '五', 6 => '六', 7 => '七', 8 => '八', 9 => '九'];
- $data = [];
- foreach($h as $i){
- $r = $i['room']==9?'别墅':$nh[$i['room']].'室'.$nh[$i['hall']].'厅'.$nh[$i['bathroom']].'卫';
- $data[] = ['id'=>$i['id'], 'housetype'=>$r];
- }
- return json(['code' => 0, 'data' => $data]);
- }
- //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;
- }
- /**
- * 添加户型
- * @return string
- */
- public function add_housetype()
- {
- $building_id = input('building_id', '', 'intval');
- if (!request()->isPost()) {
- View::assign('building_id', $building_id);
- return View::fetch();
- }
- $param = request()->only(['vr_group_ids'=>'','building_id', 'type', 'area', 'room', 'hall', 'bathroom', 'vr_link', 'house_img', 'house_count', 'orientation','reference_price','constructionid','notes']);
- $param['root_id'] = request()->employee->root_id;
- $orientation = null;
- if (!empty($param['orientation'])) {
- foreach ($param['orientation'] as $key => $val) {
- $orientation .= $key . ',';
- }
- $param['orientation'] = trim($orientation, ',');
- }
- $url = 'hnweizhihui.xiaohongwu';
- $jurl = 'web.xiaohongwu';
- if (!empty($param['vr_link'])) {
- $param['vr_link'] = $this->vrlink_set($param['vr_link']);
- }
- //增加别墅户型(其室厅卫值都为999)
- if ($param['type'] == 2) {
- $param['room'] = 9;
- $param['hall'] = 9;
- $param['bathroom'] = 9;
- }
- $result = BuildingHousetype::insertGetId($param);
- $more_files = input('more_files', '', 'html_entity_decode');
- if (!empty($more_files)) {
- $more_files = json_decode($more_files, true);
- $files = [];
- foreach ($more_files as $k => $v) {
- $v_data['housetype_id'] = $result;
- $v_data['filename'] = $v['filename'];
- $v_data['filesize'] = $v['filesize'];
- $v_data['fileurl'] = $v['fileurl'];
- $v_data['employee_id'] = request()->employee->id;
- $v_data['root_id'] = request()->employee->root_id;
- $files[] = $v_data;
- }
- BuildingHousetypeFile::insertAll($files);
- }
- if ($result) {
- return json(['code' => 0, 'msg' => '添加成功']);
- } else {
- return json(['code' => 1, 'msg' => '添加失败']);
- }
- }
- /**
- * 编辑户型
- * @return string
- */
- public function edit_housetype()
- {
- $id = input('id', '', 'intval');
- if (!request()->isPost()) {
- $info = BuildingHousetype::find($id);
- $info['orientation'] = explode(',', $info->getData('orientation'));
- $info->group_name = $info->vr_group_ids ? (VrGroup::where('id', $info->vr_group_ids)->value('title') ?: '未命名作品') : '';
- $info['files'] = BuildingHousetypeFile::where('housetype_id', '=', $id)->select()->toArray();
- View::assign('data', $info);
- return View::fetch();
- }
- $param = request()->only(['vr_group_ids'=>'','id', 'area', 'room', 'hall', 'bathroom', 'vr_link', 'house_img', 'house_count', 'orientation', 'type', 'title', 'images_exist', 'images_data', 'from','reference_price','constructionid','notes']);
- $info = BuildingHousetype::find($param['id']);
- if (!empty($param['vr_link'])) {
- $param['vr_link'] = $this->vrlink_set($param['vr_link']);
- }
- $orientation = null;
- if (!empty($param['orientation'])) {
- foreach ($param['orientation'] as $key => $val) {
- $orientation .= $key . ',';
- }
- $param['orientation'] = trim($orientation, ',');
- }
- //增加别墅户型(其室厅卫值都为999)
- if ($param['type'] == 2) {
- $param['room'] = 9;
- $param['hall'] = 9;
- $param['bathroom'] = 9;
- }
- if ($param['from'] == 1) {
- $param['house_count'] = !empty($param['title']) ? $param['title'] : '';
- $img = [];
- $newimg = [];
- $images_exist = !empty($param['images_exist']) ? $param['images_exist'] : '';
- $images_data = !empty($param['images_data']) ? $param['images_data'] : '';
- if (!empty($images_exist) && !empty($images_data)) {
- $img = array_merge($images_data, $images_exist);
- } elseif (!empty($images_exist)) {
- $img = $images_exist;
- } elseif (!empty($images_data)) {
- $img = $images_data;
- }
- if (!empty($img)) {
- foreach ($img as $key => $val) {
- $newimg[] = str_replace('https://' . config('app.ali_oss_bindurl') . '/', '', $val);
- }
- }
- $param['img_content'] = implode(',', $newimg);
- }
- $more_files = input('more_files', '', 'html_entity_decode');
- if (!empty($more_files)) {
- $more_files = json_decode($more_files, true);
- $old_files = [];
- $new_files = [];
- $delete_files = [];
- $old_files = BuildingHousetypeFile::where('housetype_id', '=', $id)->select()->toArray();
- $save_ids = array_filter(array_column($more_files, 'id'));
- foreach ($old_files as $k => $v) {
- if (!in_array($v['id'], $save_ids)) {
- BuildingHousetypeFile::where('id', '=', $v['id'])->delete();
- }
- }
- foreach ($more_files as $k => $v) {
- if (empty($v['id'])) {
- $v_data['housetype_id'] = $id;
- $v_data['filename'] = $v['filename'];
- $v_data['filesize'] = $v['filesize'];
- $v_data['fileurl'] = $v['fileurl'];
- $v_data['employee_id'] = request()->employee->id;
- $v_data['root_id'] = request()->employee->root_id;
- $new_files[] = $v_data;
- }
- }
- BuildingHousetypeFile::insertAll($new_files);
- } else {
- BuildingHousetypeFile::where([['housetype_id', '=', $id], ['root_id', '=', request()->employee->root_id]])->delete();
- }
- $result = $info->save($param);
- return json(['code' => 0, 'msg' => '修改成功']);
- if ($result) {
- return json(['code' => 0, 'msg' => '修改成功']);
- } else {
- return json(['code' => 1, 'msg' => '修改失败']);
- }
- }
- public function delete_housetype()
- {
- $id = input('id', '', 'intval');
- $find = BuildingHousetype::find($id);
- if (empty($find)) {
- return json(['code' => 0, 'msg' => '删除成功']);
- }
- if ($find['root_id'] != request()->employee->root_id) {
- return json(['code' => 1, 'msg' => '删除失败']);
- }
- $result = $find->delete();
- if ($result !== false) {
- return json(['code' => 0, 'msg' => '删除成功']);
- } else {
- return json(['code' => 1, 'msg' => '删除失败']);
- }
- }
- /**
- * 进度
- * @return string
- */
- public function progress()
- {
- if (!request()->isAjax()) {
- $building_id = input('building_id', '', 'intval');
- View::assign('building_id', $building_id);
- return View::fetch();
- }
- $building_id = input('building_id', '', 'intval');
- $list = BuildingProgress::with(['label'=>function($query){
- $query->withField(['id','name']);
- }])->where('building_id', '=', $building_id)->order('addtime desc')->select()->each(function ($item) {
- if (!empty($item['vr'])) {
- $item->vr = explode(',', $item['vr']);
- }
- })->toArray();
- $gids = array_column($list,'vr_group_ids');
- $group_ids = VrGroup::where([['id','in',$gids]])->column('sid','id');
- $host = config('app.vr_show_domain');
- foreach ($list as $key => $value) {
- $sid = ($value['vr_group_ids'] && isset($group_ids[$value['vr_group_ids']])) ? $group_ids[$value['vr_group_ids']] : '';
- $list[$key]['show_url'] = $sid ? $host.$sid : '';
- }
- return json(['code' => 0, 'data' => $list]);
- }
- /**
- * 添加进度
- * @return string
- */
- public function add_progress()
- {
- if (!request()->isPost()) {
- $building_id = input('building_id', '', 'intval');
- View::assign('building_id', $building_id);
- $label = BuildingLabel::where(['root_id'=>request()->employee->root_id])->field('id,name')->select();
- View::assign('label', $label);
- View::assign('root_id', request()->employee->root_id);
- return View::fetch();
- }
- $param = request()->only(['building_id', 'name', 'type', 'img', 'vr', 'content', 'video', 'cover','vr_group_ids'=>'', 'label_id']);
- $param['root_id'] = request()->employee->root_id;
- if (!empty($param['vr'])) {
- $vr = explode(',', $param['vr']);
- foreach ($vr as $k => $v) {
- if (!empty($v)) {
- $vr[$k] = $this->vrlink_set($v);
- }
- }
- $param['vr'] = implode(',', $vr);
- }
- if (!empty($param['video'])) {
- $param['img'] = !empty($param['cover']) ? $param['cover'] : '';
- }
- $result = BuildingProgress::create($param);
- if ($result) {
- BuildingModel::where('id', '=', $param['building_id'])->save(['update_time' => date('Y-m-d H:i:s')]);
- return json(['code' => 0, 'msg' => '添加成功']);
- } else {
- return json(['code' => 1, 'msg' => '添加失败']);
- }
- }
- /**
- * 编辑进度
- * @return string
- */
- public function edit_progress()
- {
- $id = input('id', '', 'intval');
- if (!request()->isPost()) {
- $building_id = input('building_id', '', 'intval');
- View::assign('building_id', $building_id);
- $info = BuildingProgress::find($id);
- if ($info->vr_group_ids) {
- $group = VrGroup::where('id',$info->vr_group_ids)->field('title')->findOrEmpty();
- $info->vr_name = $group->isEmpty() ? '' : ($group->title ?: '未命名作品');
- } else {
- $info->vr_name = '';
- }
- View::assign('data', $info);
- View::assign('id', $id);
- $label = BuildingLabel::where(['root_id'=>request()->employee->root_id])->field('id,name')->select();
- View::assign('root_id', request()->employee->root_id);
- View::assign('label', $label);
- return View::fetch();
- }
- $param = request()->only(['id', 'name', 'type', 'vr', 'content', 'video', 'cover', 'covers', 'videos','vr_group_ids'=>'', 'label_id']);
- $find = BuildingProgress::find($param['id']);
- if (empty($find)) {
- return json(['code' => 1, 'msg' => '保存失败']);
- }
- $new_img = input('img', [], 'trim');
- $img_exist = input('img_exist', [], 'trim');
- $img = [];
- if (!empty($new_img) && !empty($img_exist)) {
- $img = array_merge($new_img, $img_exist);
- } elseif (!empty($new_img)) {
- $img = $new_img;
- } elseif (!empty($img_exist)) {
- $img = $img_exist;
- }
- $param['img'] = implode(',', $img);
- if (!empty($param['vr'])) {
- $vr = explode(',', $param['vr']);
- foreach ($vr as $k => $v) {
- if (!empty($v)) {
- $vr[$k] = $this->vrlink_set($v);
- }
- }
- $param['vr'] = implode(',', $vr);
- }
- if (!empty($param['video']) && $param['type'] == 'video') {
- $param['covers'] = !empty($param['covers']) ? $param['covers'] : '';
- $param['img'] = !empty($param['cover']) ? $param['cover'] : $param['covers'];
- }
- $result = $find->save($param);
- if ($result !== false) {
- BuildingModel::where('id', '=', $find['building_id'])->save(['update_time' => date('Y-m-d H:i:s')]);
- return json(['code' => 0, 'msg' => '保存成功']);
- } else {
- return json(['code' => 1, 'msg' => '保存失败']);
- }
- }
- /**
- * 删除进度
- */
- public function delete_progress()
- {
- $id = input('id', '', 'intval');
- $info = BuildingProgress::find($id);
- if ($info['root_id'] != request()->employee->root_id) {
- return json(['code' => 1, 'msg' => '删除失败']);
- }
- $result = $info->delete();
- if ($result !== false) {
- return json(['code' => 0, 'msg' => '删除成功']);
- } else {
- return json(['code' => 1, 'msg' => '删除失败']);
- }
- }
- /**
- * 关联案例
- * @return string
- */
- public function material_case()
- {
- if (!request()->isAjax()) {
- $housetype_id = input('housetype_id', '', 'intval');
- View::assign('housetype_id', $housetype_id);
- return View::fetch();
- }
- $param = request()->only([
- 'housetype_id' => 0,
- 'type' => '',
- 'title' => '',
- 'square_start' => '',
- 'square_end' => '',
- 'page' => 1,
- 'limit' => 10
- ]);
- $where[] = ['root_id', '=', request()->employee->root_id];
- if ($param['title']) {
- $where[] = ['title', 'like', '%' . $param['title'] . '%'];
- }
- if ($param['square_start'] && $param['square_end']) {
- $where[] = ['square', 'between', [$param['square_start'], $param['square_end']]];
- } elseif ($param['square_start']) {
- $where[] = ['square', '>', $param['square_start']];
- } elseif ($param['square_end']) {
- $where[] = ['square', '<', $param['square_end']];
- }
- // 此户型关联案例
- if (!empty($param['type'])) {
- $material_case_id = BuildingMaterialCase::where('housetype_id', '=', $param['housetype_id'])->column('material_case_id');
- $where[] = ['id', 'in', $material_case_id];
- $list = MaterialCase::where($where)->select()->each(function ($item) {
- $item->selected = 1;
- });
- $count = MaterialCase::where([['id', 'in', $material_case_id]])->count();
- return json(['code' => 0, 'data' => $list->toArray(), 'count' => $count]);
- }
- $list = MaterialCase::where($where)->select()->each(function ($item) use ($param) {
- $item->selected = false;
- $bind = BuildingMaterialCase::where([['housetype_id', '=', $param['housetype_id']], ['material_case_id', '=', $item['id']]])->find();
- if (!empty($bind)) {
- $item->selected = true;
- }
- });
- $count = MaterialCase::where($where)->count();
- return json(['code' => 0, 'data' => $list->toArray(), 'count' => $count]);
- }
- /**
- * 案例绑定解绑
- */
- public function change_material_case()
- {
- $housetype_id = input('housetype_id', '', 'intval');
- $material_case_id = input('material_case_id', '', 'trim');
- $material_case_id_list = explode(',', $material_case_id);
- $old_ids = BuildingMaterialCase::where([['housetype_id', '=', $housetype_id]])->column('material_case_id');
- $del_ids = array_diff($old_ids, $material_case_id_list);
- $new_ids = array_filter(array_diff($material_case_id_list, $old_ids));
- if (!empty($del_ids)) {
- BuildingMaterialCase::where([['housetype_id', '=', $housetype_id], ['root_id', '=', request()->employee->root_id], ['material_case_id', 'in', $del_ids]])->delete();
- }
- if (!empty($new_ids)) {
- $new_data = [];
- $building_id = BuildingHousetype::where('id', $housetype_id)->value('building_id');
- foreach ($new_ids as $k => $v) {
- $new_data[] = [
- 'building_id' => $building_id,
- 'housetype_id' => $housetype_id,
- 'material_case_id' => $v,
- 'root_id' => request()->employee->root_id
- ];
- }
- (new BuildingMaterialCase)->saveAll($new_data);
- }
- return json(['code' => 0, 'msg' => '操作成功']);
- }
- /**
- * 催更记录
- * @return string
- */
- public function urge_index()
- {
- if (!request()->isAjax()) {
- return View::fetch();
- }
- $param = request()->only(['page' => 1, 'limit' => 10]);
- $where[] = ['root_id', '=', request()->employee->root_id];
- $list = BuildingUrge::where($where)->with(['building', 'user', 'employee'])->page($param['page'], $param['limit'])->order('addtime desc')->select();
- $count = BuildingUrge::where($where)->count();
- return json(['code' => 0, 'data' => $list->toArray(), 'count' => $count]);
- }
- /**
- * 在施工地
- */
- public function construction()
- {
- //$building_id = input('building_id', '', 'intval');
- $housetype_id = input('housetype_id', '', 'intval');
- if (!request()->isAjax()) {
- View::assign('housetype_id', $housetype_id);
- $root_id = request()->employee['root_id'];
- $step_list = ConstructionStep::where('root_id', '=', $root_id)->order('order asc')->select();
- View::assign('step_list', $step_list);
- return View::fetch();
- }
- $root_id = request()->employee['root_id'];
- //$construction_ids = BuildingConstruction::where([['building_id', '=', $building_id], ['root_id', '=', $root_id]])->column('construction_id');
- $construction_str = BuildingHousetype::where([['id', '=', $housetype_id], ['root_id', '=', $root_id]])->value('constructionid');
- $construction_ids = !empty($construction_str) ? explode(',',$construction_str) : [];
- $where[] = ['root_id', '=', $root_id];
- $list = ConstructionModel::with(['style', 'designer', 'housetype', 'community', 'employee'])->where($where)->order('id desc')->select()->each(function ($item) use ($construction_ids) {
- $new_step = ConstructionStep::hasWhere('record', [['construction_id', '=', $item->id]])->order('order desc')->findOrEmpty();
- if (!$new_step->isEmpty()) {
- $item->step_name = $new_step->name;
- } else {
- $item->step_name = '';
- }
- if (in_array($item['id'], $construction_ids)) {
- $item->selected = 1;
- } else {
- $item->selected = 0;
- }
- });
- return json(['code' => 0, 'data' => $list->toArray(), 'count' => $list->count()]);
- }
- /**
- * 关联在施工地
- */
- public function change_construction()
- {
- //$building_id = input('building_id', '', 'intval');
- $housetype_id = input('housetype_id', '', 'intval');
- if (!request()->isAjax()) {
- View::assign('housetype_id', $housetype_id);
- return View::fetch();
- }
- $construction_id = input('construction_id', '', 'trim');
- //$construction_id_list = explode(',', $construction_id);
- $housetype_data = BuildingHousetype::find($housetype_id);
- if(empty($housetype_data)) return json(['code' => 1, 'msg' => '数据不存在']);
- $housetype_data->constructionid = $construction_id;
- $housetype_data->save();
- return json(['code' => 0, 'msg' => '操作成功']);
- }
- /*
- * 小区管理
- */
- function community()
- {
- return View::fetch();
- }
- //部门人员树
- public function tree($data, $pid = 0, $persons)
- {
- $new_arr = [];
- foreach ($data as $k => $v) {
- if ($v['pid'] == $pid) {
- $persions = isset($persons[$v['id']]) ? $persons[$v['id']] : [];
- $children = $this->tree($data, $v['id'], $persons);
- $v['children'] = array_merge_recursive($children, $persions);
- if (empty($v['children'])) $v['disabled'] = true;
- $new_arr[] = $v;
- }
- }
- return $new_arr;
- }
- /**
- * 指派人员
- * @param $id
- * @return \think\response\Json
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function get_person($id)
- {
- $ids = input('id', '');
- $root_id = request()->employee->root_id;
- $keyword = input('keyword', '');
- //所有员工
- $w1[] = ['root_id', '=', $root_id];
- $w1[] = ['state', '=', '在职'];
- $w1[] = ['org_id', '>', 0];
- $w1[] = ['uid', '>', 0];
- if ($keyword) {
- $w1[] = ['name', 'like', '%' . $keyword . '%'];
- }
- $employee = Employee::where($w1)->field('id,name title,org_id,is_manager')->order('is_manager desc,id desc')->select()->toArray();
- if ($ids) {
- $ids = explode(',', $ids);
- foreach ($employee as $k => &$v) {
- $v['selected'] = in_array($v['id'], $ids);
- $v['children'] = [];
- $v['title'] = $v['is_manager'] ? $v['title'] . '(负责人)' : $v['title'];
- $v['org_class'] = 'org_' . $v['org_id'];
- $v['per_class'] = 'per_' . $v['id'];
- $v['type'] = 'per';
- }
- } else {
- foreach ($employee as $k => &$v) {
- $v['selected'] = false;
- $v['children'] = [];
- $v['all_count'] = 0;
- $v['title'] = $v['is_manager'] ? $v['title'] . '(负责人)' : $v['title'];
- $v['org_class'] = 'org_' . $v['org_id'];
- $v['per_class'] = 'per_' . $v['id'];
- $v['type'] = 'per';
- }
- }
- $persons = [];
- foreach ($employee as $k => $v1) {
- $persons[$v1['org_id']][] = $v1;
- }
- $where = [
- ['path', 'like', $root_id . '-%'],
- ['status', '=', 1]
- ];
- $count = Employee::where([['root_id', '=', $root_id], ['state', '=', '在职'], ['uid', '>', 0]])->group('org_id')->column('count(*) count', 'org_id');
- $allnodes = Org::where($where)->field('id,pid,name title,level,org_type,info,path')->order('level asc, id asc')->select()->toarray();
- foreach ($allnodes as $k => $v) {
- $allnodes[$k]['count'] = isset($count[$v['id']]) ? $count[$v['id']] : 0; //本部门人数
- $allnodes[$k]['all_count'] = 0; //包含子部门总数
- $allnodes[$k]['org_class'] = 'org_' . $v['id'];
- $allnodes[$k]['per_class'] = 'per_org_' . $v['id'];
- $allnodes[$k]['type'] = 'org';
- foreach ($allnodes as $k2 => $v2) {
- if (strpos($v2['path'], $v['path']) !== false) {
- $allnodes[$k]['all_count'] = isset($count[$v2['id']]) ? $count[$v2['id']] + $allnodes[$k]['all_count'] : $allnodes[$k]['all_count'];
- }
- }
- $allnodes[$k]['title'] = $allnodes[$k]['title'] . ' (' . $allnodes[$k]['all_count'] . ')';
- }
- $tree = $this->tree($allnodes, 0, $persons);
- if (empty($id)) {
- $info = BuildingSpecialEmp::where(['root_id' => request()->employee->root_id])->value('assign_employee');
- } else {
- $info = BuildingModel::where(['root_id' => request()->employee->root_id, 'id' => $id])->value('assign_employee');
- }
- return json(['code' => 0, 'data' => $tree, 'checkOrg' => $info]);
- }
- public function building_assigns()
- {
- if (!request()->isAjax()) {
- $id = input('id', '', 'intval');
- View::assign('id', $id);
- $assign_employee = BuildingModel::where(['root_id' => request()->employee->root_id, 'id' => $id])->value('assign_employee');
- $count = $assign_employee ? count(explode(',', $assign_employee)) : 0;
- view::assign('count', $count);
- return View::fetch();
- }
- $id = input('id', '', 'intval');
- $pid = input('pid', '', 'trim'); //多选框选中id
- $type = input('type', '', 'trim'); //选中类型,人/部门
- $res = input('res', '', 'trim'); //选择结果 1选中,0取消
- $data = [];
- $assign_employee = BuildingModel::where(['root_id' => request()->employee->root_id, 'id' => $id])->value('assign_employee');
- $a = 0;
- if ($type == 'per' && $pid) {
- $data[] = 'per_' . $pid;
- $pid = [$pid];
- $a = 1;
- } elseif ($type == 'org' && $pid) {
- $data[] = 'org_' . $pid;
- $org = Org::where([['id', '=', $pid]])->value('path');
- $orgs = Org::where([['path', 'like', $org . '%']])->column('id');
- $pid = Employee::where([['root_id', '=', request()->employee->root_id], ['org_id', 'in', $orgs], ['state', '=', '在职'], ['uid', '>', 0]])->order('is_manager desc,id desc')->column('id');
- $a = 1;
- foreach ($pid as $v) {
- $data[] = 'per_' . $v;
- }
- foreach ($orgs as $v2) {
- $data[] = 'org_' . $v2;
- }
- }
- $assign_employee = explode(',', $assign_employee);
- if ($a) {
- $arr = array_filter(array_diff($assign_employee, $pid));
- $arr = $res ? array_merge($pid, $arr) : $arr;
- $arr = array_unique($arr);
- //过滤运营人员,旧bug导致选择根部门时,运营人员也会在内
- $arr = Employee::where([['id', 'in', $arr], ['uid', '>', 0], ['state', '=', '在职']])->column('id');
- //查询指派人的组织
- $employee_org = Employee::where('id', 'in', $arr)->group('org_id')->column('org_id');
- $employee_org = implode(',', $employee_org);
- BuildingModel::where(['root_id' => request()->employee->root_id, 'id' => $id])->update(['assign_org_id' => $employee_org, 'assign_employee' => implode(',', $arr)]);
- }
- return json(['code' => 0, 'data' => $data]);
- }
- /*
- * 指派展示列表
- */
- public function building_assigns_list()
- {
- $id = input('id', '', 'intval');
- $page = input('page', 1, 'intval');
- $limit = input('limit', 10, 'intval');
- $keyword = input('keyword', '', 'trim');
- if ($keyword) {
- $w[] = ['name', 'like', '%' . $keyword . '%'];
- }
- $arr = BuildingModel::where(['root_id' => request()->employee->root_id, 'id' => $id])->value('assign_employee');
- $arr = $arr ? explode(',', $arr) : [];
- $w[] = ['id', 'in', $arr];
- $w[] = ['state', '=', '在职'];
- $w[] = ['uid', '>', 0];
- $data = Employee::with('orgName')->where($w)->visible(['name', 'org_name', 'id', 'is_manager'])->select()->toArray();
- $count = count($data);
- $arr = array_flip($arr);
- foreach ($data as $k => $v) {
- $data[$k]['order'] = $arr[$v['id']];
- }
- array_multisort($data, SORT_ASC, array_column($data, 'order'));
- foreach ($data as $k => $v) {
- $data[$k]['xh'] = $k + 1;
- }
- $data = array_slice($data, ($page - 1) * $limit, $limit);
- return json(['code' => 0, 'data' => $data, 'count' => $count]);
- }
- /**
- * 删除指派
- * @return \think\response\Json
- */
- public function del_assign()
- {
- $id = input('id', '', 'intval');
- $eid = input('eid', '', 'intval');
- if ($id && $eid) {
- if ($eid == -1) {
- BuildingModel::where(['root_id' => request()->employee->root_id, 'id' => $id])->update(['assign_employee' => '', 'assign_org_id'=> '']);
- } else {
- $arr = BuildingModel::where(['root_id' => request()->employee->root_id, 'id' => $id])->value('assign_employee');
- $arr = array_filter(array_diff(explode(',', $arr), [$eid]));
- $data = [];
- if (empty($arr)){
- $data['assign_employee'] = '';
- $data['assign_org_id'] = '';
- } else {
- $data['assign_employee'] = implode(',', $arr);
- $assign_org_id = Employee::where('id', 'in', $arr)->group('org_id')->column('org_id');
- $data['assign_org_id'] = implode(',', $assign_org_id);
- }
- BuildingModel::where(['root_id' => request()->employee->root_id, 'id' => $id])->update($data);
- }
- }
- return json(['code' => 0, 'data' => '取消成功', 'msg' => '取消成功']);
- }
- //展示已设置可见人
- public function building_special_assigns()
- {
- if (!request()->isAjax()) {
- // $id = input('id', '', 'intval');
- // View::assign('id', $id);
- $assign_employee = BuildingSpecialEmp::where(['root_id' => request()->employee->root_id])->value('assign_employee');
- $count = $assign_employee ? count(explode(',', $assign_employee)) : 0;
- view::assign('count', $count);
- return View::fetch();
- }
- $id = input('id', '', 'intval');
- $pid = input('pid', '', 'trim'); //多选框选中id
- $type = input('type', '', 'trim'); //选中类型,人/部门
- $res = input('res', '', 'trim'); //选择结果 1选中,0取消
- $data = [];
- $assign_employee = BuildingSpecialEmp::where(['root_id' => request()->employee->root_id])->value('assign_employee');
- $a = 0;
- if ($type == 'per' && $pid) {
- $data[] = 'per_' . $pid;
- $pid = [$pid];
- $a = 1;
- } elseif ($type == 'org' && $pid) {
- $data[] = 'org_' . $pid;
- $org = Org::where([['id', '=', $pid]])->value('path');
- $orgs = Org::where([['path', 'like', $org . '%']])->column('id');
- $pid = Employee::where([['root_id', '=', request()->employee->root_id], ['org_id', 'in', $orgs], ['state', '=', '在职'], ['uid', '>', 0]])->order('is_manager desc,id desc')->column('id');
- $a = 1;
- foreach ($pid as $v) {
- $data[] = 'per_' . $v;
- }
- foreach ($orgs as $v2) {
- $data[] = 'org_' . $v2;
- }
- }
- $assign_employee = explode(',', $assign_employee);
- if ($a) {
- $arr = array_filter(array_diff($assign_employee, $pid));
- $arr = $res ? array_merge($pid, $arr) : $arr;
- $arr = array_unique($arr);
- //过滤运营人员,旧bug导致选择根部门时,运营人员也会在内
- $arr = Employee::where([['id', 'in', $arr], ['uid', '>', 0], ['state', '=', '在职']])->column('id');
- //查询指派人的组织
- $employee_org = Employee::where('id', 'in', $arr)->group('org_id')->column('org_id');
- $employee_org = implode(',', $employee_org);
- $you = BuildingSpecialEmp::where('root_id', request()->employee->root_id)->find();
- if (empty($you)) {
- $add = ['root_id' => request()->employee->root_id, 'assign_org_id' => $employee_org, 'assign_employee' => implode(',', $arr)];
- BuildingSpecialEmp::insert($add);
- } else {
- BuildingSpecialEmp::where(['root_id' => request()->employee->root_id])->update(['assign_org_id' => $employee_org, 'assign_employee' => implode(',', $arr)]);
- }
- }
- return json(['code' => 0, 'data' => $data]);
- }
- /*
- * 可见人展示列表
- */
- public function building_special_list()
- {
- $page = input('page', 1, 'intval');
- $limit = input('limit', 10, 'intval');
- $keyword = input('keyword', '', 'trim');
- if ($keyword) {
- $w[] = ['name', 'like', '%' . $keyword . '%'];
- }
- $arr = BuildingSpecialEmp::where(['root_id' => request()->employee->root_id])->value('assign_employee');
- $arr = $arr ? explode(',', $arr) : [];
- $w[] = ['id', 'in', $arr];
- $w[] = ['state', '=', '在职'];
- $w[] = ['uid', '>', 0];
- $data = Employee::with('orgName')->where($w)->visible(['name', 'org_name', 'id', 'is_manager'])->select()->toArray();
- $count = count($data);
- $arr = array_flip($arr);
- foreach ($data as $k => $v) {
- $data[$k]['order'] = $arr[$v['id']];
- }
- array_multisort($data, SORT_ASC, array_column($data, 'order'));
- foreach ($data as $k => $v) {
- $data[$k]['xh'] = $k + 1;
- }
- $data = array_slice($data, ($page - 1) * $limit, $limit);
- return json(['code' => 0, 'data' => $data, 'count' => $count]);
- }
- /**
- * 删除指派
- * @return \think\response\Json
- */
- public function del_special_emp()
- {
- $eid = input('eid', '', 'intval');
- if ($eid) {
- if ($eid == -1) {
- BuildingSpecialEmp::where(['root_id' => request()->employee->root_id])->update(['assign_employee' => '']);
- } else {
- $arr = BuildingSpecialEmp::where(['root_id' => request()->employee->root_id])->value('assign_employee');
- $arr = array_filter(array_diff(explode(',', $arr), [$eid]));
- BuildingSpecialEmp::where(['root_id' => request()->employee->root_id])->update(['assign_employee' => implode(',', $arr)]);
- }
- }
- return json(['code' => 0, 'data' => '取消成功', 'msg' => '取消成功']);
- }
- //已设置的可见人列表
- public function special_emplist()
- {
- $arr = BuildingSpecialEmp::where(['root_id' => request()->employee->root_id])->value('assign_employee');
- $arr = $arr ? explode(',', $arr) : [];
- $w[] = ['id', 'in', $arr];
- $w[] = ['state', '=', '在职'];
- $w[] = ['uid', '>', 0];
- $data = Employee::where($w)->visible(['name', 'id'])->select()->toArray();
- return json(['code' => 0, 'data' => $data, 'msg' => '获取成功']);
- }
- /**
- * 研发案例
- */
- public function dev_case()
- {
- $param = request()->only(['housetype_id', '']);
- View::assign('housetype_id', $param['housetype_id']);
- return View::fetch();
- }
- public function list_dev_case()
- {
- $param = request()->only(['housetype_id']);
- $where[] = ['root_id', '=', request()->employee->root_id];
- $where[] = ['housetype_id', '=', $param['housetype_id']];
- $list = BuildingDevelopCase::with(['decostyles'])->where($where)->order('addtime desc')->select();
- $count = BuildingDevelopCase::where($where)->count();
- return json(['code' => 0, 'data' => $list, 'count' => $count, 'msg' => '获取成功']);
- }
- /**
- * 添加研发案例
- */
- public function add_dev_case()
- {
- //$housetype_id=input('housetype_id');
- $param = request()->only(['name', 'type', 'vr_link', 'content', 'decostyles_id', 'housetype_id', 'cover']);
- if (!request()->isPost()) {
- $condition = [['root_id', '=', request()->employee->root_id]];
- $decostyles = Decostyle::where($condition)->where([['type', '=', 0]])->select()->toArray();
- View::assign('decostyles', $decostyles);
- View::assign('housetype_id', $param['housetype_id']);
- return View::fetch();
- }
- if ($param['type'] == 2 && empty($param['cover'])) return json(['code' => 1, 'msg' => '图文类型的封面图不能为空']);
- $building_id = BuildingHousetype::where('id', $param['housetype_id'])->value('building_id');
- $param['building_id'] = $building_id;
- $param['root_id'] = request()->employee->root_id;
- if (!empty($param['vr_link'])) {
- $param['vr_link'] = $this->vrlink_set($param['vr_link']);
- }
- $result = BuildingDevelopCase::create($param);
- if ($result) {
- return json(['code' => 0, 'msg' => '添加成功']);
- } else {
- return json(['code' => 1, 'msg' => '添加失败']);
- }
- }
- //编辑户型研发案例
- public function edit_dev_case()
- {
- $param = request()->only(['id', 'name', 'type', 'vr_link', 'content', 'decostyles_id', 'housetype_id', 'cover', 'img_content']);
- if (!request()->isPost()) {
- $condition = [['root_id', '=', request()->employee->root_id]];
- $decostyles = Decostyle::where($condition)->where([['type', '=', 0]])->select()->toArray();
- View::assign('decostyles', $decostyles);
- $data = BuildingDevelopCase::where('id', $param['id'])->find();
- View::assign('data', $data);
- return View::fetch();
- }
- //if ($param['type'] == 2 && empty($param['cover'])) return json(['code' => 1, 'msg' => '图文类型的封面图不能为空']);
- if (!empty($param['vr_link'])) {
- $param['vr_link'] = $this->vrlink_set($param['vr_link']);
- }
- if (!empty($param['img_content'])) {
- $list = json_decode($param['img_content'], true);
- foreach ($list as $key => $val) {
- $list[$key]['img'] = str_replace('https://' . config('app.ali_oss_bindurl') . '/', '', $val['img']);
- }
- $param['img_content'] = json_encode($list);
- }
- $result = BuildingDevelopCase::where('id', $param['id'])->save($param);
- if ($result) {
- return json(['code' => 0, 'msg' => '修改成功']);
- } else {
- return json(['code' => 1, 'msg' => '修改失败']);
- }
- }
- //户型研发案例列表
- public function develop_case_list()
- {
- $param = request()->only(['id', 'name', 'type', 'vr_link', 'content', 'building_id', 'housetype_id']);
- $where[] = ['root_id', '=', request()->employee->root_id];
- $where[] = ['housetype_id', '=', $param['id']];
- $list = BuildingDevelopCase::where($where)->select();
- $count = BuildingDevelopCase::where($where)->count();
- return json(['code' => 0, 'data' => $list, 'count' => $count, 'msg' => '获取成功']);
- }
- //删除户型研发案例
- public function del_dev_case()
- {
- $id = input('id');
- if (empty($id)) return json(['code' => 1, 'msg' => '参数错误']);
- $ms = BuildingDevelopCase::where('id', $id)->delete();
- if ($ms) {
- return json(['code' => 0, 'msg' => '删除成功']);
- } else {
- return json(['code' => 1, '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 analysis(){
- $root_id = request()->employee->root_id;
- if (!request()->isAjax()){
- // 部门
- $org = OrgLogic::struc($root_id);
- View::assign('org', $org);
- $building = BuildingModel::where([['root_id', '=', $root_id], ['del', '=', 0]])->order('addtime desc')->field('id,community_id,name,assign_employee,employee_id,from')->select()->toArray();
- $have_id = [];
- foreach ($building as $k => $v){
- if (!in_array($v['community_id'], $have_id)){
- $have_id[] = $v['community_id'];
- } else {
- unset($building[$k]);
- }
- // 指派部门更新,防止有人员切换部门
- $data = [];
- if (empty($v['assign_employee'])){
- $data['assign_org_id'] = '';
- } else {
- $assign_org_id = Employee::where('id', 'in', $v['assign_employee'])->group('org_id')->column('org_id');
- $data['assign_org_id'] = implode(',', $assign_org_id);
- }
- if ($v['from'] == 1){
- $data['org_id'] = Employee::where('id', '=', $v['employee_id'])->value('org_id');
- }
- BuildingModel::where('id', '=', $v['id'])->save($data);
- }
- $building = array_values($building);
- View::assign('building', $building);
- return View::fetch();
- } else {
- $param = request()->only(['org'=> '', 'community_id'=> '', 'vr'=> '', 'time'=> '']);
- $where[] = ['root_id', '=', $root_id];
- $where[] = ['del', '=', 0];
- if ($param['community_id']){
- $where[] = ['community_id', '=', $param['community_id']];
- }
- if ($param['vr']) {
- if ($param['vr'] == '有'){
- $where[] = ['vr_link', '<>', ''];
- } elseif($param['vr'] == '无'){
- $where[] = ['vr_link', '=', ''];
- }
- }
- if ($param['org']){
- $list_o = BuildingModel::where($where)->field('id,assign_org_id')->select()->toArray();
- $child_org = orgSubIds($param['org']);
- $ids = [];
- foreach ($list_o as $k => $v){
- if (!empty($v['assign_org_id'])){
- $assign_org_id = array_filter(explode(',', $v['assign_org_id']));
- foreach ($assign_org_id as $a_o){
- if (in_array($a_o, $child_org)){
- $ids[] = $v['id'];
- continue;
- }
- }
- }
- }
- $where[] = ['id', 'in', $ids];
- }
- $list = BuildingModel::with(['materialCase','housetype'])->where($where)->order('addtime desc')->select()->toArray();
- foreach ($list as $k => $v){
- $mater_case_view = $construction_view = 0;
- $progress_list = BuildingProgress::where('building_id', '=', $v['id'])->order('addtime desc')->select();
- $list[$k]['progress_count'] = $progress_list->count();
- $list[$k]['last_update_time'] = '';
- if (!empty($progress_list)){
- foreach ($progress_list as $k_p => $p){
- if (!empty($p['addtime']) && $k_p == 0){
- $list[$k]['last_update_time'] = $p['addtime'];
- }
- }
- }
- if(!empty($v['materialCase'])){
- $mater_case_view = MaterialCase::where([['root_id','=',$root_id],['id','in',array_column($v['materialCase'],'material_case_id')]])->sum('view_times');
- }
- if(!empty($v['housetype'])){
- $all_constrids = [];
- foreach($v['housetype'] as $p=>$m){
- if(!empty($m['constructionid'])) $all_constrids = array_merge($all_constrids,explode(',',$m['constructionid']));
- }
- $construction_view = ConstructionModel::where([['root_id','=',$root_id],['id','in',array_unique($all_constrids)]])->sum('view_times');
- }
- $list[$k]['mater_case_view'] = $mater_case_view;
- $list[$k]['construction_view'] = $construction_view;
- $list[$k]['visit_due_time'] = FootprintsModel::where([['pipe_type','=','building'],['pipe_id','=',$v['id']]])->sum('visit_due_time');
- }
- if ($param['time']){
- $time = explode(' - ', $param['time']);
- $start_time = isset($time[0]) ? $time[0] . ' 00:00:00' : '';
- $end_time = isset($time[1]) ? $time[1] . ' 23:59:59' : '';
- $new_list = [];
- foreach ($list as $k => $v){
- if (($v['last_update_time'] > $start_time) && $v['last_update_time'] < $end_time) {
- $new_list[] = $v;
- }
- }
- $list = $new_list;
- }
- $housetype_all = 0; // 总户型数
- $housetype_vr_all = 0; // vr户型数
- $building_vr_all = 0; //小区vr
- $develop_all = 0; //研发案例
- $housetype_develop_all = 0; //有研发案例户型数
- $max_org_count = 0;
- foreach ($list as $k => $v) {
- $housetype = BuildingHousetype::where('building_id', '=', $v['id'])->select();
- $list[$k]['housetype_count'] = $housetype->count();
- $housetype_all += $housetype->count();
- $housetype_vr_count = 0;
- foreach ($housetype as $h){
- if ($h['vr_link']){
- $housetype_vr_count ++;
- }
- }
- $housetype_vr_all += $housetype_vr_count;
- $list[$k]['housetype_vr_count'] = $housetype_vr_count;
- $list[$k]['housetype_vr_percent'] = $list[$k]['housetype_count'] > 0 ? round($housetype_vr_count*100/$list[$k]['housetype_count'],2) : 0;
- $develop = BuildingDevelopCase::where('building_id', '=', $v['id'])->select();
- $list[$k]['develop_count'] = $develop->count();
- $develop_all += $develop->count();
- $housetype_develop = 0; //有研发案例的户型
- $housetype_have = [];
- foreach ($housetype as $h){
- foreach ($develop as $d){
- if ($d['housetype_id'] == $h['id'] && !in_array($h['id'], $housetype_have)){
- $housetype_have[] = $h['id'];
- $housetype_develop ++;
- }
- }
- }
- $housetype_develop_all += $housetype_develop;
- $list[$k]['develop_percent'] = $list[$k]['housetype_count'] > 0 ? round($housetype_develop*100/$list[$k]['housetype_count'],2) : 0;
- // 部门
- $assign_org = array_filter(explode(',', $v['assign_org_id']));
- $org_list = [];
- if (!empty($assign_org)) {
- foreach ($assign_org as $k_a => $v_a){
- $v_a_info = Org::find($v_a);
- if (!empty($v_a_info)){
- $org_list_one['id'] = $v_a;
- $org_list_one['name'] = $v_a_info['name'];
- $org_list_one['path'] = $v_a_info['path'];
- $parents = array_reverse(array_filter(explode('-', $v_a_info['path'])));
- $parents_length = 0;
- foreach ($parents as $k_p => $v_p){
- if ($v_p != $v_a) { //不是基层部门
- $org_p = Org::find($v_p);
- if (!empty($org_p) && $org_p['pid'] != 0){
- $parents_length ++;
- }
- }
- }
- $org_list[] = $org_list_one;
- if ($parents_length > $max_org_count){
- $max_org_count = $parents_length;
- }
- }
- // 基层部门判断
- /*$child = Org::where([['pid', '=', $v_a]])->findOrEmpty();
- if (!$child->isEmpty()) {
- $base = true; //判断此部门下是否有指派的子部门,如果没有则作为基层部门
- $v_child_org = orgSubIds($param['org']);
- foreach ($v_child_org as $k_c => $v_c){
- if ($v_c != $v_a){
- if (in_array($v_c, $assign_org)){
- $base = false;
- }
- }
- }
- if ($base) {
- $v_a_info = Org::find($v_a);
- $org_list_one['id'] = $v_a;
- $org_list_one['name'] = $v_a_info['name'];
- $org_list_one['path'] = $v_a_info['path'];
- $parents = array_reverse(array_filter(explode('-', $v_a_info['path'])));
- $parents_length = 0;
- foreach ($parents as $k_p => $v_p){
- if ($v_p != $v_a) { //不是基层部门
- $org_p = Org::find($v_p);
- if (!empty($org_p) && $org_p['pid'] != 0){
- $parents_length ++;
- }
- }
- }
- $org_list[] = $org_list_one;
- if ($parents_length > $max_org_count){
- $max_org_count = $parents_length;
- }
- }
- }
- if ($child->isEmpty()){
- $v_a_info = Org::find($v_a);
- if (!empty($v_a_info)){
- $org_list_one['id'] = $v_a;
- $org_list_one['name'] = $v_a_info['name'];
- $org_list_one['path'] = $v_a_info['path'];
- $parents = array_reverse(array_filter(explode('-', $v_a_info['path'])));
- $parents_length = 0;
- foreach ($parents as $k_p => $v_p){
- if ($v_p != $v_a) { //不是基层部门
- $org_p = Org::find($v_p);
- if (!empty($org_p) && $org_p['pid'] != 0){
- $parents_length ++;
- }
- }
- }
- $org_list[] = $org_list_one;
- if ($parents_length > $max_org_count){
- $max_org_count = $parents_length;
- }
- }
- }*/
- }
- } else {
- if ($v['from'] == 1){
- // 如果是手机端上传,没有指派的话,默认当前部门为指派部门且为基层部门
- $base_org = Org::find($v['org_id']);
- $org_list_one['id'] = $v['org_id'];
- $org_list_one['name'] = $base_org['name'];
- $org_list_one['path'] = $base_org['path'];
- $parents = array_reverse(array_filter(explode('-', $base_org['path'])));
- $parents_length = 0;
- foreach ($parents as $k_p => $v_p){
- if ($v_p != $v['org_id']) { //不是基层部门
- $org_p = Org::find($v_p);
- if (!empty($org_p) && $org_p['pid'] != 0){
- $parents_length ++;
- }
- }
- }
- $org_list[] = $org_list_one;
- if ($parents_length > $max_org_count){
- $max_org_count = $parents_length;
- }
- }
- }
- $list[$k]['assign_org'] = $org_list;
- // vr数量
- if (!empty($v['vr_link'])){
- $building_vr_all ++;
- }
- }
- // 父部门处理
- foreach ($list as $k => $v) {
- /*$assign_org = array_filter(explode(',', $v['assign_org_id']));
- $assign_org_select = Org::where('id', 'in', $assign_org)->select()->toArray();
- $assign_org_list = [];
- foreach($assign_org as $o_v){
- foreach($assign_org_select as $v_s){
- if ($o_v == $v_s['id']) {
- $assign_org_list[] = $v_s;
- }
- }
- }*/
- $parents_org = [];
- for ($i = 0; $i < $max_org_count; $i++){
- foreach ($v['assign_org'] as $k_a => $v_a){
- $parents = array_filter(explode('-', $v_a['path']));
- if (!empty($parents)) {
- unset($parents[0]);
- $parents = array_values($parents);
- }
- foreach($parents as $k_p => $v_p){
- if ($v_p == $v_a['id']) {
- unset($parents[$k_p]);
- }
- }
- $parents = array_values($parents);
- if (isset($parents[$i])){
- $org_p = Org::find($parents[$i]);
- if (!empty($org_p) && $org_p['pid'] != 0){
- $parents_org[$i][] = $org_p['name'];
- } else {
- $parents_org[$i][] = '无';
- }
- } else {
- $parents_org[$i][] = '无';
- }
- }
- }
- $list[$k]['parents_org'] = array_reverse($parents_org);
- }
- //楼盘数量
- $building_count = count($list);
- //户型vr完整度
- //$housetype_vr_percent = $housetype_all > 0 ? ceil($housetype_vr_all*100/$housetype_all) : 0;
- $housetype_vr_percent = $housetype_all > 0 ? round($housetype_vr_all*100/$housetype_all,2) : 0;
- //研发案例完整度
- $housetype_develop_percent = $housetype_all > 0 ? round($housetype_develop_all*100/$housetype_all,2) : 0;
- $data['building_count'] = $building_count;
- $data['vr_count'] = $building_vr_all;
- $data['housetype_count'] = $housetype_all;
- $data['housetype_vr_percent'] = $housetype_vr_percent;
- $data['develop_all'] = $develop_all;
- $data['housetype_deveolp_percent'] = $housetype_develop_percent;
- $data['org_length'] = $max_org_count;
- $data['list'] = $list;
-
- return json(['code'=> 0, 'data'=> $data, 'msg'=> '请求成功']);
- }
- }
- /**
- * 已发布的vr作品
- */
- public function Group()
- {
- $id = input('id',0);
- if (!request()->isAjax()) {
-
- View::assign('id', $id);
- return View::fetch();
- }
- $page = input('page',1);
- $limit = input('limit',10);
- $keyword = input('keyword','');
- $where = [['root_id','=',request()->employee->root_id],['status','=',2]];
- if($keyword) $where[] = ['title','like','%'.$keyword.'%'];
- $res = VrGroup::where($where)->order('id desc')->field("id,title name,sid")->page((int)$page,(int)$limit)->select()->toArray();
- $host = config('app.vr_show_domain');
- foreach ($res as $key => $val) {
- $res[$key]['name'] = $val['name'] ?: '未命名作品';
- $res[$key]['show_url'] = $host.$val['sid'];
- //选中默认值
- $res[$key]['LAY_CHECKED'] = ($id == $val['id'] || $id==$val['sid']) ? true : false;
- }
- $count = VrGroup::where($where)->order('id desc')->field("id,title name")->count();
- return json(['code' => 0, 'msg' => '保存成功', 'data' => $res,'count'=>$count]);
- }
- }
|