Building.php 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881
  1. <?php
  2. declare(strict_types=1);
  3. namespace app\mobile\controller;
  4. use app\model\Employee;
  5. use app\model\User;
  6. use think\facade\Request;
  7. use app\model\Building as BuildingModel;
  8. use app\model\BuildingSpecialEmp;
  9. use app\model\BuildingHousetype;
  10. use app\model\UserCollect;
  11. use xiaohongwu\Vr;
  12. use app\model\BuildingProgress;
  13. use app\model\Company;
  14. use app\model\Decostyle;
  15. use app\model\ConstructionStep;
  16. use app\model\Construction as ConstructionModel;
  17. use app\model\ConstructionRecord;
  18. use app\model\BuildingMaterialCase;
  19. use app\model\Community;
  20. use app\model\CustomerClue;
  21. use app\model\BuildingHousetypeCollect;
  22. use app\model\MaterialCase;
  23. use app\model\Housetype;
  24. use app\model\Designer;
  25. use toolkits\Aec;
  26. use app\model\Miniprogram;
  27. use app\model\VrGroup;
  28. use app\model\VrView;
  29. use app\model\BuildingLabel as ModelBuildingLabel;
  30. class Building extends Base
  31. {
  32. /**
  33. * 楼书列表
  34. */
  35. public function index()
  36. {
  37. $param = Request::only(['order'=>'new','name'=>'','page'=>1,'limit'=>10,'collect'=>0]);
  38. $order = $param['order']=='new' ? 'update_time desc' : 'share_log_count desc';
  39. $model = BuildingModel::with(['share_log'])->withCount(['share_log' => function ($query) {
  40. $query->where([['type', '=', 'Building']]);
  41. }]);
  42. $where[] = ['root_id', '=', $this->rootId];
  43. $where[] = ['del', '=', 0];
  44. if ($param['name']) {
  45. $condition = [
  46. ['root_id', '=', $this->rootId],
  47. ['type', '=', 0],
  48. ['name', 'like', '%' . $param['name'] . '%']
  49. ];
  50. $community_id = Community::where($condition)->column('id');
  51. $where[] = ['community_id', 'in', $community_id];
  52. }
  53. //查询收藏
  54. if ($param['collect']) {
  55. $bids = UserCollect::where([['user_id','=',$this->uid],['content_type','=','building']])->column('content_id');
  56. if(empty($bids)) return json(['code' => 0, 'data' => []]);
  57. $where[] = ['id','in',$bids];
  58. }
  59. //权限区分 设置可见人可以查看全部 否则 查询指派给我的 和 没有指派的
  60. $special=BuildingSpecialEmp::where([['root_id','=',$this->rootId],['assign_employee','find in set',$this->employeeId]])->field('id')->findOrEmpty();
  61. $info = Employee::where('id',$this->employeeId)->field('id,org_id,uid')->find();
  62. if ($special->isEmpty()) {
  63. $where1 = array_merge($where,[['assign_employee','find in set',$this->employeeId]]);
  64. $where2 = array_merge($where,[['from','=',0],['assign_employee','null',null]]);
  65. $where3 = array_merge($where,[['from','=',1],['org_id','=',$info->org_id]]);
  66. $model = $model->whereOr([$where1,$where2,$where3]);
  67. }else{
  68. $model = $model->where($where);
  69. }
  70. $list = $model->page((int)$param['page'],(int)$param['limit'])->order($order)->select()->each(function ($item) use($info) {
  71. $area_list = BuildingHousetype::where('building_id', '=', $item['id'])->order('area asc')->column('area');
  72. $item->area_list = array_values(array_unique(array_filter($area_list)));
  73. $collectedIds = UserCollect::where(['user_id' => $info->uid, 'content_type' => 'building'])->column('content_id');
  74. if (in_array($item['id'], $collectedIds)) {
  75. $item['collected'] = true;
  76. } else {
  77. $item['collected'] = false;
  78. }
  79. })->toArray();
  80. return json(['code' => 0, 'data' => $list]);
  81. }
  82. /**
  83. * 楼书详情
  84. */
  85. public function view()
  86. {
  87. $param = Request::only(['id'=>0]);
  88. $info = BuildingModel::where([['root_id','=',$this->rootId],['id','=',$param['id']]])->findOrEmpty();
  89. if($info->isEmpty()) return json(['code' => 1, 'msg' => '数据不存在']);
  90. $id = $param['id'];
  91. $area_list = BuildingHousetype::where('building_id', '=', $id)->order('area asc')->column('area');
  92. $info['area_list'] = array_values(array_unique(array_filter($area_list)));
  93. $company = Company::where('root_id', '=', $info->root_id)->field(['company_name', 'logo'])->find();
  94. $info['company_name'] = $company['company_name'];
  95. $info['company_logo'] = $company['logo'];
  96. //小区户型
  97. $housetype = BuildingHousetype::with(['devcase'=>function($query){
  98. $query->field('housetype_id,id,name,type,vr_link,content,cover,decostyles_id');
  99. }])->where('building_id', '=', $id)->withCount(['materialCase'])->select()->toArray();
  100. $aec = new Aec(config('app.aec_key'), config('app.aec_iv'));
  101. foreach ($housetype as $key => $value) {
  102. //分享加密参数 店面id ,分享人id , 楼盘id , 户型id , 案例id , 在施工地id
  103. $ids = [$this->rootId,$this->employeeId,$param['id'],$value['id'],'',''];
  104. $housetype[$key]['str'] = $aec->encrypt(implode('#',$ids));
  105. }
  106. $xin = null;
  107. $vrObj = new Vr();
  108. if(!empty($housetype)){
  109. $houselist=$housetype;
  110. foreach($houselist as $key=>$val){
  111. if(empty($val['house_img']) && !empty($val['vr_link'])){
  112. $houselist[$key]['house_img'][] = $vrObj->getFirstImg($val['vr_link']);
  113. }
  114. if(empty($val['devcase'])) continue;
  115. foreach($val['devcase'] as $k=>$v){
  116. $houselist[$key]['devcase'][$k]['decostyles_name']=Decostyle::where('id',$v['decostyles_id'])->value('name');
  117. $houselist[$key]['devcase'][$k]['area']=$val['area'];
  118. $houselist[$key]['devcase'][$k]['room']=$val['room'];
  119. $houselist[$key]['devcase'][$k]['hall']=$val['hall'];
  120. $houselist[$key]['devcase'][$k]['bathroom']=$val['bathroom'];
  121. if($v['type']==1){
  122. $houselist[$key]['devcase'][$k]['cover'] = $vrObj->getFirstImg($v['vr_link']);
  123. }
  124. }
  125. }
  126. foreach($houselist as $key => $val){
  127. $xin[$val['room']][] = $val;
  128. }
  129. $xin[0] = $houselist;
  130. }
  131. $info['vr_link_cover']='';
  132. if(!empty($info['vr_link'])){
  133. $info['vr_link_cover']=$vrObj->getFirstImg($info['vr_link']);
  134. }
  135. $info['housetype'] = $xin;
  136. $info['housetype_count'] = count($housetype);
  137. $emp = Employee::where('id',$this->employeeId)->field('id,org_id,uid')->find();
  138. $collectedIds = UserCollect::where(['user_id' => $emp->uid, 'content_type' => 'building','content_id'=>$info['id']])->count();
  139. if ($collectedIds) {
  140. $info['collected'] = true;
  141. } else {
  142. $info['collected'] = false;
  143. }
  144. //增加进度图片视频VR数量查询
  145. $prtype_list = BuildingProgress::where([['building_id', '=', $id]])->field('count(*) as count,type')->group('type')->select()->toArray();
  146. $info['prtype_list']=!empty($prtype_list)?$prtype_list:null;
  147. //分享加密参数 店面id ,分享人id , 楼盘id , 户型id , 案例id , 在施工地id
  148. $ids = [$this->rootId,$this->employeeId,$param['id'],'','',''];
  149. $value = $aec->encrypt(implode('#',$ids));
  150. if (empty($info->vr_link) && $info->vr_group_ids) {
  151. $info->vr_link = config('app.vr_show_domain').VrGroup::where('id',$info->vr_group_ids)->value('sid');
  152. }
  153. return json(['code' => 0, 'data' => $info,'str'=>$value]);
  154. }
  155. /**
  156. * 楼盘进度
  157. */
  158. public function progress()
  159. {
  160. $id = input('id', '', 'intval');
  161. $type = input('type','','trim');
  162. $where[]=['building_id', '=', $id];
  163. if(!empty($type)){
  164. $where[]=['type', '=', $type];
  165. }
  166. $page = input('page',1);
  167. $limit = input('limit',3);
  168. $label_id = input('label_id',0);
  169. if($label_id) $where[] = ['label_id','=',$label_id];
  170. $list = BuildingProgress::where($where)->page((int)$page,(int)$limit)->order('addtime desc')->select();
  171. if (empty($list)) $list = [];
  172. else $list = $list->toArray();
  173. $vrObj = new Vr();
  174. foreach ($list as &$item) {
  175. $vrData = [];
  176. if ($item['type']=='vr' && $item['vr']) {
  177. $vrUrlList = explode(',', $item['vr']);
  178. foreach ($vrUrlList as $url) {
  179. $vrData[] = [
  180. 'vrUrl' => $url,
  181. 'vrfirstImg' => $vrObj->getFirstImg($url)
  182. ];
  183. }
  184. }elseif ($item['type']=='group' && $item['vr_group_ids']) {
  185. $url = config('app.vr_show_domain');
  186. $vrgroup = VrGroup::where('id',$item['vr_group_ids'])->field('id,pic_path,sid')->findOrEmpty();
  187. $item['show_url'] = '';
  188. $item['show_img'] = '';
  189. if (!$vrgroup->isEmpty()) {
  190. $item['show_url'] = $url.$vrgroup->sid;
  191. $item['show_img'] = $vrgroup->pic_path;
  192. }
  193. }
  194. $item['vr'] = $vrData;
  195. }
  196. return json(['code' => 0, 'data' => $list]);
  197. }
  198. /**
  199. * 户型下的在施工地
  200. */
  201. public function construction(){
  202. //$building_id = input('building_id', '', 'intval');
  203. //$construction_id = BuildingConstruction::where('building_id', '=', $building_id)->column('construction_id');
  204. //$where[] = ['id', 'in', $construction_id];
  205. $housetype_id = input('housetype_id', '', 'intval');
  206. $construction_str = BuildingHousetype::where('id',$housetype_id)->value('constructionid');
  207. $construction_id = !empty($construction_str) ? explode(',',$construction_str) : [];
  208. $where[] = ['id', 'in', $construction_id];
  209. $page = input('page', 1, 'intval');
  210. $limit = input('limit', 10, 'intval');
  211. $root_id = $this->rootId;
  212. $where[] = ['root_id', '=', $root_id];
  213. $community_id = input('community_id', '', 'intval');
  214. if ($community_id) {
  215. $where[] = ['community_id', '=', $community_id];
  216. }
  217. $step_list = ConstructionStep::where('root_id', '=', $root_id)->order('order asc')->select()->toArray();
  218. $order_input = input('order', 'new', 'trim');
  219. $order = 'update_time desc';
  220. $model = ConstructionModel::with(['style', 'designer', 'housetype', 'community'])->withCount(['share_log'=> function ($query) {
  221. $query->where([['type', '=', 'construction']]);
  222. }]);
  223. if ($order_input == 'new'){
  224. $order = 'update_time desc';
  225. $list = $model->where($where)->page($page, $limit)->order($order)->select();
  226. } else if ($order_input == 'hot') {
  227. $list = $model->where($where)->order($order)->select();
  228. }
  229. $list = $list->each(function ($item) use ($step_list) {
  230. $record_list = ConstructionRecord::where([['construction_id', '=', $item['id']]])->order('update_time desc')->select();
  231. $step_now = 0; //进行到哪一步了
  232. foreach ($step_list as $k => $v) {
  233. foreach ($record_list as $kk => $vv) {
  234. if ($v['id'] == $vv['step_id'] && $v['order'] > $step_now) {
  235. $step_now = $v['order'];
  236. }
  237. }
  238. }
  239. foreach ($step_list as $k => $v) {
  240. $step_list[$k]['upload'] = 0; // 判断是否上传
  241. $step_list[$k]['need_upload'] = 0; // 判断节点是否变色(已过此节点,但是没上传)
  242. $have = false; //是否有上传 true有
  243. $need_have = false; //没上传,但是后面的节点上传了 true是
  244. foreach ($record_list as $kk => $vv) {
  245. if ($v['id'] == $vv['step_id']) {
  246. $have = true;
  247. }
  248. }
  249. if ($have == false && $v['order'] < $step_now) {
  250. $need_have = true;
  251. }
  252. if ($have) {
  253. $step_list[$k]['upload'] = 1;
  254. } elseif ($need_have) {
  255. $step_list[$k]['need_upload'] = 1;
  256. }
  257. }
  258. $item->step_list = $step_list;
  259. //收藏状态
  260. $user_id = $this->uid;
  261. $had = UserCollect::where(['user_id' => $user_id , 'content_type' => 'construction' , 'content_id' => $item['id']])->count();
  262. if ($had) {
  263. $item['collect'] = 1;
  264. } else {
  265. $item['collect'] = 0;
  266. }
  267. })->toArray();
  268. if ($order_input == 'hot') {
  269. $list_all = $list;
  270. $share_log_count = array_column($list_all, 'share_log_count');
  271. array_multisort($share_log_count, SORT_DESC, $list_all);
  272. $list = array_slice($list_all, $limit*($page-1), $limit);
  273. }
  274. $count = $model->where($where)->count();
  275. return json(['code' => 0, 'data' => $list, 'count' => $count]);
  276. }
  277. /**
  278. * 户型关联案例
  279. */
  280. public function material_case()
  281. {
  282. $housetype_id = input('housetype_id',0);
  283. $page = input('page',1,'intval');
  284. $limit = input('limit',10,'intval');
  285. $info = Employee::where('id',$this->employeeId)->field('id,org_id,uid')->find();
  286. $case_ids = BuildingMaterialCase::where([['housetype_id','=',$housetype_id],['root_id','=',$this->rootId]])->column('material_case_id');
  287. if(empty($case_ids)) return json(['code' => 0, 'data' => ['list'=>[]], 'msg' => '获取成功']);
  288. $where[] = ['id', 'in', $case_ids];
  289. $list = MaterialCase::with(['designer' => function ($query) {
  290. $query->field('id,name, headimgurl,addtime');
  291. }, 'community' => function ($query) {
  292. $query->field('id,name');
  293. }, 'decostyle' => function ($query) {
  294. $query->field('id,name');
  295. }])->page($page,$limit)->where($where)->select();
  296. $collectedIds = UserCollect::where(['user_id' => $info->uid, 'content_type' => 'materialCase'])->column('content_id');
  297. $aec = new Aec(config('app.aec_key'), config('app.aec_iv'));
  298. foreach ($list as &$item) {
  299. if (in_array($item['id'], $collectedIds)) {
  300. $item['collected'] = true;
  301. } else {
  302. $item['collected'] = false;
  303. }
  304. //分享加密参数 店面id ,分享人id , 楼盘id , 户型id , 案例id , 在施工地id
  305. $ids = [$this->rootId,$this->employeeId,'','',$item['id'],''];
  306. $item['str'] = $aec->encrypt(implode('#',$ids));
  307. }
  308. $data = ['list'=> $list];
  309. $count = MaterialCase::where($where)->count();
  310. return json(['code' => 0, 'data' => $data,'count'=>$count, 'msg' => '获取成功']);
  311. }
  312. /**
  313. * 收藏
  314. */
  315. public function collect()
  316. {
  317. $id = input('id',0);
  318. $user_id = $this->uid;
  319. $had = UserCollect::where(['user_id' => $user_id, 'content_type' => 'building', 'content_id' => $id])->count();
  320. if ($had > 0) return json(['code' => 1, 'msg' => '您已收藏']);
  321. UserCollect::insert(['user_id' => $user_id, 'content_type' => 'building', 'content_id' => $id]);
  322. return json(['code' => 0, 'msg' => '收藏成功']);
  323. }
  324. /**
  325. * 取消收藏
  326. */
  327. public function collectCancel($id)
  328. {
  329. $user_id = $this->uid;
  330. UserCollect::where(['user_id' => $user_id, 'content_type' => 'building', 'content_id' => $id])->delete();
  331. return json(['code' => 0, 'msg' => '取消收藏']);
  332. }
  333. //户型详情
  334. public function housetype_detail()
  335. {
  336. $id = input('id', '', 'intval');
  337. if(empty($id)) return json(['code'=> 1,'msg'=> '参数错误']);
  338. $data = BuildingHousetype::find($id);
  339. $data['new_orientation'] = $data->getData('orientation');
  340. $data['vr_link_img'] = '';
  341. if (!empty($data['vr_link'])) {
  342. $vrObj = new Vr();
  343. $data['vr_link_img'] = getFirstImg($data['vr_link']);
  344. }
  345. //查询楼盘地址和小区
  346. $bulid = BuildingModel::where('id',$data->building_id)->field('community_id,address')->findOrEmpty();
  347. if (!$bulid->isEmpty()){
  348. $bulid->community = $bulid->community_id ? Community::where('id',$bulid->community_id)->value('name') : '';
  349. }
  350. //是否收藏
  351. $where = [
  352. ['root_id','=',$this->rootId],
  353. ['employee_id','=',$this->employeeId],
  354. ['building_id','=',$data->building_id],
  355. ['building_housetype_id','=',$id],
  356. ['type','=',1]
  357. ];
  358. $data->is_collect = BuildingHousetypeCollect::where($where)->value('id') ? 1 : 0;
  359. //分享加密参数 店面id ,分享人id , 楼盘id , 户型id , 案例id , 在施工地id
  360. $ids = [$this->rootId,$this->employeeId,'',$id,'',''];
  361. $aec = new Aec(config('app.aec_key'), config('app.aec_iv'));
  362. $value = $aec->encrypt(implode('#',$ids));
  363. if (empty($data->vr_link) && $data->vr_group_ids) {
  364. $group = VrGroup::where('id',$data->vr_group_ids)->field('sid,pic_path')->find();
  365. $data->vr_link = config('app.vr_show_domain').$group->sid;
  366. $data->vr_link_img = $group->pic_path;
  367. }
  368. return json(['code'=> 0, 'data'=> $data,'bulid'=>$bulid, 'msg'=> '获取成功','str'=>$value]);
  369. }
  370. /*
  371. * 案例列表
  372. */
  373. public function caselist()
  374. {
  375. $param = input('');
  376. $order = (!isset($param['order']) || !$param['order']) ? 'addtime' : $param['order'];
  377. $desc = (!isset($param['desc']) || !$param['desc']) ? 'desc' : $param['desc'];
  378. // $order = $order . ' ' . $desc;
  379. $where[] = ['root_id', '=', $this->rootId];
  380. // 我上传的
  381. if (!empty($param['my_case'])) {
  382. switch ($param['my_case']) {
  383. case 'publish': //通过的
  384. $where[] = ['publish', '=', 1];
  385. $where[] = ['del', '=', 0];
  386. $where[] = ['employee_id', '=', $this->employeeId];
  387. $where[] = ['from', '=', 1];
  388. break;
  389. case 'all': //全部的
  390. $where[] = ['employee_id', '=', $this->employeeId];
  391. $where[] = ['from', '=', 1];
  392. break;
  393. default:
  394. $where[] = ['publish', '=', 1];
  395. $where[] = ['del', '=', 0];
  396. $where[] = ['employee_id', '=', $this->employeeId];
  397. $where[] = ['from', '=', 1];
  398. break;
  399. }
  400. } else {
  401. $where[] = ['del', '=', 0];
  402. $where[] = ['publish', '=', 1];
  403. }
  404. setCondition($param, ['commu_id', 'community_id'], '=', $where);
  405. setCondition($param, 'style_id', '=', $where);
  406. setCondition($param, ['square_start', 'square'], '>=', $where);
  407. setCondition($param, ['square_end', 'square'], '<', $where);
  408. setCondition($param, ['keyword', 'title'], ['like', '%VALUE%'], $where);
  409. setCondition($param, 'housetype_id', '=', $where);
  410. if (!empty($param['id'])) $where[] = ['designer_id', '=', $param['id']];
  411. if (!empty($param['case_type'])) {
  412. if ($param['case_type'] == 1) {
  413. $where[] = ['desc', '<>', ''];
  414. $where[] = ['desc', 'not null',''];
  415. }
  416. if ($param['case_type'] == 2) {
  417. $where[] = ['real_case', '<>', ''];
  418. $where[] = ['real_case', 'not null',''];
  419. }
  420. }
  421. $page = !empty($param['page']) ? $param['page'] : 1;
  422. $limit = !empty($param['limit']) ? $param['limit'] : 15;
  423. $list = MaterialCase::with(['designer' => function ($query) {
  424. $query->field('id,name, headimgurl,addtime');
  425. }, 'community' => function ($query) {
  426. $query->field('id,name');
  427. }, 'decostyle' => function ($query) {
  428. $query->field('id,name');
  429. }])->where($where);
  430. if ($order == 'clue_number' || empty($param['order'])) {
  431. $list = $list->order('addtime desc')->select()->toArray();
  432. } else {
  433. $list = $list->page($page, $limit)->order($order . ' ' . $desc)->select()->toArray();
  434. }
  435. $collectedIds = UserCollect::where(['user_id' => $this->uid, 'content_type' => 'materialCase'])->column('content_id');
  436. $list_ids = array_column($list, 'id');
  437. $clue_number = CustomerClue::where([['pipe_type', '=', 'materialCase'], ['pipe_id', 'in', $list_ids]])->group('pipe_id')->column('count(id) as id_count', 'pipe_id');
  438. foreach ($list as &$item) {
  439. if (in_array($item['id'], $collectedIds)) {
  440. $item['collected'] = true;
  441. } else {
  442. $item['collected'] = false;
  443. }
  444. $item['clue_number'] = isset($clue_number[$item['id']]) ? $clue_number[$item['id']] : 0;
  445. }
  446. // 排序
  447. if ($order == 'clue_number') {
  448. $sort = $desc == 'desc' ? SORT_DESC : SORT_ASC;
  449. array_multisort(array_column($list, $order), $sort, array_column($list, 'addtime'), SORT_DESC, $list);
  450. $list = array_slice($list, ($page-1) * $limit, $limit);
  451. }
  452. // 默认排序 vr&video->vr->video->article
  453. if (empty($param['order'])){
  454. $new_list['vr_video'] = [];
  455. $new_list['vr'] = [];
  456. $new_list['video'] = [];
  457. $new_list['article'] = [];
  458. $aec = new Aec(config('app.aec_key'), config('app.aec_iv'));
  459. foreach ($list as $k => $v){
  460. //分享加密参数 店面id ,分享人id , 楼盘id , 户型id , 案例id , 在施工地id
  461. $ids = [$this->rootId,$this->employeeId,'','',$v['id'],''];
  462. $v['str'] = $aec->encrypt(implode('#',$ids));
  463. if (!empty($v['vr_case']) && !empty($v['video_case'])){
  464. $new_list['vr_video'][] = $v;
  465. } elseif (!empty($v['vr_case'])){
  466. $new_list['vr'][] = $v;
  467. } elseif (!empty($v['video_case'])){
  468. $new_list['video'][] = $v;
  469. } else {
  470. $new_list['article'][] = $v;
  471. }
  472. }
  473. $all_list = [];
  474. foreach ($new_list as $k => $v){
  475. foreach ($v as $vv){
  476. $all_list[] = $vv;
  477. }
  478. }
  479. $list = array_slice($all_list, ($page-1) * $limit, $limit);
  480. }
  481. return json(['code' => 0, 'data' => $list, 'msg' => '获取成功']);
  482. }
  483. /**
  484. * 装修案例风格
  485. */
  486. public function decostylelist()
  487. {
  488. $styleArr = Decostyle::where(['root_id' => $this->rootId])->where([['type', '=', 0]])->field('id, name')->select();
  489. return json(['code' => 0, 'data' => $styleArr, 'msg' => '获取成功']);
  490. }
  491. /*
  492. * 装修案例户型
  493. */
  494. public function housetypelist()
  495. {
  496. $housetypeArr = Housetype::where(['root_id' => $this->rootId])->field('id,name')->select();
  497. return json(['code' => 0, 'data' => $housetypeArr, 'msg' => '获取成功']);
  498. }
  499. /**
  500. * 装修案例小区列表
  501. */
  502. public function communitylist()
  503. {
  504. $name = input('name', '', 'trim');
  505. if ($name) {
  506. $where[] = ['name', 'like', '%' . $name . '%'];
  507. }
  508. $from = input('from', '', 'trim');
  509. $where[] = ['type', '=', 0];
  510. $where[] = ['root_id', '=', $this->rootId];
  511. $communityArr = Community::where($where)->field('id,name,pinyin,case_num')->order('pinyin asc')->select()->toArray();
  512. $comidlist = array_column($communityArr, 'id');
  513. $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');
  514. // 个人上传装修案例,数量显示为此小区下此员工上传的数量
  515. if ($from) {
  516. foreach ($caseData as $k => $v) {
  517. $caseData[$k]['case_num'] = MaterialCase::where([['community_id', '=', $v['community_id']], ['from', '=', 1], ['employee_id', '=', request()->token['employee_id']]])->count();
  518. }
  519. }
  520. foreach ($communityArr as &$i) {
  521. if (isset($caseData[$i['id']])) {
  522. $i['updatetime'] = $caseData[$i['id']]['updatetime'];
  523. $i['shared_times'] = (int)$caseData[$i['id']]['shared_times'];
  524. $i['case_num'] = (int)$caseData[$i['id']]['case_num'];
  525. } else {
  526. $i['updatetime'] = 0;
  527. $i['shared_times'] = 0;
  528. $i['case_num'] = 0;
  529. }
  530. }
  531. return json(['code' => 0, 'data' => $communityArr, 'msg' => '获取成功']);
  532. }
  533. public function constructionList()
  534. {
  535. $page = input('page', 1, 'intval');
  536. $limit = input('limit', 10, 'intval');
  537. $root_id = $this->rootId;
  538. $where[] = ['root_id', '=', $root_id];
  539. //2023-02-06增加审核字段
  540. $where[] = ['status','=',1];
  541. $where[] = ['del','=',0];
  542. $community_id = input('community_id', '', 'intval');
  543. if ($community_id) {
  544. $where[] = ['community_id', '=', $community_id];
  545. }
  546. $step_list = ConstructionStep::where('root_id', '=', $root_id)->order('order asc')->select()->toArray();
  547. $order_input = input('order', 'new', 'trim');
  548. $order = 'id desc';
  549. $model = ConstructionModel::with(['style', 'designer', 'housetype', 'community'])->withCount(['share_log'=> function ($query) {
  550. $query->where([['type', '=', 'construction']]);
  551. }]);
  552. if ($order_input == 'new'){
  553. $order = 'update_time desc';
  554. } else if ($order_input = 'hot') {
  555. $order = 'share_log_count desc';
  556. }
  557. $list = $model->where($where)->page($page, $limit)->order($order)->select()->each(function ($item) use ($step_list) {
  558. $record_list = ConstructionRecord::where([['construction_id', '=', $item['id']]])->order('update_time desc')->select();
  559. $step_now = 0; //进行到哪一步了
  560. foreach ($step_list as $k => $v) {
  561. foreach ($record_list as $kk => $vv) {
  562. if ($v['id'] == $vv['step_id'] && $v['order'] > $step_now) {
  563. $step_now = $v['order'];
  564. }
  565. }
  566. }
  567. foreach ($step_list as $k => $v) {
  568. $step_list[$k]['upload'] = 0; // 判断是否上传
  569. $step_list[$k]['need_upload'] = 0; // 判断节点是否变色(已过此节点,但是没上传)
  570. $have = false; //是否有上传 true有
  571. $need_have = false; //没上传,但是后面的节点上传了 true是
  572. foreach ($record_list as $kk => $vv) {
  573. if ($v['id'] == $vv['step_id']) {
  574. $have = true;
  575. }
  576. }
  577. if ($have == false && $v['order'] < $step_now) {
  578. $need_have = true;
  579. }
  580. if ($have) {
  581. $step_list[$k]['upload'] = 1;
  582. } elseif ($need_have) {
  583. $step_list[$k]['need_upload'] = 1;
  584. }
  585. }
  586. $item->step_list = $step_list;
  587. });
  588. return json(['code' => 0, 'data' => $list->toArray(), 'count' => $list->count()]);
  589. }
  590. /**
  591. * 装修案例
  592. */
  593. public function casedetail()
  594. {
  595. $id = input('id',0);
  596. $token['uid'] = $this->uid;
  597. $token['employee_id'] = $this->employeeId;
  598. $token['root_org'] = $this->rootId;
  599. $colected = UserCollect::where(['user_id' => $token['uid'], 'content_type' => 'materialCase', 'content_id' => $id])->count();
  600. $data = MaterialCase::with([
  601. 'community',
  602. 'designer',
  603. 'decostyle',
  604. 'housetype'
  605. ])->where(['id' => $id, 'root_id' => $token['root_org']])->find();
  606. //MaterialCase::where(['id' => $id, 'root_id' => $token['root_org']])->inc('view_times')->update();
  607. $data['collected'] = $colected > 0 ? true : false;
  608. // 关联案例
  609. if (!empty($data['designer_id'])){
  610. $relatedcaselist = MaterialCase::where([['designer_id', '=', $data['designer_id']],['id', '<>', $id], ['root_id', '=', $token['root_org']], ['del', '=', 0], ['publish', '=', 1]])
  611. ->with(['community' => function ($query) {
  612. $query->field('id,name');
  613. }, 'decostyle' => function ($query) {
  614. $query->field('id,name');
  615. }])->page(1, 4)->order('id desc')->select()->each(function ($item) {
  616. $item->clue_number = CustomerClue::where([['pipe_type', '=', 'materialCase'], ['pipe_id', '=', $item['id']]])->count();
  617. })->toArray();
  618. } else {
  619. $relatedcaselist = [];
  620. }
  621. $data['designer_related_cases'] = $relatedcaselist;
  622. //设计师附属字段
  623. if ($data->designer) {
  624. $designer = Designer::where([['employee_id', '=', $data->designer_id], ['root_id', '=', $token['root_org']]])->field('id,good_at,position')->findOrEmpty();
  625. if ($designer->isEmpty()) {
  626. $data->designer->good_at = '';
  627. $data->designer->position = '';
  628. } else {
  629. $data->designer->good_at = !empty($designer->good_at) ? $designer->good_at : '';
  630. $data->designer->position = $designer->position ? $designer->position : '';
  631. }
  632. $data->designer->headimgurl = User::where('id', '=', $data->designer->uid)->value('headimgurl');
  633. }
  634. // 为null处理,防止前端报错
  635. $data['real_case'] = !is_null($data['real_case']) ? $data['real_case'] : '';
  636. $data['desc'] = !is_null($data['desc']) ? $data['desc'] : '';
  637. $data['vr_case'] = !is_null($data['vr_case']) ? $data['vr_case'] : '';
  638. //分享加密参数 店面id ,分享人id , 楼盘id , 户型id , 案例id , 在施工地id
  639. $ids = [$this->rootId,$this->employeeId,'','',$id,''];
  640. $aec = new Aec(config('app.aec_key'), config('app.aec_iv'));
  641. $value = $aec->encrypt(implode('#',$ids));
  642. return json(['code' => 0, 'data' => $data, 'msg' => '获取成功','str'=>$value]);
  643. }
  644. //在施工地详情
  645. public function constrationView()
  646. {
  647. $id = input('id', '', 'intval');
  648. if (empty($id)) {
  649. return json(['code' => self::error_msg, 'msg' => '获取失败']);
  650. }
  651. $share = input('share', '', 'trim');
  652. $info = ConstructionModel::with(['style', 'designer', 'housetype', 'community'])->find($id);
  653. $root_id = $this->rootId;
  654. $step_list = ConstructionStep::where('root_id', '=', $root_id)->order('order asc')->select()->toArray();
  655. $record_list = ConstructionRecord::where([['construction_id', '=', $id]])->order('update_time desc')->select();
  656. $step_now = 0; //进行到哪一步了
  657. foreach ($step_list as $k => $v) {
  658. foreach ($record_list as $kk => $vv) {
  659. if ($v['id'] == $vv['step_id'] && $v['order'] > $step_now) {
  660. $step_now = $v['order'];
  661. }
  662. }
  663. }
  664. $vrObj = new Vr();
  665. foreach ($step_list as $k => $v) {
  666. $step_list[$k]['upload'] = 0; // 判断是否上传
  667. $step_list[$k]['need_upload'] = 0; // 判断节点是否变色(已过此节点,但是没上传)
  668. $have = false; //是否有上传 true有
  669. $need_have = false; //没上传,但是后面的节点上传了 true是
  670. $step_list[$k]['data'] = [];
  671. foreach ($record_list as $kk => $vv) {
  672. if ($v['id'] == $vv['step_id']) {
  673. $have = true;
  674. if (!empty($vv['vr']) && $vv['type'] == 'vr') {
  675. $vrUrlList = explode(',', $vv['vr']);
  676. $vrData = [];
  677. foreach ($vrUrlList as $url) {
  678. $vrData[] = [
  679. 'vrUrl' => $url,
  680. 'vrfirstImg' => $vrObj->getFirstImg($url)
  681. ];
  682. }
  683. $vv['vr'] = $vrData;
  684. }
  685. $step_list[$k]['data'] = $vv;
  686. }
  687. }
  688. if ($have == false && $v['order'] < $step_now) {
  689. $need_have = true;
  690. }
  691. if ($have) {
  692. $step_list[$k]['upload'] = 1;
  693. } elseif ($need_have) {
  694. $step_list[$k]['need_upload'] = 1;
  695. }
  696. }
  697. $info['step_list'] = $step_list;
  698. //分享加密参数 店面id ,分享人id , 楼盘id , 户型id , 案例id , 在施工地id
  699. $ids = [$this->rootId,$this->employeeId,'','','',$id];
  700. $aec = new Aec(config('app.aec_key'), config('app.aec_iv'));
  701. $value = $aec->encrypt(implode('#',$ids));
  702. return json(['code'=> 0, 'msg'=> '请求成功', 'data'=> $info,'str'=>$value]);
  703. }
  704. /**
  705. * 收藏
  706. */
  707. public function collects()
  708. {
  709. $param = input('');
  710. $data = [
  711. 'user_id' => $this->uid,
  712. 'content_type' => $param['content_type'],
  713. 'content_id' => $param['content_id']
  714. ];
  715. $collect = UserCollect::where($data)->find();
  716. if ($collect) {
  717. $collect->delete();
  718. return json(['code' => 0, 'msg' => '取消收藏']);
  719. } else {
  720. UserCollect::create($data);
  721. return json(['code' => 0, 'msg' => '收藏成功']);
  722. }
  723. }
  724. /**
  725. * 个人信息
  726. */
  727. public function getUserInfo()
  728. {
  729. $emp = Employee::where('id',$this->employeeId)->field('org_id,qrcode,id,phone,uid,root_id,name,opt_name,wx,position,image_photo,xq_mobile_openid')->find();
  730. //数据问题导致报错
  731. $user = User::where('id',$emp->uid)->findOrEmpty();
  732. if ($user->isEmpty()) {
  733. $emp->headimgurl = '';
  734. $emp->nickname = '';
  735. }else{
  736. $emp->headimgurl = $user->headimgurl;
  737. $emp->nickname = $user->nickname;
  738. }
  739. $emp->company_name = $emp->companyJoin->company_name;
  740. $emp->logo = $emp->companyJoin->logo;
  741. $emp->org_name = $emp->org->name;
  742. $ali_oss_bindurl = config('app.ali_oss_bindurl');
  743. $emp->qrcode = ($emp->qrcode&&strpos($emp->qrcode,'http')===false) ? 'https://' . $ali_oss_bindurl . '/' . $emp->qrcode : $emp->qrcode;
  744. $emp->notify = Miniprogram::where('root_id',$emp->root_id)->value('notify');
  745. $emp = $emp->toArray();
  746. unset($emp['user']);
  747. unset($emp['companyJoin']);
  748. unset($emp['org']);
  749. return json(['code' => 0,'data'=>$emp , 'msg' => '']);
  750. }
  751. /**
  752. * 收藏楼盘户型
  753. */
  754. public function collectHousetype(){
  755. $param = Request::only(['building_id'=>0,'building_housetype_id'=>0]);
  756. $token = [
  757. 'root_org' => $this->rootId,
  758. 'employee_id'=>$this->employeeId,
  759. ];
  760. $where = [
  761. ['root_id','=',$token['root_org']],
  762. ['building_id','=',$param['building_id']],
  763. ['id','=',$param['building_housetype_id']]
  764. ];
  765. $check = BuildingHousetype::where($where)->findOrEmpty();
  766. if($check->isEmpty()) return json(['code'=> 1, 'msg'=> '收藏失败', 'data'=> []]);
  767. $where = [
  768. ['root_id','=',$token['root_org']],
  769. ['employee_id','=',$token['employee_id']],
  770. ['building_id','=',$param['building_id']],
  771. ['building_housetype_id','=',$param['building_housetype_id']],
  772. ['type','=',1]
  773. ];
  774. $info = BuildingHousetypeCollect::where($where)->findOrEmpty();
  775. if (!$info->isEmpty()) return json(['code'=> 1, 'msg'=> '已经收藏', 'data'=> []]);
  776. BuildingHousetypeCollect::insert([
  777. 'root_id'=>$token['root_org'],
  778. 'employee_id'=>$token['employee_id'],
  779. 'building_id'=>$param['building_id'],
  780. 'building_housetype_id'=>$param['building_housetype_id'],
  781. 'type'=>1
  782. ]);
  783. return json(['code'=> 0, 'msg'=> '收藏成功', 'data'=> []]);
  784. }
  785. /**
  786. * 取消收藏
  787. */
  788. public function cancelCollectHousetype(){
  789. $param = Request::only(['building_id'=>0,'building_housetype_id'=>0]);
  790. $token = [
  791. 'root_org' => $this->rootId,
  792. 'employee_id'=>$this->employeeId,
  793. ];
  794. $where = [
  795. ['root_id','=',$token['root_org']],
  796. ['employee_id','=',$token['employee_id']],
  797. ['building_id','=',$param['building_id']],
  798. ['building_housetype_id','=',$param['building_housetype_id']],
  799. ['type','=',1]
  800. ];
  801. $info = BuildingHousetypeCollect::where($where)->field('id')->findOrEmpty();
  802. if($info->isEmpty()) return json(['code'=> 1, 'msg'=> '取消失败', 'data'=> []]);
  803. BuildingHousetypeCollect::where($where)->delete();
  804. return json(['code'=> 0, 'msg'=> '取消成功', 'data'=> []]);
  805. }
  806. /**
  807. * 获取楼盘标签
  808. */
  809. public function getBuildingLabel()
  810. {
  811. $data = ModelBuildingLabel::where(['root_id' => $this->rootId])->field('id,name')->select();
  812. return json(['code'=>0, 'data'=>$data]);
  813. }
  814. }