yingzi 1 vuosi sitten
vanhempi
commit
a07a55d228
2 muutettua tiedostoa jossa 36 lisäystä ja 16 poistoa
  1. 4 15
      app/api/controller/Pub.php
  2. 32 1
      app/model/api/ServiceTimeType.php

+ 4 - 15
app/api/controller/Pub.php

@@ -226,21 +226,10 @@ class Pub extends BaseController
             ['pageSize', 50],
         ], $request);
         $post["pageSize"] = $post["pageSize"]>50 ? 50 : (int)$post["pageSize"];
-        $post["page"]     = $post["page"]<=0 ? 1 : (int)$post["page"];
-        $where=[];
-        $where[]=["status","=",1];
-        $totalCount = (new ServiceTimeType)->where($where)->count();
-        $data=null;
-        if($totalCount>0){
-            $data = (new ServiceTimeType)
-                ->field("title,code")
-                ->where($where)
-                ->order("id", "asc")
-                ->page($post["page"], $post["pageSize"])
-                ->select();
-        }
-        $data = empty($data)?[]:$data;
-        return app('json')->success(["list" => $data, "pageSize" => $post["pageSize"],"page"=>$post["page"],"totalCount"=>$totalCount]);
+        $post["page"]     = $post["page"]<=0     ? 1  : (int)$post["page"];
+        $post["status"]   = 1;
+        $data = (new ServiceTimeType)->getList($post,"title,code");
+        return app('json')->success($data);
     }
     
     

+ 32 - 1
app/model/api/ServiceTimeType.php

@@ -10,5 +10,36 @@ use think\Model;
  */
 class ServiceTimeType extends Model
 {
-    //
+    /**
+     * 获取列表
+     * @param type $post
+     * @param type $field
+     * @return type
+     */
+    public function getList($post,$field="*"){
+        $post["pageSize"] = $post["pageSize"]>50 ? 50 : (int)$post["pageSize"];
+        $post["page"]     = $post["page"]<=0     ? 1  : (int)$post["page"];
+        $where=[];
+        if(isset($post["status"]) && in_array((string)$post["status"], ["0","1"])){
+            $where[]=["status","=",(int)$post["status"]];
+        }
+        if(!empty($post["title"])){
+            $where[]=["title","like","%{$post["title"]}%"];
+        }
+        $totalCount = $this->where($where)->count();
+        $data=null;
+        if($totalCount>0){
+            $data = $this
+                ->field($field)
+                ->where($where)
+                ->order("seq", "desc")
+                ->page($post["page"], $post["pageSize"])
+                ->select();
+            if(!empty($data)){
+                $data = $data->toArray();
+            }
+        }
+        $data = empty($data)?[]:$data;
+        return ["list" => $data, "pageSize" => $post["pageSize"],"page"=>$post["page"],"totalCount"=>$totalCount];
+    }
 }