123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- <?php
- namespace app\logics;
- use app\event\FootPrints;
- use app\model\CustomerClue;
- use app\model\Employee;
- use app\model\Tool;
- use app\model\ToolSettings;
- use think\facade\Log;
- class ToolLogic
- {
- public static function list($type = '')
- {
- $styleTest = ToolSettings::where(['tool_type' => 'styleTest', 'root_id' => request()->employee->root_id])->value('value');
- if (empty($styleTest)) {
- return [];
- }
- $data = json_decode($styleTest,true);
- if(!empty($type)){
- $data = array_filter($data, function($t) use ($type) { return $t['type'] == $type; });
- }
-
- // $type = [1=>'现代简约',2=>'新中式',3=>'北欧',4=>'简欧',5=>'地中海',6=>'美式',7=>'轻奢',8=>'田园'];
- $type = (new ToolSettings())->getStyleTypeAttr();
- foreach($data as $k=>$v){
- $data[$k]['key'] = $k;
- $data[$k]['type'] = $type[$v['type']];
- $data[$k]['img'] = 'http://' . config('app.ali_oss_bindurl') .'/'. $v['img'];
- }
- return $data;
- }
-
- public static function styleTestAddSave($data)
- {
- $find = ToolSettings::where(['tool_type'=> 'styleTest', 'root_id'=> $data['root_id']])->find();
- if (empty($find)) {
- $newArr['type'] = $data['type'];
- $newArr['img'] = $data['img'];
- $array[] = $newArr;
- $save_array['tool_type'] = 'styleTest';
- $save_array['value'] = json_encode($array);
- $save_array['root_id'] = request()->employee->root_id;
- (new ToolSettings())->insert($save_array);
- } else {
- $array = json_decode($find->getData('value'),true);
- $newArr['type'] = $data['type'];
- $newArr['img'] = $data['img'];
- $array[] = $newArr;
- $find->save(['value'=>json_encode($array)]);
- }
- }
-
- public static function styleTestEdit($key)
- {
- $data = ToolSettings::where('tool_type','styleTest')->value('value');
- $editData = json_decode($data,true)[$key];
- $editData['key'] = $key;
- $editData['img'] = 'http://' . config('app.ali_oss_bindurl') .'/'. $editData['img'];
- return $editData;
- }
- public static function styleTestEditSave($data)
- {
- $tool_value = ToolSettings::where('tool_type','styleTest')->value('value');
- $editData = json_decode($tool_value,true);
- $editData[$data['key']] = ['type'=>$data['type'] , 'img'=>isset($data['img']) ? $data['img'] : $editData[$data['key']]['img']];
- $newArr = json_encode($editData);
- ToolSettings::where('tool_type','styleTest')->update(['value'=>$newArr]);
- }
- public static function delete($key)
- {
- $data = ToolSettings::where('tool_type','styleTest')->value('value');
- $tool_data = json_decode($data,true);
- unset($tool_data[$key]);
- $tool_data = json_encode($tool_data);
- ToolSettings::where('tool_type','styleTest')->update(['value'=>$tool_data]);
- }
- /**
- * 装修报价表单保存
- */
- public function formAdd($content, $user_id , $share_user_id)
- {
- $data = Tool::create([
- 'user_id' => $user_id,
- 'share_uid' => $share_user_id,
- 'tool_type' => 'priceCalculation',
- 'value' => json_encode($content)
- ]);
- // 添加客户线索
- /*if (!empty($share_user_id)) {
- // 添加客户线索
- $employee = (new Employee())->where('uid', '=', $share_user_id)->find();
- $clue_data['uid'] = $user_id;
- $clue_data['employee_id'] = $employee['id'];
- $clue_data['pipe_type'] = 'tool';
- $clue_data['pipe_id'] = $data->id;
- $clue_data['org_id'] = $employee['org_id'];
- $clue_data['phone'] = !empty($content['mobile']) ? $content['mobile'] : '';
- $customer_clue = CustomerClue::create($clue_data);
- }*/
- return $data->id;
- }
- /**
- * 风格喜好测一测
- */
- public function likeTestAdd($content, $user_id , $share_user_id){
- $data = Tool::create([
- 'user_id' => $user_id,
- 'share_uid' => $share_user_id,
- 'tool_type' => 'likeTest',
- 'value' => json_encode($content)
- ]);
- // 添加客户线索
- /*if (!empty($share_user_id)) {
- // 添加客户线索
- $employee = (new Employee())->where('uid', '=', $share_user_id)->find();
- $clue_data['uid'] = $user_id;
- $clue_data['employee_id'] = $employee['id'];
- $clue_data['pipe_type'] = 'tool';
- $clue_data['pipe_id'] = $data->id;
- $clue_data['org_id'] = $employee['org_id'];
- $clue_data['phone'] = !empty($content['mobile']) ? $content['mobile'] : '';
- $customer_clue = CustomerClue::create($clue_data);
- }*/
- return $data->id;
- }
- /**
- * 风格测一测
- */
- public function styleTestResult($content, $user_id , $share_user_id){
- $data = Tool::create([
- 'user_id' => $user_id,
- 'share_uid' => $share_user_id,
- 'tool_type' => 'styleTest',
- 'value' => json_encode($content)
- ]);
- // 添加客户线索
- /*if (!empty($share_user_id)) {
- // 添加客户线索
- $employee = (new Employee())->where('uid', '=', $share_user_id)->find();
- $clue_data['uid'] = $user_id;
- $clue_data['employee_id'] = $employee['id'];
- $clue_data['pipe_type'] = 'tool';
- $clue_data['pipe_id'] = $data->id;
- $clue_data['org_id'] = $employee['org_id'];
- $clue_data['phone'] = !empty($content['mobile']) ? $content['mobile'] : '';
- $customer_clue = CustomerClue::create($clue_data);
- }*/
- return $data->id;
- }
- }
- ?>
|