Building.php 71 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720
  1. <?php
  2. namespace app\sys\controller;
  3. use app\logics\OrgLogic;
  4. use app\model\Building as BuildingModel;
  5. use app\model\BuildingConstruction;
  6. use app\model\BuildingHousetype;
  7. use app\model\BuildingImportLog;
  8. use app\model\BuildingMaterialCase;
  9. use app\model\BuildingProgress;
  10. use app\model\BuildingUrge;
  11. use app\model\Community;
  12. use app\model\Construction as ConstructionModel;
  13. use app\model\ConstructionRecord;
  14. use app\model\ConstructionStep;
  15. use app\model\Employee;
  16. use app\model\MaterialCase;
  17. use app\model\Org;
  18. use think\facade\Db;
  19. use think\facade\Request;
  20. use think\facade\View;
  21. use app\model\Decostyle;
  22. use app\model\BuildingDevelopCase;
  23. use app\model\BuildingSpecialEmp;
  24. use app\logics\MaterialLogic;
  25. use app\model\BuildingHousetypeFile;
  26. use app\model\BuildingLabel;
  27. use app\model\VrGroup;
  28. use app\model\Footprints as FootprintsModel;
  29. class Building
  30. {
  31. public function index()
  32. {
  33. if (!request()->isAjax()) {
  34. // 运营人员列表
  35. $eid = BuildingModel::where([['del', '=', 0], ['from', '=', 0], ['root_id', '=', request()->employee->root_id], ['employee_id', '>', 0]])->group('employee_id')->column('employee_id');
  36. $where = [
  37. ['id', 'in', $eid],
  38. ['grant_id', '>', 0],
  39. ['root_id', '=', request()->employee->root_id]
  40. ];
  41. $employee = Employee::where($where)->field(['id', 'opt_name as name'])->select()->toArray();
  42. View::assign('employee', $employee);
  43. //增加手机端上传人员列表
  44. $employee_mb = $this->mobile_up_emp();
  45. View::assign('employee_mb', $employee_mb);
  46. // 部门
  47. $org = OrgLogic::struc(request()->employee->root_id);
  48. View::assign('org', $org);
  49. $orgids = orgSubIds(request()->employee->root_id);
  50. View::assign('orgids', json_encode($orgids));
  51. $communityList = Community::field('id,name,pinyin as s')->where(['root_id' => request()->employee->root_id, 'type' => 0])->order('pinyin asc')->select();
  52. if (!empty($communityList)) {
  53. $communityList = $communityList->toArray();
  54. foreach ($communityList as &$item) {
  55. if (empty($item['s']))
  56. $item['s'] = hanziInitials($item['name']);
  57. else
  58. $item['s'] = $item['s'][0];
  59. $item['upper_s'] = strtoupper($item['s'][0]);
  60. }
  61. $communityList = ['sort' => array_unique(array_column($communityList, 'upper_s')), 'arr' => $communityList];
  62. }
  63. View::assign('communityList', $communityList);
  64. return View::fetch();
  65. }
  66. $from = input('from');
  67. if (!empty($from)) {
  68. $where[] = ['from', '=', 1];
  69. } else {
  70. $where[] = ['from', '=', 0];
  71. }
  72. $where[] = ['del', '=', 0];
  73. $name = input('name', '', 'trim');
  74. if ($name) {
  75. $condition = [
  76. ['root_id', '=', request()->employee->root_id],
  77. ['type', '=', 0],
  78. ['name', 'like', '%' . $name . '%']
  79. ];
  80. $community_id = Community::where($condition)->column('id');
  81. $where[] = ['community_id', 'in', $community_id];
  82. }
  83. $employee_id = input('employee_id');
  84. if ($employee_id) {
  85. $where[] = ['employee_id', '=', $employee_id];
  86. }
  87. // 小区筛选
  88. $community_id_get = input('community_id', '', 'intval');
  89. if ($community_id_get) {
  90. $where[] = ['community_id', '=', $community_id_get];
  91. }
  92. // 时间段筛选
  93. $time = input('time', '', 'trim');
  94. if ($time) {
  95. $newtime = explode(' - ', $time);
  96. $where[] = ['addtime', 'between', [$newtime[0] . ' 00:00:00', $newtime[1] . ' 23:59:59']];
  97. }
  98. //手机上传部门上传
  99. $org_id = input('org_id','','trim');
  100. if($org_id){
  101. if($from==1){
  102. $where[] = ['org_id','=',$org_id];
  103. }
  104. }
  105. $root_id = request()->employee->root_id;
  106. $where[] = ['root_id', '=', $root_id];
  107. $page = input('page', 1, 'intval');
  108. $limit = input('limit', 10, 'intval');
  109. $list = BuildingModel::with(['employee' => function ($query) {
  110. $query->field('id,name,opt_name');
  111. }])->where($where)->withCount(['progress', 'materialCase', 'housetype'])->order('addtime desc')->page($page, $limit)->select()->each(function ($item) {
  112. $vr_count = 0;
  113. if (!empty($item['vr_link'])){
  114. $vr_count ++;
  115. }
  116. $housetype_list = BuildingHousetype::where('building_id', '=', $item['id'])->select()->toArray();
  117. if (!empty($housetype_list)){
  118. foreach ($housetype_list as $k => $h){
  119. if (!empty($h['vr_link'])){
  120. $vr_count ++;
  121. }
  122. }
  123. }
  124. $develop_list = BuildingDevelopCase::where('building_id', '=', $item['id'])->select()->toArray();
  125. if (!empty($develop_list)){
  126. foreach ($develop_list as $k => $d){
  127. if (!empty($d['vr_link'])){
  128. $vr_count ++;
  129. }
  130. }
  131. }
  132. $progress_list = BuildingProgress::where('building_id', '=', $item['id'])->order('addtime desc')->select()->toArray();
  133. $item->last_update_time = '';
  134. if (!empty($progress_list)) {
  135. foreach ($progress_list as $k => $p) {
  136. if (!empty($p['vr'])) {
  137. $vrs = explode(',', $p['vr']);
  138. $vr_count += count($vrs);
  139. }
  140. if (!empty($p['addtime']) && $k == 0) {
  141. $item->last_update_time = $p['addtime'];
  142. }
  143. }
  144. }
  145. $item->vr_count = $vr_count;
  146. })->toArray();
  147. /*if (!empty($list)) {
  148. $sort = array_column($list,'pinyin');
  149. array_multisort($sort, SORT_ASC, $list);
  150. }*/
  151. //增加转发次数浏览时长
  152. if(!empty($list)){
  153. $statismod=new MaterialLogic;
  154. $selorder=!empty($param['order'])?$param['order']:'';
  155. $list=$statismod->sel_case_share($list,'Building',$selorder);
  156. }
  157. $count = BuildingModel::where($where)->count();
  158. return json(['code'=> 0, 'data'=> $list, 'count'=> $count]);
  159. }
  160. //手机端上传人员列表
  161. public function mobile_up_emp()
  162. {
  163. $eid = BuildingModel::where([['del', '=', 0], ['from', '=', 1], ['root_id', '=', request()->employee->root_id], ['employee_id', '>', 0]])->group('employee_id')->column('employee_id');
  164. $where = [
  165. ['id', 'in', $eid],
  166. ['root_id', '=', request()->employee->root_id]
  167. ];
  168. $list = Employee::where($where)->field(['id', 'name'])->select()->toArray();
  169. return $list;
  170. }
  171. /**
  172. * 楼盘名称列表
  173. */
  174. public function name_list()
  175. {
  176. $from=input('from');
  177. $where[] = ['root_id', '=', request()->employee->root_id];
  178. $where[] = ['from', '=', $from];
  179. $list = BuildingModel::where($where)->column('community_id');
  180. //$list = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'];
  181. $condition[] = ['root_id', '=', request()->employee->root_id];
  182. $condition[] = ['id', 'in', $list];
  183. $communities = Community::where($condition)->where([['type', '=', 0]])->order('pinyin asc')->select()->toArray();
  184. $first = [];
  185. if (!empty($communities)) {
  186. $communities = hanziheadstr($communities);
  187. $first = $communities['sort'];
  188. }
  189. return json(['code' => 0, 'data' => array_values(array_filter($first, function ($arr) {
  190. if ($arr === '' || $arr === null) {
  191. return false;
  192. }
  193. return true;
  194. }))]);
  195. }
  196. /**
  197. * 添加楼盘
  198. */
  199. public function add()
  200. {
  201. if (!request()->isPost()) {
  202. $condition = [['root_id', '=', request()->employee->root_id]];
  203. //小区名称获取
  204. $communities = Community::where($condition)->where([['type', '=', 0]])->order('pinyin asc')->select()->toArray();
  205. if (!empty($communities)) {
  206. $communities = hanziheadstr($communities);
  207. }
  208. View::assign('communities', $communities);
  209. return View::fetch();
  210. }
  211. $param = request()->only(['name', 'community_id', 'address', 'duetime', 'cover', 'vr_link'=>'', 'content', 'sign_num', 'start_num', 'finish_num','vr_group_ids','cover_share_img']);
  212. /*$name = $param['name'];
  213. $first_name = mb_substr($name, 0, 1);
  214. // 开头不是字母也不是汉字,限制添加
  215. if (!ctype_alpha($first_name) && !preg_match("/[\x{4e00}-\x{9fff}]+/u", $first_name)){
  216. return json(['code'=> 1, 'msg'=> '小区名称首字限制为字母或汉字']);
  217. }
  218. $param['pinyin'] = getfirstchar($first_name);*/
  219. $param['employee_id'] = request()->employee->id;
  220. $param['root_id'] = request()->employee->root_id;
  221. if (!empty($param['vr_link'])) {
  222. $param['vr_link'] = $this->vrlink_set($param['vr_link']);
  223. }
  224. if (!empty($param['cover'])) {
  225. $param['cover'] = implode(',', $param['cover']);
  226. }
  227. $param['duetime'] = empty($param['duetime']) ? null : $param['duetime'];
  228. $result = BuildingModel::create($param);
  229. if ($result) {
  230. dataStatistics(request()->employee->root_id,'building_count',1,'inc');//manage应用首页统计数据
  231. return json(['code' => 0, 'msg' => '添加成功']);
  232. } else {
  233. return json(['code' => 1, 'msg' => '添加失败']);
  234. }
  235. }
  236. /**
  237. * 编辑楼盘
  238. */
  239. public function edit()
  240. {
  241. if (!request()->isPost()) {
  242. $condition = [['root_id', '=', request()->employee->root_id]];
  243. //小区名称获取
  244. $communities = Community::where($condition)->where([['type', '=', 0]])->order('pinyin asc')->select()->toArray();
  245. if (!empty($communities)) {
  246. $communities = hanziheadstr($communities);
  247. }
  248. View::assign('communities', $communities);
  249. $id = input('id', '', 'intval');
  250. $info = BuildingModel::find($id);
  251. $info->group_name = $info->vr_group_ids ? (VrGroup::where('id',$info->vr_group_ids)->value('title') ?: '未命名作品') : '';
  252. View::assign('data', $info);
  253. View::assign('id', $id);
  254. return View::fetch();
  255. }
  256. $param = request()->only(['id', 'community_id', 'name', 'address', 'duetime', 'cover', 'vr_link'=>'', 'content', 'sign_num', 'start_num', 'finish_num','vr_group_ids','cover_share_img']);
  257. /*$name = $param['name'];
  258. $first_name = mb_substr($name, 0, 1);
  259. // 开头不是字母也不是汉字,限制添加
  260. if (!ctype_alpha($first_name) && !preg_match("/[\x{4e00}-\x{9fff}]+/u", $first_name)){
  261. return json(['code'=> 1, 'msg'=> '小区名称首字限制为字母或汉字']);
  262. }
  263. $param['pinyin'] = getfirstchar($first_name);*/
  264. if (!empty($param['vr_link'])) {
  265. $param['vr_link'] = $this->vrlink_set($param['vr_link']);
  266. }
  267. if (!empty($param['cover'])) {
  268. $new_img = $param['cover'];
  269. }
  270. $img_exist = input('img_exist', [], 'trim');
  271. foreach ($img_exist as $key => $val) {
  272. $img_exist[$key] = str_replace('https://' . config('app.ali_oss_bindurl') . '/', '', $val);
  273. }
  274. $img = [];
  275. if (!empty($new_img) && !empty($img_exist)) {
  276. $img = array_merge($new_img, $img_exist);
  277. } elseif (!empty($new_img)) {
  278. $img = $new_img;
  279. } elseif (!empty($img_exist)) {
  280. $img = $img_exist;
  281. }
  282. $param['cover'] = implode(',', $img);
  283. // var_dump($param);
  284. // exit;
  285. $param['duetime'] = empty($param['duetime']) ? null : $param['duetime'];
  286. $result = BuildingModel::where('id', $param['id'])->save($param);
  287. if ($result !== false) {
  288. return json(['code' => 0, 'msg' => '保存成功']);
  289. } else {
  290. return json(['code' => 1, 'msg' => '保存失败']);
  291. }
  292. }
  293. /**
  294. * 删除楼盘
  295. */
  296. public function delete()
  297. {
  298. $id = input('id', '', 'intval');
  299. $find = BuildingModel::find($id);
  300. if (empty($find)) {
  301. return json(['code' => 0, 'msg' => '删除成功']);
  302. }
  303. if ($find['root_id'] != request()->employee->root_id) {
  304. return json(['code' => 1, 'msg' => '删除失败']);
  305. }
  306. $result = $find->delete();
  307. if ($result !== false) {
  308. dataStatistics(request()->employee->root_id,'building_count',1,'dec');//manage应用首页统计数据
  309. return json(['code' => 0, 'msg' => '删除成功']);
  310. } else {
  311. return json(['code' => 1, 'msg' => '删除失败']);
  312. }
  313. }
  314. /**
  315. * 户型
  316. * @return string
  317. */
  318. public function housetype()
  319. {
  320. $building_id = input('building_id', '', 'intval');
  321. if (!request()->isAjax()) {
  322. $data = BuildingModel::find($building_id);
  323. View::assign('data', $data);
  324. View::assign('building_id', $building_id);
  325. return View::fetch();
  326. }
  327. $community_id = input('community_id', '', 'intval');
  328. if ($community_id) {
  329. return $this->selectHouseType($community_id);
  330. }
  331. $page = input('page',0);
  332. $limit = input('limit',10);
  333. $list = BuildingHousetype::where('building_id', '=', $building_id)->withCount(['materialCase', 'devcase'])->order('id desc')->page($page,$limit)->select()->toArray();
  334. $count = BuildingHousetype::where('building_id', '=', $building_id)->count();
  335. foreach ($list as $k => $v) {
  336. $list[$k]['construction_count'] = $v['constructionid'] ? count(explode(',',$v['constructionid'])) : 0;
  337. }
  338. return json(['code' => 0, 'data' => $list,'count'=>$count]);
  339. }
  340. private function selectHouseType($community_id){
  341. $building_id = BuildingModel::where(['community_id'=>$community_id])->value('id');
  342. $h = BuildingHousetype::where('building_id', '=', $building_id)->select();
  343. $nh = [1 => '一', 2 => '二', 3 => '三', 4 => '四', 5 => '五', 6 => '六', 7 => '七', 8 => '八', 9 => '九'];
  344. $data = [];
  345. foreach($h as $i){
  346. $r = $i['room']==9?'别墅':$nh[$i['room']].'室'.$nh[$i['hall']].'厅'.$nh[$i['bathroom']].'卫';
  347. $data[] = ['id'=>$i['id'], 'housetype'=>$r];
  348. }
  349. return json(['code' => 0, 'data' => $data]);
  350. }
  351. //vr链接设置修改
  352. public function vrlink_set($vr_link)
  353. {
  354. //2023-05-04 志远装饰app创建的vr作品
  355. if (strpos($vr_link,'/vr/#')) return $vr_link;
  356. // 旧域名 替换成 新域名
  357. $links = [
  358. 'xiaohongwu' => 'hnweizhihui.xiaohongwu.nczyzs.com',
  359. 'kujiale' => 'pano337.p.kujiale.com',
  360. 'justeasy' => 'vr-17.justeasy.nczyzs.com',
  361. '3d66' => 'vr.3d66.nczyzs.com',
  362. ];
  363. $url = parse_url($vr_link);
  364. if ($url === false || !isset($url['host'])) {
  365. echo json_encode(['code' => 1, 'msg' => '链接格式错误']);
  366. exit;
  367. }
  368. if (strpos($url['host'], 'xiaohongwu') !== false) {
  369. return str_replace($url['host'], $links['xiaohongwu'], $vr_link);
  370. }
  371. if (strpos($url['host'], 'kujiale') !== false) {
  372. return str_replace($url['host'], $links['kujiale'], $vr_link);
  373. }
  374. if (strpos($url['host'], 'justeasy') !== false) {
  375. return str_replace($url['host'], $links['justeasy'], $vr_link);
  376. }
  377. if (strpos($url['host'], '3d66') !== false) {
  378. return str_replace($url['host'], $links['3d66'], $vr_link);
  379. }
  380. echo json_encode(['code' => 1, 'msg' => '无效的VR链接']);
  381. exit;
  382. }
  383. /**
  384. * 添加户型
  385. * @return string
  386. */
  387. public function add_housetype()
  388. {
  389. $building_id = input('building_id', '', 'intval');
  390. if (!request()->isPost()) {
  391. View::assign('building_id', $building_id);
  392. return View::fetch();
  393. }
  394. $param = request()->only(['vr_group_ids'=>'','building_id', 'type', 'area', 'room', 'hall', 'bathroom', 'vr_link', 'house_img', 'house_count', 'orientation','reference_price','constructionid','notes']);
  395. $param['root_id'] = request()->employee->root_id;
  396. $orientation = null;
  397. if (!empty($param['orientation'])) {
  398. foreach ($param['orientation'] as $key => $val) {
  399. $orientation .= $key . ',';
  400. }
  401. $param['orientation'] = trim($orientation, ',');
  402. }
  403. $url = 'hnweizhihui.xiaohongwu';
  404. $jurl = 'web.xiaohongwu';
  405. if (!empty($param['vr_link'])) {
  406. $param['vr_link'] = $this->vrlink_set($param['vr_link']);
  407. }
  408. //增加别墅户型(其室厅卫值都为999)
  409. if ($param['type'] == 2) {
  410. $param['room'] = 9;
  411. $param['hall'] = 9;
  412. $param['bathroom'] = 9;
  413. }
  414. $result = BuildingHousetype::insertGetId($param);
  415. $more_files = input('more_files', '', 'html_entity_decode');
  416. if (!empty($more_files)) {
  417. $more_files = json_decode($more_files, true);
  418. $files = [];
  419. foreach ($more_files as $k => $v) {
  420. $v_data['housetype_id'] = $result;
  421. $v_data['filename'] = $v['filename'];
  422. $v_data['filesize'] = $v['filesize'];
  423. $v_data['fileurl'] = $v['fileurl'];
  424. $v_data['employee_id'] = request()->employee->id;
  425. $v_data['root_id'] = request()->employee->root_id;
  426. $files[] = $v_data;
  427. }
  428. BuildingHousetypeFile::insertAll($files);
  429. }
  430. if ($result) {
  431. return json(['code' => 0, 'msg' => '添加成功']);
  432. } else {
  433. return json(['code' => 1, 'msg' => '添加失败']);
  434. }
  435. }
  436. /**
  437. * 编辑户型
  438. * @return string
  439. */
  440. public function edit_housetype()
  441. {
  442. $id = input('id', '', 'intval');
  443. if (!request()->isPost()) {
  444. $info = BuildingHousetype::find($id);
  445. $info['orientation'] = explode(',', $info->getData('orientation'));
  446. $info->group_name = $info->vr_group_ids ? (VrGroup::where('id', $info->vr_group_ids)->value('title') ?: '未命名作品') : '';
  447. $info['files'] = BuildingHousetypeFile::where('housetype_id', '=', $id)->select()->toArray();
  448. View::assign('data', $info);
  449. return View::fetch();
  450. }
  451. $param = request()->only(['vr_group_ids'=>'','id', 'area', 'room', 'hall', 'bathroom', 'vr_link', 'house_img', 'house_count', 'orientation', 'type', 'title', 'images_exist', 'images_data', 'from','reference_price','constructionid','notes']);
  452. $info = BuildingHousetype::find($param['id']);
  453. if (!empty($param['vr_link'])) {
  454. $param['vr_link'] = $this->vrlink_set($param['vr_link']);
  455. }
  456. $orientation = null;
  457. if (!empty($param['orientation'])) {
  458. foreach ($param['orientation'] as $key => $val) {
  459. $orientation .= $key . ',';
  460. }
  461. $param['orientation'] = trim($orientation, ',');
  462. }
  463. //增加别墅户型(其室厅卫值都为999)
  464. if ($param['type'] == 2) {
  465. $param['room'] = 9;
  466. $param['hall'] = 9;
  467. $param['bathroom'] = 9;
  468. }
  469. if ($param['from'] == 1) {
  470. $param['house_count'] = !empty($param['title']) ? $param['title'] : '';
  471. $img = [];
  472. $newimg = [];
  473. $images_exist = !empty($param['images_exist']) ? $param['images_exist'] : '';
  474. $images_data = !empty($param['images_data']) ? $param['images_data'] : '';
  475. if (!empty($images_exist) && !empty($images_data)) {
  476. $img = array_merge($images_data, $images_exist);
  477. } elseif (!empty($images_exist)) {
  478. $img = $images_exist;
  479. } elseif (!empty($images_data)) {
  480. $img = $images_data;
  481. }
  482. if (!empty($img)) {
  483. foreach ($img as $key => $val) {
  484. $newimg[] = str_replace('https://' . config('app.ali_oss_bindurl') . '/', '', $val);
  485. }
  486. }
  487. $param['img_content'] = implode(',', $newimg);
  488. }
  489. $more_files = input('more_files', '', 'html_entity_decode');
  490. if (!empty($more_files)) {
  491. $more_files = json_decode($more_files, true);
  492. $old_files = [];
  493. $new_files = [];
  494. $delete_files = [];
  495. $old_files = BuildingHousetypeFile::where('housetype_id', '=', $id)->select()->toArray();
  496. $save_ids = array_filter(array_column($more_files, 'id'));
  497. foreach ($old_files as $k => $v) {
  498. if (!in_array($v['id'], $save_ids)) {
  499. BuildingHousetypeFile::where('id', '=', $v['id'])->delete();
  500. }
  501. }
  502. foreach ($more_files as $k => $v) {
  503. if (empty($v['id'])) {
  504. $v_data['housetype_id'] = $id;
  505. $v_data['filename'] = $v['filename'];
  506. $v_data['filesize'] = $v['filesize'];
  507. $v_data['fileurl'] = $v['fileurl'];
  508. $v_data['employee_id'] = request()->employee->id;
  509. $v_data['root_id'] = request()->employee->root_id;
  510. $new_files[] = $v_data;
  511. }
  512. }
  513. BuildingHousetypeFile::insertAll($new_files);
  514. } else {
  515. BuildingHousetypeFile::where([['housetype_id', '=', $id], ['root_id', '=', request()->employee->root_id]])->delete();
  516. }
  517. $result = $info->save($param);
  518. return json(['code' => 0, 'msg' => '修改成功']);
  519. if ($result) {
  520. return json(['code' => 0, 'msg' => '修改成功']);
  521. } else {
  522. return json(['code' => 1, 'msg' => '修改失败']);
  523. }
  524. }
  525. public function delete_housetype()
  526. {
  527. $id = input('id', '', 'intval');
  528. $find = BuildingHousetype::find($id);
  529. if (empty($find)) {
  530. return json(['code' => 0, 'msg' => '删除成功']);
  531. }
  532. if ($find['root_id'] != request()->employee->root_id) {
  533. return json(['code' => 1, 'msg' => '删除失败']);
  534. }
  535. $result = $find->delete();
  536. if ($result !== false) {
  537. return json(['code' => 0, 'msg' => '删除成功']);
  538. } else {
  539. return json(['code' => 1, 'msg' => '删除失败']);
  540. }
  541. }
  542. /**
  543. * 进度
  544. * @return string
  545. */
  546. public function progress()
  547. {
  548. if (!request()->isAjax()) {
  549. $building_id = input('building_id', '', 'intval');
  550. View::assign('building_id', $building_id);
  551. return View::fetch();
  552. }
  553. $building_id = input('building_id', '', 'intval');
  554. $list = BuildingProgress::with(['label'=>function($query){
  555. $query->withField(['id','name']);
  556. }])->where('building_id', '=', $building_id)->order('addtime desc')->select()->each(function ($item) {
  557. if (!empty($item['vr'])) {
  558. $item->vr = explode(',', $item['vr']);
  559. }
  560. })->toArray();
  561. $gids = array_column($list,'vr_group_ids');
  562. $group_ids = VrGroup::where([['id','in',$gids]])->column('sid','id');
  563. $host = config('app.vr_show_domain');
  564. foreach ($list as $key => $value) {
  565. $sid = ($value['vr_group_ids'] && isset($group_ids[$value['vr_group_ids']])) ? $group_ids[$value['vr_group_ids']] : '';
  566. $list[$key]['show_url'] = $sid ? $host.$sid : '';
  567. }
  568. return json(['code' => 0, 'data' => $list]);
  569. }
  570. /**
  571. * 添加进度
  572. * @return string
  573. */
  574. public function add_progress()
  575. {
  576. if (!request()->isPost()) {
  577. $building_id = input('building_id', '', 'intval');
  578. View::assign('building_id', $building_id);
  579. $label = BuildingLabel::where(['root_id'=>request()->employee->root_id])->field('id,name')->select();
  580. View::assign('label', $label);
  581. View::assign('root_id', request()->employee->root_id);
  582. return View::fetch();
  583. }
  584. $param = request()->only(['building_id', 'name', 'type', 'img', 'vr', 'content', 'video', 'cover','vr_group_ids'=>'', 'label_id']);
  585. $param['root_id'] = request()->employee->root_id;
  586. if (!empty($param['vr'])) {
  587. $vr = explode(',', $param['vr']);
  588. foreach ($vr as $k => $v) {
  589. if (!empty($v)) {
  590. $vr[$k] = $this->vrlink_set($v);
  591. }
  592. }
  593. $param['vr'] = implode(',', $vr);
  594. }
  595. if (!empty($param['video'])) {
  596. $param['img'] = !empty($param['cover']) ? $param['cover'] : '';
  597. }
  598. $result = BuildingProgress::create($param);
  599. if ($result) {
  600. BuildingModel::where('id', '=', $param['building_id'])->save(['update_time' => date('Y-m-d H:i:s')]);
  601. return json(['code' => 0, 'msg' => '添加成功']);
  602. } else {
  603. return json(['code' => 1, 'msg' => '添加失败']);
  604. }
  605. }
  606. /**
  607. * 编辑进度
  608. * @return string
  609. */
  610. public function edit_progress()
  611. {
  612. $id = input('id', '', 'intval');
  613. if (!request()->isPost()) {
  614. $building_id = input('building_id', '', 'intval');
  615. View::assign('building_id', $building_id);
  616. $info = BuildingProgress::find($id);
  617. if ($info->vr_group_ids) {
  618. $group = VrGroup::where('id',$info->vr_group_ids)->field('title')->findOrEmpty();
  619. $info->vr_name = $group->isEmpty() ? '' : ($group->title ?: '未命名作品');
  620. } else {
  621. $info->vr_name = '';
  622. }
  623. View::assign('data', $info);
  624. View::assign('id', $id);
  625. $label = BuildingLabel::where(['root_id'=>request()->employee->root_id])->field('id,name')->select();
  626. View::assign('root_id', request()->employee->root_id);
  627. View::assign('label', $label);
  628. return View::fetch();
  629. }
  630. $param = request()->only(['id', 'name', 'type', 'vr', 'content', 'video', 'cover', 'covers', 'videos','vr_group_ids'=>'', 'label_id']);
  631. $find = BuildingProgress::find($param['id']);
  632. if (empty($find)) {
  633. return json(['code' => 1, 'msg' => '保存失败']);
  634. }
  635. $new_img = input('img', [], 'trim');
  636. $img_exist = input('img_exist', [], 'trim');
  637. $img = [];
  638. if (!empty($new_img) && !empty($img_exist)) {
  639. $img = array_merge($new_img, $img_exist);
  640. } elseif (!empty($new_img)) {
  641. $img = $new_img;
  642. } elseif (!empty($img_exist)) {
  643. $img = $img_exist;
  644. }
  645. $param['img'] = implode(',', $img);
  646. if (!empty($param['vr'])) {
  647. $vr = explode(',', $param['vr']);
  648. foreach ($vr as $k => $v) {
  649. if (!empty($v)) {
  650. $vr[$k] = $this->vrlink_set($v);
  651. }
  652. }
  653. $param['vr'] = implode(',', $vr);
  654. }
  655. if (!empty($param['video']) && $param['type'] == 'video') {
  656. $param['covers'] = !empty($param['covers']) ? $param['covers'] : '';
  657. $param['img'] = !empty($param['cover']) ? $param['cover'] : $param['covers'];
  658. }
  659. $result = $find->save($param);
  660. if ($result !== false) {
  661. BuildingModel::where('id', '=', $find['building_id'])->save(['update_time' => date('Y-m-d H:i:s')]);
  662. return json(['code' => 0, 'msg' => '保存成功']);
  663. } else {
  664. return json(['code' => 1, 'msg' => '保存失败']);
  665. }
  666. }
  667. /**
  668. * 删除进度
  669. */
  670. public function delete_progress()
  671. {
  672. $id = input('id', '', 'intval');
  673. $info = BuildingProgress::find($id);
  674. if ($info['root_id'] != request()->employee->root_id) {
  675. return json(['code' => 1, 'msg' => '删除失败']);
  676. }
  677. $result = $info->delete();
  678. if ($result !== false) {
  679. return json(['code' => 0, 'msg' => '删除成功']);
  680. } else {
  681. return json(['code' => 1, 'msg' => '删除失败']);
  682. }
  683. }
  684. /**
  685. * 关联案例
  686. * @return string
  687. */
  688. public function material_case()
  689. {
  690. if (!request()->isAjax()) {
  691. $housetype_id = input('housetype_id', '', 'intval');
  692. View::assign('housetype_id', $housetype_id);
  693. return View::fetch();
  694. }
  695. $param = request()->only([
  696. 'housetype_id' => 0,
  697. 'type' => '',
  698. 'title' => '',
  699. 'square_start' => '',
  700. 'square_end' => '',
  701. 'page' => 1,
  702. 'limit' => 10
  703. ]);
  704. $where[] = ['root_id', '=', request()->employee->root_id];
  705. if ($param['title']) {
  706. $where[] = ['title', 'like', '%' . $param['title'] . '%'];
  707. }
  708. if ($param['square_start'] && $param['square_end']) {
  709. $where[] = ['square', 'between', [$param['square_start'], $param['square_end']]];
  710. } elseif ($param['square_start']) {
  711. $where[] = ['square', '>', $param['square_start']];
  712. } elseif ($param['square_end']) {
  713. $where[] = ['square', '<', $param['square_end']];
  714. }
  715. // 此户型关联案例
  716. if (!empty($param['type'])) {
  717. $material_case_id = BuildingMaterialCase::where('housetype_id', '=', $param['housetype_id'])->column('material_case_id');
  718. $where[] = ['id', 'in', $material_case_id];
  719. $list = MaterialCase::where($where)->select()->each(function ($item) {
  720. $item->selected = 1;
  721. });
  722. $count = MaterialCase::where([['id', 'in', $material_case_id]])->count();
  723. return json(['code' => 0, 'data' => $list->toArray(), 'count' => $count]);
  724. }
  725. $list = MaterialCase::where($where)->select()->each(function ($item) use ($param) {
  726. $item->selected = false;
  727. $bind = BuildingMaterialCase::where([['housetype_id', '=', $param['housetype_id']], ['material_case_id', '=', $item['id']]])->find();
  728. if (!empty($bind)) {
  729. $item->selected = true;
  730. }
  731. });
  732. $count = MaterialCase::where($where)->count();
  733. return json(['code' => 0, 'data' => $list->toArray(), 'count' => $count]);
  734. }
  735. /**
  736. * 案例绑定解绑
  737. */
  738. public function change_material_case()
  739. {
  740. $housetype_id = input('housetype_id', '', 'intval');
  741. $material_case_id = input('material_case_id', '', 'trim');
  742. $material_case_id_list = explode(',', $material_case_id);
  743. $old_ids = BuildingMaterialCase::where([['housetype_id', '=', $housetype_id]])->column('material_case_id');
  744. $del_ids = array_diff($old_ids, $material_case_id_list);
  745. $new_ids = array_filter(array_diff($material_case_id_list, $old_ids));
  746. if (!empty($del_ids)) {
  747. BuildingMaterialCase::where([['housetype_id', '=', $housetype_id], ['root_id', '=', request()->employee->root_id], ['material_case_id', 'in', $del_ids]])->delete();
  748. }
  749. if (!empty($new_ids)) {
  750. $new_data = [];
  751. $building_id = BuildingHousetype::where('id', $housetype_id)->value('building_id');
  752. foreach ($new_ids as $k => $v) {
  753. $new_data[] = [
  754. 'building_id' => $building_id,
  755. 'housetype_id' => $housetype_id,
  756. 'material_case_id' => $v,
  757. 'root_id' => request()->employee->root_id
  758. ];
  759. }
  760. (new BuildingMaterialCase)->saveAll($new_data);
  761. }
  762. return json(['code' => 0, 'msg' => '操作成功']);
  763. }
  764. /**
  765. * 催更记录
  766. * @return string
  767. */
  768. public function urge_index()
  769. {
  770. if (!request()->isAjax()) {
  771. return View::fetch();
  772. }
  773. $param = request()->only(['page' => 1, 'limit' => 10]);
  774. $where[] = ['root_id', '=', request()->employee->root_id];
  775. $list = BuildingUrge::where($where)->with(['building', 'user', 'employee'])->page($param['page'], $param['limit'])->order('addtime desc')->select();
  776. $count = BuildingUrge::where($where)->count();
  777. return json(['code' => 0, 'data' => $list->toArray(), 'count' => $count]);
  778. }
  779. /**
  780. * 在施工地
  781. */
  782. public function construction()
  783. {
  784. //$building_id = input('building_id', '', 'intval');
  785. $housetype_id = input('housetype_id', '', 'intval');
  786. if (!request()->isAjax()) {
  787. View::assign('housetype_id', $housetype_id);
  788. $root_id = request()->employee['root_id'];
  789. $step_list = ConstructionStep::where('root_id', '=', $root_id)->order('order asc')->select();
  790. View::assign('step_list', $step_list);
  791. return View::fetch();
  792. }
  793. $root_id = request()->employee['root_id'];
  794. //$construction_ids = BuildingConstruction::where([['building_id', '=', $building_id], ['root_id', '=', $root_id]])->column('construction_id');
  795. $construction_str = BuildingHousetype::where([['id', '=', $housetype_id], ['root_id', '=', $root_id]])->value('constructionid');
  796. $construction_ids = !empty($construction_str) ? explode(',',$construction_str) : [];
  797. $where[] = ['root_id', '=', $root_id];
  798. $list = ConstructionModel::with(['style', 'designer', 'housetype', 'community', 'employee'])->where($where)->order('id desc')->select()->each(function ($item) use ($construction_ids) {
  799. $new_step = ConstructionStep::hasWhere('record', [['construction_id', '=', $item->id]])->order('order desc')->findOrEmpty();
  800. if (!$new_step->isEmpty()) {
  801. $item->step_name = $new_step->name;
  802. } else {
  803. $item->step_name = '';
  804. }
  805. if (in_array($item['id'], $construction_ids)) {
  806. $item->selected = 1;
  807. } else {
  808. $item->selected = 0;
  809. }
  810. });
  811. return json(['code' => 0, 'data' => $list->toArray(), 'count' => $list->count()]);
  812. }
  813. /**
  814. * 关联在施工地
  815. */
  816. public function change_construction()
  817. {
  818. //$building_id = input('building_id', '', 'intval');
  819. $housetype_id = input('housetype_id', '', 'intval');
  820. if (!request()->isAjax()) {
  821. View::assign('housetype_id', $housetype_id);
  822. return View::fetch();
  823. }
  824. $construction_id = input('construction_id', '', 'trim');
  825. //$construction_id_list = explode(',', $construction_id);
  826. $housetype_data = BuildingHousetype::find($housetype_id);
  827. if(empty($housetype_data)) return json(['code' => 1, 'msg' => '数据不存在']);
  828. $housetype_data->constructionid = $construction_id;
  829. $housetype_data->save();
  830. return json(['code' => 0, 'msg' => '操作成功']);
  831. }
  832. /*
  833. * 小区管理
  834. */
  835. function community()
  836. {
  837. return View::fetch();
  838. }
  839. //部门人员树
  840. public function tree($data, $pid = 0, $persons)
  841. {
  842. $new_arr = [];
  843. foreach ($data as $k => $v) {
  844. if ($v['pid'] == $pid) {
  845. $persions = isset($persons[$v['id']]) ? $persons[$v['id']] : [];
  846. $children = $this->tree($data, $v['id'], $persons);
  847. $v['children'] = array_merge_recursive($children, $persions);
  848. if (empty($v['children'])) $v['disabled'] = true;
  849. $new_arr[] = $v;
  850. }
  851. }
  852. return $new_arr;
  853. }
  854. /**
  855. * 指派人员
  856. * @param $id
  857. * @return \think\response\Json
  858. * @throws \think\db\exception\DataNotFoundException
  859. * @throws \think\db\exception\DbException
  860. * @throws \think\db\exception\ModelNotFoundException
  861. */
  862. public function get_person($id)
  863. {
  864. $ids = input('id', '');
  865. $root_id = request()->employee->root_id;
  866. $keyword = input('keyword', '');
  867. //所有员工
  868. $w1[] = ['root_id', '=', $root_id];
  869. $w1[] = ['state', '=', '在职'];
  870. $w1[] = ['org_id', '>', 0];
  871. $w1[] = ['uid', '>', 0];
  872. if ($keyword) {
  873. $w1[] = ['name', 'like', '%' . $keyword . '%'];
  874. }
  875. $employee = Employee::where($w1)->field('id,name title,org_id,is_manager')->order('is_manager desc,id desc')->select()->toArray();
  876. if ($ids) {
  877. $ids = explode(',', $ids);
  878. foreach ($employee as $k => &$v) {
  879. $v['selected'] = in_array($v['id'], $ids);
  880. $v['children'] = [];
  881. $v['title'] = $v['is_manager'] ? $v['title'] . '(负责人)' : $v['title'];
  882. $v['org_class'] = 'org_' . $v['org_id'];
  883. $v['per_class'] = 'per_' . $v['id'];
  884. $v['type'] = 'per';
  885. }
  886. } else {
  887. foreach ($employee as $k => &$v) {
  888. $v['selected'] = false;
  889. $v['children'] = [];
  890. $v['all_count'] = 0;
  891. $v['title'] = $v['is_manager'] ? $v['title'] . '(负责人)' : $v['title'];
  892. $v['org_class'] = 'org_' . $v['org_id'];
  893. $v['per_class'] = 'per_' . $v['id'];
  894. $v['type'] = 'per';
  895. }
  896. }
  897. $persons = [];
  898. foreach ($employee as $k => $v1) {
  899. $persons[$v1['org_id']][] = $v1;
  900. }
  901. $where = [
  902. ['path', 'like', $root_id . '-%'],
  903. ['status', '=', 1]
  904. ];
  905. $count = Employee::where([['root_id', '=', $root_id], ['state', '=', '在职'], ['uid', '>', 0]])->group('org_id')->column('count(*) count', 'org_id');
  906. $allnodes = Org::where($where)->field('id,pid,name title,level,org_type,info,path')->order('level asc, id asc')->select()->toarray();
  907. foreach ($allnodes as $k => $v) {
  908. $allnodes[$k]['count'] = isset($count[$v['id']]) ? $count[$v['id']] : 0; //本部门人数
  909. $allnodes[$k]['all_count'] = 0; //包含子部门总数
  910. $allnodes[$k]['org_class'] = 'org_' . $v['id'];
  911. $allnodes[$k]['per_class'] = 'per_org_' . $v['id'];
  912. $allnodes[$k]['type'] = 'org';
  913. foreach ($allnodes as $k2 => $v2) {
  914. if (strpos($v2['path'], $v['path']) !== false) {
  915. $allnodes[$k]['all_count'] = isset($count[$v2['id']]) ? $count[$v2['id']] + $allnodes[$k]['all_count'] : $allnodes[$k]['all_count'];
  916. }
  917. }
  918. $allnodes[$k]['title'] = $allnodes[$k]['title'] . ' (' . $allnodes[$k]['all_count'] . ')';
  919. }
  920. $tree = $this->tree($allnodes, 0, $persons);
  921. if (empty($id)) {
  922. $info = BuildingSpecialEmp::where(['root_id' => request()->employee->root_id])->value('assign_employee');
  923. } else {
  924. $info = BuildingModel::where(['root_id' => request()->employee->root_id, 'id' => $id])->value('assign_employee');
  925. }
  926. return json(['code' => 0, 'data' => $tree, 'checkOrg' => $info]);
  927. }
  928. public function building_assigns()
  929. {
  930. if (!request()->isAjax()) {
  931. $id = input('id', '', 'intval');
  932. View::assign('id', $id);
  933. $assign_employee = BuildingModel::where(['root_id' => request()->employee->root_id, 'id' => $id])->value('assign_employee');
  934. $count = $assign_employee ? count(explode(',', $assign_employee)) : 0;
  935. view::assign('count', $count);
  936. return View::fetch();
  937. }
  938. $id = input('id', '', 'intval');
  939. $pid = input('pid', '', 'trim'); //多选框选中id
  940. $type = input('type', '', 'trim'); //选中类型,人/部门
  941. $res = input('res', '', 'trim'); //选择结果 1选中,0取消
  942. $data = [];
  943. $assign_employee = BuildingModel::where(['root_id' => request()->employee->root_id, 'id' => $id])->value('assign_employee');
  944. $a = 0;
  945. if ($type == 'per' && $pid) {
  946. $data[] = 'per_' . $pid;
  947. $pid = [$pid];
  948. $a = 1;
  949. } elseif ($type == 'org' && $pid) {
  950. $data[] = 'org_' . $pid;
  951. $org = Org::where([['id', '=', $pid]])->value('path');
  952. $orgs = Org::where([['path', 'like', $org . '%']])->column('id');
  953. $pid = Employee::where([['root_id', '=', request()->employee->root_id], ['org_id', 'in', $orgs], ['state', '=', '在职'], ['uid', '>', 0]])->order('is_manager desc,id desc')->column('id');
  954. $a = 1;
  955. foreach ($pid as $v) {
  956. $data[] = 'per_' . $v;
  957. }
  958. foreach ($orgs as $v2) {
  959. $data[] = 'org_' . $v2;
  960. }
  961. }
  962. $assign_employee = explode(',', $assign_employee);
  963. if ($a) {
  964. $arr = array_filter(array_diff($assign_employee, $pid));
  965. $arr = $res ? array_merge($pid, $arr) : $arr;
  966. $arr = array_unique($arr);
  967. //过滤运营人员,旧bug导致选择根部门时,运营人员也会在内
  968. $arr = Employee::where([['id', 'in', $arr], ['uid', '>', 0], ['state', '=', '在职']])->column('id');
  969. //查询指派人的组织
  970. $employee_org = Employee::where('id', 'in', $arr)->group('org_id')->column('org_id');
  971. $employee_org = implode(',', $employee_org);
  972. BuildingModel::where(['root_id' => request()->employee->root_id, 'id' => $id])->update(['assign_org_id' => $employee_org, 'assign_employee' => implode(',', $arr)]);
  973. }
  974. return json(['code' => 0, 'data' => $data]);
  975. }
  976. /*
  977. * 指派展示列表
  978. */
  979. public function building_assigns_list()
  980. {
  981. $id = input('id', '', 'intval');
  982. $page = input('page', 1, 'intval');
  983. $limit = input('limit', 10, 'intval');
  984. $keyword = input('keyword', '', 'trim');
  985. if ($keyword) {
  986. $w[] = ['name', 'like', '%' . $keyword . '%'];
  987. }
  988. $arr = BuildingModel::where(['root_id' => request()->employee->root_id, 'id' => $id])->value('assign_employee');
  989. $arr = $arr ? explode(',', $arr) : [];
  990. $w[] = ['id', 'in', $arr];
  991. $w[] = ['state', '=', '在职'];
  992. $w[] = ['uid', '>', 0];
  993. $data = Employee::with('orgName')->where($w)->visible(['name', 'org_name', 'id', 'is_manager'])->select()->toArray();
  994. $count = count($data);
  995. $arr = array_flip($arr);
  996. foreach ($data as $k => $v) {
  997. $data[$k]['order'] = $arr[$v['id']];
  998. }
  999. array_multisort($data, SORT_ASC, array_column($data, 'order'));
  1000. foreach ($data as $k => $v) {
  1001. $data[$k]['xh'] = $k + 1;
  1002. }
  1003. $data = array_slice($data, ($page - 1) * $limit, $limit);
  1004. return json(['code' => 0, 'data' => $data, 'count' => $count]);
  1005. }
  1006. /**
  1007. * 删除指派
  1008. * @return \think\response\Json
  1009. */
  1010. public function del_assign()
  1011. {
  1012. $id = input('id', '', 'intval');
  1013. $eid = input('eid', '', 'intval');
  1014. if ($id && $eid) {
  1015. if ($eid == -1) {
  1016. BuildingModel::where(['root_id' => request()->employee->root_id, 'id' => $id])->update(['assign_employee' => '', 'assign_org_id'=> '']);
  1017. } else {
  1018. $arr = BuildingModel::where(['root_id' => request()->employee->root_id, 'id' => $id])->value('assign_employee');
  1019. $arr = array_filter(array_diff(explode(',', $arr), [$eid]));
  1020. $data = [];
  1021. if (empty($arr)){
  1022. $data['assign_employee'] = '';
  1023. $data['assign_org_id'] = '';
  1024. } else {
  1025. $data['assign_employee'] = implode(',', $arr);
  1026. $assign_org_id = Employee::where('id', 'in', $arr)->group('org_id')->column('org_id');
  1027. $data['assign_org_id'] = implode(',', $assign_org_id);
  1028. }
  1029. BuildingModel::where(['root_id' => request()->employee->root_id, 'id' => $id])->update($data);
  1030. }
  1031. }
  1032. return json(['code' => 0, 'data' => '取消成功', 'msg' => '取消成功']);
  1033. }
  1034. //展示已设置可见人
  1035. public function building_special_assigns()
  1036. {
  1037. if (!request()->isAjax()) {
  1038. // $id = input('id', '', 'intval');
  1039. // View::assign('id', $id);
  1040. $assign_employee = BuildingSpecialEmp::where(['root_id' => request()->employee->root_id])->value('assign_employee');
  1041. $count = $assign_employee ? count(explode(',', $assign_employee)) : 0;
  1042. view::assign('count', $count);
  1043. return View::fetch();
  1044. }
  1045. $id = input('id', '', 'intval');
  1046. $pid = input('pid', '', 'trim'); //多选框选中id
  1047. $type = input('type', '', 'trim'); //选中类型,人/部门
  1048. $res = input('res', '', 'trim'); //选择结果 1选中,0取消
  1049. $data = [];
  1050. $assign_employee = BuildingSpecialEmp::where(['root_id' => request()->employee->root_id])->value('assign_employee');
  1051. $a = 0;
  1052. if ($type == 'per' && $pid) {
  1053. $data[] = 'per_' . $pid;
  1054. $pid = [$pid];
  1055. $a = 1;
  1056. } elseif ($type == 'org' && $pid) {
  1057. $data[] = 'org_' . $pid;
  1058. $org = Org::where([['id', '=', $pid]])->value('path');
  1059. $orgs = Org::where([['path', 'like', $org . '%']])->column('id');
  1060. $pid = Employee::where([['root_id', '=', request()->employee->root_id], ['org_id', 'in', $orgs], ['state', '=', '在职'], ['uid', '>', 0]])->order('is_manager desc,id desc')->column('id');
  1061. $a = 1;
  1062. foreach ($pid as $v) {
  1063. $data[] = 'per_' . $v;
  1064. }
  1065. foreach ($orgs as $v2) {
  1066. $data[] = 'org_' . $v2;
  1067. }
  1068. }
  1069. $assign_employee = explode(',', $assign_employee);
  1070. if ($a) {
  1071. $arr = array_filter(array_diff($assign_employee, $pid));
  1072. $arr = $res ? array_merge($pid, $arr) : $arr;
  1073. $arr = array_unique($arr);
  1074. //过滤运营人员,旧bug导致选择根部门时,运营人员也会在内
  1075. $arr = Employee::where([['id', 'in', $arr], ['uid', '>', 0], ['state', '=', '在职']])->column('id');
  1076. //查询指派人的组织
  1077. $employee_org = Employee::where('id', 'in', $arr)->group('org_id')->column('org_id');
  1078. $employee_org = implode(',', $employee_org);
  1079. $you = BuildingSpecialEmp::where('root_id', request()->employee->root_id)->find();
  1080. if (empty($you)) {
  1081. $add = ['root_id' => request()->employee->root_id, 'assign_org_id' => $employee_org, 'assign_employee' => implode(',', $arr)];
  1082. BuildingSpecialEmp::insert($add);
  1083. } else {
  1084. BuildingSpecialEmp::where(['root_id' => request()->employee->root_id])->update(['assign_org_id' => $employee_org, 'assign_employee' => implode(',', $arr)]);
  1085. }
  1086. }
  1087. return json(['code' => 0, 'data' => $data]);
  1088. }
  1089. /*
  1090. * 可见人展示列表
  1091. */
  1092. public function building_special_list()
  1093. {
  1094. $page = input('page', 1, 'intval');
  1095. $limit = input('limit', 10, 'intval');
  1096. $keyword = input('keyword', '', 'trim');
  1097. if ($keyword) {
  1098. $w[] = ['name', 'like', '%' . $keyword . '%'];
  1099. }
  1100. $arr = BuildingSpecialEmp::where(['root_id' => request()->employee->root_id])->value('assign_employee');
  1101. $arr = $arr ? explode(',', $arr) : [];
  1102. $w[] = ['id', 'in', $arr];
  1103. $w[] = ['state', '=', '在职'];
  1104. $w[] = ['uid', '>', 0];
  1105. $data = Employee::with('orgName')->where($w)->visible(['name', 'org_name', 'id', 'is_manager'])->select()->toArray();
  1106. $count = count($data);
  1107. $arr = array_flip($arr);
  1108. foreach ($data as $k => $v) {
  1109. $data[$k]['order'] = $arr[$v['id']];
  1110. }
  1111. array_multisort($data, SORT_ASC, array_column($data, 'order'));
  1112. foreach ($data as $k => $v) {
  1113. $data[$k]['xh'] = $k + 1;
  1114. }
  1115. $data = array_slice($data, ($page - 1) * $limit, $limit);
  1116. return json(['code' => 0, 'data' => $data, 'count' => $count]);
  1117. }
  1118. /**
  1119. * 删除指派
  1120. * @return \think\response\Json
  1121. */
  1122. public function del_special_emp()
  1123. {
  1124. $eid = input('eid', '', 'intval');
  1125. if ($eid) {
  1126. if ($eid == -1) {
  1127. BuildingSpecialEmp::where(['root_id' => request()->employee->root_id])->update(['assign_employee' => '']);
  1128. } else {
  1129. $arr = BuildingSpecialEmp::where(['root_id' => request()->employee->root_id])->value('assign_employee');
  1130. $arr = array_filter(array_diff(explode(',', $arr), [$eid]));
  1131. BuildingSpecialEmp::where(['root_id' => request()->employee->root_id])->update(['assign_employee' => implode(',', $arr)]);
  1132. }
  1133. }
  1134. return json(['code' => 0, 'data' => '取消成功', 'msg' => '取消成功']);
  1135. }
  1136. //已设置的可见人列表
  1137. public function special_emplist()
  1138. {
  1139. $arr = BuildingSpecialEmp::where(['root_id' => request()->employee->root_id])->value('assign_employee');
  1140. $arr = $arr ? explode(',', $arr) : [];
  1141. $w[] = ['id', 'in', $arr];
  1142. $w[] = ['state', '=', '在职'];
  1143. $w[] = ['uid', '>', 0];
  1144. $data = Employee::where($w)->visible(['name', 'id'])->select()->toArray();
  1145. return json(['code' => 0, 'data' => $data, 'msg' => '获取成功']);
  1146. }
  1147. /**
  1148. * 研发案例
  1149. */
  1150. public function dev_case()
  1151. {
  1152. $param = request()->only(['housetype_id', '']);
  1153. View::assign('housetype_id', $param['housetype_id']);
  1154. return View::fetch();
  1155. }
  1156. public function list_dev_case()
  1157. {
  1158. $param = request()->only(['housetype_id']);
  1159. $where[] = ['root_id', '=', request()->employee->root_id];
  1160. $where[] = ['housetype_id', '=', $param['housetype_id']];
  1161. $list = BuildingDevelopCase::with(['decostyles'])->where($where)->order('addtime desc')->select();
  1162. $count = BuildingDevelopCase::where($where)->count();
  1163. return json(['code' => 0, 'data' => $list, 'count' => $count, 'msg' => '获取成功']);
  1164. }
  1165. /**
  1166. * 添加研发案例
  1167. */
  1168. public function add_dev_case()
  1169. {
  1170. //$housetype_id=input('housetype_id');
  1171. $param = request()->only(['name', 'type', 'vr_link', 'content', 'decostyles_id', 'housetype_id', 'cover']);
  1172. if (!request()->isPost()) {
  1173. $condition = [['root_id', '=', request()->employee->root_id]];
  1174. $decostyles = Decostyle::where($condition)->where([['type', '=', 0]])->select()->toArray();
  1175. View::assign('decostyles', $decostyles);
  1176. View::assign('housetype_id', $param['housetype_id']);
  1177. return View::fetch();
  1178. }
  1179. if ($param['type'] == 2 && empty($param['cover'])) return json(['code' => 1, 'msg' => '图文类型的封面图不能为空']);
  1180. $building_id = BuildingHousetype::where('id', $param['housetype_id'])->value('building_id');
  1181. $param['building_id'] = $building_id;
  1182. $param['root_id'] = request()->employee->root_id;
  1183. if (!empty($param['vr_link'])) {
  1184. $param['vr_link'] = $this->vrlink_set($param['vr_link']);
  1185. }
  1186. $result = BuildingDevelopCase::create($param);
  1187. if ($result) {
  1188. return json(['code' => 0, 'msg' => '添加成功']);
  1189. } else {
  1190. return json(['code' => 1, 'msg' => '添加失败']);
  1191. }
  1192. }
  1193. //编辑户型研发案例
  1194. public function edit_dev_case()
  1195. {
  1196. $param = request()->only(['id', 'name', 'type', 'vr_link', 'content', 'decostyles_id', 'housetype_id', 'cover', 'img_content']);
  1197. if (!request()->isPost()) {
  1198. $condition = [['root_id', '=', request()->employee->root_id]];
  1199. $decostyles = Decostyle::where($condition)->where([['type', '=', 0]])->select()->toArray();
  1200. View::assign('decostyles', $decostyles);
  1201. $data = BuildingDevelopCase::where('id', $param['id'])->find();
  1202. View::assign('data', $data);
  1203. return View::fetch();
  1204. }
  1205. //if ($param['type'] == 2 && empty($param['cover'])) return json(['code' => 1, 'msg' => '图文类型的封面图不能为空']);
  1206. if (!empty($param['vr_link'])) {
  1207. $param['vr_link'] = $this->vrlink_set($param['vr_link']);
  1208. }
  1209. if (!empty($param['img_content'])) {
  1210. $list = json_decode($param['img_content'], true);
  1211. foreach ($list as $key => $val) {
  1212. $list[$key]['img'] = str_replace('https://' . config('app.ali_oss_bindurl') . '/', '', $val['img']);
  1213. }
  1214. $param['img_content'] = json_encode($list);
  1215. }
  1216. $result = BuildingDevelopCase::where('id', $param['id'])->save($param);
  1217. if ($result) {
  1218. return json(['code' => 0, 'msg' => '修改成功']);
  1219. } else {
  1220. return json(['code' => 1, 'msg' => '修改失败']);
  1221. }
  1222. }
  1223. //户型研发案例列表
  1224. public function develop_case_list()
  1225. {
  1226. $param = request()->only(['id', 'name', 'type', 'vr_link', 'content', 'building_id', 'housetype_id']);
  1227. $where[] = ['root_id', '=', request()->employee->root_id];
  1228. $where[] = ['housetype_id', '=', $param['id']];
  1229. $list = BuildingDevelopCase::where($where)->select();
  1230. $count = BuildingDevelopCase::where($where)->count();
  1231. return json(['code' => 0, 'data' => $list, 'count' => $count, 'msg' => '获取成功']);
  1232. }
  1233. //删除户型研发案例
  1234. public function del_dev_case()
  1235. {
  1236. $id = input('id');
  1237. if (empty($id)) return json(['code' => 1, 'msg' => '参数错误']);
  1238. $ms = BuildingDevelopCase::where('id', $id)->delete();
  1239. if ($ms) {
  1240. return json(['code' => 0, 'msg' => '删除成功']);
  1241. } else {
  1242. return json(['code' => 1, 'msg' => '删除失败']);
  1243. }
  1244. }
  1245. /**
  1246. * 文件上传
  1247. */
  1248. public function fileupload()
  1249. {
  1250. $ali_oss_bindurl = config('app.ali_oss_bindurl');
  1251. $url = 'https://' . $ali_oss_bindurl . '/' . Request::param('file');
  1252. return json(['code' => 0, 'data' => ['src' => $url]]);
  1253. }
  1254. /**
  1255. * 统计
  1256. */
  1257. public function analysis(){
  1258. $root_id = request()->employee->root_id;
  1259. if (!request()->isAjax()){
  1260. // 部门
  1261. $org = OrgLogic::struc($root_id);
  1262. View::assign('org', $org);
  1263. $building = BuildingModel::where([['root_id', '=', $root_id], ['del', '=', 0]])->order('addtime desc')->field('id,community_id,name,assign_employee,employee_id,from')->select()->toArray();
  1264. $have_id = [];
  1265. foreach ($building as $k => $v){
  1266. if (!in_array($v['community_id'], $have_id)){
  1267. $have_id[] = $v['community_id'];
  1268. } else {
  1269. unset($building[$k]);
  1270. }
  1271. // 指派部门更新,防止有人员切换部门
  1272. $data = [];
  1273. if (empty($v['assign_employee'])){
  1274. $data['assign_org_id'] = '';
  1275. } else {
  1276. $assign_org_id = Employee::where('id', 'in', $v['assign_employee'])->group('org_id')->column('org_id');
  1277. $data['assign_org_id'] = implode(',', $assign_org_id);
  1278. }
  1279. if ($v['from'] == 1){
  1280. $data['org_id'] = Employee::where('id', '=', $v['employee_id'])->value('org_id');
  1281. }
  1282. BuildingModel::where('id', '=', $v['id'])->save($data);
  1283. }
  1284. $building = array_values($building);
  1285. View::assign('building', $building);
  1286. return View::fetch();
  1287. } else {
  1288. $param = request()->only(['org'=> '', 'community_id'=> '', 'vr'=> '', 'time'=> '']);
  1289. $where[] = ['root_id', '=', $root_id];
  1290. $where[] = ['del', '=', 0];
  1291. if ($param['community_id']){
  1292. $where[] = ['community_id', '=', $param['community_id']];
  1293. }
  1294. if ($param['vr']) {
  1295. if ($param['vr'] == '有'){
  1296. $where[] = ['vr_link', '<>', ''];
  1297. } elseif($param['vr'] == '无'){
  1298. $where[] = ['vr_link', '=', ''];
  1299. }
  1300. }
  1301. if ($param['org']){
  1302. $list_o = BuildingModel::where($where)->field('id,assign_org_id')->select()->toArray();
  1303. $child_org = orgSubIds($param['org']);
  1304. $ids = [];
  1305. foreach ($list_o as $k => $v){
  1306. if (!empty($v['assign_org_id'])){
  1307. $assign_org_id = array_filter(explode(',', $v['assign_org_id']));
  1308. foreach ($assign_org_id as $a_o){
  1309. if (in_array($a_o, $child_org)){
  1310. $ids[] = $v['id'];
  1311. continue;
  1312. }
  1313. }
  1314. }
  1315. }
  1316. $where[] = ['id', 'in', $ids];
  1317. }
  1318. $list = BuildingModel::with(['materialCase','housetype'])->where($where)->order('addtime desc')->select()->toArray();
  1319. foreach ($list as $k => $v){
  1320. $mater_case_view = $construction_view = 0;
  1321. $progress_list = BuildingProgress::where('building_id', '=', $v['id'])->order('addtime desc')->select();
  1322. $list[$k]['progress_count'] = $progress_list->count();
  1323. $list[$k]['last_update_time'] = '';
  1324. if (!empty($progress_list)){
  1325. foreach ($progress_list as $k_p => $p){
  1326. if (!empty($p['addtime']) && $k_p == 0){
  1327. $list[$k]['last_update_time'] = $p['addtime'];
  1328. }
  1329. }
  1330. }
  1331. if(!empty($v['materialCase'])){
  1332. $mater_case_view = MaterialCase::where([['root_id','=',$root_id],['id','in',array_column($v['materialCase'],'material_case_id')]])->sum('view_times');
  1333. }
  1334. if(!empty($v['housetype'])){
  1335. $all_constrids = [];
  1336. foreach($v['housetype'] as $p=>$m){
  1337. if(!empty($m['constructionid'])) $all_constrids = array_merge($all_constrids,explode(',',$m['constructionid']));
  1338. }
  1339. $construction_view = ConstructionModel::where([['root_id','=',$root_id],['id','in',array_unique($all_constrids)]])->sum('view_times');
  1340. }
  1341. $list[$k]['mater_case_view'] = $mater_case_view;
  1342. $list[$k]['construction_view'] = $construction_view;
  1343. $list[$k]['visit_due_time'] = FootprintsModel::where([['pipe_type','=','building'],['pipe_id','=',$v['id']]])->sum('visit_due_time');
  1344. }
  1345. if ($param['time']){
  1346. $time = explode(' - ', $param['time']);
  1347. $start_time = isset($time[0]) ? $time[0] . ' 00:00:00' : '';
  1348. $end_time = isset($time[1]) ? $time[1] . ' 23:59:59' : '';
  1349. $new_list = [];
  1350. foreach ($list as $k => $v){
  1351. if (($v['last_update_time'] > $start_time) && $v['last_update_time'] < $end_time) {
  1352. $new_list[] = $v;
  1353. }
  1354. }
  1355. $list = $new_list;
  1356. }
  1357. $housetype_all = 0; // 总户型数
  1358. $housetype_vr_all = 0; // vr户型数
  1359. $building_vr_all = 0; //小区vr
  1360. $develop_all = 0; //研发案例
  1361. $housetype_develop_all = 0; //有研发案例户型数
  1362. $max_org_count = 0;
  1363. foreach ($list as $k => $v) {
  1364. $housetype = BuildingHousetype::where('building_id', '=', $v['id'])->select();
  1365. $list[$k]['housetype_count'] = $housetype->count();
  1366. $housetype_all += $housetype->count();
  1367. $housetype_vr_count = 0;
  1368. foreach ($housetype as $h){
  1369. if ($h['vr_link']){
  1370. $housetype_vr_count ++;
  1371. }
  1372. }
  1373. $housetype_vr_all += $housetype_vr_count;
  1374. $list[$k]['housetype_vr_count'] = $housetype_vr_count;
  1375. $list[$k]['housetype_vr_percent'] = $list[$k]['housetype_count'] > 0 ? round($housetype_vr_count*100/$list[$k]['housetype_count'],2) : 0;
  1376. $develop = BuildingDevelopCase::where('building_id', '=', $v['id'])->select();
  1377. $list[$k]['develop_count'] = $develop->count();
  1378. $develop_all += $develop->count();
  1379. $housetype_develop = 0; //有研发案例的户型
  1380. $housetype_have = [];
  1381. foreach ($housetype as $h){
  1382. foreach ($develop as $d){
  1383. if ($d['housetype_id'] == $h['id'] && !in_array($h['id'], $housetype_have)){
  1384. $housetype_have[] = $h['id'];
  1385. $housetype_develop ++;
  1386. }
  1387. }
  1388. }
  1389. $housetype_develop_all += $housetype_develop;
  1390. $list[$k]['develop_percent'] = $list[$k]['housetype_count'] > 0 ? round($housetype_develop*100/$list[$k]['housetype_count'],2) : 0;
  1391. // 部门
  1392. $assign_org = array_filter(explode(',', $v['assign_org_id']));
  1393. $org_list = [];
  1394. if (!empty($assign_org)) {
  1395. foreach ($assign_org as $k_a => $v_a){
  1396. $v_a_info = Org::find($v_a);
  1397. if (!empty($v_a_info)){
  1398. $org_list_one['id'] = $v_a;
  1399. $org_list_one['name'] = $v_a_info['name'];
  1400. $org_list_one['path'] = $v_a_info['path'];
  1401. $parents = array_reverse(array_filter(explode('-', $v_a_info['path'])));
  1402. $parents_length = 0;
  1403. foreach ($parents as $k_p => $v_p){
  1404. if ($v_p != $v_a) { //不是基层部门
  1405. $org_p = Org::find($v_p);
  1406. if (!empty($org_p) && $org_p['pid'] != 0){
  1407. $parents_length ++;
  1408. }
  1409. }
  1410. }
  1411. $org_list[] = $org_list_one;
  1412. if ($parents_length > $max_org_count){
  1413. $max_org_count = $parents_length;
  1414. }
  1415. }
  1416. // 基层部门判断
  1417. /*$child = Org::where([['pid', '=', $v_a]])->findOrEmpty();
  1418. if (!$child->isEmpty()) {
  1419. $base = true; //判断此部门下是否有指派的子部门,如果没有则作为基层部门
  1420. $v_child_org = orgSubIds($param['org']);
  1421. foreach ($v_child_org as $k_c => $v_c){
  1422. if ($v_c != $v_a){
  1423. if (in_array($v_c, $assign_org)){
  1424. $base = false;
  1425. }
  1426. }
  1427. }
  1428. if ($base) {
  1429. $v_a_info = Org::find($v_a);
  1430. $org_list_one['id'] = $v_a;
  1431. $org_list_one['name'] = $v_a_info['name'];
  1432. $org_list_one['path'] = $v_a_info['path'];
  1433. $parents = array_reverse(array_filter(explode('-', $v_a_info['path'])));
  1434. $parents_length = 0;
  1435. foreach ($parents as $k_p => $v_p){
  1436. if ($v_p != $v_a) { //不是基层部门
  1437. $org_p = Org::find($v_p);
  1438. if (!empty($org_p) && $org_p['pid'] != 0){
  1439. $parents_length ++;
  1440. }
  1441. }
  1442. }
  1443. $org_list[] = $org_list_one;
  1444. if ($parents_length > $max_org_count){
  1445. $max_org_count = $parents_length;
  1446. }
  1447. }
  1448. }
  1449. if ($child->isEmpty()){
  1450. $v_a_info = Org::find($v_a);
  1451. if (!empty($v_a_info)){
  1452. $org_list_one['id'] = $v_a;
  1453. $org_list_one['name'] = $v_a_info['name'];
  1454. $org_list_one['path'] = $v_a_info['path'];
  1455. $parents = array_reverse(array_filter(explode('-', $v_a_info['path'])));
  1456. $parents_length = 0;
  1457. foreach ($parents as $k_p => $v_p){
  1458. if ($v_p != $v_a) { //不是基层部门
  1459. $org_p = Org::find($v_p);
  1460. if (!empty($org_p) && $org_p['pid'] != 0){
  1461. $parents_length ++;
  1462. }
  1463. }
  1464. }
  1465. $org_list[] = $org_list_one;
  1466. if ($parents_length > $max_org_count){
  1467. $max_org_count = $parents_length;
  1468. }
  1469. }
  1470. }*/
  1471. }
  1472. } else {
  1473. if ($v['from'] == 1){
  1474. // 如果是手机端上传,没有指派的话,默认当前部门为指派部门且为基层部门
  1475. $base_org = Org::find($v['org_id']);
  1476. $org_list_one['id'] = $v['org_id'];
  1477. $org_list_one['name'] = $base_org['name'];
  1478. $org_list_one['path'] = $base_org['path'];
  1479. $parents = array_reverse(array_filter(explode('-', $base_org['path'])));
  1480. $parents_length = 0;
  1481. foreach ($parents as $k_p => $v_p){
  1482. if ($v_p != $v['org_id']) { //不是基层部门
  1483. $org_p = Org::find($v_p);
  1484. if (!empty($org_p) && $org_p['pid'] != 0){
  1485. $parents_length ++;
  1486. }
  1487. }
  1488. }
  1489. $org_list[] = $org_list_one;
  1490. if ($parents_length > $max_org_count){
  1491. $max_org_count = $parents_length;
  1492. }
  1493. }
  1494. }
  1495. $list[$k]['assign_org'] = $org_list;
  1496. // vr数量
  1497. if (!empty($v['vr_link'])){
  1498. $building_vr_all ++;
  1499. }
  1500. }
  1501. // 父部门处理
  1502. foreach ($list as $k => $v) {
  1503. /*$assign_org = array_filter(explode(',', $v['assign_org_id']));
  1504. $assign_org_select = Org::where('id', 'in', $assign_org)->select()->toArray();
  1505. $assign_org_list = [];
  1506. foreach($assign_org as $o_v){
  1507. foreach($assign_org_select as $v_s){
  1508. if ($o_v == $v_s['id']) {
  1509. $assign_org_list[] = $v_s;
  1510. }
  1511. }
  1512. }*/
  1513. $parents_org = [];
  1514. for ($i = 0; $i < $max_org_count; $i++){
  1515. foreach ($v['assign_org'] as $k_a => $v_a){
  1516. $parents = array_filter(explode('-', $v_a['path']));
  1517. if (!empty($parents)) {
  1518. unset($parents[0]);
  1519. $parents = array_values($parents);
  1520. }
  1521. foreach($parents as $k_p => $v_p){
  1522. if ($v_p == $v_a['id']) {
  1523. unset($parents[$k_p]);
  1524. }
  1525. }
  1526. $parents = array_values($parents);
  1527. if (isset($parents[$i])){
  1528. $org_p = Org::find($parents[$i]);
  1529. if (!empty($org_p) && $org_p['pid'] != 0){
  1530. $parents_org[$i][] = $org_p['name'];
  1531. } else {
  1532. $parents_org[$i][] = '无';
  1533. }
  1534. } else {
  1535. $parents_org[$i][] = '无';
  1536. }
  1537. }
  1538. }
  1539. $list[$k]['parents_org'] = array_reverse($parents_org);
  1540. }
  1541. //楼盘数量
  1542. $building_count = count($list);
  1543. //户型vr完整度
  1544. //$housetype_vr_percent = $housetype_all > 0 ? ceil($housetype_vr_all*100/$housetype_all) : 0;
  1545. $housetype_vr_percent = $housetype_all > 0 ? round($housetype_vr_all*100/$housetype_all,2) : 0;
  1546. //研发案例完整度
  1547. $housetype_develop_percent = $housetype_all > 0 ? round($housetype_develop_all*100/$housetype_all,2) : 0;
  1548. $data['building_count'] = $building_count;
  1549. $data['vr_count'] = $building_vr_all;
  1550. $data['housetype_count'] = $housetype_all;
  1551. $data['housetype_vr_percent'] = $housetype_vr_percent;
  1552. $data['develop_all'] = $develop_all;
  1553. $data['housetype_deveolp_percent'] = $housetype_develop_percent;
  1554. $data['org_length'] = $max_org_count;
  1555. $data['list'] = $list;
  1556. return json(['code'=> 0, 'data'=> $data, 'msg'=> '请求成功']);
  1557. }
  1558. }
  1559. /**
  1560. * 已发布的vr作品
  1561. */
  1562. public function Group()
  1563. {
  1564. $id = input('id',0);
  1565. if (!request()->isAjax()) {
  1566. View::assign('id', $id);
  1567. return View::fetch();
  1568. }
  1569. $page = input('page',1);
  1570. $limit = input('limit',10);
  1571. $keyword = input('keyword','');
  1572. $where = [['root_id','=',request()->employee->root_id],['status','=',2]];
  1573. if($keyword) $where[] = ['title','like','%'.$keyword.'%'];
  1574. $res = VrGroup::where($where)->order('id desc')->field("id,title name,sid")->page((int)$page,(int)$limit)->select()->toArray();
  1575. $host = config('app.vr_show_domain');
  1576. foreach ($res as $key => $val) {
  1577. $res[$key]['name'] = $val['name'] ?: '未命名作品';
  1578. $res[$key]['show_url'] = $host.$val['sid'];
  1579. //选中默认值
  1580. $res[$key]['LAY_CHECKED'] = ($id == $val['id'] || $id==$val['sid']) ? true : false;
  1581. }
  1582. $count = VrGroup::where($where)->order('id desc')->field("id,title name")->count();
  1583. return json(['code' => 0, 'msg' => '保存成功', 'data' => $res,'count'=>$count]);
  1584. }
  1585. }