12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142 |
- <?php
- namespace app\api\controller;
- use app\model\Building as BuildingModel;
- use app\model\BuildingConstruction;
- use app\model\BuildingHousetype;
- use app\model\BuildingMaterialCase;
- use app\model\BuildingProgress;
- use app\model\Company;
- use app\model\Construction as ConstructionModel;
- use app\model\ConstructionRecord;
- use app\model\ConstructionStep;
- use app\model\MaterialCase;
- use app\model\Org;
- use app\model\UserCollect;
- use think\facade\Log;
- use xiaohongwu\Vr;
- use app\model\BuildingDevelopCase;
- use app\model\Decostyle;
- use think\facade\Console;
- use app\model\Community;
- use app\model\Employee;
- use app\model\BuildingSpecialEmp;
- use app\model\BuildingHousetypeCollect;
- use think\facade\Request;
- use app\model\VrGroup;
- use app\model\VrView;
- class Building extends Base
- {
- /**
- * vr楼书列表
- */
- public function index()
- {
- $order_input = input('order', 'new', 'trim');
- $order = 'update_time desc';
- if ($order_input == 'new') {
- $order = 'update_time desc';
- } elseif ($order_input == 'hot') {
- $order = 'share_log_count desc';
- }
- $model = BuildingModel::with(['share_log'])->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]);
- }
- }
|