SettingModel.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. namespace app\common\model;
  3. class SettingModel extends BaseModel
  4. {
  5. // 设置表名
  6. protected $name = 'setting';
  7. // 短信配置
  8. const SMS = [
  9. 'sms_chuanglan_appkey',
  10. 'sms_chuanglan_secret',
  11. 'sms_type',
  12. 'sms_verify_expire',
  13. ];
  14. const SYSTEM = [
  15. 'site_name',
  16. ];
  17. const SMS_TYPE = [
  18. ['value' => '\\chuanglan\\Chuanglan', 'text' => '创蓝短信'],
  19. ];
  20. public static function getConfigValue($code)
  21. {
  22. $res = [];
  23. if (is_array($code)) {
  24. $list = self::where('code', 'in', $code)->select();
  25. if ($list->isEmpty()) {
  26. return [];
  27. }
  28. foreach ($list as $v) {
  29. $res[$v['code']] = $v['value'];
  30. }
  31. } elseif (is_string($code)) {
  32. $info = self::where('code', $code)->find();
  33. if (empty($info)) {
  34. return '';
  35. }
  36. $res = $info['value'];
  37. }
  38. return $res;
  39. }
  40. public static function setConfigValue($code, $value = '')
  41. {
  42. if (is_array($code)) {
  43. foreach ($code as $k => $v) {
  44. self::setConfigValueSingle($k, $v);
  45. }
  46. } elseif (is_string($code)) {
  47. self::setConfigValueSingle($code, $value);
  48. }
  49. }
  50. public static function setConfigValueSingle($code, $value = '')
  51. {
  52. $info = self::where('code', $code)->find();
  53. if (empty($info)) {
  54. self::create(['code' => $code, 'value' => $value]);
  55. } else {
  56. $info->value = $value;
  57. $info->save();
  58. }
  59. }
  60. }