123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449 |
- <?php
- namespace app\admin\controller;
- use app\common\model\WashingRecord;
- use think\App;
- use think\Db;
- class WashRecord extends Auth
- {
- public function __construct(App $app = null) {
- parent::__construct($app);
- $this->table='washing_record';
- $this->model = new WashingRecord();
- }
- 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;
- $title = input('title','','trim');
- if($title!=''){
- $map[] = ['title','like','%'.$title.'%'];
- }
- $start1 = input('start','','trim');
- if($start1 != ''){
- $map[] = ['create_yyyymm','>=',date('Ymd',strtotime($start1))];
- }
- $end = input('end','','trim');
- if($end != ''){
- $map[] = ['create_yyyymm','<=',date('Ymd',strtotime($end))];
- }
- $mode = input('mode','','trim');
- if($mode!=''){
- $map[] = ['mode','=',$mode];
- }
- $dep_id = input('dep_id','','trim');
- if($dep_id!=''){
- $map[] = ['dep_id','=',$dep_id];
- }
- $map[] = ['del','=',0];
- $map[] = ['org_id','=',$this->orgId];
- $map= empty($map) ? true: $map;
- //数据查询
- $lists = db($this->table)->where($map)
- ->limit($start,$length)->order('id desc')->select();
- foreach ($lists as $k=>$v){
- $lists[$k]['real_name'] = Db::name('user')
- ->where('id',$v['user_id'])
- ->value('real_name');
- $lists[$k]['title'] = Db::name('address')
- ->where('id',$v['dep_id'])
- ->value('title');
- $items = Db::name('washing_record_item')
- ->where('washing_record_id',$v['id'])
- ->select();
- $s = '';
- if(!empty($items)){
- foreach ($items as $k1=>$v1){
- $it = Db::name('washing_items')
- ->where('id',$v1['items_id'])
- ->value('title');
- $s.=$it.':'.$v1['num'].' ';
- }
- }
- $lists[$k]['items'] = $s;
- }
- //数据返回
- $totalCount = db($this->table)->where($map)->count();
- $totalPage = ceil($totalCount/$length);
- $result['page'] = $page;
- $result['total'] = $totalPage;
- $result['records'] = $totalCount;
- $result['rows'] = $lists;
- return json($result);
- }else{
- $address = (new \app\common\model\Address())->getListByType(9,$this->orgId);
- $this->assign('address',$address);
- $this->assign('ids',is_login());
- return $this->fetch();
- }
- }
- public function returnWash($id) {
- if (!$id) {
- $this->error('参数错误');
- }
- $ret = $this->model->returnWash($id, $this->orgId);
- if (!$ret) {
- $this->error($this->model->getError());
- }
- // model('ActionLog')->addlog(is_login(),34,'洗涤记录:归还',['id' => $id],cur_org_id());
- $this->success('归还成功');
- }
- public function confirmWash($id) {
- if(!request()->isPost()){
- if (!$id) {
- $this->error('参数错误');
- }
- $this->assign('id',$id);
- return $this->fetch();
- }
- else {
- $sign = input('sign');
- $img = input('img');
- if (!$sign) {
- $this->error('请上传签名图');
- }
- $ret = $this->model->confirmWash($id, $this->orgId, $sign,$img);
- if (!$ret) {
- $this->error($this->model->getError());
- }
- // model('ActionLog')->addlog(is_login(),34,'洗涤记录:确认',['id' => $id],cur_org_id());
- $this->success('确认成功');
- }
- }
- /**
- * 新增/编辑
- */
- public function add($id=0){
- if(request()->isPost()){
- $data = request()->post();
- if (empty($data['dep_id'])) {
- $this->error('地点不能为空');
- }
- if (empty($data['items'])) {
- $this->error('物品不能为空');
- }
- $items = json_decode( $data['items'],true);
- if (empty($items)) {
- $this->error('物品不能为空');
- }
- foreach ($items as $k => $val) {
- if(empty($val['num'])){
- $this->error($val['title'] . '数量不能为空');
- }
- }
- foreach ($items as $k => $v) {
- $params['items'][$k] = [
- 'items_id' => $v['id'],
- 'num' => $v['num'],
- ];
- }
- $sqImg = input('sq_img','');
- $sqSign = input('sq_sign','');
- if(!$sqSign)$this->error('收取签名不能为空');
- $params['dep_id'] = $data['dep_id'];
- $params['org_id'] = $this->orgId;
- $params['user_id'] = $this->userId;
- $params['sq_img'] = $sqImg;
- $params['sq_sign'] = $sqSign;
- $res = $this->model->addSave($params);
- if($res){
- $this->success('操作成功',url('index'));
- }else{
- $this->error($this->model->getError());
- }
- }else{
- $address = (new \app\common\model\Address())->getListByType(9,$this->orgId);
- $this->assign('dep',$address);
- $items = (new \app\common\model\WashingItems())->getList($this->orgId);
- $this->assign('items',$items);
- return $this->fetch();
- }
- }
- /**
- * 删除记录
- * @param int $id
- */
- public function del($id=0){
- if(!$id){
- $this->error('参数错误');
- }
- $res = db($this->table)->where('id',$id)->update([
- 'del'=>1,
- 'del_time'=>getTime(),
- ]);
- if($res){
- // model('ActionLog')->addlog(is_login(),34,'洗涤记录:删除',['id' => $id],cur_org_id());
- $this->success('删除成功');
- }else{
- $this->error('删除失败');
- }
- }
- public function washRecordExport(){
- $start = input('start','','trim');
- if($start != ''){
- $map[] = ['create_yyyymm','>=',date('Ymd',strtotime($start))];
- }
- $end = input('end','','trim');
- if($end != ''){
- $map[] = ['create_yyyymm','<=',date('Ymd',strtotime($end))];
- }
- $mode = input('mode','','trim');
- if($mode!=''){
- $map[] = ['mode','=',$mode];
- }
- $dep_id = input('dep_id','','trim');
- if($dep_id!=''){
- $map[] = ['dep_id','=',$dep_id];
- }
- $map[] = ['del','=',0];
- $map[] = ['org_id','=',$this->orgId];
- $map= empty($map) ? true: $map;
- //数据查询
- $lists = Db::name('washing_record')->where($map)->order('id asc')->select();
- foreach ($lists as $k=>$v){
- $lists[$k]['real_name'] = Db::name('user')
- ->where('id',$v['user_id'])
- ->value('real_name');
- $lists[$k]['title'] = Db::name('address')
- ->where('id',$v['dep_id'])
- ->value('title');
- $items = Db::name('washing_record_item')
- ->where('washing_record_id',$v['id'])
- ->select();
- $s = '';
- if(!empty($items)){
- foreach ($items as $k1=>$v1){
- $it = Db::name('washing_items')
- ->where('id',$v1['items_id'])
- ->value('title');
- $s.=$it.':'.$v1['num'].' ';
- }
- }
- $lists[$k]['items'] = $s;
- }
- include_once env('root_path').'/extend/phpexcel/Classes/PHPExcel.php';
- //实例化PHPExcel类
- $objPHPExcel = new \PHPExcel();
- //激活当前的sheet表
- $objPHPExcel->setActiveSheetIndex(0);
- //设置表格头(即excel表格的第一行)
- $objActSheet = $objPHPExcel->setActiveSheetIndex(0)
- ->setCellValue('A1', '编号')
- ->setCellValue('B1', '操作人')
- ->setCellValue('C1', '地点')
- ->setCellValue('D1', '物品')
- ->setCellValue('E1', '领取时间')
- ->setCellValue('F1', '归还时间')
- ->setCellValue('G1', '确定时间')
- ->setCellValue('H1', '状态')
- ->setCellValue('I1', '收取签名')
- ->setCellValue('J1', '送达签名');
- // 设置表格头水平居中
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('A1')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('B1')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('C1')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('D1')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('E1')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('F1')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('G1')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('H1')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('I1')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('J1')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('K1')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('L1')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- //设置列水平居中
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('A')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('B')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('C')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('D')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('E')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('F')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('G')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('H')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('I')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('J')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('K')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('L')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- //设置单元格宽度
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('A')->setWidth(10);
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('B')->setWidth(20);
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('C')->setWidth(20);
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('D')->setWidth(20);
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('E')->setWidth(20);
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('F')->setWidth(50);
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('G')->setWidth(20);
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('H')->setWidth(20);
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('I')->setWidth(20);
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('J')->setWidth(20);
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('K')->setWidth(20);
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('L')->setWidth(20);
- //循环刚取出来的数组,将数据逐一添加到excel表格。
- for ($i = 0; $i < count($lists); $i++) {
- $objPHPExcel->getActiveSheet()->setCellValue('A' . ($i + 2), $lists[$i]['id']);
- $objPHPExcel->getActiveSheet()->setCellValue('B' . ($i + 2), $lists[$i]['real_name']);
- $objPHPExcel->getActiveSheet()->setCellValue('C' . ($i + 2), $lists[$i]['title']);
- $objPHPExcel->getActiveSheet()->setCellValue('D' . ($i + 2), $lists[$i]['items']);
- $objPHPExcel->getActiveSheet()->setCellValue('E' . ($i + 2), $lists[$i]['create_time']);
- $objPHPExcel->getActiveSheet()->setCellValue('F' . ($i + 2), $lists[$i]['return_time']);
- $objPHPExcel->getActiveSheet()->setCellValue('G' . ($i + 2), $lists[$i]['confirm_time']);
- if($lists[$i]['mode'] == 1){
- $objPHPExcel->getActiveSheet()->setCellValue('H' . ($i + 2),'已收取');
- }elseif($lists[$i]['mode'] == 2){
- $objPHPExcel->getActiveSheet()->setCellValue('H' . ($i + 2),'已归还');
- }else{
- $objPHPExcel->getActiveSheet()->setCellValue('H' . ($i + 2),'已确认');
- }
- $sqsignList = explode(".",$lists[$i]['sq_sign']);
- if($sqsignList){
- $ext = end($sqsignList);
- $img ='';
- if ($ext == 'jpg' || $ext == 'jpeg'){
- $img = @imagecreatefromjpeg($lists[$i]['sq_sign']);
- }
- if ($ext == 'png'){
- $img = @imagecreatefrompng($lists[$i]['sq_sign']);
- }
- if($img){
- //实例化图片操作类
- $objDrawing = new \PHPExcel_Worksheet_MemoryDrawing();
- $objDrawing->setImageResource($img);
- $objDrawing->setRenderingFunction(\PHPExcel_Worksheet_MemoryDrawing::RENDERING_DEFAULT);//渲染方法
- $objDrawing->setMimeType(\PHPExcel_Worksheet_MemoryDrawing::MIMETYPE_DEFAULT);
- $objDrawing->setHeight(40);//照片高度
- $objDrawing->setWidth(40); //照片宽度
- $objDrawing->setCoordinates('I'.($i+2));//图片要插入的单元格
- $objDrawing->setOffsetX(8);//图片X轴偏移
- $objDrawing->setOffsetY(8);//图片Y轴偏移
- $objDrawing->setWorksheet($objPHPExcel->getActiveSheet());
- //设置每一行高度
- }else{
- $objPHPExcel->getActiveSheet()->setCellValue('I' . ($i + 2), '');
- }
- }else{
- $objPHPExcel->getActiveSheet()->setCellValue('I' . ($i + 2), '');
- }
- $signList = explode(".",$lists[$i]['sign']);
- if($signList){
- $ext = end($signList);
- $img ='';
- if ($ext == 'jpg' || $ext == 'jpeg'){
- $img = @imagecreatefromjpeg($lists[$i]['sign']);
- }
- if ($ext == 'png'){
- $img = @imagecreatefrompng($lists[$i]['sign']);
- }
- if($img){
- //实例化图片操作类
- $objDrawing = new \PHPExcel_Worksheet_MemoryDrawing();
- $objDrawing->setImageResource($img);
- $objDrawing->setRenderingFunction(\PHPExcel_Worksheet_MemoryDrawing::RENDERING_DEFAULT);//渲染方法
- $objDrawing->setMimeType(\PHPExcel_Worksheet_MemoryDrawing::MIMETYPE_DEFAULT);
- $objDrawing->setHeight(40);//照片高度
- $objDrawing->setWidth(40); //照片宽度
- $objDrawing->setCoordinates('J'.($i+2));//图片要插入的单元格
- $objDrawing->setOffsetX(8);//图片X轴偏移
- $objDrawing->setOffsetY(8);//图片Y轴偏移
- $objDrawing->setWorksheet($objPHPExcel->getActiveSheet());
- //设置每一行高度
- }else{
- $objPHPExcel->getActiveSheet()->setCellValue('J' . ($i + 2), '');
- }
- }else{
- $objPHPExcel->getActiveSheet()->setCellValue('J' . ($i + 2), '');
- }
- $objActSheet->getRowDimension($i + 2)->setRowHeight(40); // 行高
- }
- //设置保存的Excel表格名称
- $filename = '洗涤记录'.'_' . date('YmdHis', time()) . '.xls';
- //设置当前激活的sheet表格名称
- $objPHPExcel->getActiveSheet()->setTitle('洗涤记录');
- //设置浏览器窗口下载表格
- ob_end_clean();
- header("Content-Type: application/force-download");
- header("Content-Type: application/octet-stream");
- header("Content-Type: application/download");
- header('Content-Disposition:inline;filename="' . $filename);
- //生成excel文件
- $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
- //下载文件在浏览器窗口
- return $objWriter->save('php://output');
- }
- }
|