123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814 |
- <?php
- namespace app\admin\controller;
- use app\common\model\User;
- use app\hander\HelpHander;
- use think\App;
- use think\Db;
- use think\Exception;
- class WasteRecord extends Auth {
- public function __construct(App $app = null) {
- parent::__construct($app);
- $this->model = new \app\common\model\WasteRecord();
- $this->table = $this->model->table;
- }
- 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;
- $cateid = input('cateid', '', 'trim');
- if ($cateid) {
- $map[] = ['cateid', 'like', '%' . $cateid . '%'];
- }
- $start_time = input('start', '', 'trim');
- $end_time = input('end', '', 'trim');
- if ($start_time !== '' && $end_time !== '') {
- if ($start_time <= $end_time) {
- $start_time = date('Ymd', strtotime($start_time));
- $end_time = date('Ymd', strtotime($end_time));
- $map[] = ['create_yyyymmdd', 'between', [$start_time, $end_time]];
- }
- }
- if ($start_time !== '' && $end_time == '') {
- $start_time = date('Ymd', strtotime($start_time));
- $map[] = ['create_yyyymmdd', '>=', $start_time];
- }
- if ($start_time == '' && $end_time !== '') {
- $end_time = date('Ymd', strtotime($end_time));
- $map[] = ['create_yyyymmdd', '<=', $end_time];
- }
- $status = input('status', '', 'trim');
- if ($status != '') {
- if ($status == 4) {
- $map[] = ['status', 'in', [0, 1]];
- }
- else {
- if (in_array($status, array(0, 1, 2, 3))) {
- $map[] = ['status', '=', $status];
- }
- }
- }
- $post = request()->post();
- if (!isset($post['status'])) {
- $map[] = ['status', 'in', [0, 1]];
- }
- $map[] = ['del', '=', 0];
- $map[] = ['org_id', '=', $this->orgId];
- $map = empty($map) ? true : $map;
- //数据查询
- $lists = db($this->table)
- ->where($map)
- ->limit($start, $length)
- ->order($order)
- ->select();
- foreach ($lists as $k => $v) {
- $lists[$k]['waste_device'] = db('address')
- ->where('id', $v['waste_device_id'])
- ->value('title');
- $lists[$k]['real_name'] = db('user')
- ->where('id', $v['user_id'])
- ->value('real_name');
- $lists[$k]['cate'] = db('waste_type')
- ->where('id', $v['cateid'])
- ->value('title');
- // $lists[$k]['weight'] = round($v['weight'] / 1000, 2);
- $lists[$k]['serial_number_path'] = url('Qrcode/qrcode') . '?code=' . $v['serial_number'];
- $lists[$k]['status'] = $this->model->status[$v['status']];
- $type = Db::name('waste_type')
- ->where('id', $v['cateid'])
- ->find();
- $num = '';
- if($type['type'] == 1 && $v['num'] > 0){
- $num = ' ('.$v['num'].$type['unit'].')';
- }
- $lists[$k]['weight'] = round($v['weight'] / 1000, 2).$num;
- }
- //数据返回
- $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 {
- $type = (new \app\common\model\WasteType())->getList($this->orgId);
- $this->assign('m_name', '医废类型');
- $this->assign('type', $type);
- $this->assign('status', $this->model->status);
- return $this->fetch();
- }
- }
- // 科室医废
- public function index2() {
- if (request()->isAjax()) {
- $depId = Db::name('user_dep')->where("user_id",$this->userId)->value('dep_id');
- $addrs = [];
- $alists = model("Address")->getListByType(7,$this->orgId);
- foreach ($alists as $k=>$v){
- if($v['dep_id'] == $depId){
- $addrs[] = $v['id'];
- }
- }
- //分页参数
- $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;
- $cateid = input('cateid', '', 'trim');
- if ($cateid) {
- $map[] = ['cateid', 'like', '%' . $cateid . '%'];
- }
- $start_time = input('start', '', 'trim');
- $end_time = input('end', '', 'trim');
- if ($start_time !== '' && $end_time !== '') {
- if ($start_time <= $end_time) {
- $start_time = date('Ymd', strtotime($start_time));
- $end_time = date('Ymd', strtotime($end_time));
- $map[] = ['create_yyyymmdd', 'between', [$start_time, $end_time]];
- }
- }
- if ($start_time !== '' && $end_time == '') {
- $start_time = date('Ymd', strtotime($start_time));
- $map[] = ['create_yyyymmdd', '>=', $start_time];
- }
- if ($start_time == '' && $end_time !== '') {
- $end_time = date('Ymd', strtotime($end_time));
- $map[] = ['create_yyyymmdd', '<=', $end_time];
- }
- $status = input('status', '', 'trim');
- if ($status != '') {
- if ($status == 4) {
- $map[] = ['status', 'in', [0, 1]];
- }
- else {
- if (in_array($status, array(0, 1, 2, 3))) {
- $map[] = ['status', '=', $status];
- }
- }
- }
- $post = request()->post();
- if (!isset($post['status'])) {
- $map[] = ['status', 'in', [0, 1]];
- }
- $map[] = ['waste_device_id', 'in', $addrs];
- $map[] = ['del', '=', 0];
- $map[] = ['org_id', '=', $this->orgId];
- $map = empty($map) ? true : $map;
- //数据查询
- $lists = db($this->table)->where($map)
- ->limit($start, $length)
- ->order($order)->select();
- foreach ($lists as $k => $v) {
- $lists[$k]['waste_device'] = db('address')
- ->where('id', $v['waste_device_id'])
- ->value('title');
- $lists[$k]['real_name'] = db('user')
- ->where('id', $v['user_id'])
- ->value('real_name');
- $lists[$k]['cate'] = db('waste_type')
- ->where('id', $v['cateid'])
- ->value('title');
- // $lists[$k]['weight'] = round($v['weight'] / 1000, 2);
- $lists[$k]['serial_number_path'] = url('Qrcode/qrcode') . '?code=' . $v['serial_number'];
- $lists[$k]['status'] = $this->model->status[$v['status']];
- $type = Db::name('waste_type')
- ->where('id', $v['cateid'])
- ->find();
- $num = '';
- if($type['type'] == 1 && $v['num'] > 0){
- $num = ' ('.$v['num'].$type['unit'].')';
- }
- $lists[$k]['weight'] = round($v['weight'] / 1000, 2).$num;
- }
- //数据返回
- $totalCount = db($this->table)->where($map)->count();
- $totalPage = ceil($totalCount / $length);
- $result['page'] = $page;
- $result['total'] = $totalPage;
- $result['records'] = $totalCount;
- $result['rows'] = $lists;
- $types = (new \app\common\model\WasteType())->getList($this->orgId);
- $tname = '';
- foreach ($types as $k=>$v){
- $weight = db($this->table)->where($map)->where('cateid',$v['id'])->sum('weight');
- $tname .= $v['title'].':'.round($weight/1000,2).'kg'.' ';
- if($v['type'] == 1){
- $num = db($this->table)->where($map)->where('cateid',$v['id'])->sum('num');
- $tname .= $v['title'].':'.round($weight/1000,2).'kg'.'('.$num.$v['unit'].' ) ';
- }
- // $types[$k]['weight'] = round($weight/1000,2);
- }
- $result['tnames'] = $tname;
- return json($result);
- }
- else {
- $type = (new \app\common\model\WasteType())->getList($this->orgId);
- $this->assign('m_name', '医废类型');
- $this->assign('type', $type);
- $this->assign('status', $this->model->status);
- return $this->fetch();
- }
- }
- // 所有科室医废
- public function index3() {
- 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;
- $cateid = input('cateid', '', 'trim');
- if ($cateid) {
- $map[] = ['cateid', 'like', '%' . $cateid . '%'];
- }
- $start_time = input('start', '', 'trim');
- $end_time = input('end', '', 'trim');
- if ($start_time !== '' && $end_time !== '') {
- if ($start_time <= $end_time) {
- $start_time = date('Ymd', strtotime($start_time));
- $end_time = date('Ymd', strtotime($end_time));
- $map[] = ['create_yyyymmdd', 'between', [$start_time, $end_time]];
- }
- }
- if ($start_time !== '' && $end_time == '') {
- $start_time = date('Ymd', strtotime($start_time));
- $map[] = ['create_yyyymmdd', '>=', $start_time];
- }
- if ($start_time == '' && $end_time !== '') {
- $end_time = date('Ymd', strtotime($end_time));
- $map[] = ['create_yyyymmdd', '<=', $end_time];
- }
- $status = input('status', '', 'trim');
- if ($status != '') {
- if ($status == 4) {
- $map[] = ['status', 'in', [0, 1]];
- }
- else {
- if (in_array($status, array(0, 1, 2, 3))) {
- $map[] = ['status', '=', $status];
- }
- }
- }
- $post = request()->post();
- if (!isset($post['status'])) {
- $map[] = ['status', 'in', [0, 1]];
- }
- $map[] = ['del', '=', 0];
- $map[] = ['org_id', '=', $this->orgId];
- $map = empty($map) ? true : $map;
- //数据查询
- $lists = db($this->table)->where($map)
- ->limit($start, $length)
- ->order($order)->select();
- foreach ($lists as $k => $v) {
- $lists[$k]['waste_device'] = db('address')
- ->where('id', $v['waste_device_id'])
- ->value('title');
- $lists[$k]['real_name'] = db('user')
- ->where('id', $v['user_id'])
- ->value('real_name');
- $lists[$k]['cate'] = db('waste_type')
- ->where('id', $v['cateid'])
- ->value('title');
- $lists[$k]['weight'] = round($v['weight'] / 1000, 2);
- $lists[$k]['serial_number_path'] = url('Qrcode/qrcode') . '?code=' . $v['serial_number'];
- $lists[$k]['status'] = $this->model->status[$v['status']];
- $type = Db::name('waste_type')
- ->where('id', $v['cateid'])
- ->find();
- $num = '';
- if($type['type'] == 1 && $v['num'] > 0){
- $num = ' ('.$v['num'].$type['unit'].')';
- }
- $lists[$k]['weight'] = round($v['weight'] / 1000, 2).$num;
- }
- //数据返回
- $totalCount = db($this->table)->where($map)->count();
- $totalPage = ceil($totalCount / $length);
- $result['page'] = $page;
- $result['total'] = $totalPage;
- $result['records'] = $totalCount;
- $result['rows'] = $lists;
- // $weight = db($this->table)->where($map)->sum('weight');
- // $result['weight'] = round($weight/1000,2);
- $types = (new \app\common\model\WasteType())->getList($this->orgId);
- // foreach ($types as $k=>$v){
- // $weight = db($this->table)->where($map)->where('cateid',$v['id'])->sum('weight');
- // $types[$k]['weight'] = round($weight/1000,2);
- // }
- $tname = '';
- foreach ($types as $k=>$v){
- $weight = db($this->table)->where($map)->where('cateid',$v['id'])->sum('weight');
- $tname .= $v['title'].':'.round($weight/1000,2).'kg'.' ';
- if($v['type'] == 1){
- $num = db($this->table)->where($map)->where('cateid',$v['id'])->sum('num');
- $tname .= $v['title'].':'.round($weight/1000,2).'kg'.'('.$num.$v['unit'].' ) ';
- }
- // $types[$k]['weight'] = round($weight/1000,2);
- }
- $result['tnames'] = $tname;
- $result['types'] = $types;
- return json($result);
- }
- else {
- $type = (new \app\common\model\WasteType())->getList($this->orgId);
- $this->assign('m_name', '医废类型');
- $this->assign('type', $type);
- $this->assign('status', $this->model->status);
- return $this->fetch();
- }
- }
- public function add($id=0){
- if(request()->isPost()){
- $data = [
- 'org_id' => $this->orgId,
- 'user_id' => input('user_id/d',0),
- 'waste_device_id' => input('waste_device_id/d',0),
- 'cateid' =>input('cateid/d',0),
- 'weight' => input('weight',0),
- 'create_time' => input('create_time'),
- 'status' => 0,
- 'is_print' => 0,
- 'num'=>input('num',0)
- ];
- if(!$data['waste_device_id']){
- $this->error('未选择收取科室');
- }
- if(!$data['cateid']){
- $this->error('类型不能为空');
- }
- $type = Db::name('waste_type')->where('id',$data['cateid'])->find();
- if(!$type){
- $this->error('类型不存在');
- }
- if($type['type'] == 0 && $data['weight'] <= 0){
- $this->error('重量不能为空');
- }
- if($type['type'] == 1 && $data['num'] <= 0){
- HelpHander::error('数量不能为空');
- }
- if(!$data['create_time']){
- $this->error('未选择收取时间');
- }
- $waste_record_id = $this->model->saverecord($data);
- if(!$waste_record_id){
- HelpHander::error($this->model->getError());
- }
- $this->success('操作成功',url('index'));
- }else{
- $addrs = model("Address")->getListByType(7,$this->orgId);
- $this->assign('addrs', $addrs);
- $type = (new \app\common\model\WasteType())->getList($this->orgId);
- $this->assign('type', $type);
- $this->assign('user',(new User())->getWasteWorker());
- return $this->fetch();
- }
- }
- /**
- * 详情
- *
- * @author wst
- * @date 2021/9/8 17:29
- * @return array
- */
- public function info($id = 0) {
- $info = $this->model->info($id,cur_org_id());
- if (!$info) {
- $this->error('记录不存在');
- }
- $this->assign('info', $info);
- return $this->fetch();
- }
- /**
- * 转运
- *
- * @author wst
- * @date 2021/9/8 17:48
- * @param int $id
- * @return bool
- */
- public function finish($id) {
- $info = $this->model->getOne($id,cur_org_id());
- if (!$info) {
- $this->error('记录不存在');
- }
- if ($info['status'] != 1) {
- $this->error('处于已交接状态的才可转运');
- }
- $ret = $this->model->finish($id, is_login());
- $ret ? $this->success('转运成功') : $this->error($this->model->getError());
- }
- /**
- * 批量转运
- *
- * @author wst
- * @date 2021/9/8 17:48
- * @param array $ids
- * @return bool
- */
- public function batchFinish() {
- $ids = input('ids', [], 'trim');
- if (empty($ids)) {
- $this->error('未选择记录');
- }
- $success = 0;
- $error = '';
- foreach ($ids as $k => $v) {
- $info = $this->model->getOne($v,cur_org_id());
- if (!$info) {
- $error .= 'id='.$v . ':记录不存在';
- continue;
- }
- if ($info['status'] != 1) {
- $error .= '当前状态不可转运';
- continue;
- }
- $ret = $this->model->finish($v, is_login());
- if ($ret) {
- $success++;
- }
- else {
- $error .= 'id='.$v.':' . $this->model->getError();
- }
- }
- $success ? $this->success('成功转运' . $success . '条记录') : $this->error($error);
- }
- /**
- * 删除记录
- * @param int $id
- */
- public function del($id = 0) {
- if (!$id) {
- $this->error('参数错误');
- }
- $res = db($this->table)->where('id', $id)->update([
- 'del' => 1,
- 'del_user_id' => is_login(),
- 'del_datetime' => getTime(),
- ]);
- if ($res) {
- $this->success('删除成功');
- }
- else {
- $this->error('删除失败');
- }
- }
- //excel导出
- public function export() {
- $meta_title = '医废记录';
- if (request()->isGet()) {
- $cateid = input('cateid', '', 'trim');
- if ($cateid) {
- $map[] = ['cateid', 'like', '%' . $cateid . '%'];
- }
- $start_time = input('start', '', 'trim');
- $end_time = input('end', '', 'trim');
- if ($start_time !== '' && $end_time !== '') {
- if ($start_time <= $end_time) {
- $start_time = date('Ymd', strtotime($start_time));
- $end_time = date('Ymd', strtotime($end_time));
- $map[] = ['create_yyyymmdd', 'between', [$start_time, $end_time]];
- }
- }
- if ($start_time !== '' && $end_time == '') {
- $start_time = date('Ymd', strtotime($start_time));
- $map[] = ['create_yyyymmdd', '>=', $start_time];
- }
- if ($start_time == '' && $end_time !== '') {
- $end_time = date('Ymd', strtotime($end_time));
- $map[] = ['create_yyyymmdd', '<=', $end_time];
- }
- $status = input('status', '', 'trim');
- if ($status != '') {
- if ($status == 4) {
- $map[] = ['status', 'in', [0, 1]];
- }
- else {
- if (in_array($status, array(0, 1, 2, 3))) {
- $map[] = ['status', '=', $status];
- }
- }
- }
- $map[] = ['del', '=', 0];
- $map[] = ['org_id', '=', $this->orgId];
- $map = empty($map) ? true : $map;
- //数据查询
- $lists = db($this->table)->where($map)->select();
- foreach ($lists as $k => $v) {
- $lists[$k]['waste_device'] = db('address')
- ->where('id', $v['waste_device_id'])
- ->value('title');
- $lists[$k]['real_name'] = db('user')
- ->where('id', $v['user_id'])
- ->value('real_name');
- $lists[$k]['cate'] = db('waste_type')
- ->where('id', $v['cateid'])
- ->value('title');
- // $lists[$k]['weight'] = round($v['weight'] / 1000, 2);
- $lists[$k]['serial_number_path'] = url('Qrcode/qrcode') . '?code=' . $v['serial_number'];
- $lists[$k]['status'] = $this->model->status[$v['status']];
- $type = Db::name('waste_type')
- ->where('id', $v['cateid'])
- ->find();
- $num = '';
- if($type['type'] == 1 && $v['num'] > 0){
- $num = ' ('.$v['num'].$type['unit'].')';
- }
- $lists[$k]['weight'] = round($v['weight'] / 1000, 2).$num;
- }
- include_once env('root_path').'/extend/phpexcel/Classes/PHPExcel.php';
- //实例化PHPExcel类
- $objPHPExcel = new \PHPExcel();
- //激活当前的sheet表
- $objActSheet = $objPHPExcel->setActiveSheetIndex(0);
- //设置表格头(即excel表格的第一行)
- $objPHPExcel->setActiveSheetIndex(0)
- ->setCellValue('A1', '编号')
- ->setCellValue('B1', '收取地点')
- ->setCellValue('C1', '收取人')
- ->setCellValue('D1', '类别')
- ->setCellValue('E1', '重量(kg)')
- ->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('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)->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);
- //循环刚取出来的数组,将数据逐一添加到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]['waste_device']);
- $objPHPExcel->getActiveSheet()->setCellValue('C' . ($i + 2), $lists[$i]['real_name']);
- $objPHPExcel->getActiveSheet()->setCellValue('D' . ($i + 2), $lists[$i]['cate']);
- $objPHPExcel->getActiveSheet()->setCellValue('E' . ($i + 2), $lists[$i]['weight']);
- $objPHPExcel->getActiveSheet()->setCellValue('F' . ($i + 2), $lists[$i]['create_time']);
- $objPHPExcel->getActiveSheet()->setCellValue('G' . ($i + 2), $lists[$i]['status']);
- $objPHPExcel->getActiveSheet()->setCellValue('H' . ($i + 2), $lists[$i]['reason']);
- $sign_text = '否';
- if($lists[$i]['sign'] == 1){
- $sign_text = '是';
- }
- $objPHPExcel->getActiveSheet()->setCellValue('I' . ($i + 2), $sign_text);
- $signList = explode(".",$lists[$i]['sign_path']);
- if($signList){
- $ext = end($signList);
- $img ='';
- if ($ext == 'jpg' || $ext == 'jpeg'){
- $img = @imagecreatefromjpeg($lists[$i]['sign_path']);
- }
- if ($ext == 'png'){
- $img = @imagecreatefrompng($lists[$i]['sign_path']);
- }
- 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 = $meta_title.'_' . date('YmdHis', time()) . '.xls';
- //设置当前激活的sheet表格名称
- $objPHPExcel->getActiveSheet()->setTitle($meta_title);
- //设置浏览器窗口下载表格
- 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');
- }
- }
- public function allZy(){
- $ids = Db::name('waste_record')
- ->where('org_id',$this->orgId)
- ->where('del',0)
- ->where('status',1)
- ->column('id');
- if($ids){
- // 启动事务
- Db::startTrans();
- try {
- $ret = Db::name('waste_record')
- ->whereIn('id', $ids)
- ->update(['status'=>2]);
- if(!$ret){
- throw new Exception('更新状态失败');
- }
- foreach ($ids as $k=>$v){
- $ret2 = Db::name('waste_record_user')->insert(array(
- 'waste_record_id' => $v,
- 'user_id' => $this->userId,
- 'status' => 2,
- 'create_time' => getTime()
- ));
- if(!$ret2){
- throw new exception('保存操作记录失败');
- }
- }
- // 提交事务
- Db::commit();
- } catch (\Exception $e) {
- // 回滚事务
- Db::rollback();
- }
- $this->success('成功转运' . count($ids) . '条记录');
- }else{
- $this->success('成功转运');
- }
- }
- public function apply() {
- $id= input('id', '');
- if (empty($id)) {
- $this->error('未选择记录');
- }
- $info = $this->model->getOne($id,cur_org_id());
- $info['type'] = Db::name('waste_type')->where('id',$info['cateid'])->value('type');
- if (!$info) {
- $this->error('医废记录不存在');
- }
- if (request()->isPost()) {
- $data = request()->post();
- $check = Db::name('waste_apply')
- ->where('record_id',$id)
- ->where('del',0)
- ->where('status',0)
- ->find();
- if ($check) {
- $this->error('当前记录正在申请中');
- }
- $old = Db::name('waste_record')
- ->where('id',$info['id'])
- ->find();
- $key = ['user_id','cateid','weight','waste_device_id','num'];
- $su = 0;
- foreach ($key as $kk=>$vv){
- if($data[$vv]!=$old[$vv]){
- $su++;
- }
- }
- if($su==0){
- $this->error('当前数据未做修改');
- }
- $data['record_id'] = $data['id'];
- $data['org_id'] =$this->orgId;
- $data['create_time'] = getTime();
- unset($data['id']);
- $result = validate('WasteApply')->check($data,[],'');
- if(true !== $result){
- $this->error(validate('WasteApply')->getError());
- }
- $data['old_data'] = json_encode($old);
- $res = Db::name('waste_apply')->insertGetId($data);
- $res?$this->success('操作成功'):$this->error('操作失败');
- }else{
- $scan = Db::name('waste_scale')
- ->where('enable',1)
- ->where('del',0)
- ->where('org_id',cur_org_id())
- ->select();
- $uList = [];
- if(!empty($scan)){
- $uList = Db::name('user')
- ->where('del',0)
- ->where('id','in',array_column($scan,'user_id'))
- ->field('id,real_name as title')
- ->select();
- }
- $type = model('WasteType')->getList($this->orgId);
- $addr = model('Address')->getListByType(7,$this->orgId);
- $this->assign('addr', $addr);
- $this->assign('type', $type);
- $this->assign('uList',$uList);
- $this->assign('info',$info);
- $uInfo = Db::name('user')
- ->where('id',$this->userId)
- ->find();
- $this->assign('uInfo',$uInfo);
- return $this->fetch();
- }
- }
- public function wasteType(){
- $id = input('id');
- $info = Db::name('waste_type')->where('id',$id)->find();
- $this->success('操作成功','',$info);
- }
- }
|