123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- <?php
- declare(strict_types=1);
- namespace app\logics;
- use app\model\ToolSettings;
- class ToolSettingsLogic
- {
- /**
- * 风格测试获客
- */
- public function list()
- {
- $styleTest = ToolSettings::where('tool_type','styleTest')->value('value');
- $data = json_decode($styleTest,true);
- $type = [1=>'现代简约',2=>'新中式',3=>'北欧',4=>'简欧',5=>'地中海',6=>'美式',7=>'轻奢',8=>'田园'];
- foreach($data as $k=>$v){
- $data[$k]['key'] = $k;
- $data[$k]['type'] = $type[$v['type']];
- $data[$k]['img'] = 'https://' . config('app.ali_oss_bindurl') .'/'. $v['img'];
- }
-
- return ['code'=>0, 'data'=>$data, 'count'=>count($data)];
- }
- /**
- * 总数获取
- */
- public function count($where)
- {
- $modelObj = ToolSettings::where($where);
- $num = $modelObj->count();
- return $num;
- }
-
- /*
- * 添加
- */
- public function addimg($data)
- {
- $find = ToolSettings::where('tool_type','styleTest')->find();
- $array = json_decode($find['value'],true);
- $newArr['type'] = $data['type'];
- $newArr['img'] = $data['img'];
- $newArr['addtime'] = date('Y-m-d H:i:s');
- $array[] = $newArr;
-
- $editNewData = json_encode($array);
- $find->value = $editNewData;
- $find->save();
- }
-
- /*
- * 删除
- */
- public function delete($key)
- {
- $data = ToolSettings::where('tool_type','styleTest')->value('value');
- $tool_data = json_decode($data,true);
- unset($tool_data[0]);
- $tool_data = json_encode($tool_data);
- ToolSettings::where('tool_type','styleTest')->setField('value',$tool_data);
- }
-
- /*
- * 修改查看
- */
- public function edit($key)
- {
- $data = ToolSettings::where('tool_type','styleTest')->value('value');
- $editData = json_decode($data,true)[$key];
- $editData['key'] = $key;
- $editData['img'] = 'https://' . config('app.ali_oss_bindurl') .'/'. $editData['img'];
- return $editData;
- }
-
- /*
- * 保存修改
- */
- public function editSave($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'] , 'addtime'=>date('Y-m-d H:i:s')];
- $newArr = json_encode($editData);
- ToolSettings::where('tool_type','styleTest')->setField('value',$newArr);
- }
- /*
- * 保存decoration helper设置
- */
- public function saveDeco($json_str){
- $deco = ToolSettings::where('tool_type','decoHelper')->find();
- if($deco){
- if(ToolSettings::where('tool_type','decoHelper')->update(['value' => $json_str])){
- return ['code'=>0, 'msg'=>'保存成功'];
- }else{
- return ['code'=>1, 'msg'=>'保存失败'];
- }
- }else{
- if((new ToolSettings())->insert(['tool_type'=>'decoHelper', 'value' => $json_str])){
- return ['code'=>0, 'msg'=>'保存成功'];
- }else{
- return ['code'=>1, 'msg'=>'保存失败'];
- }
- }
- }
- /*
- * 获取decohelper value
- */
- public function decovalue(){
- $decostr = ToolSettings::where('tool_type','decoHelper')->value('value');
- return $decostr;
- }
- }
|