yingzi 2 years ago
parent
commit
5bb3b07408
3 changed files with 129 additions and 60 deletions
  1. 9 9
      app/model/api/InfoAudit.php
  2. 103 1
      app/model/api/TypeAudit.php
  3. 17 50
      app/system/controller/Audit.php

+ 9 - 9
app/model/api/InfoAudit.php

@@ -25,30 +25,30 @@ class InfoAudit extends Model
         $post["page"]     = $post["page"]<=0     ? 1  : (int)$post["page"];
         $where=[];
         if(is_numeric($post['status'])) {
-            $where[]=["t.status","=",(int)$post['status']];
+            $where[]=["au.status","=",(int)$post['status']];
         }
         if(is_numeric($post['uid']) && $post['uid']>0) {
-            $where[]=["t.uid","=",(int)$post['uid']];
+            $where[]=["au.uid","=",(int)$post['uid']];
         }else if(is_mobile($post['user_mobile'])){
             $udata = (new UserModel)->where("mobile",$post['user_mobile'])->find();
             if(!empty($udata)){
-                $where[]=["t.uid","=",(int)$udata['uid']];
+                $where[]=["au.uid","=",(int)$udata['uid']];
             }
         }
         if(is_mobile($post['mobile'])) {
-            $where[]=["t.mobile","=",$post['mobile']];
+            $where[]=["au.mobile","=",$post['mobile']];
         }
         $startTime = "";
         $endTime = "";
         if(!empty($post['time'][0]) && !empty($post['time'][1])) {
            $startTime =  strtotime($post['time'][0]);
            $endTime = strtotime($post['time'][1]);
-           $where[]=["t.time","between","{$startTime},{$endTime}"];
+           $where[]=["au.time","between","{$startTime},{$endTime}"];
         }
         if(!empty($post['keyword'])){
-            $where[]=["t.name","=",$post['keyword']];
+            $where[]=["au.name","=",$post['keyword']];
         }
-        $pageCount = (new InfoAudit)->alias("au")->where($where)->count();
+        $pageCount = $this->alias("au")->where($where)->count();
         $data = null;
         if($pageCount>0){
             $userField = $is_admin==1 ? ",u.mobile as user_mobile,u.nickname as user_nickname,u.avatar as user_avatar,a.name as admin_name" : "";
@@ -103,7 +103,7 @@ class InfoAudit extends Model
             return [];
         }
         $where=[];
