Building.php 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142
  1. <?php
  2. namespace app\api\controller;
  3. use app\model\Building as BuildingModel;
  4. use app\model\BuildingConstruction;
  5. use app\model\BuildingHousetype;
  6. use app\model\BuildingMaterialCase;
  7. use app\model\BuildingProgress;
  8. use app\model\Company;
  9. use app\model\Construction as ConstructionModel;
  10. use app\model\ConstructionRecord;
  11. use app\model\ConstructionStep;
  12. use app\model\MaterialCase;
  13. use app\model\Org;
  14. use app\model\UserCollect;
  15. use think\facade\Log;
  16. use xiaohongwu\Vr;
  17. use app\model\BuildingDevelopCase;
  18. use app\model\Decostyle;
  19. use think\facade\Console;
  20. use app\model\Community;
  21. use app\model\Employee;
  22. use app\model\BuildingSpecialEmp;
  23. use app\model\BuildingHousetypeCollect;
  24. use think\facade\Request;
  25. use app\model\VrGroup;
  26. use app\model\VrView;
  27. class Building extends Base
  28. {
  29. /**
  30. * vr楼书列表
  31. */
  32. public function index()
  33. {
  34. $order_input = input('order', 'new', 'trim');
  35. $order = 'update_time desc';
  36. if ($order_input == 'new') {
  37. $order = 'update_time desc';
  38. } elseif ($order_input == 'hot') {
  39. $order = 'share_log_count desc';
  40. }
  41. $model = BuildingModel::with(['share_log'])->withCount(['share_log' => function ($query) {
  42. $query->where([['type', '=', 'Building']]);
  43. }]);
  44. $root_id = $this->request->token['root_org'];
  45. $where[] = ['root_id', '=', $root_id];
  46. $where[] = ['del', '=', 0];
  47. $name = input('name', '', 'trim');
  48. if ($name) {
  49. $condition = [
  50. ['root_id', '=', $root_id],
  51. ['type', '=', 0],
  52. ['name', 'like', '%' . $name . '%']
  53. ];
  54. $community_id = Community::where($condition)->column('id');
  55. /**
  56. * 查询楼盘地址是否有匹配
  57. */
  58. $whereor1[] = ['community_id', 'in', $community_id];
  59. $whereor1[] = ['address','like','%'.$name.'%'];
  60. $adrids = BuildingModel::where($where)->where(function($query) use ($whereor1){
  61. $query->whereOr($whereor1);
  62. })->column('id');
  63. $where[] = ['id','in',$adrids];
  64. //$where[] = ['community_id', 'in', $community_id];
  65. }
  66. $page = input('page', 1, 'intval');
  67. $employee_id = $this->request->token['employee_id'];
  68. //查询设置可见人信息
  69. $special=BuildingSpecialEmp::where('root_id',$this->request->token['root_org'])->value('assign_employee');
  70. $assign_employee = !empty($special)? explode(',', $special):[];
  71. if(in_array($employee_id,$assign_employee)){
  72. $data = $model->where($where);
  73. }else{
  74. $data = $model->where($where)->where(function ($query) use ($employee_id){
  75. $query->whereRaw("FIND_IN_SET(" . $employee_id . " , assign_employee)")
  76. ->whereOr('assign_employee', '=', NULL)
  77. ->whereOr('assign_employee', '=', '');
  78. })->where(function ($query) use ($employee_id) {
  79. $query->whereRaw("`from` = 0 or (`from` =1 and `org_id` =" . $this->request->token['org_id'] . ") or ( `from` = 1 and (FIND_IN_SET(" . $employee_id . " , assign_employee)))");
  80. });
  81. }
  82. $list=$data->page($page, 10)->order($order)->select()->each(function ($item) {
  83. $area_list = BuildingHousetype::where('building_id', '=', $item['id'])->order('area asc')->column('area');
  84. $item->area_list = array_values(array_unique(array_filter($area_list)));
  85. $collectedIds = UserCollect::where(['user_id' => $this->request->token['uid'], 'content_type' => 'building'])->column('content_id');
  86. if (in_array($item['id'], $collectedIds)) {
  87. $item['collected'] = true;
  88. } else {
  89. $item['collected'] = false;
  90. }
  91. })->toArray();
  92. return json(['code' => self::success, 'data' => $list]);
  93. }
  94. /**
  95. * 详情
  96. */
  97. public function view()
  98. {
  99. $id = input('id', '', 'intval');
  100. $info = BuildingModel::find($id);
  101. if (empty($info)) {
  102. return json(['code' => self::error_msg, 'msg' => '数据不存在']);
  103. }
  104. $area_list = BuildingHousetype::where('building_id', '=', $id)->order('area asc')->column('area');
  105. $info['area_list'] = array_values(array_unique(array_filter($area_list)));
  106. $company = Company::where('root_id', '=', $info['root_id'])->field(['company_name', 'logo'])->find();
  107. $info['company_name'] = $company['company_name'];
  108. $info['company_logo'] = $company['logo'];
  109. //小区户型
  110. $housetype = BuildingHousetype::with(['devcase'=>function($query){
  111. $query->field('housetype_id,id,name,type,vr_link,content,cover,decostyles_id');
  112. }])->where('building_id', '=', $id)->withCount(['materialCase'])->select()->toArray();
  113. //vr作品处理
  114. $show_url = config('app.vr_show_domain');
  115. foreach ($housetype as $key => $value) {
  116. $sid = VrGroup::where('id',$value['vr_group_ids'])->value('sid');
  117. $housetype[$key]['vr_link'] = $sid ? $show_url.$sid : '';
  118. }
  119. $xin = [];
  120. $vrObj = new Vr();
  121. if(!empty($housetype)){
  122. $houselist=$housetype;
  123. foreach($houselist as $key=>$val){
  124. if(empty($val['house_img']) && !empty($val['vr_link'])){
  125. $houselist[$key]['house_img'][] = $vrObj->getFirstImg($val['vr_link']);
  126. }
  127. if(empty($val['devcase'])) continue;
  128. foreach($val['devcase'] as $k=>$v){
  129. $houselist[$key]['devcase'][$k]['decostyles_name']=Decostyle::where('id',$v['decostyles_id'])->value('name');
  130. $houselist[$key]['devcase'][$k]['area']=$val['area'];
  131. $houselist[$key]['devcase'][$k]['room']=$val['room'];
  132. $houselist[$key]['devcase'][$k]['hall']=$val['hall'];
  133. $houselist[$key]['devcase'][$k]['bathroom']=$val['bathroom'];
  134. if($v['type']==1){
  135. $houselist[$key]['devcase'][$k]['cover'] = $vrObj->getFirstImg($v['vr_link']);
  136. }
  137. }
  138. }
  139. foreach($houselist as $key => $val){
  140. @$xin[$val['room']][] = $val;
  141. }
  142. $xin[0] = $houselist;
  143. }
  144. $info['vr_link_cover']='';
  145. if(!empty($info['vr_link'])){
  146. $info['vr_link_cover']=$vrObj->getFirstImg($info['vr_link']);
  147. }elseif($info['vr_group_ids']){
  148. $vrgroup = VrGroup::where('id',$info['vr_group_ids'])->field('id,pic_path,sid')->findOrEmpty();
  149. if (!$vrgroup->isEmpty()) {
  150. $info['vr_link'] = $show_url.$vrgroup->sid;
  151. $info['vr_link_cover'] = $vrgroup->pic_path;
  152. }
  153. }
  154. $info['housetype'] = $xin;
  155. $info['housetype_count'] = count($housetype);
  156. $collectedIds = UserCollect::where(['user_id' => $this->request->token['uid'], 'content_type' => 'building','content_id'=>$info['id']])->count();
  157. if ($collectedIds) {
  158. $info['collected'] = true;
  159. } else {
  160. $info['collected'] = false;
  161. }
  162. //增加进度图片视频VR数量查询
  163. $prtype_list = BuildingProgress::where([['building_id', '=', $id]])->field('count(*) as count,type')->group('type')->select()->toArray();
  164. $info['prtype_list']=!empty($prtype_list)?$prtype_list:null;
  165. return json(['code' => self::success, 'data' => $info]);
  166. }
  167. /**
  168. * 研发案例列表
  169. */
  170. public function dev_case_list()
  171. {
  172. $id = input('id', '', 'intval');
  173. if (empty($id)) return json(['code' => 1, 'msg' => '参数错误']);
  174. $list= BuildingDevelopCase::with(['decostyles'])->where('housetype_id',$id)
  175. ->field('id,name,type,housetype_id,decostyles_id')
  176. ->select();
  177. return json(['code' => self::success, 'data' => $list]);
  178. }
  179. /**
  180. * 研发案例详情
  181. */
  182. public function dev_case_detail()
  183. {
  184. $id = input('id', '', 'intval');
  185. if (empty($id)) return json(['code' => 1, 'msg' => '参数错误']);
  186. $data = BuildingDevelopCase::with(['decostyles'])->where('id', $id)->find();
  187. return json(['code' => self::success, 'data' => $data]);
  188. }
  189. /**
  190. * 楼盘进度
  191. */
  192. public function progress()
  193. {
  194. $token = $this->request->token;
  195. $id = input('id', '', 'intval');
  196. $type = input('type','','trim');
  197. $labelId = input('label_id');
  198. $where[]=['building_id', '=', $id];
  199. $where[]=['root_id','=',$token['root_org']];
  200. if($labelId)
  201. $where[]=['label_id','=',$labelId];
  202. if(!empty($type)){
  203. $where[]=['type', '=', $type];
  204. }
  205. $page = input('page',1);
  206. $limit = input('limit',3);
  207. $list = BuildingProgress::with(['label'=>function($query){
  208. $query->withField(['id','name']);
  209. }])->where($where)->order('addtime desc')->page($page,$limit)->select();
  210. if (empty($list)) $list = [];
  211. else $list = $list->toArray();
  212. $vrObj = new Vr();
  213. //vr作品处理
  214. $sids = VrGroup::where([['id','in',array_column($list,'vr_group_ids')]])->column('sid','id');
  215. $show_url = config('app.vr_show_domain');
  216. foreach ($list as &$item) {
  217. $vrData = [];
  218. if (!empty($item['vr'])) {
  219. $vrUrlList = explode(',', $item['vr']);
  220. foreach ($vrUrlList as $url) {
  221. $vrData[] = [
  222. 'vrUrl' => $url,
  223. 'vrfirstImg' => getFirstImg($url)
  224. ];
  225. }
  226. }elseif (!empty($item['vr_group_ids'])) {
  227. $vrgroup = VrGroup::where('id',$item['vr_group_ids'])->field('id,pic_path,sid')->findOrEmpty();
  228. $item['show_url'] = '';
  229. $item['show_img'] = '';
  230. if (!$vrgroup->isEmpty()) {
  231. $item['show_url'] = $show_url.$vrgroup->sid;
  232. $item['show_img'] = $vrgroup->pic_path;
  233. }
  234. }
  235. $item['vr'] = $vrData;
  236. }
  237. return json(['code' => self::success, 'data' => $list]);
  238. }
  239. /**
  240. * 户型关联案例
  241. */
  242. public function material_case()
  243. {
  244. $housetype_id = input('housetype_id',0);
  245. $token = $this->request->token;
  246. $page = input('page',1);
  247. $limit = input('limit',10);
  248. $case_ids = BuildingMaterialCase::where([['housetype_id','=',$housetype_id],['root_id','=',$token['root_org']]])->column('material_case_id');
  249. if(empty($case_ids)) return json(['code' => 0, 'data' => [], 'msg' => '获取成功']);
  250. $where[] = ['id', 'in', $case_ids];
  251. $list = MaterialCase::with(['designer' => function ($query) {
  252. $query->field('id,name, headimgurl,addtime');
  253. }, 'community' => function ($query) {
  254. $query->field('id,name');
  255. }, 'decostyle' => function ($query) {
  256. $query->field('id,name');
  257. }])->order('recommend desc')->page($page,$limit)->where($where)->select();
  258. $collectedIds = UserCollect::where(['user_id' => $token['uid'], 'content_type' => 'materialCase'])->column('content_id');
  259. foreach ($list as &$item) {
  260. if (in_array($item['id'], $collectedIds)) {
  261. $item['collected'] = true;
  262. } else {
  263. $item['collected'] = false;
  264. }
  265. }
  266. $data = ['list'=> $list];
  267. $count = MaterialCase::where($where)->count();
  268. return json(['code' => 0, 'data' => $data,'count'=>$count, 'msg' => '获取成功']);
  269. }
  270. /**
  271. * 收藏
  272. */
  273. public function collect($id)
  274. {
  275. $user_id = $this->request->token['uid'];
  276. $had = UserCollect::where(['user_id' => $user_id, 'content_type' => 'building', 'content_id' => $id])->count();
  277. if ($had > 0) return json(['code' => 1, 'msg' => '您已收藏']);
  278. UserCollect::insert(['user_id' => $user_id, 'content_type' => 'building', 'content_id' => $id]);
  279. return json(['code' => 0, 'msg' => '收藏成功']);
  280. }
  281. /**
  282. * 取消收藏
  283. */
  284. public function collectCancel($id)
  285. {
  286. $user_id = $this->request->token['uid'];
  287. UserCollect::where(['user_id' => $user_id, 'content_type' => 'building', 'content_id' => $id])->delete();
  288. return json(['code' => 0, 'msg' => '取消收藏']);
  289. }
  290. public function construction(){
  291. //$building_id = input('building_id', '', 'intval');
  292. //$construction_id = BuildingConstruction::where('building_id', '=', $building_id)->column('construction_id');
  293. //$where[] = ['id', 'in', $construction_id];
  294. $housetype_id = input('housetype_id', '', 'intval');
  295. $construction_str = BuildingHousetype::where('id',$housetype_id)->value('constructionid');
  296. $construction_id = !empty($construction_str) ? explode(',',$construction_str) : [];
  297. $where[] = ['id', 'in', $construction_id];
  298. $page = input('page', 1, 'intval');
  299. $limit = input('limit', 10, 'intval');
  300. $root_id = $this->request->token['root_org'];
  301. $where[] = ['root_id', '=', $root_id];
  302. $community_id = input('community_id', '', 'intval');
  303. if ($community_id) {
  304. $where[] = ['community_id', '=', $community_id];
  305. }
  306. $step_list = ConstructionStep::where('root_id', '=', $root_id)->order('order asc')->select()->toArray();
  307. $order_input = input('order', 'new', 'trim');
  308. $order = 'recommend desc,update_time desc';
  309. $model = ConstructionModel::with(['style', 'designer', 'housetype', 'community'])->withCount(['share_log'=> function ($query) {
  310. $query->where([['type', '=', 'construction']]);
  311. }]);
  312. if ($order_input == 'new'){
  313. $order = 'recommend desc,update_time desc';
  314. $list = $model->where($where)->page($page, $limit)->order($order)->select();
  315. } else if ($order_input == 'hot') {
  316. $list = $model->where($where)->order($order)->select();
  317. }
  318. $list = $list->each(function ($item) use ($step_list) {
  319. $record_list = ConstructionRecord::where([['construction_id', '=', $item['id']]])->order('update_time desc')->select();
  320. $step_now = 0; //进行到哪一步了
  321. foreach ($step_list as $k => $v) {
  322. foreach ($record_list as $kk => $vv) {
  323. if ($v['id'] == $vv['step_id'] && $v['order'] > $step_now) {
  324. $step_now = $v['order'];
  325. }
  326. }
  327. }
  328. foreach ($step_list as $k => $v) {
  329. $step_list[$k]['upload'] = 0; // 判断是否上传
  330. $step_list[$k]['need_upload'] = 0; // 判断节点是否变色(已过此节点,但是没上传)
  331. $have = false; //是否有上传 true有
  332. $need_have = false; //没上传,但是后面的节点上传了 true是
  333. foreach ($record_list as $kk => $vv) {
  334. if ($v['id'] == $vv['step_id']) {
  335. $have = true;
  336. }
  337. }
  338. if ($have == false && $v['order'] < $step_now) {
  339. $need_have = true;
  340. }
  341. if ($have) {
  342. $step_list[$k]['upload'] = 1;
  343. } elseif ($need_have) {
  344. $step_list[$k]['need_upload'] = 1;
  345. }
  346. }
  347. $item->step_list = $step_list;
  348. //收藏状态
  349. $user_id = $this->request->token['uid'];
  350. $had = UserCollect::where(['user_id' => $user_id , 'content_type' => 'construction' , 'content_id' => $item['id']])->count();
  351. if ($had) {
  352. $item['collect'] = 1;
  353. } else {
  354. $item['collect'] = 0;
  355. }
  356. })->toArray();
  357. if ($order_input == 'hot') {
  358. $list_all = $list;
  359. $share_log_count = array_column($list_all, 'share_log_count');
  360. array_multisort($share_log_count, SORT_DESC, $list_all);
  361. $list = array_slice($list_all, $limit*($page-1), $limit);
  362. }
  363. $count = $model->where($where)->count();
  364. return json(['code' => self::success, 'data' => $list, 'count' => $count]);
  365. }
  366. //户型研发案例详情
  367. public function building_detail()
  368. {
  369. $id=input('id');
  370. if(empty($id)) return json(['code'=> 1,'msg'=> '参数错误']);
  371. $data=BuildingModel::find($id);
  372. return json(['code'=> 0, 'data'=>$data,'msg'=> '获取成功']);
  373. }
  374. //手机端添加热装楼盘
  375. public function add_building()
  376. {
  377. $param = $this->request->only(['community_name', 'address', 'duetime', 'cover', 'vr_link', 'content','sign_num','start_num','finish_num', 'cover_share_img']);
  378. if (!empty($param['community_name'])) {
  379. //新增小区
  380. if (strlen($param['community_name']) > 45) {
  381. return json(['code' => self::error_msg, 'msg' => '楼盘名称过长']);
  382. }
  383. $condition[] = ['name', '=', $param['community_name']];
  384. $condition[] = ['type', '=', 0];
  385. $condition[] = ['root_id', '=', $this->request->token['root_org']];
  386. $exitedobj = Community::where($condition)->findorEmpty();
  387. if (!$exitedobj->isEmpty()) {
  388. $param['community_id'] = $exitedobj['id'];
  389. }else{
  390. $pinyin = hanzi2pinyin($param['community_name']);
  391. $community_id = Community::create([
  392. 'root_id' => $this->request->token['root_org'],
  393. 'pinyin' => $pinyin,
  394. 'name' => $param['community_name'],
  395. 'type' => 0,
  396. 'initials' => strtoupper(substr($pinyin,0,1)),
  397. 'employee_id'=> request()->token['employee_id']
  398. ]);
  399. $param['community_id'] = $community_id->id;
  400. }
  401. }
  402. $param['duetime'] = empty($param['duetime']) ? null : $param['duetime'];
  403. $param['employee_id'] = $this->request->token['employee_id'];
  404. $param['org_id'] = $this->request->token['org_id'];
  405. $param['root_id'] = $this->request->token['root_org'];
  406. if (!empty($param['vr_link'])){
  407. $param['vr_link'] = $this->vrlink_set($param['vr_link']);
  408. }
  409. if(!empty($param['cover'])){
  410. $media_id = [];
  411. foreach ($param['cover'] as $k => $v) {
  412. $media_id[$k] = [
  413. 'serverId' => !empty($v['serverId'])?$v['serverId']:'',
  414. 'img' =>!empty($v['img'])?str_replace('https://'.config('app.ali_oss_bindurl').'/', '', $v['img']):''
  415. ];
  416. }
  417. $param['down_status'] = 1;
  418. $param['media_id'] = json_encode($media_id);
  419. }
  420. $param['cover']=1;
  421. $param['from']=1;
  422. // $orgids = orgSubIds($this->request->token['org_id']);
  423. // $emp_data = Employee::where([['root_id', '=', $this->request->token['root_org']], ['org_id', 'in', $orgids], ['state', '=', '在职'], ['uid', '>', 0]])->order('is_manager desc,id desc')->column('id');
  424. // $param['assign_org_id'] = implode(',', $orgids);
  425. // $param['assign_employee'] = implode(',', $emp_data);
  426. $result = BuildingModel::create($param);
  427. Console::call('download', ['building']);
  428. if ($result) {
  429. dataStatistics($this->request->token['root_org'],'building_count',1,'inc');//manage应用首页统计数据
  430. return json(['code'=> 0, 'msg'=> '添加成功','data'=>$result->id]);
  431. } else {
  432. return json(['code'=> 1, 'msg'=> '添加失败','data'=>'']);
  433. }
  434. }
  435. //员工修改楼盘
  436. public function edit_building()
  437. {
  438. $param = $this->request->only(['id','community_name', 'address', 'duetime', 'cover', 'vr_link', 'content','sign_num','start_num','finish_num','cover_share_img'=>'']);
  439. $data=BuildingModel::where('id',$param['id'])->find();
  440. if (!empty($param['community_name'])) {
  441. //新增小区
  442. if (strlen($param['community_name']) > 45) {
  443. return json(['code' => self::error_msg, 'msg' => '楼盘名称过长']);
  444. }
  445. $condition[] = ['name', '=', $param['community_name']];
  446. $condition[] = ['type', '=', 0];
  447. $condition[] = ['root_id', '=', $this->request->token['root_org']];
  448. $exitedobj = Community::where($condition)->findorEmpty();
  449. if (!$exitedobj->isEmpty()) {
  450. $param['community_id'] = $exitedobj['id'];
  451. }else{
  452. $pinyin = hanzi2pinyin($param['community_name']);
  453. $community_id = Community::create([
  454. 'root_id' => $this->request->token['root_org'],
  455. 'pinyin' => $pinyin,
  456. 'name' => $param['community_name'],
  457. 'type' => 0,
  458. 'initials' => strtoupper(substr($pinyin,0,1)),
  459. 'employee_id'=> request()->token['employee_id']
  460. ]);
  461. $param['community_id'] = $community_id->id;
  462. }
  463. }
  464. if (!empty($param['vr_link'])){
  465. $param['vr_link'] = $this->vrlink_set($param['vr_link']);
  466. }
  467. if(!empty($param['cover'])){
  468. $media_id = [];
  469. foreach ($param['cover'] as $k => $v) {
  470. $media_id[$k] = [
  471. 'serverId' => !empty($v['serverId'])?$v['serverId']:'',
  472. 'img' =>!empty($v['img'])?str_replace('https://'.config('app.ali_oss_bindurl').'/', '', $v['img']):''
  473. ];
  474. }
  475. $param['down_status'] = 1;
  476. $param['media_id'] = json_encode($media_id);
  477. }
  478. $param['duetime'] = empty($param['duetime']) ? null : $param['duetime'];
  479. $result = $data->save($param);
  480. Console::call('download', ['building']);
  481. if ($result) {
  482. return json(['code'=> 0, 'msg'=> '修改成功']);
  483. } else {
  484. return json(['code'=> 1, 'msg'=> '修改失败']);
  485. }
  486. }
  487. //楼盘列表
  488. public function empup_building_list()
  489. {
  490. $param = Request()->only(['type'=>0,'page'=>1,'limit'=>10, 'keyword'=> '']);
  491. $token = $this->request->token;
  492. $employee_id = $token['employee_id'];
  493. $where[] = ['root_id', '=', $token['root_org']];
  494. $where[] = ['del', '=', 0];
  495. if ($param['keyword']){
  496. $condition = [
  497. ['root_id', '=', $token['root_org']],
  498. ['type', '=', 0],
  499. ['name', 'like', '%' . $param['keyword'] . '%']
  500. ];
  501. $community_id = Community::where($condition)->column('id');
  502. /**
  503. * 查询楼盘地址是否有匹配
  504. */
  505. $whereor1[] = ['community_id', 'in', $community_id];
  506. $whereor1[] = ['address','like','%'.$param['keyword'].'%'];
  507. $adrids = BuildingModel::where($where)->where(function($query) use ($whereor1){
  508. $query->whereOr($whereor1);
  509. })->column('id');
  510. $where[] = ['id','in',$adrids];
  511. //$where[] = ['community_id', 'in', $community_id];
  512. }
  513. if ($param['type'] == 1) {
  514. //后台上传
  515. $where[] = ['from', '=', 0];
  516. //查询设置可见人信息
  517. $special = BuildingSpecialEmp::where('root_id', $token['root_org'])->value('assign_employee');
  518. $assign_employee = !empty($special) ? array_filter(explode(',', $special)) : [];
  519. $model = BuildingModel::withCount(['housetype', 'devcase', 'construction']);
  520. if(in_array($employee_id, $assign_employee)){
  521. $model = $model->where($where);
  522. } else {
  523. /*$sql = "(assign_employee is null or assign_employee='' or find_in_set(".$token['employee_id'].",assign_employee))";
  524. $model = $model->where($where)->whereRaw($sql);*/
  525. $model = $model->where($where)->where(function ($query) use ($employee_id){
  526. $query->whereRaw("FIND_IN_SET(" . $employee_id . " , assign_employee)")
  527. ->whereOr('assign_employee', '=', NULL)
  528. ->whereOr('assign_employee', '=', '');
  529. });
  530. }
  531. $list = $model->page($param['page'], $param['limit'])->select()->toArray();
  532. }else{
  533. //手机端上传 修改后台跟手机端指派的都可以在自己上传的页面看到
  534. $where[] = ['from', '=', 1];
  535. $where[] = ['employee_id', '=', $employee_id];
  536. $where1[] = ['assign_employee', 'find in set', $employee_id];
  537. $list = BuildingModel::withCount(['housetype','devcase','construction'])->whereOr([$where,$where1])->page($param['page'],$param['limit'])->select()->toArray();
  538. }
  539. return json(['code'=> 0, 'data'=>$list,'msg'=> '获取成功']);
  540. }
  541. //vr链接设置修改
  542. public function vrlink_set($vr_link)
  543. {
  544. //2023-05-04 志远装饰app创建的vr作品
  545. if (strpos($vr_link,'/vr/#')) return $vr_link;
  546. // 旧域名 替换成 新域名
  547. $links = [
  548. 'xiaohongwu' => 'hnweizhihui.xiaohongwu.nczyzs.com',
  549. 'kujiale' => 'pano337.p.kujiale.com',
  550. 'justeasy' => 'vr-17.justeasy.nczyzs.com',
  551. '3d66' => 'vr.3d66.nczyzs.com',
  552. ];
  553. $url = parse_url($vr_link);
  554. if ($url === false || !isset($url['host'])) {
  555. echo json_encode(['code' => 1, 'msg' => '链接格式错误']);
  556. exit;
  557. }
  558. if (strpos($url['host'], 'xiaohongwu') !== false) {
  559. return str_replace($url['host'], $links['xiaohongwu'], $vr_link);
  560. }
  561. if (strpos($url['host'], 'kujiale') !== false) {
  562. return str_replace($url['host'], $links['kujiale'], $vr_link);
  563. }
  564. if (strpos($url['host'], 'justeasy') !== false) {
  565. return str_replace($url['host'], $links['justeasy'], $vr_link);
  566. }
  567. if (strpos($url['host'], '3d66') !== false) {
  568. return str_replace($url['host'], $links['3d66'], $vr_link);
  569. }
  570. echo json_encode(['code' => 1, 'msg' => '无效的VR链接']);
  571. exit;
  572. }
  573. //户型详情
  574. public function housetype_detail()
  575. {
  576. $token = $this->request->token;
  577. $id = input('id', '', 'intval');
  578. if(empty($id)) return json(['code'=> 1,'msg'=> '参数错误']);
  579. $data = BuildingHousetype::find($id);
  580. $data['new_orientation'] = $data->getData('orientation');
  581. $data['vr_link_img'] = '';
  582. if (!empty($data['vr_link'])) {
  583. $vrObj = new Vr();
  584. $data['vr_link_img'] = getFirstImg($data['vr_link']);
  585. }elseif($data['vr_group_ids']){
  586. $show_url = config('app.vr_show_domain');
  587. $vrgroup = VrGroup::where('id',$data['vr_group_ids'])->field('id,pic_path,sid')->findOrEmpty();
  588. if (!$vrgroup->isEmpty()) {
  589. $data['vr_link'] = $show_url.$vrgroup->sid;
  590. $data['vr_link_img'] = $vrgroup->pic_path;
  591. }
  592. }
  593. //查询楼盘地址和小区
  594. $build = BuildingModel::where('id',$data->building_id)->field('community_id,address')->findOrEmpty();
  595. if (!$build->isEmpty()){
  596. $build->community = $build->community_id ? Community::where('id',$build->community_id)->value('name') : '';
  597. }
  598. //是否收藏
  599. $where = [
  600. ['root_id','=',$token['root_org']],
  601. ['employee_id','=',$token['employee_id']],
  602. ['building_id','=',$data->building_id],
  603. ['building_housetype_id','=',$id],
  604. ['type','=',1]
  605. ];
  606. $data->is_collect = BuildingHousetypeCollect::where($where)->value('id') ? 1 : 0;
  607. return json(['code'=> 0, 'data'=> $data,'build'=>$build, 'msg'=> '获取成功']);
  608. }
  609. //添加楼盘户型
  610. public function add_housetype()
  611. {
  612. $param = request()->only(['building_id', 'type','area', 'room', 'hall', 'bathroom','vr_link','house_img','house_count','orientation','media_id', 'house_img_media_id']);
  613. $param['root_id'] = $this->request->token['root_org'];
  614. $orientation=null;
  615. if(!empty($param['orientation'])){
  616. foreach($param['orientation'] as $key=>$val){
  617. $orientation.=$val.',';
  618. }
  619. $param['orientation']=trim($orientation,',');
  620. }
  621. if (!empty($param['vr_link'])){
  622. $param['vr_link'] = $this->vrlink_set($param['vr_link']);
  623. }
  624. if(!empty($param['media_id'])){
  625. $media_id = [];
  626. foreach ($param['media_id'] as $k => $v) {
  627. $media_id[$k] = [
  628. 'serverId' => !empty($v['serverId'])?$v['serverId']:'',
  629. 'img' =>!empty($v['img'])?str_replace('https://'.config('app.ali_oss_bindurl').'/', '', $v['img']):''
  630. ];
  631. }
  632. $param['down_status'] = 1;
  633. $param['media_id'] = json_encode($media_id);
  634. }
  635. if(!empty($param['house_img_media_id'])){
  636. $house_img_media_id = [];
  637. foreach ($param['house_img_media_id'] as $k => $v) {
  638. $house_img_media_id[$k] = [
  639. 'serverId' => !empty($v['serverId']) ? $v['serverId'] : '',
  640. 'img' => !empty($v['img']) ? str_replace('https://'.config('app.ali_oss_bindurl').'/', '', $v['img']) : ''
  641. ];
  642. }
  643. $param['down_status'] = 1;
  644. $param['house_img_media_id'] = json_encode($house_img_media_id);
  645. }
  646. $param['from']=1;
  647. //增加别墅户型(其室厅卫值都为9)
  648. if($param['type']==2){
  649. $param['room']=9;
  650. $param['hall']=9;
  651. $param['bathroom']=9;
  652. }
  653. $result = BuildingHousetype::create($param);
  654. Console::call('download', ['buildinghousetype']);
  655. if ($result) {
  656. return json(['code'=> 0, 'msg'=> '添加成功','data'=>$result->id]);
  657. } else {
  658. return json(['code'=> 1, 'msg'=> '添加失败','data'=>'']);
  659. }
  660. }
  661. //修改楼盘户型
  662. public function edit_housetype()
  663. {
  664. $param = request()->only(['id','building_id', 'type','area', 'room', 'hall', 'bathroom','vr_link','house_img','house_count','orientation','media_id', 'house_img_media_id']);
  665. $info=BuildingHousetype::where('id',$param['id'])->find();
  666. $orientation=null;
  667. if(!empty($param['orientation'])){
  668. foreach($param['orientation'] as $key=>$val){
  669. $orientation.=$val.',';
  670. }
  671. $param['orientation']=trim($orientation,',');
  672. }
  673. if (!empty($param['vr_link'])){
  674. $param['vr_link'] = $this->vrlink_set($param['vr_link']);
  675. }
  676. if(!empty($param['media_id'])){
  677. $media_id = [];
  678. foreach ($param['media_id'] as $k => $v) {
  679. $media_id[$k] = [
  680. 'serverId' => !empty($v['serverId'])?$v['serverId']:'',
  681. 'img' =>!empty($v['img'])?str_replace('https://'.config('app.ali_oss_bindurl').'/', '', $v['img']):''
  682. ];
  683. }
  684. $param['down_status'] = 1;
  685. $param['media_id'] = json_encode($media_id);
  686. }
  687. if(!empty($param['house_img_media_id'])){
  688. $house_img_media_id = [];
  689. foreach ($param['house_img_media_id'] as $k => $v) {
  690. $house_img_media_id[$k] = [
  691. 'serverId' => !empty($v['serverId']) ? $v['serverId'] : '',
  692. 'img' => !empty($v['img']) ? str_replace('https://'.config('app.ali_oss_bindurl').'/', '', $v['img']) : ''
  693. ];
  694. }
  695. $param['down_status'] = 1;
  696. $param['house_img_media_id'] = json_encode($house_img_media_id);
  697. } else {
  698. $param['house_img'] = '';
  699. }
  700. //增加别墅户型(其室厅卫值都为9)
  701. if($param['type']==2){
  702. $param['room']=9;
  703. $param['hall']=9;
  704. $param['bathroom']=9;
  705. }
  706. $result = $info->save($param);
  707. Console::call('download', ['buildinghousetype']);
  708. if ($result) {
  709. return json(['code'=> 0, 'msg'=> '修改成功','data'=>$param['id']]);
  710. } else {
  711. return json(['code'=> 1, 'msg'=> '修改失败','data'=>'']);
  712. }
  713. }
  714. //楼盘户型列表
  715. public function housetype_list()
  716. {
  717. $building_id = input('building_id', '', 'intval');
  718. $list = BuildingHousetype::where('building_id', '=', $building_id)->select()->toArray();
  719. return json(['code'=> 0, 'data'=> $list]);
  720. }
  721. //户型研发案例详情
  722. public function devcase_detail()
  723. {
  724. $id=input('id');
  725. if(empty($id)) return json(['code'=> 1,'msg'=> '参数错误']);
  726. $data=BuildingDevelopCase::find($id);
  727. return json(['code'=> 0, 'data'=>$data,'msg'=> '获取成功']);
  728. }
  729. //户型研发案例列表
  730. public function devcase_list()
  731. {
  732. $id=input('id');
  733. if(empty($id)) return json(['code'=> 1,'msg'=> '参数错误']);
  734. $list=BuildingDevelopCase::with(['decostyles','housetype'=>function($query){
  735. $query->field('id,area,room,hall,bathroom');
  736. }])->where('housetype_id',$id)->field('id,name,type,vr_link,building_id,housetype_id,decostyles_id,cover,from')->select();
  737. $vrObj=new Vr;
  738. foreach($list as $key=>$val){
  739. if($val['type']==1){
  740. $list[$key]['cover'] = $vrObj->getFirstImg($val['vr_link']);
  741. }
  742. }
  743. return json(['code'=> 0, 'data'=>$list,'msg'=> '获取成功']);
  744. }
  745. //添加户型研发案例
  746. public function add_devcase()
  747. {
  748. $param = request()->only([ 'name', 'type', 'vr_link', 'content','decostyles_id','housetype_id','cover']);
  749. if($param['type']==2 && empty($param['cover'])) return json(['code'=> 1, 'msg'=> '图文类型的封面图不能为空']);
  750. $building_id=BuildingHousetype::where('id',$param['housetype_id'])->value('building_id');
  751. $param['building_id']=$building_id;
  752. $param['root_id']=$this->request->token['root_org'];
  753. if (!empty($param['vr_link'])){
  754. $param['vr_link'] = $this->vrlink_set($param['vr_link']);
  755. }
  756. if(!empty($param['cover'])){
  757. $media_id = [];
  758. foreach ($param['cover'] as $k => $v) {
  759. $media_id[$k] = [
  760. 'serverId' => !empty($v['serverId'])?$v['serverId']:'',
  761. 'text' => !empty($v['text'])?$v['text']:'',
  762. 'img' =>!empty($v['img'])?str_replace('https://'.config('app.ali_oss_bindurl').'/', '', $v['img']):''
  763. ];
  764. }
  765. $param['down_status'] = 1;
  766. $param['media_id'] = json_encode($media_id);
  767. }
  768. $param['from']=1;
  769. $result = BuildingDevelopCase::create($param);
  770. if($param['type']==2){
  771. Console::call('download', ['buildingdevcase']);
  772. }
  773. if ($result) {
  774. return json(['code'=> 0, 'msg'=> '添加成功']);
  775. } else {
  776. return json(['code'=> 1, 'msg'=> '添加失败']);
  777. }
  778. }
  779. //修改户型研发案例
  780. public function edit_devcase()
  781. {
  782. $param = request()->only(['id','name', 'type', 'vr_link', 'content','decostyles_id','housetype_id','cover']);
  783. if($param['type']==2 && empty($param['cover'])) return json(['code'=> 1, 'msg'=> '图文类型的封面图不能为空']);
  784. $building_id=BuildingHousetype::where('id',$param['housetype_id'])->value('building_id');
  785. $param['building_id']=$building_id;
  786. $param['root_id']=$this->request->token['root_org'];
  787. if (!empty($param['vr_link'])){
  788. $param['vr_link'] = $this->vrlink_set($param['vr_link']);
  789. }
  790. if(!empty($param['cover'])){
  791. $media_id = [];
  792. foreach ($param['cover'] as $k => $v) {
  793. $media_id[$k] = [
  794. 'serverId' => !empty($v['serverId'])?$v['serverId']:'',
  795. 'text' => !empty($v['text'])?$v['text']:'',
  796. 'img' =>!empty($v['img'])?str_replace('https://'.config('app.ali_oss_bindurl').'/', '', $v['img']):''
  797. ];
  798. }
  799. $param['down_status'] = 1;
  800. $param['media_id'] = json_encode($media_id);
  801. }
  802. $result = BuildingDevelopCase::where('id',$param['id'])->update($param);
  803. if($param['type']==2){
  804. Console::call('download', ['buildingdevcase']);
  805. }
  806. if ($result) {
  807. return json(['code'=> 0, 'msg'=> '修改成功']);
  808. } else {
  809. return json(['code'=> 1, 'msg'=> '修改失败']);
  810. }
  811. }
  812. //案例风格列表
  813. public function decostyles_list()
  814. {
  815. $condition = [['root_id', '=', $this->request->token['root_org']]];
  816. $decostyles = Decostyle::where($condition)->where([['type', '=', 0]])->select()->toArray();
  817. return json(['code'=> 0, 'data'=>$decostyles,'msg'=> '获取成功']);
  818. }
  819. //楼盘进度详情
  820. public function progress_detail()
  821. {
  822. $id=input('id');
  823. if(empty($id)) return json(['code'=> 1,'msg'=> '参数错误']);
  824. $data=BuildingProgress::find($id);
  825. return json(['code'=> 0, 'data'=>$data,'msg'=> '获取成功']);
  826. }
  827. //添加楼盘进度
  828. public function add_progress()
  829. {
  830. $param = request()->only(['building_id', 'name', 'type', 'img', 'vr', 'content','video','cover']);
  831. if(!empty($param['img'])){
  832. $media_id = [];
  833. foreach ($param['img'] as $k => $v) {
  834. $media_id[$k] = [
  835. 'serverId' => !empty($v['serverId'])?$v['serverId']:'',
  836. 'img' =>!empty($v['img'])?str_replace('https://'.config('app.ali_oss_bindurl').'/', '', $v['img']):''
  837. ];
  838. }
  839. $param['down_status'] = 1;
  840. $param['media_id'] = json_encode($media_id);
  841. $param['img']=1;
  842. }else{
  843. $param['img']='';
  844. }
  845. $param['root_id'] = $this->request->token['root_org'];
  846. if (!empty($param['vr'])){
  847. $vr = explode(',', $param['vr']);
  848. foreach ($vr as $k => $v) {
  849. if (!empty($v)){
  850. $vr[$k] = $this->vrlink_set($v);
  851. }
  852. }
  853. $param['vr'] = implode(',', $vr);
  854. }else{
  855. $param['vr']='';
  856. }
  857. if (!empty($param['video'])){
  858. $param['img']=!empty($param['cover'])?$param['cover']:'';
  859. }
  860. $param['from']=1;
  861. $param['content']=!empty($param['content'])?$param['content']:'';
  862. // var_dump($param);
  863. // exit;
  864. $result = BuildingProgress::create($param);
  865. if($param['type']=='img'){
  866. Console::call('download', ['buildingprogress']);
  867. }
  868. if ($result) {
  869. BuildingModel::where('id', '=', $param['building_id'])->save(['update_time'=> date('Y-m-d H:i:s')]);
  870. return json(['code'=> 0, 'msg'=> '添加成功']);
  871. } else {
  872. return json(['code'=> 1, 'msg'=> '添加失败']);
  873. }
  874. }
  875. //编辑楼盘进度
  876. public function edit_progress()
  877. {
  878. $param = request()->only(['id','building_id', 'name', 'type', 'img', 'vr', 'content','video','cover']);
  879. $info=BuildingProgress::find($param['id']);
  880. if(!empty($param['img'])){
  881. $media_id = [];
  882. foreach ($param['img'] as $k => $v) {
  883. $media_id[$k] = [
  884. 'serverId' => !empty($v['serverId'])?$v['serverId']:'',
  885. 'img' =>!empty($v['img'])?str_replace('https://'.config('app.ali_oss_bindurl').'/', '', $v['img']):''
  886. ];
  887. }
  888. $param['down_status'] = 1;
  889. $param['media_id'] = json_encode($media_id);
  890. $param['img']=1;
  891. }else{
  892. $param['img']='';
  893. }
  894. $param['root_id'] = $this->request->token['root_org'];
  895. if (!empty($param['vr'])){
  896. $vr = explode(',', $param['vr']);
  897. foreach ($vr as $k => $v) {
  898. if (!empty($v)){
  899. $vr[$k] = $this->vrlink_set($v);
  900. }
  901. }
  902. $param['vr'] = implode(',', $vr);
  903. }else{
  904. $param['vr']='';
  905. }
  906. if (!empty($param['video'])){
  907. $param['img']=!empty($param['cover'])?$param['cover']:'';
  908. }
  909. $param['content']=!empty($param['content'])?$param['content']:'';
  910. $result = $info->save($param);
  911. if($param['type']=='img'){
  912. Console::call('download', ['buildingprogress']);
  913. }
  914. if ($result) {
  915. BuildingModel::where('id', '=', $param['building_id'])->save(['update_time'=> date('Y-m-d H:i:s')]);
  916. return json(['code'=> 0, 'msg'=> '修改成功']);
  917. } else {
  918. return json(['code'=> 1, 'msg'=> '修改失败']);
  919. }
  920. }
  921. /**
  922. * 获取部门人员
  923. */
  924. public function get_orgemp()
  925. {
  926. $root_id = $this->request->token['root_org'];
  927. $orgs = Org::with(['employee' => function ($query) {
  928. $query->field('e.id,e.name,user.headimgurl,e.org_id')
  929. ->alias('e')
  930. ->where([['e.state', '=', '在职']])
  931. ->join('user', 'user.id=e.uid');
  932. }])->where([
  933. ['path', 'like', $root_id . '-%']
  934. ])->order('level asc, id desc')->field('id,name,pid')->select()->toArray();
  935. $data = [];
  936. $id = input('id', '', 'intval');
  937. $building = BuildingModel::find($id);
  938. $assign_employee = [];
  939. if (!empty($building['assign_employee'])) {
  940. $assign_employee = array_filter(explode(',', $building['assign_employee']));
  941. }
  942. while (!empty($orgs)) {
  943. $org = array_pop($orgs);
  944. $all_show = true; // 整个部门人员是否都是可见人员
  945. foreach ($org['employee'] as $k => $v){
  946. if (in_array($v['id'], $assign_employee)){
  947. $org['employee'][$k]['show'] = 1;
  948. } else {
  949. $org['employee'][$k]['show'] = 0;
  950. $all_show = false;
  951. }
  952. }
  953. $childOrg = [
  954. 'id' => $org['id'],
  955. 'name' => $org['name'],
  956. 'pid' => $org['pid'],
  957. 'employee' => $org['employee'],
  958. 'employee_num' => count($org['employee'])
  959. ];
  960. if ($all_show && !empty($org['employee'])){
  961. $childOrg['show'] = 1;
  962. } else {
  963. $childOrg['show'] = 0;
  964. }
  965. if (isset($data[$org['id']])) {
  966. $childOrg['child_org'] = $data[$org['id']]['child_org'];
  967. $childOrg['employee_num'] += $data[$org['id']]['employee_num'];
  968. unset($data[$org['id']]);
  969. }
  970. $data[$org['pid']]['child_org'][] = $childOrg;
  971. $data[$org['pid']]['employee_num'] = isset($data[$org['pid']]['employee_num']) ? $data[$org['pid']]['employee_num']+$childOrg['employee_num'] : $childOrg['employee_num'];
  972. }
  973. $data = array_pop($data);
  974. $result = [
  975. 'employee' => isset($data['employee']) ? $data['employee'] : [],
  976. 'child_org' => isset($data['child_org']) ? $data['child_org'] : []
  977. ];
  978. return json(['code'=> 0, 'data'=> $result, 'msg'=> '获取成功']);
  979. }
  980. //设置指派人员
  981. public function set_orgemp()
  982. {
  983. $id = input('id','', 'intval');
  984. $empid = input('empid', '', 'trim');
  985. $assign_employee = implode(',', $empid);
  986. $assign_org_id = Employee::where('id', 'in', $assign_employee)->group('org_id')->column('org_id');
  987. $ms = BuildingModel::where('id', $id)->update(array('assign_employee'=> $assign_employee, 'assign_org_id'=> $assign_org_id));
  988. if ($ms !== false) {
  989. return json(['code'=> 0, 'msg'=> '设置成功']);
  990. } else {
  991. return json(['code'=> 1, 'msg'=> '设置失败']);
  992. }
  993. }
  994. /**
  995. * 根据楼盘名称获取楼盘信息
  996. * @return [type] [description]
  997. */
  998. public function getBuildingByName(){
  999. $name = input('name', '', 'trim');
  1000. if ($name) {
  1001. $where[] = ['name', '=', $name];
  1002. $where[] = ['root_id', '=', $this->request->token['root_org']];
  1003. $community_id = Community::where($where)->value('id');
  1004. if ($community_id) {
  1005. $building = BuildingModel::where('community_id', '=', $community_id)->order('id desc')->findOrEmpty();
  1006. if (!$building->isEmpty()) {
  1007. return json(['code'=> 0, 'msg'=> 'success', 'data'=> $building]);
  1008. }
  1009. }
  1010. }
  1011. return json(['code'=> 0, 'msg'=> 'success', 'data'=> []]);
  1012. }
  1013. /**
  1014. * 收藏楼盘户型
  1015. */
  1016. public function collectHousetype(){
  1017. $param = Request::only(['building_id'=>0,'building_housetype_id'=>0]);
  1018. $token = $this->request->token;
  1019. $where = [
  1020. ['root_id','=',$token['root_org']],
  1021. ['building_id','=',$param['building_id']],
  1022. ['id','=',$param['building_housetype_id']]
  1023. ];
  1024. $check = BuildingHousetype::where($where)->findOrEmpty();
  1025. if($check->isEmpty()) return json(['code'=> 1, 'msg'=> '收藏失败', 'data'=> []]);
  1026. $where = [
  1027. ['root_id','=',$token['root_org']],
  1028. ['employee_id','=',$token['employee_id']],
  1029. ['building_id','=',$param['building_id']],
  1030. ['building_housetype_id','=',$param['building_housetype_id']],
  1031. ['type','=',1]
  1032. ];
  1033. $info = BuildingHousetypeCollect::where($where)->findOrEmpty();
  1034. if (!$info->isEmpty()) return json(['code'=> 1, 'msg'=> '已经收藏', 'data'=> []]);
  1035. BuildingHousetypeCollect::insert([
  1036. 'root_id'=>$token['root_org'],
  1037. 'employee_id'=>$token['employee_id'],
  1038. 'building_id'=>$param['building_id'],
  1039. 'building_housetype_id'=>$param['building_housetype_id'],
  1040. 'type'=>1
  1041. ]);
  1042. return json(['code'=> 0, 'msg'=> '收藏成功', 'data'=> []]);
  1043. }
  1044. /**
  1045. * 取消收藏
  1046. */
  1047. public function cancelCollectHousetype(){
  1048. $param = Request::only(['building_id'=>0,'building_housetype_id'=>0]);
  1049. $token = $this->request->token;
  1050. $where = [
  1051. ['root_id','=',$token['root_org']],
  1052. ['employee_id','=',$token['employee_id']],
  1053. ['building_id','=',$param['building_id']],
  1054. ['building_housetype_id','=',$param['building_housetype_id']],
  1055. ['type','=',1]
  1056. ];
  1057. $info = BuildingHousetypeCollect::where($where)->field('id')->findOrEmpty();
  1058. if($info->isEmpty()) return json(['code'=> 1, 'msg'=> '取消失败', 'data'=> []]);
  1059. BuildingHousetypeCollect::where($where)->delete();
  1060. return json(['code'=> 0, 'msg'=> '取消成功', 'data'=> []]);
  1061. }
  1062. public function housetype($community_id)
  1063. {
  1064. $token = $this->request->token;
  1065. $building_id = BuildingModel::where(['community_id'=>$community_id, 'root_id'=>$token['root_org']])->value('id');
  1066. $h = BuildingHousetype::where('building_id', '=', $building_id)->select();
  1067. $nh = [1 => '一', 2 => '二', 3 => '三', 4 => '四', 5 => '五', 6 => '六', 7 => '七', 8 => '八', 9 => '九'];
  1068. $data = [];
  1069. foreach($h as $i){
  1070. $r = $i['room']==9?'别墅':$nh[$i['room']].'室'.$nh[$i['hall']].'厅'.$nh[$i['bathroom']].'卫';
  1071. $data[] = ['id'=>$i['id'], 'housetype'=>$r];
  1072. }
  1073. return json(['code' => 0, 'data' => $data]);
  1074. }
  1075. }