1
0

Construction.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523
  1. <?php
  2. namespace app\sys\controller;
  3. use app\model\Community;
  4. use app\model\ConstructionRecord;
  5. use app\model\ConstructionStep;
  6. use app\model\Decostyle;
  7. use app\model\Designer;
  8. use app\model\Employee as EmployeeModel;
  9. use app\model\Housetype;
  10. use app\model\Org;
  11. use think\facade\Request;
  12. use think\facade\View;
  13. use app\event\Msg;
  14. use app\model\VrGroup;
  15. use app\model\Construction as ConstructionModel;
  16. class Construction
  17. {
  18. /**
  19. * 列表
  20. */
  21. public function index()
  22. {
  23. if (!request()->isAjax()) {
  24. $styleList = Decostyle::where(['root_id' => request()->employee->root_id, 'type' => 0])->select();
  25. View::assign('decostyle', $styleList);
  26. $eid = ConstructionModel::where([['root_id','=',request()->employee->root_id],['employee_id','>',0]])->group('employee_id')->column('employee_id,type');
  27. $type0 = $type1 = [];
  28. foreach ($eid as $ks => $vs) {
  29. $vs['type']==0 ? $type0[]=$vs['employee_id'] : $type1[]=$vs['employee_id'];
  30. }
  31. // 运营人员列表
  32. $employee = EmployeeModel::where([['id','in',$type0],['root_id', '=', request()->employee->root_id]])->field('id,opt_name,name')->select()->toArray();
  33. foreach ($employee as $key => $val) {
  34. $employee[$key]['name'] = $val['name'] ?: ($val['opt_name'] ?: '');
  35. }
  36. View::assign('employee', $employee);
  37. $employee1 = EmployeeModel::where([['id','in',$type1],['root_id', '=', request()->employee->root_id]])->field('id,opt_name,name')->select()->toArray();
  38. foreach ($employee1 as $key1 => $val1) {
  39. $employee1[$key1]['name'] = $val1['name'] ?: ($val1['opt_name'] ?: '');
  40. }
  41. View::assign('employee_mb', $employee1);
  42. $communityList = Community::where(['root_id' => request()->employee->root_id, 'type' => 0])->order('pinyin asc')->select();
  43. if (!empty($communityList)){
  44. $communityList= hanziheadstr($communityList);
  45. }
  46. View::assign('communityList', $communityList);
  47. //户型获取
  48. $housetype = Housetype::where('root_id','=', request()->employee->root_id)->select()->toArray();
  49. View::assign('housetype', $housetype);
  50. return View::fetch();
  51. }
  52. $page = input('page', 1, 'intval');
  53. $limit = input('limit', 10, 'intval');
  54. $employee_id = input('employee_id');
  55. $style_id = input('decostyle');
  56. $community_id = input('community');
  57. $housetype_id = input('housetype');
  58. $addtime = input('addtime');
  59. $root_id = request()->employee['root_id'];
  60. $where[] = ['root_id', '=', $root_id];
  61. //2023-02-04 增加手机上传
  62. $where[] = ['type','=',input('type',0)];
  63. empty($employee_id)?:$where[] = ['employee_id', '=', $employee_id];
  64. empty($style_id)?:$where[] = ['style_id', '=', $style_id];
  65. empty($community_id)?:$where[] = ['community_id', '=', $community_id];
  66. empty($housetype_id)?:$where[] = ['housetype_id', '=', $housetype_id];
  67. if (!empty($addtime)) {
  68. list($start_date, $end_date) = explode(' - ', $addtime);
  69. $where[] = ['addtime', '>=', $start_date];
  70. $where[] = ['addtime', '<', date('Y-m-d H:i:s', strtotime($end_date) + 86400)];
  71. }
  72. $step_list = ConstructionStep::where('root_id', '=', $root_id)->order('order asc')->select()->toArray();
  73. $list = ConstructionModel::with(['style', 'designer', 'housetype', 'community', 'employee'])->where($where)->page($page, $limit)->order('recommend desc,id desc')->select()->append(['housetype.name'])->each(function ($item) use ($step_list){
  74. foreach ($step_list as $k => $v) {
  75. // 判断该阶段是否上传
  76. $step_list[$k]['record_id'] = 0;
  77. $find = ConstructionRecord::where([['construction_id', '=', $item['id']], ['step_id', '=', $v['id']]])->find();
  78. if (!empty($find)) {
  79. $step_list[$k]['record_id'] = $find['id'];
  80. }
  81. }
  82. $item->step_list = $step_list;
  83. })->toArray();
  84. foreach ($list as $k => $v) {
  85. if(!$v['employee']){
  86. $list[$k]['opt_name'] = '';
  87. }else{
  88. $list[$k]['opt_name'] = $v['employee']['name'] ?: ($v['employee']['opt_name'] ?: '');
  89. }
  90. if(empty($v['housetype'])) $list[$k]['housetype'] = null;
  91. }
  92. $count = ConstructionModel::where($where)->count();
  93. return json(['code'=> 0, 'data'=> $list, 'count'=> $count]);
  94. }
  95. /**
  96. * 添加
  97. */
  98. public function add(){
  99. $root_id = request()->employee['root_id'];
  100. if (!request()->isPost()) {
  101. $condition = [['root_id', '=', request()->employee->root_id]];
  102. //小区名称获取
  103. $communities = Community::where($condition)->where([['type', '=', 0]])->order('pinyin asc')->select()->toArray();
  104. if (!empty($communities)){
  105. $communities= hanziheadstr($communities);
  106. }
  107. View::assign('communities', $communities);
  108. //设计师获取
  109. /*$designers = Designer::where($condition)->select()->toArray();
  110. View::assign('designer', $designers);*/
  111. $w[] = ['path', 'like', $root_id . '-%'];
  112. $w[] = ['org_type','=',2];
  113. $orgs = Org::where($w)->column('id');
  114. $w3[] = ['org_id','in',$orgs];
  115. $w3[] = ['root_id','=', $root_id];
  116. $w3[] = ['state','=','在职'];
  117. $designers = EmployeeModel::with(['designer'=>function($query) use ($root_id){
  118. $query->where('root_id',$root_id)->visible(['headimgurl','employee_id','desc','good_at','position','work_years','addtime','good_house','design_concept','vcr'])->bind(['desc','good_at','position','work_years','addtime','good_house','design_concept','vcr','name','headimgurl']);
  119. }])->where($w3)->field('name title,id,show,initials s')->order('s asc')->select()->toArray();
  120. foreach ($designers as $k => $v) {
  121. $designers[$k]['name'] = $v['name'] ?: $v['title'];
  122. unset($designers[$k]['designer']);
  123. }
  124. if (!empty($designers)) {
  125. // $designers = hanziInitsort($designers,'name');
  126. $sort = array_column($designers,'s');
  127. sort($sort);
  128. array_multisort($sort, SORT_ASC, $designers);
  129. $sort = array_unique($sort);
  130. $designers = ['sort' => $sort, 'arr' => $designers];
  131. }
  132. View::assign('designer', $designers);
  133. //风格获取
  134. $decostyles = Decostyle::where($condition)->where([['type', '=', 0]])->select()->toArray();
  135. View::assign('style', $decostyles);
  136. //户型获取
  137. $housetype = Housetype::where($condition)->select()->toArray();
  138. View::assign('housetype', $housetype);
  139. return View::fetch();
  140. } else {
  141. $param = request()->only(['name', 'area', 'cover'=> '', 'start_time', 'style_id', 'designer_id', 'community_id', 'housetype_id', 'recommend', 'cover_share_img', 'housetype_type'=>'']);
  142. $param['recommend'] = (isset($param['recommend']) && $param['recommend'] == 'on') ? 1 : 0;
  143. $param['root_id'] = $root_id;
  144. $param['del'] = 0;
  145. $param['employee_id'] = request()->employee->id;
  146. $param['step_id'] = 0;
  147. $result = ConstructionModel::create($param);
  148. if ($result) {
  149. dataStatistics($root_id,'plant_count',1,'inc');//manage应用首页统计数据
  150. return json(['code'=> 0, 'msg'=> '添加成功']);
  151. } else {
  152. return json(['code'=> 1, 'msg'=> '添加失败']);
  153. }
  154. }
  155. }
  156. /**
  157. * 编辑
  158. */
  159. public function edit(){
  160. $id = input('id', '', 'intval');
  161. $root_id = request()->employee['root_id'];
  162. if (!request()->isPost()) {
  163. $condition = [['root_id', '=', request()->employee->root_id]];
  164. //小区名称获取
  165. $communities = Community::where($condition)->where([['type', '=', 0]])->order('pinyin asc')->select()->toArray();
  166. if (!empty($communities)) {
  167. $communities= hanziheadstr($communities);
  168. }
  169. View::assign('communities', $communities);
  170. //设计师获取
  171. /*$designers = Designer::where($condition)->select()->toArray();
  172. View::assign('designer', $designers);*/
  173. $w[] = ['path', 'like', $root_id . '-%'];
  174. $w[] = ['org_type','=',2];
  175. $orgs = Org::where($w)->column('id');
  176. $w3[] = ['org_id','in',$orgs];
  177. $w3[] = ['root_id','=', $root_id];
  178. $w3[] = ['state','=','在职'];
  179. $designers = EmployeeModel::with(['designer'=>function($query) use ($root_id){
  180. $query->where('root_id',$root_id)->visible(['headimgurl','employee_id','desc','good_at','position','work_years','addtime','good_house','design_concept','vcr'])->bind(['desc','good_at','position','work_years','addtime','good_house','design_concept','vcr','name','headimgurl']);
  181. }])->where($w3)->field('name title,id,show,initials s')->order('s asc')->select()->toArray();
  182. foreach ($designers as $k => $v) {
  183. $designers[$k]['name'] = $v['name'] ?: $v['title'];
  184. unset($designers[$k]['designer']);
  185. }
  186. if (!empty($designers)) {
  187. // $designers = hanziInitsort($designers,'name');
  188. $sort = array_column($designers,'s');
  189. sort($sort);
  190. array_multisort($sort, SORT_ASC, $designers);
  191. $sort = array_unique($sort);
  192. $designers = ['sort' => $sort, 'arr' => $designers];
  193. }
  194. View::assign('designer', $designers);
  195. //风格获取
  196. $decostyles = Decostyle::where($condition)->where([['type', '=', 0]])->select()->toArray();
  197. View::assign('style', $decostyles);
  198. //户型获取
  199. $housetype = Housetype::where($condition)->select()->toArray();
  200. View::assign('housetype', $housetype);
  201. $data = ConstructionModel::with(['style', 'designer', 'housetype', 'community'])->find($id);
  202. View::assign('data', $data);
  203. View::assign('id', $id);
  204. return View::fetch();
  205. } else {
  206. $param = request()->only(['id', 'name', 'area', 'cover', 'start_time', 'style_id', 'designer_id', 'community_id', 'housetype_id', 'recommend', 'cover_share_img', 'housetype_type'=>'housetype']);
  207. $param['recommend'] = (isset($param['recommend']) && $param['recommend'] == 'on') ? 1 : 0;
  208. $construction = ConstructionModel::where(['root_id'=>$root_id, 'id'=>$param['id']])->find();
  209. $construction->save($param);
  210. return json(['code'=> 0, 'msg'=> '保存成功']);
  211. }
  212. }
  213. /**
  214. * 删除
  215. */
  216. public function delete(){
  217. $id = input('id', '', 'intval');
  218. $root_id = request()->employee['root_id'];
  219. $where = [
  220. ['id','=',$id],
  221. ['root_id','=',$root_id]
  222. ];
  223. $find = ConstructionModel::where($where)->findOrEmpty();
  224. if($find->isEmpty()) return json(['code'=> 1, 'msg'=> '操作异常,请刷新后重试']);
  225. $find->delete();
  226. ConstructionRecord::where([['construction_id','=',$id]])->delete();
  227. dataStatistics($root_id,'plant_count',1,'dec');//manage应用首页统计数据
  228. return json(['code'=> 0, 'msg'=> '删除成功']);
  229. }
  230. /**
  231. * 审核
  232. */
  233. public function approve(){
  234. $id = input('id', '', 'intval');
  235. $root_id = request()->employee['root_id'];
  236. $status = input('status','');
  237. $remark = input('remark','');
  238. if(!in_array($status,[1,2])) return json(['code'=> 1, 'msg'=> '审核失败']);
  239. $find = ConstructionModel::where([['id', '=', $id],['root_id','=',$root_id]])->findOrEmpty();
  240. if($find->isEmpty()) return json(['code'=> 1, 'msg'=> '审核失败']);
  241. $find->status = $status;
  242. $find->save();
  243. //审核后发送通知消息核公众号消息
  244. $remark = $remark ? ',原因是:'.$remark : '';
  245. $msg = $status==1 ? '您提交的在施工地“'.$find->name.'”'.'已审核通过,请及时查看。' : '您提交的在施工地“'.$find->name.'”'.'审核不通过'.$remark.'请及时查看。';
  246. event(new Msg($find->employee_id,$msg, 'constructionApprove'));
  247. if($status==1) dataStatistics($root_id,'plant_count',1,'inc');//manage应用首页统计数据
  248. return json(['code'=> 0, 'data'=> '审核完成','msg'=> '审核完成']);
  249. }
  250. /**
  251. * 调整案例状态
  252. */
  253. public function change_status(){
  254. $id = input('id', '', 'intval');
  255. $root_id = request()->employee['root_id'];
  256. $find = ConstructionModel::find($id);
  257. if (empty($find)) {
  258. return json(['code'=> 1, 'msg'=> '操作失败']);
  259. }
  260. if ($find['root_id'] != $root_id) {
  261. return json(['code'=> 1, 'msg'=> '操作异常,请刷新后重试']);
  262. }
  263. if (intval($find['del']) == 0) {
  264. $find->del = 1;
  265. } elseif (intval($find['del']) == 1) {
  266. $find->del = 0;
  267. }
  268. $result = $find->save();
  269. if ($result !== false) {
  270. return json(['code'=> 0, 'msg'=> '操作成功']);
  271. } else {
  272. return json(['code'=> 1, 'msg'=> '操作失败']);
  273. }
  274. }
  275. /**
  276. * 设置施工阶段
  277. */
  278. public function step_setting(){
  279. $root_id = request()->employee['root_id'];
  280. if (!request()->isPost()) {
  281. return View::fetch();
  282. }
  283. $form = input('form');
  284. if (!empty($form)) {
  285. $form_setting = json_decode($form, true);
  286. $setting = ConstructionStep::where('root_id', '=', $root_id)->order('order asc')->select()->toArray();
  287. $ids = array_column($setting, 'id');
  288. if (!empty($form_setting)) {
  289. $form_ids = array_column($form_setting, 'id');
  290. $diff = array_diff($ids, $form_ids);
  291. if (!empty($diff)) {
  292. $record = ConstructionRecord::where([['step_id', 'in', $diff], ['root_id', '=', $root_id]])->select()->toArray();
  293. if (!empty($record)) {
  294. return json(['code'=> 1, 'msg'=> '被删除的节点已有节点数据,无法删除']);
  295. } else {
  296. ConstructionStep::where([['id', 'in', $diff]])->delete();
  297. }
  298. }
  299. }
  300. if (!empty($form_setting)) {
  301. foreach ($form_setting as $k => $v) {
  302. if ($v['id']) {
  303. ConstructionStep::where('id', '=', $v['id'])->save(['name'=> $v['name'], 'order'=> $v['order']]);
  304. } else {
  305. ConstructionStep::create(['name'=> $v['name'], 'order'=> $v['order'], 'root_id'=> $root_id]);
  306. }
  307. }
  308. }
  309. return json(['code'=> 0, 'msg'=> '操作成功']);
  310. }
  311. }
  312. public function step_list(){
  313. $root_id = request()->employee['root_id'];
  314. $step_list = ConstructionStep::where('root_id', '=', $root_id)->order('order asc')->select();
  315. return json(['code'=> 0, 'msg'=> '操作成功','step_list' => $step_list]);
  316. }
  317. /**
  318. * 上传施工进度
  319. */
  320. public function update_step(){
  321. $id = input('id', '', 'intval');
  322. $steps_id = input('steps_id', 0, 'intval');
  323. $construction_id = input('construction_id', '', 'intval');
  324. if (!request()->isPost()) {
  325. $info['id'] = 0;
  326. $info['construction_id'] = $construction_id;
  327. $info['step_id'] = $steps_id;
  328. $info['img'] = [];
  329. $info['video'] = '';
  330. $info['video_cover'] = '';
  331. $info['vr'] = [];
  332. $info['content'] = '';
  333. $info['type'] = '';
  334. $info['group_name'] = '';
  335. $info['vr_group_ids'] = '';
  336. if ($id) {
  337. $info = ConstructionRecord::find($id);
  338. $info->group_name = $info->vr_group_ids ? (VrGroup::where('id',$info->vr_group_ids)->value('title') ?: '未命名作品') : '未命名作品';
  339. $construction_id = $info['construction_id'];
  340. } elseif($steps_id && $construction_id) {
  341. $f_info = ConstructionRecord::where([['step_id', '=', $steps_id], ['construction_id', '=', $construction_id]])->findOrEmpty();
  342. if (!$f_info->isEmpty()){
  343. $info = $f_info;
  344. $id = $f_info['id'];
  345. }
  346. }
  347. if (!empty($info['vr'])){
  348. $info['vr'] = explode(',', $info['vr']);
  349. }
  350. $root_id = request()->employee['root_id'];
  351. $step = ConstructionStep::where('root_id', '=', $root_id)->order('order asc')->select();
  352. View::assign('id', $id);
  353. View::assign('construction_id', $construction_id);
  354. View::assign('step', $step);
  355. View::assign('data', $info);
  356. View::assign('steps_id', $steps_id);
  357. $url = config('app.ali_oss_bindurl');
  358. View::assign('url','https://'.$url.'/');
  359. return View::fetch();
  360. }
  361. if ($id) {
  362. // 编辑
  363. $find = ConstructionRecord::find($id);
  364. $image = input('img', [], 'trim');
  365. $image_exist = input('image_exist', [], 'trim');
  366. $step_id = input('step_id', '', 'intval');
  367. $data_vr = input('vr', '', 'trim');
  368. $video = input('video', '', 'trim');
  369. $video_cover = input('video_cover', '', 'trim');
  370. $type = input('type', '', 'trim');
  371. if (!empty($data_vr) && $type == 'vr') {
  372. $vr = explode(',', $data_vr);
  373. foreach ($vr as $k => $v) {
  374. if (!empty($v)){
  375. $vr[$k] = $this->vrlink_set($v);
  376. }
  377. }
  378. $find->vr = implode(',', $vr);
  379. } else {
  380. $find->vr = '';
  381. }
  382. if ($type == 'img'){
  383. $img = implode(',', array_merge($image, $image_exist));
  384. $find->img = $img;
  385. } else {
  386. $find->img = '';
  387. }
  388. if ($type == 'video'){
  389. $find->video = $video;
  390. $find->video_cover = $video_cover;
  391. } else {
  392. $find->video = '';
  393. $find->video_cover = '';
  394. }
  395. $find->type = $type;
  396. $find->step_id = $step_id;
  397. $find->content = input('content', '', 'trim');
  398. $find->update_time = date('Y-m-d H:i:s', time());
  399. $find->vr_group_ids = input('vr_group_ids','');
  400. if ($step_id != $find['step_id']) {
  401. $type_find = ConstructionRecord::where([['construction_id', '=', $find['construction_id']], ['step_id', '=', $step_id]])->find();
  402. if (!empty($type_find)){
  403. return json(['code'=> 1, 'msg'=> '该阶段已上传']);
  404. }
  405. }
  406. $result = $find->save();
  407. } else {
  408. //添加
  409. $data = request()->only(['img', 'step_id', 'content', 'vr', 'video', 'video_cover', 'type','vr_group_ids'=>'']);
  410. $data['construction_id'] = $construction_id;
  411. if (!empty($data['img']) && $data['type'] == 'img') {
  412. $data['img'] = implode(',', $data['img']);
  413. }
  414. if (!empty($data['vr']) && $data['type'] == 'vr') {
  415. $vr = explode(',', $data['vr']);
  416. foreach ($vr as $k => $v) {
  417. if (!empty($v)){
  418. $vr[$k] = $this->vrlink_set($v);
  419. }
  420. }
  421. $data['vr'] = implode(',', $vr);
  422. } else {
  423. $data['vr'] = '';
  424. }
  425. if ($data['type'] != 'video') {
  426. $data['video'] = '';
  427. $data['video_cover'] = '';
  428. }
  429. $data['employee_id'] = request()->employee['id'];
  430. $data['root_id'] = request()->employee['root_id'];
  431. $data['update_time'] = date('Y-m-d H:i:s', time());
  432. $type_find = ConstructionRecord::where([['construction_id', '=', $construction_id], ['step_id', '=', $data['step_id']]])->find();
  433. if (!empty($type_find)){
  434. return json(['code'=> 1, 'msg'=> '该阶段已上传']);
  435. }
  436. $result = ConstructionRecord::create($data);
  437. }
  438. if ($result) {
  439. ConstructionModel::where('id', '=', $construction_id)->save(['update_time'=> date('Y-m-d H:i:s', time())]);
  440. return json(['code'=> 0, 'msg'=> '保存成功']);
  441. } else {
  442. return json(['code'=> 1, 'msg'=> '保存失败']);
  443. }
  444. }
  445. //vr链接设置修改
  446. public function vrlink_set($vr_link)
  447. {
  448. // 旧域名 替换成 新域名
  449. $links = [
  450. 'xiaohongwu' => 'hnweizhihui.xiaohongwu.nczyzs.com',
  451. 'kujiale' => 'pano337.p.kujiale.com',
  452. 'justeasy' => 'vr-17.justeasy.nczyzs.com',
  453. '3d66' => 'vr.3d66.nczyzs.com',
  454. ];
  455. $url = parse_url($vr_link);
  456. if ($url === false || !isset($url['host'])) {
  457. echo json_encode(['code' => 1, 'msg' => '链接格式错误']);
  458. exit;
  459. }
  460. if (strpos($url['host'], 'xiaohongwu') !== false) {
  461. return str_replace($url['host'], $links['xiaohongwu'], $vr_link);
  462. }
  463. if (strpos($url['host'], 'kujiale') !== false) {
  464. return str_replace($url['host'], $links['kujiale'], $vr_link);
  465. }
  466. if (strpos($url['host'], 'justeasy') !== false) {
  467. return str_replace($url['host'], $links['justeasy'], $vr_link);
  468. }
  469. if (strpos($url['host'], '3d66') !== false) {
  470. return str_replace($url['host'], $links['3d66'], $vr_link);
  471. }
  472. echo json_encode(['code' => 1, 'msg' => '无效的VR链接']);
  473. exit;
  474. }
  475. /**
  476. * 文件上传
  477. */
  478. public function fileupload()
  479. {
  480. $ali_oss_bindurl = config('app.ali_oss_bindurl');
  481. $url = 'https://' . $ali_oss_bindurl . '/' . Request::param('file');
  482. return json(['code' => 0, 'data' => ['src' => $url]]);
  483. }
  484. }