Setting.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | A3Mall
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2020 http://www.a3-mall.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Author: xzncit <158373108@qq.com>
  8. // +----------------------------------------------------------------------
  9. namespace mall\basic;
  10. use think\facade\Db;
  11. class Setting {
  12. public static function save($name="",$data=null){
  13. if(empty($data)){
  14. return false;
  15. }
  16. $array["value"] = is_array($data) ? json_encode($data,JSON_UNESCAPED_UNICODE) : $data;
  17. if(Db::name("setting")->where(["name"=>$name])->count()){
  18. Db::name("setting")->where(["name"=>$name])->update($array);
  19. }else{
  20. $array["name"] = $name;
  21. Db::name("setting")->insert($array);
  22. }
  23. return true;
  24. }
  25. public static function get($name="",$json=false){
  26. $content = Db::name("setting")->where(["name"=>$name])->value("value");
  27. if(empty($content)){
  28. return "";
  29. }
  30. return $json ? $content : json_decode($content,true);
  31. }
  32. }