withCount(['share_log' => function ($query) { $query->where([['type', '=', 'Building']]); }]); $root_id = $this->request->token['root_org']; $where[] = ['root_id', '=', $root_id]; $where[] = ['del', '=', 0]; $name = input('name', '', 'trim'); if ($name) { $condition = [ ['root_id', '=', $root_id], ['type', '=', 0], ['name', 'like', '%' . $name . '%'] ]; $community_id = Community::where($condition)->column('id'); /** * 查询楼盘地址是否有匹配 */ $whereor1[] = ['community_id', 'in', $community_id]; $whereor1[] = ['address','like','%'.$name.'%']; $adrids = BuildingModel::where($where)->where(function($query) use ($whereor1){ $query->whereOr($whereor1); })->column('id'); $where[] = ['id','in',$adrids]; //$where[] = ['community_id', 'in', $community_id]; } $page = input('page', 1, 'intval'); $employee_id = $this->request->token['employee_id']; //查询设置可见人信息 $special=BuildingSpecialEmp::where('root_id',$this->request->token['root_org'])->value('assign_employee'); $assign_employee = !empty($special)? explode(',', $special):[]; if(in_array($employee_id,$assign_employee)){ $data = $model->where($where); }else{ $data = $model->where($where)->where(function ($query) use ($employee_id){ $query->whereRaw("FIND_IN_SET(" . $employee_id . " , assign_employee)") ->whereOr('assign_employee', '=', NULL) ->whereOr('assign_employee', '=', ''); })->where(function ($query) use ($employee_id) { $query->whereRaw("`from` = 0 or (`from` =1 and `org_id` =" . $this->request->token['org_id'] . ") or ( `from` = 1 and (FIND_IN_SET(" . $employee_id . " , assign_employee)))"); }); } $list=$data->page($page, 10)->order($order)->select()->each(function ($item) { $area_list = BuildingHousetype::where('building_id', '=', $item['id'])->order('area asc')->column('area'); $item->area_list = array_values(array_unique(array_filter($area_list))); $collectedIds = UserCollect::where(['user_id' => $this->request->token['uid'], 'content_type' => 'building'])->column('content_id'); if (in_array($item['id'], $collectedIds)) { $item['collected'] = true; } else { $item['collected'] = false; } })->toArray(); return json(['code' => self::success, 'data' => $list]); } /** * 详情 */ public function view() { $id = input('id', '', 'intval'); $info = BuildingModel::find($id); if (empty($info)) { return json(['code' => self::error_msg, 'msg' => '数据不存在']); } $area_list = BuildingHousetype::where('building_id', '=', $id)->order('area asc')->column('area'); $info['area_list'] = array_values(array_unique(array_filter($area_list))); $company = Company::where('root_id', '=', $info['root_id'])->field(['company_name', 'logo'])->find(); $info['company_name'] = $company['company_name']; $info['company_logo'] = $company['logo']; //小区户型 $housetype = BuildingHousetype::with(['devcase'=>function($query){ $query->field('housetype_id,id,name,type,vr_link,content,cover,decostyles_id'); }])->where('building_id', '=', $id)->withCount(['materialCase'])->select()->toArray(); //vr作品处理 $show_url = config('app.vr_show_domain'); foreach ($housetype as $key => $value) { $sid = VrGroup::where('id',$value['vr_group_ids'])->value('sid'); $housetype[$key]['vr_link'] = $sid ? $show_url.$sid : ''; } $xin = []; $vrObj = new Vr(); if(!empty($housetype)){ $houselist=$housetype; foreach($houselist as $key=>$val){ if(empty($val['house_img']) && !empty($val['vr_link'])){ $houselist[$key]['house_img'][] = $vrObj->getFirstImg($val['vr_link']); } if(empty($val['devcase'])) continue; foreach($val['devcase'] as $k=>$v){ $houselist[$key]['devcase'][$k]['decostyles_name']=Decostyle::where('id',$v['decostyles_id'])->value('name'); $houselist[$key]['devcase'][$k]['area']=$val['area']; $houselist[$key]['devcase'][$k]['room']=$val['room']; $houselist[$key]['devcase'][$k]['hall']=$val['hall']; $houselist[$key]['devcase'][$k]['bathroom']=$val['bathroom']; if($v['type']==1){ $houselist[$key]['devcase'][$k]['cover'] = $vrObj->getFirstImg($v['vr_link']); } } } foreach($houselist as $key => $val){ @$xin[$val['room']][] = $val; } $xin[0] = $houselist; } $info['vr_link_cover']=''; if(!empty($info['vr_link'])){ $info['vr_link_cover']=$vrObj->getFirstImg($info['vr_link']); }elseif($info['vr_group_ids']){ $vrgroup = VrGroup::where('id',$info['vr_group_ids'])->field('id,pic_path,sid')->findOrEmpty(); if (!$vrgroup->isEmpty()) { $info['vr_link'] = $show_url.$vrgroup->sid; $info['vr_link_cover'] = $vrgroup->pic_path; } } $info['housetype'] = $xin; $info['housetype_count'] = count($housetype); $collectedIds = UserCollect::where(['user_id' => $this->request->token['uid'], 'content_type' => 'building','content_id'=>$info['id']])->count(); if ($collectedIds) { $info['collected'] = true; } else { $info['collected'] = false; } //增加进度图片视频VR数量查询 $prtype_list = BuildingProgress::where([['building_id', '=', $id]])->field('count(*) as count,type')->group('type')->select()->toArray(); $info['prtype_list']=!empty($prtype_list)?$prtype_list:null; return json(['code' => self::success, 'data' => $info]); } /** * 研发案例列表 */ public function dev_case_list() { $id = input('id', '', 'intval'); if (empty($id)) return json(['code' => 1, 'msg' => '参数错误']); $list= BuildingDevelopCase::with(['decostyles'])->where('housetype_id',$id) ->field('id,name,type,housetype_id,decostyles_id') ->select(); return json(['code' => self::success, 'data' => $list]); } /** * 研发案例详情 */ public function dev_case_detail() { $id = input('id', '', 'intval'); if (empty($id)) return json(['code' => 1, 'msg' => '参数错误']); $data = BuildingDevelopCase::with(['decostyles'])->where('id', $id)->find(); return json(['code' => self::success, 'data' => $data]); } /** * 楼盘进度 */ public function progress() { $token = $this->request->token; $id = input('id', '', 'intval'); $type = input('type','','trim'); $labelId = input('label_id'); $where[]=['building_id', '=', $id]; $where[]=['root_id','=',$token['root_org']]; if($labelId) $where[]=['label_id','=',$labelId]; if(!empty($type)){ $where[]=['type', '=', $type]; } $page = input('page',1); $limit = input('limit',3); $list = BuildingProgress::with(['label'=>function($query){ $query->withField(['id','name']); }])->where($where)->order('addtime desc')->page($page,$limit)->select(); if (empty($list)) $list = []; else $list = $list->toArray(); $vrObj = new Vr(); //vr作品处理 $sids = VrGroup::where([['id','in',array_column($list,'vr_group_ids')]])->column('sid','id'); $show_url = config('app.vr_show_domain'); foreach ($list as &$item) { $vrData = []; if (!empty($item['vr'])) { $vrUrlList = explode(',', $item['vr']); foreach ($vrUrlList as $url) { $vrData[] = [ 'vrUrl' => $url, 'vrfirstImg' => getFirstImg($url) ]; } }elseif (!empty($item['vr_group_ids'])) { $vrgroup = VrGroup::where('id',$item['vr_group_ids'])->field('id,pic_path,sid')->findOrEmpty(); $item['show_url'] = ''; $item['show_img'] = ''; if (!$vrgroup->isEmpty()) { $item['show_url'] = $show_url.$vrgroup->sid; $item['show_img'] = $vrgroup->pic_path; } } $item['vr'] = $vrData; } return json(['code' => self::success, 'data' => $list]); } /** * 户型关联案例 */ public function material_case() { $housetype_id = input('housetype_id',0); $token = $this->request->token; $page = input('page',1); $limit = input('limit',10); $case_ids = BuildingMaterialCase::where([['housetype_id','=',$housetype_id],['root_id','=',$token['root_org']]])->column('material_case_id'); if(empty($case_ids)) return json(['code' => 0, 'data' => [], 'msg' => '获取成功']); $where[] = ['id', 'in', $case_ids]; $list = MaterialCase::with(['designer' => function ($query) { $query->field('id,name, headimgurl,addtime'); }, 'community' => function ($query) { $query->field('id,name'); }, 'decostyle' => function ($query) { $query->field('id,name'); }])->order('recommend desc')->page($page,$limit)->where($where)->select(); $collectedIds = UserCollect::where(['user_id' => $token['uid'], 'content_type' => 'materialCase'])->column('content_id'); foreach ($list as &$item) { if (in_array($item['id'], $collectedIds)) { $item['collected'] = true; } else { $item['collected'] = false; } } $data = ['list'=> $list]; $count = MaterialCase::where($where)->count(); return json(['code' => 0, 'data' => $data,'count'=>$count, 'msg' => '获取成功']); } /** * 收藏 */ public function collect($id) { $user_id = $this->request->token['uid']; $had = UserCollect::where(['user_id' => $user_id, 'content_type' => 'building', 'content_id' => $id])->count(); if ($had > 0) return json(['code' => 1, 'msg' => '您已收藏']); UserCollect::insert(['user_id' => $user_id, 'content_type' => 'building', 'content_id' => $id]); return json(['code' => 0, 'msg' => '收藏成功']); } /** * 取消收藏 */ public function collectCancel($id) { $user_id = $this->request->token['uid']; UserCollect::where(['user_id' => $user_id, 'content_type' => 'building', 'content_id' => $id])->delete(); return json(['code' => 0, 'msg' => '取消收藏']); } public function construction(){ //$building_id = input('building_id', '', 'intval'); //$construction_id = BuildingConstruction::where('building_id', '=', $building_id)->column('construction_id'); //$where[] = ['id', 'in', $construction_id]; $housetype_id = input('housetype_id', '', 'intval'); $construction_str = BuildingHousetype::where('id',$housetype_id)->value('constructionid'); $construction_id = !empty($construction_str) ? explode(',',$construction_str) : []; $where[] = ['id', 'in', $construction_id]; $page = input('page', 1, 'intval'); $limit = input('limit', 10, 'intval'); $root_id = $this->request->token['root_org']; $where[] = ['root_id', '=', $root_id]; $community_id = input('community_id', '', 'intval'); if ($community_id) { $where[] = ['community_id', '=', $community_id]; } $step_list = ConstructionStep::where('root_id', '=', $root_id)->order('order asc')->select()->toArray(); $order_input = input('order', 'new', 'trim'); $order = 'recommend desc,update_time desc'; $model = ConstructionModel::with(['style', 'designer', 'housetype', 'community'])->withCount(['share_log'=> function ($query) { $query->where([['type', '=', 'construction']]); }]); if ($order_input == 'new'){ $order = 'recommend desc,update_time desc'; $list = $model->where($where)->page($page, $limit)->order($order)->select(); } else if ($order_input == 'hot') { $list = $model->where($where)->order($order)->select(); } $list = $list->each(function ($item) use ($step_list) { $record_list = ConstructionRecord::where([['construction_id', '=', $item['id']]])->order('update_time desc')->select(); $step_now = 0; //进行到哪一步了 foreach ($step_list as $k => $v) { foreach ($record_list as $kk => $vv) { if ($v['id'] == $vv['step_id'] && $v['order'] > $step_now) { $step_now = $v['order']; } } } foreach ($step_list as $k => $v) { $step_list[$k]['upload'] = 0; // 判断是否上传 $step_list[$k]['need_upload'] = 0; // 判断节点是否变色(已过此节点,但是没上传) $have = false; //是否有上传 true有 $need_have = false; //没上传,但是后面的节点上传了 true是 foreach ($record_list as $kk => $vv) { if ($v['id'] == $vv['step_id']) { $have = true; } } if ($have == false && $v['order'] < $step_now) { $need_have = true; } if ($have) { $step_list[$k]['upload'] = 1; } elseif ($need_have) { $step_list[$k]['need_upload'] = 1; } } $item->step_list = $step_list; //收藏状态 $user_id = $this->request->token['uid']; $had = UserCollect::where(['user_id' => $user_id , 'content_type' => 'construction' , 'content_id' => $item['id']])->count(); if ($had) { $item['collect'] = 1; } else { $item['collect'] = 0; } })->toArray(); if ($order_input == 'hot') { $list_all = $list; $share_log_count = array_column($list_all, 'share_log_count'); array_multisort($share_log_count, SORT_DESC, $list_all); $list = array_slice($list_all, $limit*($page-1), $limit); } $count = $model->where($where)->count(); return json(['code' => self::success, 'data' => $list, 'count' => $count]); } //户型研发案例详情 public function building_detail() { $id=input('id'); if(empty($id)) return json(['code'=> 1,'msg'=> '参数错误']); $data=BuildingModel::find($id); return json(['code'=> 0, 'data'=>$data,'msg'=> '获取成功']); } //手机端添加热装楼盘 public function add_building() { $param = $this->request->only(['community_name', 'address', 'duetime', 'cover', 'vr_link', 'content','sign_num','start_num','finish_num', 'cover_share_img']); if (!empty($param['community_name'])) { //新增小区 if (strlen($param['community_name']) > 45) { return json(['code' => self::error_msg, 'msg' => '楼盘名称过长']); } $condition[] = ['name', '=', $param['community_name']]; $condition[] = ['type', '=', 0]; $condition[] = ['root_id', '=', $this->request->token['root_org']]; $exitedobj = Community::where($condition)->findorEmpty(); if (!$exitedobj->isEmpty()) { $param['community_id'] = $exitedobj['id']; }else{ $pinyin = hanzi2pinyin($param['community_name']); $community_id = Community::create([ 'root_id' => $this->request->token['root_org'], 'pinyin' => $pinyin, 'name' => $param['community_name'], 'type' => 0, 'initials' => strtoupper(substr($pinyin,0,1)), 'employee_id'=> request()->token['employee_id'] ]); $param['community_id'] = $community_id->id; } } $param['duetime'] = empty($param['duetime']) ? null : $param['duetime']; $param['employee_id'] = $this->request->token['employee_id']; $param['org_id'] = $this->request->token['org_id']; $param['root_id'] = $this->request->token['root_org']; if (!empty($param['vr_link'])){ $param['vr_link'] = $this->vrlink_set($param['vr_link']); } if(!empty($param['cover'])){ $media_id = []; foreach ($param['cover'] as $k => $v) { $media_id[$k] = [ 'serverId' => !empty($v['serverId'])?$v['serverId']:'', 'img' =>!empty($v['img'])?str_replace('https://'.config('app.ali_oss_bindurl').'/', '', $v['img']):'' ]; } $param['down_status'] = 1; $param['media_id'] = json_encode($media_id); } $param['cover']=1; $param['from']=1; // $orgids = orgSubIds($this->request->token['org_id']); // $emp_data = Employee::where([['root_id', '=', $this->request->token['root_org']], ['org_id', 'in', $orgids], ['state', '=', '在职'], ['uid', '>', 0]])->order('is_manager desc,id desc')->column('id'); // $param['assign_org_id'] = implode(',', $orgids); // $param['assign_employee'] = implode(',', $emp_data); $result = BuildingModel::create($param); Console::call('download', ['building']); if ($result) { dataStatistics($this->request->token['root_org'],'building_count',1,'inc');//manage应用首页统计数据 return json(['code'=> 0, 'msg'=> '添加成功','data'=>$result->id]); } else { return json(['code'=> 1, 'msg'=> '添加失败','data'=>'']); } } //员工修改楼盘 public function edit_building() { $param = $this->request->only(['id','community_name', 'address', 'duetime', 'cover', 'vr_link', 'content','sign_num','start_num','finish_num','cover_share_img'=>'']); $data=BuildingModel::where('id',$param['id'])->find(); if (!empty($param['community_name'])) { //新增小区 if (strlen($param['community_name']) > 45) { return json(['code' => self::error_msg, 'msg' => '楼盘名称过长']); } $condition[] = ['name', '=', $param['community_name']]; $condition[] = ['type', '=', 0]; $condition[] = ['root_id', '=', $this->request->token['root_org']]; $exitedobj = Community::where($condition)->findorEmpty(); if (!$exitedobj->isEmpty()) { $param['community_id'] = $exitedobj['id']; }else{ $pinyin = hanzi2pinyin($param['community_name']); $community_id = Community::create([ 'root_id' => $this->request->token['root_org'], 'pinyin' => $pinyin, 'name' => $param['community_name'], 'type' => 0, 'initials' => strtoupper(substr($pinyin,0,1)), 'employee_id'=> request()->token['employee_id'] ]); $param['community_id'] = $community_id->id; } } if (!empty($param['vr_link'])){ $param['vr_link'] = $this->vrlink_set($param['vr_link']); } if(!empty($param['cover'])){ $media_id = []; foreach ($param['cover'] as $k => $v) { $media_id[$k] = [ 'serverId' => !empty($v['serverId'])?$v['serverId']:'', 'img' =>!empty($v['img'])?str_replace('https://'.config('app.ali_oss_bindurl').'/', '', $v['img']):'' ]; } $param['down_status'] = 1; $param['media_id'] = json_encode($media_id); } $param['duetime'] = empty($param['duetime']) ? null : $param['duetime']; $result = $data->save($param); Console::call('download', ['building']); if ($result) { return json(['code'=> 0, 'msg'=> '修改成功']); } else { return json(['code'=> 1, 'msg'=> '修改失败']); } } //楼盘列表 public function empup_building_list() { $param = Request()->only(['type'=>0,'page'=>1,'limit'=>10, 'keyword'=> '']); $token = $this->request->token; $employee_id = $token['employee_id']; $where[] = ['root_id', '=', $token['root_org']]; $where[] = ['del', '=', 0]; if ($param['keyword']){ $condition = [ ['root_id', '=', $token['root_org']], ['type', '=', 0], ['name', 'like', '%' . $param['keyword'] . '%'] ]; $community_id = Community::where($condition)->column('id'); /** * 查询楼盘地址是否有匹配 */ $whereor1[] = ['community_id', 'in', $community_id]; $whereor1[] = ['address','like','%'.$param['keyword'].'%']; $adrids = BuildingModel::where($where)->where(function($query) use ($whereor1){ $query->whereOr($whereor1); })->column('id'); $where[] = ['id','in',$adrids]; //$where[] = ['community_id', 'in', $community_id]; } if ($param['type'] == 1) { //后台上传 $where[] = ['from', '=', 0]; //查询设置可见人信息 $special = BuildingSpecialEmp::where('root_id', $token['root_org'])->value('assign_employee'); $assign_employee = !empty($special) ? array_filter(explode(',', $special)) : []; $model = BuildingModel::withCount(['housetype', 'devcase', 'construction']); if(in_array($employee_id, $assign_employee)){ $model = $model->where($where); } else { /*$sql = "(assign_employee is null or assign_employee='' or find_in_set(".$token['employee_id'].",assign_employee))"; $model = $model->where($where)->whereRaw($sql);*/ $model = $model->where($where)->where(function ($query) use ($employee_id){ $query->whereRaw("FIND_IN_SET(" . $employee_id . " , assign_employee)") ->whereOr('assign_employee', '=', NULL) ->whereOr('assign_employee', '=', ''); }); } $list = $model->page($param['page'], $param['limit'])->select()->toArray(); }else{ //手机端上传 修改后台跟手机端指派的都可以在自己上传的页面看到 $where[] = ['from', '=', 1]; $where[] = ['employee_id', '=', $employee_id]; $where1[] = ['assign_employee', 'find in set', $employee_id]; $list = BuildingModel::withCount(['housetype','devcase','construction'])->whereOr([$where,$where1])->page($param['page'],$param['limit'])->select()->toArray(); } return json(['code'=> 0, 'data'=>$list,'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 housetype_detail() { $token = $this->request->token; $id = input('id', '', 'intval'); if(empty($id)) return json(['code'=> 1,'msg'=> '参数错误']); $data = BuildingHousetype::find($id); $data['new_orientation'] = $data->getData('orientation'); $data['vr_link_img'] = ''; if (!empty($data['vr_link'])) { $vrObj = new Vr(); $data['vr_link_img'] = getFirstImg($data['vr_link']); }elseif($data['vr_group_ids']){ $show_url = config('app.vr_show_domain'); $vrgroup = VrGroup::where('id',$data['vr_group_ids'])->field('id,pic_path,sid')->findOrEmpty(); if (!$vrgroup->isEmpty()) { $data['vr_link'] = $show_url.$vrgroup->sid; $data['vr_link_img'] = $vrgroup->pic_path; } } //查询楼盘地址和小区 $build = BuildingModel::where('id',$data->building_id)->field('community_id,address')->findOrEmpty(); if (!$build->isEmpty()){ $build->community = $build->community_id ? Community::where('id',$build->community_id)->value('name') : ''; } //是否收藏 $where = [ ['root_id','=',$token['root_org']], ['employee_id','=',$token['employee_id']], ['building_id','=',$data->building_id], ['building_housetype_id','=',$id], ['type','=',1] ]; $data->is_collect = BuildingHousetypeCollect::where($where)->value('id') ? 1 : 0; return json(['code'=> 0, 'data'=> $data,'build'=>$build, 'msg'=> '获取成功']); } //添加楼盘户型 public function add_housetype() { $param = request()->only(['building_id', 'type','area', 'room', 'hall', 'bathroom','vr_link','house_img','house_count','orientation','media_id', 'house_img_media_id']); $param['root_id'] = $this->request->token['root_org']; $orientation=null; if(!empty($param['orientation'])){ foreach($param['orientation'] as $key=>$val){ $orientation.=$val.','; } $param['orientation']=trim($orientation,','); } if (!empty($param['vr_link'])){ $param['vr_link'] = $this->vrlink_set($param['vr_link']); } if(!empty($param['media_id'])){ $media_id = []; foreach ($param['media_id'] as $k => $v) { $media_id[$k] = [ 'serverId' => !empty($v['serverId'])?$v['serverId']:'', 'img' =>!empty($v['img'])?str_replace('https://'.config('app.ali_oss_bindurl').'/', '', $v['img']):'' ]; } $param['down_status'] = 1; $param['media_id'] = json_encode($media_id); } if(!empty($param['house_img_media_id'])){ $house_img_media_id = []; foreach ($param['house_img_media_id'] as $k => $v) { $house_img_media_id[$k] = [ 'serverId' => !empty($v['serverId']) ? $v['serverId'] : '', 'img' => !empty($v['img']) ? str_replace('https://'.config('app.ali_oss_bindurl').'/', '', $v['img']) : '' ]; } $param['down_status'] = 1; $param['house_img_media_id'] = json_encode($house_img_media_id); } $param['from']=1; //增加别墅户型(其室厅卫值都为9) if($param['type']==2){ $param['room']=9; $param['hall']=9; $param['bathroom']=9; } $result = BuildingHousetype::create($param); Console::call('download', ['buildinghousetype']); if ($result) { return json(['code'=> 0, 'msg'=> '添加成功','data'=>$result->id]); } else { return json(['code'=> 1, 'msg'=> '添加失败','data'=>'']); } } //修改楼盘户型 public function edit_housetype() { $param = request()->only(['id','building_id', 'type','area', 'room', 'hall', 'bathroom','vr_link','house_img','house_count','orientation','media_id', 'house_img_media_id']); $info=BuildingHousetype::where('id',$param['id'])->find(); $orientation=null; if(!empty($param['orientation'])){ foreach($param['orientation'] as $key=>$val){ $orientation.=$val.','; } $param['orientation']=trim($orientation,','); } if (!empty($param['vr_link'])){ $param['vr_link'] = $this->vrlink_set($param['vr_link']); } if(!empty($param['media_id'])){ $media_id = []; foreach ($param['media_id'] as $k => $v) { $media_id[$k] = [ 'serverId' => !empty($v['serverId'])?$v['serverId']:'', 'img' =>!empty($v['img'])?str_replace('https://'.config('app.ali_oss_bindurl').'/', '', $v['img']):'' ]; } $param['down_status'] = 1; $param['media_id'] = json_encode($media_id); } if(!empty($param['house_img_media_id'])){ $house_img_media_id = []; foreach ($param['house_img_media_id'] as $k => $v) { $house_img_media_id[$k] = [ 'serverId' => !empty($v['serverId']) ? $v['serverId'] : '', 'img' => !empty($v['img']) ? str_replace('https://'.config('app.ali_oss_bindurl').'/', '', $v['img']) : '' ]; } $param['down_status'] = 1; $param['house_img_media_id'] = json_encode($house_img_media_id); } else { $param['house_img'] = ''; } //增加别墅户型(其室厅卫值都为9) if($param['type']==2){ $param['room']=9; $param['hall']=9; $param['bathroom']=9; } $result = $info->save($param); Console::call('download', ['buildinghousetype']); if ($result) { return json(['code'=> 0, 'msg'=> '修改成功','data'=>$param['id']]); } else { return json(['code'=> 1, 'msg'=> '修改失败','data'=>'']); } } //楼盘户型列表 public function housetype_list() { $building_id = input('building_id', '', 'intval'); $list = BuildingHousetype::where('building_id', '=', $building_id)->select()->toArray(); return json(['code'=> 0, 'data'=> $list]); } //户型研发案例详情 public function devcase_detail() { $id=input('id'); if(empty($id)) return json(['code'=> 1,'msg'=> '参数错误']); $data=BuildingDevelopCase::find($id); return json(['code'=> 0, 'data'=>$data,'msg'=> '获取成功']); } //户型研发案例列表 public function devcase_list() { $id=input('id'); if(empty($id)) return json(['code'=> 1,'msg'=> '参数错误']); $list=BuildingDevelopCase::with(['decostyles','housetype'=>function($query){ $query->field('id,area,room,hall,bathroom'); }])->where('housetype_id',$id)->field('id,name,type,vr_link,building_id,housetype_id,decostyles_id,cover,from')->select(); $vrObj=new Vr; foreach($list as $key=>$val){ if($val['type']==1){ $list[$key]['cover'] = $vrObj->getFirstImg($val['vr_link']); } } return json(['code'=> 0, 'data'=>$list,'msg'=> '获取成功']); } //添加户型研发案例 public function add_devcase() { $param = request()->only([ 'name', 'type', 'vr_link', 'content','decostyles_id','housetype_id','cover']); 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']=$this->request->token['root_org']; if (!empty($param['vr_link'])){ $param['vr_link'] = $this->vrlink_set($param['vr_link']); } if(!empty($param['cover'])){ $media_id = []; foreach ($param['cover'] as $k => $v) { $media_id[$k] = [ 'serverId' => !empty($v['serverId'])?$v['serverId']:'', 'text' => !empty($v['text'])?$v['text']:'', 'img' =>!empty($v['img'])?str_replace('https://'.config('app.ali_oss_bindurl').'/', '', $v['img']):'' ]; } $param['down_status'] = 1; $param['media_id'] = json_encode($media_id); } $param['from']=1; $result = BuildingDevelopCase::create($param); if($param['type']==2){ Console::call('download', ['buildingdevcase']); } if ($result) { return json(['code'=> 0, 'msg'=> '添加成功']); } else { return json(['code'=> 1, 'msg'=> '添加失败']); } } //修改户型研发案例 public function edit_devcase() { $param = request()->only(['id','name', 'type', 'vr_link', 'content','decostyles_id','housetype_id','cover']); 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']=$this->request->token['root_org']; if (!empty($param['vr_link'])){ $param['vr_link'] = $this->vrlink_set($param['vr_link']); } if(!empty($param['cover'])){ $media_id = []; foreach ($param['cover'] as $k => $v) { $media_id[$k] = [ 'serverId' => !empty($v['serverId'])?$v['serverId']:'', 'text' => !empty($v['text'])?$v['text']:'', 'img' =>!empty($v['img'])?str_replace('https://'.config('app.ali_oss_bindurl').'/', '', $v['img']):'' ]; } $param['down_status'] = 1; $param['media_id'] = json_encode($media_id); } $result = BuildingDevelopCase::where('id',$param['id'])->update($param); if($param['type']==2){ Console::call('download', ['buildingdevcase']); } if ($result) { return json(['code'=> 0, 'msg'=> '修改成功']); } else { return json(['code'=> 1, 'msg'=> '修改失败']); } } //案例风格列表 public function decostyles_list() { $condition = [['root_id', '=', $this->request->token['root_org']]]; $decostyles = Decostyle::where($condition)->where([['type', '=', 0]])->select()->toArray(); return json(['code'=> 0, 'data'=>$decostyles,'msg'=> '获取成功']); } //楼盘进度详情 public function progress_detail() { $id=input('id'); if(empty($id)) return json(['code'=> 1,'msg'=> '参数错误']); $data=BuildingProgress::find($id); return json(['code'=> 0, 'data'=>$data,'msg'=> '获取成功']); } //添加楼盘进度 public function add_progress() { $param = request()->only(['building_id', 'name', 'type', 'img', 'vr', 'content','video','cover']); if(!empty($param['img'])){ $media_id = []; foreach ($param['img'] as $k => $v) { $media_id[$k] = [ 'serverId' => !empty($v['serverId'])?$v['serverId']:'', 'img' =>!empty($v['img'])?str_replace('https://'.config('app.ali_oss_bindurl').'/', '', $v['img']):'' ]; } $param['down_status'] = 1; $param['media_id'] = json_encode($media_id); $param['img']=1; }else{ $param['img']=''; } $param['root_id'] = $this->request->token['root_org']; 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); }else{ $param['vr']=''; } if (!empty($param['video'])){ $param['img']=!empty($param['cover'])?$param['cover']:''; } $param['from']=1; $param['content']=!empty($param['content'])?$param['content']:''; // var_dump($param); // exit; $result = BuildingProgress::create($param); if($param['type']=='img'){ Console::call('download', ['buildingprogress']); } 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'=> '添加失败']); } } //编辑楼盘进度 public function edit_progress() { $param = request()->only(['id','building_id', 'name', 'type', 'img', 'vr', 'content','video','cover']); $info=BuildingProgress::find($param['id']); if(!empty($param['img'])){ $media_id = []; foreach ($param['img'] as $k => $v) { $media_id[$k] = [ 'serverId' => !empty($v['serverId'])?$v['serverId']:'', 'img' =>!empty($v['img'])?str_replace('https://'.config('app.ali_oss_bindurl').'/', '', $v['img']):'' ]; } $param['down_status'] = 1; $param['media_id'] = json_encode($media_id); $param['img']=1; }else{ $param['img']=''; } $param['root_id'] = $this->request->token['root_org']; 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); }else{ $param['vr']=''; } if (!empty($param['video'])){ $param['img']=!empty($param['cover'])?$param['cover']:''; } $param['content']=!empty($param['content'])?$param['content']:''; $result = $info->save($param); if($param['type']=='img'){ Console::call('download', ['buildingprogress']); } 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'=> '修改失败']); } } /** * 获取部门人员 */ public function get_orgemp() { $root_id = $this->request->token['root_org']; $orgs = Org::with(['employee' => function ($query) { $query->field('e.id,e.name,user.headimgurl,e.org_id') ->alias('e') ->where([['e.state', '=', '在职']]) ->join('user', 'user.id=e.uid'); }])->where([ ['path', 'like', $root_id . '-%'] ])->order('level asc, id desc')->field('id,name,pid')->select()->toArray(); $data = []; $id = input('id', '', 'intval'); $building = BuildingModel::find($id); $assign_employee = []; if (!empty($building['assign_employee'])) { $assign_employee = array_filter(explode(',', $building['assign_employee'])); } while (!empty($orgs)) { $org = array_pop($orgs); $all_show = true; // 整个部门人员是否都是可见人员 foreach ($org['employee'] as $k => $v){ if (in_array($v['id'], $assign_employee)){ $org['employee'][$k]['show'] = 1; } else { $org['employee'][$k]['show'] = 0; $all_show = false; } } $childOrg = [ 'id' => $org['id'], 'name' => $org['name'], 'pid' => $org['pid'], 'employee' => $org['employee'], 'employee_num' => count($org['employee']) ]; if ($all_show && !empty($org['employee'])){ $childOrg['show'] = 1; } else { $childOrg['show'] = 0; } if (isset($data[$org['id']])) { $childOrg['child_org'] = $data[$org['id']]['child_org']; $childOrg['employee_num'] += $data[$org['id']]['employee_num']; unset($data[$org['id']]); } $data[$org['pid']]['child_org'][] = $childOrg; $data[$org['pid']]['employee_num'] = isset($data[$org['pid']]['employee_num']) ? $data[$org['pid']]['employee_num']+$childOrg['employee_num'] : $childOrg['employee_num']; } $data = array_pop($data); $result = [ 'employee' => isset($data['employee']) ? $data['employee'] : [], 'child_org' => isset($data['child_org']) ? $data['child_org'] : [] ]; return json(['code'=> 0, 'data'=> $result, 'msg'=> '获取成功']); } //设置指派人员 public function set_orgemp() { $id = input('id','', 'intval'); $empid = input('empid', '', 'trim'); $assign_employee = implode(',', $empid); $assign_org_id = Employee::where('id', 'in', $assign_employee)->group('org_id')->column('org_id'); $ms = BuildingModel::where('id', $id)->update(array('assign_employee'=> $assign_employee, 'assign_org_id'=> $assign_org_id)); if ($ms !== false) { return json(['code'=> 0, 'msg'=> '设置成功']); } else { return json(['code'=> 1, 'msg'=> '设置失败']); } } /** * 根据楼盘名称获取楼盘信息 * @return [type] [description] */ public function getBuildingByName(){ $name = input('name', '', 'trim'); if ($name) { $where[] = ['name', '=', $name]; $where[] = ['root_id', '=', $this->request->token['root_org']]; $community_id = Community::where($where)->value('id'); if ($community_id) { $building = BuildingModel::where('community_id', '=', $community_id)->order('id desc')->findOrEmpty(); if (!$building->isEmpty()) { return json(['code'=> 0, 'msg'=> 'success', 'data'=> $building]); } } } return json(['code'=> 0, 'msg'=> 'success', 'data'=> []]); } /** * 收藏楼盘户型 */ public function collectHousetype(){ $param = Request::only(['building_id'=>0,'building_housetype_id'=>0]); $token = $this->request->token; $where = [ ['root_id','=',$token['root_org']], ['building_id','=',$param['building_id']], ['id','=',$param['building_housetype_id']] ]; $check = BuildingHousetype::where($where)->findOrEmpty(); if($check->isEmpty()) return json(['code'=> 1, 'msg'=> '收藏失败', 'data'=> []]); $where = [ ['root_id','=',$token['root_org']], ['employee_id','=',$token['employee_id']], ['building_id','=',$param['building_id']], ['building_housetype_id','=',$param['building_housetype_id']], ['type','=',1] ]; $info = BuildingHousetypeCollect::where($where)->findOrEmpty(); if (!$info->isEmpty()) return json(['code'=> 1, 'msg'=> '已经收藏', 'data'=> []]); BuildingHousetypeCollect::insert([ 'root_id'=>$token['root_org'], 'employee_id'=>$token['employee_id'], 'building_id'=>$param['building_id'], 'building_housetype_id'=>$param['building_housetype_id'], 'type'=>1 ]); return json(['code'=> 0, 'msg'=> '收藏成功', 'data'=> []]); } /** * 取消收藏 */ public function cancelCollectHousetype(){ $param = Request::only(['building_id'=>0,'building_housetype_id'=>0]); $token = $this->request->token; $where = [ ['root_id','=',$token['root_org']], ['employee_id','=',$token['employee_id']], ['building_id','=',$param['building_id']], ['building_housetype_id','=',$param['building_housetype_id']], ['type','=',1] ]; $info = BuildingHousetypeCollect::where($where)->field('id')->findOrEmpty(); if($info->isEmpty()) return json(['code'=> 1, 'msg'=> '取消失败', 'data'=> []]); BuildingHousetypeCollect::where($where)->delete(); return json(['code'=> 0, 'msg'=> '取消成功', 'data'=> []]); } public function housetype($community_id) { $token = $this->request->token; $building_id = BuildingModel::where(['community_id'=>$community_id, 'root_id'=>$token['root_org']])->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]); } }