zgg vor 11 Stunden
Ursprung
Commit
6cf3d2e13e

+ 1 - 1
application/admin/controller/EnergyGasRecord.php

@@ -227,6 +227,6 @@ class EnergyGasRecord extends Auth
         }
         $res = Db::name('energy_gas_record')->whereIn('id', $ids)->update(['del'=>1]);
         if (!$res) $this->error('批量删除失败');
-        $this->success('批量删除传成功');
+        $this->success('批量删除成功');
     }
 }

+ 195 - 0
application/admin/controller/PatrolPlan.php

@@ -248,6 +248,106 @@ class PatrolPlan extends Auth
     }
 
     /**
+     * 批量关闭巡查计划
+     * @param string $ids 计划ID,多个用逗号分隔,如 "1,2,3"
+     */
+    public function multiClose(){
+        $ids = input('ids', [], 'trim');
+        if(empty($ids)){
+            $this->error('参数错误');
+        }
+
+
+        // 2. 批量查询计划
+        $list = Db::name('patrol_plan')
+            ->field('id,title')
+            ->where('org_id',$this->orgId)
+            ->where('id','in',$ids)
+            ->where('del',0)
+            ->select();
+
+        if(!$list){
+            $this->error('计划不存在');
+        }
+
+        $validIds    = [];
+        $errorMsgs   = [];
+        foreach($list as $info){
+            if($info['close'] == 1){
+                $errorMsgs[] = "计划:[{$info['title']}]已关闭";
+                continue;
+            }
+            if($info['status'] == 2){
+                $errorMsgs[] = "计划:[{$info['title']}]已结束";
+                continue;
+            }
+            $validIds[] = $info['id'];
+        }
+
+        if(empty($validIds)){
+            $this->error(implode(';', $errorMsgs) ?: '没有可关闭的计划');
+        }
+
+        // 4. 事务处理
+        Db::startTrans();
+        try{
+            $now = getTime();
+
+            // 4.1 批量更新计划状态
+            $res = Db::name('patrol_plan')
+                ->where('org_id',$this->orgId)
+                ->where('id','in',$validIds)
+                ->update([
+                    'status'         => 2,
+                    'close'          => 1,
+                    'close_user_id'  => $this->userId,
+                    'close_time'     => $now,
+                ]);
+
+            if($res === false){
+                throw new \Exception('操作失败');
+            }
+
+            // 4.2 批量关闭任务(待执行/执行中)
+            Db::name('patrol_task')
+                ->where('del',0)
+                ->where('plan_id','in',$validIds)
+                ->where('status','in',[0,1])
+                ->update([
+                    'status'      => 6,
+                    'update_time' => $now,
+                ]);
+
+            // 4.3 查询已加入的任务ID(注意:要针对所有相关任务,不能只查状态为0/1的)
+            $taskIds = Db::name('patrol_task')
+                ->where('del',0)
+                ->where('plan_id','in',$validIds)
+                ->column('id');
+
+            // 4.4 批量删除关联任务
+            if($taskIds){
+                Db::name('task')
+                    ->where('org_id',$this->orgId)
+                    ->where('type',2)
+                    ->where('bus_id','in',$taskIds)
+                    ->delete();
+            }
+
+            Db::commit();
+        }catch (\Exception $e){
+            Db::rollback();
+            $this->error('操作失败:' . $e->getMessage());
+        }
+
+        // 5. 返回结果
+        $msg = '操作成功';
+        if($errorMsgs){
+            $msg .= ';部分计划未处理:' . implode(';', $errorMsgs);
+        }
+        $this->success($msg);
+    }
+
+    /**
      * 删除计划
      */
     public function del($id=0){
@@ -301,6 +401,101 @@ class PatrolPlan extends Auth
         $this->success('操作成功');
     }
 
