DictFunctionModel.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <?php
  2. namespace App\Web\Models;
  3. use App\Models\BaseModel;
  4. class DictFunctionModel extends BaseModel
  5. {
  6. /**
  7. * 状态字段
  8. */
  9. const DELETED_AT = 'status';
  10. /**
  11. * @var string
  12. */
  13. protected $table = 'dict_function';
  14. /**
  15. * 获取功能列表
  16. * */
  17. public function getFunctionList($params,$fields=''){
  18. if (empty($fields)) {
  19. $fields = 'a.*';
  20. }
  21. list($pageSize, $page, $skip) = $this->getPaginatorParams($params);
  22. $where=[];
  23. if(isset($params['status'])){
  24. $where[]=['a.status','=',$params['status']];
  25. }else{
  26. $where[]=['a.status','<',2];
  27. }
  28. $query= $this->newInstance()->alias('a')->where($where);
  29. if (!empty($params['keyword'])) {
  30. $keyword = $params['keyword'];
  31. $query->where('a.name', 'like', "%" . $keyword . "%");
  32. }
  33. $totalCount = $query->count();
  34. $list= $query->skip($skip)
  35. ->limit($pageSize)
  36. ->selectRaw($fields)
  37. ->get();
  38. if(!empty($list)){
  39. $list=$list->toArray();
  40. }else{
  41. $list=[];
  42. }
  43. $result = $this->buildPaginator($list, $skip, $page, $pageSize, $totalCount);
  44. return $result;
  45. }
  46. /**
  47. * 功能保存
  48. * @param array $data
  49. * */
  50. public function saveFunctionData($data){
  51. if (!empty($data['id'])) {
  52. $id = $data['id'];
  53. $this->newInstance()->where('id', $data['id'])->update($data);
  54. } else {
  55. $id = $this->newInstance()->insertGetId($data);
  56. }
  57. return $id;
  58. }
  59. /**
  60. * 检查 名称是否唯一
  61. * */
  62. public function checkFunctionNameUnique($name,$id=0){
  63. $where=[];
  64. if(!empty($id)){
  65. $where[]=['id', '<>', $id];
  66. }
  67. $where[]=['status', '<', 2];
  68. $where[]=['name', '=', trim($name)];
  69. return $this->checkFieldUnique('name',$where);
  70. }
  71. /**
  72. * 获取功能详情
  73. * @param array $params
  74. * */
  75. public function getFunctionInfo($params=[]){
  76. if(empty($params)){
  77. return [];
  78. }
  79. $where=[];
  80. $where[]=['status','<',2];
  81. if(!empty($params['id'])){
  82. $where['id']=$params['id'];
  83. }
  84. $info= $this->newInstance()->where($where)->first();
  85. if(!empty($info)){
  86. return $info->toArray();
  87. }else{
  88. return [];
  89. }
  90. }
  91. /**
  92. * 获取标签基本列表
  93. * */
  94. public function getBaseFunctionList($params,$fields='a.*'){
  95. $where=[];
  96. $where['a.status']=0;
  97. $query= $this->newInstance()->alias('a')
  98. ->where($where);
  99. $pageSize = $this->getPageSize($params);
  100. $list= $query->limit($pageSize)
  101. ->selectRaw($fields)
  102. ->get();
  103. if(!empty($list)){
  104. $list=$list->toArray();
  105. }else{
  106. $list=[];
  107. }
  108. return $list;
  109. }
  110. }