ServiceLabel.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\model\api;
  4. use think\Model;
  5. /**
  6. * @mixin \think\Model
  7. */
  8. class ServiceLabel extends Model
  9. {
  10. /**
  11. * 获取标签列表
  12. * @param type $post
  13. * @param type $field
  14. * @return type
  15. */
  16. public function getList($post,$field="*"){
  17. $post["pageSize"] = $post["pageSize"]>50 ? 50 : (int)$post["pageSize"];
  18. $post["page"] = $post["page"]<=0 ? 1 : (int)$post["page"];
  19. $where=[];
  20. if(isset($post["status"]) && in_array((string)$post["status"], ["0","1"])){
  21. $where[]=["status","=",(int)$post["status"]];
  22. }
  23. if(!empty($post["title"])){
  24. $where[]=["title","like","%{$post["title"]}%"];
  25. }
  26. $totalCount = $this->where($where)->count();
  27. $data=null;
  28. if($totalCount>0){
  29. $data = $this
  30. ->field($field)
  31. ->where($where)
  32. ->order("seq", "desc")
  33. ->page($post["page"], $post["pageSize"])
  34. ->select();
  35. if(!empty($data)){
  36. $data = $data->toArray();
  37. }
  38. }
  39. $data = empty($data)?[]:$data;
  40. return ["list" => $data, "pageSize" => $post["pageSize"],"page"=>$post["page"],"totalCount"=>$totalCount];
  41. }
  42. public function getColumnList($field="id",$value="id",$in=[]){
  43. if(empty($in)){
  44. return [];
  45. }
  46. if(is_string($in)){
  47. $in = explode(",", $in);
  48. }
  49. $labelData = $this
  50. ->where("status",1)
  51. ->where($field,"in",$in)
  52. ->column($value);
  53. $labelData = empty($labelData)?[]:$labelData;
  54. return $labelData;
  55. }
  56. }