input('id/d',0), 'title' => input('title','','trim'), 'sn' => input('sn','','trim'), 'remark' => input('remark','','trim'), 'org_id' => input('orgId/d',0), 'enable' => input('enable/d',1), ]; $logdata = json_encode($data); $result = validate('Car')->check($data,[],''); if(true !== $result){ HelpHander::error(validate('Car')->getError()); } $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){ HelpHander::error('操作失败'); } if($id > 0){ $content = '修改车辆'; }else{ $content = '添加车辆'; } model('ActionLog')->add(10,$content,0,$logdata); return true; } public function info($id){ $info = $this->where('id',$id)->find(); if(!$info){ HelpHander::error('数据不存在'); } return $info->toArray(); } public function lists($page,$size,$title,$enable,$orgId){ $map[] = ['del','=',0]; $map[] = ['org_id','=',$orgId]; if($title != ''){ $map[] = ['title|sn','like','%'.$title.'%']; } if($enable >= 0){ $map[] = ['enable','=',$enable]; } $lists = $this ->where($map) ->page($page,$size) ->order('id desc') ->select(); $total = $this->where($map)->count(); $data = [ 'total' => $total, 'list' => $lists?$lists->toArray():[] ]; return $data; } public function all($orgId){ $map[] = ['del','=',0]; $map[] = ['enable','=',1]; $map[] = ['org_id','=',$orgId]; $lists = $this ->where($map) ->field('id,title,sn') ->order('id asc') ->select(); $lists = $lists?$lists->toArray():[]; foreach ($lists as $k=>$v){ $lists[$k]['title'] = $v['title'].' ['.$v['sn'].']'; unset($lists[$k]['sn']); } return $lists; } public function del($id){ $ret = $this->where('id',$id)->setField('del',1); if(!$ret){ HelpHander::error('删除失败'); } $logdata = json_encode(['id' => $id]); model('ActionLog')->add(10,'删除车辆',0,$logdata); return true; } public function record($page,$size,$carId,$orgId){ $map[] = ['status','=',1]; $map[] = ['org_id','=',$orgId]; if($carId > 0){ $map[] = ['car_id','=',$carId]; } $lists = Db::name('car_record') ->where($map) ->page($page,$size) ->order('id desc') ->select(); $lists = $lists?$lists:[]; foreach ($lists as $k=>$v){ $lists[$k]['userPhone'] = Db::name('user')->where('id',$v['user_id'])->value('phone'); $lists[$k]['userName'] = Db::name('user_info')->where('user_id',$v['user_id'])->value('name'); $car = Db::name('car')->where('id',$v['car_id'])->find(); $lists[$k]['carName'] = $car?$car['title'].' ['.$car['sn'].']':''; $lists[$k]['depName'] = Db::name('dep')->where('id',$v['dep_id'])->value('name'); } $total = Db::name('car_record')->where($map)->count(); $data = [ 'total' => $total, 'list' => $lists?$lists:[] ]; return $data; } public function export($carId,$orgId){ $map[] = ['status','=',1]; $map[] = ['org_id','=',$orgId]; if($carId > 0){ $map[] = ['car_id','=',$carId]; } $lists = Db::name('car_record') ->where($map) ->order('id desc') ->select(); $lists = $lists?$lists:[]; foreach ($lists as $k=>$v){ $lists[$k]['userPhone'] = Db::name('user')->where('id',$v['user_id'])->value('phone'); $lists[$k]['userName'] = Db::name('user_info')->where('user_id',$v['user_id'])->value('name'); $car = Db::name('car')->where('id',$v['car_id'])->find(); $lists[$k]['carName'] = $car?$car['title'].' ['.$car['sn'].']':''; $lists[$k]['depName'] = Db::name('dep')->where('id',$v['dep_id'])->value('name'); } $columns[] = ["title" => "申请人","key" => "userName"]; $columns[] = ["title" => "联系电话","key" => "userPhone"]; $columns[] = ["title" => "部门","key" => "depName"]; $columns[] = ["title" => "车辆","key" => "carName"]; $columns[] = ["title" => "出车时间","key" => "startTime"]; $columns[] = ["title" => "交车时间","key" => "endTime"]; $columns[] = ["title" => "事由","key" => "reason"]; $columns[] = ["title" => "出车地点","key" => "address"]; $columns[] = ["title" => "驾驶员","key" => "driver"]; $columns[] = ["title" => "出车里程","key" => "start"]; $columns[] = ["title" => "交车里程","key" => "end"]; $data = [ 'columns' => $columns, 'list' => $lists?$lists:[] ]; return $data; } }