SinglePageModel.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace app\common\model;
  3. class SinglePageModel extends BaseModel
  4. {
  5. // 设置表名
  6. protected $name = 'single_page';
  7. // 短信配置
  8. const CODE = [
  9. 'privacy',
  10. 'service',
  11. 'about',
  12. ];
  13. const CODE_TITLE = [
  14. 'privacy' => '隐私政策',
  15. 'service' => '用户协议',
  16. 'about' => '关于我们',
  17. ];
  18. public static function getConfigValue($code)
  19. {
  20. $res = [];
  21. if (is_array($code)) {
  22. $list = self::where('code', 'in', $code)->select();
  23. if ($list->isEmpty()) {
  24. return [];
  25. }
  26. foreach ($list as $v) {
  27. $res[$v['code']] = $v['value'];
  28. }
  29. } elseif (is_string($code)) {
  30. $info = self::where('code', $code)->find();
  31. if (empty($info)) {
  32. return '';
  33. }
  34. $res = $info['value'];
  35. }
  36. return $res;
  37. }
  38. public static function setConfigValue($code, $value = '')
  39. {
  40. if (is_array($code)) {
  41. foreach ($code as $k => $v) {
  42. self::setConfigValueSingle($k, $v);
  43. }
  44. } elseif (is_string($code)) {
  45. self::setConfigValueSingle($code, $value);
  46. }
  47. }
  48. public static function setConfigValueSingle($code, $value = '')
  49. {
  50. if (in_array($code,self::CODE)) {
  51. $info = self::where('code', $code)->find();
  52. if (empty($info)) {
  53. self::create(['code' => $code, 'value' => $value]);
  54. } else {
  55. $info->value = $value;
  56. $info->save();
  57. }
  58. }
  59. }
  60. }