Material.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. <?php
  2. namespace app\client\controller;
  3. use app\event\FootPrints;
  4. use app\event\Msg;
  5. use app\model\Community;
  6. use app\model\CompanyVrshow;
  7. use app\model\CustomerClue;
  8. use app\model\DesignerReserve;
  9. use app\model\Employee;
  10. use app\model\MaterialCase;
  11. use app\model\Decostyle;
  12. use app\model\EvidenceCate;
  13. use app\model\Housetype;
  14. use app\model\MaterialEvidence;
  15. use app\model\Designer;
  16. use app\model\User;
  17. use app\model\VrGroup;
  18. use app\model\Footprints as FootprintsModel;
  19. use think\facade\Request;
  20. class Material extends Base
  21. {
  22. /**
  23. * 装修案例风格
  24. */
  25. public function decostylelist()
  26. {
  27. $styleArr = Decostyle::where(['root_id' => request()->token['root_org']])->field('id, name')->select();
  28. return json(['code' => 0, 'data' => $styleArr, 'msg' => '获取成功']);
  29. }
  30. /**
  31. * 设计师预约
  32. */
  33. public function designer_reserve(){
  34. $token = request()->token;
  35. if ($token['isEmployee']) {
  36. return json(['code' => 1, 'data' =>'员工无法预约', 'msg' =>'员工无法预约']);
  37. }
  38. $param = request()->only(['id'=> '', 'designer_id'=> '', 'type'=> '', 'share_uid'=> 0]);
  39. $employee = $param['share_uid'] ? Employee::where([['uid', '=', $param['share_uid']], ['root_id', '=', $token['root_org']]])->findOrEmpty() : [];
  40. $designer_data['designer_id'] = $param['designer_id'];
  41. $designer_data['uid'] = $token['uid'];
  42. $designer_data['employee_id'] = !empty($employee) ? $employee['id'] : 0;
  43. $designer_data['pipe_type'] = 'materialCase';
  44. $designer_data['data_id'] = $param['id'];
  45. $designer_data['root_id'] = $token['root_org'];
  46. DesignerReserve::create($designer_data);
  47. $where[] = ['id', '=', $param['designer_id']];
  48. $where[] = ['root_id', '=', $token['root_org']];
  49. $root_id = $token['root_org'];
  50. $data = Employee::with(['designer'=>function($query) use ($root_id){
  51. $query->where('root_id', $root_id)->visible(['headimgurl','employee_id','desc','good_at','position','work_years','addtime','good_house','design_concept','vcr','id designer_id'])->bind(['desc','good_at','position','work_years','addtime','good_house','design_concept','vcr','name','headimgurl']);
  52. }])->where($where)->field('name title,id,show,id designer_id,root_id')->findOrEmpty();
  53. $data['share_pipe_type'] = 'materialCase';
  54. $data['share_data_id'] = $param['id'];
  55. event(new FootPrints($token['uid'], $token['share_employee'] ?? 0, $token['share_org'] ?? 0, $data, 'designer'));
  56. //预约设计师获客线索提醒:*** 预约了 **** 设计师,请跟进沟通
  57. $username = User::where('id', '=', $token['uid'])->value('nickname');
  58. if (!$data->isEmpty()) {
  59. $designer_name = $data['title'];
  60. } else {
  61. $designer_name = '';
  62. }
  63. $new = $username . '预约了' . $designer_name . '设计师,请及时跟进';
  64. if (!empty($employee)){
  65. event(new Msg($employee['id'], $new, 'designer'));
  66. }
  67. return json(['code' => 0, 'data' =>'预约成功', 'msg' =>'预约成功']);
  68. }
  69. /*
  70. * material case list
  71. */
  72. public function caselist()
  73. {
  74. $param = $this->request->param();
  75. $where[] = ['root_id', '=', request()->token['root_org']];
  76. $where[] = ['del', '=', 0];
  77. $where[] = ['publish', '=', 1];
  78. setCondition($param, ['commu_id', 'community_id'], '=', $where);
  79. setCondition($param, 'style_id', '=', $where);
  80. setCondition($param, ['square_start', 'square'], '>=', $where);
  81. setCondition($param, ['square_end', 'square'], '<', $where);
  82. setCondition($param, ['keyword', 'title'], ['like', '%VALUE%'], $where);
  83. setCondition($param, 'housetype_id', '=', $where);
  84. if (!empty($param['case_type'])) {
  85. if ($param['case_type'] == 1) {
  86. $where[] = ['desc', '<>', ''];
  87. $where[] = ['desc', 'not null',''];
  88. }
  89. if ($param['case_type'] == 2) {
  90. $where[] = ['real_case', '<>', ''];
  91. $where[] = ['real_case', 'not null',''];
  92. }
  93. }
  94. $page = !empty($param['page']) ? $param['page'] : 1;
  95. $limit = !empty($param['limit']) ? $param['limit'] : 15;
  96. $list = MaterialCase::with(['community','decostyle'])->field('id,title,cover_img,view_times,square,addtime,community_id,style_id,vr_case,recommend')->where($where)->page($page, $limit)->order('recommend desc, updatetime desc')->select();
  97. return json(['code' => 0, 'data' => $list, 'msg' => '获取成功']);
  98. }
  99. /**
  100. * 装修案例
  101. */
  102. public function casedetail()
  103. {
  104. $id = $this->request->param('id');
  105. $share = input('share', '', 'trim');
  106. $data = MaterialCase::with([
  107. 'community',
  108. 'designer',
  109. 'decostyle',
  110. 'housetype'
  111. ])->find($id);
  112. $token = $this->request->token;
  113. if ($data['designer']){
  114. $designer = Designer::where([['employee_id', '=', $data['designer']['id']], ['root_id', '=', $token['root_org']]])->findOrEmpty();
  115. if (!$designer->isEmpty()) {
  116. $data['designer']['good_at'] = $designer['good_at'];
  117. $data['designer']['position'] = $designer['position'];
  118. } else {
  119. $data['designer']['good_at'] = '';
  120. $data['designer']['position'] = '';
  121. }
  122. $data['designer']['headimgurl'] = User::where('id', '=', $data['designer']['uid'])->value('headimgurl');
  123. }
  124. if (empty($share) && !$token['isEmployee']){
  125. MaterialCase::where('id', $id)->inc('view_times')->update();
  126. }
  127. if (!empty($token['uid']) && !$token['isEmployee'] && empty($share)) {
  128. event(new FootPrints($token['uid'], $token['share_employee'] ?? 0, $token['share_org'] ?? 0, $data));
  129. }
  130. // 关联案例
  131. if (!empty($data['designer_id'])) {
  132. $relatedcaselist = MaterialCase::where([['designer_id', '=', $data->designer_id], ['id', '<>', $id], ['root_id', '=', $token['root_org']], ['del', '=', 0], ['publish', '=', 1]])
  133. ->with(['community' => function ($query) {
  134. $query->field('id,name');
  135. }, 'decostyle' => function ($query) {
  136. $query->field('id,name');
  137. }])->page(1, 4)->order('id desc')->select()->each(function ($item) {
  138. $item->clue_number = CustomerClue::where([['pipe_type', '=', 'materialCase'], ['pipe_id', '=', $item['id']]])->count();
  139. })->toArray();
  140. } else {
  141. $relatedcaselist = [];
  142. }
  143. $data['designer_related_cases'] = $relatedcaselist;
  144. // 查询上一条
  145. $data['preid'] = MaterialCase::where([['updatetime', '>', $data['updatetime']], ['id', '<>', $id]])
  146. ->order('updatetime asc')->value('id');
  147. $data['nextid'] = MaterialCase::where([['updatetime', '<', $data['updatetime']], ['id', '<>', $id]])
  148. ->order('updatetime desc')->value('id');
  149. // 为null处理,防止前端报错
  150. $data['real_case'] = !is_null($data['real_case']) ? $data['real_case'] : '';
  151. $data['desc'] = !is_null($data['desc']) ? $data['desc'] : '';
  152. $data['vr_case'] = !is_null($data['vr_case']) ? $data['vr_case'] : '';
  153. $data['housetype']['name'] = $data->housetype->name;
  154. return json(['code' => 0, 'data' => $data, 'msg' => '获取成功']);
  155. }
  156. /**
  157. * 设计师相关案例
  158. */
  159. public function designercases()
  160. {
  161. $data = input();
  162. //$style_id = $data['style_id'];
  163. $page = $data['page'];
  164. $limit = $data['limit'];
  165. $material_case_id = input('material_case_id', '', 'intval');
  166. if ($material_case_id) {//相关推荐时,去除所查看的案例
  167. $where[] = ['id', '<>', $material_case_id];
  168. }
  169. //$where[] = ['style_id', '=', $style_id];
  170. $designer_id = input('designer_id', '', 'intval');
  171. if ($designer_id) {
  172. $where[] = ['designer_id', '=', $designer_id];
  173. } else {
  174. return json(['code' => 0, 'data' => [], 'msg' => '获取成功']);
  175. }
  176. $where[] = ['root_id', '=', request()->token['root_org']];
  177. $where[] = ['del', '=', 0];
  178. $where[] = ['publish', '=', 1];
  179. $relatedcaselist = MaterialCase::where($where)->with(['community', 'decostyle'])->page($page, $limit)->order('id desc')->select();
  180. return json(['code' => 0, 'data' => $relatedcaselist, 'msg' => '获取成功']);
  181. }
  182. /*
  183. * 口碑见证列表
  184. */
  185. public function evidencelist()
  186. {
  187. $param = $this->request->param();
  188. $param['difference'] = isset($param['difference']) ? $param['difference'] : 0;
  189. $where[] = ['root_id', '=', request()->token['root_org']];
  190. $where[] = ['del', '=', 0];
  191. $where[] = ['publish', '=', 1];
  192. if ($param['difference']) {
  193. $where[] = ['difference', '=', $param['difference']];
  194. }
  195. setCondition($param, 'cate', '=', $where);
  196. setCondition($param, ['keyword', 'title'], ['like', '%VALUE%'], $where);
  197. $page = !empty($param['page']) ? $param['page'] : 1;
  198. $limit = !empty($param['limit']) ? $param['limit'] : 15;
  199. $list = MaterialEvidence::where($where)->limit($limit)->page($page, $limit)->order('addtime desc')->select();
  200. return json(['code' => 0, 'data' => $list, 'msg' => '获取成功']);
  201. }
  202. /**
  203. * 口碑见证详情
  204. */
  205. public function evidencedetail($id)
  206. {
  207. $evidence = MaterialEvidence::find($id);
  208. $token = $this->request->token;
  209. if (!$token['isEmployee']) {
  210. MaterialEvidence::where(['id' => $id])->inc('view_times')->update();
  211. }
  212. // 足迹
  213. if (!empty($token['uid']) && !$token['isEmployee']) {
  214. event(new FootPrints($token['uid'], $token['share_employee'] ?? 0, $token['share_org'] ?? 0, $evidence));
  215. }
  216. if (empty($evidence)) return json(['code' => self::error_msg, 'msg' => '数据不存在']);
  217. // 查询上一条
  218. $lastId = MaterialEvidence::where([['addtime', '>', $evidence->addtime], ['id', '<>', $id]])
  219. ->order('addtime asc')->value('id');
  220. $nextId = MaterialEvidence::where([['addtime', '<', $evidence->addtime], ['id', '<>', $id]])
  221. ->order('addtime desc')->value('id');
  222. return json(['code' => 0, 'data' => $evidence, 'msg' => '获取成功', 'lastId' => $lastId, 'nextId' => $nextId]);
  223. }
  224. /**
  225. * 口碑见证分类
  226. */
  227. public function evidenceCate()
  228. {
  229. $styleArr = EvidenceCate::where(['root_id' => request()->token['root_org']])->field('id, name')->select();
  230. return json(['code' => 0, 'data' => $styleArr, 'msg' => '获取成功']);
  231. }
  232. /*
  233. * 装修案例户型
  234. */
  235. public function housetypelist()
  236. {
  237. $housetypeArr = Housetype::where(['root_id' => request()->token['root_org']])->field('id,name')->select();
  238. return json(['code' => 0, 'data' => $housetypeArr, 'msg' => '获取成功']);
  239. }
  240. /**
  241. * 装修案例小区列表
  242. */
  243. public function communitylist()
  244. {
  245. $communityArr = Community::where(['root_id' => request()->token['root_org']])->where([['type', '=', 0]])->field('id,name,pinyin,case_num')->select()->toArray();
  246. $comidlist = array_column($communityArr, 'id');
  247. $caseData = MaterialCase::where([['community_id', 'in', $comidlist], ['del', '=', 0], ['publish', '=', 1]])->group('community_id')->order('updatetime asc')->column('max(updatetime) as updatetime, sum(shared_times) as shared_times, count(id) as case_num', 'community_id');
  248. foreach ($communityArr as &$i) {
  249. if (isset($caseData[$i['id']])) {
  250. $i['updatetime'] = $caseData[$i['id']]['updatetime'];
  251. $i['shared_times'] = (int)$caseData[$i['id']]['shared_times'];
  252. $i['case_num'] = (int)$caseData[$i['id']]['case_num'];
  253. } else {
  254. $i['updatetime'] = 0;
  255. $i['shared_times'] = 0;
  256. $i['case_num'] = 0;
  257. }
  258. }
  259. return json(['code' => 0, 'data' => $communityArr, 'msg' => '获取成功']);
  260. }
  261. /*
  262. * 案例vr足迹、热装楼盘vr足迹、线上展厅vr、名片vr
  263. */
  264. public function vrfootprints()
  265. {
  266. $param = $this->request->param();
  267. if(!in_array($param['type'],['materialCase','building','company','employeeCard','construction','groupVr','housetype'])){
  268. return json(['code' => 1, 'msg' => '类型错误']);
  269. }
  270. if($param['type'] == 'company'){
  271. $className = 'app\\model\\CompanyVrshow';
  272. $obj = new $className();
  273. $data = $obj->where('id',$param['id'])->field('id,url as vr_show,name')->find();
  274. if(empty($data)) return json(['code' => 1, 'msg' => '数据不存在']);
  275. }if ($param['type'] == 'groupVr') {
  276. $className = 'app\\model\\VrGroup';
  277. $obj = new $className();
  278. $data = $obj->where('id|sid',$param['id'])->find();
  279. if(empty($data)) return json(['code' => 1, 'msg' => '数据不存在']);
  280. $param['type'] = 'group';
  281. }elseif($param['type'] == 'housetype'){
  282. //
  283. $className = 'app\\model\\BuildingHousetype';
  284. $obj = new $className();
  285. $data = $obj->where('id',$param['id'])->find();
  286. }else{
  287. $className = 'app\\model\\' . ucfirst($param['type']);
  288. $obj = new $className();
  289. $field = $param['type'] == 'employeeCard' ? 'employee_id' : 'id';
  290. $data = $obj->where($field,$param['id'])->find();
  291. }
  292. if(isset($param['prompt'])) $data->prompt = $param['prompt'];//扩展字段 按需求使用
  293. // 足迹
  294. $token = $this->request->token;
  295. if (!empty($token['uid']) && !$token['isEmployee']) {
  296. event(new FootPrints($token['uid'], $token['share_employee'] ?? 0, $token['share_org'] ?? 0, $data, $param['type'].'Vr'));
  297. }
  298. }
  299. /**
  300. * vr作品场景 浏览详情
  301. * 作品中的每个场景具体浏览了多长时间
  302. * id 作品id或者sid
  303. * view_id 场景id
  304. * time 浏览时长
  305. * viewtime 浏览场景的具体时间
  306. */
  307. public function saveViewFoots()
  308. {
  309. $token = $this->request->token;
  310. $param = Request::only(['sid','view_id','time'=>0,'viewtime'=>'']);
  311. $id = VrGroup::where('id|sid',$param['sid'])->value('id');
  312. $where = [['uid', '=', $token['uid']],['pipe_type','like','%Vr%']];
  313. $info = FootprintsModel::where($where)->order('id desc')->findOrEmpty();
  314. if($info->isEmpty()) return json(['code' => 1,'data'=>'足迹不存在', 'msg' => '足迹不存在']);
  315. $arr = $info->getData('reg_info') ? json_decode($info->getData('reg_info'),true) : [];
  316. $ls_arr = [['vid'=>$param['view_id'],'time'=>$param['time'],'viewtime'=>$param['viewtime']]];
  317. $arr['view_foots'] = isset($arr['view_foots']) ? array_merge($arr['view_foots'],$ls_arr) : $ls_arr;
  318. $info->reg_info = json_encode($arr);
  319. if($arr['view_foots']) $info->visit_due_time = array_sum(array_column($arr['view_foots'],'time'));
  320. $info->save();
  321. return json(['code'=>0,'data'=>'保存完成','msg'=>'保存完成']);
  322. }
  323. }