ToolLogic.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <?php
  2. namespace app\logics;
  3. use app\event\FootPrints;
  4. use app\model\CustomerClue;
  5. use app\model\Employee;
  6. use app\model\Tool;
  7. use app\model\ToolSettings;
  8. use think\facade\Log;
  9. class ToolLogic
  10. {
  11. public static function list($type = '')
  12. {
  13. $styleTest = ToolSettings::where(['tool_type' => 'styleTest', 'root_id' => request()->employee->root_id])->value('value');
  14. if (empty($styleTest)) {
  15. return [];
  16. }
  17. $data = json_decode($styleTest,true);
  18. if(!empty($type)){
  19. $data = array_filter($data, function($t) use ($type) { return $t['type'] == $type; });
  20. }
  21. // $type = [1=>'现代简约',2=>'新中式',3=>'北欧',4=>'简欧',5=>'地中海',6=>'美式',7=>'轻奢',8=>'田园'];
  22. $type = (new ToolSettings())->getStyleTypeAttr();
  23. foreach($data as $k=>$v){
  24. $data[$k]['key'] = $k;
  25. $data[$k]['type'] = $type[$v['type']];
  26. $data[$k]['img'] = 'http://' . config('app.ali_oss_bindurl') .'/'. $v['img'];
  27. }
  28. return $data;
  29. }
  30. public static function styleTestAddSave($data)
  31. {
  32. $find = ToolSettings::where(['tool_type'=> 'styleTest', 'root_id'=> $data['root_id']])->find();
  33. if (empty($find)) {
  34. $newArr['type'] = $data['type'];
  35. $newArr['img'] = $data['img'];
  36. $array[] = $newArr;
  37. $save_array['tool_type'] = 'styleTest';
  38. $save_array['value'] = json_encode($array);
  39. $save_array['root_id'] = request()->employee->root_id;
  40. (new ToolSettings())->insert($save_array);
  41. } else {
  42. $array = json_decode($find->getData('value'),true);
  43. $newArr['type'] = $data['type'];
  44. $newArr['img'] = $data['img'];
  45. $array[] = $newArr;
  46. $find->save(['value'=>json_encode($array)]);
  47. }
  48. }
  49. public static function styleTestEdit($key)
  50. {
  51. $data = ToolSettings::where('tool_type','styleTest')->value('value');
  52. $editData = json_decode($data,true)[$key];
  53. $editData['key'] = $key;
  54. $editData['img'] = 'http://' . config('app.ali_oss_bindurl') .'/'. $editData['img'];
  55. return $editData;
  56. }
  57. public static function styleTestEditSave($data)
  58. {
  59. $tool_value = ToolSettings::where('tool_type','styleTest')->value('value');
  60. $editData = json_decode($tool_value,true);
  61. $editData[$data['key']] = ['type'=>$data['type'] , 'img'=>isset($data['img']) ? $data['img'] : $editData[$data['key']]['img']];
  62. $newArr = json_encode($editData);
  63. ToolSettings::where('tool_type','styleTest')->update(['value'=>$newArr]);
  64. }
  65. public static function delete($key)
  66. {
  67. $data = ToolSettings::where('tool_type','styleTest')->value('value');
  68. $tool_data = json_decode($data,true);
  69. unset($tool_data[$key]);
  70. $tool_data = json_encode($tool_data);
  71. ToolSettings::where('tool_type','styleTest')->update(['value'=>$tool_data]);
  72. }
  73. /**
  74. * 装修报价表单保存
  75. */
  76. public function formAdd($content, $user_id , $share_user_id)
  77. {
  78. $data = Tool::create([
  79. 'user_id' => $user_id,
  80. 'share_uid' => $share_user_id,
  81. 'tool_type' => 'priceCalculation',
  82. 'value' => json_encode($content)
  83. ]);
  84. // 添加客户线索
  85. /*if (!empty($share_user_id)) {
  86. // 添加客户线索
  87. $employee = (new Employee())->where('uid', '=', $share_user_id)->find();
  88. $clue_data['uid'] = $user_id;
  89. $clue_data['employee_id'] = $employee['id'];
  90. $clue_data['pipe_type'] = 'tool';
  91. $clue_data['pipe_id'] = $data->id;
  92. $clue_data['org_id'] = $employee['org_id'];
  93. $clue_data['phone'] = !empty($content['mobile']) ? $content['mobile'] : '';
  94. $customer_clue = CustomerClue::create($clue_data);
  95. }*/
  96. return $data->id;
  97. }
  98. /**
  99. * 风格喜好测一测
  100. */
  101. public function likeTestAdd($content, $user_id , $share_user_id){
  102. $data = Tool::create([
  103. 'user_id' => $user_id,
  104. 'share_uid' => $share_user_id,
  105. 'tool_type' => 'likeTest',
  106. 'value' => json_encode($content)
  107. ]);
  108. // 添加客户线索
  109. /*if (!empty($share_user_id)) {
  110. // 添加客户线索
  111. $employee = (new Employee())->where('uid', '=', $share_user_id)->find();
  112. $clue_data['uid'] = $user_id;
  113. $clue_data['employee_id'] = $employee['id'];
  114. $clue_data['pipe_type'] = 'tool';
  115. $clue_data['pipe_id'] = $data->id;
  116. $clue_data['org_id'] = $employee['org_id'];
  117. $clue_data['phone'] = !empty($content['mobile']) ? $content['mobile'] : '';
  118. $customer_clue = CustomerClue::create($clue_data);
  119. }*/
  120. return $data->id;
  121. }
  122. /**
  123. * 风格测一测
  124. */
  125. public function styleTestResult($content, $user_id , $share_user_id){
  126. $data = Tool::create([
  127. 'user_id' => $user_id,
  128. 'share_uid' => $share_user_id,
  129. 'tool_type' => 'styleTest',
  130. 'value' => json_encode($content)
  131. ]);
  132. // 添加客户线索
  133. /*if (!empty($share_user_id)) {
  134. // 添加客户线索
  135. $employee = (new Employee())->where('uid', '=', $share_user_id)->find();
  136. $clue_data['uid'] = $user_id;
  137. $clue_data['employee_id'] = $employee['id'];
  138. $clue_data['pipe_type'] = 'tool';
  139. $clue_data['pipe_id'] = $data->id;
  140. $clue_data['org_id'] = $employee['org_id'];
  141. $clue_data['phone'] = !empty($content['mobile']) ? $content['mobile'] : '';
  142. $customer_clue = CustomerClue::create($clue_data);
  143. }*/
  144. return $data->id;
  145. }
  146. }
  147. ?>