ToolSettingsLogic.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. declare(strict_types=1);
  3. namespace app\logics;
  4. use app\model\ToolSettings;
  5. class ToolSettingsLogic
  6. {
  7. /**
  8. * 风格测试获客
  9. */
  10. public function list()
  11. {
  12. $styleTest = ToolSettings::where('tool_type','styleTest')->value('value');
  13. $data = json_decode($styleTest,true);
  14. $type = [1=>'现代简约',2=>'新中式',3=>'北欧',4=>'简欧',5=>'地中海',6=>'美式',7=>'轻奢',8=>'田园'];
  15. foreach($data as $k=>$v){
  16. $data[$k]['key'] = $k;
  17. $data[$k]['type'] = $type[$v['type']];
  18. $data[$k]['img'] = 'https://' . config('app.ali_oss_bindurl') .'/'. $v['img'];
  19. }
  20. return ['code'=>0, 'data'=>$data, 'count'=>count($data)];
  21. }
  22. /**
  23. * 总数获取
  24. */
  25. public function count($where)
  26. {
  27. $modelObj = ToolSettings::where($where);
  28. $num = $modelObj->count();
  29. return $num;
  30. }
  31. /*
  32. * 添加
  33. */
  34. public function addimg($data)
  35. {
  36. $find = ToolSettings::where('tool_type','styleTest')->find();
  37. $array = json_decode($find['value'],true);
  38. $newArr['type'] = $data['type'];
  39. $newArr['img'] = $data['img'];
  40. $newArr['addtime'] = date('Y-m-d H:i:s');
  41. $array[] = $newArr;
  42. $editNewData = json_encode($array);
  43. $find->value = $editNewData;
  44. $find->save();
  45. }
  46. /*
  47. * 删除
  48. */
  49. public function delete($key)
  50. {
  51. $data = ToolSettings::where('tool_type','styleTest')->value('value');
  52. $tool_data = json_decode($data,true);
  53. unset($tool_data[0]);
  54. $tool_data = json_encode($tool_data);
  55. ToolSettings::where('tool_type','styleTest')->setField('value',$tool_data);
  56. }
  57. /*
  58. * 修改查看
  59. */
  60. public function edit($key)
  61. {
  62. $data = ToolSettings::where('tool_type','styleTest')->value('value');
  63. $editData = json_decode($data,true)[$key];
  64. $editData['key'] = $key;
  65. $editData['img'] = 'https://' . config('app.ali_oss_bindurl') .'/'. $editData['img'];
  66. return $editData;
  67. }
  68. /*
  69. * 保存修改
  70. */
  71. public function editSave($data)
  72. {
  73. $tool_value = ToolSettings::where('tool_type','styleTest')->value('value');
  74. $editData = json_decode($tool_value,true);
  75. $editData[$data['key']] = ['type'=>$data['type'] , 'img'=>isset($data['img']) ? $data['img'] : $editData[$data['key']]['img'] , 'addtime'=>date('Y-m-d H:i:s')];
  76. $newArr = json_encode($editData);
  77. ToolSettings::where('tool_type','styleTest')->setField('value',$newArr);
  78. }
  79. /*
  80. * 保存decoration helper设置
  81. */
  82. public function saveDeco($json_str){
  83. $deco = ToolSettings::where('tool_type','decoHelper')->find();
  84. if($deco){
  85. if(ToolSettings::where('tool_type','decoHelper')->update(['value' => $json_str])){
  86. return ['code'=>0, 'msg'=>'保存成功'];
  87. }else{
  88. return ['code'=>1, 'msg'=>'保存失败'];
  89. }
  90. }else{
  91. if((new ToolSettings())->insert(['tool_type'=>'decoHelper', 'value' => $json_str])){
  92. return ['code'=>0, 'msg'=>'保存成功'];
  93. }else{
  94. return ['code'=>1, 'msg'=>'保存失败'];
  95. }
  96. }
  97. }
  98. /*
  99. * 获取decohelper value
  100. */
  101. public function decovalue(){
  102. $decostr = ToolSettings::where('tool_type','decoHelper')->value('value');
  103. return $decostr;
  104. }
  105. }