123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785 |
- <?php
- namespace app\admin\controller;
- use think\App;
- use think\Db;
- use think\Exception;
- class Todo extends Auth
- {
- public function __construct(App $app = null) {
- parent::__construct($app);
- $this->model= new \app\common\model\Todo();
- $this->table='todo_view';
- }
- //工单列表
- public function index(){
- $mode = input('mode',0);
- $quality_type = input('quality_type','');
- 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;
- $content = input('content','','trim');
- if($content){
- $map[] = ['content','like','%'.$content.'%'];
- }
- $name = input('name','','trim');
- if($name){
- $map[] = ['to_real_name','like','%'.$name.'%'];
- }
- $todo_mode = input('todo_mode','','trim');
- if($todo_mode != ''){
- if($todo_mode==100){//已挂起
- $map[] = ['todo_mode','=',2];
- $map[] = ['pause','=',1];
- }else{
- $map[] = ['todo_mode','=',$todo_mode];
- }
- }
- $b = input('start','','trim');
- $e = input('end','','trim');
- if($b){
- $b = date('Ymd',strtotime($b));
- $map[] = ['create_yyyymmdd','>=',$b];
- }
- if($e){
- $e = date('Ymd',strtotime($e));
- $map[] = ['create_yyyymmdd','<=',$e];
- }
- $map[] = ['org_id','=',$this->orgId];
- if($mode==-1){//一键呼叫订单
- $map[] = ['source_type','=',4];
- }
- if($mode==-2){ //一键呼叫工单
- $map[] = ['work_type_mode','=',0];
- }
- if($mode == 15){ // 品质检查,单独处理
- $map[] = ['work_type_mode','=',$mode];
- if($quality_type !=''){
- $map[] = ['quality_type','=',$quality_type];
- }
- }else{
- $work_type_mode = input('work_type_mode','','trim');
- if(!is_admin($this->userId)){
- $auth = get_dispatch_auth($this->userId);
- if($auth){
- $map[] = ['work_type_mode', 'in', $auth];
- if($mode > 0){
- $map[] = ['work_type_mode', '=', $mode];
- }else{
- if($work_type_mode!=''){
- $map[] = ['work_type_mode','=',$work_type_mode];
- }
- }
- }else{
- $map[] = ['work_type_mode', '=', -1];
- }
- }else{
- if($mode > 0){
- $map[] = ['work_type_mode', '=', $mode];
- }else{
- if($work_type_mode!=''){
- $map[] = ['work_type_mode','=',$work_type_mode];
- }
- }
- }
- }
- $sn = input('sn', '', 'trim');
- if ($sn) {
- $map[] = ['sn', 'like', '%' . $sn . '%'];
- }
- $order_sn = input('order_sn', '', 'trim');
- if ($order_sn) {
- $map[] = ['order_sn', 'like', '%' . $order_sn . '%'];
- }
- $dep_cate = input('dep_cate', '', 'trim');
- if ($dep_cate != '') {
- $depIds = Db::name('dep')
- ->where('org_id',$this->orgId)
- ->where('cate_id',$dep_cate)
- ->where('del',0)
- ->column('id');
- if(!empty($depIds)){
- $map[] = ['dep_id', 'in', $depIds];
- }else{
- $map[] = ['dep_id', '=', -1];
- }
- }
- $from = input('from', '', 'trim');
- if ($from) {
- if($from >3){
- $map[] = ['from','=',0];
- $map[] = ['work_type_mode','=',$from-3];
- }else{
- $map[] = ['from','=',$from];
- }
- }
- $map= empty($map) ? true: $map;
- //数据查询
- $lists = db($this->table)->where($map)
- ->limit($start,$length)
- ->order($order)->select();
- foreach ($lists as $k=>$v){
- $lists[$k] = $this->model->newFormatTodo($v);
- }
- //数据返回
- $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{
- if($mode>0){
- $mode_name = $this->getTableField('work_type_mode',['id'=>$mode],'name');
- }else{
- $mode_name = '';
- }
- $auths = [1,2,3,4,15,0];
- if(!is_admin($this->userId)){
- $auth = get_dispatch_auth($this->userId);
- if($auth){
- $auths = array_intersect($auths,$auth);
- if($mode > 0){
- $auths = array_intersect($auths,[$mode]);
- }
- }else{
- $auths = [];
- }
- }
- $this->assign('auths',$auths);
- $todo_order_mode = Db::name('todo_mode')
- ->select();
- $this->assign('todo_mode_list',$todo_order_mode);
- $this->assign('m_name',$mode_name);
- $this->assign('mode',$mode);
- $this->assign('quality_type',$quality_type);
- $dep_cate = model('DepCate')->getList();
- $this->assign('dep_cate',$dep_cate);
- $is = 0;
- if(!isset($_GET['quality_type']) && $mode==15){
- $is = 1;
- }
- $this->assign('is',$is);
- if($mode==1){
- return $this->fetch('index1');
- }else if ($mode==3){
- return $this->fetch('index3');
- }else if ($mode==0 || $mode==-1){
- return $this->fetch('index0');
- }else{
- return $this->fetch('index');
- }
- }
- }
- //用户取消订单
- public function cancel($id){
- $res = $this->model->cancel($id,$this->userId);
- if(!$res){
- $this->error($this->model->getError());
- }
- $this->success('取消成功');
- }
- //调度取消订单
- public function disCancel($id){
- if(request()->isGet()){
- $this->assign('id',$id);
- return $this->fetch();
- }else{
- $reason = input('cancel_reason');
- $res = $this->model->cancel($id,$reason);
- if(!$res){
- $this->error($this->model->getError());
- }
- $this->success('取消成功');
- }
- }
- //工单详情
- public function detail($id){
- if (!$id) {
- $this->error('参数错误');
- }
- $order = Db::name('todo_view')->where(['id' => $id])->find();
- $order = $this->model->formatTodo($order);
- $order['images'] = !empty($order['images'])?explode(',',$order['images']):'';
- $order['to_ok_images'] = !empty($order['to_ok_images'])?explode(',',$order['to_ok_images']):'';
- $this->assign('info', $order);
- $workTypeName = $this->getTableField('work_type_mode',['id'=>$order['work_type_mode']],'name');
- $this->assign('meta_title', $workTypeName.'工单详情');
- return $this->fetch();
- }
- //调度删除订单
- public function del($id=0){
- if(!$id){
- $this->error('参数错误');
- }
- $model = (new \app\common\model\Orders());
- $res = $model->del($id,$this->userId);
- if(!$res){
- $this->error($model->getError());
- }
- $this->success('删除成功');
- }
- //派单
- public function send($id,$mode=1){
- if(request()->isGet()){
- $this->assign('id',$id);
- $this->assign('mode',$mode);
- if($mode==1){
- $order_type = (new \app\common\model\OrderType())->getList();
- $address = (new \app\common\model\Address())->getListByType(1);
- $todoInfo = Db::name('todo')
- ->where('id',$id)
- ->find();
- $order_repair = Db::name('order_repair')
- ->where('order_id',$todoInfo['order_id'])
- ->find();
- $this->assign('order_repair',$order_repair);
- $this->assign('order_type_list',$order_type);
- $this->assign('address_list',$address);
- }
- $this->assign('send_user_num',model('orders')->sendUserNum($mode,$this->orgId));
- $this->assign('user_list',(new \app\common\model\WorkTypeMode())->getRolesUser($mode,$this->orgId,1));
- return $this->fetch();
- }else{
- $data = request()->post();
- $data['org_id'] = $this->orgId;
- $res = $this->model->send($id,$this->userId,$data);
- if(!$res){
- $this->error($this->model->getError());
- }
- $this->success('操作成功');
- }
- }
- //完成工单
- public function finish($id){
- $res = $this->model->finish($id);
- if(!$res){
- $this->error($this->model->getError());
- }
- $this->success('操作成功');
- }
- public function removeEmojiChar($str)
- {
- $mbLen = mb_strlen($str);
- $strArr = [];
- for ($i = 0; $i < $mbLen; $i++) {
- $mbSubstr = mb_substr($str, $i, 1, 'utf-8');
- if (strlen($mbSubstr) >= 4) {
- continue;
- }
- $strArr[] = $mbSubstr;
- }
- return implode('', $strArr);
- }
- //excel导出
- public function export($mode) {
- set_time_limit(0);
- ini_set("memory_limit", "1024M");
- $meta_title = '工单列表';
- if ($mode == 1) {
- $meta_title = '报修' . $meta_title;
- }
- elseif ($mode == 2) {
- $meta_title = '保洁' . $meta_title;
- }
- elseif ($mode == 3) {
- $meta_title = '运送' . $meta_title;
- }
- elseif ($mode == 4) {
- $meta_title = '安保' . $meta_title;
- }
- elseif ($mode == 15) {
- $meta_title = '品质整改' . $meta_title;
- }elseif ($mode == -1) {
- $meta_title = '一键呼叫' . $meta_title;
- }
- $quality_type = input('quality_type','');
- if (request()->isGet()) {
- //排序
- $sortRow = input('sidx','id','trim'); //排序列
- $sort = input('sord','desc','trim'); //排序方式
- $order = $sortRow.' '.$sort;
- $content = input('content','','trim');
- if($content){
- $map[] = ['content','like','%'.$content.'%'];
- }
- $name = input('name','','trim');
- if($name){
- $map[] = ['to_real_name','like','%'.$name.'%'];
- }
- $todo_mode = input('todo_mode','','trim');
- if($todo_mode != ''){
- if($todo_mode==100){//已挂起
- $map[] = ['todo_mode','=',2];
- $map[] = ['pause','=',1];
- }else{
- $map[] = ['todo_mode','=',$todo_mode];
- }
- }
- $b = input('start','','trim');
- $e = input('end','','trim');
- if($b){
- $b = date('Ymd',strtotime($b));
- $map[] = ['create_yyyymmdd','>=',$b];
- }
- if($e){
- $e = date('Ymd',strtotime($e));
- $map[] = ['create_yyyymmdd','<=',$e];
- }
- $map[] = ['org_id','=',$this->orgId];
- if($mode==-1){//一键呼叫订单
- $map[] = ['source_type','=',4];
- }
- if($mode == 15){ // 品质检查,单独处理
- $map[] = ['work_type_mode','=',$mode];
- if($quality_type !=''){
- $map[] = ['quality_type','=',$quality_type];
- }
- }else{
- $work_type_mode = input('work_type_mode','','trim');
- if(!is_admin($this->userId)){
- $auth = get_dispatch_auth($this->userId);
- if($auth){
- $map[] = ['work_type_mode', 'in', $auth];
- if($mode > 0){
- $map[] = ['work_type_mode', '=', $mode];
- }else{
- if($work_type_mode!=''){
- $map[] = ['work_type_mode','=',$work_type_mode];
- }
- }
- }else{
- $map[] = ['work_type_mode', '=', -1];
- }
- }else{
- if($mode > 0){
- $map[] = ['work_type_mode', '=', $mode];
- }else{
- if($work_type_mode!=''){
- $map[] = ['work_type_mode','=',$work_type_mode];
- }
- }
- }
- }
- $sn = input('sn', '', 'trim');
- if ($sn) {
- $map[] = ['sn', 'like', '%' . $sn . '%'];
- }
- $order_sn = input('order_sn', '', 'trim');
- if ($order_sn) {
- $map[] = ['order_sn', 'like', '%' . $order_sn . '%'];
- }
- $dep_cate = input('dep_cate', '', 'trim');
- if ($dep_cate != '') {
- $depIds = Db::name('dep')
- ->where('org_id',$this->orgId)
- ->where('cate_id',$dep_cate)
- ->where('del',0)
- ->column('id');
- if(!empty($depIds)){
- $map[] = ['dep_id', 'in', $depIds];
- }else{
- $map[] = ['dep_id', '=', -1];
- }
- }
- $from = input('from', '', 'trim');
- if ($from) {
- if($from >3){
- $map[] = ['from','=',0];
- $map[] = ['work_type_mode','=',$from-3];
- }else{
- $map[] = ['from','=',$from];
- }
- }
- $map= empty($map) ? true: $map;
- //数据查询
- $lists = db($this->table)->where($map)
- ->order($order)->select();
- foreach ($lists as $k=>$v){
- $lists[$k] = $this->model->newFormatTodo($v);
- $lists[$k]['content'] = $this->removeEmojiChar($v['content']);
- }
- include_once env('root_path') . '/extend/phpexcel/Classes/PHPExcel.php';
- //实例化PHPExcel类
- $objPHPExcel = new \PHPExcel();
- //激活当前的sheet表
- $objActSheet = $objPHPExcel->setActiveSheetIndex(0);
- //设置表格头(即excel表格的第一行)
- if ($mode == 1) {
- $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', '接单时长')
- ->setCellValue('P1', '处理时长')
- ->setCellValue('Q1', '挂起开始时间')
- ->setCellValue('R1', '挂起结束时间')
- ->setCellValue('S1', '挂起时长')
- ->setCellValue('T1', '所在科室/部门')
- ->setCellValue('U1', '来源')
- ->setCellValue('V1', '部门分类')
- ->setCellValue('w1', '签名图');
- }
- else {
- if ($mode == 3) {
- $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', '状态')
- ->setCellValue('P1', '调度分派时长')
- ->setCellValue('Q1', '接单时长')
- ->setCellValue('R1', '处理时长')
- ->setCellValue('S1', '所在科室/部门')
- ->setCellValue('T1', '来源')
- ->setCellValue('U1', '部门分类');
- }
- else {
- if($mode==0){
- $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', '所在科室/部门')
- ->setCellValue('P1', '来源')
- ->setCellValue('Q1', '部门分类');
- }else{
- $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', '来源')
- ->setCellValue('P1', '部门分类');
- }
- }
- }
- // 设置表格头水平居中
- $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表格。
- if ($mode == 1) {
- for ($i = 0; $i < count($lists); $i++) {
- $objPHPExcel->getActiveSheet()->setCellValue('A' . ($i + 2), $lists[$i]['sn']);
- $objPHPExcel->getActiveSheet()->setCellValue('B' . ($i + 2), $lists[$i]['order_sn']);
- $objPHPExcel->getActiveSheet()->setCellValue('C' . ($i + 2), $lists[$i]['real_name']);
- $objPHPExcel->getActiveSheet()->setCellValue('D' . ($i + 2), $lists[$i]['to_real_name']);
- $objPHPExcel->getActiveSheet()->setCellValue('E' . ($i + 2), $lists[$i]['order_type']);
- $objPHPExcel->getActiveSheet()->setCellValue('F' . ($i + 2), $lists[$i]['order_type_matter']);
- $objPHPExcel->getActiveSheet()->setCellValue('G' . ($i + 2), $lists[$i]['address_title']);
- $objPHPExcel->getActiveSheet()->setCellValue('H' . ($i + 2), $lists[$i]['content']);
- $objPHPExcel->getActiveSheet()->setCellValue('I' . ($i + 2), $lists[$i]['create_time']);
- $objPHPExcel->getActiveSheet()->setCellValue('J' . ($i + 2), $lists[$i]['to_create_time']);
- $objPHPExcel->getActiveSheet()->setCellValue('K' . ($i + 2), $lists[$i]['confirm_time']);
- $objPHPExcel->getActiveSheet()->setCellValue('L' . ($i + 2), $lists[$i]['done_time']);
- $objPHPExcel->getActiveSheet()->setCellValue('M' . ($i + 2), $lists[$i]['todo_mode_in_content']);
- $objPHPExcel->getActiveSheet()->setCellValue('N' . ($i + 2), $lists[$i]['dispatch_time']);
- $objPHPExcel->getActiveSheet()->setCellValue('O' . ($i + 2), $lists[$i]['jiedan_time']);
- $objPHPExcel->getActiveSheet()->setCellValue('P' . ($i + 2), $lists[$i]['time_cost']);
- $objPHPExcel->getActiveSheet()->setCellValue('Q' . ($i + 2), $lists[$i]['pause_time']);
- $objPHPExcel->getActiveSheet()->setCellValue('R' . ($i + 2), $lists[$i]['pause_end']);
- $objPHPExcel->getActiveSheet()->setCellValue('S' . ($i + 2), $lists[$i]['pause_cost']);
- $objPHPExcel->getActiveSheet()->setCellValue('T' . ($i + 2), $lists[$i]['dep']);
- $objPHPExcel->getActiveSheet()->setCellValue('U' . ($i + 2), $lists[$i]['source_type_text']);
- $objPHPExcel->getActiveSheet()->setCellValue('V' . ($i + 2), $lists[$i]['dep_cate_name']);
- $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('W'.($i+2));//图片要插入的单元格
- $objDrawing->setOffsetX(8);//图片X轴偏移
- $objDrawing->setOffsetY(8);//图片Y轴偏移
- $objDrawing->setWorksheet($objPHPExcel->getActiveSheet());
- //设置每一行高度
- }else{
- $objPHPExcel->getActiveSheet()->setCellValue('W' . ($i + 2), '');
- }
- }else{
- $objPHPExcel->getActiveSheet()->setCellValue('W' . ($i + 2), '');
- }
- $objActSheet->getRowDimension($i + 2)->setRowHeight(40); // 行高
- }
- }
- else {
- if ($mode == 3) {
- for ($i = 0; $i < count($lists); $i++) {
- $objPHPExcel->getActiveSheet()->setCellValue('A' . ($i + 2), $lists[$i]['sn']);
- $objPHPExcel->getActiveSheet()->setCellValue('B' . ($i + 2), $lists[$i]['order_sn']);
- $objPHPExcel->getActiveSheet()->setCellValue('C' . ($i + 2), $lists[$i]['real_name']);
- $objPHPExcel->getActiveSheet()->setCellValue('D' . ($i + 2), $lists[$i]['to_real_name']);
- $objPHPExcel->getActiveSheet()->setCellValue('E' . ($i + 2), $lists[$i]['content']);
- $objPHPExcel->getActiveSheet()->setCellValue('F' . ($i + 2), $lists[$i]['create_time']);
- $objPHPExcel->getActiveSheet()->setCellValue('G' . ($i + 2), $lists[$i]['to_create_time']);
- $objPHPExcel->getActiveSheet()->setCellValue('H' . ($i + 2), $lists[$i]['confirm_time']);
- $objPHPExcel->getActiveSheet()->setCellValue('I' . ($i + 2), $lists[$i]['done_time']);
- $objPHPExcel->getActiveSheet()->setCellValue('J' . ($i + 2), $lists[$i]['start_name']);
- $objPHPExcel->getActiveSheet()->setCellValue('K' . ($i + 2), $lists[$i]['xq_time']);
- $objPHPExcel->getActiveSheet()->setCellValue('L' . ($i + 2), $lists[$i]['end_name']);
- $objPHPExcel->getActiveSheet()->setCellValue('M' . ($i + 2), $lists[$i]['ywc_time']);
- $objPHPExcel->getActiveSheet()->setCellValue('N' . ($i + 2), $lists[$i]['type_name']);
- $objPHPExcel->getActiveSheet()->setCellValue('O' . ($i + 2), $lists[$i]['todo_mode_in_content']);
- $objPHPExcel->getActiveSheet()->setCellValue('P' . ($i + 2), $lists[$i]['dispatch_time']);
- $objPHPExcel->getActiveSheet()->setCellValue('Q' . ($i + 2), $lists[$i]['jiedan_time']);
- $objPHPExcel->getActiveSheet()->setCellValue('R' . ($i + 2), $lists[$i]['time_cost']);
- $objPHPExcel->getActiveSheet()->setCellValue('S' . ($i + 2), $lists[$i]['dep']);
- $objPHPExcel->getActiveSheet()->setCellValue('T' . ($i + 2), $lists[$i]['source_type_text']);
- $objPHPExcel->getActiveSheet()->setCellValue('U' . ($i + 2), $lists[$i]['dep_cate_name']);
- }
- }
- else {
- if($mode==0){
- for ($i = 0; $i < count($lists); $i++) {
- $objPHPExcel->getActiveSheet()->setCellValue('A' . ($i + 2), $lists[$i]['sn']);
- $objPHPExcel->getActiveSheet()->setCellValue('B' . ($i + 2), $lists[$i]['order_sn']);
- $objPHPExcel->getActiveSheet()->setCellValue('C' . ($i + 2), $lists[$i]['real_name']);
- $objPHPExcel->getActiveSheet()->setCellValue('D' . ($i + 2), $lists[$i]['to_real_name']);
- $objPHPExcel->getActiveSheet()->setCellValue('E' . ($i + 2), $lists[$i]['content']);
- $objPHPExcel->getActiveSheet()->setCellValue('F' . ($i + 2), $lists[$i]['create_time']);
- $objPHPExcel->getActiveSheet()->setCellValue('G' . ($i + 2), $lists[$i]['to_create_time']);
- $objPHPExcel->getActiveSheet()->setCellValue('H' . ($i + 2), $lists[$i]['confirm_time']);
- $objPHPExcel->getActiveSheet()->setCellValue('I' . ($i + 2), $lists[$i]['done_time']);
- $objPHPExcel->getActiveSheet()->setCellValue('J' . ($i + 2), $lists[$i]['todo_mode_in_content']);
- $objPHPExcel->getActiveSheet()->setCellValue('K' . ($i + 2), $lists[$i]['work_type_mode_text']);
- $objPHPExcel->getActiveSheet()->setCellValue('L' . ($i + 2), $lists[$i]['dispatch_time']);
- $objPHPExcel->getActiveSheet()->setCellValue('M' . ($i + 2), $lists[$i]['jiedan_time']);
- $objPHPExcel->getActiveSheet()->setCellValue('N' . ($i + 2), $lists[$i]['time_cost']);
- $objPHPExcel->getActiveSheet()->setCellValue('O' . ($i + 2), $lists[$i]['dep']);
- $objPHPExcel->getActiveSheet()->setCellValue('P' . ($i + 2), $lists[$i]['source_type_text']);
- $objPHPExcel->getActiveSheet()->setCellValue('Q' . ($i + 2), $lists[$i]['dep_cate_name']);
- }
- }else{
- for ($i = 0; $i < count($lists); $i++) {
- $objPHPExcel->getActiveSheet()->setCellValue('A' . ($i + 2), $lists[$i]['sn']);
- $objPHPExcel->getActiveSheet()->setCellValue('B' . ($i + 2), $lists[$i]['order_sn']);
- $objPHPExcel->getActiveSheet()->setCellValue('C' . ($i + 2), $lists[$i]['real_name']);
- $objPHPExcel->getActiveSheet()->setCellValue('D' . ($i + 2), $lists[$i]['to_real_name']);
- $objPHPExcel->getActiveSheet()->setCellValue('E' . ($i + 2), $lists[$i]['content']);
- $objPHPExcel->getActiveSheet()->setCellValue('F' . ($i + 2), $lists[$i]['create_time']);
- $objPHPExcel->getActiveSheet()->setCellValue('G' . ($i + 2), $lists[$i]['to_create_time']);
- $objPHPExcel->getActiveSheet()->setCellValue('H' . ($i + 2), $lists[$i]['confirm_time']);
- $objPHPExcel->getActiveSheet()->setCellValue('I' . ($i + 2), $lists[$i]['done_time']);
- $objPHPExcel->getActiveSheet()->setCellValue('J' . ($i + 2), $lists[$i]['todo_mode_in_content']);
- $objPHPExcel->getActiveSheet()->setCellValue('K' . ($i + 2), $lists[$i]['dispatch_time']);
- $objPHPExcel->getActiveSheet()->setCellValue('L' . ($i + 2), $lists[$i]['jiedan_time']);
- $objPHPExcel->getActiveSheet()->setCellValue('M' . ($i + 2), $lists[$i]['time_cost']);
- $objPHPExcel->getActiveSheet()->setCellValue('N' . ($i + 2), $lists[$i]['dep']);
- $objPHPExcel->getActiveSheet()->setCellValue('O' . ($i + 2), $lists[$i]['source_type_text']);
- $objPHPExcel->getActiveSheet()->setCellValue('P' . ($i + 2), $lists[$i]['dep_cate_name']);
- }
- }
- }
- }
- //设置保存的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 print($id){
- $info = Db::name('todo_view')->where('id',$id)->find();
- $depName = Db::name('dep')
- ->where('id',$info['dep_id'])
- ->value('title');
- $info['depName'] = $depName;
- $info['cons'] = [];
- $info['sign'] = Db::name('todo')->where('id',$id)->value('sign');
- $total = $totalPrice = 0;
- $mate = Db::name('todo_mate_item')
- ->alias('tmi')
- ->join('todo_mate tm','tmi.todo_mate_id = tm.id')
- ->join('mate_goods mg','mg.id = tmi.items_id')
- ->field('tmi.items_id,tmi.total,tmi.money,tmi.total_money,mg.title')
- ->where('tm.todo_id',$info['id'])
- ->select();
- if(!empty($mate)){
- foreach ($mate as $kk=>$todo_mate){
- $info['cons'][] = [
- 'title' =>$todo_mate['title'],
- 'total' =>$todo_mate['total'],
- 'money' =>$todo_mate['money'],
- 'total_money' =>$todo_mate['total_money'],
- ];
- $total +=$todo_mate['total'];
- $totalPrice +=$todo_mate['total_money'];
- }
- }
- $aa = [
- 'title'=>'',
- 'total'=>'',
- 'money'=>'',
- 'total_money'=>'',
- ];
- if(empty($info['cons'])){
- for ($i=1;$i<=4;$i++){
- $info['cons'][] = $aa;
- }
- }elseif (count($info['cons']) <4){
- $ii = 4-count($info['cons']);
- for ($i=1;$i<=$ii;$i++){
- $info['cons'][] = $aa;
- }
- }
- $info['total'] = $total;
- $info['totalPrice'] = round($totalPrice,2);
- $this->assign('info', $info);
- return $this->fetch();
- }
- }
|