123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398 |
- <?php
- namespace app\admin\controller;
- use think\Db;
- class AssetItems extends Auth
- {
- public function index($cateId=0){
- $title = input('title','','trim');
- if($title){
- $map[] = ['title|sn','like','%'.$title.'%'];
- }
- $classId = input('class_id','');
- if($classId !=''){
- $map[] = ['class_id','=',$classId];
- }
- $addId = input('add_id','');
- if($addId !=''){
- $map[] = ['add_id','=',$addId];
- }
- $enable = input('enable','');
- if($enable !=''){
- $map[] = ['enable','=',$enable];
- }
- if($cateId > 0){
- $map[] = ['cate_id','=',$cateId];
- }
- $map[] = ['org_id','=',cur_org_id()];
- $map[] = ['del','=',0];
- if(request()->isAjax()){
- //分页参数
- $length = input('rows',10,'intval'); //每页条数
- $page = input('page',1,'intval'); //第几页
- $start = ($page - 1) * $length; //分页开始位置
- //排序
- $sortRow = input('sidx','id','trim'); //排序列
- $sort = input('sort','desc','trim'); //排序方式
- $order = $sortRow.' '.$sort;
- $map= empty($map) ? true: $map;
- //数据查询
- $lists = Db::name('asset_items')->where($map)->limit($start,$length)->order('id desc')->select();
- foreach ($lists as $k=>$v){
- $lists[$k]['statusTxt'] = model('asset_items')->statusTxt[$v['enable']];
- $lists[$k]['cateName'] = Db::name('asset_cate')->where('id',$v['cate_id'])->value('title');
- $lists[$k]['className'] = Db::name('asset_class')->where('id',$v['class_id'])->value('title');
- $lists[$k]['addName'] = Db::name('asset_add')->where('id',$v['add_id'])->value('title');
- $lists[$k]['unitName'] = Db::name('asset_unit')->where('id',$v['unit_id'])->value('title');
- $lists[$k]['print'] = $v['print'] == 1 ?'是':'否';
- $ly = Db::name('asset_receive_items')
- ->alias('ari')
- ->join('asset_items ai','ai.id=ari.items_id')
- ->where('ari.items_id',$v['id'])
- ->where('ai.enable',2)
- ->find();
- $lists[$k]['is_ly'] = $ly ? 1 : 0;
- $lists[$k]['userName'] = Db::name('user')->where('id',$v['user_id'])->value('real_name');
- $lists[$k]['depName'] = Db::name('dep')->where('id',$v['dep_id'])->value('title');
- }
- //数据返回
- $totalCount = Db::name('asset_items')->where($map)->count();
- $totalPage = ceil($totalCount/$length);
- $result['page'] = $page;
- $result['total'] = $totalPage;
- $result['records'] = $totalCount;
- $result['rows'] = $lists;
- $countPrice = Db::name('asset_items')->where($map)->sum('price');
- $result['countPrice'] = $countPrice;
- return json($result);
- }else{
- $class = model('AssetClass')->getList($this->orgId);
- $this->assign('class',$class);
- $add = model('AssetAdd')->getList($this->orgId);
- $this->assign('add',$add);
- $tree = model('AssetCate')->showAllTree();
- $this->assign('tree',$tree);
- $this->assign('cateId',$cateId);
- $cateTitle = Db::name('asset_cate')->where('id',$cateId)->value('title');
- $this->assign('cateTitle',$cateTitle);
- $countPrice = Db::name('asset_items')->where($map)->sum('price');
- $this->assign('countPrice',$countPrice);
- return $this->fetch();
- }
- }
- /**
- * 新增/编辑
- */
- public function add($id=0){
- if(request()->isPost()){
- $res = model('asset_items')->updates();
- if($res){
- $this->success('操作成功',url('index'));
- }else{
- $this->error(model('asset_items')->getError());
- }
- }else{
- if($id){
- $info = db('asset_items')->where('id',$id)->find();
- $this->assign('info',$info);
- }
- $class = model('AssetClass')->getList($this->orgId);
- $this->assign('class',$class);
- $add = model('AssetAdd')->getList($this->orgId);
- $this->assign('add',$add);
- $unit= model('AssetUnit')->getList($this->orgId);
- $this->assign('unit',$unit);
- $tree = model('AssetCate')->formatAllTree();
- $this->assign('tree',$tree);
- return $this->fetch();
- }
- }
- public function edit($id=0){
- if(request()->isPost()){
- $res = model('asset_items')->updates();
- if($res){
- $this->success('操作成功',url('index'));
- }else{
- $this->error(model('asset_items')->getError());
- }
- }else{
- if($id){
- $info = db('asset_items')->where('id',$id)->find();
- $this->assign('info',$info);
- }
- $class = model('AssetClass')->getList($this->orgId);
- $this->assign('class',$class);
- $add = model('AssetAdd')->getList($this->orgId);
- $this->assign('add',$add);
- $unit= model('AssetUnit')->getList($this->orgId);
- $this->assign('unit',$unit);
- $tree = model('AssetCate')->formatAllTree();
- $this->assign('tree',$tree);
- return $this->fetch();
- }
- }
- /**
- * 删除记录
- * @param int $id
- */
- public function del($id=0){
- if(!$id){
- $this->error('参数错误');
- }
- $res = Db::name('asset_items')->where('id',$id)->setField('del',1);
- if($res){
- $this->success('删除成功');
- }else{
- $this->error('删除失败');
- }
- }
- public function print($id=0){
- $info = Db::name('asset_items')->where('id',$id)->find();
- $this->assign('info',$info);
- return $this->fetch();
- }
- public function export(){
- $title = input('title','','trim');
- if($title){
- $map[] = ['title|sn','like','%'.$title.'%'];
- }
- $classId = input('class_id','');
- if($classId !=''){
- $map[] = ['class_id','=',$classId];
- }
- $addId = input('add_id','');
- if($addId !=''){
- $map[] = ['add_id','=',$addId];
- }
- $enable = input('enable','');
- if($enable !=''){
- $map[] = ['enable','=',$enable];
- }
- $cateId = input('cateId',0);
- if($cateId > 0){
- $map[] = ['cate_id','=',$cateId];
- }
- $map[] = ['org_id','=',cur_org_id()];
- $map[] = ['del','=',0];
- $lists = Db::name('asset_items')->where($map)->order('id desc')->select();
- foreach ($lists as $k=>$v){
- $lists[$k]['statusTxt'] = model('asset_items')->statusTxt[$v['enable']];
- $lists[$k]['cateName'] = Db::name('asset_cate')->where('id',$v['cate_id'])->value('title');
- $lists[$k]['className'] = Db::name('asset_class')->where('id',$v['class_id'])->value('title');
- $lists[$k]['addName'] = Db::name('asset_add')->where('id',$v['add_id'])->value('title');
- $lists[$k]['unitName'] = Db::name('asset_unit')->where('id',$v['unit_id'])->value('title');
- $lists[$k]['print'] = $v['print'] == 1 ?'是':'否';
- }
- include_once env('root_path').'/extend/phpexcel/Classes/PHPExcel.php';
- //实例化PHPExcel类
- $objPHPExcel = new \PHPExcel();
- //激活当前的sheet表
- $objPHPExcel->setActiveSheetIndex(0);
- //设置表格头(即excel表格的第一行)
- $objPHPExcel->setActiveSheetIndex(0)
- ->setCellValue('A1', '编号')
- ->setCellValue('B1', '名称')
- ->setCellValue('C1', '规格')
- ->setCellValue('D1', '数量')
- ->setCellValue('E1', '状态')
- ->setCellValue('F1', '类型')
- ->setCellValue('G1', '类别')
- ->setCellValue('H1', '增加方式')
- ->setCellValue('I1', '品牌')
- ->setCellValue('J1', '原值')
- ->setCellValue('K1', '存放地点')
- ->setCellValue('L1', '资产用途')
- ->setCellValue('M1', '购买日期')
- ->setCellValue('N1', '是否打印标签')
- ->setCellValue('O1', '备注')
- ;
- // 设置表格头水平居中
- $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('M1')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('N1')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('O1')->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)->getStyle('M')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('N')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objPHPExcel->setActiveSheetIndex(0)->getStyle('O')->getAlignment()
- ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- //设置单元格宽度
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('A')->setWidth(30);
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('B')->setWidth(30);
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('C')->setWidth(30);
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('D')->setWidth(30);
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('E')->setWidth(30);
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('F')->setWidth(30);
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('G')->setWidth(30);
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('H')->setWidth(30);
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('I')->setWidth(30);
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('J')->setWidth(30);
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('K')->setWidth(30);
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('L')->setWidth(30);
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('M')->setWidth(30);
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('N')->setWidth(30);
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('O')->setWidth(30);
- //循环刚取出来的数组,将数据逐一添加到excel表格。
- for ($i = 0; $i < count($lists); $i++) {
- $objPHPExcel->getActiveSheet()->setCellValue('A' . ($i + 2), $lists[$i]['sn']);
- $objPHPExcel->getActiveSheet()->setCellValue('B' . ($i + 2), $lists[$i]['title']);
- $objPHPExcel->getActiveSheet()->setCellValue('C' . ($i + 2), $lists[$i]['spec']);
- $objPHPExcel->getActiveSheet()->setCellValue('D' . ($i + 2), $lists[$i]['nums']);
- $objPHPExcel->getActiveSheet()->setCellValue('E' . ($i + 2), $lists[$i]['statusTxt']);
- $objPHPExcel->getActiveSheet()->setCellValue('F' . ($i + 2), $lists[$i]['cateName']);
- $objPHPExcel->getActiveSheet()->setCellValue('G' . ($i + 2), $lists[$i]['className']);
- $objPHPExcel->getActiveSheet()->setCellValue('H' . ($i + 2), $lists[$i]['addName']);
- $objPHPExcel->getActiveSheet()->setCellValue('I' . ($i + 2), $lists[$i]['brand']);
- $objPHPExcel->getActiveSheet()->setCellValue('J' . ($i + 2), $lists[$i]['price']);
- $objPHPExcel->getActiveSheet()->setCellValue('K' . ($i + 2), $lists[$i]['address']);
- $objPHPExcel->getActiveSheet()->setCellValue('L' . ($i + 2), $lists[$i]['used']);
- $objPHPExcel->getActiveSheet()->setCellValue('M' . ($i + 2), $lists[$i]['buy_time']);
- $objPHPExcel->getActiveSheet()->setCellValue('N' . ($i + 2), $lists[$i]['print']);
- $objPHPExcel->getActiveSheet()->setCellValue('O' . ($i + 2), $lists[$i]['remark']);
- }
- //设置保存的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');
- }
- public function qrcode($id=0){
- $info = Db::name('asset_items')->where('org_id',$this->orgId)->where('id',$id)->find();
- $code = get_qrcode_str('asset',$id);
- $config = config('app.addr_url');
- $code = $config.$code;
- $this->assign('code',$code);
- $this->assign('info',$info);
- return $this->fetch();
- }
- public function allot($id=0){
- if(request()->isPost()){
- $data = request()->post();
- if($data['receive_user_id'] < 1){
- $this->error('被调拨人不能为空');
- }
- $receiveDepId = db('user_dep')->where('user_id',$data['receive_user_id'])->value('dep_id');
- $adata = [
- 'user_id'=>is_login(),
- 'allot_user_id'=>$data['receive_user_id'],
- 'allot_dep_id'=>$receiveDepId,
- 'items_id'=>$data['id'],
- 'org_id'=>cur_org_id(),
- 'create_time'=>date('Y-m-d H:i:s')
- ];
- Db::name('asset_allot')->insert($adata);
- $res = Db::name('asset_items')->where('id',$data['id'])->update(['user_id'=>$data['receive_user_id'],'dep_id'=>$receiveDepId]);
- if($res){
- $this->success('操作成功',url('index'));
- }else{
- $this->error('操作失败');
- }
- }else{
- if($id){
- $info = db('asset_receive')
- ->alias('ar')
- ->field('ar.*,ari.items_id')
- ->join('asset_receive_items ari','ari.receive_id=ar.id')
- ->where('ari.items_id',$id)
- ->find();
- $info['user_name'] = Db::name('user')->where('id',$info['receive_user_id'])->value('real_name');
- $this->assign('info',$info);
- }
- $userList = model('WorkTypeMode')->getWorkerUser(cur_org_id());
- $this->assign('userList',$userList);
- return $this->fetch();
- }
- return $this->fetch();
- }
- }
|