isAjax()) { $styleList = Decostyle::where(['root_id' => request()->employee->root_id, 'type' => 0])->select(); View::assign('decostyle', $styleList); $eid = ConstructionModel::where([['root_id','=',request()->employee->root_id],['employee_id','>',0]])->group('employee_id')->column('employee_id,type'); $type0 = $type1 = []; foreach ($eid as $ks => $vs) { $vs['type']==0 ? $type0[]=$vs['employee_id'] : $type1[]=$vs['employee_id']; } // 运营人员列表 $employee = EmployeeModel::where([['id','in',$type0],['root_id', '=', request()->employee->root_id]])->field('id,opt_name,name')->select()->toArray(); foreach ($employee as $key => $val) { $employee[$key]['name'] = $val['name'] ?: ($val['opt_name'] ?: ''); } View::assign('employee', $employee); $employee1 = EmployeeModel::where([['id','in',$type1],['root_id', '=', request()->employee->root_id]])->field('id,opt_name,name')->select()->toArray(); foreach ($employee1 as $key1 => $val1) { $employee1[$key1]['name'] = $val1['name'] ?: ($val1['opt_name'] ?: ''); } View::assign('employee_mb', $employee1); $communityList = Community::where(['root_id' => request()->employee->root_id, 'type' => 0])->order('pinyin asc')->select(); if (!empty($communityList)){ $communityList= hanziheadstr($communityList); } View::assign('communityList', $communityList); //户型获取 $housetype = Housetype::where('root_id','=', request()->employee->root_id)->select()->toArray(); View::assign('housetype', $housetype); return View::fetch(); } $page = input('page', 1, 'intval'); $limit = input('limit', 10, 'intval'); $employee_id = input('employee_id'); $style_id = input('decostyle'); $community_id = input('community'); $housetype_id = input('housetype'); $addtime = input('addtime'); $root_id = request()->employee['root_id']; $where[] = ['root_id', '=', $root_id]; //2023-02-04 增加手机上传 $where[] = ['type','=',input('type',0)]; empty($employee_id)?:$where[] = ['employee_id', '=', $employee_id]; empty($style_id)?:$where[] = ['style_id', '=', $style_id]; empty($community_id)?:$where[] = ['community_id', '=', $community_id]; empty($housetype_id)?:$where[] = ['housetype_id', '=', $housetype_id]; if (!empty($addtime)) { list($start_date, $end_date) = explode(' - ', $addtime); $where[] = ['addtime', '>=', $start_date]; $where[] = ['addtime', '<', date('Y-m-d H:i:s', strtotime($end_date) + 86400)]; } $step_list = ConstructionStep::where('root_id', '=', $root_id)->order('order asc')->select()->toArray(); $list = ConstructionModel::with(['style', 'designer', 'housetype', 'community', 'employee'])->where($where)->page($page, $limit)->order('recommend desc,id desc')->select()->append(['housetype.name'])->each(function ($item) use ($step_list){ foreach ($step_list as $k => $v) { // 判断该阶段是否上传 $step_list[$k]['record_id'] = 0; $find = ConstructionRecord::where([['construction_id', '=', $item['id']], ['step_id', '=', $v['id']]])->find(); if (!empty($find)) { $step_list[$k]['record_id'] = $find['id']; } } $item->step_list = $step_list; })->toArray(); foreach ($list as $k => $v) { if(!$v['employee']){ $list[$k]['opt_name'] = ''; }else{ $list[$k]['opt_name'] = $v['employee']['name'] ?: ($v['employee']['opt_name'] ?: ''); } if(empty($v['housetype'])) $list[$k]['housetype'] = null; } $count = ConstructionModel::where($where)->count(); return json(['code'=> 0, 'data'=> $list, 'count'=> $count]); } /** * 添加 */ public function add(){ $root_id = request()->employee['root_id']; 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); //设计师获取 /*$designers = Designer::where($condition)->select()->toArray(); View::assign('designer', $designers);*/ $w[] = ['path', 'like', $root_id . '-%']; $w[] = ['org_type','=',2]; $orgs = Org::where($w)->column('id'); $w3[] = ['org_id','in',$orgs]; $w3[] = ['root_id','=', $root_id]; $w3[] = ['state','=','在职']; $designers = EmployeeModel::with(['designer'=>function($query) use ($root_id){ $query->where('root_id',$root_id)->visible(['headimgurl','employee_id','desc','good_at','position','work_years','addtime','good_house','design_concept','vcr'])->bind(['desc','good_at','position','work_years','addtime','good_house','design_concept','vcr','name','headimgurl']); }])->where($w3)->field('name title,id,show,initials s')->order('s asc')->select()->toArray(); foreach ($designers as $k => $v) { $designers[$k]['name'] = $v['name'] ?: $v['title']; unset($designers[$k]['designer']); } if (!empty($designers)) { // $designers = hanziInitsort($designers,'name'); $sort = array_column($designers,'s'); sort($sort); array_multisort($sort, SORT_ASC, $designers); $sort = array_unique($sort); $designers = ['sort' => $sort, 'arr' => $designers]; } View::assign('designer', $designers); //风格获取 $decostyles = Decostyle::where($condition)->where([['type', '=', 0]])->select()->toArray(); View::assign('style', $decostyles); //户型获取 $housetype = Housetype::where($condition)->select()->toArray(); View::assign('housetype', $housetype); return View::fetch(); } else { $param = request()->only(['name', 'area', 'cover'=> '', 'start_time', 'style_id', 'designer_id', 'community_id', 'housetype_id', 'recommend', 'cover_share_img', 'housetype_type'=>'']); $param['recommend'] = (isset($param['recommend']) && $param['recommend'] == 'on') ? 1 : 0; $param['root_id'] = $root_id; $param['del'] = 0; $param['employee_id'] = request()->employee->id; $param['step_id'] = 0; $result = ConstructionModel::create($param); if ($result) { dataStatistics($root_id,'plant_count',1,'inc');//manage应用首页统计数据 return json(['code'=> 0, 'msg'=> '添加成功']); } else { return json(['code'=> 1, 'msg'=> '添加失败']); } } } /** * 编辑 */ public function edit(){ $id = input('id', '', 'intval'); $root_id = request()->employee['root_id']; 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); //设计师获取 /*$designers = Designer::where($condition)->select()->toArray(); View::assign('designer', $designers);*/ $w[] = ['path', 'like', $root_id . '-%']; $w[] = ['org_type','=',2]; $orgs = Org::where($w)->column('id'); $w3[] = ['org_id','in',$orgs]; $w3[] = ['root_id','=', $root_id]; $w3[] = ['state','=','在职']; $designers = EmployeeModel::with(['designer'=>function($query) use ($root_id){ $query->where('root_id',$root_id)->visible(['headimgurl','employee_id','desc','good_at','position','work_years','addtime','good_house','design_concept','vcr'])->bind(['desc','good_at','position','work_years','addtime','good_house','design_concept','vcr','name','headimgurl']); }])->where($w3)->field('name title,id,show,initials s')->order('s asc')->select()->toArray(); foreach ($designers as $k => $v) { $designers[$k]['name'] = $v['name'] ?: $v['title']; unset($designers[$k]['designer']); } if (!empty($designers)) { // $designers = hanziInitsort($designers,'name'); $sort = array_column($designers,'s'); sort($sort); array_multisort($sort, SORT_ASC, $designers); $sort = array_unique($sort); $designers = ['sort' => $sort, 'arr' => $designers]; } View::assign('designer', $designers); //风格获取 $decostyles = Decostyle::where($condition)->where([['type', '=', 0]])->select()->toArray(); View::assign('style', $decostyles); //户型获取 $housetype = Housetype::where($condition)->select()->toArray(); View::assign('housetype', $housetype); $data = ConstructionModel::with(['style', 'designer', 'housetype', 'community'])->find($id); View::assign('data', $data); View::assign('id', $id); return View::fetch(); } else { $param = request()->only(['id', 'name', 'area', 'cover', 'start_time', 'style_id', 'designer_id', 'community_id', 'housetype_id', 'recommend', 'cover_share_img', 'housetype_type'=>'housetype']); $param['recommend'] = (isset($param['recommend']) && $param['recommend'] == 'on') ? 1 : 0; $construction = ConstructionModel::where(['root_id'=>$root_id, 'id'=>$param['id']])->find(); $construction->save($param); return json(['code'=> 0, 'msg'=> '保存成功']); } } /** * 删除 */ public function delete(){ $id = input('id', '', 'intval'); $root_id = request()->employee['root_id']; $where = [ ['id','=',$id], ['root_id','=',$root_id] ]; $find = ConstructionModel::where($where)->findOrEmpty(); if($find->isEmpty()) return json(['code'=> 1, 'msg'=> '操作异常,请刷新后重试']); $find->delete(); ConstructionRecord::where([['construction_id','=',$id]])->delete(); dataStatistics($root_id,'plant_count',1,'dec');//manage应用首页统计数据 return json(['code'=> 0, 'msg'=> '删除成功']); } /** * 审核 */ public function approve(){ $id = input('id', '', 'intval'); $root_id = request()->employee['root_id']; $status = input('status',''); $remark = input('remark',''); if(!in_array($status,[1,2])) return json(['code'=> 1, 'msg'=> '审核失败']); $find = ConstructionModel::where([['id', '=', $id],['root_id','=',$root_id]])->findOrEmpty(); if($find->isEmpty()) return json(['code'=> 1, 'msg'=> '审核失败']); $find->status = $status; $find->save(); //审核后发送通知消息核公众号消息 $remark = $remark ? ',原因是:'.$remark : ''; $msg = $status==1 ? '您提交的在施工地“'.$find->name.'”'.'已审核通过,请及时查看。' : '您提交的在施工地“'.$find->name.'”'.'审核不通过'.$remark.'请及时查看。'; event(new Msg($find->employee_id,$msg, 'constructionApprove')); if($status==1) dataStatistics($root_id,'plant_count',1,'inc');//manage应用首页统计数据 return json(['code'=> 0, 'data'=> '审核完成','msg'=> '审核完成']); } /** * 调整案例状态 */ public function change_status(){ $id = input('id', '', 'intval'); $root_id = request()->employee['root_id']; $find = ConstructionModel::find($id); if (empty($find)) { return json(['code'=> 1, 'msg'=> '操作失败']); } if ($find['root_id'] != $root_id) { return json(['code'=> 1, 'msg'=> '操作异常,请刷新后重试']); } if (intval($find['del']) == 0) { $find->del = 1; } elseif (intval($find['del']) == 1) { $find->del = 0; } $result = $find->save(); if ($result !== false) { return json(['code'=> 0, 'msg'=> '操作成功']); } else { return json(['code'=> 1, 'msg'=> '操作失败']); } } /** * 设置施工阶段 */ public function step_setting(){ $root_id = request()->employee['root_id']; if (!request()->isPost()) { return View::fetch(); } $form = input('form'); if (!empty($form)) { $form_setting = json_decode($form, true); $setting = ConstructionStep::where('root_id', '=', $root_id)->order('order asc')->select()->toArray(); $ids = array_column($setting, 'id'); if (!empty($form_setting)) { $form_ids = array_column($form_setting, 'id'); $diff = array_diff($ids, $form_ids); if (!empty($diff)) { $record = ConstructionRecord::where([['step_id', 'in', $diff], ['root_id', '=', $root_id]])->select()->toArray(); if (!empty($record)) { return json(['code'=> 1, 'msg'=> '被删除的节点已有节点数据,无法删除']); } else { ConstructionStep::where([['id', 'in', $diff]])->delete(); } } } if (!empty($form_setting)) { foreach ($form_setting as $k => $v) { if ($v['id']) { ConstructionStep::where('id', '=', $v['id'])->save(['name'=> $v['name'], 'order'=> $v['order']]); } else { ConstructionStep::create(['name'=> $v['name'], 'order'=> $v['order'], 'root_id'=> $root_id]); } } } return json(['code'=> 0, 'msg'=> '操作成功']); } } public function step_list(){ $root_id = request()->employee['root_id']; $step_list = ConstructionStep::where('root_id', '=', $root_id)->order('order asc')->select(); return json(['code'=> 0, 'msg'=> '操作成功','step_list' => $step_list]); } /** * 上传施工进度 */ public function update_step(){ $id = input('id', '', 'intval'); $steps_id = input('steps_id', 0, 'intval'); $construction_id = input('construction_id', '', 'intval'); if (!request()->isPost()) { $info['id'] = 0; $info['construction_id'] = $construction_id; $info['step_id'] = $steps_id; $info['img'] = []; $info['video'] = ''; $info['video_cover'] = ''; $info['vr'] = []; $info['content'] = ''; $info['type'] = ''; $info['group_name'] = ''; $info['vr_group_ids'] = ''; if ($id) { $info = ConstructionRecord::find($id); $info->group_name = $info->vr_group_ids ? (VrGroup::where('id',$info->vr_group_ids)->value('title') ?: '未命名作品') : '未命名作品'; $construction_id = $info['construction_id']; } elseif($steps_id && $construction_id) { $f_info = ConstructionRecord::where([['step_id', '=', $steps_id], ['construction_id', '=', $construction_id]])->findOrEmpty(); if (!$f_info->isEmpty()){ $info = $f_info; $id = $f_info['id']; } } if (!empty($info['vr'])){ $info['vr'] = explode(',', $info['vr']); } $root_id = request()->employee['root_id']; $step = ConstructionStep::where('root_id', '=', $root_id)->order('order asc')->select(); View::assign('id', $id); View::assign('construction_id', $construction_id); View::assign('step', $step); View::assign('data', $info); View::assign('steps_id', $steps_id); $url = config('app.ali_oss_bindurl'); View::assign('url','https://'.$url.'/'); return View::fetch(); } if ($id) { // 编辑 $find = ConstructionRecord::find($id); $image = input('img', [], 'trim'); $image_exist = input('image_exist', [], 'trim'); $step_id = input('step_id', '', 'intval'); $data_vr = input('vr', '', 'trim'); $video = input('video', '', 'trim'); $video_cover = input('video_cover', '', 'trim'); $type = input('type', '', 'trim'); if (!empty($data_vr) && $type == 'vr') { $vr = explode(',', $data_vr); foreach ($vr as $k => $v) { if (!empty($v)){ $vr[$k] = $this->vrlink_set($v); } } $find->vr = implode(',', $vr); } else { $find->vr = ''; } if ($type == 'img'){ $img = implode(',', array_merge($image, $image_exist)); $find->img = $img; } else { $find->img = ''; } if ($type == 'video'){ $find->video = $video; $find->video_cover = $video_cover; } else { $find->video = ''; $find->video_cover = ''; } $find->type = $type; $find->step_id = $step_id; $find->content = input('content', '', 'trim'); $find->update_time = date('Y-m-d H:i:s', time()); $find->vr_group_ids = input('vr_group_ids',''); if ($step_id != $find['step_id']) { $type_find = ConstructionRecord::where([['construction_id', '=', $find['construction_id']], ['step_id', '=', $step_id]])->find(); if (!empty($type_find)){ return json(['code'=> 1, 'msg'=> '该阶段已上传']); } } $result = $find->save(); } else { //添加 $data = request()->only(['img', 'step_id', 'content', 'vr', 'video', 'video_cover', 'type','vr_group_ids'=>'']); $data['construction_id'] = $construction_id; if (!empty($data['img']) && $data['type'] == 'img') { $data['img'] = implode(',', $data['img']); } if (!empty($data['vr']) && $data['type'] == 'vr') { $vr = explode(',', $data['vr']); foreach ($vr as $k => $v) { if (!empty($v)){ $vr[$k] = $this->vrlink_set($v); } } $data['vr'] = implode(',', $vr); } else { $data['vr'] = ''; } if ($data['type'] != 'video') { $data['video'] = ''; $data['video_cover'] = ''; } $data['employee_id'] = request()->employee['id']; $data['root_id'] = request()->employee['root_id']; $data['update_time'] = date('Y-m-d H:i:s', time()); $type_find = ConstructionRecord::where([['construction_id', '=', $construction_id], ['step_id', '=', $data['step_id']]])->find(); if (!empty($type_find)){ return json(['code'=> 1, 'msg'=> '该阶段已上传']); } $result = ConstructionRecord::create($data); } if ($result) { ConstructionModel::where('id', '=', $construction_id)->save(['update_time'=> date('Y-m-d H:i:s', time())]); return json(['code'=> 0, 'msg'=> '保存成功']); } else { return json(['code'=> 1, 'msg'=> '保存失败']); } } //vr链接设置修改 public function vrlink_set($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 fileupload() { $ali_oss_bindurl = config('app.ali_oss_bindurl'); $url = 'https://' . $ali_oss_bindurl . '/' . Request::param('file'); return json(['code' => 0, 'data' => ['src' => $url]]); } }