Config.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. namespace app\admin\model;
  3. use app\BaseModel;
  4. use think\facade\Lang;
  5. class Config extends BaseModel
  6. {
  7. protected $autoWriteTimestamp = true;
  8. protected $createTime = 'created_at';
  9. protected $updateTime = 'updated_at';
  10. // protected $json = ['val'];
  11. // protected $jsonAssoc = true;
  12. public static function getSelect($language_code, $select = true) {
  13. Lang::setLangSet($language_code);
  14. $data = [
  15. 'kefu_chat_type' => [
  16. '1' => Lang::get('顺序分配')
  17. ],
  18. 'user_vip_level' => [
  19. '1' => '1',
  20. '2' => '2',
  21. '3' => '3',
  22. '4' => '4',
  23. '5' => '5',
  24. '6' => '6',
  25. '7' => '7',
  26. '8' => '8',
  27. '9' => '9',
  28. ]
  29. ];
  30. if ($select) {
  31. foreach ($data as &$item) {
  32. $item = getSelectData($item,'value', 'label', 1);
  33. }
  34. }
  35. return $data;
  36. }
  37. //字段val如果是json格式,转换为数组
  38. // public function getValAttribute($value)
  39. // {
  40. // return $value ? json_decode($value, true) : '';
  41. // }
  42. //获取指定配置的数据
  43. public static function getFieldValue($field, $language_code = '')
  44. {
  45. $where['field'] = $field;
  46. if($language_code){
  47. $where['language_code'] = $language_code;
  48. }
  49. $config = self::where($where)->find();
  50. if (!empty($config['type']) && $config['type'] == 'rich_text') {
  51. return $config['val'] ? json_decode($config['val'], true) : '';
  52. }
  53. return $config['val'];
  54. }
  55. //获取配置数据
  56. public static function getConfigData($fields, $flag = 1)
  57. {
  58. if (!empty($fields)) {
  59. $list = Config::whereIn('field',$fields)->select();
  60. } else {
  61. $list = Config::where('flag',$flag)->whereIn('field',$fields)->select();
  62. }
  63. $data = [];
  64. foreach ($list as $item) {
  65. if ($item['type'] == 'rich_text') {
  66. $item['val'] = $item['val'] ? json_decode($item['val'], true) : '';
  67. }
  68. $data[$item['field']] = $item['val'];
  69. }
  70. return $data;
  71. }
  72. //获取客服接线数量的上限配置
  73. public static function getKefuChatMax()
  74. {
  75. //先从缓存中读取config表获取客服接线数量的上限配置
  76. $kefu_chat_max = cache('config_kefu_chat_max');
  77. if ($kefu_chat_max) {
  78. return $kefu_chat_max;
  79. }
  80. $kefu_chat_max = (int)Config::where('field','kefu_chat_max')->value('val');
  81. $kefu_chat_max = $kefu_chat_max ? $kefu_chat_max : 1;
  82. cache('config_kefu_chat_max', $kefu_chat_max);
  83. return $kefu_chat_max;
  84. }
  85. }