SysGlobalConfigModel.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. namespace App\Web\Models;
  3. use App\Models\BaseModel;
  4. use Illuminate\Support\Facades\DB;
  5. class SysGlobalConfigModel extends BaseModel
  6. {
  7. /**
  8. * 状态字段
  9. */
  10. const DELETED_AT = 'status';
  11. /**
  12. * @var string
  13. */
  14. protected $table = 'sys_global_config';
  15. /**
  16. * 获取全局配置列表
  17. * */
  18. public function getGlobalConfigList($params){
  19. $where=[];
  20. if(isset($params['status'])){
  21. $where[]=['a.status','=',$params['status']];
  22. }else{
  23. $where[]=['a.status','<',2];
  24. }
  25. $query= $this->newInstance()->alias('a')->where($where);
  26. $list= $query->selectRaw('a.*')
  27. ->orderBy('id')
  28. ->get();
  29. if(!empty($list)){
  30. $list=$list->toArray();
  31. }else{
  32. $list=[];
  33. }
  34. return $list;
  35. }
  36. /**
  37. * 文章全局配置数据保存
  38. * @param array $data
  39. * */
  40. public function saveGlobalConfigData($data){
  41. if (!empty($data['id'])) {
  42. $id = $data['id'];
  43. $this->newInstance()->where('id', $data['id'])->update($data);
  44. } else {
  45. $id = $this->newInstance()->insertGetId($data);
  46. }
  47. return $id;
  48. }
  49. /**
  50. * 获取全局配置详情
  51. * @param array $params
  52. * */
  53. public function getGlobalConfigInfo($params=[]){
  54. if(empty($params)){
  55. return [];
  56. }
  57. $where=[];
  58. $where[]=['status','<',2];
  59. if(!empty($params['id'])){
  60. $where['id']=$params['id'];
  61. }
  62. if(!empty($params['global_key'])){
  63. $where['global_key']=$params['global_key'];
  64. }
  65. $info= $this->newInstance()->where($where)->first();
  66. if(!empty($info)){
  67. return $info->toArray();
  68. }else{
  69. return [];
  70. }
  71. }
  72. /**
  73. * 检查 global_key是否唯一
  74. * */
  75. public function checkGlobalKeyUnique($globalKey,$id=0){
  76. $where=[];
  77. if(!empty($id)){
  78. $where[]=['id', '<>', $id];
  79. }
  80. $where[]=['status', '<', 2];
  81. $where[]=['global_key', '=', trim($globalKey)];
  82. return $this->checkFieldUnique('global_key',$where);
  83. }
  84. }