Parcourir la source

吉利1.0药品运送功能迁移

zgg il y a 1 mois
Parent
commit
a301edc995

+ 126 - 0
application/admin/controller/AutoUser.php

@@ -0,0 +1,126 @@
+<?php
+namespace app\admin\controller;
+
+use app\common\util\ExcelUtil;
+use think\Db;
+
+class AutoUser extends Auth
+{
+
+    public function index(){
+        if(request()->isAjax()){
+            //分页参数
+            $length = input('rows',10,'intval');   //每页条数
+            $page = input('page',1,'intval');      //第几页
+            $start = ($page - 1) * $length;     //分页开始位置
+            //排序
+            $sortRow = input('sidx','id','trim');      //排序列
+            $sort = input('sord','desc','trim');        //排序方式
+            $order = $sortRow.' '.$sort;
+
+            $user = input('user','','trim');
+            if($user){
+                $id = Db::name('user')
+                ->join('user_org uo','user.id=uo.user_id')
+                ->where('uo.org_id',$this->orgId)
+                ->where('user.real_name',$user)
+                ->value('user.id');
+                $map[] = ['user_id','=',$id];
+            }
+            $s = input('start','','trim');
+            if($s != ''){
+                $id = Db::name('address')->where('del',0)->where('org_id',$this->orgId)->where('title',$s)->value('id');
+                $map[] = ['start','=',$id];
+            }
+            $end = input('end','','trim');
+            if($end != ''){
+                $id = Db::name('address')->where('del',0)->where('org_id',$this->orgId)->where('title',$end)->value('id');
+                $map[] = ['end','=',$id];
+            }
+            // $map[] = ['del','=',0];
+            $map[] = ['org_id','=',$this->orgId];
+            $map= empty($map) ? true: $map;
+            //数据查询
+            $lists = db('auto_user')->where($map)->limit($start,$length)->order($order)->select();
+            foreach ($lists as $k=>$v){
+            $lists[$k]['real_name']= Db::name('user')->where('del',0)->where('id',$v['user_id'])->value('real_name');
+            $lists[$k]['start_name'] = Db::name('address')->where('del',0)->where('org_id',$this->orgId)->where('id',$v['start'])->value('title');
+            $lists[$k]['end_name'] = Db::name('address')->where('del',0)->where('org_id',$this->orgId)->where('id',$v['end'])->value('title');
+            }
+
+            //数据返回
+            $totalCount = db('auto_user')->where($map)->count();
+            $totalPage = ceil($totalCount/$length);
+            $result['page'] = $page;
+            $result['total'] = $totalPage;
+            $result['records'] = $totalCount;
+            $result['rows'] = $lists;
+            return json($result);
+        }else{
+            return $this->fetch();
+        }
+    }
+
+    /**
+     * 新增/编辑
+     */
+    public function add($id=0){
+        if(request()->isPost()){
+            $res = model('AutoUser')->updates();
+            if($res){
+                $this->success('操作成功',url('index'));
+            }else{
+                $this->error(model('AutoUser')->getError());
+            }
+        }else{
+            if($id){
+                $info = db('AutoUser')->where('id',$id)->find();
+                $this->assign('info',$info);
+            }
+            // halt($info);
+            $address = model('address')->getListByTypes('',2,$this->orgId);
+            $this->assign('address',$address);
+            $user = (new \app\common\model\WorkTypeMode())->getRolesUserByNum(3, $this->orgId,1);
+            foreach ($user[0]['user'] as $k =>$v){
+                $user[0]['user'][$k]['title']= preg_replace('/\(.*?\)/', '', $v['real_name']);
+            };
+            $this->assign('user', $user[0]['user']);
+            return $this->fetch();
+        }
+    }
+
+    /**
+     * 删除记录
+     * @param int $id
+     */
+    public function del($id=0){
+        if(!$id){
+            $this->error('参数错误');
+        }
+        $res = db('AutoUser')->where('id',$id)->delete();
+        if($res){
+            $this->success('删除成功');
+        }else{
+            $this->error('删除失败');
+        }
+    }
+
+    /**
+     * 改变字段值
+     * @param int $fv
+     * @param string $fn
+     * @param int $fv
+     */
+    public function changeField($id=0,$fn='',$fv=0){
+        if(!$fn||!$id){
+            $this->error('参数错误');
+        }
+        $res = db('AutoUser')->where('id',$id)->setField($fn,$fv);
+        if($res){
+            $this->success('操作成功');
+        }else{
+            $this->error('操作失败');
+        }
+    }
+
+}

+ 2 - 1
application/admin/controller/ConveyStatistics.php

@@ -220,7 +220,7 @@ class ConveyStatistics extends Auth
         //下载文件在浏览器窗口
         return $objWriter->save('php://output');
     }
-
+    
     public function conveyOrder(){
         $start = input('start',date('Y-m-d',strtotime('-7 day')));
         $end = input('end',date('Y-m-d'));
@@ -362,4 +362,5 @@ class ConveyStatistics extends Auth
         //下载文件在浏览器窗口
         return $objWriter->save('php://output');
     }
+
 }

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

@@ -202,7 +202,7 @@ class MateCheck extends Auth
             Db::rollback();
             $this->error('操作失败');
         }
-
+        
         $this->success('操作成功');
     }
 

+ 29 - 29
application/admin/controller/OrderStatistics.php

@@ -172,7 +172,7 @@ class OrderStatistics extends Auth
             return $this->fetch();
         }
     }
