0
0

Complain.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640
  1. <?php
  2. namespace app\admin\controller;
  3. use app\common\model\Config;
  4. use think\App;
  5. use think\Db;
  6. use think\Exception;
  7. use think\Model;
  8. class Complain extends Auth
  9. {
  10. public function __construct(App $app = null) {
  11. parent::__construct($app);
  12. $this->model= new \app\common\model\Complain();
  13. $this->table = 'complain';
  14. }
  15. public function index(){
  16. if(request()->isAjax()){
  17. //分页参数
  18. $length = input('rows',10,'intval'); //每页条数
  19. $page = input('page',1,'intval'); //第几页
  20. $start = ($page - 1) * $length; //分页开始位置
  21. //排序
  22. $sortRow = input('sidx','id','trim'); //排序列
  23. $sort = input('sord','desc','trim'); //排序方式
  24. $order = $sortRow.' '.$sort;
  25. $content = input('content','','trim');
  26. if($content){
  27. $map[] = ['content','like','%'.$content.'%'];
  28. }
  29. $user = input('user','','trim');
  30. if($user != ''){
  31. $userIds = Db::name('user')->where('del',0)->where('real_name','like','%'.$user.'%')->column('id');
  32. $map[] = ['create_user_id','in',$userIds];
  33. }
  34. $st = input('start','','trim');
  35. if($st !=''){
  36. $map[] = ['create_time','>=',$st.' 00:00:00'];
  37. }
  38. $et = input('end','','trim');
  39. if($et !=''){
  40. $map[] = ['create_time','<=',$et.' 23:59:59'];
  41. }
  42. $map[] = ['del','=',0];
  43. $map[] = ['org_id','=',$this->orgId];
  44. $hour = (new Config())->getConfig('org_complain_hour',$this->orgId);
  45. $hour = $hour>0?$hour:0;
  46. $endTime = date('Y-m-d H:i:s',time() - $hour*60*60);
  47. // $type = input('type/d',0);
  48. // if($hour > 0 && $type == 1){
  49. // $map[] = ['create_time','<',$endTime];
  50. // $map[] = ['status','=',0];
  51. // }
  52. $from = input('from', '', 'trim');
  53. if ($from!='') {
  54. if($from == 1){
  55. $map[] = ['order_id','>',0];
  56. $map[] = ['bus_type','<>',0];
  57. $map[] = ['to_from','=',0];
  58. }else{
  59. $map[] = ['order_id','>',0];
  60. $map[] = ['bus_type','<>',0];
  61. $map[] = ['to_from','<>',0];
  62. }
  63. }
  64. $map= empty($map) ? true: $map;
  65. //数据查询
  66. $lists = db($this->table)
  67. ->where($map)
  68. ->limit($start,$length)
  69. ->order($order)
  70. ->select();
  71. foreach ($lists as $k=>$v){
  72. $lists[$k]['depName'] = Db::name('dep')
  73. ->where('id',$v['dep_id'])
  74. ->value('title');
  75. // $lists[$k]['fromName'] =$this->model->from[$v['from']];
  76. $lists[$k]['fromName'] = '';
  77. if($v['order_id'] > 0 && $v['bus_type'] != 0){
  78. if($v['to_from'] == 0){
  79. $lists[$k]['fromName'] = '一键呼叫';
  80. }else{
  81. $lists[$k]['fromName'] = '隐患';
  82. }
  83. }
  84. $lists[$k]['worktypemode'] = '';
  85. if($v['order_id'] > 0 && in_array($v['bus_type'],[0,1])){
  86. $worktype = Db::name('orders')
  87. ->alias('o')
  88. ->join('work_type_mode w','o.work_type_mode = w.id')
  89. ->where('o.id',$v['order_id'])
  90. ->value('w.name');
  91. $lists[$k]['worktypemode'] = $worktype?$worktype:'';
  92. }
  93. if($v['hide'] == 1){
  94. $lists[$k]['realName'] = '匿名';
  95. }else{
  96. $lists[$k]['realName'] = Db::name('user')
  97. ->where('id',$v['create_user_id'])
  98. ->value('real_name');
  99. }
  100. $orderMode = 0;
  101. if($v['order_id'] > 0){
  102. $orderMode = Db::name('orders')->where('id',$v['order_id'])->value('order_mode');
  103. }
  104. $lists[$k]['statusTxt'] = model('Complain')->formatStatus($v['status'],$v['order_id'],$v['id']);
  105. $lists[$k]['order_mode'] = $orderMode;
  106. if($v['create_time'] < $endTime && $v['status']==0){
  107. $lists[$k]['statusTxt'] = $lists[$k]['statusTxt'].'<span style="color:red;">(已超时)</span>';
  108. }
  109. }
  110. //数据返回
  111. $totalCount = db($this->table)->where($map)->count();
  112. $totalPage = ceil($totalCount/$length);
  113. $result['page'] = $page;
  114. $result['total'] = $totalPage;
  115. $result['records'] = $totalCount;
  116. $result['rows'] = $lists;
  117. return json($result);
  118. }else{
  119. return $this->fetch('index');
  120. }
  121. }
  122. public function del($id=0){
  123. if(!$id){
  124. $this->error('参数错误');
  125. }
  126. $res = Db::name($this->table)
  127. ->where('id',$id)
  128. ->update([
  129. 'del'=>1,
  130. 'del_user_id'=>$this->userId,
  131. 'del_time'=>getTime(),
  132. ]);
  133. if(!$res){
  134. $this->error('删除失败');
  135. }
  136. $this->success('删除成功');
  137. }
  138. public function edit($id){
  139. if(request()->isGet()){
  140. $this->assign('id',$id);
  141. return $this->fetch();
  142. }else{
  143. $info = Db::name('complain')
  144. ->where('id',$id)
  145. ->find();
  146. if(!$info){
  147. $this->error('记录不存在');
  148. }
  149. if($info['status'] == 1){
  150. $this->error('该记录已处理');
  151. }
  152. $curRoles = Db::name('user_roles')
  153. ->where('user_id',$this->userId)
  154. ->value('roles_id');
  155. $data = array(
  156. 'curr_roles_id' => $curRoles,
  157. 'note' => input('note','','trim'),
  158. 'status' => 1,
  159. 'update_time' => date('Y-m-d H:i:s'),
  160. 'hand_user_id' => $this->userId
  161. );
  162. $res =Db::name('complain')
  163. ->where(array('id'=>$id))
  164. ->update($data);
  165. if($res){
  166. model('Complain')->pushCreateUser(0,$info['create_user_id']);
  167. $this->success('处理成功');
  168. }else{
  169. $this->error('处理失败');
  170. }
  171. }
  172. }
  173. public function detail($id){
  174. $info = Db::name('complain')
  175. ->where('id',$id)
  176. ->find();
  177. $info['depName'] = Db::name('dep')
  178. ->where('id',$info['dep_id'])
  179. ->value('title');
  180. if($info['hide']==1){
  181. $info['realName'] = '匿名';
  182. }else{
  183. $info['realName'] = Db::name('user')
  184. ->where('id',$info['create_user_id'])
  185. ->value('real_name');;
  186. }
  187. // $info['statusTxt'] = $info['status']==1?'已处理':"未处理";
  188. $info['images'] = !empty($info['images'])?explode(',',$info['images']):'';
  189. $orderMode = 0;
  190. if($info['order_id'] > 0){
  191. $orderMode = Db::name('orders')->where('id',$info['order_id'])->value('order_mode');
  192. }
  193. $info['statusTxt'] = model('Complain')->formatStatus($info['status'],$info['order_id'],$info['id']);
  194. $info['order_mode'] = $orderMode;
  195. $comment = Db::name('comment')
  196. ->alias('c')
  197. ->join('user u','u.id = c.user_id')
  198. ->where('c.from_id',$id)
  199. ->where('c.type',16)
  200. ->field('c.id,c.score,c.content,c.create_time,u.real_name,u.head_image')
  201. ->order('c.id desc')
  202. ->find();
  203. $info['comment'] = $comment?$comment:[];
  204. $this->assign('info',$info);
  205. return $this->fetch();
  206. }
  207. public function tsDetail($id){
  208. $info = Db::name('complain')
  209. ->where('id',$id)
  210. ->find();
  211. $info['depName'] = Db::name('dep')
  212. ->where('id',$info['dep_id'])
  213. ->value('title');
  214. if($info['hide']==1){
  215. $info['realName'] = '匿名';
  216. }else{
  217. $info['realName'] = Db::name('user')
  218. ->where('id',$info['create_user_id'])
  219. ->value('real_name');;
  220. }
  221. // $info['statusTxt'] = $info['status']==1?'已处理':"未处理";
  222. $info['images'] = !empty($info['images'])?explode(',',$info['images']):'';
  223. $orderMode = 0;
  224. if($info['order_id'] > 0){
  225. $orderMode = Db::name('orders')->where('id',$info['order_id'])->value('order_mode');
  226. }
  227. $info['statusTxt'] = model('Complain')->formatStatus($info['status'],$info['order_id'],$info['id']);
  228. $info['order_mode'] = $orderMode;
  229. $this->assign('info',$info);
  230. return $this->fetch();
  231. }
  232. //派单
  233. public function send($id) {
  234. if (request()->isGet()) {
  235. $this->assign('id', $id);
  236. $complainInfo = Db::name($this->table)->where('id',$id)->find();
  237. $this->assign('complain',$complainInfo);
  238. $order_type = (new \app\common\model\OrderType())->getList();
  239. $address = (new \app\common\model\Address())->getListByType(1);
  240. $this->assign('order_type_list', $order_type);
  241. $this->assign('address_list', $address);
  242. $order_repair = Db::name('order_repair')
  243. ->where('order_id', $id)
  244. ->find();
  245. $this->assign('order_repair', $order_repair);
  246. $workType = Db::name('work_type_mode')
  247. ->where('type',1)
  248. ->select();
  249. $config = Db::name('config')
  250. ->where('name','web_order_transfer_type')
  251. ->value('value');
  252. if(empty($config)){
  253. $workType = [];
  254. }else{
  255. $ll = explode('|',$config);
  256. foreach ($workType as $kk=>$vv){
  257. if(!in_array($vv['id'],$ll)){
  258. unset($workType[$kk]);
  259. }
  260. }
  261. }
  262. foreach ($workType as $k=>$v){
  263. $this->assign('send_user_num'.$v['id'], model('Orders')->sendUserNum($v['id'], $this->orgId));
  264. $this->assign('user_list'.$v['id'], (new \app\common\model\WorkTypeMode())->getRolesUserByNum($v['id'], $this->orgId, 1));
  265. $two_dispatch_roles = model('user')->get_two_dispatch_role($this->orgId, $v['id']);
  266. $this->assign('dispatch_roles'.$v['id'], $two_dispatch_roles);
  267. }
  268. $this->assign('dispatch_type', check_two_dispatch($this->userId));
  269. $this->assign('two_dispatch_off', two_dispatch_off($this->orgId));
  270. $this->assign('workType', $workType);
  271. $address = (new \app\common\model\Address())->getListByType(2);
  272. $conveyCate = (new \app\common\model\ConveyCate());
  273. $priority = $conveyCate->priority;
  274. $order_convey = $conveyCate->getList();
  275. $order_device = (new \app\common\model\ConveyDevice())->getList();
  276. $this->assign('address', $address);
  277. $this->assign('priority', $priority);
  278. $this->assign('order_convey_type', $order_convey);
  279. $this->assign('order_device', $order_device);
  280. $oCid = Db::name('order_convey')
  281. ->where('order_id',$id)
  282. ->find();
  283. $opt = Db::name('order_convey_patient')
  284. ->where('order_id',$id)
  285. ->find();
  286. $this->assign('ocid',$oCid);
  287. $this->assign('opt',$opt);
  288. $this->assign('ps',empty($opt)?1:0);
  289. $auths = [1,2,3,4,15,0];
  290. if(!is_admin($this->userId)){
  291. $auth = get_dispatch_auth($this->userId);
  292. if($auth){
  293. $auths = array_intersect($auths,$auth);
  294. }else{
  295. $auths = [];
  296. }
  297. }
  298. $this->assign('auths',$auths);
  299. return $this->fetch();
  300. }
  301. else {
  302. $data = request()->post();
  303. $data['org_id'] = $this->orgId;
  304. $res = model('Complain')->send($id, $this->userId, $data);
  305. if (!$res) {
  306. $this->error(model('Complain')->getError());
  307. }
  308. $this->success('操作成功');
  309. }
  310. }
  311. //转单
  312. public function ts_send($id) {
  313. if (request()->isGet()) {
  314. $this->assign('id', $id);
  315. $complainInfo = Db::name($this->table)->where('id',$id)->find();
  316. $this->assign('complain',$complainInfo);
  317. $order_type = (new \app\common\model\OrderType())->getList();
  318. $address = (new \app\common\model\Address())->getListByType(1);
  319. $this->assign('order_type_list', $order_type);
  320. $this->assign('address_list', $address);
  321. // $order_repair = Db::name('order_repair')
  322. // ->where('order_id', $id)
  323. // ->find();
  324. $this->assign('order_repair', []);
  325. $workType = Db::name('work_type_mode')
  326. ->where('type',1)
  327. ->select();
  328. $config = Db::name('config')
  329. ->where('name','web_order_transfer_type')
  330. ->value('value');
  331. if(empty($config)){
  332. $workType = [];
  333. }else{
  334. $ll = explode('|',$config);
  335. foreach ($workType as $kk=>$vv){
  336. if(!in_array($vv['id'],$ll)){
  337. unset($workType[$kk]);
  338. }
  339. }
  340. }
  341. foreach ($workType as $k=>$v){
  342. $this->assign('send_user_num'.$v['id'], model('Orders')->sendUserNum($v['id'], $this->orgId));
  343. $this->assign('user_list'.$v['id'], (new \app\common\model\WorkTypeMode())->getRolesUserByNum($v['id'], $this->orgId, 1));
  344. $two_dispatch_roles = model('user')->get_two_dispatch_role($this->orgId, $v['id']);
  345. $this->assign('dispatch_roles'.$v['id'], $two_dispatch_roles);
  346. }
  347. foreach ($workType as $k=>$v){
  348. if($v['id']!==0){
  349. unset($workType[$k]);
  350. }
  351. }
  352. $this->assign('dispatch_type', check_two_dispatch($this->userId));
  353. $this->assign('two_dispatch_off', two_dispatch_off($this->orgId));
  354. $this->assign('workType', $workType);
  355. $address = (new \app\common\model\Address())->getListByType(2);
  356. $conveyCate = (new \app\common\model\ConveyCate());
  357. $priority = $conveyCate->priority;
  358. $order_convey = $conveyCate->getList();
  359. $order_device = (new \app\common\model\ConveyDevice())->getList();
  360. $this->assign('address', $address);
  361. $this->assign('priority', $priority);
  362. $this->assign('order_convey_type', $order_convey);
  363. $this->assign('order_device', $order_device);
  364. $oCid = Db::name('order_convey')
  365. ->where('order_id',-1)
  366. ->find();
  367. $opt = Db::name('order_convey_patient')
  368. ->where('order_id',-1)
  369. ->find();
  370. $this->assign('ocid',$oCid);
  371. $this->assign('opt',$opt);
  372. $this->assign('ps',empty($opt)?1:0);
  373. $auths = [1,2,3,4,15,0];
  374. if(!is_admin($this->userId)){
  375. $auth = get_dispatch_auth($this->userId);
  376. if($auth){
  377. $auths = array_intersect($auths,$auth);
  378. }else{
  379. $auths = [];
  380. }
  381. }
  382. $this->assign('auths',$auths);
  383. return $this->fetch();
  384. }
  385. else {
  386. $data = request()->post();
  387. $data['org_id'] = $this->orgId;
  388. $res = model('complain')->zd_send($id, $data,$this->userId);
  389. if (!$res) {
  390. $this->error(model('complain')->getError());
  391. }
  392. $this->success('操作成功');
  393. }
  394. }
  395. public function summary($id){
  396. if(request()->isGet()){
  397. $info = Db::name('complain')
  398. ->where('id',$id)
  399. ->find();
  400. $this->assign('info',$info);
  401. $this->assign('id',$id);
  402. return $this->fetch();
  403. }else{
  404. $data = array(
  405. 'summary' => input('summary','','trim'),
  406. 'update_time' => date('Y-m-d H:i:s'),
  407. );
  408. $res =Db::name('complain')
  409. ->where(array('id'=>$id))
  410. ->update($data);
  411. $res?$this->success('操作成功'):$this->error('操作失败');
  412. }
  413. }
  414. public function export(){
  415. $meta_title = '投诉订单';
  416. if (request()->isGet()) {
  417. $content = input('content','','trim');
  418. if($content){
  419. $map[] = ['content','like','%'.$content.'%'];
  420. }
  421. $user = input('user','','trim');
  422. if($user != ''){
  423. $userIds = Db::name('user')->where('del',0)->where('real_name','like','%'.$user.'%')->column('id');
  424. $map[] = ['create_user_id','in',$userIds];
  425. }
  426. $map[] = ['del','=',0];
  427. $map[] = ['org_id','=',$this->orgId];
  428. $st = input('start','','trim');
  429. if($st !=''){
  430. $map[] = ['create_time','>=',$st.' 00:00:00'];
  431. }
  432. $et = input('end','','trim');
  433. if($et !=''){
  434. $map[] = ['create_time','<=',$et.' 23:59:59'];
  435. }
  436. $hour = (new Config())->getConfig('org_complain_hour',$this->orgId);
  437. $hour = $hour>0?$hour:0;
  438. $endTime = date('Y-m-d H:i:s',time() - $hour*60*60);
  439. // $type = input('type/d',0);
  440. // if($hour > 0 && $type == 1){
  441. // $map[] = ['create_time','<',$endTime];
  442. // $map[] = ['status','=',0];
  443. // }
  444. $from = input('from', '', 'trim');
  445. if ($from!='') {
  446. if($from == 1){
  447. $map[] = ['order_id','>',0];
  448. $map[] = ['bus_type','<>',0];
  449. $map[] = ['to_from','=',0];
  450. }else{
  451. $map[] = ['order_id','>',0];
  452. $map[] = ['bus_type','<>',0];
  453. $map[] = ['to_from','<>',0];
  454. }
  455. }
  456. $map= empty($map) ? true: $map;
  457. //数据查询
  458. $lists = db($this->table)->where($map)
  459. ->order('id','desc')->select();
  460. foreach ($lists as $k=>$v){
  461. $lists[$k]['depName'] = Db::name('dep')
  462. ->where('id',$v['dep_id'])
  463. ->value('title');
  464. // $lists[$k]['fromName'] =$this->model->from[$v['from']];
  465. $lists[$k]['fromName'] = '';
  466. if($v['order_id'] > 0 && $v['bus_type'] != 0){
  467. if($v['to_from'] == 0){
  468. $lists[$k]['fromName'] = '一键呼叫';
  469. }else{
  470. $lists[$k]['fromName'] = '隐患';
  471. }
  472. }
  473. if($v['hide'] == 1){
  474. $lists[$k]['realName'] = '匿名';
  475. }else{
  476. $lists[$k]['realName'] = Db::name('user')
  477. ->where('id',$v['create_user_id'])
  478. ->value('real_name');
  479. }
  480. $orderMode = 0;
  481. if($v['order_id'] > 0){
  482. $orderMode = Db::name('orders')->where('id',$v['order_id'])->value('order_mode');
  483. }
  484. $lists[$k]['statusTxt'] = model('Complain')->formatStatus($v['status'],$v['order_id'],$v['id']);
  485. $lists[$k]['order_mode'] = $orderMode;
  486. // if($v['create_time'] < $endTime){
  487. // $lists[$k]['statusTxt'] = $lists[$k]['statusTxt'].'<span style="color:red;">(已超时)</span>';
  488. // }
  489. $lists[$k]['jdsc'] = $v['update_time']?getM1($v['update_time'],$v['create_time']):'';
  490. $lists[$k]['clsc'] = $v['finish_time'] && $v['update_time']?getM1($v['finish_time'],$v['update_time']):'';
  491. }
  492. include_once env('root_path').'/extend/phpexcel/Classes/PHPExcel.php';
  493. //实例化PHPExcel类
  494. $objPHPExcel = new \PHPExcel();
  495. //激活当前的sheet表
  496. $objPHPExcel->setActiveSheetIndex(0);
  497. //设置表格头(即excel表格的第一行)
  498. $objPHPExcel->setActiveSheetIndex(0)
  499. ->setCellValue('A1', '编号')
  500. ->setCellValue('B1', '时间')
  501. ->setCellValue('C1', '处理时间')
  502. ->setCellValue('D1', '完成时间')
  503. ->setCellValue('E1', '内容')
  504. ->setCellValue('F1', '部门')
  505. ->setCellValue('G1', '用户')
  506. ->setCellValue('H1', '状态')
  507. ->setCellValue('I1', '来源')
  508. ->setCellValue('J1', '去向')
  509. ->setCellValue('K1', '接单反应时长')
  510. ->setCellValue('L1', '处理时长');
  511. // 设置表格头水平居中
  512. $objPHPExcel->setActiveSheetIndex(0)->getStyle('A1')->getAlignment()
  513. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  514. $objPHPExcel->setActiveSheetIndex(0)->getStyle('B1')->getAlignment()
  515. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  516. $objPHPExcel->setActiveSheetIndex(0)->getStyle('C1')->getAlignment()
  517. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  518. $objPHPExcel->setActiveSheetIndex(0)->getStyle('D1')->getAlignment()
  519. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  520. $objPHPExcel->setActiveSheetIndex(0)->getStyle('E1')->getAlignment()
  521. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  522. $objPHPExcel->setActiveSheetIndex(0)->getStyle('F1')->getAlignment()
  523. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  524. $objPHPExcel->setActiveSheetIndex(0)->getStyle('G1')->getAlignment()
  525. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  526. $objPHPExcel->setActiveSheetIndex(0)->getStyle('H1')->getAlignment()
  527. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  528. //设置列水平居中
  529. $objPHPExcel->setActiveSheetIndex(0)->getStyle('A')->getAlignment()
  530. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  531. $objPHPExcel->setActiveSheetIndex(0)->getStyle('B')->getAlignment()
  532. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  533. $objPHPExcel->setActiveSheetIndex(0)->getStyle('C')->getAlignment()
  534. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  535. $objPHPExcel->setActiveSheetIndex(0)->getStyle('D')->getAlignment()
  536. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  537. $objPHPExcel->setActiveSheetIndex(0)->getStyle('E')->getAlignment()
  538. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  539. $objPHPExcel->setActiveSheetIndex(0)->getStyle('F')->getAlignment()
  540. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  541. $objPHPExcel->setActiveSheetIndex(0)->getStyle('G')->getAlignment()
  542. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  543. $objPHPExcel->setActiveSheetIndex(0)->getStyle('H')->getAlignment()
  544. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  545. //设置单元格宽度
  546. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('A')->setWidth(10);
  547. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('B')->setWidth(20);
  548. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('C')->setWidth(20);
  549. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('D')->setWidth(20);
  550. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('E')->setWidth(20);
  551. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('F')->setWidth(50);
  552. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('G')->setWidth(20);
  553. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('H')->setWidth(20);
  554. //循环刚取出来的数组,将数据逐一添加到excel表格。
  555. for ($i = 0; $i < count($lists); $i++) {
  556. $objPHPExcel->getActiveSheet()->setCellValue('A' . ($i + 2), $lists[$i]['id']);
  557. $objPHPExcel->getActiveSheet()->setCellValue('B' . ($i + 2), $lists[$i]['create_time']);
  558. $objPHPExcel->getActiveSheet()->setCellValue('C' . ($i + 2), $lists[$i]['update_time']);
  559. $objPHPExcel->getActiveSheet()->setCellValue('D' . ($i + 2), $lists[$i]['finish_time']);
  560. $objPHPExcel->getActiveSheet()->setCellValue('E' . ($i + 2), $lists[$i]['content']);
  561. $objPHPExcel->getActiveSheet()->setCellValue('F' . ($i + 2), $lists[$i]['depName']);
  562. $objPHPExcel->getActiveSheet()->setCellValue('G' . ($i + 2), $lists[$i]['realName']);
  563. $objPHPExcel->getActiveSheet()->setCellValue('H' . ($i + 2), $lists[$i]['statusTxt']);
  564. if($lists[$i]['from'] > 0){
  565. $objPHPExcel->getActiveSheet()->setCellValue('I' . ($i + 2), '投诉');
  566. }else{
  567. $objPHPExcel->getActiveSheet()->setCellValue('I' . ($i + 2), '');
  568. }
  569. $objPHPExcel->getActiveSheet()->setCellValue('J' . ($i + 2), $lists[$i]['fromName']);
  570. $objPHPExcel->getActiveSheet()->setCellValue('K' . ($i + 2), $lists[$i]['jdsc']);
  571. $objPHPExcel->getActiveSheet()->setCellValue('L' . ($i + 2), $lists[$i]['clsc']);
  572. }
  573. //设置保存的Excel表格名称
  574. $filename = $meta_title.'_' . date('YmdHis', time()) . '.xls';
  575. //设置当前激活的sheet表格名称
  576. $objPHPExcel->getActiveSheet()->setTitle($meta_title);
  577. //设置浏览器窗口下载表格
  578. ob_end_clean();
  579. header("Content-Type: application/force-download");
  580. header("Content-Type: application/octet-stream");
  581. header("Content-Type: application/download");
  582. header('Content-Disposition:inline;filename="' . $filename);
  583. //生成excel文件
  584. $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
  585. //下载文件在浏览器窗口
  586. return $objWriter->save('php://output');
  587. }
  588. }
  589. }