+
+    /**
+     * 批量删除巡查计划
+     * @param string $ids 计划ID,多个用逗号分隔,如 "1,2,3"
+     */
+    public function multiDel(){
+        $ids = input('ids', [], 'trim');
+        if(empty($ids)){
+            $this->error('参数错误');
+        }
+
+        $list = Db::name('patrol_plan')
+            ->field('id,title')
+            ->where('org_id',$this->orgId)
+            ->where('id','in',$ids)
+            ->where('del',0)
+            ->select();
+
+        if(!$list){
+            $this->error('计划不存在');
+        }
+
+        // 3. 逐条校验状态,收集可删除的ID
+        $validIds  = [];
+        $errorMsgs = [];
+        foreach($list as $info){
+            if($info['status'] != 2){
+                $errorMsgs[] = "计划:[{$info['title']}]未结束";
+                continue;
+            }
+            $validIds[] = $info['id'];
+        }
+
+        if(empty($validIds)){
+            $this->error(implode(';', $errorMsgs) ?: '没有可删除的计划');
+        }
+
+        // 4. 事务处理
+        Db::startTrans();
+        try{
+            $now = getTime();
+
+            // 4.1 批量软删除计划
+            $res = Db::name('patrol_plan')
+                ->where('org_id',$this->orgId)
+                ->where('id','in',$validIds)
+                ->update([
+                    'del'         => 1,
+                    'del_user_id' => $this->userId,
+                    'del_time'    => $now,
+                ]);
+
+            if($res === false){
+                throw new \Exception('操作失败');
+            }
+
+            // 4.2 查询关联的任务ID
+            $taskIds = Db::name('patrol_task')
+                ->where('del',0)
+                ->where('plan_id','in',$validIds)
+                ->column('id');
+
+            // 4.3 批量删除已加入的任务
+            if($taskIds){
+                Db::name('task')
+                    ->where('org_id',$this->orgId)
+                    ->where('type',2)
+                    ->where('bus_id','in',$taskIds)
+                    ->delete();
+            }
+
+            // 4.4 批量软删除任务
+            Db::name('patrol_task')
+                ->where('del',0)
+                ->where('plan_id','in',$validIds)
+                ->update([
+                    'del'         => 1,
+                    'del_user_id' => $this->userId,
+                    'del_time'    => $now,
+                ]);
+
+            Db::commit();
+        }catch (\Exception $e){
+            Db::rollback();
+            $this->error('操作失败:' . $e->getMessage());
+        }
+
+        // 5. 返回结果
+        $msg = '操作成功';
+        if($errorMsgs){
+            $msg .= ';部分计划未处理:' . implode(';', $errorMsgs);
+        }
+        $this->success($msg);
+    }
+
     public function info($id=0,$mode){
         $modeName = (new \app\common\model\PatrolAddrForm())->getModeTitle($mode);
         $meta_title=$modeName.'巡视轨迹';

+ 87 - 0
application/admin/controller/PatrolStatistics.php

@@ -180,6 +180,93 @@ class PatrolStatistics extends Auth {
             ->group('user_id')
             ->distinct(true)
             ->select();
+
+        $userIds = array_unique(array_column($list, 'user_id'));
+        $userIds = array_filter($userIds);
+
+        // 一次性取出姓名(原循环内逐条查询 -> 1 条)
+        $userNames = [];
+        if (!empty($userIds)) {
+            $userNames = Db::name('user')
+                ->whereIn('id', $userIds)
+                ->column('real_name', 'id');
+        }
+
+        // 一次性聚合每个用户的记录统计(原 3 次 count -> 1 条)
+        $recordStats = [];
+        if (!empty($userIds)) {
+            $rows = Db::name('patrol_record')
+                ->field([
+                    'user_id',
+                    'COUNT(*) as total',
+                    'SUM(CASE WHEN is_normal = 0 THEN 1 ELSE 0 END) as cnt0',
+                    'SUM(CASE WHEN is_normal = 1 THEN 1 ELSE 0 END) as cnt1'
+                ])
+                ->where($map1)
+                ->where('patrol_mode', $type)
+                ->whereIn('user_id', $userIds)
+                ->group('user_id')
+                ->select();
+            foreach ($rows as $row) {
+                $recordStats[$row['user_id']] = $row;
+            }
+        }
+
+        // 一次性聚合每个用户的任务统计(原 2 次 join count -> 1 条)
+        $taskStats = [];
+        if (!empty($userIds)) {
+            $rows = Db::name('patrol_task_user')
+                ->alias('a')
+                ->join('patrol_task b', 'a.patrol_task_id=b.id')
+                ->field([
+                    'a.user_id',
+                    'COUNT(*) as task_total',
+                    'SUM(CASE WHEN b.status = 2 THEN 1 ELSE 0 END) as task_done'
+                ])
+                ->where('a.user_id', 'in', $userIds)
+                ->where('b.org_id', $this->orgId)
+                ->where('b.status', '<>', 6)
+                ->where('b.start_time', '>=', $start1)
+                ->where('b.end_time', '<=', $end1)
+                ->where('b.patrol_mode', '=', $type)
+                ->group('a.user_id')
+                ->select();
+            foreach ($rows as $row) {
+                $taskStats[$row['user_id']] = $row;
+            }
+        }
+
+        foreach ($list as $k => $v) {
+            $uid = $v['user_id'];
+            $list[$k]['title'] = $userNames[$uid] ?? '';
+
+            $rs = $recordStats[$uid] ?? null;
+            $list[$k]['count']  = $rs ? (int)$rs['total'] : 0; // 总数
+            $list[$k]['count1'] = $rs ? (int)$rs['cnt0']   : 0; // 异常(is_normal=0)
+            $list[$k]['count2'] = $rs ? (int)$rs['cnt1']   : 0; // 正常(is_normal=1)
+
+            $ts = $taskStats[$uid] ?? null;
+            $taskCount = $ts ? (int)$ts['task_total'] : 0; // 需要完成(status<>6)
+            $ywcCount  = $ts ? (int)$ts['task_done']  : 0; // 已完成(status=2)
+
+            $wcl = $taskCount > 0 ? round($ywcCount / $taskCount, 2) * 100 : 0;
+            $wcl = $wcl . '%';
+            $list[$k]['wcl'] = $wcl;
+            $list[$k]['count3'] = $ywcCount;
+            $list[$k]['count4'] = $taskCount;
+        }
+        return $list;
+    }
+    public function workDataOld($start1, $end1, $type) {
+        $map1[] = ['create_time', '>=', $start1];
+        $map1[] = ['create_time', '<=', $end1];
+        $map1[] = ['org_id', '=', $this->orgId];
+        $list = Db::name('patrol_record')
+            ->where($map1)
+            ->where('patrol_mode', $type)
+            ->group('user_id')
+            ->distinct(true)
+            ->select();
         foreach ($list as $k => $v) {
             $list[$k]['title'] = Db::name('user')
                 ->where('id', $v['user_id'])

+ 153 - 0
application/admin/controller/PatrolTask.php

@@ -240,6 +240,84 @@ class PatrolTask extends Auth
 
     }
 
+
+    /**
+     * 批量删除巡查任务
+     * @param string $ids 任务ID,多个用逗号分隔,如 "1,2,3"
+     */
+    public function multiDel(){
+        $ids = input('ids', [], 'trim');
+        // 1. 参数处理与校验
+        if(empty($ids)){
+            $this->error('参数错误');
+        }
+
+        // 2. 批量查询任务
+        $list = Db::name('patrol_task')
+            ->field('id,title')
+            ->where('org_id',$this->orgId)
+            ->where('id','in',$ids)
+            ->where('del',0)
+            ->select();
+
+        if(!$list){
+            $this->error('任务不存在');
+        }
+
+        // 3. 逐条校验状态,收集可删除的ID
+        $validIds  = [];
+        $errorMsgs = [];
+        foreach($list as $info){
+            if($info['status'] != 6){
+                $errorMsgs[] = "任务:[{$info['title']}]未关闭不可删除";
+                continue;
+            }
+            $validIds[] = $info['id'];
+        }
+
+        if(empty($validIds)){
+            $this->error(implode(';', $errorMsgs) ?: '没有可删除的任务');
+        }
+
+        // 4. 事务处理
+        Db::startTrans();
+        try{
+            $now = getTime();
+
+            // 4.1 批量软删除任务
+            $res = Db::name('patrol_task')
+                ->where('org_id',$this->orgId)
+                ->where('id','in',$validIds)
+                ->update([
+                    'del'         => 1,
+                    'del_user_id' => is_login(),
+                    'del_time'    => $now,
+                ]);
+
+            if($res === false){
+                throw new \Exception('操作失败');
+            }
+
+            // 4.2 批量删除任务栏中的关联任务
+            Db::name('task')
+                ->where('bus_id','in',$validIds)
+                ->where('type',2)
+                ->delete();
+
+            Db::commit();
+        }catch (\Exception $e){
+            Db::rollback();
+            $this->error('删除失败:' . $e->getMessage());
+        }
+
+        // 5. 返回结果
+        $msg = '删除成功';
+        if($errorMsgs){
+            $msg .= ';部分任务未处理:' . implode(';', $errorMsgs);
+        }
+        $this->success($msg);
+    }
+
     /**
      * 关闭记录
      */
@@ -275,6 +353,81 @@ class PatrolTask extends Auth
 
     }
 
+    /**
+     * 批量关闭巡查任务
+     * @param string $ids 任务ID,多个用逗号分隔,如 "1,2,3"
+     */
+    public function multiClose(){
+        $ids = input('ids', [], 'trim');
+        // 1. 参数处理与校验
+        if(empty($ids)){
+            $this->error('参数错误');
+        }
+
+        // 2. 批量查询任务
+        $list = Db::name('patrol_task')
+            ->field('id,title')
+            ->where('org_id',$this->orgId)
+            ->where('id','in',$ids)
+            ->where('del',0)
+            ->select();
+
+        if(!$list){
+            $this->error('任务不存在');
+        }
+
+        $validIds  = [];
+        $errorMsgs = [];
+        foreach($list as $info){
+            if($info['status'] == 6){
+                $errorMsgs[] = "任务:[{$info['title']}]已关闭";
+                continue;
+            }
+            $validIds[] = $info['id'];
+        }
+
+        if(empty($validIds)){
+            $this->error(implode(';', $errorMsgs) ?: '没有可关闭的任务');
+        }
+
+        // 4. 事务处理
+        Db::startTrans();
+        try{
+            $now = getTime();
+
+            // 4.1 批量更新任务状态
+            $res = Db::name('patrol_task')
+                ->where('org_id',$this->orgId)
+                ->where('id','in',$validIds)
+                ->update([
+                    'status'      => 6,
+                    'update_time' => $now,
+                ]);
+
+            if($res === false){
+                throw new \Exception('操作失败');
+            }
+
+            // 4.2 批量删除任务栏中的关联任务
+            Db::name('task')
+                ->where('bus_id','in',$validIds)
+                ->where('type',2)
+                ->delete();
+
+            Db::commit();
+        }catch (\Exception $e){
+            Db::rollback();
+            $this->error('操作失败:' . $e->getMessage());
+        }
+
+        // 5. 返回结果
+        $msg = '操作成功';
+        if($errorMsgs){
+            $msg .= ';部分任务未处理:' . implode(';', $errorMsgs);
+        }
+        $this->success($msg);
+    }
+
 
     public function info($id=0,$mode){
         $modeName = (new \app\common\model\PatrolAddrForm())->getModeTitle($mode);

+ 10 - 0
application/admin/controller/User.php

@@ -303,6 +303,16 @@ class User extends Auth
         }
     }
 
