model= new \app\common\model\Complain();
$this->table = 'complain';
}
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;
$content = input('content','','trim');
if($content){
$map[] = ['content','like','%'.$content.'%'];
}
$user = input('user','','trim');
if($user != ''){
$userIds = Db::name('user')->where('del',0)->where('real_name','like','%'.$user.'%')->column('id');
$map[] = ['create_user_id','in',$userIds];
}
$st = input('start','','trim');
if($st !=''){
$map[] = ['create_time','>=',$st.' 00:00:00'];
}
$et = input('end','','trim');
if($et !=''){
$map[] = ['create_time','<=',$et.' 23:59:59'];
}
$map[] = ['del','=',0];
$map[] = ['org_id','=',$this->orgId];
$hour = (new Config())->getConfig('org_complain_hour',$this->orgId);
$hour = $hour>0?$hour:0;
$endTime = date('Y-m-d H:i:s',time() - $hour*60*60);
// $type = input('type/d',0);
// if($hour > 0 && $type == 1){
// $map[] = ['create_time','<',$endTime];
// $map[] = ['status','=',0];
// }
$from = input('from', '', 'trim');
if ($from!='') {
if($from == 1){
$map[] = ['order_id','>',0];
$map[] = ['bus_type','<>',0];
$map[] = ['to_from','=',0];
}else{
$map[] = ['order_id','>',0];
$map[] = ['bus_type','<>',0];
$map[] = ['to_from','<>',0];
}
}
$map= empty($map) ? true: $map;
//数据查询
$lists = db($this->table)
->where($map)
->limit($start,$length)
->order($order)
->select();
foreach ($lists as $k=>$v){
$lists[$k]['depName'] = Db::name('dep')
->where('id',$v['dep_id'])
->value('title');
// $lists[$k]['fromName'] =$this->model->from[$v['from']];
$lists[$k]['fromName'] = '';
if($v['order_id'] > 0 && $v['bus_type'] != 0){
if($v['to_from'] == 0){
$lists[$k]['fromName'] = '一键呼叫';
}else{
$lists[$k]['fromName'] = '隐患';
}
}
$lists[$k]['worktypemode'] = '';
if($v['order_id'] > 0 && in_array($v['bus_type'],[0,1])){
$worktype = Db::name('orders')
->alias('o')
->join('work_type_mode w','o.work_type_mode = w.id')
->where('o.id',$v['order_id'])
->value('w.name');
$lists[$k]['worktypemode'] = $worktype?$worktype:'';
}
if($v['hide'] == 1){
$lists[$k]['realName'] = '匿名';
}else{
$lists[$k]['realName'] = Db::name('user')
->where('id',$v['create_user_id'])
->value('real_name');
}
$orderMode = 0;
if($v['order_id'] > 0){
$orderMode = Db::name('orders')->where('id',$v['order_id'])->value('order_mode');
}
$lists[$k]['statusTxt'] = model('Complain')->formatStatus($v['status'],$v['order_id'],$v['id']);
$lists[$k]['order_mode'] = $orderMode;
if($v['create_time'] < $endTime && $v['status']==0){
$lists[$k]['statusTxt'] = $lists[$k]['statusTxt'].'(已超时)';
}
}
//数据返回
$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{
return $this->fetch('index');
}
}
public function del($id=0){
if(!$id){
$this->error('参数错误');
}
$res = Db::name($this->table)
->where('id',$id)
->update([
'del'=>1,
'del_user_id'=>$this->userId,
'del_time'=>getTime(),
]);
if(!$res){
$this->error('删除失败');
}
$this->success('删除成功');
}
public function edit($id){
if(request()->isGet()){
$this->assign('id',$id);
return $this->fetch();
}else{
$info = Db::name('complain')
->where('id',$id)
->find();
if(!$info){
$this->error('记录不存在');
}
if($info['status'] == 1){
$this->error('该记录已处理');
}
$curRoles = Db::name('user_roles')
->where('user_id',$this->userId)
->value('roles_id');
$data = array(
'curr_roles_id' => $curRoles,
'note' => input('note','','trim'),
'status' => 1,
'update_time' => date('Y-m-d H:i:s'),
'hand_user_id' => $this->userId
);
$res =Db::name('complain')
->where(array('id'=>$id))
->update($data);
if($res){
model('Complain')->pushCreateUser(0,$info['create_user_id']);
$this->success('处理成功');
}else{
$this->error('处理失败');
}
}
}
public function detail($id){
$info = Db::name('complain')
->where('id',$id)
->find();
$info['depName'] = Db::name('dep')
->where('id',$info['dep_id'])
->value('title');
if($info['hide']==1){
$info['realName'] = '匿名';
}else{
$info['realName'] = Db::name('user')
->where('id',$info['create_user_id'])
->value('real_name');;
}
// $info['statusTxt'] = $info['status']==1?'已处理':"未处理";
$info['images'] = !empty($info['images'])?explode(',',$info['images']):'';
$orderMode = 0;
if($info['order_id'] > 0){
$orderMode = Db::name('orders')->where('id',$info['order_id'])->value('order_mode');
}
$info['statusTxt'] = model('Complain')->formatStatus($info['status'],$info['order_id'],$info['id']);
$info['order_mode'] = $orderMode;
$comment = Db::name('comment')
->alias('c')
->join('user u','u.id = c.user_id')
->where('c.from_id',$id)
->where('c.type',16)
->field('c.id,c.score,c.content,c.create_time,u.real_name,u.head_image')
->order('c.id desc')
->find();
$info['comment'] = $comment?$comment:[];
$this->assign('info',$info);
return $this->fetch();
}
public function tsDetail($id){
$info = Db::name('complain')
->where('id',$id)
->find();
$info['depName'] = Db::name('dep')
->where('id',$info['dep_id'])
->value('title');
if($info['hide']==1){
$info['realName'] = '匿名';
}else{
$info['realName'] = Db::name('user')
->where('id',$info['create_user_id'])
->value('real_name');;
}
// $info['statusTxt'] = $info['status']==1?'已处理':"未处理";
$info['images'] = !empty($info['images'])?explode(',',$info['images']):'';
$orderMode = 0;
if($info['order_id'] > 0){
$orderMode = Db::name('orders')->where('id',$info['order_id'])->value('order_mode');
}
$info['statusTxt'] = model('Complain')->formatStatus($info['status'],$info['order_id'],$info['id']);
$info['order_mode'] = $orderMode;
$this->assign('info',$info);
return $this->fetch();
}
//派单
public function send($id) {
if (request()->isGet()) {
$this->assign('id', $id);
$complainInfo = Db::name($this->table)->where('id',$id)->find();
$this->assign('complain',$complainInfo);
$order_type = (new \app\common\model\OrderType())->getList();
$address = (new \app\common\model\Address())->getListByType(1);
$this->assign('order_type_list', $order_type);
$this->assign('address_list', $address);
$order_repair = Db::name('order_repair')
->where('order_id', $id)
->find();
$this->assign('order_repair', $order_repair);
$workType = Db::name('work_type_mode')
->where('type',1)
->select();
$config = Db::name('config')
->where('name','web_order_transfer_type')
->value('value');
if(empty($config)){
$workType = [];
}else{
$ll = explode('|',$config);
foreach ($workType as $kk=>$vv){
if(!in_array($vv['id'],$ll)){
unset($workType[$kk]);
}
}
}
foreach ($workType as $k=>$v){
$this->assign('send_user_num'.$v['id'], model('Orders')->sendUserNum($v['id'], $this->orgId));
$this->assign('user_list'.$v['id'], (new \app\common\model\WorkTypeMode())->getRolesUserByNum($v['id'], $this->orgId, 1));
$two_dispatch_roles = model('user')->get_two_dispatch_role($this->orgId, $v['id']);
$this->assign('dispatch_roles'.$v['id'], $two_dispatch_roles);
}
$this->assign('dispatch_type', check_two_dispatch($this->userId));
$this->assign('two_dispatch_off', two_dispatch_off($this->orgId));
$this->assign('workType', $workType);
$address = (new \app\common\model\Address())->getListByType(2);
$conveyCate = (new \app\common\model\ConveyCate());
$priority = $conveyCate->priority;
$order_convey = $conveyCate->getList();
$order_device = (new \app\common\model\ConveyDevice())->getList();
$this->assign('address', $address);
$this->assign('priority', $priority);
$this->assign('order_convey_type', $order_convey);
$this->assign('order_device', $order_device);
$oCid = Db::name('order_convey')
->where('order_id',$id)
->find();
$opt = Db::name('order_convey_patient')
->where('order_id',$id)
->find();
$this->assign('ocid',$oCid);
$this->assign('opt',$opt);
$this->assign('ps',empty($opt)?1:0);
$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);
}else{
$auths = [];
}
}
$this->assign('auths',$auths);
return $this->fetch();
}
else {
$data = request()->post();
$data['org_id'] = $this->orgId;
$res = model('Complain')->send($id, $this->userId, $data);
if (!$res) {
$this->error(model('Complain')->getError());
}
$this->success('操作成功');
}
}
//转单
public function ts_send($id) {
if (request()->isGet()) {
$this->assign('id', $id);
$complainInfo = Db::name($this->table)->where('id',$id)->find();
$this->assign('complain',$complainInfo);
$order_type = (new \app\common\model\OrderType())->getList();
$address = (new \app\common\model\Address())->getListByType(1);
$this->assign('order_type_list', $order_type);
$this->assign('address_list', $address);
// $order_repair = Db::name('order_repair')
// ->where('order_id', $id)
// ->find();
$this->assign('order_repair', []);
$workType = Db::name('work_type_mode')
->where('type',1)
->select();
$config = Db::name('config')
->where('name','web_order_transfer_type')
->value('value');
if(empty($config)){
$workType = [];
}else{
$ll = explode('|',$config);
foreach ($workType as $kk=>$vv){
if(!in_array($vv['id'],$ll)){
unset($workType[$kk]);
}
}
}
foreach ($workType as $k=>$v){
$this->assign('send_user_num'.$v['id'], model('Orders')->sendUserNum($v['id'], $this->orgId));
$this->assign('user_list'.$v['id'], (new \app\common\model\WorkTypeMode())->getRolesUserByNum($v['id'], $this->orgId, 1));
$two_dispatch_roles = model('user')->get_two_dispatch_role($this->orgId, $v['id']);
$this->assign('dispatch_roles'.$v['id'], $two_dispatch_roles);
}
foreach ($workType as $k=>$v){
if($v['id']!==0){
unset($workType[$k]);
}
}
$this->assign('dispatch_type', check_two_dispatch($this->userId));
$this->assign('two_dispatch_off', two_dispatch_off($this->orgId));
$this->assign('workType', $workType);
$address = (new \app\common\model\Address())->getListByType(2);
$conveyCate = (new \app\common\model\ConveyCate());
$priority = $conveyCate->priority;
$order_convey = $conveyCate->getList();
$order_device = (new \app\common\model\ConveyDevice())->getList();
$this->assign('address', $address);
$this->assign('priority', $priority);
$this->assign('order_convey_type', $order_convey);
$this->assign('order_device', $order_device);
$oCid = Db::name('order_convey')
->where('order_id',-1)
->find();
$opt = Db::name('order_convey_patient')
->where('order_id',-1)
->find();
$this->assign('ocid',$oCid);
$this->assign('opt',$opt);
$this->assign('ps',empty($opt)?1:0);
$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);
}else{
$auths = [];
}
}
$this->assign('auths',$auths);
return $this->fetch();
}
else {
$data = request()->post();
$data['org_id'] = $this->orgId;
$res = model('complain')->zd_send($id, $data,$this->userId);
if (!$res) {
$this->error(model('complain')->getError());
}
$this->success('操作成功');
}
}
public function summary($id){
if(request()->isGet()){
$info = Db::name('complain')
->where('id',$id)
->find();
$this->assign('info',$info);
$this->assign('id',$id);
return $this->fetch();
}else{
$data = array(
'summary' => input('summary','','trim'),
'update_time' => date('Y-m-d H:i:s'),
);
$res =Db::name('complain')
->where(array('id'=>$id))
->update($data);
$res?$this->success('操作成功'):$this->error('操作失败');
}
}
public function export(){
$meta_title = '投诉订单';
if (request()->isGet()) {
$content = input('content','','trim');
if($content){
$map[] = ['content','like','%'.$content.'%'];
}
$user = input('user','','trim');
if($user != ''){
$userIds = Db::name('user')->where('del',0)->where('real_name','like','%'.$user.'%')->column('id');
$map[] = ['create_user_id','in',$userIds];
}
$map[] = ['del','=',0];
$map[] = ['org_id','=',$this->orgId];
$st = input('start','','trim');
if($st !=''){
$map[] = ['create_time','>=',$st.' 00:00:00'];
}
$et = input('end','','trim');
if($et !=''){
$map[] = ['create_time','<=',$et.' 23:59:59'];
}
$hour = (new Config())->getConfig('org_complain_hour',$this->orgId);
$hour = $hour>0?$hour:0;
$endTime = date('Y-m-d H:i:s',time() - $hour*60*60);
// $type = input('type/d',0);
// if($hour > 0 && $type == 1){
// $map[] = ['create_time','<',$endTime];
// $map[] = ['status','=',0];
// }
$from = input('from', '', 'trim');
if ($from!='') {
if($from == 1){
$map[] = ['order_id','>',0];
$map[] = ['bus_type','<>',0];
$map[] = ['to_from','=',0];
}else{
$map[] = ['order_id','>',0];
$map[] = ['bus_type','<>',0];
$map[] = ['to_from','<>',0];
}
}
$map= empty($map) ? true: $map;
//数据查询
$lists = db($this->table)->where($map)
->order('id','desc')->select();
foreach ($lists as $k=>$v){
$lists[$k]['depName'] = Db::name('dep')
->where('id',$v['dep_id'])
->value('title');
// $lists[$k]['fromName'] =$this->model->from[$v['from']];
$lists[$k]['fromName'] = '';
if($v['order_id'] > 0 && $v['bus_type'] != 0){
if($v['to_from'] == 0){
$lists[$k]['fromName'] = '一键呼叫';
}else{
$lists[$k]['fromName'] = '隐患';
}
}
if($v['hide'] == 1){
$lists[$k]['realName'] = '匿名';
}else{
$lists[$k]['realName'] = Db::name('user')
->where('id',$v['create_user_id'])
->value('real_name');
}
$orderMode = 0;
if($v['order_id'] > 0){
$orderMode = Db::name('orders')->where('id',$v['order_id'])->value('order_mode');
}
$lists[$k]['statusTxt'] = model('Complain')->formatStatus($v['status'],$v['order_id'],$v['id']);
$lists[$k]['order_mode'] = $orderMode;
// if($v['create_time'] < $endTime){
// $lists[$k]['statusTxt'] = $lists[$k]['statusTxt'].'(已超时)';
// }
$lists[$k]['jdsc'] = $v['update_time']?getM1($v['update_time'],$v['create_time']):'';
$lists[$k]['clsc'] = $v['finish_time'] && $v['update_time']?getM1($v['finish_time'],$v['update_time']):'';
}
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', '处理时长');
// 设置表格头水平居中
$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]['create_time']);
$objPHPExcel->getActiveSheet()->setCellValue('C' . ($i + 2), $lists[$i]['update_time']);
$objPHPExcel->getActiveSheet()->setCellValue('D' . ($i + 2), $lists[$i]['finish_time']);
$objPHPExcel->getActiveSheet()->setCellValue('E' . ($i + 2), $lists[$i]['content']);
$objPHPExcel->getActiveSheet()->setCellValue('F' . ($i + 2), $lists[$i]['depName']);
$objPHPExcel->getActiveSheet()->setCellValue('G' . ($i + 2), $lists[$i]['realName']);
$objPHPExcel->getActiveSheet()->setCellValue('H' . ($i + 2), $lists[$i]['statusTxt']);
if($lists[$i]['from'] > 0){
$objPHPExcel->getActiveSheet()->setCellValue('I' . ($i + 2), '投诉');
}else{
$objPHPExcel->getActiveSheet()->setCellValue('I' . ($i + 2), '');
}
$objPHPExcel->getActiveSheet()->setCellValue('J' . ($i + 2), $lists[$i]['fromName']);
$objPHPExcel->getActiveSheet()->setCellValue('K' . ($i + 2), $lists[$i]['jdsc']);
$objPHPExcel->getActiveSheet()->setCellValue('L' . ($i + 2), $lists[$i]['clsc']);
}
//设置保存的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');
}
}
}