Upsource.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. $where[]=["is_del","=",0];
  28. if(isset($post["status"]) && in_array((string)$post["status"], ["0","1"])){
  29. $where[]=["status","=",(int)$post["status"]];
  30. }
  31. if(!empty($post["title"])){
  32. $where[]=["title","like","%{$post["title"]}%"];
  33. }
  34. if(!empty($post["type"])){
  35. $where[]=["type","=",$post["type"]];
  36. }
  37. $totalCount = $this->where($where)->count();
  38. $data=null;
  39. if($totalCount>0){
  40. $data = $this
  41. ->field($field)
  42. ->where($where)
  43. ->order("id", "desc")
  44. ->page($post["page"], $post["pageSize"])
  45. ->select();
  46. if(!empty($data)){
  47. $data = $data->toArray();
  48. }
  49. }
  50. $data = empty($data)?[]:$data;
  51. foreach($data as $k=>$v){
  52. $data[$k]["time"] = date("Y-m-d H:i:s",$v["time"]);
  53. }
  54. return ["list" => $data, "pageSize" => $post["pageSize"],"page"=>$post["page"],"totalCount"=>$totalCount];
  55. }
  56. public function saveData(){
  57. }
  58. public function delData(){
  59. }
  60. }