-        if(isset($post["status"]) && in_array((string)$post["status"], ["0","1"])){
+        if(isset($post["status"]) && in_array((string)$post["status"], ["0","1","-1"])){
             $where[]=["au.status","=",(int)$post["status"]];
         }
         if(!empty($post["id"])){
@@ -114,7 +114,7 @@ class InfoAudit extends Model
         }
         //后台
         $userField = $is_admin==1 ? ",u.mobile as user_mobile,u.nickname as user_nickname,u.avatar as user_avatar,a.name as admin_name" : "";
-        $data = (new InfoAudit)
+        $data = $this
                 ->alias("au")
                 ->field("au.*,wt.title as user_work_type_title,s.title as service_time_type_title{$userField}")
                 ->leftJoin("user u"              ,"u.uid = au.uid")//用户信息

+ 103 - 1
app/model/api/TypeAudit.php

@@ -10,5 +10,107 @@ use think\Model;
  */
 class TypeAudit extends Model
 {
-    //
+    /**
+     * 获取列表
+     * @param type $post
+     * @param type $is_admin
+     */
+    public function getList($post,$is_admin=0){
+        $post["pageSize"] = $post["pageSize"]>50 ? 50 : (int)$post["pageSize"];
+        $post["page"]     = $post["page"]<=0     ? 1  : (int)$post["page"];
+        $where=[];
+        if(is_numeric($post['status'])) {
+            $where[]=["au.status","=",(int)$post['status']];
+        }
+        if(is_numeric($post['uid']) && $post['uid']>0) {
+            $where[]=["au.uid","=",(int)$post['uid']];
+        }else if(is_mobile($post['user_mobile'])){
+            $udata = (new UserModel)->where("mobile",$post['user_mobile'])->find();
+            if(!empty($udata)){
+                $where[]=["au.uid","=",(int)$udata['uid']];
+            }
+        }
+//        if(is_mobile($post['mobile'])) {
+//            $where[]=["au.mobile","=",$post['mobile']];
+//        }
+        $startTime = "";
+        $endTime = "";
+        if(!empty($post['time'][0]) && !empty($post['time'][1])) {
+           $startTime =  strtotime($post['time'][0]);
+           $endTime = strtotime($post['time'][1]);
+           $where[]=["au.time","between","{$startTime},{$endTime}"];
+        }
+//        if(!empty($post['keyword'])){
+//            $where[]=["au.name","=",$post['keyword']];
+//        }
+        $pageCount = $this->alias("au")->where($where)->count();
+        $data = null;
+        if($pageCount>0){
+            $userField = $is_admin==1 ? ",u.mobile as user_mobile,u.nickname as user_nickname,u.avatar as user_avatar,a.name as admin_name" : "";
+            $data = $this
+                ->alias("au")
+                ->field("au.*{$userField}")
+                ->leftJoin("user u"          , "u.uid  = au.uid")//用户信息
+                ->leftJoin("admin a"         , "a.id   = au.admin_id")//管理员
+                ->where($where)
+                ->order("au.id","desc")
+                ->page((int)$post["page"], $post["pageSize"])
+                ->select()
+                ->toArray();
+        }
+        $data = empty($data) ? [] : $data;
+        $serviceTypeModel = new ServiceTypeModel();
+        foreach($data as $k=>$v){
+            $data[$k]["time"]               = date("Y-m-d H:i:s",$data[$k]["time"]);//添加时间
+            $data[$k]["service_audit_imgs"] = getImageAr($data[$k]["service_audit_imgs"]);//认证图片
+            $data[$k]["admin_time"] = empty($data[$k]["admin_time"])?"":date("Y-m-d H:i:s",$data[$k]["admin_time"]);
+        }
+        return ["list" => $data, "pageSize" => $post["pageSize"],"page"=>$post["page"],"totalCount"=>$pageCount];
+    }
+    /**
+     * 
+     * @param type $id
+     * @param type $type
+     */
+    public function getItem($post,$is_admin=0){
+        if(empty($post)){
+            return [];
+        }
+        $where=[];
+        if(isset($post["status"]) && in_array((string)$post["status"], ["0","1","-1"])){
+            $where[]=["au.status","=",(int)$post["status"]];
+        }
+        if(!empty($post["id"])){
+            $where[]=["au.id","=",$post["id"]];
+        }
+        if(!empty($post["uid"])){
+            $where[]=["au.uid","=",$post["uid"]];
+        }
+        //后台
+        $userField = $is_admin==1 ? ",u.mobile as user_mobile,u.nickname as user_nickname,u.avatar as user_avatar,a.name as admin_name" : "";
+        $data = $this
+                ->alias("au")
+                ->field("au.*{$userField}")
+                ->leftJoin("user u"              ,"u.uid = au.uid")//用户信息
+                ->leftJoin("admin a"             , "a.id = au.admin_id")//管理员
+                ->where($where)
+                ->order("au.id","desc")
+                ->find();
+        if(empty($data)){
+            return [];
+        }
+        $data = $data->toArray();
+        $data["time"]               = date("Y-m-d H:i:s",$data["time"]);//添加时间
+        $data["service_audit_imgs"] = getImageAr($data["service_audit_imgs"]);//我的证书
+        if($is_admin==0){
+            unset($data["admin_id"]);
+            unset($data["admin_mono"]);
+            unset($data["admin_time"]);
+            unset($data["uid"]);
+        }else{
+            $data["admin_time"] = empty($data["admin_time"])?"":date("Y-m-d H:i:s",$data["admin_time"]);
+        }
+        return $data;
+        
+    }
 }

+ 17 - 50
app/system/controller/Audit.php

@@ -153,7 +153,14 @@ class Audit extends BaseController
      * @param Request $request
      */
     public function typeAuditInfo(Request $request){
-        
+        $post = UtilService::getMore([
+            ['id', '', 'empty', '参数错误'],
+        ], $request);
+        $data = (new TypeAudit)->getItem($post,1);
+        if(empty($data)){
+            return app('json')->fail('数据不存在');
+        }
+        return app('json')->success($data);
     }
 
     /**
@@ -162,65 +169,25 @@ class Audit extends BaseController
      */
     public function typeAuditList(Request $request)
     {
-        $pageSize = 50;
         $post     = UtilService::getMore(
             [
                 ['page', 1],
+                ['pageSize', 50],
                 ['keyword',''],
-                ['status', ''],
+                ['mobile',''],
                 ['user_mobile',''],
+                ['status', ''],
                 ['uid', ''],
                 ['time',[]],
             ], $request
         );
-        $where    = [];
-        if(is_numeric($post['status'])) {
-            $where[]=["t.status","=",(int)$post['status']];
-        }
-        if(is_numeric($post['uid']) && $post['uid']>0) {
-            $where[]=["t.uid","=",(int)$post['uid']];
-        }else if(is_mobile($post['user_mobile'])){
-            $udata = (new UserModel)->where("mobile",$post['user_mobile'])->find();
-            if(!empty($udata)){
-                $where[]=["t.uid","=",(int)$udata['uid']];
-            }
-        }
-        $startTime = "";
-        $endTime = "";
-        if(!empty($post['time'][0]) && !empty($post['time'][1])) {
-           $startTime =  strtotime($post['time'][0]);
-           $endTime = strtotime($post['time'][1]);
-           $where[]=["t.time","between","{$startTime},{$endTime}"];
-        }
-        if(!empty($post['keyword'])){
-            $where[]=["t.name","=",$post['keyword']];
-        }
-        $pageCount = (new TypeAudit)->alias("t")->where($where)->count();
-        $data = null;
-        if($pageCount>0){
-            $data = (new TypeAudit)
-                ->alias("t")
-                ->field("t.*,u.nickname,a.username as admin_name")
-                ->leftJoin("user u", "u.uid = t.uid")
-                ->leftJoin("admin a", "a.id = t.admin_id")
-                ->where($where)
-                ->page((int)$post["page"], $pageSize)
-                ->order("t.id","desc")
-                ->select()
-                ->toArray();
-        }
-        $data = empty($data) ? [] : $data;
-        $serviceTypeModel = new ServiceTypeModel();
-        foreach($data as $k=>$v){
-            $data[$k]["admin_time"] = empty($v["admin_time"])?"":date("Y-m-d H:i:s",$v["admin_time"]);
-            $data[$k]["time"]   = date("Y-m-d H:i:s",$v["time"]);
-            $data[$k]["service_audit_imgs"] = getImageAr($v["service_audit_imgs"]);
-        }
+        
+        $data = (new TypeAudit)->getList($post,1);
         return app('json')->success([
-            'list'      => $data,
-            'pageCount' => $pageCount,
-            'pageSize'  => $pageSize,
-            'page'      => $post['page'],
+            'list'      => $data["list"],
+            'pageCount' => $data["totalCount"],
+            'pageSize'  => $data["pageSize"],
+            'page'      => $data["page"],
         ]);
     }
     /**