1
0

Detail.php 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737
  1. <?php
  2. declare(strict_types=1);
  3. namespace app\mobile\controller;
  4. use app\model\Employee;
  5. use app\model\VrGroup;
  6. use app\model\VrView;
  7. use app\model\Building as BuildingModel;
  8. use app\model\BuildingHousetype;
  9. use app\model\Company;
  10. use xiaohongwu\Vr;
  11. use app\model\Designer;
  12. use app\model\Decostyle;
  13. use app\model\BuildingProgress;
  14. use app\model\BuildingConstruction;
  15. use think\facade\Request;
  16. use toolkits\Aec;
  17. use app\model\WeworksingleCompanySetting;
  18. use app\model\Community;
  19. use EasyWeChat\Factory;
  20. use app\model\BuildingMaterialCase;
  21. use app\model\ConstructionStep;
  22. use app\model\MaterialCase;
  23. use app\model\CustomerClue;
  24. use app\model\Housetype;
  25. use app\model\ConstructionRecord;
  26. use app\model\Miniprogram;
  27. use app\model\Construction as ConstructionModel;
  28. use app\model\User;
  29. use Firebase\JWT\JWT;
  30. use openssl\Aes;
  31. class Detail extends Enjoy {
  32. public function analysisToken($token,$str,$emp_id){
  33. if ($token) {
  34. JWT::$leeway = 60; //token的弹性有效时间
  35. $decoded = JWT::decode($token, config('app.jwt_key'), ['HS256']);
  36. $arr = (array) $decoded;
  37. $aes = new Aes(config('app.jwt_key'));
  38. $queryData = $aes->decrypt($arr['data']);
  39. parse_str($queryData, $token);
  40. $emp_id = $token['employee_id'];
  41. }elseif ($str) {
  42. $aec = new Aec(config('app.aec_key'), config('app.aec_iv'));
  43. $arr = $aec->decrypt($str);
  44. $arr = explode('#',$arr);
  45. $emp_id = $arr[1];
  46. }
  47. $employee = Employee::where('id', '=', $emp_id)->findOrEmpty();
  48. return $employee;
  49. }
  50. public function info(){
  51. $sid = input('sid', '', 'trim');
  52. $token = input('tokens','');//分享人token
  53. $str = input('str','');//分享人加密字符串
  54. if (empty($sid)) {
  55. return json(['code'=> 0, 'data'=> [], 'msg'=> '获取成功']);
  56. }
  57. $info = VrGroup::where('sid', '=', $sid)->findOrEmpty();
  58. if ($info->isEmpty()) {
  59. return json(['code'=> 0, 'data'=> [], 'msg'=> '获取成功']);
  60. }
  61. // $employee = Employee::where('id', '=', $info['emp_id'])->findOrEmpty();
  62. $employee = $this->analysisToken($token,$str,$info['emp_id']);
  63. if ($employee->isEmpty()) {
  64. $info['employee_name'] = '';
  65. $info['employee_headimgurl'] = '';
  66. $info['employee_phone'] = '';
  67. $info['employee_qrcode'] = '';
  68. $info['uid'] = 0;
  69. }else{
  70. $info['employee_name'] = $employee['name'];
  71. $info['employee_headimgurl'] = User::where('id',$employee['uid'])->value('headimgurl');
  72. $info['employee_phone'] = $employee['phone'];
  73. $info['employee_qrcode'] = $employee['qrcode'];
  74. $info['uid'] = $employee['uid'];
  75. }
  76. $vr_view = VrView::with(['hotspot'])->where('vr_group_id', '=', $info['id'])->order('sort asc')->select()->toArray();
  77. $ali_oss_bindurl = config('app.vr_ali_oss_bindurl');
  78. $url = 'https://' . $ali_oss_bindurl;
  79. foreach ($vr_view as $k => $v) {
  80. $vr_view[$k]['vr_path'] = $url.'/'.$v['structure'];
  81. foreach ($v['hotspot'] as $k2 => $v2) {
  82. $arr = [];
  83. $arr1 = $v2['embedValue'] ? explode('|',$v2['embedValue']) : [];
  84. foreach ($arr1 as $v3) {
  85. $arr1_1 = explode(',',$v3);
  86. $arr[] = ['ath'=>$arr1_1[0],'atv'=>$arr1_1[1]];
  87. }
  88. $v2['embedValue'] = $arr;
  89. $arr2 = $v2['titlePosition'] ? explode(',',$v2['titlePosition']) : [];
  90. $v2['titlePosition'] = $arr2 ? ['ath'=>$arr2[0],'atv'=>$arr2[1]] : [];
  91. $json = json_encode($v2);
  92. $vr_view[$k]['hotspot'][$k2] = ['content'=>$json];
  93. unset($json);
  94. }
  95. }
  96. $info['view'] = array_values($vr_view);
  97. $info['str'] = $this->employee['str'];
  98. $notify = Miniprogram::where('root_id',$employee['root_id'])->value('notify');
  99. return json(['code'=> 0, 'data'=> $info, 'msg'=> '获取成功','notify'=>$notify]);
  100. }
  101. /**
  102. * 详情
  103. */
  104. public function view(){
  105. $id = $this->params['buildingId'];
  106. if(!$id) return json(['code' => 0, 'data' => [], 'msg' => '获取成功']);
  107. $share = input('share', '', 'trim');
  108. $info = BuildingModel::find($id);
  109. if (empty($info)){
  110. return json(['code'=> 1, 'msg'=> '数据不存在']);
  111. }
  112. $area_list = BuildingHousetype::where('building_id', '=', $id)->order('area asc')->column('area');
  113. $info['area_list'] = array_values(array_unique(array_filter($area_list)));
  114. $company = Company::where('root_id', '=', $info['root_id'])->field(['company_name', 'logo'])->find();
  115. $info['company_name'] = $company['company_name'];
  116. $info['company_logo'] = $company['logo'];
  117. $info['company_address'] = $company['company_address'];
  118. //小区户型
  119. $housetype = BuildingHousetype::with(['devcase'=>function($query){
  120. $query->field('housetype_id,id,name,type,vr_link,content,cover,decostyles_id');
  121. }])->where('building_id', '=', $id)->withCount(['materialCase'])->select();
  122. $xin = null;
  123. $vrObj = new Vr();
  124. if(!empty($housetype->toArray())){
  125. $houselist=$housetype->toArray();
  126. foreach($houselist as $key=>$val){
  127. if(empty($val['house_img']) && !empty($val['vr_link'])){
  128. $houselist[$key]['house_img'][] = $vrObj->getFirstImg($val['vr_link']);
  129. }
  130. if(empty($val['devcase'])) continue;
  131. foreach($val['devcase'] as $k=>$v){
  132. $houselist[$key]['devcase'][$k]['decostyles_name']=Decostyle::where('id',$v['decostyles_id'])->value('name');
  133. $houselist[$key]['devcase'][$k]['area']=$val['area'];
  134. $houselist[$key]['devcase'][$k]['room']=$val['room'];
  135. $houselist[$key]['devcase'][$k]['hall']=$val['hall'];
  136. $houselist[$key]['devcase'][$k]['bathroom']=$val['bathroom'];
  137. if($v['type']==1){
  138. $houselist[$key]['devcase'][$k]['cover'] = $vrObj->getFirstImg($v['vr_link']);
  139. }
  140. }
  141. }
  142. //分享加密参数 店面id ,分享人id , 楼盘id , 户型id , 案例id , 在施工地id
  143. $aec = new Aec(config('app.aec_key'), config('app.aec_iv'));
  144. foreach($houselist as $key => $val){
  145. $ids = [$this->params['rootId'],$this->params['employeeId'],'',$val['id'],'',''];
  146. $val['str'] = $houselist[$key]['str'] = $aec->encrypt(implode('#',$ids));
  147. $xin[$val['room']][] = $val;
  148. }
  149. $xin[0] = $houselist;
  150. }
  151. $info['vr_link_cover']='';
  152. if(!empty($info['vr_link'])){
  153. $info['vr_link_cover']=$vrObj->getFirstImg($info['vr_link']);
  154. }
  155. $info['housetype'] = $xin;
  156. $info['housetype_count'] = $housetype->count();
  157. //增加进度图片视频VR数量查询
  158. $prtype_list = BuildingProgress::where([['building_id', '=', $id]])->field('count(*) as count,type')->group('type')->select()->toArray();
  159. $info['prtype_list']=!empty($prtype_list)?$prtype_list:null;
  160. BuildingModel::where('id', '=', $id)->inc('view_times')->update();
  161. if (empty($info->vr_link) && $info->vr_group_ids) {
  162. $group = VrGroup::where('id',$info->vr_group_ids)->field('sid,pic_path')->find();
  163. $info->vr_link = config('app.vr_show_domain').$group->sid;
  164. $info->vr_link_img = $group->pic_path;
  165. }
  166. return json(['code'=> 0, 'data'=> $info]);
  167. }
  168. //户型详情
  169. public function housetype_detail()
  170. {
  171. $id = $this->params['housetypeId'];
  172. if(!$id) return json(['code' => 0, 'data' => [], 'msg' => '获取成功']);
  173. if(empty($id)) return json(['code'=> 1,'msg'=> '参数错误']);
  174. $data = BuildingHousetype::find($id);
  175. $data['new_orientation'] = $data->getData('orientation');
  176. $data['vr_link_img'] = '';
  177. if (!empty($data['vr_link'])) {
  178. $vrObj = new Vr();
  179. $data['vr_link_img'] = getFirstImg($data['vr_link']);
  180. }
  181. //查询楼盘地址和小区
  182. $bulid = BuildingModel::where('id',$data->building_id)->field('community_id,address')->findOrEmpty();
  183. if (!$bulid->isEmpty()){
  184. $bulid->community = $bulid->community_id ? Community::where('id',$bulid->community_id)->value('name') : '';
  185. }
  186. if (empty($data->vr_link) && $data->vr_group_ids) {
  187. $group = VrGroup::where('id',$data->vr_group_ids)->field('sid,pic_path')->find();
  188. $data->vr_link = config('app.vr_show_domain').$group->sid;
  189. $data->vr_link_img = $group->pic_path;
  190. }
  191. return json(['code'=> 0, 'data'=> $data,'bulid'=>$bulid, 'msg'=> '获取成功']);
  192. }
  193. /**
  194. * 楼盘进度
  195. */
  196. public function progress(){
  197. // $id = input('id', '', 'intval');
  198. $id = $this->params['buildingId'];
  199. $page = input('page',1);
  200. $limit = input('limit',10);
  201. if(!$id) return json(['code' => 0, 'data' => [], 'msg' => '获取成功']);
  202. $type = input('type','','trim');
  203. $where[]=['building_id', '=', $id];
  204. if(!empty($type)){
  205. $where[]=['type', '=', $type];
  206. }
  207. $label_id = input('label_id',0);
  208. if($label_id) $where[] = ['label_id','=',$label_id];
  209. $list = BuildingProgress::where($where)->page((int)$page,(int)$limit)->order('addtime desc')->select();
  210. if (empty($list)) $list = [];
  211. else $list = $list->toArray();
  212. $vrObj = new Vr();
  213. foreach ($list as &$item) {
  214. $vrData = [];
  215. if ($item['type']=='vr' && $item['vr']) {
  216. $vrUrlList = explode(',', $item['vr']);
  217. foreach ($vrUrlList as $url) {
  218. $vrData[] = [
  219. 'vrUrl' => $url,
  220. 'vrfirstImg' => $vrObj->getFirstImg($url)
  221. ];
  222. }
  223. }elseif ($item['type']=='group' && $item['vr_group_ids']) {
  224. $url = config('app.vr_show_domain');
  225. $vrgroup = VrGroup::where('id',$item['vr_group_ids'])->field('id,pic_path,sid')->findOrEmpty();
  226. $item['show_url'] = '';
  227. $item['show_img'] = '';
  228. if (!$vrgroup->isEmpty()) {
  229. $item['show_url'] = $url.$vrgroup->sid;
  230. $item['show_img'] = $vrgroup->pic_path;
  231. }
  232. }
  233. $item['vr'] = $vrData;
  234. }
  235. $count = BuildingProgress::where($where)->count();
  236. return json(['code' =>0, 'data' => $list,'count'=>$count]);
  237. }
  238. /**
  239. * 个人信息
  240. */
  241. public function getUserInfo()
  242. {
  243. $aec = new Aec(config('app.aec_key'), config('app.aec_iv'));
  244. $emp = Employee::where([['id','=',$this->params['employeeId']],['root_id','=',$this->params['rootId']]])->field('qrcode,id,phone,uid,root_id,name,opt_name')->findOrEmpty();
  245. if($emp->isEmpty()) return json(['code' => 0,'data'=>[] , 'msg' => '']);
  246. $emp->headimgurl = $emp->user->headimgurl;
  247. $emp->company_name = $emp->companyJoin->company_name;
  248. $emp->logo = $emp->companyJoin->logo;
  249. $emp->notify = Miniprogram::where('root_id',$emp->root_id)->value('notify');
  250. $emp->str = $aec->encrypt($emp->root_id.'#'.$emp->id);
  251. $emp = $emp->toArray();
  252. unset($emp['user']);
  253. unset($emp['company']);
  254. return json(['code' => 0,'data'=>$emp , 'msg' => '']);
  255. }
  256. /**
  257. * 户型关联案例
  258. */
  259. public function materialCase()
  260. {
  261. // $housetype_id = input('housetype_id',0);
  262. $housetype_id = $this->params['housetypeId'];
  263. $page = input('page',1,'intval');
  264. $limit = input('limit',10,'intval');
  265. if(!$housetype_id) return json(['code' => 0, 'data' => ['list'=>[]], 'msg' => '获取成功']);
  266. $info = Employee::where('id',$this->params['employeeId'])->field('id,org_id,uid')->find();
  267. $case_ids = BuildingMaterialCase::where([['housetype_id','=',$housetype_id],['root_id','=',$this->params['rootId']]])->column('material_case_id');
  268. if(empty($case_ids)) return json(['code' => 0, 'data' => ['list'=>[]], 'msg' => '获取成功']);
  269. $where[] = ['id', 'in', $case_ids];
  270. $list = MaterialCase::with(['designer' => function ($query) {
  271. $query->field('id,name, headimgurl,addtime');
  272. }, 'community' => function ($query) {
  273. $query->field('id,name');
  274. }, 'decostyle' => function ($query) {
  275. $query->field('id,name');
  276. }])->page((int)$page,(int)$limit)->where($where)->select()->toArray();
  277. //分享加密参数 店面id ,分享人id , 楼盘id , 户型id , 案例id , 在施工地id
  278. $aec = new Aec(config('app.aec_key'), config('app.aec_iv'));
  279. foreach ($list as $key => $val) {
  280. $ids = [$this->params['rootId'],$this->params['employeeId'],'','',$val['id'],''];
  281. $list[$key]['str'] = $aec->encrypt(implode('#',$ids));
  282. }
  283. $data = ['list'=> $list];
  284. $count = MaterialCase::where($where)->count();
  285. return json(['code' => 0, 'data' => $data,'count'=>$count, 'msg' => '获取成功']);
  286. }
  287. /**
  288. * 户型下的在施工地
  289. */
  290. public function construction(){
  291. $housetype_id = $this->params['housetypeId'];
  292. if(!$housetype_id) return json(['code' => 0, 'data' => [], 'msg' => '获取成功']);
  293. // $housetype_id = input('housetype_id', '', 'intval');
  294. $construction_str = BuildingHousetype::where('id',$housetype_id)->value('constructionid');
  295. $construction_id = !empty($construction_str) ? explode(',',$construction_str) : [];
  296. $where[] = ['id', 'in', $construction_id];
  297. $page = input('page', 1, 'intval');
  298. $limit = input('limit', 10, 'intval');
  299. $root_id = $this->params['rootId'];
  300. $where[] = ['root_id', '=', $root_id];
  301. $step_list = ConstructionStep::where('root_id', '=', $root_id)->order('order asc')->select()->toArray();
  302. $order_input = input('order', 'new', 'trim');
  303. $order = 'update_time desc';
  304. $model = ConstructionModel::with(['style', 'designer', 'housetype', 'community'])->withCount(['share_log'=> function ($query) {
  305. $query->where([['type', '=', 'construction']]);
  306. }]);
  307. $order = 'update_time desc';
  308. $list = $model->where($where)->page($page, $limit)->order($order)->select();
  309. //
  310. $list = $list->each(function ($item) use ($step_list) {
  311. $record_list = ConstructionRecord::where([['construction_id', '=', $item['id']]])->order('update_time desc')->select();
  312. $step_now = 0; //进行到哪一步了
  313. foreach ($step_list as $k => $v) {
  314. foreach ($record_list as $kk => $vv) {
  315. if ($v['id'] == $vv['step_id'] && $v['order'] > $step_now) {
  316. $step_now = $v['order'];
  317. }
  318. }
  319. }
  320. foreach ($step_list as $k => $v) {
  321. $step_list[$k]['upload'] = 0; // 判断是否上传
  322. $step_list[$k]['need_upload'] = 0; // 判断节点是否变色(已过此节点,但是没上传)
  323. $have = false; //是否有上传 true有
  324. $need_have = false; //没上传,但是后面的节点上传了 true是
  325. foreach ($record_list as $kk => $vv) {
  326. if ($v['id'] == $vv['step_id']) {
  327. $have = true;
  328. }
  329. }
  330. if ($have == false && $v['order'] < $step_now) {
  331. $need_have = true;
  332. }
  333. if ($have) {
  334. $step_list[$k]['upload'] = 1;
  335. } elseif ($need_have) {
  336. $step_list[$k]['need_upload'] = 1;
  337. }
  338. }
  339. $item->step_list = $step_list;
  340. })->toArray();
  341. //分享加密参数 店面id ,分享人id , 楼盘id , 户型id , 案例id , 在施工地id
  342. $aec = new Aec(config('app.aec_key'), config('app.aec_iv'));
  343. foreach ($list as $key => $val) {
  344. $ids = [$this->params['rootId'],$this->params['employeeId'],'','','',$val['id']];
  345. $list[$key]['str'] = $aec->encrypt(implode('#',$ids));
  346. }
  347. $count = $model->where($where)->count();
  348. return json(['code' => 0, 'data' => $list, 'count' => $count]);
  349. }
  350. /*
  351. * 案例列表 查看更多
  352. */
  353. public function caselist()
  354. {
  355. $param = input('');
  356. $order = (!isset($param['order']) || !$param['order']) ? 'addtime' : $param['order'];
  357. $desc = (!isset($param['desc']) || !$param['desc']) ? 'desc' : $param['desc'];
  358. // $order = $order . ' ' . $desc;
  359. $where[] = ['root_id', '=', $this->rootId];
  360. // 我上传的
  361. if (!empty($param['my_case'])) {
  362. switch ($param['my_case']) {
  363. case 'publish': //通过的
  364. $where[] = ['publish', '=', 1];
  365. $where[] = ['del', '=', 0];
  366. $where[] = ['employee_id', '=', $this->employeeId];
  367. $where[] = ['from', '=', 1];
  368. break;
  369. case 'all': //全部的
  370. $where[] = ['employee_id', '=', $this->employeeId];
  371. $where[] = ['from', '=', 1];
  372. break;
  373. default:
  374. $where[] = ['publish', '=', 1];
  375. $where[] = ['del', '=', 0];
  376. $where[] = ['employee_id', '=', $this->employeeId];
  377. $where[] = ['from', '=', 1];
  378. break;
  379. }
  380. } else {
  381. $where[] = ['del', '=', 0];
  382. $where[] = ['publish', '=', 1];
  383. }
  384. setCondition($param, ['commu_id', 'community_id'], '=', $where);
  385. setCondition($param, 'style_id', '=', $where);
  386. setCondition($param, ['square_start', 'square'], '>=', $where);
  387. setCondition($param, ['square_end', 'square'], '<', $where);
  388. setCondition($param, ['keyword', 'title'], ['like', '%VALUE%'], $where);
  389. setCondition($param, 'housetype_id', '=', $where);
  390. if (!empty($param['id'])) $where[] = ['designer_id', '=', $param['id']];
  391. if (!empty($param['case_type'])) {
  392. if ($param['case_type'] == 1) {
  393. $where[] = ['desc', '<>', ''];
  394. $where[] = ['desc', 'not null',''];
  395. }
  396. if ($param['case_type'] == 2) {
  397. $where[] = ['real_case', '<>', ''];
  398. $where[] = ['real_case', 'not null',''];
  399. }
  400. }
  401. $page = !empty($param['page']) ? $param['page'] : 1;
  402. $limit = !empty($param['limit']) ? $param['limit'] : 15;
  403. $list = MaterialCase::with(['designer' => function ($query) {
  404. $query->field('id,name, headimgurl,addtime');
  405. }, 'community' => function ($query) {
  406. $query->field('id,name');
  407. }, 'decostyle' => function ($query) {
  408. $query->field('id,name');
  409. }])->where($where);
  410. if ($order == 'clue_number' || empty($param['order'])) {
  411. $list = $list->order('addtime desc')->select()->toArray();
  412. } else {
  413. $list = $list->page($page, $limit)->order($order . ' ' . $desc)->select()->toArray();
  414. }
  415. $list_ids = array_column($list, 'id');
  416. $clue_number = CustomerClue::where([['pipe_type', '=', 'materialCase'], ['pipe_id', 'in', $list_ids]])->group('pipe_id')->column('count(id) as id_count', 'pipe_id');
  417. foreach ($list as &$item) {
  418. $item['clue_number'] = isset($clue_number[$item['id']]) ? $clue_number[$item['id']] : 0;
  419. }
  420. // 排序
  421. if ($order == 'clue_number') {
  422. $sort = $desc == 'desc' ? SORT_DESC : SORT_ASC;
  423. array_multisort(array_column($list, $order), $sort, array_column($list, 'addtime'), SORT_DESC, $list);
  424. $list = array_slice($list, ($page-1) * $limit, $limit);
  425. }
  426. // 默认排序 vr&video->vr->video->article
  427. if (empty($param['order'])){
  428. $new_list['vr_video'] = [];
  429. $new_list['vr'] = [];
  430. $new_list['video'] = [];
  431. $new_list['article'] = [];
  432. foreach ($list as $k => $v){
  433. if (!empty($v['vr_case']) && !empty($v['video_case'])){
  434. $new_list['vr_video'][] = $v;
  435. } elseif (!empty($v['vr_case'])){
  436. $new_list['vr'][] = $v;
  437. } elseif (!empty($v['video_case'])){
  438. $new_list['video'][] = $v;
  439. } else {
  440. $new_list['article'][] = $v;
  441. }
  442. }
  443. $all_list = [];
  444. foreach ($new_list as $k => $v){
  445. foreach ($v as $vv){
  446. $all_list[] = $vv;
  447. }
  448. }
  449. $list = array_slice($all_list, ($page-1) * $limit, $limit);
  450. }
  451. //分享加密参数 店面id ,分享人id , 楼盘id , 户型id , 案例id , 在施工地id
  452. $aec = new Aec(config('app.aec_key'), config('app.aec_iv'));
  453. foreach ($list as $key => $val) {
  454. $ids = [$this->params['rootId'],$this->params['employeeId'],'','',$val['id'],''];
  455. $list[$key]['str'] = $aec->encrypt(implode('#',$ids));
  456. }
  457. return json(['code' => 0, 'data' => $list, 'msg' => '获取成功']);
  458. }
  459. /**
  460. * 装修案例风格
  461. */
  462. public function decostylelist()
  463. {
  464. $styleArr = Decostyle::where(['root_id' => $this->rootId])->where([['type', '=', 0]])->field('id, name')->select();
  465. return json(['code' => 0, 'data' => $styleArr, 'msg' => '获取成功']);
  466. }
  467. /*
  468. * 装修案例户型
  469. */
  470. public function housetypelist()
  471. {
  472. $housetypeArr = Housetype::where(['root_id' => $this->rootId])->field('id,name')->select();
  473. return json(['code' => 0, 'data' => $housetypeArr, 'msg' => '获取成功']);
  474. }
  475. /**
  476. * 装修案例小区列表
  477. */
  478. public function communitylist()
  479. {
  480. $name = input('name', '', 'trim');
  481. if ($name) {
  482. $where[] = ['name', 'like', '%' . $name . '%'];
  483. }
  484. $from = input('from', '', 'trim');
  485. $where[] = ['type', '=', 0];
  486. $where[] = ['root_id', '=', $this->rootId];
  487. $communityArr = Community::where($where)->field('id,name,pinyin,case_num')->order('pinyin asc')->select()->toArray();
  488. $comidlist = array_column($communityArr, 'id');
  489. $caseData = MaterialCase::where([['community_id', 'in', $comidlist], ['del', '=', 0], ['publish', '=', 1]])->group('community_id')->order('updatetime asc')->column('max(updatetime) as updatetime, sum(shared_times) as shared_times, count(id) as case_num', 'community_id');
  490. // 个人上传装修案例,数量显示为此小区下此员工上传的数量
  491. if ($from) {
  492. foreach ($caseData as $k => $v) {
  493. $caseData[$k]['case_num'] = MaterialCase::where([['community_id', '=', $v['community_id']], ['from', '=', 1], ['employee_id', '=', request()->token['employee_id']]])->count();
  494. }
  495. }
  496. foreach ($communityArr as &$i) {
  497. if (isset($caseData[$i['id']])) {
  498. $i['updatetime'] = $caseData[$i['id']]['updatetime'];
  499. $i['shared_times'] = (int)$caseData[$i['id']]['shared_times'];
  500. $i['case_num'] = (int)$caseData[$i['id']]['case_num'];
  501. } else {
  502. $i['updatetime'] = 0;
  503. $i['shared_times'] = 0;
  504. $i['case_num'] = 0;
  505. }
  506. }
  507. return json(['code' => 0, 'data' => $communityArr, 'msg' => '获取成功']);
  508. }
  509. public function constructionList()
  510. {
  511. $page = input('page', 1, 'intval');
  512. $limit = input('limit', 10, 'intval');
  513. $root_id = $this->rootId;
  514. $where[] = ['root_id', '=', $root_id];
  515. //2023-02-06增加审核字段
  516. $where[] = ['status','=',1];
  517. $where[] = ['del','=',0];
  518. $community_id = input('community_id', '', 'intval');
  519. if ($community_id) {
  520. $where[] = ['community_id', '=', $community_id];
  521. }
  522. $step_list = ConstructionStep::where('root_id', '=', $root_id)->order('order asc')->select()->toArray();
  523. $order_input = input('order', 'new', 'trim');
  524. $order = 'id desc';
  525. $model = ConstructionModel::with(['style', 'designer', 'housetype', 'community'])->withCount(['share_log'=> function ($query) {
  526. $query->where([['type', '=', 'construction']]);
  527. }]);
  528. if ($order_input == 'new'){
  529. $order = 'update_time desc';
  530. } else if ($order_input = 'hot') {
  531. $order = 'share_log_count desc';
  532. }
  533. $list = $model->where($where)->page($page, $limit)->order($order)->select()->each(function ($item) use ($step_list) {
  534. $record_list = ConstructionRecord::where([['construction_id', '=', $item['id']]])->order('update_time desc')->select();
  535. $step_now = 0; //进行到哪一步了
  536. foreach ($step_list as $k => $v) {
  537. foreach ($record_list as $kk => $vv) {
  538. if ($v['id'] == $vv['step_id'] && $v['order'] > $step_now) {
  539. $step_now = $v['order'];
  540. }
  541. }
  542. }
  543. foreach ($step_list as $k => $v) {
  544. $step_list[$k]['upload'] = 0; // 判断是否上传
  545. $step_list[$k]['need_upload'] = 0; // 判断节点是否变色(已过此节点,但是没上传)
  546. $have = false; //是否有上传 true有
  547. $need_have = false; //没上传,但是后面的节点上传了 true是
  548. foreach ($record_list as $kk => $vv) {
  549. if ($v['id'] == $vv['step_id']) {
  550. $have = true;
  551. }
  552. }
  553. if ($have == false && $v['order'] < $step_now) {
  554. $need_have = true;
  555. }
  556. if ($have) {
  557. $step_list[$k]['upload'] = 1;
  558. } elseif ($need_have) {
  559. $step_list[$k]['need_upload'] = 1;
  560. }
  561. }
  562. $item->step_list = $step_list;
  563. });
  564. //分享加密参数 店面id ,分享人id , 楼盘id , 户型id , 案例id , 在施工地id
  565. $aec = new Aec(config('app.aec_key'), config('app.aec_iv'));
  566. foreach ($list as $key => $val) {
  567. $ids = [$this->params['rootId'],$this->params['employeeId'],'','','',$val['id']];
  568. $list[$key]['str'] = $aec->encrypt(implode('#',$ids));
  569. }
  570. return json(['code' => 0, 'data' => $list->toArray(), 'count' => $list->count()]);
  571. }
  572. /**
  573. * 装修案例
  574. */
  575. public function casedetail()
  576. {
  577. $id = $this->params['caseId'];
  578. if(!$id) return json(['code' => 0, 'data' => [], 'msg' => '获取成功']);
  579. $token['employee_id'] = $this->employeeId;
  580. $token['root_org'] = $this->rootId;
  581. $data = MaterialCase::with([
  582. 'community',
  583. 'designer',
  584. 'decostyle',
  585. 'housetype'
  586. ])->where(['id' => $id, 'root_id' => $token['root_org']])->find();
  587. MaterialCase::where(['id' => $id, 'root_id' => $token['root_org']])->inc('view_times')->update();
  588. // 关联案例
  589. if (!empty($data['designer_id'])){
  590. $relatedcaselist = MaterialCase::where([['designer_id', '=', $data['designer_id']],['id', '<>', $id], ['root_id', '=', $token['root_org']], ['del', '=', 0], ['publish', '=', 1]])
  591. ->with(['community' => function ($query) {
  592. $query->field('id,name');
  593. }, 'decostyle' => function ($query) {
  594. $query->field('id,name');
  595. }])->page(1, 4)->order('id desc')->select()->each(function ($item) {
  596. $item->clue_number = CustomerClue::where([['pipe_type', '=', 'materialCase'], ['pipe_id', '=', $item['id']]])->count();
  597. })->toArray();
  598. } else {
  599. $relatedcaselist = [];
  600. }
  601. $data['designer_related_cases'] = $relatedcaselist;
  602. //设计师附属字段
  603. if ($data->designer) {
  604. $designer = Designer::where([['employee_id', '=', $data->designer_id], ['root_id', '=', $token['root_org']]])->field('id,good_at,position')->findOrEmpty();
  605. if ($designer->isEmpty()) {
  606. $data->designer->good_at = '';
  607. $data->designer->position = '';
  608. } else {
  609. $data->designer->good_at = !empty($designer->good_at) ? $designer->good_at : '';
  610. $data->designer->position = $designer->position ? $designer->position : '';
  611. }
  612. $data->designer->headimgurl = User::where('id', '=', $data->designer->uid)->value('headimgurl');
  613. }
  614. // 为null处理,防止前端报错
  615. $data['real_case'] = !is_null($data['real_case']) ? $data['real_case'] : '';
  616. $data['desc'] = !is_null($data['desc']) ? $data['desc'] : '';
  617. $data['vr_case'] = !is_null($data['vr_case']) ? $data['vr_case'] : '';
  618. return json(['code' => 0, 'data' => $data, 'msg' => '获取成功']);
  619. }
  620. //在施工地详情
  621. public function constrationView()
  622. {
  623. $id = $this->params['constructionId'];
  624. if(!$id) return json(['code' => 0, 'data' => [], 'msg' => '获取成功']);
  625. $share = input('share', '', 'trim');
  626. $info = ConstructionModel::with(['style', 'designer', 'housetype', 'community'])->find($id);
  627. $root_id = $this->rootId;
  628. $step_list = ConstructionStep::where('root_id', '=', $root_id)->order('order asc')->select()->toArray();
  629. $record_list = ConstructionRecord::where([['construction_id', '=', $id]])->order('update_time desc')->select();
  630. $step_now = 0; //进行到哪一步了
  631. foreach ($step_list as $k => $v) {
  632. foreach ($record_list as $kk => $vv) {
  633. if ($v['id'] == $vv['step_id'] && $v['order'] > $step_now) {
  634. $step_now = $v['order'];
  635. }
  636. }
  637. }
  638. $vrObj = new Vr();
  639. foreach ($step_list as $k => $v) {
  640. $step_list[$k]['upload'] = 0; // 判断是否上传
  641. $step_list[$k]['need_upload'] = 0; // 判断节点是否变色(已过此节点,但是没上传)
  642. $have = false; //是否有上传 true有
  643. $need_have = false; //没上传,但是后面的节点上传了 true是
  644. $step_list[$k]['data'] = [];
  645. foreach ($record_list as $kk => $vv) {
  646. if ($v['id'] == $vv['step_id']) {
  647. $have = true;
  648. if (!empty($vv['vr']) && $vv['type'] == 'vr') {
  649. $vrUrlList = explode(',', $vv['vr']);
  650. $vrData = [];
  651. foreach ($vrUrlList as $url) {
  652. $vrData[] = [
  653. 'vrUrl' => $url,
  654. 'vrfirstImg' => $vrObj->getFirstImg($url)
  655. ];
  656. }
  657. $vv['vr'] = $vrData;
  658. }
  659. $step_list[$k]['data'] = $vv;
  660. }
  661. }
  662. if ($have == false && $v['order'] < $step_now) {
  663. $need_have = true;
  664. }
  665. if ($have) {
  666. $step_list[$k]['upload'] = 1;
  667. } elseif ($need_have) {
  668. $step_list[$k]['need_upload'] = 1;
  669. }
  670. }
  671. $info['step_list'] = $step_list;
  672. return json(['code'=> 0, 'msg'=> '请求成功', 'data'=> $info]);
  673. }
  674. }