123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179 |
- <?php
- namespace app\client\controller;
- use app\model\Community;
- use app\model\Construction as ConstructionModel;
- use app\model\ConstructionRecord;
- use app\model\ConstructionStep;
- use app\event\FootPrints;
- use app\model\Housetype;
- use xiaohongwu\Vr;
- use app\model\VrGroup;
- class Construction extends Base
- {
- public function index()
- {
- $page = input('page', 1, 'intval');
- $limit = input('limit', 10, 'intval');
- $root_id = $this->request->token['root_org'];
- $where[] = ['root_id', '=', $root_id];
- //2023-02-06增加审核字段
- $where[] = ['status','=',1];
- $where[] = ['del','=',0];
- $community_id = input('community_id', '', 'intval');
- if ($community_id) {
- $where[] = ['community_id', '=', $community_id];
- }
- $step_list = ConstructionStep::where('root_id', '=', $root_id)->order('order asc')->select()->toArray();
- $order_input = input('order', 'new', 'trim');
- $order = 'id desc';
- $model = ConstructionModel::with(['style', 'designer', 'housetype', 'community'])->withCount(['share_log'=> function ($query) {
- $query->where([['type', '=', 'construction']]);
- }]);
- if ($order_input == 'new'){
- $order = 'recommend desc, update_time desc';
- } else if ($order_input = 'hot') {
- $order = 'recommend desc, share_log_count desc';
- }
- $list = $model->where($where)->page($page, $limit)->order($order)->select()->each(function ($item) use ($step_list) {
- $record_list = ConstructionRecord::where([['construction_id', '=', $item['id']]])->order('update_time desc')->select();
- $step_now = 0; //进行到哪一步了
- foreach ($step_list as $k => $v) {
- foreach ($record_list as $kk => $vv) {
- if ($v['id'] == $vv['step_id'] && $v['order'] > $step_now) {
- $step_now = $v['order'];
- }
- }
- }
- foreach ($step_list as $k => $v) {
- $step_list[$k]['upload'] = 0; // 判断是否上传
- $step_list[$k]['need_upload'] = 0; // 判断节点是否变色(已过此节点,但是没上传)
- $have = false; //是否有上传 true有
- $need_have = false; //没上传,但是后面的节点上传了 true是
- foreach ($record_list as $kk => $vv) {
- if ($v['id'] == $vv['step_id']) {
- $have = true;
- }
- }
- if ($have == false && $v['order'] < $step_now) {
- $need_have = true;
- }
- if ($have) {
- $step_list[$k]['upload'] = 1;
- } elseif ($need_have) {
- $step_list[$k]['need_upload'] = 1;
- }
- }
- $item->step_list = $step_list;
- });
- return json(['code' => self::success, 'data' => $list->toArray(), 'count' => $list->count()]);
- }
- public function view()
- {
- $id = input('id', '', 'intval');
- if (empty($id)) {
- return json(['code' => self::error_msg, 'msg' => '获取失败']);
- }
- $share = input('share', '', 'trim');
- $info = ConstructionModel::with(['style', 'designer', 'housetype', 'community'])->find($id);
- $root_id = $this->request->token['root_org'];
- $step_list = ConstructionStep::where('root_id', '=', $root_id)->order('order asc')->select()->toArray();
- $record_list = ConstructionRecord::where([['construction_id', '=', $id]])->order('update_time desc')->select()->toArray();
- //vr作品处理
- $sids = VrGroup::where([['id','in',array_column($record_list,'vr_group_ids')]])->column('sid','id');
- $show_url = config('app.vr_show_domain');
- $step_now = 0; //进行到哪一步了
- foreach ($step_list as $k => $v) {
- foreach ($record_list as $kk => $vv) {
- if ($v['id'] == $vv['step_id'] && $v['order'] > $step_now) {
- $step_now = $v['order'];
- }
- }
- }
- $vrObj = new Vr();
- foreach ($step_list as $k => $v) {
- $step_list[$k]['upload'] = 0; // 判断是否上传
- $step_list[$k]['need_upload'] = 0; // 判断节点是否变色(已过此节点,但是没上传)
- $have = false; //是否有上传 true有
- $need_have = false; //没上传,但是后面的节点上传了 true是
- $step_list[$k]['data'] = [];
- foreach ($record_list as $kk => $vv) {
- if ($v['id'] == $vv['step_id']) {
- $have = true;
- if (!empty($vv['vr']) && $vv['type'] == 'vr') {
- $vrUrlList = explode(',', $vv['vr']);
- $vrData = [];
- foreach ($vrUrlList as $url) {
- $vrData[] = [
- 'vrUrl' => $url,
- 'vrfirstImg' => $vrObj->getFirstImg($url)
- ];
- }
- $vv['vr'] = $vrData;
- }elseif (!empty($vv['vr_group_ids']) && $vv['type'] == 'groupVr') {
- $vrgroup = VrGroup::where('id',$vv['vr_group_ids'])->field('id,pic_path,sid')->findOrEmpty();
- $vrData = [];
- if (!$vrgroup->isEmpty()) {
- $vrData[] = [
- 'vrUrl' => $show_url.$vrgroup->sid,
- 'vrfirstImg' => $vrgroup->pic_path
- ];
- }
- $vv['vr'] = $vrData;
- }
- $step_list[$k]['data'] = $vv;
- }
- }
- if ($have == false && $v['order'] < $step_now) {
- $need_have = true;
- }
- if ($have) {
- $step_list[$k]['upload'] = 1;
- } elseif ($need_have) {
- $step_list[$k]['need_upload'] = 1;
- }
- }
- $info['step_list'] = $step_list;
- // 添加足迹
- if (empty($share)){
- $token = request()->token;
- if (!empty($token['uid']) && !$token['isEmployee']) {
- event(new FootPrints($token['uid'], $token['share_employee'] ?? 0, $token['share_org'] ?? 0, $info, 'construction'));
- }
- if (!$token['isEmployee']) {
- ConstructionModel::where('id', '=', $id)->inc('view_times')->update();
- }
- }
- if(!empty($info->housetype))
- $info['housetype']['name'] = $info->housetype->name;
- else
- $info['housetype'] = '';
- return json(['code'=> self::success, 'msg'=> '请求成功', 'data'=> $info]);
- }
- /**
- * 装修案例小区列表
- */
- public function communitylist()
- {
- $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){
- $item['construction_count'] = ConstructionModel::where('community_id', '=', $item['id'])->count();
- })->toArray();
- return json(['code' => 0, 'data' => $communityArr, 'msg' => '获取成功']);
- }
- }
|