modular = ['introduce' => '公司简介', 'pattern' => '模式优势', 'boutique' => '精品设计', 'science' => '材料', 'major' => '大牌软装', 'customized' => '定制家具', 'realistic' => '实景样板房', 'praise' => '口碑及服务', 'platinum' => '铂金工程']; $param = Request::only(['token' => '']); $value = ''; if ($param['token']) { $aec = new Aec(config('app.aec_key'), config('app.aec_iv')); $value = $aec->decrypt($param['token']); } if(!$value){ json(['code'=>1,'msg'=>'参数错误'])->send(); exit; } $value = explode('#',$value); $this->root_id = $value[0]; $this->employee_id = $value[1]; $this->customer_id = $value[2]; } /** * 面板 */ public function index() { //9个模块 $modular = array_keys($this->modular); $where = [ ['root_id', '=', $this->root_id], ['code', 'in', $modular] ]; $res = SmartScreen::where($where)->column('*', 'code'); $ali_oss_bindurl = config('app.ali_oss_bindurl'); foreach ($res as $k2 => $v2) { $res[$k2]['background_img'] = $v2['background_img'] ? 'https://' . $ali_oss_bindurl . '/' . $v2['background_img'] : ''; $res[$k2]['lcon_img'] = $v2['lcon_img'] ? 'https://' . $ali_oss_bindurl . '/' . $v2['lcon_img'] : ''; } $diff = array_diff($modular, array_keys($res)); $row = []; foreach ($diff as $v) { $row[$v] = [ 'title' => $this->modular[$v], 'code' => $v, 'background_img' => '', 'lcon_img' => '' ]; } $row = array_merge($res, $row); //排序后的数据 $where = [ ['name', '=', 'wisdomMenuOrder'], ['root_id', '=', $this->root_id] ]; $ids = Setting::where($where)->value('content'); $order = Permission::where([['uri','like','%smartScreen/content?type=%']])->order('sort asc,id asc')->column('uri,id'); if ($ids) { $ids = array_flip(explode(',',$ids)); foreach ($order as $key => $value) { $order[$key]['order'] = $ids[$value['id']]; } array_multisort(array_column($order,'order'),SORT_ASC, $order); } $order = array_column($order,'uri'); $res = []; foreach ($order as $v2) { foreach ($row as $v3) { if(strpos($v2,$v3['code']) !== false){ $res[$v3['code']] = $v3; break; } } } //前端跳需要转参数 $url = SmartScreen::changeState('url'); foreach ($res as $k4 => $v4) { $field = $url[$k4]; $res[$k4] = array_merge($v4,$field); } //录音开关 $where = [ ['name', '=', 'recordingSwitch'], ['root_id', '=', $this->root_id] ]; $info = Setting::where($where)->findOrEmpty(); $switch = (!$info->isEmpty() && $info->content) ? 1 : 0; //公司名称 $company_name = Company::where('root_id',$this->root_id)->value('company_name'); $bind = $this->customer_id ? 1 : 0; //设计师编辑方案管理判断 $empdata = Employee::with(['org'])->where([['root_id', '=', $this->root_id], ['id', '=', $this->employee_id]])->field('id,org_id')->find(); $is_designer = !empty($empdata['org']['org_type']) && $empdata['org']['org_type'] == 2 ? 1 : 0; $designer_edit = $is_designer ? 1 : 0; $plandata = ['background_img' => '', 'code' => 'plandata', 'lcon_img' => '', 'logo' => 'icon-fanganguanli_mian', 'title' => '方案资料', 'url' => '/index/programme', 'sort' => 2]; $res['plandata'] = $plandata; return json(['code' => 0, 'data' => $res, 'designer_edit' => $designer_edit, 'switch' => $switch, 'company_name' => $company_name, 'bind' => $bind]); } /** * 获取一级分类 */ public function getCate1() { $param = Request::only(['type'=>'']); $where = [ ['root_id','=',$this->root_id], ['level','=',1], ['pid','=',0], ['del','=',0], ['code','=',$param['type']] ]; $res = SmartScreenCate::where($where)->select()->toArray(); return json(['code'=> 0, 'data'=> $res]); } /** * 获取二级分类 */ public function getCate2() { $param = Request::only(['type'=>'','pid'=>0]); $where = [ ['root_id','=',$this->root_id], ['level','=',2], ['pid','=',$param['pid']], ['del','=',0], ['code','=',$param['type']] ]; $cate2 = SmartScreenCate::where($where)->select()->toArray(); $where = [ ['root_id','=',$this->root_id], ['level','=',3], ['pid','in',array_column($cate2,'id')], ['del','=',0], ['code','=',$param['type']] ]; $cate3 = SmartScreenCate::where($where)->select()->toArray(); foreach ($cate2 as $k2 => $v2) { $cate2[$k2]['child'] = []; foreach ($cate3 as $k3 => $v3) { if ($v2['id']==$v3['pid']) { $cate2[$k2]['child'][] = $v3; } } } return json(['code'=> 0, 'data'=> $cate2]); } /** * 获取内容 */ public function getData() { $param = Request::only(['cate1'=>0,'cate2'=>0,'cate3'=>'','page'=>1,'limit'=>10,'community_id'=>0,'decostyle_id'=>0,'housetype_id'=>0]); $where[] = ['cate1','=',$param['cate1']]; $where[] = ['del','=',0]; $where[] = ['root_id','=',$this->root_id]; if ($param['cate2']) $where[] = ['cate2','=',$param['cate2']]; if ($param['cate3']){ $ids = explode(',',$param['cate3']); $where[] = ['cate3','in',$ids]; } if($param['community_id']) $where[] = ['community_id','=',$param['community_id']]; if($param['decostyle_id']) $where[] = ['decostyle_id','=',$param['decostyle_id']]; if($param['housetype_id']) $where[] = ['housetype_id','=',$param['housetype_id']]; $list = SmartScreenData::with(['designer'=>function($query){ $query->field('id,name')->bind(['designer_name'=>'name']); },'community'=>function($query){ $query->field('id,title')->bind(['community_name'=>'title']); },'decostyle'=>function($query){ $query->field('id,title')->bind(['decostyle_name'=>'title']); },'housetype'=>function($query){ $query->field('id,title')->bind(['housetype_name'=>'title']); },'cate1'=>function($query){ $query->field('id,title,is_case')->bind(['cate1_name'=>'title','is_case'=>'is_case']); },'cate2'=>function($query){ $query->field('id,title')->bind(['cate2_name'=>'title']); },'cate3'=>function($query){ $query->field('id,title')->bind(['cate3_name'=>'title']); }])->where($where)->page($param['page'],$param['limit'])->select()->toArray(); $vrObj = new Vr(); foreach ($list as $k => $v) { $list[$k]['vr_case_img'] = $v['vr_case'] ? getFirstImg($v['vr_case']) : ''; //封面图 if ($v['is_case']==0 && $v['difference']==3) { $list[$k]['leixing'] = 'VR'; $list[$k]['covers'] = $v['vr_case'] ? getFirstImg($v['vr_case']) : ''; }elseif ($v['is_case']==0 && $v['difference']==1){ $list[$k]['leixing'] = '视频'; if ($v['cover']) { $list[$k]['covers'] = $v['cover']; }elseif ($v['video_case']) { $list[$k]['covers'] = $v['video_case'].'?x-oss-process=video/snapshot,t_100,f_jpg,w_200,m_fast'; }else{ $list[$k]['covers'] = ''; } // $list[$k]['covers'] = $v['cover'] ? $v['cover'].'?x-oss-process=image/resize,w_50' : ''; // $list[$k]['covers'] = $v['covers'] ? $v['video_case'].'?x-oss-process=video/snapshot,t_100,f_jpg,w_200,m_fast' : ''; }elseif ($v['is_case']==0 && $v['difference']==2){ $list[$k]['leixing'] = '图文'; $list[$k]['covers'] = $v['cover']; }elseif ($v['is_case']==0 && $v['difference']==4){ $list[$k]['leixing'] = 'PDF'; $list[$k]['covers'] = $v['cover']; }elseif($v['difference']==5){ $list[$k]['leixing'] = 'VR作品'; $list[$k]['covers'] = ''; //VR作品 if ($v['vr_case']) { $sid = str_replace(substr($v['vr_case'],0,-32),'',$v['vr_case']); $info = VrGroup::where('sid',$sid)->field('pic_path')->findOrEmpty(); $list[$k]['covers'] = $info->isEmpty() ? '' : $info->pic_path; } }else{ $list[$k]['leixing'] = '案例'; $list[$k]['covers'] = $v['cover']; } } $count = SmartScreenData::where($where)->count(); return json(['code'=> 0, 'data'=> $list,'count'=>$count]); } /** * 获取详情 */ public function getRead() { $param = Request::only(['id'=>0]); $where = [ ['id','=',$param['id']] ]; $vrObj = new Vr(); $res = SmartScreenData::with(['designer'=>function($query){ $query->field('id,name')->bind(['designer_name'=>'name','position'=>'position','image_photo'=>'image_photo']); },'community'=>function($query){ $query->field('id,title')->bind(['community_name'=>'title']); },'decostyle'=>function($query){ $query->field('id,title')->bind(['decostyle_name'=>'title']); },'housetype'=>function($query){ $query->field('id,title')->bind(['housetype_name'=>'title']); },'cate1'=>function($query){ $query->field('id,title')->bind(['cate1_name'=>'title','is_case'=>'is_case']); },'cate2'=>function($query){ $query->field('id,title')->bind(['cate2_name'=>'title']); },'cate3'=>function($query){ $query->field('id,title')->bind(['cate3_name'=>'title']); }])->where('id',$param['id'])->find(); $res->vr_case_img = ''; if ($res->vr_case && strpos($res->vr_case,'vr/#')) { //2023-06-02 vr作品获取封面图 $sid = str_replace(substr($res->vr_case,0,-32),'',$res->vr_case); $info = VrGroup::where('sid',$sid)->field('pic_path')->findOrEmpty(); $res->vr_case_img = $info->isEmpty() ? '' : $info->pic_path; }elseif ($res->vr_case) { $res->vr_case_img = $vrObj->getFirstImg($res->vr_case); } $res->good_at = []; if($res->designer_id){ $designer = Designer::where('employee_id',$res->designer_id)->findOrEmpty(); if (!$designer->isEmpty()) { $res->good_at = $designer->good_at; } } if ($res->vr_case) { $url_res = filter_var($res->vr_case, FILTER_VALIDATE_URL); if ($url_res === FALSE){ $res->vr_case = ''; } } $employee['phone'] = $employee['name'] = $employee['img'] = ''; if ($this->employee_id) { $info = Employee::where('id',$this->employee_id)->find(); $employee['phone'] = $info->phone; $employee['name'] = $info->name; $employee['img'] = User::where('id',$info->uid)->value('headimgurl'); } return json(['code'=> 0, 'data'=> $res,'info'=>$employee]); } /** * 讲解记录 * $time = 0#unix,1#unix,0#unix */ public function saveLog() { if(!$this->employee_id || !$this->customer_id) return json(['code'=> 1, 'data'=> '未绑定客户','msg'=>'未绑定客户']); $param = Request::only(['file'=>'','time'=>'']); $info = Employee::where('id',$this->employee_id)->find(); $customer_name = Customer::where('id',$this->customer_id)->value('name'); $count = explode(',',$param['time']); if (count($count)<=1) { $param['time'] = ''; $param['unix'] = 0; }else{ $param['unix'] = end($count); $str = array_slice($count,0,count($count)-1); $param['time'] = implode('',$str); } $param['time'] = '接待了客户:'.$customer_name.',谈单时长:'.ceil($param['unix']/60).'分钟;
智慧屏讲解内容:
'.$param['time']; $save = [ 'customer_id'=>$this->customer_id, 'type'=>1, 'remark'=>$param['time'].'@讲解智慧屏##'.$param['file'], 'employee_id'=>$this->employee_id, 'user_id' => $info->uid, 'customer_employee_id' => $this->employee_id, 'org_id' => $info->org_id, 'customer_org_id' => $info->org_id, 'state'=>'未到访', 'next_contact_date' =>date('Y-m-d'), 'talking_order_time'=> ceil($param['unix']/60) ]; CustomerVisitLog::create($save); return json(['code'=> 0, 'data'=> '保存成功']); } /** * 获取客户智慧屏图片图片 */ public function getWisdomImg(){ if(!$this->employee_id || !$this->customer_id) return json(['code'=> 0, 'data'=> [],'msg'=>'']); $param = Request::only(['type'=>0]); $where = [ 'customer_id'=>$this->customer_id, 'type'=>$param['type'], 'root_id' => $this->root_id ]; $list = CustomerWisdomImg::where($where)->field('id,img')->order('id asc')->select()->toArray(); return json(['code'=> 0, 'data'=>$list, 'msg'=> '获取成功']); } /** * 获取报价套餐 */ public function getRenovatePackage(){ if(!$this->employee_id || !$this->customer_id) return json(['code'=> 0, 'data'=> ['package_list'=>[],'cusdata'=>[]],'msg'=>'']); //$param = Request::only(['type'=>0]); $package_list = RenovatePrice::where([['root_id','=',$this->root_id],['status','=',0]])->field('id,package_name,addtime')->order('sort desc')->select()->toArray(); $cusdata = Customer::where([['org_id','in',orgSubIds($this->root_id)],['id','=',$this->customer_id]])->field('id,name,phone,community_name,square,ext')->find(); $cusdata['unit_number'] = ''; if(!empty($cusdata['ext'])){ $ext = json_decode($cusdata['ext'],true); foreach($ext as $key=>$val){ if(!empty($val['keyname']) && $val['keyname'] == 'unit_number') $cusdata['unit_number'] = $val['value']; } } $data = ['package_list'=>$package_list,'cusdata'=>$cusdata]; return json(['code'=> 0, 'data'=>$data, 'msg'=> '获取成功']); } /** * 计算报价 */ public function callRenovatePrice() { if(!$this->employee_id || !$this->customer_id) return json(['code'=>0,'data'=>[],'msg'=>'获取成功']); $param = Request::only(['hall'=>0,'room'=>0,'kitchen'=>0,'toilet'=>0,'square'=>0,'package_id'=>0,'out_square'=>0,'name'=>'','community_name'=>'']); $package_id = !empty($param['package_id']) ? explode(',',$param['package_id']) : ''; if(empty($package_id)) return json(['code'=>'1','msg'=>'套餐参数错误']); if(empty($param['square'])) return json(['code'=>1,'msg'=>'面积为空']); $cusdata = Customer::where([['org_id','in',orgSubIds($this->root_id)],['id','=',$this->customer_id]])->find(); if(!empty($param['name'])) $cusdata->name = $param['name']; if(!empty($param['community_name'])) $cusdata->community_name = $param['community_name']; if(!empty($param['square'])) $cusdata->square = $param['square']; $cusdata->save(); $packdata = RenovatePrice::with('item')->where([['root_id','=',$this->root_id],['id','in',$package_id]])->select()->toArray(); if(empty($packdata)) return json(['code'=>1,'msg'=>'套餐不存在']); foreach($packdata as $k=>$v){ $price = 0; $discount_price = 0; //$item = $v['item'] ? $v['item'] : []; //if(empty($item)) $price = 0; //rule 1=>单价*套内建筑面积 2=>单价*建筑面积 3=>单价*卧室数 4=>单价*卫生间数 5=>单价*厨房数 6=>固定价 7=>单价*客厅数 foreach($v['item'] as $key=>$val){ if($val['rule']==1 && !empty($param['square'])){ $price+= $val['price'] * $param['square']; $discount_price+= $val['discount_price']; $packdata[$k]['item'][$key]['item_price'] = round($val['price'] * $param['square'] * $v['service_price'],2); } if($val['rule']==2 && !empty($param['out_square'])){ $price+= $val['price'] * $param['out_square']; $discount_price+= $val['discount_price']; $packdata[$k]['item'][$key]['item_price'] = round($val['price'] * $param['out_square'] * $v['service_price'],2); } if($val['rule']==3 && !empty($param['room'])){ $price+= $val['price'] * $param['room']; $discount_price+= $val['discount_price']; $packdata[$k]['item'][$key]['item_price'] = round($val['price'] * $param['room'] * $v['service_price'],2); } if($val['rule']==4 && !empty($param['toilet'])){ $price+= $val['price'] * $param['toilet']; $discount_price+= $val['discount_price']; $packdata[$k]['item'][$key]['item_price'] = round($val['price'] * $param['toilet'] * $v['service_price'],2); } if($val['rule']==5 && !empty($param['kitchen'])){ $price+= $val['price'] * $param['kitchen']; $discount_price+= $val['discount_price']; $packdata[$k]['item'][$key]['item_price'] = round($val['price'] * $param['kitchen'] * $v['service_price'],2); } if($val['rule']==6){ $price+= $val['price']; $discount_price+= $val['discount_price']; $packdata[$k]['item'][$key]['item_price'] = round($val['price'] * $v['service_price'],2); } if($val['rule']==7 && !empty($param['hall'])){ $price+= $val['price'] * $param['hall']; $discount_price+= $val['discount_price']; $packdata[$k]['item'][$key]['item_price'] = round($val['price'] * $param['hall'] * $v['service_price'],2); } } $price = $price * $v['service_price'] + $v['devise_price'] - $discount_price; $packdata[$k]['price'] = round($price,2); $packdata[$k]['discount_price'] = $discount_price; $packdata[$k]['yuan_price'] = round($price,2) + $discount_price; } $remark = '客户'.$cusdata->name.'于'.date('Y-m-d H:i:s').'使用'; $msg = ''; foreach($packdata as $k=>$v){ $msg.= $v['package_name'].'套餐进行装修报价,价格为'.$v['price'].'元,优惠金额为'.$v['discount_price'].'元'; } //echo ($remark.trim($msg,','));exit; $info = Employee::where([['root_id','=',$this->root_id],['id','=',$this->employee_id]])->find(); //增加客户计算报价的记录 $save = [ 'customer_id'=>$this->customer_id, 'type'=>1, 'remark'=>$remark.trim($msg,','), 'employee_id'=>$this->employee_id, 'user_id' => $info->uid, 'customer_employee_id' => $this->employee_id, 'org_id' => $info->org_id, 'customer_org_id' => $info->org_id, 'state'=>$cusdata->state != '待确认' ? 10 : 1, 'next_contact_date' =>date('Y-m-d') ]; CustomerVisitLog::create($save); return json(['code'=>0,'data'=>$packdata,'msg'=>'获取成功']); } /** * 生成绑定二维码 * 每次刷新都是新码 * */ public function getQrcode() { $list = scandir('upload'); foreach ($list as $v) { if(strpos($v,'wisdomqrcode') !== false) @unlink('upload/'.$v); //删除失效文件 } $str = 'wisdomqrcode'.uniqid().'@'.$this->root_id.'@'; $name = $str.'.jpg'; $img = qrcode($str, 'upload/'.$name); $url = request()->domain().'/'.'upload/'.$name; return json(['code'=>0,'data'=>$url,'msg'=>'获取成功','str'=>$str]); } /** * 循环调用api */ public function ergodic() { $param = Request::only(['str'=>'']); if(!$param['str']) return json(['code'=>1,'data'=>'未绑定','msg'=>'未绑定']); $res = Cache::get($param['str']); if($res){ $aec = new Aec(config('app.aec_key'), config('app.aec_iv')); $value = $aec->decrypt($res); $value = explode('#',$value); $root_id = $value[0]; $employee_id = $value[1]; $customer_id = $value[2]; $log_data['root_id'] = $root_id; $log_data['employee_id'] = $employee_id; $log_data['customer_id'] = $customer_id; $log_data['str'] = $res; $log_data['time'] = 0; SmartScreenLog::create($log_data); return json(['code'=>0,'data'=>$res,'msg'=>'获取成功']); }else{ return json(['code'=>1,'data'=>'未绑定','msg'=>'未绑定']); } } /** * 解绑 */ public function logout() { $param = Request::only(['str'=>'']); $log_where[] = ['root_id', '=', $this->root_id]; $log_where[] = ['employee_id', '=', $this->employee_id]; $log_where[] = ['customer_id', '=', $this->customer_id]; $log_where[] = ['str', '=', $param['str']]; $find = SmartScreenLog::where($log_where)->findOrEmpty(); if (!$find->isEmpty()) { $time = time() - strtotime($find['addtime']); $find->time = $time; $find->endtime = date('Y-m-d H:i:s'); $find->save(); } $res = Cache::delete($param['str']); $aec = new Aec(config('app.aec_key'), config('app.aec_iv')); $str = $aec->encrypt($this->root_id.'#0#0'); return json(['code'=>0,'data'=>$str,'msg'=>'解绑成功']); } /** * 客户设计师列表 */ public function cus_designer_list() { $orgids = orgSubIds($this->root_id); $where[] = ['org_id', 'in', $orgids]; $where[] = ['id', '=', $this->customer_id]; $assign = Customer::where($where)->value('assigned_personnel'); $list = []; if (!empty($assign)) { $list = Employee::hasWhere('org', ['org_type' => 2])->where('Employee.id', 'in', explode(',', $assign))->column('Employee.id,Employee.name'); } return json(['code' => 0, 'data' => $list, 'msg' => '获取成功']); } /** * 设计师个人介绍 */ public function designer_detail($designer_id) { $dw[] = ['root_id', '=', $this->root_id]; $dw[] = ['employee_id', '=', $designer_id]; $data = Designer::where($dw)->field('headimgurl,good_at,desc,position,work_years,good_house,design_concept,vcr')->find(); $data['is_designer'] = !empty($data) ? 1 : 2; $data['employee_name'] = Employee::where([['root_id', '=', $this->root_id], ['id', '=', $this->employee_id]])->value('name'); return json(['code' => 0, 'data' => $data, 'msg' => '获取成功']); } /** * 设计师作品集 */ public function designer_worklist() { $param = Request::only(['page' => 1, 'limit' => 10, 'housetype_id' => 0, 'designer_id']); if (empty($param['designer_id'])) return json(['code' => 1, 'msg' => '请选择设计师']); $dw[] = ['root_id', '=', $this->root_id]; $dw[] = ['employee_id', '=', $param['designer_id']]; if (!empty($param['housetype_id'])) $dw[] = ['housetype_id', '=', $param['housetype_id']]; $list = DesignerCollectionWorks::with(['decostyle', 'housetype'])->where($dw)->page($param['page'], $param['limit'])->select()->toArray(); foreach ($list as $key => $val) { if ($val['type'] == 2 && !empty($val['vr_case'])) { $list[$key]['cover_img'] = !empty($val['vr_case'][0]['vr_img']) ? $val['vr_case'][0]['vr_img'] : ''; } } return json(['code' => 0, 'data' => $list, 'msg' => '获取成功']); } /** * 作品集户型分类 */ public function work_housetype($designer_id) { $dw[] = ['root_id', '=', $this->root_id]; $dw[] = ['employee_id', '=', $designer_id]; $ids = DesignerCollectionWorks::where($dw)->group('housetype_id')->column('housetype_id'); $list = Housetype::where([['root_id', '=', $this->root_id], ['id', 'in', $ids]])->column('id,name'); return json(['code' => 0, 'data' => $list, 'msg' => '获取成功']); } /** * 设计师作品详情 */ public function designer_workdet() { $param = Request::only(['designer_id' => 0, 'id' => 0]); $where[] = ['root_id', '=', $this->root_id]; $where[] = ['employee_id', '=', $param['designer_id']]; $where[] = ['id', '=', $param['id']]; $data = DesignerCollectionWorks::with(['decostyle', 'housetype'])->where($where)->find(); $info = Employee::with(['user' => function ($query) { $query->field('id,headimgurl'); }])->where([['root_id', '=', $this->root_id], ['id', '=', $this->employee_id]])->field('uid,name,phone')->find()->toArray(); $info['img'] = !empty($info['user']['headimgurl']) ? $info['user']['headimgurl'] : ''; if (empty($data)) return json(['code' => 1, 'msg' => '数据不存在']); return json(['code' => 0, 'data' => $data, 'info' => $info, 'msg' => '获取成功']); } /** * 工地状态 */ public function construction_step() { $root_id = $this->root_id; $step_list = ConstructionStep::where('root_id', '=', $root_id)->order('order asc')->select()->toArray(); return json(['code' => 0, 'data' => $step_list]); } /** * 在施工地 */ public function construction() { $root_id = $this->root_id; $param = request()->only(['page'=> 1, 'limit'=> 15, 'keyword'=> '', 'emp_name'=> '', 'status'=> '']); $model = SmartScreenConstruction::with(['designer', 'employee'])->where([['root_id', '=', $root_id]]); if (!empty($param['keyword'])){ $where_k = [['owner_name|address', 'like', '%' . $param['keyword'] . '%']]; $model = $model->where($where_k); } if (!empty($param['emp_name'])) { $where_e = [['project_manager|inspection', 'like', '%' . $param['emp_name'] . '%']]; $emp_name = $param['emp_name']; $designer_org = Org::where([['path', 'like', $root_id . '%'], ['org_type', '=', 2], ['status', '=', 1]])->column('id'); $designer_id = Employee::where([['root_id', '=', $root_id], ['name', 'like', '%' . $param['emp_name'] . '%'], ['state', '=', '在职'], ['org_id', 'in', $designer_org]])->column('id'); $where_d = [['designer_id', 'in', $designer_id]]; if (empty($designer_id)) { $model = $model->where($where_e); } else { $model = $model->where(function ($query) use ($emp_name, $where_d) { $query->whereOr([[['project_manager', 'like', '%' . $emp_name . '%']], [['inspection', 'like', '%' . $emp_name . '%']], $where_d]); }); } } if (!empty($param['status'])) { $where_s = [['status', '=', $param['status']]]; $model = $model->where($where_s); } $count = $model->count(); $list = $model->order('addtime desc')->page($param['page'], $param['limit'])->select()->toArray(); return json(['code'=> 0, 'data'=> $list, 'count'=> $count]); } /** * 项目清单 */ public function project(){ $root_id = $this->root_id; $param = request()->only(['page'=> 1, 'limit'=> 15, 'keyword'=> '']); $where[] = ['root_id', '=', $root_id]; $keyword = $param['keyword']; $list = SmartScreenProjectCate::with(['project'=> function($query) use ($keyword){ if ($keyword) { $query->where('name', 'like', '%' . $keyword . '%')->with('employee'); } else { $query->with('employee'); } }])->withCount(['project'=> function($query) use ($keyword){ $query->where('name', 'like', '%' . $keyword . '%')->with('employee'); }])->where('root_id', '=', $root_id)->page($param['page'], $param['limit'])->select()->toArray(); $count = SmartScreenProjectCate::where($where)->count(); return json(['code'=> 0, 'data'=> $list, 'count'=> $count]); } /** * 获取设计师的所有客户 */ public function designer_cuslist() { $param = request()->only(['page' => 1, 'limit' => 15, 'keyword' => '']); $check = Employee::with(['org'])->where([['root_id', '=', $this->root_id], ['id', '=', $this->employee_id]])->find(); if (!empty($check['org']) && $check['org']['org_type'] != 2) return json(['code' => 1, 'data' => [], 'msg' => '获取成功']); $orgids = orgSubIds($this->root_id); $where[] = ['org_id', 'in', $orgids]; $where[] = ['designer_id|assigned_personnel', 'find in set', $this->employee_id]; $where[] = ['state', 'not in', Customer::changeState('无效', 'chaos')]; $orCondition = []; if (!empty($param['keyword'])) { $aec = new Aes(config('app.aec_key'), config('app.aec_iv')); $aecPhone = $aec->encrypt($param['keyword']); $orCondition = [ [['name', 'like', '%'.$param['keyword'].'%']], [['phone', '=', $aecPhone]] ]; } if (empty($orCondition)) $list = Customer::with(['plandata'])->where($where)->field('id,name,community_name,sex,ext')->page($param['page'], $param['limit'])->order('assign_time desc')->select()->toArray(); else $list = Customer::with(['plandata'])->where($where)->where(function ($query) use ($orCondition) { $query->whereOr($orCondition); })->field('id,name,community_name,sex,ext')->page($param['page'], $param['limit'])->order('assign_time desc')->select()->toArray(); foreach ($list as &$val) { $imglist = CustomerWisdomImg::where(['customer_id' => $val['id']])->field('img')->select()->toArray(); $val['img_cont'] = count($imglist); $val['vr_cont'] = !empty($val['plandata']['vrurl']) ? count($val['plandata']['vrurl']) : 0; $val['pdf_cont'] = !empty($val['plandata']['pdfurl']) ? count($val['plandata']['pdfurl']) : 0; $val['plandata']['imgurl'] = !empty($imglist) ? array_column($imglist,'img') : ''; $housetype_arrow = ''; if (!empty($val['ext'])) { $ext_data = json_decode($val['ext'], true); foreach ($ext_data as $k => $v) { if (isset($v['keyname']) && $v['keyname'] == 'housetype_arrow' && !empty($v['value'])) { $housetype_arrow = CustomerPortraitFieldSelect::where([['pid', '=', $v['id']], ['id', '=', $v['value']]])->value('name'); } } } $val['housetype_arrow'] = $housetype_arrow; } $count = Customer::where($where)->count(); return json(['code' => 0, 'data' => $list, 'count' => $count, 'msg' => '获取成功']); } /** * 客户的方案资料详情 */ public function planDetail($cid = null) { $cid = empty($cid) ? $this->customer_id : $cid; $orgids = orgSubIds($this->root_id); $customer = Customer::where([['id', '=', $cid], ['org_id', 'in', $orgids]])->find(); if (empty($customer)) return json(['code' => 0, 'data' => [], 'msg' => '获取失败']); $data = DesignerCustomerPlandata::where([['root_id', '=', $this->root_id], ['designer_id', '=', $this->employee_id], ['customer_id', '=', $cid]])->find(); if (empty($data)) $data = []; else $data = $data->toArray(); $imgList = CustomerWisdomImg::where([['root_id', '=', $this->root_id], ['customer_id', '=', $cid]])->order('addtime asc')->column('img'); $ali_oss_bindurl = config('app.ali_oss_bindurl'); foreach ($imgList as $k => $img) { $imgList[$k] = 'https://' . $ali_oss_bindurl . '/' . $img; } $data['imgurl'] = $imgList; return json(['code' => 0, 'data' => $data, 'msg' => '获取成功']); } /** * 设计师编辑客户的方案资料 */ public function designer_editplan() { $param = request()->only(['customer_id' => 0, 'imgurl' => '', 'vrurl' => '', 'pdfurl' => '']); if (empty($param['customer_id'])) return json(['code' => 1, 'msg' => '参数错误']); $where[] = ['root_id', '=', $this->root_id]; $where[] = ['designer_id', '=', $this->employee_id]; $where[] = ['customer_id', '=', $param['customer_id']]; $check = DesignerCustomerPlandata::where($where)->find(); $vrstr = ''; if (!empty($param['vrurl'])) { $vrlist = explode(',', $param['vrurl']); foreach ($vrlist as $val) { $vrstr .= vrlinkSet($val) . ','; } $vrstr = trim($vrstr, ','); } $save = [ 'vrurl' => $vrstr, 'pdfurl' => $param['pdfurl'] ]; if (empty($check)) { $save['designer_id'] = $this->employee_id; $save['customer_id'] = $param['customer_id']; $save['root_id'] = $this->root_id; DesignerCustomerPlandata::create($save); } else { $save['id'] = $check->id; DesignerCustomerPlandata::update($save); } if (!empty($param['imgurl'])) { $imgList = explode(',', $param['imgurl']); $domain = config('app.ali_oss_bindurl'); $replaceDomain = 'https://' . $domain . '/'; $nowHad = CustomerWisdomImg::where([ ['root_id', '=', $this->root_id], ['customer_id', '=', $param['customer_id']] ])->column('id'); $updateId = []; foreach ($imgList as $v) { $v = str_replace($replaceDomain, '', $v); $save = [ 'root_id' => $this->root_id, 'customer_id' => $param['customer_id'], 'img' => $v ]; $hadid = CustomerWisdomImg::where($save)->value('id'); if ($hadid) { $updateId[] = $hadid; } else { $customerWisdomImg = CustomerWisdomImg::create($save); $updateId[] = $customerWisdomImg->id; } } $delId = array_diff($nowHad, $updateId); if ($delId) CustomerWisdomImg::where([['id', 'in', $delId]])->delete(); } return json(['code' => 0, 'msg' => '编辑成功']); } /** * 获取VR链接第一帧 */ public function get_vrimg($url) { $url = vrlinkSet($url); $data = ['vr_link' => $url, 'vr_img' => getFirstImg($url)]; return json(['code' => 0, 'data' => $data, 'msg' => '获取成功']); } /** * 清空客户方案资料 */ public function delPlandata($cid) { $where[] = ['customer_id', '=', $cid]; $where[] = ['root_id', '=', $this->root_id]; $where[] = ['designer_id', '=', $this->employee_id]; $check = DesignerCustomerPlandata::where($where)->find(); if (empty($check)) return json(['code' => 1, 'msg' => '数据不存在']); $check->imgurl = $check->vrurl = $check->pdfurl = null; $check->save(); CustomerWisdomImg::where([ 'root_id' => $this->root_id, 'customer_id' => $cid, ])->delete(); return json(['code' => 0, 'msg' => '清除成功']); } /* * 作品集户型 */ public function housetypelist() { $housetype = Housetype::where(['root_id' => $this->root_id])->field('id,name')->select(); $decostyles = Decostyle::field('id,name')->where([['root_id', '=', $this->root_id], ['type', '=', 0]])->select(); $data = ['housetype' => $housetype, 'decostyles' => $decostyles]; return json(['code' => 0, 'data' => $data, 'msg' => '获取成功']); } /** * 设计师增加个人作品 */ public function designer_add_works() { $param = Request::only(['id' => 0, 'title', 'style_id' => 0, 'housetype_id' => 0, 'square', 'money', 'type', 'desc' => '', 'vr_case' => '']); if (strlen($param['title']) > 50) { return json(['code' => 1, 'msg' => '作品名称过长']); } $cover_img = $vrstr = null; if (!empty($param['vr_case']) && $param['type'] == 2) { $vrlist = explode(',', $param['vr_case']); foreach ($vrlist as $val) { $vrstr .= vrlinkSet($val) . ','; } $vrstr = trim($vrstr, ','); } if (!empty($param['desc']) && $param['type'] == 1) { $imgs = explode(',', $param['desc']); $cover_img = $imgs[0]; } $add = [ 'title' => $param['title'], 'housetype_id' => $param['housetype_id'], 'square' => $param['square'], 'money' => $param['money'], 'type' => $param['type'], 'desc' => $param['desc'], 'cover_img' => $cover_img, 'vr_case' => $vrstr, 'style_id' => $param['style_id'] ]; if ($param['id']) { $check = DesignerCollectionWorks::where([['root_id', '=', $this->root_id], ['employee_id', '=', $this->employee_id], ['id', '=', $param['id']]])->find(); if (empty($check)) return json(['code' => 1, 'msg' => '数据不存在']); $add['id'] = $param['id']; DesignerCollectionWorks::update($add); } else { $empdata = Employee::with(['org'])->where([['root_id', '=', $this->root_id], ['id', '=', $this->employee_id]])->field('id,org_id')->find(); $add['employee_id'] = $this->employee_id; $add['root_id'] = $this->root_id; $add['designer_id'] = $empdata['org']['org_type'] == 2 ? $this->employee_id : 0; $ms = DesignerCollectionWorks::create($add); } return json(['code' => 0, 'msg' => '编辑成功']); } /** * 设计师个人作品详情 */ public function designer_worksdet() { $param = Request::only(['id']); $data = DesignerCollectionWorks::with(['decostyle', 'housetype'])->where([['root_id', '=', $this->root_id], ['employee_id', '=', $this->employee_id], ['id', '=', $param['id']]])->find(); if (empty($data)) return json(['code' => 1, 'msg' => '数据不存在']); return json(['code' => 0, 'data' => $data, 'msg' => '获取成功']); } /** * 设计师作品集列表 */ public function designer_work() { $param = Request::only(['page' => 1, 'limit' => 10, 'keyword', 'type', 'housetype_id']); $where[] = ['root_id', '=', $this->root_id]; $where[] = ['employee_id', '=', $this->employee_id]; if (!empty($param['keyword'])) $where[] = ['title', 'like', '%' . $param['keyword'] . '%']; if (!empty($param['type'])) $where[] = ['type', '=', $param['type']]; if (!empty($param['housetype_id'])) $where[] = ['housetype_id', '=', $param['housetype_id']]; $list = DesignerCollectionWorks::with(['decostyle', 'housetype'])->where($where)->page($param['page'], $param['limit'])->select()->toArray(); foreach ($list as $key => $val) { if ($val['type'] == 2 && !empty($val['vr_case'])) { $list[$key]['cover_img'] = !empty($val['vr_case'][0]['vr_img']) ? $val['vr_case'][0]['vr_img'] : ''; } } $count = DesignerCollectionWorks::where($where)->count(); return json(['code' => 0, 'data' => $list, 'count' => $count, 'msg' => '获取成功']); } /** * 设计师个人作品集户型分类 */ public function designer_housetype() { $dw[] = ['root_id', '=', $this->root_id]; $dw[] = ['employee_id', '=', $this->employee_id]; $ids = DesignerCollectionWorks::where($dw)->group('housetype_id')->column('housetype_id'); $list = Housetype::where([['root_id', '=', $this->root_id], ['id', 'in', $ids]])->column('id,name'); return json(['code' => 0, 'data' => $list, 'msg' => '获取成功']); } /** * 内部资料 */ public function private_data(){ $page = input('page', 1, 'intval'); $limit = input('limit', 10, 'intval'); $keyword = input('keyword', '', 'trim'); $where[] = ['BuildingHousetype.root_id', '=', $this->root_id]; if ($keyword) { $community_id = Community::where([['root_id', '=', $this->root_id], ['name', 'like', '%' . $keyword . '%']])->column('id'); $building_id = Building::where([['root_id', '=', $this->root_id], ['community_id', 'in', $community_id]])->column('id'); $where[] = ['BuildingHousetype.building_id', 'in', $building_id]; } $list = BuildingHousetype::has('file', '>', 0)->with(['file', 'building'])->where($where)->page($page, $limit)->select()->toArray(); $count = BuildingHousetype::has('file', '>', 0)->where($where)->count(); return json(['code'=> 0, 'data'=> $list, 'msg'=> '获取成功', 'count'=> $count]); } }