Tool.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. namespace app\client\controller;
  3. use app\event\FootPrints;
  4. use app\model\ToolSettings;
  5. class Tool extends Base
  6. {
  7. /*
  8. * 工具浏览量增加
  9. */
  10. public function tool_view($type)
  11. {
  12. ToolSettings::where(['tool_type'=> $type, 'root_id' => request()->employee->root_id])->inc('use_number');
  13. return json(['code' => self::success, 'msg' => '浏览量增加']);
  14. }
  15. /*
  16. * 装修报价算一算
  17. */
  18. public function quotationform()
  19. {
  20. $param = $this->request->only(['name', 'mobile', 'community', 'area', 'room', 'office', 'wei', 'style', 'type']);
  21. $data = [
  22. 'name' => $param['name'],
  23. 'mobile' => $param['mobile'],
  24. 'community' => $param['community'],
  25. 'area' => $param['area'],
  26. 'bedroom' => $param['room'] . '/' . $param['office'] . '/' . $param['wei'],
  27. 'style' => $param['style'],
  28. 'type' => $param['type'],
  29. ];
  30. // 足迹
  31. $token = $this->request->token;
  32. if (!empty($token['uid']) && !$token['isEmployee']) {
  33. event(new FootPrints($token['uid'], $token['share_employee'] ?? 0, $token['share_org'] ?? 0, $data, 'priceCalculation'));
  34. }
  35. return json(['code' => self::success, 'msg' => '报名成功,等待联系']);
  36. }
  37. /*
  38. * 风格图片测试结果
  39. */
  40. public function styleTestResult()
  41. {
  42. $result = $this->request->param('result'); //逗号分隔的喜欢风格类型
  43. // 风格结果
  44. $style = [
  45. 1 => ['style' => '现代简约', 'msg' => '线条简单,设计独特', 'function' => '色彩明亮洁净', 'city' => '郑州、广州', 'style_elements' => '黑白灰为主色调'],
  46. 2 => ['style' => '新中式', 'msg' => '文化涵养', 'function' => '文化氛围', 'city' => '杭州、北京', 'style_elements' => '黑白灰基础上加与红黄蓝绿'],
  47. 3 => ['style' => '北欧', 'msg' => '优雅自然风情', 'function' => '简约大方', 'city' => '上海、江苏', 'style_elements' => '偏浅色、以纯色为主'],
  48. 4 => ['style' => '简欧', 'msg' => '华美厚重', 'function' => '典雅、自然、高贵', 'city' => '武汉、南京', 'style_elements' => '白色、淡色为主,风格统一'],
  49. 5 => ['style' => '地中海', 'msg' => '人文风情', 'function' => '素雅浪漫', 'city' => '青岛、海南', 'style_elements' => '蓝与白、土黄与红褐'],
  50. 6 => ['style' => '美式', 'msg' => '自在、随意', 'function' => '外观简洁大方', 'city' => '上海、北京', 'style_elements' => '暗中色、土黄色,自然色彩'],
  51. 7 => ['style' => '轻奢', 'msg' => '高级感', 'function' => '高级感', 'city' => '深圳、苏州', 'style_elements' => '金属、大理石、蓝色配色等元素来烘托空间'],
  52. 8 => ['style' => '田园', 'msg' => '回归自然', 'function' => '自然、舒适、温婉内敛', 'city' => '苏州、济南', 'style_elements' => '田园气息、追求朴实亲切感'],
  53. 9 => ['style' => '混搭', 'msg' => '简约时尚', 'function' => '追求自主', 'city' => '成都、西安', 'style_elements' => '色彩随意自主、极富个性']
  54. ];
  55. // 风格结果计算方式
  56. $arr = explode(',', $result);
  57. //计算结果
  58. if (empty($result)) {
  59. //全部不喜欢,为混搭
  60. $style_status = 9;
  61. } elseif (mb_strlen($result) == 1) {
  62. //喜欢一张,则喜欢这一种风格为测试结果
  63. $style_status = $result;
  64. } elseif (count($arr) == count(array_unique($arr))) {
  65. //喜欢的风格没有重复,则为混搭
  66. $style_status = 9;
  67. } else {
  68. $res = array_unique(array_diff_assoc($arr, array_unique($arr)));
  69. if (count($res) == 1) {
  70. //喜欢的风格出现一种重复则测试结果为这种风格
  71. $re = implode($res);
  72. $style_status = $re;
  73. } else {
  74. //喜欢风格出现两种以上重复,则为混搭
  75. $style_status = 9;
  76. }
  77. }
  78. $data = ['style' => $style[$style_status]['style']];
  79. // 足迹
  80. $token = $this->request->token;
  81. if (!empty($token['uid']) && !$token['isEmployee']) {
  82. event(new FootPrints($token['uid'], $token['share_employee'] ?? 0, $token['share_org'] ?? 0, $data, 'styleTest'));
  83. }
  84. $count = ToolSettings::where(['tool_type'=> 'styleTest','root_id' => request()->employee->root_id])->value('use_number');
  85. return json([
  86. 'code' => self::success,
  87. 'style' => $style[$style_status]['style'],
  88. 'msg' => $style[$style_status]['msg'],
  89. 'function' => $style[$style_status]['function'],
  90. 'city' => $style[$style_status]['city'],
  91. 'style_elements' => $style[$style_status]['style_elements'],
  92. 'testNum' => $count
  93. ]);
  94. }
  95. }