OrderStatistics.php 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733
  1. <?php
  2. namespace app\admin\controller;
  3. use think\Db;
  4. use think\Exception;
  5. class OrderStatistics extends Auth
  6. {
  7. public function repairItems(){
  8. $start = input('start',date('Y-m-d',strtotime('-7 day')));
  9. $end = input('end',date('Y-m-d'));
  10. if(request()->isAjax()){
  11. $sTime = $start.' 00:00:00';
  12. $eTime = $end.' 23:59:59';
  13. $list = Db::name('order_type')
  14. ->field('id,title')
  15. ->where('enable',1)
  16. ->where('del',0)
  17. ->where('org_id',$this->orgId)
  18. ->where('parent_id','>',0)
  19. ->select();
  20. foreach ($list as $k=>$v){
  21. $list[$k]['nums'] = Db::name('orders')
  22. ->alias('o')
  23. ->join('order_repair or','or.order_id=o.id')
  24. ->where('or.type_id',$v['id'])
  25. ->where('o.del',0)
  26. ->where('o.create_time','>=',$sTime)
  27. ->where('o.create_time','<=',$eTime)
  28. ->count();
  29. }
  30. $data = list_sort_by($list,'nums','desc');
  31. $result['rows'] = $data;
  32. return json($result);
  33. }else{
  34. $this->assign('start',$start);
  35. $this->assign('end',$end);
  36. return $this->fetch();
  37. }
  38. }
  39. public function repairItemsExport(){
  40. $start = input('start',date('Y-m-d',strtotime('-7 day')));
  41. $end = input('end',date('Y-m-d'));
  42. $sTime = $start.' 00:00:00';
  43. $eTime = $end.' 23:59:59';
  44. $list = Db::name('order_type')
  45. ->field('id,title')
  46. ->where('enable',1)
  47. ->where('del',0)
  48. ->where('org_id',$this->orgId)
  49. ->where('parent_id','>',0)
  50. ->select();
  51. foreach ($list as $k=>$v){
  52. $list[$k]['nums'] = Db::name('orders')
  53. ->alias('o')
  54. ->join('order_repair or','or.order_id=o.id')
  55. ->where('or.type_id',$v['id'])
  56. ->where('o.del',0)
  57. ->where('o.create_time','>=',$sTime)
  58. ->where('o.create_time','<=',$eTime)
  59. ->count();
  60. }
  61. $data = list_sort_by($list,'nums','desc');
  62. include_once env('root_path').'/extend/phpexcel/Classes/PHPExcel.php';
  63. //实例化PHPExcel类
  64. $objPHPExcel =new \PHPExcel();
  65. //激活当前的sheet表
  66. $objPHPExcel->setActiveSheetIndex(0);
  67. //设置表格头(即excel表格的第一行)
  68. $objPHPExcel->setActiveSheetIndex(0)
  69. ->setCellValue('A1', '报修事项')
  70. ->setCellValue('B1', '总数');
  71. // 设置表格头水平居中
  72. $objPHPExcel->setActiveSheetIndex(0)->getStyle('A1')->getAlignment()
  73. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  74. $objPHPExcel->setActiveSheetIndex(0)->getStyle('B1')->getAlignment()
  75. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  76. $objPHPExcel->setActiveSheetIndex(0)->getStyle('C1')->getAlignment()
  77. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  78. //设置列水平居中
  79. $objPHPExcel->setActiveSheetIndex(0)->getStyle('A')->getAlignment()
  80. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  81. $objPHPExcel->setActiveSheetIndex(0)->getStyle('B')->getAlignment()
  82. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  83. $objPHPExcel->setActiveSheetIndex(0)->getStyle('C')->getAlignment()
  84. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  85. //设置单元格宽度
  86. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('A')->setWidth(30);
  87. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('B')->setWidth(30);
  88. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('C')->setWidth(30);
  89. //循环刚取出来的数组,将数据逐一添加到excel表格。
  90. for ($i = 0; $i < count($data); $i++) {
  91. $objPHPExcel->getActiveSheet()->setCellValue('A' . ($i + 2), $data[$i]['title']);
  92. $objPHPExcel->getActiveSheet()->setCellValue('B' . ($i + 2), $data[$i]['nums']);
  93. }
  94. //设置保存的Excel表格名称
  95. $filename = '报修事项统计报表_' . date('YmdHis', time()) . '.xls';
  96. //设置当前激活的sheet表格名称
  97. $objPHPExcel->getActiveSheet()->setTitle('报修事项统计报表');
  98. //设置浏览器窗口下载表格
  99. ob_end_clean();
  100. header("Content-Type: application/force-download");
  101. header("Content-Type: application/octet-stream");
  102. header("Content-Type: application/download");
  103. header('Content-Disposition:inline;filename="' . $filename);
  104. //生成excel文件
  105. $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
  106. //下载文件在浏览器窗口
  107. return $objWriter->save('php://output');
  108. }
  109. public function repairCate(){
  110. $start = input('start',date('Y-m-d',strtotime('-7 day')));
  111. $end = input('end',date('Y-m-d'));
  112. if(request()->isAjax()){
  113. $sTime = $start.' 00:00:00';
  114. $eTime = $end.' 23:59:59';
  115. $list = Db::name('order_type')
  116. ->field('id,title,parent_id')
  117. ->where('enable',1)
  118. ->where('del',0)
  119. ->where('org_id',$this->orgId)
  120. ->where('parent_id','=',0)
  121. ->select();
  122. foreach ($list as $k=>$v){
  123. $type = Db::name('order_type')
  124. ->field('id')
  125. ->where('enable',1)
  126. ->where('del',0)
  127. ->where('org_id',$this->orgId)
  128. ->where('parent_id',$v['id'])
  129. ->select();
  130. $ids = [];
  131. foreach ($type as $kk=>$vv){
  132. $ids[$kk] = $vv['id'];
  133. }
  134. $list[$k]['ids'] = $ids;
  135. }
  136. foreach ($list as $k=>$v){
  137. $list[$k]['nums'] = Db::name('orders')
  138. ->alias('o')
  139. ->join('order_repair or','or.order_id=o.id')
  140. ->whereIn('or.type_id',$v['ids'])
  141. ->where('o.del',0)
  142. ->where('o.org_id',$this->orgId)
  143. ->where('o.create_time','>=',$sTime)
  144. ->where('o.create_time','<=',$eTime)
  145. ->count();
  146. }
  147. $data = list_sort_by($list,'nums','desc');
  148. $result['rows'] = $data;
  149. return json($result);
  150. }else{
  151. $this->assign('start',$start);
  152. $this->assign('end',$end);
  153. return $this->fetch();
  154. }
  155. }
  156. public function repairCateExport(){
  157. $start = input('start',date('Y-m-d',strtotime('-7 day')));
  158. $end = input('end',date('Y-m-d'));
  159. $sTime = $start.' 00:00:00';
  160. $eTime = $end.' 23:59:59';
  161. $list = Db::name('order_type')
  162. ->field('id,title,parent_id')
  163. ->where('enable',1)
  164. ->where('del',0)
  165. ->where('org_id',$this->orgId)
  166. ->where('parent_id','=',0)
  167. ->select();
  168. foreach ($list as $k=>$v){
  169. $type = Db::name('order_type')
  170. ->field('id')
  171. ->where('enable',1)
  172. ->where('del',0)
  173. ->where('org_id',$this->orgId)
  174. ->where('parent_id',$v['id'])
  175. ->select();
  176. $ids = [];
  177. foreach ($type as $kk=>$vv){
  178. $ids[$kk] = $vv['id'];
  179. }
  180. $list[$k]['ids'] = $ids;
  181. }
  182. foreach ($list as $k=>$v){
  183. $list[$k]['nums'] = Db::name('orders')
  184. ->alias('o')
  185. ->join('order_repair or','or.order_id=o.id')
  186. ->whereIn('or.type_id',$v['ids'])
  187. ->where('o.del',0)
  188. ->where('o.org_id',$this->orgId)
  189. ->where('o.create_time','>=',$sTime)
  190. ->where('o.create_time','<=',$eTime)
  191. ->count();
  192. }
  193. $data = list_sort_by($list,'nums','desc');
  194. include_once env('root_path').'/extend/phpexcel/Classes/PHPExcel.php';
  195. //实例化PHPExcel类
  196. $objPHPExcel =new \PHPExcel();
  197. //激活当前的sheet表
  198. $objPHPExcel->setActiveSheetIndex(0);
  199. //设置表格头(即excel表格的第一行)
  200. $objPHPExcel->setActiveSheetIndex(0)
  201. ->setCellValue('A1', '报修类型')
  202. ->setCellValue('B1', '总数');
  203. // 设置表格头水平居中
  204. $objPHPExcel->setActiveSheetIndex(0)->getStyle('A1')->getAlignment()
  205. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  206. $objPHPExcel->setActiveSheetIndex(0)->getStyle('B1')->getAlignment()
  207. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  208. $objPHPExcel->setActiveSheetIndex(0)->getStyle('C1')->getAlignment()
  209. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  210. //设置列水平居中
  211. $objPHPExcel->setActiveSheetIndex(0)->getStyle('A')->getAlignment()
  212. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  213. $objPHPExcel->setActiveSheetIndex(0)->getStyle('B')->getAlignment()
  214. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  215. $objPHPExcel->setActiveSheetIndex(0)->getStyle('C')->getAlignment()
  216. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  217. //设置单元格宽度
  218. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('A')->setWidth(30);
  219. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('B')->setWidth(30);
  220. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('C')->setWidth(30);
  221. //循环刚取出来的数组,将数据逐一添加到excel表格。
  222. for ($i = 0; $i < count($data); $i++) {
  223. $objPHPExcel->getActiveSheet()->setCellValue('A' . ($i + 2), $data[$i]['title']);
  224. $objPHPExcel->getActiveSheet()->setCellValue('B' . ($i + 2), $data[$i]['nums']);
  225. }
  226. //设置保存的Excel表格名称
  227. $filename = '报修类型统计报表_' . date('YmdHis', time()) . '.xls';
  228. //设置当前激活的sheet表格名称
  229. $objPHPExcel->getActiveSheet()->setTitle('报修类型统计报表');
  230. //设置浏览器窗口下载表格
  231. ob_end_clean();
  232. header("Content-Type: application/force-download");
  233. header("Content-Type: application/octet-stream");
  234. header("Content-Type: application/download");
  235. header('Content-Disposition:inline;filename="' . $filename);
  236. //生成excel文件
  237. $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
  238. //下载文件在浏览器窗口
  239. return $objWriter->save('php://output');
  240. }
  241. public function repairWorkload($mode){
  242. $start = input('start',date('Y-m-d 00:00:00',strtotime('-7 day')));
  243. $end = input('end',date('Y-m-d 23:59:59'));
  244. $mode = input('mode');
  245. $lists = $this->repairWorkloadData($start,$end,$mode);
  246. $this->assign('list',$lists['list']);
  247. $this->assign('totalList',$lists['totalList']);
  248. if($mode == 1){
  249. $title = '报修工作量统计报表';
  250. }elseif ($mode == 2){
  251. $title = '保洁工作量统计报表';
  252. }elseif ($mode == 3){
  253. $title = '运送工作量统计报表';
  254. }elseif ($mode == 4){
  255. $title = '应急工作量统计报表';
  256. }elseif ($mode == 0){
  257. $title = '一键呼叫工作量统计报表';
  258. }
  259. $this->assign('mode',$mode);
  260. $this->assign('title',$title);
  261. $this->assign('start',$start);
  262. $this->assign('end',$end);
  263. return $this->fetch();
  264. }
  265. public function repairWorkloadData($start,$end,$mode){
  266. // $sTime = $start.' 00:00:00';
  267. // $eTime = $end.' 23:59:59';
  268. $sTime = $start;
  269. $eTime = $end;
  270. $list = Db::name('todo')
  271. ->field('id,to_user_id')
  272. ->where('del',0)
  273. ->where('org_id',$this->orgId)
  274. ->where('create_time','>=',$sTime)
  275. ->where('create_time','<=',$eTime)
  276. ->where('work_type_mode',$mode)
  277. ->group('to_user_id')
  278. ->select();
  279. foreach ($list as $k=>$v){
  280. $list[$k]['user_name'] = Db::name('user')->where('id',$v['to_user_id'])->value('real_name');
  281. $list[$k]['score'] = 0;
  282. if($mode==3){
  283. $list[$k]['score'] = Db::name('todo')
  284. ->alias('a')
  285. ->join('order_convey b','a.order_id=b.order_id')
  286. ->where('a.del',0)
  287. ->where('a.to_user_id',$v['to_user_id'])
  288. ->where('a.org_id',$this->orgId)
  289. ->where('a.create_time','>=',$sTime)
  290. ->where('a.create_time','<=',$eTime)
  291. ->where('a.work_type_mode',$mode)
  292. ->where('a.todo_mode',3)
  293. ->sum('b.score');
  294. }
  295. $list[$k]['nums'] =Db::name('todo')
  296. ->where('del',0)
  297. ->where('to_user_id',$v['to_user_id'])
  298. ->where('org_id',$this->orgId)
  299. ->where('create_time','>=',$sTime)
  300. ->where('create_time','<=',$eTime)
  301. ->where('work_type_mode',$mode)
  302. ->count();
  303. $list[$k]['nums1'] =Db::name('todo')
  304. ->where('del',0)
  305. ->where('to_user_id',$v['to_user_id'])
  306. ->where('org_id',$this->orgId)
  307. ->where('create_time','>=',$sTime)
  308. ->where('create_time','<=',$eTime)
  309. ->where('work_type_mode',$mode)
  310. ->where('todo_mode',1)
  311. ->count();
  312. $list[$k]['nums2'] =Db::name('todo')
  313. ->where('del',0)
  314. ->where('to_user_id',$v['to_user_id'])
  315. ->where('org_id',$this->orgId)
  316. ->where('create_time','>=',$sTime)
  317. ->where('create_time','<=',$eTime)
  318. ->where('work_type_mode',$mode)
  319. ->where('todo_mode',2)
  320. ->count();
  321. $list[$k]['nums3'] =Db::name('todo')
  322. ->where('del',0)
  323. ->where('to_user_id',$v['to_user_id'])
  324. ->where('org_id',$this->orgId)
  325. ->where('create_time','>=',$sTime)
  326. ->where('create_time','<=',$eTime)
  327. ->where('work_type_mode',$mode)
  328. ->where('todo_mode',3)
  329. ->count();
  330. $list[$k]['nums4'] =Db::name('todo')
  331. ->where('del',0)
  332. ->where('to_user_id',$v['to_user_id'])
  333. ->where('org_id',$this->orgId)
  334. ->where('create_time','>=',$sTime)
  335. ->where('create_time','<=',$eTime)
  336. ->where('work_type_mode',$mode)
  337. ->where('todo_mode',4)
  338. ->count();
  339. $list[$k]['nums5'] =Db::name('todo')
  340. ->where('del',0)
  341. ->where('to_user_id',$v['to_user_id'])
  342. ->where('org_id',$this->orgId)
  343. ->where('create_time','>=',$sTime)
  344. ->where('create_time','<=',$eTime)
  345. ->where('work_type_mode',$mode)
  346. ->where('todo_mode',5)
  347. ->count();
  348. $list[$k]['nums6'] =Db::name('todo')
  349. ->where('del',0)
  350. ->where('to_user_id',$v['to_user_id'])
  351. ->where('org_id',$this->orgId)
  352. ->where('create_time','>=',$sTime)
  353. ->where('create_time','<=',$eTime)
  354. ->where('work_type_mode',$mode)
  355. ->where('todo_mode',6)
  356. ->count();
  357. }
  358. $list = $list ? list_sort_by($list,'nums','desc'):[];
  359. $totalList = [
  360. array_sum(array_column($list,'score')),
  361. array_sum(array_column($list,'nums')),
  362. array_sum(array_column($list,'nums1')),
  363. array_sum(array_column($list,'nums2')),
  364. array_sum(array_column($list,'nums3')),
  365. array_sum(array_column($list,'nums4')),
  366. array_sum(array_column($list,'nums5')),
  367. array_sum(array_column($list,'nums6')),
  368. ];
  369. if($mode!=3){
  370. unset($totalList[0]);
  371. }
  372. return ['list'=>$list,'totalList'=>$totalList];
  373. }
  374. public function repairWorkloadExport(){
  375. $start = input('start',date('Y-m-d 00:00:00',strtotime('-7 day')));
  376. $end = input('end',date('Y-m-d 23:59:59'));
  377. $mode = input('mode');
  378. $ret = $this->repairWorkloadData($start,$end,$mode);
  379. $list = $ret['list'];
  380. $totalList = $ret['totalList'];
  381. $title = '';
  382. if($mode == 1){
  383. $title = '报修工作量统计报表';
  384. }elseif ($mode == 2){
  385. $title = '保洁工作量统计报表';
  386. }elseif ($mode == 3){
  387. $title = '运送工作量统计报表';
  388. }elseif ($mode == 4){
  389. $title = '应急工作量统计报表';
  390. }elseif ($mode == 0){
  391. $title = '一键呼叫工作量统计报表';
  392. }
  393. set_time_limit(0);
  394. ini_set("memory_limit", "1024M");
  395. header("Content-type: application/vnd.ms-excel");
  396. header("Content-Type: application/force-download");
  397. header("Content-Disposition: attachment; filename=".$title.".xls");
  398. header('Expires:0');
  399. header('Pragma:public');
  400. $res = '';
  401. $res.='<table style="border-top: 1px solid #ddd;border-left: 1px solid #ddd;border-spacing: 0;">';
  402. $res.='<tr style="background: #ffffff;">';
  403. $res.='<th style="text-align: center;background: #ffffff;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">姓名</th>';
  404. if($mode==3){
  405. $res.='<th style="text-align: center;background: #ffffff;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">累计运送积分</th>';
  406. }
  407. $res.='<th style="text-align: center;background: #ffffff;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">总数</th>';
  408. $res.='<th style="text-align: center;background: #ffffff;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">待接单</th>';
  409. $res.='<th style="text-align: center;background: #ffffff;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">已接单</th>';
  410. $res.='<th style="text-align: center;background: #ffffff;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">已完成</th>';
  411. $res.='<th style="text-align: center;background: #ffffff;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">被员工驳回</th>';
  412. $res.='<th style="text-align: center;background: #ffffff;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">客观原因无法完成</th>';
  413. $res.='<th style="text-align: center;background: #ffffff;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">已取消</th>';
  414. $res.='</tr>';
  415. foreach ($list as $k=>$v){
  416. $res.='<tr style="background: #ffffff;">';
  417. $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v['user_name'].'</td>';
  418. if($mode==3){
  419. $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v['score'].'</td>';
  420. }
  421. $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v['nums'].'</td>';
  422. $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v['nums1'].'</td>';
  423. $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v['nums2'].'</td>';
  424. $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v['nums3'].'</td>';
  425. $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v['nums4'].'</td>';
  426. $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v['nums5'].'</td>';
  427. $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v['nums6'].'</td>';
  428. $res.='</tr>';
  429. }
  430. $res.='<tr style="background: #ffffff;">';
  431. $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd" >合计:</td>';
  432. foreach ($totalList as $k=>$v){
  433. $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd" >'.$v.'</td>';
  434. }
  435. $res.='</tr>';
  436. echo $res;
  437. }
  438. public function conveyCateWorkload(){
  439. $start = input('start',date('Y-m-d 00:00:00',strtotime('-7 day')));
  440. $end = input('end',date('Y-m-d 23:59:59'));
  441. $lists = $this->conveyCateWorkloadData($start,$end);
  442. $this->assign('list',$lists);
  443. $this->assign('start',$start);
  444. $this->assign('end',$end);
  445. return $this->fetch();
  446. }
  447. public function conveyCateWorkloadData($start,$end){
  448. // $sTime = $start.' 00:00:00';
  449. // $eTime = $end.' 23:59:59';
  450. $sTime = $start;
  451. $eTime = $end;
  452. $list = Db::name('address')
  453. ->field('id,title')
  454. ->where('enable',1)
  455. ->where('del',0)
  456. ->where('org_id',$this->orgId)
  457. ->where('find_in_set(2,types)')
  458. ->select();
  459. foreach ($list as $k=>$v){
  460. $list[$k]['nums'] = Db::name('order_convey_lis')
  461. ->where('org_id',$this->orgId)
  462. ->where('addr_id',$v['id'])
  463. ->where('create_time','>=',$sTime)
  464. ->where('create_time','<=',$eTime)
  465. ->count();
  466. }
  467. return $list;
  468. }
  469. public function conveyCateWorkloadExport(){
  470. $start = input('start',date('Y-m-d 00:00:00',strtotime('-7 day')));
  471. $end = input('end',date('Y-m-d 23:59:59'));
  472. $list = $this->conveyCateWorkloadData($start,$end);
  473. include_once env('root_path').'/extend/phpexcel/Classes/PHPExcel.php';
  474. //实例化PHPExcel类
  475. $objPHPExcel =new \PHPExcel();
  476. //激活当前的sheet表
  477. $objPHPExcel->setActiveSheetIndex(0);
  478. //设置表格头(即excel表格的第一行)
  479. $objPHPExcel->setActiveSheetIndex(0)
  480. ->setCellValue('A1', '运送地点')
  481. ->setCellValue('B1', '标本');
  482. // 设置表格头水平居中
  483. $objPHPExcel->setActiveSheetIndex(0)->getStyle('A1')->getAlignment()
  484. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  485. $objPHPExcel->setActiveSheetIndex(0)->getStyle('B1')->getAlignment()
  486. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  487. $objPHPExcel->setActiveSheetIndex(0)->getStyle('C1')->getAlignment()
  488. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  489. //设置列水平居中
  490. $objPHPExcel->setActiveSheetIndex(0)->getStyle('A')->getAlignment()
  491. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  492. $objPHPExcel->setActiveSheetIndex(0)->getStyle('B')->getAlignment()
  493. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  494. $objPHPExcel->setActiveSheetIndex(0)->getStyle('C')->getAlignment()
  495. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  496. //设置单元格宽度
  497. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('A')->setWidth(30);
  498. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('B')->setWidth(30);
  499. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('C')->setWidth(30);
  500. //循环刚取出来的数组,将数据逐一添加到excel表格。
  501. for ($i = 0; $i < count($list); $i++) {
  502. $objPHPExcel->getActiveSheet()->setCellValue('A' . ($i + 2), $list[$i]['title']);
  503. $objPHPExcel->getActiveSheet()->setCellValue('B' . ($i + 2), $list[$i]['nums']);
  504. }
  505. //设置保存的Excel表格名称
  506. $filename = '运送类型工作量统计_'. date('YmdHis', time()) . '.xls';
  507. //设置当前激活的sheet表格名称
  508. $objPHPExcel->getActiveSheet()->setTitle('运送类型工作量统计_');
  509. //设置浏览器窗口下载表格
  510. ob_end_clean();
  511. header("Content-Type: application/force-download");
  512. header("Content-Type: application/octet-stream");
  513. header("Content-Type: application/download");
  514. header('Content-Disposition:inline;filename="' . $filename);
  515. //生成excel文件
  516. $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
  517. //下载文件在浏览器窗口
  518. return $objWriter->save('php://output');
  519. }
  520. public function conveyCateTodo(){
  521. $start = input('start',date('Y-m-d 00:00:00',strtotime('-7 day')));
  522. $end = input('end',date('Y-m-d 23:59:59'));
  523. $ret = $this->conveyCateTodoData($start,$end);
  524. $this->assign('list',$ret);
  525. $this->assign('start',$start);
  526. $this->assign('end',$end);
  527. return $this->fetch();
  528. }
  529. public function conveyCateTodoData($start,$end){
  530. // $sTime = $start.' 00:00:00';
  531. // $eTime = $end.' 23:59:59';
  532. $sTime = $start;
  533. $eTime = $end;
  534. $list = Db::name('convey_cate')
  535. ->field('id,title')
  536. ->where('enable',1)
  537. ->where('del',0)
  538. ->where('org_id',$this->orgId)
  539. ->select();
  540. foreach ($list as $k=>$v){
  541. $todo = Db::name('todo')
  542. ->alias('t')
  543. ->field('t.wc_time')
  544. ->join('order_convey oc','oc.order_id=t.order_id')
  545. ->where('oc.type',$v['id'])
  546. ->where('t.del',0)
  547. ->where('t.create_time','>=',$sTime)
  548. ->where('t.create_time','<=',$eTime)
  549. ->where('t.todo_mode',3)
  550. ->select();
  551. $todoCount = Db::name('todo')
  552. ->alias('t')
  553. ->field('t.wc_time')
  554. ->join('order_convey oc','oc.order_id=t.order_id')
  555. ->where('oc.type',$v['id'])
  556. ->where('t.del',0)
  557. ->where('t.create_time','>=',$sTime)
  558. ->where('t.create_time','<=',$eTime)
  559. ->where('t.todo_mode',3)
  560. ->count();
  561. $totalTime = 0;
  562. foreach ($todo as $key=>$val){
  563. $totalTime +=$val['wc_time'];
  564. }
  565. $aveTime = $totalTime>0?round($totalTime/$todoCount/60,2):0;
  566. $list[$k]['count'] = isset($todoCount)?$todoCount:0;
  567. $list[$k]['total_time'] = isset($totalTime)?round($totalTime/60,2):0;
  568. $list[$k]['ave_time'] = isset($aveTime)&&$aveTime>0?$aveTime:0;
  569. }
  570. $list = $list?arraySequence($list,'count','SORT_DESC'):[];
  571. return $list;
  572. }
  573. public function conveyCateTodoExport(){
  574. $start = input('start',date('Y-m-d 00:00:00',strtotime('-7 day')));
  575. $end = input('end',date('Y-m-d 23:59:59'));
  576. $list = $this->conveyCateTodoData($start,$end);
  577. include_once env('root_path').'/extend/phpexcel/Classes/PHPExcel.php';
  578. //实例化PHPExcel类
  579. $objPHPExcel =new \PHPExcel();
  580. //激活当前的sheet表
  581. $objPHPExcel->setActiveSheetIndex(0);
  582. //设置表格头(即excel表格的第一行)
  583. $objPHPExcel->setActiveSheetIndex(0)
  584. ->setCellValue('A1', '运送类型')
  585. ->setCellValue('B1', '工单数')
  586. ->setCellValue('C1', '总时长(分)')
  587. ->setCellValue('D1', '平均时长(分)');
  588. // 设置表格头水平居中
  589. $objPHPExcel->setActiveSheetIndex(0)->getStyle('A1')->getAlignment()
  590. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  591. $objPHPExcel->setActiveSheetIndex(0)->getStyle('B1')->getAlignment()
  592. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  593. $objPHPExcel->setActiveSheetIndex(0)->getStyle('C1')->getAlignment()
  594. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  595. $objPHPExcel->setActiveSheetIndex(0)->getStyle('D1')->getAlignment()
  596. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  597. //设置列水平居中
  598. $objPHPExcel->setActiveSheetIndex(0)->getStyle('A')->getAlignment()
  599. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  600. $objPHPExcel->setActiveSheetIndex(0)->getStyle('B')->getAlignment()
  601. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  602. $objPHPExcel->setActiveSheetIndex(0)->getStyle('C')->getAlignment()
  603. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  604. $objPHPExcel->setActiveSheetIndex(0)->getStyle('D')->getAlignment()
  605. ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  606. //设置单元格宽度
  607. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('A')->setWidth(30);
  608. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('B')->setWidth(30);
  609. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('C')->setWidth(30);
  610. $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('D')->setWidth(30);
  611. //循环刚取出来的数组,将数据逐一添加到excel表格。
  612. for ($i = 0; $i < count($list); $i++) {
  613. $objPHPExcel->getActiveSheet()->setCellValue('A' . ($i + 2), $list[$i]['title']);
  614. $objPHPExcel->getActiveSheet()->setCellValue('B' . ($i + 2), $list[$i]['count']);
  615. $objPHPExcel->getActiveSheet()->setCellValue('C' . ($i + 2), $list[$i]['total_time']);
  616. $objPHPExcel->getActiveSheet()->setCellValue('D' . ($i + 2), $list[$i]['ave_time']);
  617. }
  618. //设置保存的Excel表格名称
  619. $filename = '运送类型工单统计_'. date('YmdHis', time()) . '.xls';
  620. //设置当前激活的sheet表格名称
  621. $objPHPExcel->getActiveSheet()->setTitle('运送类型工单统计_');
  622. //设置浏览器窗口下载表格
  623. ob_end_clean();
  624. header("Content-Type: application/force-download");
  625. header("Content-Type: application/octet-stream");
  626. header("Content-Type: application/download");
  627. header('Content-Disposition:inline;filename="' . $filename);
  628. //生成excel文件
  629. $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
  630. //下载文件在浏览器窗口
  631. return $objWriter->save('php://output');
  632. }
  633. }