Construction.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <?php
  2. namespace app\client\controller;
  3. use app\model\Community;
  4. use app\model\Construction as ConstructionModel;
  5. use app\model\ConstructionRecord;
  6. use app\model\ConstructionStep;
  7. use app\event\FootPrints;
  8. use app\model\Housetype;
  9. use xiaohongwu\Vr;
  10. use app\model\VrGroup;
  11. class Construction extends Base
  12. {
  13. public function index()
  14. {
  15. $page = input('page', 1, 'intval');
  16. $limit = input('limit', 10, 'intval');
  17. $root_id = $this->request->token['root_org'];
  18. $where[] = ['root_id', '=', $root_id];
  19. //2023-02-06增加审核字段
  20. $where[] = ['status','=',1];
  21. $where[] = ['del','=',0];
  22. $community_id = input('community_id', '', 'intval');
  23. if ($community_id) {
  24. $where[] = ['community_id', '=', $community_id];
  25. }
  26. $step_list = ConstructionStep::where('root_id', '=', $root_id)->order('order asc')->select()->toArray();
  27. $order_input = input('order', 'new', 'trim');
  28. $order = 'id desc';
  29. $model = ConstructionModel::with(['style', 'designer', 'housetype', 'community'])->withCount(['share_log'=> function ($query) {
  30. $query->where([['type', '=', 'construction']]);
  31. }]);
  32. if ($order_input == 'new'){
  33. $order = 'recommend desc, update_time desc';
  34. } else if ($order_input = 'hot') {
  35. $order = 'recommend desc, share_log_count desc';
  36. }
  37. $list = $model->where($where)->page($page, $limit)->order($order)->select()->each(function ($item) use ($step_list) {
  38. $record_list = ConstructionRecord::where([['construction_id', '=', $item['id']]])->order('update_time desc')->select();
  39. $step_now = 0; //进行到哪一步了
  40. foreach ($step_list as $k => $v) {
  41. foreach ($record_list as $kk => $vv) {
  42. if ($v['id'] == $vv['step_id'] && $v['order'] > $step_now) {
  43. $step_now = $v['order'];
  44. }
  45. }
  46. }
  47. foreach ($step_list as $k => $v) {
  48. $step_list[$k]['upload'] = 0; // 判断是否上传
  49. $step_list[$k]['need_upload'] = 0; // 判断节点是否变色(已过此节点,但是没上传)
  50. $have = false; //是否有上传 true有
  51. $need_have = false; //没上传,但是后面的节点上传了 true是
  52. foreach ($record_list as $kk => $vv) {
  53. if ($v['id'] == $vv['step_id']) {
  54. $have = true;
  55. }
  56. }
  57. if ($have == false && $v['order'] < $step_now) {
  58. $need_have = true;
  59. }
  60. if ($have) {
  61. $step_list[$k]['upload'] = 1;
  62. } elseif ($need_have) {
  63. $step_list[$k]['need_upload'] = 1;
  64. }
  65. }
  66. $item->step_list = $step_list;
  67. });
  68. return json(['code' => self::success, 'data' => $list->toArray(), 'count' => $list->count()]);
  69. }
  70. public function view()
  71. {
  72. $id = input('id', '', 'intval');
  73. if (empty($id)) {
  74. return json(['code' => self::error_msg, 'msg' => '获取失败']);
  75. }
  76. $share = input('share', '', 'trim');
  77. $info = ConstructionModel::with(['style', 'designer', 'housetype', 'community'])->find($id);
  78. $root_id = $this->request->token['root_org'];
  79. $step_list = ConstructionStep::where('root_id', '=', $root_id)->order('order asc')->select()->toArray();
  80. $record_list = ConstructionRecord::where([['construction_id', '=', $id]])->order('update_time desc')->select()->toArray();
  81. //vr作品处理
  82. $sids = VrGroup::where([['id','in',array_column($record_list,'vr_group_ids')]])->column('sid','id');
  83. $show_url = config('app.vr_show_domain');
  84. $step_now = 0; //进行到哪一步了
  85. foreach ($step_list as $k => $v) {
  86. foreach ($record_list as $kk => $vv) {
  87. if ($v['id'] == $vv['step_id'] && $v['order'] > $step_now) {
  88. $step_now = $v['order'];
  89. }
  90. }
  91. }
  92. $vrObj = new Vr();
  93. foreach ($step_list as $k => $v) {
  94. $step_list[$k]['upload'] = 0; // 判断是否上传
  95. $step_list[$k]['need_upload'] = 0; // 判断节点是否变色(已过此节点,但是没上传)
  96. $have = false; //是否有上传 true有
  97. $need_have = false; //没上传,但是后面的节点上传了 true是
  98. $step_list[$k]['data'] = [];
  99. foreach ($record_list as $kk => $vv) {
  100. if ($v['id'] == $vv['step_id']) {
  101. $have = true;
  102. if (!empty($vv['vr']) && $vv['type'] == 'vr') {
  103. $vrUrlList = explode(',', $vv['vr']);
  104. $vrData = [];
  105. foreach ($vrUrlList as $url) {
  106. $vrData[] = [
  107. 'vrUrl' => $url,
  108. 'vrfirstImg' => $vrObj->getFirstImg($url)
  109. ];
  110. }
  111. $vv['vr'] = $vrData;
  112. }elseif (!empty($vv['vr_group_ids']) && $vv['type'] == 'groupVr') {
  113. $vrgroup = VrGroup::where('id',$vv['vr_group_ids'])->field('id,pic_path,sid')->findOrEmpty();
  114. $vrData = [];
  115. if (!$vrgroup->isEmpty()) {
  116. $vrData[] = [
  117. 'vrUrl' => $show_url.$vrgroup->sid,
  118. 'vrfirstImg' => $vrgroup->pic_path
  119. ];
  120. }
  121. $vv['vr'] = $vrData;
  122. }
  123. $step_list[$k]['data'] = $vv;
  124. }
  125. }
  126. if ($have == false && $v['order'] < $step_now) {
  127. $need_have = true;
  128. }
  129. if ($have) {
  130. $step_list[$k]['upload'] = 1;
  131. } elseif ($need_have) {
  132. $step_list[$k]['need_upload'] = 1;
  133. }
  134. }
  135. $info['step_list'] = $step_list;
  136. // 添加足迹
  137. if (empty($share)){
  138. $token = request()->token;
  139. if (!empty($token['uid']) && !$token['isEmployee']) {
  140. event(new FootPrints($token['uid'], $token['share_employee'] ?? 0, $token['share_org'] ?? 0, $info, 'construction'));
  141. }
  142. if (!$token['isEmployee']) {
  143. ConstructionModel::where('id', '=', $id)->inc('view_times')->update();
  144. }
  145. }
  146. if(!empty($info->housetype))
  147. $info['housetype']['name'] = $info->housetype->name;
  148. else
  149. $info['housetype'] = '';
  150. return json(['code'=> self::success, 'msg'=> '请求成功', 'data'=> $info]);
  151. }
  152. /**
  153. * 装修案例小区列表
  154. */
  155. public function communitylist()
  156. {
  157. $communityArr = Community::where(['root_id' => request()->token['root_org']])->where([['type', '=', 0]])->field('id,name,pinyin,case_num')->order('pinyin asc')->select()->each(function ($item){
  158. $item['construction_count'] = ConstructionModel::where('community_id', '=', $item['id'])->count();
  159. })->toArray();
  160. return json(['code' => 0, 'data' => $communityArr, 'msg' => '获取成功']);
  161. }
  162. }