123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376 |
- <?php
- namespace app\admin\controller;
- use think\App;
- use think\Db;
- use think\Exception;
- class Settled extends Auth
- {
- protected $status = [
- 0=>'待分配',
- 1=>'进行中',
- 2=>'已完成',
- 3=>'已作废',
- 4=>'已结算'
- ];
- public function index(){
- if(request()->isAjax()){
- //分页参数
- $length = input('rows',10,'intval'); //每页条数
- $page = input('page',1,'intval'); //第几页
- $start = ($page - 1) * $length; //分页开始位置
- //排序
- $sortRow = input('sidx','u.id','trim'); //排序列
- $sort = input('sord','desc','trim'); //排序方式
- $order = 'a.id desc';
- $title = input('title','','trim');//用户
- if($title){
- $user = Db::name('user')
- ->alias('u')
- ->join('user_org uo','uo.user_id = u.id')
- ->where('u.real_name','like','%'.$title.'%')
- ->where('uo.org_id',$this->orgId)
- ->column('u.id');
- if(!empty($user)){
- $map[] = ['a.user_id','in',$user];
- }else{
- $map[] = ['a.user_id','=',0];
- }
- }
- $title1 = input('title1','','trim');//护工
- if($title1){
- $user = Db::name('worker')
- ->where('name','like','%'.$title1.'%')
- ->where('org_id',$this->orgId)
- ->column('id');
- if(!empty($user)){
- $ids = Db::name('todo')
- ->where('worker_id','in',$user)
- ->column('order_id');
- if(empty($ids)){
- $map[] = ['a.id','=',0];
- }else{
- $map[] = ['a.id','in',$ids];
- }
- }else{
- $map[] = ['a.id','=',0];
- }
- }
- $sn = input('sn','','trim');
- if($sn){
- $map[] = ['a.sn','=',$sn];
- }
- $settlement = input('settlement','','trim');
- if($settlement!=''){
- $map[] = ['a.settlement','=',$settlement];
- }
- $completion = input('completion','','trim');
- if($completion!=''){
- $map[] = ['a.completion','=',$completion];
- }
- $is_make_account = input('is_make_account','','trim');
- if($is_make_account!=''){
- $map[] = ['a.is_make_account','=',$is_make_account];
- }
- $addrId = input('addrId','','trim');
- if($addrId){
- $map[] = ['a.addr_id','=',$addrId];
- }
- $query = Db::name('ph_orders')->alias('a');
- $map[] = ['a.status','=',4];
- $map[] = ['a.org_id','=',$this->orgId];
- $b = input('begin','','trim');
- $e = input('end','','trim');
- if($b){
- $b = date('Y-m-d 00:00:00',strtotime($b));
- $map[] = ['a.create_time','>=',$b];
- }
- if($b){
- $e = date('Y-m-d 23:59:59',strtotime($e));
- $map[] = ['a.create_time','<=',$e];
- }
- $query1 = $query;
- $map= empty($map) ? true: $map;
- //数据查询
- $lists = $query->where($map)
- ->field('a.*')
- ->limit($start,$length)
- ->order($order)
- ->select();
- foreach ($lists as $k=>$v){
- $lists[$k]['userName'] = Db::name('user')
- ->where('id',$v['user_id'])
- ->value('real_name');
- $lists[$k]['depName'] = '';
- $lists[$k]['cateName'] = '';
- if($v['cate_id'] > 0){
- $lists[$k]['cateName'] = Db::name('cate')
- ->where('id',$v['cate_id'])
- ->value('title');
- }
- if($v['dep_id'] > 0){
- $lists[$k]['depName'] = Db::name('dep')
- ->where('id',$v['dep_id'])
- ->value('title');
- }
- }
- //数据返回
- $query2 = clone $query;
- $query3 = clone $query;
- $query4 = clone $query;
- $query5 = clone $query;
- $totalCount = $query1->alias('a')
- ->where($map)->count();
- $totalPage = ceil($totalCount/$length);
- $totalMoney = $query2->alias('a')
- ->where($map)->sum('a.settlement_money');
- $totalMoney1 = $query3->alias('a')
- ->where($map)->sum('a.amount');
- $result['totalMoney'] = $totalMoney;
- $result['zsr'] = $totalMoney1;
- $result['page'] = $page;
- $result['total'] = $totalPage;
- $result['records'] = $totalCount;
- $result['rows'] = $lists;
- return json($result);
- }else{
- $this->assign('status',$this->status);
- return $this->fetch();
- }
- }
- public function detail($id=0){
- $model = new \app\common\model\PhOrders();
- $info = $model->getInfo($id);
- if(!$info){
- $this->error('订单不存在');
- }
- $this->assign('info',$info);
- return $this->fetch();
- }
- //excel导出
- public function export(){
- if(request()->isGet()){
- $order = 'a.id desc';
- $title = input('title','','trim');//用户
- if($title){
- $user = Db::name('user')
- ->alias('u')
- ->join('user_org uo','uo.user_id = u.id')
- ->where('u.real_name','like','%'.$title.'%')
- ->where('uo.org_id',$this->orgId)
- ->column('u.id');
- if(!empty($user)){
- $map[] = ['a.user_id','in',$user];
- }else{
- $map[] = ['a.user_id','=',0];
- }
- }
- $title1 = input('title1','','trim');//护工
- if($title1){
- $user = Db::name('worker')
- ->where('name','like','%'.$title1.'%')
- ->where('org_id',$this->org_id)
- ->column('id');
- if(!empty($user)){
- $ids = Db::name('todo')
- ->where('worker_id','in',$user)
- ->column('order_id');
- if(empty($ids)){
- $map[] = ['a.id','=',0];
- }else{
- $map[] = ['a.id','in',$ids];
- }
- }else{
- $map[] = ['a.id','=',0];
- }
- }
- $sn = input('sn','','trim');
- if($sn){
- $map[] = ['a.sn','=',$sn];
- }
- $settlement = input('settlement','','trim');
- if($settlement!=''){
- $map[] = ['a.settlement','=',$settlement];
- }
- $completion = input('completion','','trim');
- if($completion!=''){
- $map[] = ['a.completion','=',$completion];
- }
- $is_make_account = input('is_make_account','','trim');
- if($is_make_account!=''){
- $map[] = ['a.is_make_account','=',$is_make_account];
- }
- $addrId = input('addrId','','trim');
- if($addrId){
- $map[] = ['a.addr_id','=',$addrId];
- }
- $query = Db::name('ph_orders')->alias('a');
- $map[] = ['a.status','=',4];
- $map[] = ['a.org_id','=',$this->orgId];
- $b = input('begin','','trim');
- $e = input('end','','trim');
- if($b){
- $b = date('Y-m-d 00:00:00',strtotime($b));
- $map[] = ['a.create_time','>=',$b];
- }
- if($b){
- $e = date('Y-m-d 23:59:59',strtotime($e));
- $map[] = ['a.create_time','<=',$e];
- }
- $query1 = $query;
- $map= empty($map) ? true: $map;
- //数据查询
- $lists = $query->where($map)
- ->field('a.*')
- ->order($order)
- ->select();
- foreach ($lists as $k=>$v){
- $lists[$k]['userName'] = Db::name('user')
- ->where('id',$v['user_id'])
- ->value('real_name');
- $lists[$k]['depName'] = '';
- $lists[$k]['cateName'] = '';
- if($v['cate_id'] > 0){
- $lists[$k]['cateName'] = Db::name('cate')->where('id',$v['cate_id'])->value('title');
- }
- if($v['dep_id'] > 0){
- $lists[$k]['depName'] = Db::name('dep')->where('id',$v['dep_id'])->value('title');
- }
- }
- //实例化PHPExcel类
- include_once env('root_path') . '/extend/phpexcel/Classes/PHPExcel.php';
- $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', '下单时间');
- // 设置表格头水平居中
- $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('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)->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);
- $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('M')->setWidth(20);
- //循环刚取出来的数组,将数据逐一添加到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]['contact']);
- $objPHPExcel->getActiveSheet()->setCellValue('C' . ($i + 2), $lists[$i]['phone']);
- $objPHPExcel->getActiveSheet()->setCellValue('D' . ($i + 2), $lists[$i]['depName']);
- $objPHPExcel->getActiveSheet()->setCellValue('E' . ($i + 2), $lists[$i]['cateName']);
- $objPHPExcel->getActiveSheet()->setCellValue('F' . ($i + 2), $lists[$i]['amount']);
- $objPHPExcel->getActiveSheet()->setCellValue('G' . ($i + 2), $lists[$i]['settlement_money']);
- $objPHPExcel->getActiveSheet()->setCellValue('H' . ($i + 2), $lists[$i]['create_time']);
- }
- //设置保存的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');
- }
- }
- }
|