+    public function multiDel() {
+        $ids = input('ids', [], 'trim');
+        if (empty($ids)) {
+            $this->error('未选择用户');
+        }
+        $res = Db::name('user')->whereIn('id', $ids)->update(['del'=>1]);
+        if ($res === false) $this->error('批量删除失败');
+        $this->success('批量删除成功');
+    }
+
     /**
      * 改变字段值
      * @param int $fv

+ 74 - 0
application/admin/view/patrol_plan/index.html

@@ -6,6 +6,10 @@
         <div class="row">
             <div class="col-xs-3">
                 <a url="{:url('add',['mode'=>$mode])}" href="javascript:;" data-title="新增计划" onclick="layer_open(this,1)" class="btn btn-sm btn-primary">新增计划</a>
+                <a  href="javascript:;" id="close" class="btn btn-sm btn-danger">批量关闭</a>
+                {if btnAuth(session("user_auth.id"),"PatrolPlan/del?mode=$mode")}
+                <a  href="javascript:;" id="del" class="btn btn-sm btn-danger">批量删除</a>
+                {/if}
             </div>
             <div class="col-xs-9" style="text-align: right;">
                 <form class="form-inline" id="form-search" action="{:url('index',['mode'=>$mode])}">
@@ -114,6 +118,7 @@
             emptyrecords: "暂无数据",
             sortorder: "desc",
             caption:"{$meta_title}",
+            multiselect: true,//可多选
             loadComplete: function (xhr) {
                 if(xhr.code==0){
                     layer.msg(xhr.msg);
@@ -121,6 +126,75 @@
                 }
             },
         });
+        $('#close').click(function () {
+            var rowIds = jQuery("#table").jqGrid('getGridParam', 'selarrrow');    //获取勾选记录的ID
+            if(rowIds.length <=0){
+                updateAlert('请选择计划','alert-danger');
+                setTimeout(function(){
+                    $('#top-alert').find('button').click();
+                },1500);
+                return;
+            }
+
+            layer.confirm('确定批量关闭所选计划?', {
+                icon: 3,
+                btn: ['确定', '取消'],
+                skin: 'layer-ext-moon'
+            }, function(index) {
+                layer.close(layer.index);
+                $.post('{:url("multiClose")}',{ids:rowIds},function (res) {
+                    if(res.code==0){
+                        updateAlert(res.msg,'alert-danger');
+                        setTimeout(function(){
+                            $('#top-alert').find('button').click();
+                        },1500);
+                        // window.location.reload();
+                    }else {
+                        updateAlert(res.msg,'alert-success');
+                        setTimeout(function(){
+                            $('#top-alert').find('button').click();
+                            $("#table").trigger("reloadGrid");
+                        },1500);
+
+                    }
+                })
+            });
+        })
+
+        $('#del').click(function () {
+            var rowIds = jQuery("#table").jqGrid('getGridParam', 'selarrrow');    //获取勾选记录的ID
+            if(rowIds.length <=0){
+                updateAlert('请选择计划','alert-danger');
+                setTimeout(function(){
+                    $('#top-alert').find('button').click();
+                },1500);
+                return;
+            }
+
+            layer.confirm('确定批量删除所选计划?', {
+                icon: 3,
+                btn: ['确定', '取消'],
+                skin: 'layer-ext-moon'
+            }, function(index) {
+                layer.close(layer.index);
+                $.post('{:url("multiDel")}',{ids:rowIds},function (res) {
+                    if(res.code==0){
+                        updateAlert(res.msg,'alert-danger');
+                        setTimeout(function(){
+                            $('#top-alert').find('button').click();
+                        },1500);
+                        // window.location.reload();
+                    }else {
+                        updateAlert(res.msg,'alert-success');
+                        setTimeout(function(){
+                            $('#top-alert').find('button').click();
+                            $("#table").trigger("reloadGrid");
+                        },1500);
+
+                    }
+                })
+            });
+        })
     });
 </script>
 <script>

+ 73 - 0
application/admin/view/patrol_task/index.html

@@ -7,6 +7,8 @@
             <div class="col-xs-3">
                 <a href="{:url('calendar',['mode'=>$mode])}" class="btn btn-sm btn-warning">日历显示</a>
 <!--                <a href="{:url('add',[],'')}/id/0/mode/{$mode}" class="btn btn-sm btn-primary">新增</a>-->
+                <a  href="javascript:;" id="close" class="btn btn-sm btn-danger">批量关闭</a>
+                <a  href="javascript:;" id="del" class="btn btn-sm btn-danger">批量删除</a>
             </div>
             <div class="col-xs-9" style="text-align: right;">
                 <form class="form-inline" id="form-search" action="{:url('index',['mode'=>$mode])}">
@@ -174,6 +176,7 @@
             emptyrecords: "暂无数据",
             sortorder: "desc",
             caption:"{$meta_title}",
+            multiselect: true,//可多选
             loadComplete: function (xhr) {
                 if(xhr.code==0){
                     layer.msg(xhr.msg);
@@ -181,6 +184,76 @@
                 }
             },
         });
+
+        $('#close').click(function () {
+            var rowIds = jQuery("#table").jqGrid('getGridParam', 'selarrrow');    //获取勾选记录的ID
+            if(rowIds.length <=0){
+                updateAlert('请选择任务','alert-danger');
+                setTimeout(function(){
+                    $('#top-alert').find('button').click();
+                },1500);
+                return;
+            }
+
+            layer.confirm('确定批量关闭所选任务?', {
+                icon: 3,
+                btn: ['确定', '取消'],
+                skin: 'layer-ext-moon'
+            }, function(index) {
+                layer.close(layer.index);
+                $.post('{:url("multiClose")}',{ids:rowIds},function (res) {
+                    if(res.code==0){
+                        updateAlert(res.msg,'alert-danger');
+                        setTimeout(function(){
+                            $('#top-alert').find('button').click();
+                        },1500);
+                        // window.location.reload();
+                    }else {
+                        updateAlert(res.msg,'alert-success');
+                        setTimeout(function(){
+                            $('#top-alert').find('button').click();
+                            $("#table").trigger("reloadGrid");
+                        },1500);
+
+                    }
+                })
+            });
+        })
+
+        $('#del').click(function () {
+            var rowIds = jQuery("#table").jqGrid('getGridParam', 'selarrrow');    //获取勾选记录的ID
+            if(rowIds.length <=0){
+                updateAlert('请选择任务','alert-danger');
+                setTimeout(function(){
+                    $('#top-alert').find('button').click();
+                },1500);
+                return;
+            }
+
+            layer.confirm('确定批量删除所选任务?', {
+                icon: 3,
+                btn: ['确定', '取消'],
+                skin: 'layer-ext-moon'
+            }, function(index) {
+                layer.close(layer.index);
+                $.post('{:url("multiDel")}',{ids:rowIds},function (res) {
+                    if(res.code==0){
+                        updateAlert(res.msg,'alert-danger');
+                        setTimeout(function(){
+                            $('#top-alert').find('button').click();
+                        },1500);
+                        // window.location.reload();
+                    }else {
+                        updateAlert(res.msg,'alert-success');
+                        setTimeout(function(){
+                            $('#top-alert').find('button').click();
+                            $("#table").trigger("reloadGrid");
+                        },1500);
+
+                    }
+                })
+            });
+        })
     });
 </script>
 <script>

+ 35 - 1
application/admin/view/user/index.html

@@ -7,6 +7,7 @@
             <div class="col-xs-3">
                 <a href="javascript:;" url="{:url('add')}" data-title="新增用户" onclick="layer_open(this,1)" class="btn btn-sm btn-primary">新增</a>
                 <a href="javascript:;" onclick="batchSorts()" class="btn btn-sm btn-warning">保存排序</a>
+                <a  href="javascript:;" id="del" class="btn btn-sm btn-danger">批量删除</a>
             </div>
             <div class="col-xs-9" style="text-align: right;">
             <form class="form-inline" id="form-search" action="{:url('index')}">
@@ -135,6 +136,7 @@
             emptyrecords: "暂无数据",
             sortorder: "desc",
             caption:"用户列表",
+            multiselect: true,//可多选
             loadComplete: function (xhr) {
                 if(xhr.code==0){
                     layer.msg(xhr.msg);
@@ -143,10 +145,42 @@
             },
         });
 
+    });
 
+    $('#del').click(function () {
+        var rowIds = jQuery("#table").jqGrid('getGridParam', 'selarrrow');    //获取勾选记录的ID
+        if(rowIds.length <=0){
+            updateAlert('请选择用户','alert-danger');
+            setTimeout(function(){
+                $('#top-alert').find('button').click();
+            },1500);
+            return;
+        }
 
+        layer.confirm('确定批量删除所选用户?', {
+            icon: 3,
+            btn: ['确定', '取消'],
+            skin: 'layer-ext-moon'
+        }, function(index) {
+            layer.close(layer.index);
+            $.post('{:url("multiDel")}',{ids:rowIds},function (res) {
+                if(res.code==0){
+                    updateAlert(res.msg,'alert-danger');
+                    setTimeout(function(){
+                        $('#top-alert').find('button').click();
+                    },1500);
+                    // window.location.reload();
+                }else {
+                    updateAlert(res.msg,'alert-success');
+                    setTimeout(function(){
+                        $('#top-alert').find('button').click();
+                        $("#table").trigger("reloadGrid");
+                    },1500);
 
-    });
+                }
+            })
+        });
+    })
 
     function batchSorts() {
         let data = [];

+ 2 - 0
application/common/model/Orders.php

@@ -742,6 +742,7 @@ class Orders extends Base {
                 ->select();
             if (!empty($todo)) {
                 foreach ($todo as $k => $v1) {
+                    $todo[$k]['todo_content']= $v1['todo_content'] .','.$v['schedulContent'];
                     $todo[$k]['to_real_name'] = $this->getTableField('user', ['id' => $v1['to_user_id']], 'real_name');
                     $todo[$k]['todo_mode_text'] = $this->getTableField('todo_mode', ['id' => $v1['todo_mode']], 'in_content');
                     $tx = $this->getTableField('todo_mode', ['id' => $v1['todo_mode']], 'out_content');
@@ -2164,6 +2165,7 @@ class Orders extends Base {
                 ->field('a.id,a.addr,b.title,a.scan,a.create_time,a.update_time')
                 ->select();
             $info['ends'] = $conveyends?$conveyends:[];
+            $info['schedulContent'] = $info['schedulContent'].'——'.$info['ps'];
 
             $payinfo = [
                 'is_pay' => 0,

+ 64 - 26
application/h5/controller/Repair.php

@@ -226,7 +226,7 @@ class Repair extends Controller
             ->where('patrol_mode',4)
             ->where('patrol_addr_id',$addr['id'])
             ->order('id desc')
-            ->paginate(10,true)
+            ->paginate(10)
             ->each(function($item,$key){
                 $item['addrName'] = Db::name('address')->where('id',$item['patrol_addr_id'])->value('title');
                 $item['userName'] = Db::name('user')->where('id',$item['user_id'])->value('real_name');
@@ -250,38 +250,76 @@ class Repair extends Controller
                 $item['statusTxt'] = $statusTxt;
                 return $item;
             });
-        $page = $list->render();
-//        foreach ($list as $k=>$v){
-//            $list[$k]['addrName'] = Db::name('address')->where('id',$v['patrol_addr_id'])->value('title');
-//            $list[$k]['userName'] = Db::name('user')->where('id',$v['user_id'])->value('real_name');
-//            $status = Db::name('patrol_task')->where('id',$v['patrol_task_id'])->value('status');
-//            $statusTxt = '';
-//            if($status == 0){
-//                $statusTxt = '待完成';
-//            }elseif ($status == 1){
-//                $statusTxt = '执行中';
-//            }elseif ($status == 2){
-//                $statusTxt = '已完成';
-//            }elseif ($status == 3){
-//                $statusTxt = '未完成';
-//            }elseif ($status == 5){
-//                $statusTxt = '中断';
-//            }elseif ($status == 6){
-//                $statusTxt = '已关闭';
-//            }
-//            $list[$k]['statusTxt'] = $statusTxt;
-//            $list[$k]['status'] = $status;
-//            $list[$k]['create_time'] = date('m-d H:i:s',strtotime($v['create_time']));
-//        }
-
         $this->assign('list',$list);
-        $this->assign('page',$page);
+        $this->assign('currentPage',$list->currentPage());
+        $this->assign('lastPage',$list->lastPage());
+        $this->assign('total',$list->total());
         $this->assign('title','巡检记录');
         return  $this->fetch();
 
 
     }
 
+
+    public function recordDetail()
+    {
+        $id = input('id', 0, 'intval');
+        if (!$id) {
+            $this->error('参数错误');
+        }
+        $info = Db::name('patrol_record')->where('id', $id)->find();
+        if (!$info) {
+            $this->error('记录不存在');
+        }
+        $info['addr'] = Db::name('address')->where('id', $info['patrol_addr_id'])->value('title');
+        $info['task_name'] = Db::name('patrol_task')->where('id', $info['patrol_task_id'])->value('title');
+        $info['in_order'] = Db::name('patrol_task')->where('id', $info['patrol_task_id'])->value('in_order');
+        $info['task_addr_form'] = Db::name('patrol_addr_form')
+            ->alias('a')
+            ->join('patrol_task_addr b', 'a.id = b.patrol_form_id')
+            ->where('b.id', $info['patrol_addr_form_id'])->value('a.title');
+        $info['task_user'] = Db::name('user')->where('id', $info['user_id'])->value('real_name');
+        $info['check_json'] = json_decode($info['check_json'], true);
+        $info['images'] = $info['images'] ? array_filter(explode(',', $info['images'])) : [];
+
+        // 整改状态:关联工单是否存在
+        $zgType = 0;
+        if ($info['order_id'] > 0) {
+            $order = Db::name('orders')
+                ->where('id', $info['order_id'])
+                ->where('quality_type', $info['patrol_mode'] + 1)
+                ->whereIn('order_mode', [5, 6])
+                ->where('del', 0)
+                ->find();
+            $zgType = $order ? 2 : 1;
+        }
+        $info['zg_type'] = $zgType;
+
+        // 任务状态(与列表页保持一致)
+        $taskStatus = Db::name('patrol_task')->where('id', $info['patrol_task_id'])->value('status');
+        $statusTxt = '';
+        if ($taskStatus == 0) {
+            $statusTxt = '待完成';
+        } elseif ($taskStatus == 1) {
+            $statusTxt = '执行中';
+        } elseif ($taskStatus == 2) {
+            $statusTxt = '已完成';
+        } elseif ($taskStatus == 3) {
+            $statusTxt = '未完成';
+        } elseif ($taskStatus == 5) {
+            $statusTxt = '中断';
+        } elseif ($taskStatus == 6) {
+            $statusTxt = '已关闭';
+        }
+        $info['statusTxt'] = $statusTxt;
+        $info['status'] = $taskStatus;
+        $info['create_time'] = date('Y-m-d H:i:s', strtotime($info['create_time']));
+
+        $this->assign('info', $info);
+        $this->assign('title', '记录详情');
+        return $this->fetch();
+    }
+
 }
 
 

+ 119 - 5
application/h5/view/repair/record.html

@@ -10,24 +10,135 @@
     <script type="text/javascript" src="/static/layer/layer.js"></script>
     <link rel="stylesheet" href="/repair/style.css">
     <title>{$title}</title>
+    <style>
+        .add-table-record-box{
+            padding-bottom: 20px;
+        }
+        .record-table{
+            table-layout: fixed;
+            margin-bottom: 0;
+        }
+        .record-table th,
+        .record-table td{
+            font-size: 13px;
+            vertical-align: middle;
+            word-break: break-all;
+        }
+        .record-table td.col-content{
+            white-space: nowrap;
+            overflow: hidden;
+            text-overflow: ellipsis;
+        }
+        .record-table tbody tr{
+            cursor: pointer;
+        }
+        .record-table tbody tr:active{
+            background-color: #f5f5f5;
+        }
+        .col-chevron{
+            width: 26px;
+            text-align: center;
+            color: #bbb;
+            font-size: 18px;
+            padding: 0;
+        }
+        .record-status{
+            display: inline-block;
+            padding: 1px 6px;
+            border-radius: 4px;
+            font-size: 12px;
+        }
+        .record-status.s-0{ background:#fff7e6; color:#fa8c16; }
+        .record-status.s-1{ background:#e6f7ff; color:#1890ff; }
+        .record-status.s-2{ background:#f6ffed; color:#52c41a; }
+        .record-status.s-3{ background:#fff1f0; color:#f5222d; }
+        .record-status.s-5{ background:#fff1f0; color:#f5222d; }
+        .record-status.s-6{ background:#fafafa; color:#999; }
+
+        /* 分页样式优化 */
+        .record-pager{
+            display: flex;
+            align-items: center;
+            justify-content: space-between;
+            margin: 14px 5px 0 5px;
+            font-size: 13px;
+        }
+        .record-pager .pager-btn{
+            flex: 0 0 auto;
+            min-width: 64px;
+            height: 32px;
+            line-height: 32px;
+            text-align: center;
+            padding: 0 12px;
+            background-color: #fff;
+            border-radius: 16px;
+            color: #284a94;
+            text-decoration: none;
+            box-shadow: 0 1px 4px rgba(0,0,0,.06);
+        }
+        .record-pager .pager-btn:active{
+            background-color: #f0f0f0;
+        }
+        .record-pager .pager-disabled{
+            color: #ccc;
+            background-color: #fafafa;
+            box-shadow: none;
+            pointer-events: none;
+        }
+        .record-pager .pager-info{
+            flex: 1 1 auto;
+            text-align: center;
+            color: #888;
+        }
+    </style>
 </head>
 <body>
     <div class="add-table-record-box">
