Config.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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);
  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 getConfigData($fields, $flag = 1)
  44. {
  45. if (!empty($fields)) {
  46. $list = Config::whereIn('field',$fields)->select();
  47. } else {
  48. $list = Config::where('flag',$flag)->whereIn('field',$fields)->select();
  49. }
  50. $data = [];
  51. foreach ($list as $item) {
  52. $data[$item['field']] = $item['val'];
  53. }
  54. return $data;
  55. }
  56. //获取客服接线数量的上限配置
  57. public function getKefuChatMax()
  58. {
  59. //先从缓存中读取config表获取客服接线数量的上限配置
  60. $kefu_chat_max = cache('config_kefu_chat_max');
  61. if ($kefu_chat_max) {
  62. return $kefu_chat_max;
  63. }
  64. $config = Config::whereIn('field',['kefu_chat_max'])->column('val', 'field');
  65. cache('config_kefu_chat_max', $config['kefu_chat_max'] ?? 0);
  66. return $config['kefu_chat_max'] ?? 0;
  67. }
  68. }