Upsource.php 1.6 KB

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