-        <table class="table table-bordered">
+        <table class="table table-bordered record-table">
+            <thead>
+            <tr>
+                <th>提交时间</th>
+                <th>巡检地点</th>
+                <th>任务内容</th>
+                <th>状态(执行人)</th>
+            </tr>
+            </thead>
             <tbody>
             {if isset($list)}
             {foreach $list as $k=>$v}
-            <tr>
+            <tr onclick="goDetail({$v['id']})">
                 <td>{$v['create_time']}</td>
                 <td>{$v['addrName']}</td>
-                <td>{$v['content']}</td>
-                <td>{$v['statusTxt']}({$v['userName']})</td>
+                <td class="col-content">{$v['content']}</td>
+                <td>
+                    <span class="record-status s-{$v['status']}">{$v['statusTxt']}</span>
+                    <div style="font-size:12px;margin-top:2px;">{$v['userName']}</div>
+                </td>
             </tr>
             {/foreach}
             {/if}
             </tbody>
         </table>
-        {$page|raw}
+
+        {if $lastPage > 1}
+        <div class="record-pager">
+            {if $currentPage > 1}
+            <a class="pager-btn" href="{:url('repair/record',['page'=>$currentPage-1])}">上一页</a>
+            {else}
+            <span class="pager-btn pager-disabled">上一页</span>
+            {/if}
+            <span class="pager-info">第 {$currentPage} / {$lastPage} 页 共 {$total} 条</span>
+            {if $currentPage < $lastPage}
+            <a class="pager-btn" href="{:url('repair/record',['page'=>$currentPage+1])}">下一页</a>
+            {else}
+            <span class="pager-btn pager-disabled">下一页</span>
+            {/if}
+        </div>
+        {else/}
+        <div class="record-pager">
+            <span class="pager-info">共 {$total} 条</span>
+        </div>
+        {/if}
     </div>
 
 