-
+    
     public function repairCateExport(){
         $start = input('start',date('Y-m-d',strtotime('-7 day')));
         $end = input('end',date('Y-m-d'));
@@ -180,40 +180,40 @@ class OrderStatistics extends Auth
         $eTime = $end.' 23:59:59';
 
         $list = Db::name('order_type')
-            ->field('id,title,parent_id')
-            ->where('enable',1)
-            ->where('del',0)
-            ->where('org_id',$this->orgId)
-            ->where('parent_id','=',0)
-            ->select();
-        foreach ($list as $k=>$v){
-            $type = Db::name('order_type')
-                ->field('id')
+                ->field('id,title,parent_id')
                 ->where('enable',1)
                 ->where('del',0)
                 ->where('org_id',$this->orgId)
-                ->where('parent_id',$v['id'])
+                ->where('parent_id','=',0)
                 ->select();
-            $ids = [];
-            foreach ($type as $kk=>$vv){
-                $ids[$kk] = $vv['id'];
+            foreach ($list as $k=>$v){
+                $type = Db::name('order_type')
+                    ->field('id')
+                    ->where('enable',1)
+                    ->where('del',0)
+                    ->where('org_id',$this->orgId)
+                    ->where('parent_id',$v['id'])
+                    ->select();
+                $ids = [];
+                foreach ($type as $kk=>$vv){
+                    $ids[$kk] = $vv['id'];
+                }
+                $list[$k]['ids'] = $ids;
             }
-            $list[$k]['ids'] = $ids;
-        }
-
-        foreach ($list as $k=>$v){
-            $list[$k]['nums'] =  Db::name('orders')
-                ->alias('o')
-                ->join('order_repair or','or.order_id=o.id')
-                ->whereIn('or.type_id',$v['ids'])
-                ->where('o.del',0)
-                ->where('o.org_id',$this->orgId)
-                ->where('o.create_time','>=',$sTime)
-                ->where('o.create_time','<=',$eTime)
-                ->count();
-        }
-        $data = list_sort_by($list,'nums','desc');
 
+            foreach ($list as $k=>$v){
+                $list[$k]['nums'] =  Db::name('orders')
+                    ->alias('o')
+                    ->join('order_repair or','or.order_id=o.id')
+                    ->whereIn('or.type_id',$v['ids'])
+                    ->where('o.del',0)
+                    ->where('o.org_id',$this->orgId)
+                    ->where('o.create_time','>=',$sTime)
+                    ->where('o.create_time','<=',$eTime)
+                    ->count();
+            }
+            $data = list_sort_by($list,'nums','desc');
+           
 
         include_once env('root_path').'/extend/phpexcel/Classes/PHPExcel.php';
         //实例化PHPExcel类

+ 1 - 0
application/admin/controller/Orders.php

@@ -1171,6 +1171,7 @@ class Orders extends Auth {
 
         }
         else {
+
             $data = request()->post();
             $data['org_id'] = $this->orgId;
             $res = $this->model->send($id, $this->userId, $data);

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

@@ -1044,7 +1044,7 @@ class RepairStatistics extends Auth
             $sheet->setCellValueByColumnAndRow(0, $k + 2, $v['title']);
             foreach ($mate as $kk=>$vv){
                 $sheet->setCellValueByColumnAndRow($kk+1, $k + 2, $v['type'.$vv['id']]);
-
+                    
             }
 
         }

+ 30 - 0
application/admin/controller/Test.php

@@ -0,0 +1,30 @@
+<?php
+namespace app\admin\controller;
+
+use app\common\util\ExcelUtil;
+use think\Db;
+
+class Test extends Auth
+{
+    public function index(){
+       $data =  Db::name('device_record')
+                ->alias('dr')
+                ->join('device d', 'd.id=dr.device_id')
+                ->field('dr.*,d.title as device_name,d.content as device_details')
+                ->where('dr.org_id',$this->orgId)
+                ->where('cate_id','in',[22,23])
+                ->order('dr.id desc')
+                ->limit(30)
+                ->select();
+
+        foreach ($data as $k=>$v){
+            $img = explode(',',$v['images']);
+            if($img){
+                $data[$k]['images'] = $img[0];
+            }
+        }
+        halt($data);
+        HelpHander::success($data);
+    }
+
+}

+ 9 - 8
application/admin/controller/WasteStatistics.php

@@ -984,7 +984,7 @@ class WasteStatistics extends Auth {
         }
 
         $data = $this->wasteMonthData($month,$addr_id,$type_id);
-
+        
         $this->assign('data',$data['res']);
         $this->assign('totalData',$data['total']);
         $this->assign('typeList',$typeList);
@@ -1265,9 +1265,9 @@ class WasteStatistics extends Auth {
                 $kk = $k+1;
                 $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$kk.'</td>';
                 if(isset($v['list'])){
-                    foreach ($v['list'] as $k1=>$v1){
-                        $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v1.'</td>';
-                    }
+                foreach ($v['list'] as $k1=>$v1){
+                    $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v1.'</td>';
+                }
                 }
                 $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd"></td>';
                 $res.='</tr>';
@@ -1286,7 +1286,6 @@ class WasteStatistics extends Auth {
        </tr>';
         echo $res;
     }
-
     //科室月统计
     public function wasteDeviceMonth() {
         $month = input('start',date('Y-m'));
@@ -1438,6 +1437,7 @@ class WasteStatistics extends Auth {
                 $ttkg = $totalkg?round($totalkg/1000,3):0;
                 $dep[$k]['totalkg'] = $ttkg;
 
+
                 $we =  $weight?round($weight/1000,3):0;
 
                 if($totalNum > 0){
@@ -1451,6 +1451,7 @@ class WasteStatistics extends Auth {
                 }
                 $dep[$k]['total'][] =$we2.$num2;
 
+              //  $dep[$k]['total'][] = $we2 > 0 ? $we2 : $totalNum2.$v1['unit'];
             }
             $tnum += $ttnums;
             $tkg += $ttkg;
@@ -1464,8 +1465,8 @@ class WasteStatistics extends Auth {
 
         return $data;
     }
-
-    public function wasteDeviceMonthExport()
+    
+     public function wasteDeviceMonthExport()
     {
         set_time_limit(0);
         ini_set("memory_limit", "1024M");
@@ -1536,7 +1537,7 @@ class WasteStatistics extends Auth {
         echo $res;
 
     }
-
+        
     // 医废年统计
     public function wasteYears() {
         $month = input('start',date('Y'));

+ 66 - 0
application/admin/controller/Wlps.php

@@ -0,0 +1,66 @@
+<?php
+namespace app\admin\controller;
+
+use think\Db;
+
+class Wlps extends Auth
+{   
+    private $org_Id=103;
+
+    public function index(){
+        if(request()->isAjax()){
+            //分页参数
+            $length = input('rows',10,'intval');   //每页条数
+            $page = input('page',1,'intval');      //第几页
+            $start = ($page - 1) * $length;     //分页开始位置
+            //排序
+            $sortRow = input('sidx','id','trim');      //排序列
+            $sort = input('sord','desc','trim');        //排序方式
+            $order = $sortRow.' '.$sort;
+
+            $bh = input('bh','','trim');
+            if($bh){
+                $map[] = ['jjddjbh','=',$bh];
+            }
+            
+            if ($this->orgId != $this->org_Id) {
+                $map[] = ['order_id','=',-1];
+            }
+            $map= empty($map) ? true: $map;
+            //数据查询
+            // $lists = Db::connect('db_config_jili')->name('wlps')->where($map)->limit($start,$length)->order($order)->select();
+            $lists = Db::name('wlps')->where($map)->limit($start,$length)->order($order)->select();
+
+            //数据返回
+            // $totalCount = Db::connect('db_config_jili')->name('wlps')->where($map)->count();
+            $totalCount = Db::name('wlps')->where($map)->count();
+            $totalPage = ceil($totalCount/$length);
+            $result['page'] = $page;
+            $result['total'] = $totalPage;
+            $result['records'] = $totalCount;
+            $result['rows'] = $lists;
+            return json($result);
+        }else{
+            return $this->fetch();
+        }
+    }
+    
+        public function deal(){
+        $id = input('id','','intval');
+        // $info = Db::connect('db_config_jili')->name('wlps')->where('id',$id)->find();
+        $info = Db::name('wlps')->where('id',$id)->find();
+        if(!$info){
+            $this->error('记录不存在');
+        }
+        if($info['is_deal'] != 2 || $info['is_qx'] != 'N'){
+            $this->error('该状态无法执行此操作');
+        }
+        $ret = model('Wlps')->deal_wlps($info);
+        if($ret){
+            $this->success('操作成功');
+        }else{
+            $this->error('操作失败,'.model('Wlps')->getError());
+        }
+    }
+
+}

+ 7 - 0
application/admin/view/address/add.html

@@ -73,6 +73,13 @@
                             </label>
                         </div>
                     </div>
+                    
+                    <div class="form-group">
+                        <label class="col-sm-2 control-label">第三方编号</label>
+                        <div class="col-sm-6">
+                            <input type="text" class="form-control" name="third_sn" value="{$info.third_sn|default=''}">
+                        </div>
+                    </div>
 
                     <div id="issss" style="display:none ">
                         <div class="form-group">

+ 1 - 0
application/admin/view/address/index.html

@@ -84,6 +84,7 @@
             colModel:[
                 {label:'ID',name:'id',index:'id', width:30,sortable: false},
                 {label:'名称',name:'title',index:'title',width:100,editable: false,sortable: false},
+                {label:'第三方编号',name:'third_sn',index:'third_sn',width:60,editable: false,sortable: false},
                 {label:'二维码',name:'id',index:'id',width:40,sortable: false,formatter:function (a,b,c){
                     var editurl = "{:url('qrcode',[],'')}/id/"+c.id;
                     var btn = '<a url="'+editurl+'" href="javascript:;" data-title="二维码" onclick="layer_open(this,1)"><span class="label label-primary" title="查看">查看</span></a>';

+ 59 - 0
application/admin/view/auto_user/add.html

@@ -0,0 +1,59 @@
+{extend name="common/common2" /}
+{block name="main"}
+<div class="row">
+    <div class="col-sm-12">
+        <div class="ibox float-e-margins">
+            <div class="ibox-content">
+                <form method="post" action="{:url('add')}" class="form-horizontal">
+                    <input type="hidden" name="id" value="{$info['id']|default='0'}">
+                    <div class="form-group">
+                        <label class="col-sm-2 control-label">开始地点<span class="text-danger">*</span></label>
+                        <div class="col-sm-6">
+                            {:widget_view('common/select',['name'=>'start','lists' => $address, 'value' => isset($info)?$info['start']:''])}
+                        </div>
+                    </div>
+
+                    <div class="form-group">
+                        <label class="col-sm-2 control-label">送达地点<span class="text-danger">*</span></label>
+                        <div class="col-sm-6">
+                            {:widget_view('common/select',['name'=>'end','lists' => $address, 'value' => isset($info)?$info['end']:''])}
+                        </div>
+                    </div>
+                    <div class="form-group">
+                        <label class="col-sm-2 control-label">人员<span class="text-danger">*</span></label>
+                           <div class="col-sm-6">
+                            {:widget_view('common/select',['name'=>'user_id','lists' => $user, 'value' => isset($info)?$info['user_id']:''])}
+                        </div>
+                    </div>
+                    <div class="form-group">
+                        <label class="col-sm-2 control-label">状态</label>
+                        <div class="col-sm-6">
+                            <label class="cr-inline">
+                                <input type="radio" value="1" name="enable">可用&nbsp;&nbsp;
+                            </label>
+                            <label class="cr-inline">
+                                <input type="radio" value="0" name="enable">停用
+                            </label>
+                        </div>
+                    </div>
+                    <div class="hr-line-dashed"></div>
+                    <div class="form-group">
+                        <div class="col-sm-6 col-sm-offset-2">
+                            <button class="btn btn-primary ajax-post" data-layer="1" target-form="form-horizontal" type="submit">确 定</button>
+                            <button  class="btn cancel-btn btn-default" type="button">取 消</button>
+                        </div>
+                    </div>
+                </form>
+            </div>
+        </div>
+    </div>
+</div>
+{/block}
+{block name="script"}
+<script>
+    $(document).ready(function(){
+        formSetValue("enable", {$info.enable|default=1});
+    });
+
+</script>
+{/block}

+ 108 - 0
application/admin/view/auto_user/index.html

@@ -0,0 +1,108 @@
+{extend name="common/common2" /}
+{block name="main"}
+
+<div class="ibox">
+    <div class="ibox-content">
+        <div class="row">
+            <div class="col-xs-2">
+                <a href="javascript:;" url="{:url('add',[],'')}" data-title="添加" onclick="layer_open(this,1)" class="btn btn-sm btn-primary">添加</a>
+                &nbsp;
+            </div>
+            <div class="col-xs-10" style="text-align: right;">
+                <form class="form-inline" id="form-search" action="{:url('index')}">
+                    <div class="input-group">
+                        <input type="text" class="form-control" name="user" placeholder="人员名称">
+                    </div>
+                    <div class="input-group">
+                        <input type="text" class="form-control" name="start" placeholder="开始地点">
+                    </div>
+                     <div class="input-group">
+                        <input type="text" class="form-control" name="end" placeholder="结束地点">
+                    </div>
+                    <div class="input-group">
+                        <span class="input-group-btn">
+                        <button class="btn-sm btn-primary" type="button" id ="search-btn" ><i class="fa fa-search"></i></button>
+                    </span> &nbsp;
+                        <span class="input-group-btn">
+                        <button class="btn-sm btn-warning" type="button" id="search-clear"><i class="fa fa-undo"></i></button>
+                    </span>
+                    </div>
+                </form>
+        </div>
+        </div>
+    </div>
+    <div class="ibox-content">
+        <div class="jqGrid_wrapper">
+            <table id="table" style="border-collapse: collapse"></table>
+            <div id="pager"></div>
+        </div>
+    </div>
+</div>
+{/block}
+{block name="script"}
+<script src="/static/layDate-v5.0.9/laydate.js"></script>
+
+<script>
+    //导出
+    function excel_download(_self){
+        var url = $(_self).attr('data-url');
+        var param = $('#form-search').serialize();
+        window.location.href = url+'?'+param;
+    }
+    $(function () {
+        $(window).bind("resize",function(){
+            var width=$(".jqGrid_wrapper").width();
+            $("#table").setGridWidth(width);
+        });
+
+        $.jgrid.defaults.styleUI="Bootstrap";
+        $("#table").jqGrid({
+            url:"{:url('index')}",
+            datatype: "json",
+            colModel:[
+                {label:'开始地点',name:'start_name',index:'start_name', width:80,sortable: false},
+                {label:'结束地点',name:'end_name',index:'end_name',width:50,sortable: true},
+                {label:'人员',name:'real_name',index:'real_name',width:60,sortable: true},
+                {label:'状态',name:'enable',index:'enable',width:40,editable: false,sortable: false,formatter:function (a,b,c){
+                    if(a == 0){
+                        var url = "{:url('changeField',[],'')}/fn/enable/fv/1/id/"+c.id;
+                        return '<a href="'+url+'" class="ajax-get" data-table="1"><span class="label label-danger" title="停用">停用</span></a>';
+                    } else{
+                        var url = "{:url('changeField',[],'')}/fn/enable/fv/0/id/"+c.id;
+                        return '<a href="'+url+'" class="ajax-get" data-table="1"><span class="label label-primary" title="可用">可用</span></a>';
+                    }
+                }},
+                {label:'时间',name:'create_time',index:'create_time',width:60,sortable: true},
+                {label:'操作',width:50,sortable: false,formatter: function (a, b, c) {
+                    var edit_url = "{:url('add',[],'')}/id/"+c.id;
+                    var del_url = "{:url('del',[],'')}/id/"+c.id;
+
+                   // var btn = '<a  href="'+detail_url+'" ><span class="label label-primary" title="详情">详情</span></a>&nbsp;';
+                        var btn = '<a url="'+edit_url+'" href="javascript:;" data-title="编辑" onclick="layer_open(this,1)"><span class="label label-primary" title="编辑">编辑</span></a>&nbsp;';
+                        btn += '<a href="'+del_url+'" class="confirm ajax-get" data-confirm="确定要删除吗?" data-table="1"><span class="label label-danger" title="删除">删除</span></a>';
+
+                        return btn;
+                }},
+            ],
+            rowNum:10,
+            rowList:[10,20,30,50,100],
+            pager: '#pager',
+            sortname: 'id',
+            viewrecords: true,
+            autowidth:true,
+            mtype: 'post',
+            height: 'auto',
+            emptyrecords: "暂无数据",
+            sortorder: "desc",
+            caption:"自动接单人员",
+            loadComplete: function (xhr) {
+                if(xhr.code==0){
+                    layer.msg(xhr.msg);
+                    return false;
+                }
+            },
+        });
+    });
+
+</script>
+{/block}

+ 143 - 0
application/admin/view/wlps/index.html

@@ -0,0 +1,143 @@
+{extend name="common/common2" /}
+{block name="main"}
+
+<div class="ibox">
+    <div class="ibox-content">
+        <div class="row">
+            <div class="col-xs-2">
+            </div>
+            <div class="col-xs-10" style="text-align: right;">
+                <form class="form-inline" id="form-search" action="{:url('index')}">
+                    <div class="input-group">
+                        <input type="text" class="form-control" name="bh" placeholder="请输入编号">
+                    </div>
+                    <div class="input-group">
+                        <span class="input-group-btn">
+                        <button class="btn-sm btn-primary" type="button" id ="search-btn" ><i class="fa fa-search"></i></button>
+                    </span> &nbsp;
+                        <span class="input-group-btn">
+                        <button class="btn-sm btn-warning" type="button" id="search-clear"><i class="fa fa-undo"></i></button>
+                    </span>
+                    </div>
+                </form>
+        </div>
+        </div>
+    </div>
+    <div class="ibox-content">
+        <div class="jqGrid_wrapper">
+            <table id="table" style="border-collapse: collapse"></table>
+            <div id="pager"></div>
+        </div>
+    </div>
+</div>
+{/block}
+{block name="script"}
+<script src="/static/layDate-v5.0.9/laydate.js"></script>
+
+<script>
+    //导出
+    function excel_download(_self){
+        var url = $(_self).attr('data-url');
+        var param = $('#form-search').serialize();
+        window.location.href = url+'?'+param;
+    }
+    $(function () {
+        $(window).bind("resize",function(){
+            var width=$(".jqGrid_wrapper").width();
+            $("#table").setGridWidth(width);
+        });
+
+        $.jgrid.defaults.styleUI="Bootstrap";
+        $("#table").jqGrid({
+            url:"{:url('index')}",
+            datatype: "json",
+            colModel:[
+                {label:'任务日期',name:'start_date',index:'start_name', width:50,sortable: false},
+                {label:'任务单号',name:'jjddjbh',index:'end_name',width:60,sortable: true},
+                {label:'地点',name:'id',index:'id',width:100,sortable: false,formatter:function (a,b,c){
+                    var span = '<span >发起部门编号:'+c.s_bmid+'</span><br>';
+                    span+='<span >病区编码:'+c.department_no+'</span>';
+                    return span;
+                }},
+                {label:'快递柜',name:'',index:'',width:80,editable: false,sortable: false,formatter:function (a,b,c){
+                    var span = '<span >快递柜编号:'+c.kdg_id+'</span><br>';
+                    span+='<span >取件码:'+c.qjm+'</span><br>';
+                    span+='<span >配送箱编号:'+c.psx_id+'</span><br>';
+                    return span;
+
+                }},
+                {label:'批次',name:'create_time',index:'create_time',width:60,sortable: false,formatter:function (a,b,c){
+                    var span = '<span >批次:'+c.pici+'</span><br>';
+                    span+='<span >医嘱类别:'+c.pici+'</span>';
+                    return span;
+                }},
+                {label:'药品',name:'',index:'',width:60,sortable: false,formatter:function (a,b,c){
+                    var span = '<span >总数量:'+c.z_num+'</span><br>';
+                    if(c.tpn_num >0){
+                    span+='<span >'+c.tpn_name+':'+c.tpn_num+'</span><br>';
+                    }
+                    
+                    if(c.pt_num >0){
+                    span+='<span >'+c.pt_name+':'+c.pt_num+'</span><br>';
+                    }
+                    
+                    if(c.kss_num>0){
+                    span+='<span >'+c.kss_name+':'+c.kss_num+'</span><br>';
+                    }
+                    
+                    if(c.hl_num >0){
+                    span+='<span >'+c.hl_name+':'+c.hl_num+'</span><br>';
+                    }
+                    return span;
+
+                }},
+                {label:'取件信息',name:'qjmsg_desc',index:'qjmsg_desc',width:60,sortable: false},
+                {label:'打包时间',name:'db_time',index:'db_time',width:80,sortable: true},
+                {label:'是否取消',name:'is_qx',index:'is_qx',width:45,sortable: false,formatter:function (a,b,c){
+                  if(a =='N'){
+                        return '<span>否</span>';
+                    } else{
+                        return '<span>是</span>';
+                    }
+                }},
+                {label:'状态',name:'is_deal',index:'is_deal',width:60,sortable: false ,formatter:function (a,b,c){
+                  if(a ==0){
+                        return '<span>未处理</span>';
+                    } else
+                    if(a==1){
+                        return '<span>已处理</span>';
+                    }else{
+                        return '<span>处理失败</span><br><span>原因:'+c.reason+'</span>';
+                    }
+                }},
+                {label:'操作',width:50,sortable: false,formatter:function (a,b,c){
+                  if(c.is_deal ==2 && c.is_qx=='N'){
+                        var url = "{:url('deal',[],'')}/id/"+c.id;
+                        return '<a href="'+url+'" class="ajax-get" data-table="1"><span class="label label-primary" >重新处理</span></a>';
+                    }else{
+                        return '';
+                    }
+                }},
+            ],
+            rowNum:10,
+            rowList:[10,20,30,50,100],
+            pager: '#pager',
+            sortname: 'id',
+            viewrecords: true,
+            autowidth:true,
+            mtype: 'post',
+            height: 'auto',
+            emptyrecords: "暂无数据",
+            sortorder: "desc",
+            caption:"药品运送记录",
+            loadComplete: function (xhr) {
+                if(xhr.code==0){
+                    layer.msg(xhr.msg);
+                    return false;
+                }
+            },
+        });
+    });
+
+</script>
+{/block}

+ 32 - 0
application/common/model/AutoUser.php

@@ -0,0 +1,32 @@
+<?php
+namespace app\common\model;
+
+use think\Db;
+
+class AutoUser extends Base
+{
+    public function updates(){
+       $data = request()->post();
+       $data['org_id'] = cur_org_id();
+        $result = validate('AutoUser')->check($data,[],'');
+        if(true !== $result){
+            $this->error = validate('AutoUser')->getError();
+            return false;
+        }
+        $id = $data['id'];
+        unset($data['id']);
+        if($id > 0){
+            $data['update_time'] = date('Y-m-d H:i:s');
+            $ret = $this->allowField(true)->save($data,['id'=>$id]);
+        }else{
+            $data['create_time'] = date('Y-m-d H:i:s');
+            $ret = $this->allowField(true)->save($data);
+        }
+        if(!$ret){
+            $this->error = '操作失败';
+            return false;
+        }
+        return true;
+    }
+
+}

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

@@ -1572,6 +1572,18 @@ class Orders extends Base {
                 }
 
             }
+            if($info['work_type_mode'] == 3){
+//                $wlps = Db::connect('db_config_jili')->name('wlps')->where('order_id',$info['id'])->find();
+                $wlps = Db::name('wlps')->where('order_id',$info['id'])->find();
+                if($wlps){
+//                    Db::connect('db_config_jili')->name('wlps')->where('id',$wlps['id'])->update([
+//                        'send_time' => date('Y-m-d H:i:s')
+//                    ]);
+                    Db::name('wlps')->where('id',$wlps['id'])->update([
+                        'send_time' => date('Y-m-d H:i:s')
+                    ]);
+                }
+            }
             $this->commit();
             if($pusharr){
                 foreach ($pusharr as $k=>$v){
@@ -2007,6 +2019,18 @@ class Orders extends Base {
                         }
                     }
                 }
+                if($info['work_type_mode'] == 3){
+//                $wlps = Db::connect('db_config_jili')->name('wlps')->where('order_id',$info['id'])->find();
+                    $wlps = Db::name('wlps')->where('order_id',$info['id'])->find();
+                    if($wlps){
+//                    Db::connect('db_config_jili')->name('wlps')->where('id',$wlps['id'])->update([
+//                        'send_time' => date('Y-m-d H:i:s')
+//                    ]);
+                        Db::name('wlps')->where('id',$wlps['id'])->update([
+                            'send_time' => date('Y-m-d H:i:s')
+                        ]);
+                    }
+                }
                 $this->commit();
             } catch (Exception $e) {
                 $this->rollback();

+ 59 - 0
application/common/model/Todo.php

@@ -464,6 +464,29 @@ class Todo extends Base
             if(!$ret){
                 exception('订单修改失败');
             }
+            if($info['work_type_mode'] == 3){
+//               $wlps = Db::connect('db_config_jili')->name('wlps')->where('order_id',$info['order_id'])->find();
+                $wlps = Db::name('wlps')->where('order_id',$info['order_id'])->find();
+                if($wlps){
+                    $user = Db::name('user')->where('id',$info['to_user_id'])->find();
+//                    Db::connect('db_config_jili')->name('wlps')
+//                        ->where('id',$wlps['id'])
+//                        ->update([
+//                            'paisr' => $user?$user['user_id']:'',
+//                            'paisr_name' => $user?$user['real_name']:'',
+//                            'paisr_phone' => $user?$user['mobile']:'',
+//                            'pais_time' => date('Y-m-d H:i:s')
+//                        ]);
+                    Db::name('wlps')
+                        ->where('id',$wlps['id'])
+                        ->update([
+                            'paisr' => $user?$user['id']:'',
+                            'paisr_name' => $user?$user['real_name']:'',
+                            'paisr_phone' => $user?$user['mobile']:'',
+                            'pais_time' => date('Y-m-d H:i:s')
+                        ]);
+                }
+            }
             $this->commit();
             return true;
         } catch (Exception $e) {
@@ -587,6 +610,19 @@ class Todo extends Base
                     }
                 }
             }
+            if($data['work_type_mode'] == 3){
+//                $wlps = Db::connect('db_config_jili')->name('wlps')->where('order_id',$data['order_id'])->find();
+                $wlps = Db::name('wlps')->where('order_id',$data['order_id'])->find();
+                if($wlps){
+//                    Db::connect('db_config_jili')->name('wlps')->where('id',$wlps['id'])->update([
+//                        'send_time' => date('Y-m-d H:i:s')
+//                    ]);
+                    Db::name('wlps')->where('id',$wlps['id'])->update([
+                        'send_time' => date('Y-m-d H:i:s')
+                    ]);
+                }
+            }
+
             $this->commit();
             if($pusharr){
                 foreach ($pusharr as $k=>$v){
@@ -902,6 +938,29 @@ class Todo extends Base
                 $this->error = '操作失败';
                 return false;
             }
+            if($todo['work_type_mode'] == 3){
+//               $wlps = Db::connect('db_config_jili')->name('wlps')->where('order_id',$todo['order_id'])->find();
+                $wlps = Db::name('wlps')->where('order_id',$todo['order_id'])->find();
+                if($wlps){
+                    $user = Db::name('user')->where('id',$todo['to_user_id'])->find();
+//                    Db::connect('db_config_jili')->name('wlps')
+//                        ->where('id',$wlps['id'])
+//                        ->update([
+//                            'paisr' => $user?$user['user_id']:'',
+//                            'paisr_name' => $user?$user['real_name']:'',
+//                            'paisr_phone' => $user?$user['mobile']:'',
+//                            'pais_time' => date('Y-m-d H:i:s')
+//                        ]);
+                    Db::name('wlps')
+                        ->where('id',$wlps['id'])
+                        ->update([
+                            'paisr' => $user?$user['id']:'',
+                            'paisr_name' => $user?$user['real_name']:'',
+                            'paisr_phone' => $user?$user['mobile']:'',
+                            'pais_time' => date('Y-m-d H:i:s')
+                        ]);
+                }
+            }
         }else if($todoMode == 6){ // 取消驳回工单
 
             $this->startTrans();

+ 1 - 1
application/common/model/User.php

@@ -128,7 +128,7 @@ class User extends Model
                     }
                 }
             }
-
+            model('Wlps')->updateYsUser($ids,$data['real_name'],$data['mobile'],$rolesId,$orgId);
             Db::commit();
             return true;
         }catch (Exception $e){

+ 252 - 0
application/common/model/Wlps.php

@@ -0,0 +1,252 @@
+<?php
+namespace app\common\model;
+
+use think\Db;
+use app\common\util\AppMsg;
+class Wlps extends Base
+{
+    private $orgId=103;
+    public function deal_wlps($v){
+        $cate = 25;
+        $orgId = 103;
+        $dep = 798;
+        $userId = 3401;
+        if(!$v['s_bmid'] || !$v['department_no']){
+            // Db::connect('db_config_jili')->name('wlps')->where('id',$v['id'])->update(['is_deal'=>2,'reason'=>'发起部门编号或病区编码为空']);
+            Db::name('wlps')->where('id',$v['id'])->update(['is_deal'=>2,'reason'=>'发起部门编号或病区编码为空']);
+            $this->error = '发起部门编号或病区编码为空';
+            return false;
+        }
+        $start = Db::name('address')->where('del',0)->where('org_id',$orgId)->where('','exp',Db::raw("FIND_IN_SET(2,types)"))->where('third_sn',$v['s_bmid'])->find();
+        $end = Db::name('address')->where('del',0)->where('org_id',$orgId)->where('','exp',Db::raw("FIND_IN_SET(2,types)"))->where('third_sn',$v['department_no'])->find();
+        if(!$start || !$end){
+            //  Db::connect('db_config_jili')->name('wlps')->where('id',$v['id'])->update(['is_deal'=>2,'reason'=>'未查找到相关联的发起部门编号或病区编码']);
+            Db::name('wlps')->where('id',$v['id'])->update(['is_deal'=>2,'reason'=>'未查找到相关联的发起部门编号或病区编码']);
+            $this->error = '未查找到相关联的发起部门编号或病区编码';
+            return false;
+        }
+        $this->startTrans();
+        try{
+            $content = '';
+            if($v['kdg_id']){
+                $content .= '快递柜编号:'.$v['kdg_id'].';';
+            }
+            if($v['qjm']){
+                $content .= '取件码:'.$v['qjm'].';';
+            }
+            if($v['psx_id']){
+                $content .= '配送箱编号:'.$v['psx_id'].';';
+            }
+            if($v['z_num']){
+                $content .= '总数量:'.$v['z_num'].';';
+            }
+            if($v['tpn_num'] > 0){
+                $content .= $v['tpn_name'].':'.$v['tpn_num'].';';
+            }
+            if($v['pt_num'] > 0){
+                $content .= $v['pt_name'].':'.$v['pt_num'].';';
+            }
+            if($v['kss_num'] > 0){
+                $content .= $v['kss_name'].':'.$v['kss_num'].';';
+            }
+            if($v['hl_num'] > 0){
+                $content .= $v['hl_name'].':'.$v['hl_num'].';';
+            }
+            if($v['qjmsg_desc']){
+                $content .= $v['qjmsg_desc'];
+            }
+            // 检查是否设置路线
+            $auto = Db::name('auto_user')
+                ->where('org_id',$orgId)
+                ->where('start',$start['id'])
+                ->where('end',$end['id'])
+                ->where('enable',1)
+                ->find();
+            $data = [
+                'org_id' => $orgId,
+                'dep_id' => $dep,
+                'order_mode' => $auto?5:1,
+                'content' => $content,
+                'sn' => get_unique_sn(get_config('sn_prefix')),
+                'user_id' => $userId,
+                'create_time' => date('Y-m-d H:i:s'),
+                'create_yyyy' => date('Y'),
+                'create_yyyymm' => date('Ym'),
+                'create_yyyymmdd' => date('Ymd'),
+                'source_type' => 2,
+                'work_type_mode' => 3
+            ];
+            if($auto){
+                $data['send_time'] = date('Y-m-d H:i:s');
+            }
+            
+            $ret = Db::name('orders')->insertGetId($data);
+            if (!$ret) {
+                exception('订单保存失败');
+            }
+            $orderId = $ret;
+
+            $cd = [
+                'order_id' => $orderId,
+                'type' => $cate,
+                'start' => $start['id'],
+                'end' => $end['id'],
+                'xq_time' => date('Y-m-d H:i:s'),
+                'ywc_time' => date('Y-m-d H:i:s',time() + 30*60),
+                'priority' => 2
+            ];
+            $res = Db::name('order_convey')->insert($cd);
+            if (!$res) {
+                exception('订单保存失败');
+            }
+            $wd = [
+                'is_deal'=>1,
+                'order_id'=>$orderId
+            ];
+            if($auto){
+                $wd['send_time'] = date('Y-m-d H:i:s');
+            }
+            // $res = Db::connect('db_config_jili')->name('wlps')->where('id',$v['id'])->update($wd);
+            $res = Db::name('wlps')->where('id',$v['id'])->update($wd);
+            if (!$res) {
+                exception('订单保存失败');
+            }
+
+            // 自动派单
+            if($auto){
+                //添加工单
+                $todo = array(
+                    'order_id' => $orderId,
+                    'todo_content' => '',
+                    'org_id' => $orgId,
+                    'create_time' => date('Y-m-d H:i:s'),
+                    'todo_mode' => 1, //待处理
+                    'work_type_mode' => 3,
+                    'to_user_id' => $auto['user_id']
+                );
+                $todores = $this->add_todo($todo);
+                if(!$todores){
+                    exception('工单添加失败');
+                }
+            }
+            $this->commit();
+
+            if($auto){
+                //极光推送
+                send_jpush(array($auto['user_id']),AppMsg::PUSH_WORKER_ORDER_SEND,'',['id'=>$todores]);
+            }
+
+            return true;
+        }catch (\Exception $e){
+            $this->rollback();
+            $this->error = $e->getMessage();
+            return false;
+        }
+    }
+    
+   public function add_todo($data){
+        try{
+            //TODO::检查是否存在重复工单
+            $data['create_yyyy'] = date('Y',strtotime($data['create_time']));
+            $data['create_yyyymm'] = date('Ym',strtotime($data['create_time']));
+            $data['create_yyyymmdd'] = date('Ymd',strtotime($data['create_time']));
+            $todoid = Db::name('todo')->insertGetId($data);
+            if(!$todoid){
+                exception('调度日志保存失败');
+            }
+
+            //添加调度记录
+            $dis = array(
+                'user_id' => $data['dispatch_user_id'],
+                'create_time' => $data['create_time'],
+                'content' => $data['todo_content'],
+                'order_id' => $data['order_id']
+            );
+            $dlid=Db::name('dispatch_log')->insert($dis);
+            if(!$dlid){
+                exception('调度日志保存失败');
+            }
+
+            return $todoid;
+        }catch (\Exception $e){
+            return false;
+        }
+    }
+
+    // 更新运送用户信息
+    public function updateYsUser($userId,$name,$phone,$rolesId,$orgId){
+        if($this->orgId != $orgId){
+            return true;
+        }
+        // 检查角色是否是运送工人
+        $roles = Db::name('roles')->where('id',$rolesId)->find();
+        if(!$roles || ($roles['parent_id'] != 6)){
+            return true;
+        }
+
+        // 检查用户是否已存在
+        $ysuser = Db::name('ysuser')->where('user_id',$userId)->find();
+        if(!$ysuser){
+            Db::name('ysuser')->insert([
+                'user_id' => $userId,
+                'name' => $name,
+                'phone' => $phone,
+                'jluser_id' => 'JL'.$userId
+            ]);
+        }else{
+            Db::name('ysuser')->where('id',$ysuser['id'])->update([
+                'name' => $name,
+                'phone' => $phone,
+            ]);
+        }
+
+        return true;
+    }
+
+    // 初始化运送用户信息
+    public function initYsUser(){
+        $rolesids = [];
+        $list = Db::name('roles')
+            ->whereLike('mode','%'.'182868')
+            ->where('org_id',$this->orgId)
+            ->where('enable',1)
+            ->column('roles_id');
+        foreach ($list as $kk=>$vv){
+            $rolesids[] = $vv['roles_id'];
+        }
+        if($rolesids){
+            $map[] = $this->whereIn('ur.roles_id',$rolesids);
+        }else{
+            $map[] = $this->where('ur.roles_id',-1);
+        }
+        $map = $map?$map:true;
+        $users = Db::name('user_roles')
+            ->alias('ur')
+            ->field('u.user_id,u.real_name,u.mobile')
+            ->join('user as u','u.user_id = ur.user_id')
+            ->join('roles as r','ur.roles_id = r.roles_id')
+            ->where('u.enable',1)
+            ->where('u.del_ref',0)
+            ->where($map)
+            ->select();
+        $users = $users?$users:[];
+        foreach ($users as $k=>$v){
+            // 检查用户是否已存在
+            $ysuser = Db::name('ysuser')->where('user_id',$v['user_id'])->find();
+            if(!$ysuser){
+                Db::name('ysuser')->insert([
+                    'user_id' => $v['user_id'],
+                    'name' => $v['real_name'],
+                    'phone' => $v['mobile'],
+                    'jluser_id' => 'JL'.$v['user_id']
+                ]);
+            }else{
+                Db::name('ysuser')->where('id',$ysuser['id'])->update([
+                    'name' => $v['real_name'],
+                    'phone' => $v['mobile'],
+                ]);
+            }
+        }
+        return true;
+    }
+}

+ 16 - 0
application/common/validate/AutoUser.php

@@ -0,0 +1,16 @@
+<?php
+namespace app\common\validate;
+
+use think\Validate;
+
+class AutoUser extends Validate{
+
+    protected $rule = [
+        'start|开始地点'  =>  'require',
+        'end|送达地点'  =>  'require',    
+        'user_id|人员'  =>  'require',    
+    ];
+
+
+}
+

+ 82 - 0
application/cron/Wlps.php

@@ -0,0 +1,82 @@
+<?php
+namespace app\cron;
+
+use think\Db;
+use yunwuxin\cron\Task;
+
+class Wlps extends Task
+{
+    public function configure()
+    {
+        $this->everyMinute(); //每分钟执行一次
+    }
+
+    /**
+     * 执行任务
+     * @return mixed
+     */
+    protected function execute()
+    {
+        try{
+            $this->ypconvey();
+            $this->cancelypconvey();
+        }catch (\Exception $e){
+            trace($e->getMessage());
+        }
+
+    }
+    
+    public function ypconvey(){
+        // $lists = Db::connect('db_config_jili')->name('wlps')->where('is_deal',0)->where('is_qx','N')->select();
+        $lists = Db::name('wlps')->where('is_deal',0)->where('is_qx','N')->select();
+        $lists = $lists?$lists:[];
+        foreach ($lists as $k=>$v){
+            (new \app\common\model\Wlps())->deal_wlps($v);
+        }
+    }
+    // 药品运送取消,每分钟查询一次
+    public function cancelypconvey(){
+        // $lists=Db::connect('db_config_jili')
+        //     ->name('wlps')
+        //     ->alias('a')
+        //     ->join('orders as b','a.order_id = b.order_id')
+        //     ->field('b.*')
+        //     ->whereIn('b.order_mode',[1,5])
+        //     ->where('b.del_ref',0)
+        //     ->where('a.order_id', '>',0)
+        //     ->where('a.is_qx','<>','N')
+        //     ->select();
+        $lists=Db::name('wlps')
+            ->alias('a')
+            ->join('orders as b','a.order_id = b.order_id')
+            ->field('b.*')
+            ->whereIn('b.order_mode',[1,5])
+            ->where('b.del_ref',0)
+            ->where('a.order_id', '>',0)
+            ->where('a.is_qx','<>','N')
+            ->select();
+        $lists = $lists?$lists:[];
+        foreach ($lists as $k=>$v){
+             $this->startTrans();
+            try{
+
+                $ret = Db::name('orders')->where('order_id',$v['order_id'])->update(['order_mode'=>2,'cancel_time'=>date('Y-m-d H:i:s')]);
+                if (!$ret) {
+                     exception('保存失败');
+                }
+
+                if($v['order_mode'] == 5){
+                    $res = Db::name('todo')->where('order_id',$v['order_id'])->whereIn('todo_mode',[1,2,3])->update(['todo_mode'=>6]);
+                    if (!$res) {
+                        exception('保存失败');
+                    }
+                }
+
+                $this->commit();
+            }catch (\Exception $e){
+            trace('error',$e->getMessage());
+            $this->rollback();
+            }
+        }
+    }
+}

+ 2 - 2
application/temperature/controller/Push.php

@@ -4,7 +4,7 @@ namespace app\temperature\controller;
 
 use think\Exception;
 use think\Db;
-require_once $_SERVER['DOCUMENT_ROOT'].'/../vendor/wenkong/TemperatureDevice.php';
+use tools\TemperatureDevice;
 
 class Push extends Base
 {
@@ -20,7 +20,7 @@ class Push extends Base
                 "del"=>0,
                 "enable"=>1,
             ])->column('snaddr');
-        $api = new \TemperatureDevice();
+        $api = new TemperatureDevice();
         try{
             if(empty($device)) return json(['msg'=>'操作成功']);
             $data = $api->getDevice(implode(',',$device));

+ 1 - 0
config/cron.php

@@ -20,5 +20,6 @@ return [
         \app\cron\TemperatureDevice::class,
         \app\cron\Orders::class,
         \app\cron\ConveyCron::class,
+        \app\cron\Wlps::class,
     ]
 ];

+ 12 - 0
config/database.php

@@ -93,4 +93,16 @@ return [
         'charset'     => 'utf8mb4',
         'prefix'      => '',
     ],
+
+    //吉利e联数据库
+    'db_config_jili' => [
+        'type'        => 'mysql',
+        'hostname'    => '124.71.235.188',
+        'database'    => 'jili_jya_tech_co',
+        'username'    => 'jili_jya_tech_co',
+        'password'    => '6pT8sD3b53dAfyYZ',
+        'hostport'    => 3306,
+        'charset'     => 'utf8mb4',
+        'prefix'      => '',
+    ],
 ];

+ 102 - 0
extend/tools/TemperatureDevice.php

@@ -0,0 +1,102 @@
+<?php
+namespace tools;
+
+class TemperatureDevice {
+    protected $produceUrl = 'http://yun.eefield.com/coop/api/';
+    protected $userName = '18610012796';
+    protected $pwd = '123456';
+    protected $login = false;
+
+    /**
+     *获取单个设备数据
+     *
+     * @author wst
+     * @date   2021/6/8 18:03
+     * @deviceId 设备id 多个用英文逗号隔开
+     */
+    public function getDevice($deviceId){
+        $token = $this->getToken();
+        try{
+            if (empty($token)) {
+               throw new \Exception('token获取失败');
+            }else{
+                $data = curl_post($this->produceUrl . 'device/intimeData.htm', ['accessToken' => $token
+                    ,"snaddrs"=>$deviceId]);
+                $data = json_decode($data, true);
+                if ($data['code'] == 0) {
+                    $r = [
+                        'success' => true,
+                        'msg' => '操作成功',
+                        'list' => $data['data']
+                    ];
+                }else {
+                    throw new \Exception($data['msg']);
+
+                }
+            }
+            return $r;
+        }catch (\Exception $e){
+              $r = [
+                  'success'=>false,
+                  'msg'=>$e->getMessage(),
+              ];
+            return $r;
+
+        }
+
+    }
+    /**
+     * 获取所有设备的基本信息
+     *
+     * @author wst
+     * @date   2021/6/8 17:50
+     */
+    public function getDeviceList() {
+        $token = $this->getToken();
+        try{
+            if (empty($token)) {
+                throw new \Exception('token获取失败');
+            }
+            else {
+                $data = curl_post($this->produceUrl . 'device/list.htm', ['accessToken' => $token]);
+                $data = json_decode($data, true);
+                if ($data['code'] == 0) {
+                    $r = [
+                        'success' => true,
+                        'msg' => '操作成功',
+                        'list' => $data['data']
+                    ];
+                }
+                else {
+                    throw new \Exception($data['msg']);
+                }
+            }
+            return $r;
+        }catch (\Exception $e){
+            $r = [
+                'success'=>false,
+                'msg'=>$e->getMessage(),
+            ];
+            return $r;
+        }
+
+    }
+    public function getToken() {
+        $cookie = cache('temperature_token');
+        //\think\facade\Cache::delete('aqg_cookie');
+        if (empty($cookie) || $cookie == 'false') {
+            $url = $this->produceUrl . 'token.htm';
+            $data = curl_post($url, ['user' => $this->userName, 'psw' => md5($this->pwd)]);
+            $data = json_decode($data, true);
+            if ($data['code'] == 0) {
+                $cookie = $data['accessToken'];
+                cache('temperature_token', $data['accessToken'], 604800);
+            }
+            else {
+                $cookie = false;
+
+            }
+        }
+        return $cookie;
+    }
+}