request->token['root_org']; $where[] = ['root_id', '=', $root_id]; $type = input('type',1) ? 1 : 0; $where[] = ['type','=',$type]; if($type == 1) $where[] = ['employee_id','=',$this->request->token['employee_id']]; $status = input('status',''); if($status !== '') $where[] = ['status','=',$status]; $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, id 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 communitylist() { $communityArr = Community::where(['root_id' => request()->token['root_org']])->where([['type', '=', 0]])->field('id,name,pinyin,case_num')->order('pinyin asc')->select()->each(function ($item){ $item['construction_count'] = ConstructionModel::where('community_id', '=', $item['id'])->count(); })->toArray(); return json(['code' => 0, 'data' => $communityArr, 'msg' => '获取成功']); } /** * 小区,风格,户型,设计师下拉列表 */ public function selectList() { $token = request()->token; $condition[] = ['root_id','=',$token['root_org']]; //小区 $data['communities'] = Community::where($condition)->where([['type', '=', 0]])->order('pinyin asc')->column('id,name'); //风格 $data['decostyles'] = Decostyle::where($condition)->where([['type', '=', 0]])->column('id,name'); //户型获取 $data['housetype'] = Housetype::where($condition)->column('id,name'); //设计师 $root_id = $token['root_org']; $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','=','在职']; $w3[] = ['uid','>',0]; $data['designers'] = EmployeeModel::where($w3)->column('id,name'); //施工阶段 $data['step'] = ConstructionStep::where('root_id', '=', $root_id)->order('order asc')->select(); return json(['code' => 0, 'data' => $data, 'msg' => '获取成功']); } /** * 获取施工阶段 */ public function getConstructionStage() { $param = Request::only(['construction_id'=>0]); $token = request()->token; $where = [ ['root_id','=',$token['root_org']], ['construction_id','=',$param['construction_id']] ]; $list = ConstructionRecord::with(['step'=>function($query){ $query->bind(['name','order','update_date'=>'addtime']); }])->where($where)->select()->toArray(); $vrObj = new Vr(); foreach ($list as $k => $v) { $list[$k]['update_date'] = date('Y-m-d',strtotime($v['update_date'])); $list[$k]['vr'] = []; if ($v['vr'] && $v['type']=='vr'){ $arr = explode(',',$v['vr']); foreach ($arr as $k2 => $v2) { $vr = []; $vr['vr_url'] = $v2; $vr['vr_img'] = $vrObj->getFirstImg($v2); $list[$k]['vr'][] = $vr; } } } return json(['code' => 0, 'data' => $list, 'msg' => '获取成功']); } public function view() { $id = input('id', '', 'intval'); if (empty($id)) { return json(['code' => self::error_msg, 'msg' => '获取失败']); } $info = ConstructionModel::with(['style', 'designer', 'housetype', 'community'])->find($id); $root_id = $this->request->token['root_org']; $step_list = ConstructionStep::where('root_id', '=', $root_id)->order('order asc')->select()->toArray(); $record_list = ConstructionRecord::where([['construction_id', '=', $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']; } } } $vrObj = new Vr(); foreach ($step_list as $k => $v) { $step_list[$k]['upload'] = 0; // 判断是否上传 $step_list[$k]['need_upload'] = 0; // 判断节点是否变色(已过此节点,但是没上传) $have = false; //是否有上传 true有 $need_have = false; //没上传,但是后面的节点上传了 true是 $step_list[$k]['data'] = []; foreach ($record_list as $kk => $vv) { if ($v['id'] == $vv['step_id']) { $have = true; if (!empty($vv['vr']) && $vv['type'] == 'vr') { $vrUrlList = explode(',', $vv['vr']); $vrData = []; foreach ($vrUrlList as $url) { $vrData[] = [ 'vrUrl' => $url, 'vrfirstImg' => $vrObj->getFirstImg($url) ]; } $vv['vr'] = $vrData; } $step_list[$k]['data'] = $vv; } } 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; } } $info['step_list'] = $step_list; //收藏状态 $user_id = $this->request->token['uid']; $had = UserCollect::where(['user_id' => $user_id , 'content_type' => 'construction' , 'content_id' => $id])->count(); if ($had) { $info['collect'] = 1; } else { $info['collect'] = 0; } $info['housetype']['name'] = $info->housetype->name; return json(['code'=> self::success, 'msg'=> '请求成功', 'data'=> $info]); } /** * 收藏 */ public function collect($id) { $user_id = $this->request->token['uid']; $had = UserCollect::where(['user_id' => $user_id , 'content_type' => 'construction' , 'content_id' => $id])->count(); if ($had > 0) return json(['code' => 1, 'msg' => '您已收藏']); UserCollect::insert(['user_id' => $user_id , 'content_type' => 'construction' , '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' => 'construction' , 'content_id' => $id])->delete(); return json(['code' => 0, 'msg' => '取消收藏']); } /** * 添加 */ public function add(){ $param = request()->only(['name', 'area', 'cover'=> '', 'start_time', 'style_id', 'designer_id', 'community_id', 'housetype_id', 'cover_share_img', 'housetype_type'=>'housetype']); $token = $this->request->token; $param['root_id'] = $token['root_org']; $param['del'] = 0; $param['employee_id'] = $token['employee_id']; $param['step_id'] = 0; $param['type'] = 1; $param['status'] = 0; $result = ConstructionModel::create($param); if ($result) { return json(['code'=> 0, 'msg'=> '添加成功','data'=>$result->id]); } else { return json(['code'=> 1, 'msg'=> '添加失败']); } } /** * 编辑 */ public function edit(){ $param = request()->only(['id', 'name', 'area', 'cover', 'start_time', 'style_id', 'designer_id', 'community_id', 'housetype_id', 'cover_share_img', 'housetype_type'=>'housetype']); $token = $this->request->token; $find = ConstructionModel::where([['id', '=', $param['id']],['root_id','=',$token['root_org']]])->findOrEmpty(); if($find->isEmpty()) return json(['code'=> 1, 'msg'=> '保存失败']); unset($param['id']); foreach ($param as $k => $v) { $find->$k = $v; } if($find->status != 1) $find->status = 0; $find->save(); return json(['code'=> 0, 'msg'=> '保存成功']); // $result = ConstructionModel::where('id', '=', $param['id'])->save($param); // if ($result) { // return json(['code'=> 0, 'msg'=> '保存成功']); // } else { // return json(['code'=> 1, 'msg'=> '保存失败']); // } } /** * 删除 */ public function delete(){ $id = input('id', '', 'intval'); $root_id = request()->token['root_org']; $find = ConstructionModel::find($id); if (empty($find)) { return json(['code'=> 0, 'msg'=> '删除成功']); } if ($find['root_id'] != $root_id) { return json(['code'=> 1, 'msg'=> '操作异常,请刷新后重试']); } $result = $find->delete(); if ($result !== false) { return json(['code'=> 0, 'msg'=> '删除成功']); } else { return json(['code'=> 1, 'msg'=> '删除失败']); } } /** * 更新施工进度 */ public function update_step(){ $id = input('id', '', 'intval'); $construction_id = input('construction_id', '', 'intval'); $step_id = input('step_id', '', 'intval'); $step = ConstructionStep::where('id',$step_id)->findOrEmpty(); if($step->isEmpty()) return json(['code'=> 1, 'msg'=> '施工阶段已删除,请重新选择']); if ($id) { // 编辑 $find = ConstructionRecord::find($id); $data_vr = input('vr', '', 'trim'); $video = input('video', '', 'trim'); $video_cover = input('video_cover', '', 'trim'); $type = input('type', '', 'trim'); $media_id = input('media_id', '', 'trim'); $img = input('img','','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'){ $find->img = $img; if ($media_id) { $find->media_id = $media_id; $find->down_status = 1; } // $data['down_status'] = 1; // $data['media_id'] = $media_id; } 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()); 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(); Console::call('download', ['construction_record']); } else { //添加 $data = request()->only(['img', 'step_id', 'content', 'vr', 'video', 'video_cover', 'type', 'media_id'=> '']); $data['construction_id'] = $construction_id; if (!empty($data['media_id']) && $data['type'] == 'img') { $data['down_status'] = 1; } 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()->token['employee_id']; $data['root_id'] = request()->token['root_org']; $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); Console::call('download', ['construction_record']); } if ($result) { //编辑进度后如果在施工地为审核不通过状态,则改为待审核状态 ConstructionModel::where([['id','=',$construction_id],['status','=',2]])->update(['status'=>0]); 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链接设置修改 * @param $vr_link * @return string|string[] */ 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; } }