@@ -35,5 +146,8 @@
 </html>
 <script>
 
+    function goDetail(id){
+        window.location.href = "{:url('repair/recordDetail')}?id=" + id;
+    }
 
 </script>

+ 241 - 0
application/h5/view/repair/record_detail.html

@@ -0,0 +1,241 @@
+<!doctype html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <meta name="viewport"
+          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
+    <meta http-equiv="X-UA-Compatible" content="ie=edge">
+    <link rel="stylesheet" href="/static/bootstrap-3.3.7/css/bootstrap.css">
+    <script type="text/javascript" src="/static/jquery-2.2.4.min.js"></script>
+    <script type="text/javascript" src="/static/layer/layer.js"></script>
+    <link rel="stylesheet" href="/repair/style.css">
+    <title>{$title}</title>
+    <style>
+        body{ background-color:#F1F1F1; }
+        .detail-container{
+            width:100%;
+            max-width:750px;
+            margin:0 auto;
+            padding-bottom:30px;
+        }
+
+        .detail-card{
+            width:calc(100% - 20px);
+            margin:10px 10px 0 10px;
+            background-color:#fff;
+            border-radius:10px;
+            padding:12px 14px 14px;
+            box-shadow:0 1px 4px rgba(0,0,0,.04);
+        }
+        .detail-card-title{
+            font-size:15px;
+            font-weight:bold;
+            color:#284a94;
+            padding-bottom:10px;
+            margin-bottom:6px;
+            border-bottom:1px solid #f0f0f0;
+        }
+        .detail-row{
+            display:flex;
+            font-size:14px;
+            line-height:1.8;
+            padding:3px 0;
+        }
+        .detail-row .label{
+            flex:0 0 84px;
+            color:#999;
+        }
+        .detail-row .value{
+            flex:1 1 auto;
+            color:#333;
+            word-break:break-all;
+        }
+        .tag{
+            display:inline-block;
+            padding:1px 8px;
+            border-radius:4px;
+            font-size:12px;
+        }
+        .tag-wait{ background:#fff7e6; color:#fa8c16; }
+        .tag-doing{ background:#e6f7ff; color:#1890ff; }
+        .tag-done{ background:#f6ffed; color:#52c41a; }
+        .tag-fail{ background:#fff1f0; color:#f5222d; }
+        .tag-closed{ background:#fafafa; color:#999; }
+        .tag-zg1{ background:#fff7e6; color:#fa8c16; }
+        .tag-zg2{ background:#f6ffed; color:#52c41a; }
+
+        /* 检查项 */
+        .check-group{ margin-bottom:12px; }
+        .check-group:last-child{ margin-bottom:0; }
+        .check-group-title{
+            font-size:14px;
+            font-weight:bold;
+            color:#333;
+            margin-bottom:6px;
+        }
+        .check-item{
+            display:flex;
+            align-items:center;
+            justify-content:space-between;
+            font-size:14px;
+            padding:7px 10px;
+            background:#fafafa;
+            border-radius:6px;
+            margin-bottom:6px;
+        }
+        .check-item .check-name{
+            flex:1 1 auto;
+            color:#555;
+            word-break:break-all;
+            padding-right:10px;
+        }
+        .check-item .check-right{
+            flex:0 0 auto;
+            text-align:right;
+            white-space:nowrap;
+        }
+        .check-item .check-val{ color:#333; }
+        .badge-status{
+            display:inline-block;
+            padding:1px 7px;
+            border-radius:10px;
+            font-size:12px;
+            margin-left:8px;
+        }
+        .badge-ok{ background:#f6ffed; color:#52c41a; }
+        .badge-err{ background:#fff1f0; color:#f5222d; }
+
+        /* 图片 */
+        .img-grid{
+            display:flex;
+            flex-wrap:wrap;
+            margin:0 -4px;
+        }
+        .img-grid img{
+            width:calc(33.33% - 8px);
+            height:90px;
+            object-fit:cover;
+            margin:4px;
+            border-radius:6px;
+            background:#f0f0f0;
+        }
+        .detail-content{
+            font-size:14px;
+            color:#333;
+            line-height:1.7;
+            white-space:pre-wrap;
+            word-break:break-all;
+        }
+        .empty-tip{
+            font-size:13px;
+            color:#bbb;
+            text-align:center;
+            padding:14px 0;
+        }
+    </style>
+</head>
+<body>
+    <div class="detail-container">
+        <!-- 基本信息 -->
+        <div class="detail-card">
+            <div class="detail-card-title">基本信息</div>
+            <div class="detail-row"><span class="label">编号</span><span class="value">{$info.id}</span></div>
+            <div class="detail-row"><span class="label">名称</span><span class="value">{$info.task_name}</span></div>
+            <div class="detail-row"><span class="label">地点</span><span class="value">{$info.addr}</span></div>
+            <div class="detail-row"><span class="label">任务内容</span><span class="value">{$info.task_addr_form}</span></div>
+            <div class="detail-row"><span class="label">执行人</span><span class="value">{$info.task_user}</span></div>
+            <div class="detail-row"><span class="label">提交时间</span><span class="value">{$info.create_time}</span></div>
+            <div class="detail-row">
+                <span class="label">状态</span>
+                <span class="value">
+                    {if $info.status == 0}<span class="tag tag-wait">待完成</span>
+                    {elseif $info.status == 1}<span class="tag tag-doing">执行中</span>
+                    {elseif $info.status == 2}<span class="tag tag-done">已完成</span>
+                    {elseif $info.status == 3}<span class="tag tag-fail">未完成</span>
+                    {elseif $info.status == 5}<span class="tag tag-fail">中断</span>
+                    {elseif $info.status == 6}<span class="tag tag-closed">已关闭</span>
+                    {else/}<span class="tag tag-closed">-</span>
+                    {/if}
+                </span>
+            </div>
+            {if $info.zg_type > 0}
+            <div class="detail-row">
+                <span class="label">整改状态</span>
+                <span class="value">
+                    {if $info.zg_type == 1}<span class="tag tag-zg1">整改中</span>
+                    {elseif $info.zg_type == 2}<span class="tag tag-zg2">已完成</span>
+                    {/if}
+                </span>
+            </div>
+            {/if}
+        </div>
+
+        <!-- 检查项 -->
+        {if $info.check_json}
+        <div class="detail-card">
+            <div class="detail-card-title">检查项</div>
+            {foreach $info.check_json as $group}
+            <div class="check-group">
+                <div class="check-group-title">{$group.title}</div>
+                {foreach $group.forms as $form}
+                <div class="check-item">
+                    <span class="check-name">{$form.title}</span>
+                    <span class="check-right">
+                        {if $form.type == 0}
+                            <span class="check-val">{if $form.result == 1}是{else}否{/if}</span>
+                        {else}
+                            <span class="check-val">{$form.result}</span>
+                        {/if}
+                        {if isset($form.status)}
+                            {if $form.status == 0}<span class="badge-status badge-err">异常</span>
+                            {elseif $form.status == 1}<span class="badge-status badge-ok">正常</span>
+                            {/if}
+                        {/if}
+                    </span>
+                </div>
+                {/foreach}
+            </div>
+            {/foreach}
+        </div>
+        {/if}
+
+        <!-- 设备图片 -->
+        <div class="detail-card">
+            <div class="detail-card-title">设备图片</div>
+            {if $info.images}
+            <div class="img-grid">
+                {foreach $info.images as $img}
+                <img src="{$img}" onclick="previewImg(this)" alt="">
+                {/foreach}
+            </div>
+            {else/}
+            <div class="empty-tip">暂无图片</div>
+            {/if}
+        </div>
+
+        <!-- 汇报内容 -->
+        <div class="detail-card">
+            <div class="detail-card-title">汇报内容</div>
+            {if $info.content}
+            <div class="detail-content">{$info.content}</div>
+            {else/}
+            <div class="empty-tip">暂无内容</div>
+            {/if}
+        </div>
+    </div>
+</body>
+</html>
+<script>
+
+    function previewImg(img){
+        var src = img.getAttribute('src');
+        layer.open({
+            type:1,
+            skin:'layui-layer-img',
+            shadeClose:true,
+            area:['90%','auto'],
+            content:'<img src="'+src+'" style="width:100%;display:block;border-radius:6px;">'
+        });
+    }
+
+</script>