Setting.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * Author: 芸众商城 www.yunzshop.com
  5. * Date: 01/03/2017
  6. * Time: 12:51
  7. */
  8. namespace app\common\facades;
  9. use Illuminate\Support\Facades\Facade;
  10. use app\common\models\Setting as SettingModel;
  11. class Setting extends Facade
  12. {
  13. public static $uniqueAccountId = 0;
  14. private static $instance;
  15. protected static function getFacadeAccessor()
  16. {
  17. return 'setting';
  18. }
  19. public static function getInstance()
  20. {
  21. if (is_null(self::$instance)) {
  22. self::$instance = new SettingModel();
  23. }
  24. return self::$instance;
  25. }
  26. /**
  27. * 设置配置信息
  28. *
  29. * @param $key
  30. * @param null $value
  31. */
  32. public static function set($key, $value = null)
  33. {
  34. return self::getInstance()->setValue(self::$uniqueAccountId, $key, $value);
  35. }
  36. /**
  37. * 设置不区分公众号配置信息
  38. *
  39. * @param $key
  40. * @param null $value
  41. * @return mixed
  42. */
  43. public static function setNotUniacid($key, $value = null)
  44. {
  45. return self::getInstance()->setValue(0, $key, $value);
  46. }
  47. /**
  48. * 获取配置信息
  49. *
  50. * @param $key
  51. * @param null $default
  52. * @return mixed
  53. */
  54. public static function get($key, $default = null)
  55. {
  56. return self::getInstance()->getValue(self::$uniqueAccountId, $key, $default);
  57. }
  58. /**
  59. * 获取不区分公众号配置信息
  60. *
  61. * @param $key
  62. * @param null $default
  63. * @return mixed
  64. */
  65. public static function getNotUniacid($key, $default = null)
  66. {
  67. return self::getInstance()->getValue(0, $key, $default);
  68. }
  69. /**
  70. * 检测是否存在分组
  71. * @param $group
  72. * @return bool
  73. */
  74. public static function exitsGroup($group)
  75. {
  76. return self::getInstance()->exists(self::$uniqueAccountId, $group);
  77. }
  78. /**
  79. * 获取分组所有值
  80. * @param $group
  81. * @return \Illuminate\Database\Eloquent\Collection|static[]
  82. */
  83. public static function getAllByGroup($group)
  84. {
  85. return self::getInstance()->fetchSettings(self::$uniqueAccountId, $group);
  86. }
  87. /**
  88. * 获取分组所有值
  89. * @param $group
  90. * @return \Illuminate\Database\Eloquent\Collection|static[]
  91. */
  92. public static function getByGroup($group)
  93. {
  94. return self::getInstance()->getItems(self::$uniqueAccountId, $group);
  95. }
  96. }